kstaken 2002/07/12 03:09:51
Modified: java/src/org/apache/xindice/client/xmldb DatabaseImpl.java
ResourceSetImpl.java XindiceCollection.java
java/src/org/apache/xindice/client/xmldb/services
CollectionManagementServiceImpl.java
QueryService.java
java/src/org/apache/xindice/client/xmldb/xmlrpc
CollectionImpl.java
Added: java/src/org/apache/xindice/client/xmldb/embed
CollectionImpl.java DatabaseImpl.java
Log:
Adding an intial implementation of an embedded XML:DB API driver. It passes
the
tests, but it's not configurable and the command line tools won't work with
it yet. I also believe there are problems with the IDs it is using on
resources. The same probably applies to the XML-RPC impl.
Revision Changes Path
1.7 +7 -5
xml-xindice/java/src/org/apache/xindice/client/xmldb/DatabaseImpl.java
Index: DatabaseImpl.java
===================================================================
RCS file:
/home/cvs/xml-xindice/java/src/org/apache/xindice/client/xmldb/DatabaseImpl.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- DatabaseImpl.java 12 Jul 2002 03:06:16 -0000 1.6
+++ DatabaseImpl.java 12 Jul 2002 10:09:51 -0000 1.7
@@ -85,15 +85,17 @@
/**
* These are the URI prefixes this proxy impl understands.
+ *
+ * XML-RPC is the default.
*/
- public static String CORBA_URI = "xindice-corba://";
public static String XMLRPC_URI = "xindice://";
+ public static String CORBA_URI = "xindice-corba://";
public static String EMBED_URI = "xindice-embed://";
/**
- * Name used in the uri for collections associated with this instance.
+ * Name used in the uri for collections associated with this instance.
*/
- public static String INSTANCE_NAME = "xindice";
+ public static String INSTANCE_NAME = "xindice, xindice-embed,
xindice-corba";
/**
* The XML:DB API Core Level Conformance of this implementation.
@@ -185,7 +187,7 @@
driver = (Database)
Class.forName("org.apache.xindice.client.xmldb.xmlrpc.DatabaseImpl").newInstance();
}
else if (uri.startsWith(EMBED_URI)) {
-
+ driver = (Database)
Class.forName("org.apache.xindice.client.xmldb.embed.DatabaseImpl").newInstance();
}
}
}
1.4 +3 -5
xml-xindice/java/src/org/apache/xindice/client/xmldb/ResourceSetImpl.java
Index: ResourceSetImpl.java
===================================================================
RCS file:
/home/cvs/xml-xindice/java/src/org/apache/xindice/client/xmldb/ResourceSetImpl.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ResourceSetImpl.java 12 Jul 2002 03:06:17 -0000 1.3
+++ ResourceSetImpl.java 12 Jul 2002 10:09:51 -0000 1.4
@@ -60,9 +60,7 @@
*/
import org.apache.xindice.client.xmldb.resources.*;
-
-// TODO: This is shouldn't be here for this class to be generic.
-import org.apache.xindice.client.xmldb.xmlrpc.CollectionImpl;
+import org.apache.xindice.client.xmldb.*;
import org.xmldb.api.base.*;
import org.xmldb.api.modules.*;
@@ -224,7 +222,7 @@
Element set = doc.createElementNS(RESOURCE_SET_NS, "xapi:resourceSet");
set.setAttributeNS(RESOURCE_SET_NS, "xapi:collectionURI",
- "xmldb:xindice://" + ((CollectionImpl)
collection).getCanonicalName());
+ "xmldb:xindice://" + ((XindiceCollection)
collection).getCanonicalName());
set.setAttribute("xmlns:xapi", RESOURCE_SET_NS);
doc.appendChild(set);
1.2 +2 -3
xml-xindice/java/src/org/apache/xindice/client/xmldb/XindiceCollection.java
Index: XindiceCollection.java
===================================================================
RCS file:
/home/cvs/xml-xindice/java/src/org/apache/xindice/client/xmldb/XindiceCollection.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XindiceCollection.java 12 Jul 2002 04:51:49 -0000 1.1
+++ XindiceCollection.java 12 Jul 2002 10:09:51 -0000 1.2
@@ -214,8 +214,7 @@
*
* @return collection name
*/
- public String getName() {
-
+ public String getName() {
return collPath.substring(collPath.lastIndexOf('/') + 1);
}
1.1
xml-xindice/java/src/org/apache/xindice/client/xmldb/embed/CollectionImpl.java
Index: CollectionImpl.java
===================================================================
package org.apache.xindice.client.xmldb.embed;
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xindice" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999-2001, The dbXML
* Group, L.L.C., http://www.dbxmlgroup.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* $Id: CollectionImpl.java,v 1.1 2002/07/12 10:09:51 kstaken Exp $
*/
import org.xmldb.api.base.*;
import org.xmldb.api.modules.*;
import org.apache.xindice.util.*;
import org.apache.xindice.core.FaultCodes;
import org.apache.xindice.core.Database;
import org.apache.xindice.core.Collection;
import org.apache.xindice.core.data.*;
import org.apache.xindice.client.xmldb.resources.*;
import org.apache.xindice.xml.dom.*;
import org.apache.xindice.xml.*;
import org.apache.xindice.client.xmldb.*;
import org.apache.xindice.client.xmldb.services.*;
import org.w3c.dom.*;
import java.io.*;
import java.util.*;
/**
* Implementation of XML:DB's <code>Collection</code> interface using
* XML-RPC to interact with database server
*
* @author James Bates <[EMAIL PROTECTED]>
* @author Kimbro Staken <[EMAIL PROTECTED]>
* @version 1
*/
public class CollectionImpl extends XindiceCollection {
Database db = null;
Collection col = null;
/**
/* Creates new <code>CollectionImpl</code> instance representing
connection
* to server collection.
*
* @param hostPort hostname and port number in <code>host:port</code>
format.
* Port no is optional, in which case HTTP default is assumed.
* @exception XMLDBException thrown if a connection could not be
established,
* because of URL syntax errors, or connection failure, or if
no
* collection with path <code>collPath</code> could be located.
*/
public CollectionImpl(Database db, String collPath) throws XMLDBException
{
super(collPath);
this.db = db;
try {
this.col = db.getCollection(collPath);
} catch (Exception e) {
throw new XMLDBException(ErrorCodes.NO_SUCH_COLLECTION,
"Collection not found: " + collPath);
}
}
/**
* Returns the named resource in this collection
*
* @param resourceName resource name
* @return the resource
*/
public Resource getResource(String resourceName) throws XMLDBException {
checkOpen();
try {
Document doc = col.getDocument(resourceName);
// This should probably just pass the document.
return new XMLResourceImpl(resourceName, this, ((DocumentImpl)
doc).getSymbols(),
((DocumentImpl) doc).getDataBytes());
} catch (Exception e) {
return null;
}
}
/**
* Returns number of resources in this collection.
*
* @return the number of resources
* @exception XMLDBException thrown if count could not be obtained for
* some unexpected reason
*/
public int getResourceCount() throws XMLDBException {
checkOpen();
try {
return (int) col.getDocumentCount();
} catch (Exception e) {
throw new XMLDBException(ErrorCodes.UNKNOWN_ERROR,
e.getMessage());
}
}
/**
* Stores contents of reource back to database
*
* @param resource the resource to store in database
* @exception XMLDBException thrown if resource was of incompatible type,
* or if some other error condition arises.
*/
public void storeResource(Resource resource) throws XMLDBException {
if (!(resource instanceof XMLResource)) {
throw new XMLDBException(ErrorCodes.INVALID_RESOURCE,
"Only XML resources supported");
}
if (resource.getContent() == null) {
throw new XMLDBException(ErrorCodes.INVALID_RESOURCE,
"no resource data");
}
checkOpen();
try {
String name = "";
Node content = ((XMLResourceImpl) resource).getContentAsDOM();
if (content != null && content instanceof Document) {
// TODO: make sure this is using the correct Id. May need to be
documentID.
if (resource.getId() != null) {
col.insertDocument(resource.getId(),
(Document) content);
}
else {
name = col.insertDocument((Document) content).toString();
((XMLResourceImpl) resource).setId(name);
}
}
else {
throw new XMLDBException(ErrorCodes.INVALID_RESOURCE,
"A resource must be a document in
order to be stored.");
}
} catch (Exception e) {
throw new XMLDBException(ErrorCodes.UNKNOWN_ERROR,
e.getMessage());
}
}
/**
* Checks if the collection is still open. Only open collections are safe
* to work with.
*
* @return whether the collection is still open
*/
public boolean isOpen() {
return (col != null);
}
/**
* Returns XML:DB URI that would retrieve this collection
*
* @return a complete XML:DB URI
*/
public String getURI() {
return "xmldb:" + DatabaseImpl.DRIVER_NAME + "://" + collPath;
}
/**
* Returns child collection of this collection with specified name
*
* @param colName child's name
* @return the child collection
* @exception XMLDBException thrown if there is no such child, or some
* other connection error occurred
*/
public org.xmldb.api.base.Collection getChildCollection(String collName)
throws XMLDBException {
if (collName.indexOf('/') != -1) {
throw new XMLDBException(ErrorCodes.INVALID_COLLECTION);
}
return new CollectionImpl(db, collPath + "/" + collName);
}
/**
* Creates a new identifier that can be used as name for a resource in
this
* collection.
*
* @return the new identifier name
* @exception XMLDBException thrown in case of some unknwon error
condition
*/
public String createId() throws XMLDBException {
checkOpen();
try {
return col.createNewOID().toString();
} catch (Exception e) {
throw new XMLDBException(ErrorCodes.UNKNOWN_ERROR,
e.getMessage());
}
}
/**
* Closes the collection.
*
* After calling this method, most methods will throw a
<code>XMLDBException</code>
* exception with code <code>ErrorCodes.COLLECTION_CLOSED</code>. The
collection
* object will in effect become useless.
*/
public void close() throws org.xmldb.api.base.XMLDBException {
col = null;
}
/**
* Returns the parent collection, if any, of this collection
*
* @return the parent collectionm
* @exception XMLDBException thrown if this is the root collection (which
* has no parent), or in case of some other unknown error.
*/
public org.xmldb.api.base.Collection getParentCollection() throws
XMLDBException {
// If there's only one slash then it's the root.
// Not too sure about the robustness of this code.
if (collPath.equals("/") || collPath.equals("")) {
return null;
}
return new CollectionImpl(db, collPath.substring(0,
collPath.lastIndexOf('/')));
}
/**
* Removes a (XML) resource from this collection.
*
* The resource object itself is still valid after removal, and can be
used
* to modify the resource and possibly store it back to the database
again.
*
* @param resource resource to remove from the databasew
* @exception XMLDBException thrown if the resource couldn't be located,
or
* in case of some other error
*/
public void removeResource(Resource resource) throws XMLDBException {
if (!(resource instanceof XMLResource)) {
throw new XMLDBException(ErrorCodes.INVALID_RESOURCE,
"Only XML resources supported");
}
checkOpen();
try {
// TODO: Make sure this is the right ID.
col.remove(resource.getId());
} catch (Exception e) {
throw new XMLDBException(ErrorCodes.NO_SUCH_RESOURCE,
e.getMessage());
}
}
/**
* Lists the available child collections of this collection
*
* @return array containing child collection names
* @exception XMLDBException thrown in case of unknwon error condition
*/
public String[] listChildCollections() throws XMLDBException {
checkOpen();
try {
return col.listCollections();
} catch (Exception e) {
throw new XMLDBException(ErrorCodes.UNKNOWN_ERROR,
e.getMessage());
}
}
/**
* Returns number of child collections in this collection
*
* @return the number of child collections
* @exception XMLDBException thrown in case of unknwon error condition
*/
public int getChildCollectionCount() throws XMLDBException {
checkOpen();
try {
return (int) col.countCollections();
} catch (Exception e) {
throw new XMLDBException(ErrorCodes.UNKNOWN_ERROR,
e.getMessage());
}
}
/**
* Lists the available documents of this collection
*
* @return array containing resource names
* @exception XMLDBException thrown in case of unknwon error condition
*/
public String[] listResources() throws XMLDBException {
checkOpen();
try {
return col.listDocuments();
} catch (Exception e) {
throw new XMLDBException(ErrorCodes.UNKNOWN_ERROR,
e.getMessage());
}
}
/**
* Queries a specific document or the entire collection and returns result
*
* @param name name of document to query, or <code>null</code> to query
* entire collection.
* @param queryLang <code>XUpdate</code> or <code>XPath</code>.
* @param query the text of the query statement
* @param nsMap namespace bindings to use when evaluating query
* @return set containing result of query
* @throws XMLDBException thrown in case of invalid query or other error
*/
public ResourceSet query(String name, String queryLang, String query,
Hashtable nsMap)
throws XMLDBException {
checkOpen();
try {
// Copy the namespaces into a NamespaceMap.
NamespaceMap namespaces = new NamespaceMap();
Enumeration keys = nsMap.keys();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
namespaces.put(key, nsMap.get(key));
}
NodeSet result;
if (name != null) {
result = col.queryDocument(queryLang, query, namespaces, name);
}
else {
result = col.queryCollection(queryLang, query, namespaces);
}
ResourceSetImpl rs = new ResourceSetImpl(this, null);
while (result.hasMoreNodes()) {
Node n = result.getNextNode();
if ( n instanceof DBNode ) {
( ( DBNode ) n ).expandSource();
}
String documentId = ((Element) n).getAttributeNS(QUERY_NS,
"key");
// TODO: this is almost certainly using the wrong id.
XMLResourceImpl resource = new XMLResourceImpl(documentId,
this,
new TextWriter(n).toString());
rs.addResource(resource);
}
return rs;
} catch (Exception e) {
throw new XMLDBException(ErrorCodes.UNKNOWN_ERROR,
"Query error: " + e.getMessage());
}
}
/**
* Creates a new child collection in this collection
*
* @param childName name for new child collection
* @return object representing newly created collection
* @exception XMLDBException thrown if collection createion fails for some
* reason
*/
public org.xmldb.api.base.Collection createCollection(String name)
throws XMLDBException {
checkOpen();
try {
Document doc = new DocumentImpl();
Element colEle = doc.createElement("collection");
colEle.setAttribute("compressed", "true");
colEle.setAttribute("name", name);
doc.appendChild(colEle);
Element filEle = doc.createElement("filer");
filEle.setAttribute("class",
"org.apache.xindice.core.filer.BTreeFiler");
colEle.appendChild(filEle);
return createCollection(name, doc);
} catch (Exception e) {
throw new XMLDBException(ErrorCodes.INVALID_COLLECTION,
"Cannot create child collection: " + e.getMessage());
}
}
/**
* Creates a new collection.
*/
public org.xmldb.api.base.Collection createCollection(String name,
Document configuration) throws XMLDBException {
checkOpen();
try {
Configuration config = new
Configuration(configuration.getDocumentElement(), false);
col.createCollection( name, config );
return getChildCollection(name);
}
catch (Exception e) {
throw new XMLDBException(ErrorCodes.INVALID_COLLECTION,
"Cannot create child collection: " + e.getMessage());
}
}
/**
* Removes child collection from this collection
*
* @param childName name of child collection
* @exception XMLDBException thrown if collection createion fails for some
* reason
*/
public void removeCollection(String childName) throws XMLDBException {
checkOpen();
try {
col.dropCollection(col.getCollection(collPath + "/" + childName));
} catch (Exception e) {
throw new XMLDBException(ErrorCodes.INVALID_COLLECTION,
"Cannot remove child collection: " + e.getMessage());
}
}
/**
* Returns a list of all indexers for this collection.
*
* @return the list of indexers
* @exception XMLDBException
*/
public String[] listIndexers() throws XMLDBException {
try {
return col.listIndexers();
}
catch (Exception e) {
throw FaultCodes.createXMLDBException(e);
}
}
/**
* Creates a new Indexer for this collection.
*
* @param name The name for this indexer
* @param configuration The configuration to use for this indexer.
* @exception XMLDBException
*/
public void createIndexer(Document configuration) throws XMLDBException {
try {
col.createIndexer(new Configuration(configuration, false));
}
catch (Exception e) {
throw FaultCodes.createXMLDBException(e);
}
}
/**
* Drops the indexer from the collection
*
* @param indexer The indexer to drop.
* @exception XMLDBException
*/
public void dropIndexer(String name) throws XMLDBException {
try {
col.dropIndexer(col.getIndexer(name));
}
catch (Exception e) {
throw FaultCodes.createXMLDBException(e);
}
}
/**
* Shutsdown the Database instance
*
* @return the result of the shutdown operation
* @exception XMLDBException
*/
public void shutdown() throws XMLDBException {
try {
}
catch (Exception e) {
throw FaultCodes.createXMLDBException(e);
}
}
}
1.1
xml-xindice/java/src/org/apache/xindice/client/xmldb/embed/DatabaseImpl.java
Index: DatabaseImpl.java
===================================================================
package org.apache.xindice.client.xmldb.embed;
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xindice" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999-2001, The dbXML
* Group, L.L.C., http://www.dbxmlgroup.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* $Id: DatabaseImpl.java,v 1.1 2002/07/12 10:09:51 kstaken Exp $
*/
import org.apache.xindice.core.*;
import org.apache.xindice.xml.dom.*;
import org.apache.xindice.util.*;
import org.xmldb.api.base.Collection;
import org.xmldb.api.base.XMLDBException;
import org.xmldb.api.base.ErrorCodes;
import org.apache.xindice.client.xmldb.CommonConfigurable;
import org.w3c.dom.*;
/**
* implements XML:DB's <code>Database</code> interface providing
* embedded access to a Xindice database.
*
* @author Kimbro Staken <[EMAIL PROTECTED]>
* @author James Bates <[EMAIL PROTECTED]>
* @version 1
*/
public class DatabaseImpl extends CommonConfigurable implements
org.xmldb.api.base.Database {
/* prefix used to denote XML:DB URI's that should use this driver */
static String DRIVER_NAME = "xindice-embed";
/* XML:DB conformance level of this driver */
private String CONFORMANCE_LEVEL = "0";
protected Database db;
/**
* Creates new <code>DatabaseImpl</code> instance
*/
public DatabaseImpl() {
db = new Database();
String configXML = "<root-collection dbroot=\"./db/\" name=\"db\">" +
"<queryengine>" +
"<resolver autoindex=\"false\"
class=\"org.apache.xindice.core.query.XPathQueryResolver\" />" +
"<resolver
class=\"org.apache.xindice.core.xupdate.XUpdateQueryResolver\" />" +
"</queryengine>" +
"</root-collection>";
try {
Document doc = DOMParser.toDocument(configXML);
db.setConfig(new Configuration(doc.getDocumentElement(), false));
}
catch (Exception e) {
e.printStackTrace();
}
}
/**
* Checks whether this driver can handle the <code>xmldbURI</code>
collection
* URI.
*
* @param xmldbURI XML:DB URI to check, without the 'xmldb:' prefix
* @return whether this driver can handle it
*/
public boolean acceptsURI(String xmldbURI) throws XMLDBException {
return ((xmldbURI != null) && xmldbURI.startsWith(getName() + "://"));
}
/**
* Returns the collection referred to by <code>xmldbURI</code>, attempting
* to authenticate access to it using <code>userName</code> and
* <code>password</code> credentials.
*
* @param xmldbURI XML:DB URI to collection, without the 'xmldb:' prefix
* @param userName username used to log into database server
* @param password password used to log into database server
* @exception XMLDBException thrown in case a connection could not be
* established
*/
public Collection getCollection(String xmldbURI, String userName, String
password)
throws XMLDBException {
/* TODO: introduce authentication some day */
if (!acceptsURI(xmldbURI)) {
throw new XMLDBException(ErrorCodes.INVALID_URI);
}
/* Chop off driver prefix, and '://' */
xmldbURI = xmldbURI.substring(getName().length() + 3);
/* Extract host name & port, if present */
int firstSlash = xmldbURI.indexOf('/');
if (firstSlash == -1) {
throw new XMLDBException(ErrorCodes.INVALID_URI);
}
String collPath = xmldbURI.substring(firstSlash);
// The path must start with a /
if ( collPath.startsWith( "/" ) ) {
// find the database name. We just skip the first slash
int colIndex = collPath.indexOf( '/', 1 );
// We assume there's no collection specified
String dbName = collPath.substring( 1 );
String colName = "/";
// if colIndex isn't -1 then we need to pick out the db and
collection
if ( colIndex != -1 ) {
dbName = collPath.substring( 1, colIndex );
// The rest of the name locates the collection
colName = collPath.substring( colIndex );
}
if ( colName.equals("") ) {
colName = "/";
}
return new CollectionImpl(db, colName);
}
else {
throw new XMLDBException(ErrorCodes.INVALID_URI,
"Collection name must begin with a '/'" );
}
}
/**
* Returns the prefix used in XML:DB to denote URI's that this driver can
* handle.
*
* @return the prefix driver name
*/
public String getName() throws XMLDBException {
return DRIVER_NAME;
}
public String getConformanceLevel() throws XMLDBException {
return CONFORMANCE_LEVEL;
}
}
1.2 +13 -12
xml-xindice/java/src/org/apache/xindice/client/xmldb/services/CollectionManagementServiceImpl.java
Index: CollectionManagementServiceImpl.java
===================================================================
RCS file:
/home/cvs/xml-xindice/java/src/org/apache/xindice/client/xmldb/services/CollectionManagementServiceImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CollectionManagementServiceImpl.java 12 Jul 2002 04:51:49 -0000
1.1
+++ CollectionManagementServiceImpl.java 12 Jul 2002 10:09:51 -0000
1.2
@@ -62,10 +62,11 @@
import org.xmldb.api.base.Collection;
import org.xmldb.api.base.XMLDBException;
import org.xmldb.api.base.ErrorCodes;
-import org.apache.xindice.client.xmldb.CommonConfigurable;
-import org.apache.xindice.client.xmldb.xmlrpc.CollectionImpl;
+
+import org.apache.xindice.client.xmldb.*;
import org.apache.xindice.core.FaultCodes;
-import org.w3c.dom.Document;
+
+import org.w3c.dom.*;
/**
* XML:DB CollectionManagementService implementation using XML-RPC to
@@ -112,7 +113,7 @@
"Must set collection for this service");
}
- return ((CollectionImpl) coll).createCollection(childCollName);
+ return ((XindiceCollection) coll).createCollection(childCollName);
}
/**
@@ -127,7 +128,7 @@
"Must set collection for this service");
}
- ((CollectionImpl) coll).removeCollection(childCollName);
+ ((XindiceCollection) coll).removeCollection(childCollName);
}
/**
@@ -174,7 +175,7 @@
*/
public String getCanonicalName() throws XMLDBException {
try {
- return ((CollectionImpl) coll).getCanonicalName();
+ return ((XindiceCollection) coll).getCanonicalName();
}
catch (Exception e) {
throw FaultCodes.createXMLDBException(e);
@@ -198,7 +199,7 @@
"Must set collection for this
service");
}
- return ((CollectionImpl) coll).createCollection(path,
configuration);
+ return ((XindiceCollection) coll).createCollection(path,
configuration);
}
/**
@@ -219,7 +220,7 @@
*/
public String[] listIndexers() throws XMLDBException {
try {
- return ((CollectionImpl) coll).listIndexers();
+ return ((XindiceCollection) coll).listIndexers();
}
catch (Exception e) {
throw FaultCodes.createXMLDBException(e);
@@ -234,7 +235,7 @@
*/
public void createIndexer(Document configuration) throws XMLDBException {
try {
- ((CollectionImpl) coll).createIndexer(configuration);
+ ((XindiceCollection) coll).createIndexer(configuration);
}
catch (Exception e) {
throw FaultCodes.createXMLDBException(e);
@@ -249,7 +250,7 @@
*/
public void dropIndexer(String name) throws XMLDBException {
try {
- ((CollectionImpl) coll).dropIndexer(name);
+ ((XindiceCollection) coll).dropIndexer(name);
}
catch (Exception e) {
throw FaultCodes.createXMLDBException(e);
@@ -263,7 +264,7 @@
* @exception XMLDBException
*/
public void shutdown() throws XMLDBException {
- ((CollectionImpl) coll).shutdown();
+ ((XindiceCollection) coll).shutdown();
}
1.2 +5 -10
xml-xindice/java/src/org/apache/xindice/client/xmldb/services/QueryService.java
Index: QueryService.java
===================================================================
RCS file:
/home/cvs/xml-xindice/java/src/org/apache/xindice/client/xmldb/services/QueryService.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- QueryService.java 12 Jul 2002 04:51:49 -0000 1.1
+++ QueryService.java 12 Jul 2002 10:09:51 -0000 1.2
@@ -58,14 +58,9 @@
* $Id$
*/
-import org.xmldb.api.base.Service;
import org.xmldb.api.modules.XPathQueryService;
-import org.xmldb.api.base.Collection;
-import org.apache.xindice.client.xmldb.CommonConfigurable;
-import org.xmldb.api.base.ResourceSet;
-import org.xmldb.api.base.XMLDBException;
-import org.xmldb.api.base.ErrorCodes;
-import org.apache.xindice.client.xmldb.xmlrpc.CollectionImpl;
+import org.xmldb.api.base.*;
+import org.apache.xindice.client.xmldb.*;
import java.util.Hashtable;
/**
@@ -107,7 +102,7 @@
public ResourceSet queryResource(String name, String query)
throws XMLDBException {
- return ((CollectionImpl) collection).query(name, queryLang, query,
nsMap);
+ return ((XindiceCollection) collection).query(name, queryLang,
query, nsMap);
}
public void clearNamespaces() {
@@ -127,7 +122,7 @@
public ResourceSet query(String query) throws XMLDBException {
- return ((CollectionImpl) collection).query(queryLang, query, nsMap);
+ return ((XindiceCollection) collection).query(queryLang, query,
nsMap);
}
public void removeNamespace(String prefix) throws XMLDBException {
1.5 +1 -1
xml-xindice/java/src/org/apache/xindice/client/xmldb/xmlrpc/CollectionImpl.java
Index: CollectionImpl.java
===================================================================
RCS file:
/home/cvs/xml-xindice/java/src/org/apache/xindice/client/xmldb/xmlrpc/CollectionImpl.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- CollectionImpl.java 12 Jul 2002 04:51:49 -0000 1.4
+++ CollectionImpl.java 12 Jul 2002 10:09:51 -0000 1.5
@@ -266,7 +266,7 @@
return (client != null);
}
-
+
/**
* Returns XML:DB URI that would retrieve this collection
*