/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $Id: RPCDefaultMessage.java 541508 2007-05-25 01:54:12Z vgritsenko $
*/
package org.apache.xindice.server.rpc;
import org.apache.xindice.core.Collection;
import org.apache.xindice.core.DBException;
import org.apache.xindice.core.Database;
import org.apache.xmlrpc.XmlRpcException;
import org.xmldb.api.base.ErrorCodes;
import org.xmldb.api.base.XMLDBException;
/**
* Base class for all XML-RPC messages.
*
* @author <a href="mailto:kstaken@xmldatabases.org">Kimbro Staken</a>
* @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
* @version $Revision: 541508 $, $Date: 2007-05-24 21:54:12 -0400 (Thu, 24 May 2007) $
*/
public abstract class RPCDefaultMessage implements RPCMessage {
public static final String API_NAME = "Xindice XML-RPC";
public static final String API_VERSION = "0.1";
public static final String RESULT = "result";
public static final String NAME = "name";
public static final String COLLECTION = "collection";
public static final String DOCUMENT = "document";
public static final String COMPRESSED = "compressed";
public static final String TIMESTAMP = "timestamp";
public static final String PATTERN = "pattern";
public static final String MAXKEYSIZE = "maxkeysize";
public static final String PAGESIZE = "pagesize";
public static final String TYPE = "type";
public static final String QUERY = "query";
public static final String NAMESPACES = "namespaces";
public static final String CONFIGURATION = "configuration";
public static final String META = "meta";
public static final String MISSING_COLLECTION_PARAM = "Required parameter 'collection' not found.";
public static final String MISSING_NAME_PARAM = "Required parameter 'name' not found.";
public static final String MISSING_DOCUMENT_PARAM = "Required parameter 'document' not found.";
public static final String MISSING_PATTERN_PARAM = "Required parameter 'pattern' not found.";
public static final String MISSING_TYPE_PARAM = "Required parameter 'type' not found.";
public static final String MISSING_QUERY_PARAM = "Required parameter 'query' not found.";
public static final String MISSING_TIMESTAMP_PARAM = "For compressed results a timestamp must be provided.";
public static final String MISSING_CONFIGURATION_PARAM = "You must either provide a document containing the configuration or specify the 'name' and 'patter' parameters.";
public static final String MISSING_META_CONFIGURATION = "Meta information requested but not enabled";
public static final String MISSING_META_PARAM = "Required parameter 'meta' not found";
/**
* Retrieves a Collection instance based on the path provided in name.
*
* @param name The collection to retrieve
* @return The Collection value
* @exception XmlRpcException
*/
protected Collection getCollection(String name) throws XmlRpcException, XMLDBException, DBException {
// Get rid of any trailling slashes.
while (name.endsWith("/")) {
name = name.substring(0, name.lastIndexOf("/"));
}
// name must start with a /
if (name.startsWith("/")) {
// find the database name. We just skip the first slash
int colIndex = name.indexOf('/', 1);
// We assume there's no collection specified
String dbName = name.substring(1);
String colName = "/";
// if colIndex isn't -1 then we need to pick out the db and collection
if (colIndex != -1) {
dbName = name.substring(1, colIndex);
// The rest of the name locates the collection
colName = name.substring(colIndex + 1);
}
Database db = Database.getDatabase(dbName);
if (db == null) {
throw new XMLDBException(ErrorCodes.NO_SUCH_DATABASE,
"Database '" + dbName + "' could not be found");
}
Collection col = db.getCollection(colName);
if (col == null) {
throw new XMLDBException(ErrorCodes.NO_SUCH_COLLECTION,
"Collection '" + colName + "' could not be found");
}
return col;
} else {
throw new XMLDBException(ErrorCodes.INVALID_URI,
"Collection name must begin with a '/'");
}
}
}