Clover coverage report -
Coverage timestamp: Sun Nov 1 2009 23:08:24 UTC
file stats: LOC: 116   Methods: 1
NCLOC: 63   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
RPCDefaultMessage.java 90% 94.1% 100% 92.9%
coverage coverage
 1    /*
 2    * Licensed to the Apache Software Foundation (ASF) under one or more
 3    * contributor license agreements. See the NOTICE file distributed with
 4    * this work for additional information regarding copyright ownership.
 5    * The ASF licenses this file to You under the Apache License, Version 2.0
 6    * (the "License"); you may not use this file except in compliance with
 7    * the License. You may obtain a copy of the License at
 8    *
 9    * http://www.apache.org/licenses/LICENSE-2.0
 10    *
 11    * Unless required by applicable law or agreed to in writing, software
 12    * distributed under the License is distributed on an "AS IS" BASIS,
 13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14    * See the License for the specific language governing permissions and
 15    * limitations under the License.
 16    *
 17    * $Id: RPCDefaultMessage.java 541508 2007-05-25 01:54:12Z vgritsenko $
 18    */
 19   
 20    package org.apache.xindice.server.rpc;
 21   
 22    import org.apache.xindice.core.Collection;
 23    import org.apache.xindice.core.DBException;
 24    import org.apache.xindice.core.Database;
 25    import org.apache.xmlrpc.XmlRpcException;
 26   
 27    import org.xmldb.api.base.ErrorCodes;
 28    import org.xmldb.api.base.XMLDBException;
 29   
 30    /**
 31    * Base class for all XML-RPC messages.
 32    *
 33    * @author <a href="mailto:kstaken@xmldatabases.org">Kimbro Staken</a>
 34    * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
 35    * @version $Revision: 541508 $, $Date: 2007-05-24 18:54:12 -0700 (Thu, 24 May 2007) $
 36    */
 37    public abstract class RPCDefaultMessage implements RPCMessage {
 38   
 39    public static final String API_NAME = "Xindice XML-RPC";
 40    public static final String API_VERSION = "0.1";
 41   
 42    public static final String RESULT = "result";
 43    public static final String NAME = "name";
 44    public static final String COLLECTION = "collection";
 45    public static final String DOCUMENT = "document";
 46    public static final String COMPRESSED = "compressed";
 47    public static final String TIMESTAMP = "timestamp";
 48    public static final String PATTERN = "pattern";
 49    public static final String MAXKEYSIZE = "maxkeysize";
 50    public static final String PAGESIZE = "pagesize";
 51    public static final String TYPE = "type";
 52    public static final String QUERY = "query";
 53    public static final String NAMESPACES = "namespaces";
 54    public static final String CONFIGURATION = "configuration";
 55    public static final String META = "meta";
 56   
 57    public static final String MISSING_COLLECTION_PARAM = "Required parameter 'collection' not found.";
 58    public static final String MISSING_NAME_PARAM = "Required parameter 'name' not found.";
 59    public static final String MISSING_DOCUMENT_PARAM = "Required parameter 'document' not found.";
 60    public static final String MISSING_PATTERN_PARAM = "Required parameter 'pattern' not found.";
 61    public static final String MISSING_TYPE_PARAM = "Required parameter 'type' not found.";
 62    public static final String MISSING_QUERY_PARAM = "Required parameter 'query' not found.";
 63    public static final String MISSING_TIMESTAMP_PARAM = "For compressed results a timestamp must be provided.";
 64    public static final String MISSING_CONFIGURATION_PARAM = "You must either provide a document containing the configuration or specify the 'name' and 'patter' parameters.";
 65    public static final String MISSING_META_CONFIGURATION = "Meta information requested but not enabled";
 66    public static final String MISSING_META_PARAM = "Required parameter 'meta' not found";
 67   
 68    /**
 69    * Retrieves a Collection instance based on the path provided in name.
 70    *
 71    * @param name The collection to retrieve
 72    * @return The Collection value
 73    * @exception XmlRpcException
 74    */
 75  2381 protected Collection getCollection(String name) throws XmlRpcException, XMLDBException, DBException {
 76    // Get rid of any trailling slashes.
 77  2381 while (name.endsWith("/")) {
 78  1 name = name.substring(0, name.lastIndexOf("/"));
 79    }
 80   
 81    // name must start with a /
 82  2381 if (name.startsWith("/")) {
 83    // find the database name. We just skip the first slash
 84  2381 int colIndex = name.indexOf('/', 1);
 85   
 86    // We assume there's no collection specified
 87  2381 String dbName = name.substring(1);
 88  2381 String colName = "/";
 89   
 90    // if colIndex isn't -1 then we need to pick out the db and collection
 91  2381 if (colIndex != -1) {
 92  2372 dbName = name.substring(1, colIndex);
 93   
 94    // The rest of the name locates the collection
 95  2372 colName = name.substring(colIndex + 1);
 96    }
 97   
 98  2381 Database db = Database.getDatabase(dbName);
 99  2381 if (db == null) {
 100  1 throw new XMLDBException(ErrorCodes.NO_SUCH_DATABASE,
 101    "Database '" + dbName + "' could not be found");
 102    }
 103   
 104  2380 Collection col = db.getCollection(colName);
 105  2380 if (col == null) {
 106  1 throw new XMLDBException(ErrorCodes.NO_SUCH_COLLECTION,
 107    "Collection '" + colName + "' could not be found");
 108    }
 109   
 110  2379 return col;
 111    } else {
 112  0 throw new XMLDBException(ErrorCodes.INVALID_URI,
 113    "Collection name must begin with a '/'");
 114    }
 115    }
 116    }