kstaken     2002/07/11 21:51:49

  Modified:    java/src/org/apache/xindice/client/xmldb/xmlrpc
                        CollectionImpl.java
  Added:       java/src/org/apache/xindice/client/xmldb
                        XindiceCollection.java
               java/src/org/apache/xindice/client/xmldb/services
                        CollectionManagementServiceImpl.java
                        QueryService.java XPathQueryServiceImpl.java
                        XUpdateQueryServiceImpl.java
  Removed:     java/src/org/apache/xindice/client/xmldb/services
                        XMLObjectService.java
               java/src/org/apache/xindice/client/xmldb/xmlrpc/services
                        CollectionManagementServiceImpl.java
                        QueryService.java XPathQueryServiceImpl.java
                        XUpdateQueryServiceImpl.java
  Log:
  Refactoring to make more code reusable for the embedded version of the API.
  
  Revision  Changes    Path
  1.1                  
xml-xindice/java/src/org/apache/xindice/client/xmldb/XindiceCollection.java
  
  Index: XindiceCollection.java
  ===================================================================
  package org.apache.xindice.client.xmldb;
  /*
   * 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: XindiceCollection.java,v 1.1 2002/07/12 04:51:49 kstaken Exp $
   */
  import org.xmldb.api.base.*;
  import org.xmldb.api.modules.*;
  import org.xmldb.api.base.Collection;
  
  import org.apache.xindice.util.*;
  import org.apache.xindice.core.FaultCodes;
  import org.apache.xindice.client.xmldb.services.*;
  import org.apache.xindice.client.xmldb.resources.XMLResourceImpl;
  import org.apache.xindice.xml.TextWriter;
  
  import java.util.*;
  import org.w3c.dom.*;
  
  import org.xmldb.api.base.ResourceSet;
  import javax.xml.parsers.DocumentBuilderFactory;
  import java.io.StringReader;
  
  /**
  * This is a base XML:DB Collection that is extended by all Xindice
   * XML:DB API drivers. It includes the functionality that is common to
   * all drivers and abstract methods for all other driver specific methods.
   * This enables the implementation of drivers in just two classes and the
   * use of common services implementations.
   *
   * @author Kimbro Staken <[EMAIL PROTECTED]>
   * @author James Bates <[EMAIL PROTECTED]>
   * @version 1
   */
  public abstract class XindiceCollection extends CommonConfigurable implements 
Collection {      
      /* Instantiated named services map */
      protected Hashtable services = null;
      
      /* Xindice query result meta-info namespace */
      public static final String QUERY_NS = 
"http://xml.apache.org/xindice/Query";;
      
      /* path to collection on target server */
      protected String collPath;    
  
      /**
      /* 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 XindiceCollection(String collPath) throws XMLDBException {
          
          this.collPath = collPath;
  
          services = new Hashtable();
          
          // Register all services supported by this collection implementation.
          XPathQueryServiceImpl xpath = new XPathQueryServiceImpl();
          xpath.setCollection(this);
  //        xpath.setSymbolDeserializer(syms);
          registerService(xpath);
  
          XUpdateQueryServiceImpl xupdate = new XUpdateQueryServiceImpl();
          xupdate.setCollection(this);
          registerService(xupdate);
  
          try {
             CollectionManagementServiceImpl manager = new 
CollectionManagementServiceImpl();
             manager.setCollection(this);
             registerService(manager);
  
             // CollectionManagementServiceImpl provides both standard access 
as a
             // CollectionManagementService and Xindice specific access as a
             // CollectionManager and DatabaseInstanceManager.
             // We need to register it explicitly to make it available
             services.put("CollectionManager" + manager.getVersion(), manager);
             services.put("DatabaseInstanceManager" + manager.getVersion(), 
manager);           
          }
          catch (Exception e) {
             throw FaultCodes.createXMLDBException(e);
          }
      }
  
       /**
        * Returns the list of Services supported by this Collection.
        *
        * @return A list of supported Services
        * @exception XMLDBException
        */
       public org.xmldb.api.base.Service[] getServices() throws XMLDBException {
          checkOpen();
  
          Enumeration e = services.elements();
          Service[] result = new Service[services.size()];
  
          int i = 0;
          while (e.hasMoreElements()) {
             result[i] = (Service) e.nextElement();
             i++;
          }
  
          return result;
       }
  
       /**
        * Get a Service instance based on the name and version.
        *
        * @param name The Service instance to retrieve
        * @param version The version of the service to retrieve.
        * @return The Service instance or null if no service was found.
        * @exception XMLDBException
        */
       public org.xmldb.api.base.Service getService(String name, String 
version) throws XMLDBException {
          checkOpen();
  
          Service result = (Service) services.get(name + version);
  
          return result;
       }
  
       /**
        * Registers a new Service with this Collection.
        *
        * @param service Description of Parameter
        * @exception XMLDBException
        */
       public void registerService(org.xmldb.api.base.Service service) throws 
XMLDBException {
          //checkOpen();
  
          service.setCollection(this);
          services.put(service.getName() + service.getVersion(), service);
       }
  
       /**
       * Checks if the collection is still open. Only open collections are safe
        * to work with.
        *
        * @return whether the collection is still open
        */
       public abstract boolean isOpen();
       
      /**
       * Throws an exception if collection is no longer open
       *
       * @exception XMLDBException thrown if collection is closed
       */
      protected void checkOpen() throws XMLDBException {
         
          if (!isOpen()) {
              
              throw new XMLDBException(ErrorCodes.COLLECTION_CLOSED);
          }
      }
      
      /**
       * Returns this collection's name
       *
       * @return collection name
       */
      public String getName() {
  
          return collPath.substring(collPath.lastIndexOf('/') + 1);
      }
          
      /**
       * Returns complete path to collection
       *
       * @return the collection path
       */
      public String getCanonicalName() {
          
          return collPath;
      }
      
      /**
       * Returns XML:DB URI that would retrieve this collection
       *
       * @return a complete XML:DB URI
       */
      public abstract String getURI(); 
      
      /**
       * Constructs a new resource that will belong in this collection.
       *
       * Only XML resources are supported. To save the resource to the 
database, you
       * must first set the resource's XML data, and then call
       * <code>storeResource()</code>.
       *
       * @param name name for new resource. If empty or <code>null</code>, a 
name
       *        will be assigned when storing the resource in the database.
       * @param type must be <code>XMLResource</code>.
       * @exception XMLDBException thrown in case of an invalid resource type 
or name
       */
      public Resource createResource(String name, String type) throws 
XMLDBException {
          if (name == null) {
  
              name = "";
          }
          
          if (name.indexOf('/') != -1) {
              
              throw new XMLDBException(ErrorCodes.INVALID_RESOURCE, 
                      "Name cannot contain '/'");
          }
          
          if (!"XMLResource".equals(type)) {
              
              throw new XMLDBException(ErrorCodes.UNKNOWN_RESOURCE_TYPE,
                      "only XMLResources supported");
          }
          
          return new XMLResourceImpl(name, this);
      }
      
      /**
       * Queries the entire collection and resturns the result
       *
       * @param name name of document to query
       * @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 queryLang, String query, Hashtable nsMap)
              throws XMLDBException {
                  
          return query(null, queryLang, query, nsMap);
      }
  
      /**
       * 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 abstract ResourceSet query(String name, String queryLang, String 
query, Hashtable nsMap)
              throws XMLDBException;
       
      /**
       * 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 abstract Collection createCollection(String childName)
              throws XMLDBException;
       
      public abstract Collection createCollection(String name, Document 
configuration) throws XMLDBException;
       
      /**
       * Removes child collection from this collection
       *
       * @param childName name of child collection
       * @exception XMLDBException thrown if collection createion fails for some
       *                           reason
       */
      public abstract void removeCollection(String childName) throws 
XMLDBException;
       
       /**
        * Returns a list of all indexers for this collection.
        *
        * @return the list of indexers
        * @exception XMLDBException
        */
       public abstract String[] listIndexers() throws XMLDBException;
  
       /**
        * 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 abstract void createIndexer(Document configuration) throws 
XMLDBException;
  
       /**
        * Drops the indexer from the collection
        *
        * @param indexer The indexer to drop.
        * @exception XMLDBException
        */
       public abstract void dropIndexer(String name) throws XMLDBException;
  
       /**
        * Shutsdown the Database instance
        *
        * @return the result of the shutdown operation
        * @exception XMLDBException
        */
       public abstract void shutdown() throws XMLDBException;
  }
  
  
  
  1.1                  
xml-xindice/java/src/org/apache/xindice/client/xmldb/services/CollectionManagementServiceImpl.java
  
  Index: CollectionManagementServiceImpl.java
  ===================================================================
  package org.apache.xindice.client.xmldb.services;
  /*
   * 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: CollectionManagementServiceImpl.java,v 1.1 2002/07/12 04:51:49 
kstaken Exp $
   */
  
  import org.xmldb.api.modules.CollectionManagementService;
  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.core.FaultCodes;
  import org.w3c.dom.Document;
  
  /**
   * XML:DB CollectionManagementService implementation using XML-RPC to
   * communicate with Xindice.
   *
   * @author James Bates <[EMAIL PROTECTED]>
   * @author Kimbro Staken <[EMAIL PROTECTED]>
   * @version 1.0
   */
  public class CollectionManagementServiceImpl extends CommonConfigurable
          implements CollectionManagementService, CollectionManager, 
DatabaseInstanceManager {
  
      /* The collection this service operates on */
      private Collection coll = null;
      
      /* service version */
      private final static String SERVICE_VERSION = "1.0";
      
      /* service name */
      private final static String SERVICE_NAME = "CollectionManagementService";
      
      /**
       * Returns service version
       *
       * @return <code>1.0</code>
       */
      public String getVersion() throws XMLDBException {
          
          return SERVICE_VERSION;
      }
      
      /**
       * Inserts new child collection into this collection
       *
       * @param childCollName name for new child collection
       * @return the newly created child
       */
      public Collection createCollection(String childCollName)
              throws XMLDBException {
                  
          if (coll == null) {
              
              throw new XMLDBException(ErrorCodes.INVALID_COLLECTION,
                  "Must set collection for this service");
          }
          
          return ((CollectionImpl) coll).createCollection(childCollName);
      }
      
      /**
       * Removes child collection from this collection
       *
       * @param childCollName name of child collection to remove
       */
      public void removeCollection(String childCollName) throws XMLDBException {
          if (coll == null) {
              
              throw new XMLDBException(ErrorCodes.INVALID_COLLECTION,
                  "Must set collection for this service");
          }
          
          ((CollectionImpl) coll).removeCollection(childCollName);
      }
      
      /**
       * Returns service name
       *
       * @return <code>CollectionManagementService</code>
       */
      public String getName() {
          
          return SERVICE_NAME;
      }
      
      /**
       * Sets collection this service should operate on
       *
       * @param collection the collection this service should operate on
       */
      public void setCollection(Collection collection) {
          
          this.coll = collection;
      }
  
      /**
         * Returns the name of the collection that this manager is associated 
with.
       *
       * @return the name of the collection
       * @exception XMLDBException
       */
      public String getCollectionName() throws XMLDBException {
         try {
            return coll.getName();
         }
         catch (Exception e) {
            throw FaultCodes.createXMLDBException(e);
         }
      }
  
      /**
         * Returns the fully qualified name of the collection that this manager 
is
       * associated with. This name includes all parent collections.
       *
       * @return the fully qualified name for this collection.
       * @exception XMLDBException
       */
      public String getCanonicalName() throws XMLDBException {
         try {
            return ((CollectionImpl) coll).getCanonicalName();
         }
         catch (Exception e) {
            throw FaultCodes.createXMLDBException(e);
         }
      }
      
      /**
         * Creates a new collection in the database identified by name and using
       * the provided configuration.
       *
       * @param path the path of the new collection
       * @param configuration the XML collection configuration to use for
       *        creating this collection.
       * @return The newly created collection
       * @exception XMLDBException
       */
      public Collection createCollection(String path, Document configuration)
         throws XMLDBException {
            if (coll == null) {
               throw new XMLDBException(ErrorCodes.INVALID_COLLECTION,
                                        "Must set collection for this service");
            }
  
            return ((CollectionImpl) coll).createCollection(path, 
configuration);
         }
  
      /**
       * Drops a child collection from this collection.
       *
       * @param collection The child collection to drop.
       * @exception XMLDBException
       */
      public void dropCollection(String name) throws XMLDBException {
          this.removeCollection(name);
      }
  
      /**
       * Returns a list of all indexers for this collection.
       *
       * @return the list of indexers
       * @exception XMLDBException
       */
      public String[] listIndexers() throws XMLDBException {
         try {
            return ((CollectionImpl) coll).listIndexers();
         }
         catch (Exception e) {
            throw FaultCodes.createXMLDBException(e);
         }
      }
  
      /**
       * Creates a new Indexer for this collection.
       *
       * @param configuration The configuration to use for this indexer.
       * @exception XMLDBException
       */
      public void createIndexer(Document configuration) throws XMLDBException {
         try {
            ((CollectionImpl) coll).createIndexer(configuration);
         }
         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 {
            ((CollectionImpl) coll).dropIndexer(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 {
            ((CollectionImpl) coll).shutdown();
  
      }
  
  
      /**
         * Returns a list of all collection level XMLObjects for this 
collection.
       *
       * @return the list of XMLObjects.
       * @exception XMLDBException
       */
      public String[] listXMLObjects() throws XMLDBException {
         return null;
      }
  
      /**
         * Creates a new collection level XMLObject using the provided 
configuration.
       * The XMLObject will be added to the collection using the provided name 
as
       * a key.
       *
       * @param name The name of this XMLObject
       * @param configuration The XML configuration to use
       * @return The created XMLObject
       * @exception XMLDBException
       */
      public void createXMLObject(Document configuration) throws XMLDBException 
{
         
      }
  
      /**
         * Drops a collection level XMLObject from the collection.
       *
       * @param object The XMLObject to drop.
       * @exception XMLDBException
       */
      public void dropXMLObject(String name)
         throws XMLDBException {
         
         }
  }
  
  
  
  1.1                  
xml-xindice/java/src/org/apache/xindice/client/xmldb/services/QueryService.java
  
  Index: QueryService.java
  ===================================================================
  package org.apache.xindice.client.xmldb.services;
  /*
   * 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: QueryService.java,v 1.1 2002/07/12 04:51:49 kstaken Exp $
   */
  
  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 java.util.Hashtable;
  
  /**
   * Abstract query service.
   * 
   * Used to implemented both XUpdate and XPath query
   * service, as the interface for these queries on the XML-RPC API is more
   * or less identical.
   *
   * @author James Bates <[EMAIL PROTECTED]>
   * @version 1.0
   */
  public abstract class QueryService extends CommonConfigurable implements 
Service {
  
      /* XPath or XUpdate. This property should be set by subclasses */
      protected String queryLang;
      
      /* Collection that this query service should query in */
      Collection collection;
      
      /* namespace bindings in use for this query */
      Hashtable nsMap = new Hashtable();
      
      public String getVersion() {
          
          return "1.0";
      }    
      
      public String getName() {
          
          return queryLang + "QueryService";
      }    
      
      public void setCollection(Collection collection) {
          
          this.collection = collection;
      }
      
      public ResourceSet queryResource(String name, String query)
              throws XMLDBException {
          
          return ((CollectionImpl) collection).query(name, queryLang, query, 
nsMap);
      }    
  
      public void clearNamespaces() {
          
          nsMap.clear();
      }
      
      public String getNamespace(String prefix) {
          
          return (String) nsMap.get(prefix);
      }
      
      public void setNamespace(String prefix, String namespaceURI) {
          
          nsMap.put(prefix, namespaceURI);
      }
      
      public ResourceSet query(String query) throws XMLDBException {
          
          return ((CollectionImpl) collection).query(queryLang, query, nsMap);
      }
      
      public void removeNamespace(String prefix) throws XMLDBException {
          
          nsMap.remove(prefix);
      }
      
  }
  
  
  
  1.3       +19 -181   
xml-xindice/java/src/org/apache/xindice/client/xmldb/services/XPathQueryServiceImpl.java
  
  
  
  
  1.4       +61 -168   
xml-xindice/java/src/org/apache/xindice/client/xmldb/services/XUpdateQueryServiceImpl.java
  
  
  
  
  1.4       +19 -189   
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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- CollectionImpl.java       12 Jul 2002 03:06:17 -0000      1.3
  +++ CollectionImpl.java       12 Jul 2002 04:51:49 -0000      1.4
  @@ -58,29 +58,27 @@
    * $Id$
    */
   import org.xmldb.api.base.*;
  +import org.xmldb.api.base.Collection;
   import org.xmldb.api.modules.*;
  +
   import org.apache.xmlrpc.*;
  +
   import org.apache.xindice.util.*;
   import org.apache.xindice.core.FaultCodes;
   import org.apache.xindice.server.rpc.RPCDefaultMessage;
  -import java.util.Hashtable;
  -import java.util.Vector;
  -import java.util.Enumeration;
  -import java.net.MalformedURLException;
  -import org.apache.xindice.client.xmldb.resources.XMLResourceImpl;
  +import org.apache.xindice.client.xmldb.resources.*;
   import org.apache.xindice.xml.TextWriter;
  -import org.xmldb.api.base.ResourceSet;
  +import org.apache.xindice.client.xmldb.*;
  +import org.apache.xindice.client.xmldb.services.*;
  +
  +import org.w3c.dom.*;
  +import org.xml.sax.*;
  +
   import javax.xml.parsers.DocumentBuilderFactory;
  -import org.w3c.dom.Document;
  -import org.w3c.dom.Element;
  -import org.w3c.dom.Node;
  -import org.w3c.dom.NodeList;
  -import org.xml.sax.InputSource;
  -import java.io.StringReader;
  -import org.apache.xindice.client.xmldb.CommonConfigurable;
  -import org.apache.xindice.client.xmldb.ResourceSetImpl;
  -import org.apache.xindice.client.xmldb.ResourceIteratorImpl;
  -import org.apache.xindice.client.xmldb.xmlrpc.services.*;
  +
  +import java.io.*;
  +import java.util.*;
  +import java.net.MalformedURLException;
   
   /**
    * Implementation of XML:DB's <code>Collection</code> interface using
  @@ -90,22 +88,13 @@
    * @author Kimbro Staken <[EMAIL PROTECTED]>
    * @version 1
    */
  -public class CollectionImpl extends CommonConfigurable implements Collection 
{      
  -    /* Instantiated named services map */
  -    protected Hashtable services = null;
  -    
  +public class CollectionImpl extends XindiceCollection {          
       /* path to XML-RPC service on database */
       private static String XINDICE_SERVICE_LOCATION = "/RPC2";
   
  -    /* Xindice query result meta-info namespace */
  -    public static final String QUERY_NS = 
"http://xml.apache.org/xindice/Query";;
  -    
       /* host and port number of server */
       private String hostPort;
  -    
  -    /* path to collection on target server */
  -    private String collPath;
  -    
  +        
       /* the XML-RPC client stub, connected to server */
       private XmlRpcClient client = null;
   
  @@ -121,7 +110,8 @@
        *            collection with path <code>collPath</code> could be 
located.
        */
       public CollectionImpl(String hostPort, String collPath) throws 
XMLDBException {
  -        
  +        super(collPath);
  +       
           this.hostPort = hostPort;
           this.collPath = collPath;
           String xmlrpcURI = "http://"; + hostPort + XINDICE_SERVICE_LOCATION;
  @@ -150,86 +140,8 @@
               throw new XMLDBException(ErrorCodes.NO_SUCH_COLLECTION,
                                        "Collection not found: " + collPath);
           }
  -
  -        services = new Hashtable();
  -        
  -        // Register all services supported by this collection implementation.
  -        XPathQueryServiceImpl xpath = new XPathQueryServiceImpl();
  -        xpath.setCollection(this);
  -//        xpath.setSymbolDeserializer(syms);
  -        registerService(xpath);
  -
  -        XUpdateQueryServiceImpl xupdate = new XUpdateQueryServiceImpl();
  -        xupdate.setCollection(this);
  -        registerService(xupdate);
  -
  -        try {
  -           CollectionManagementServiceImpl manager = new 
CollectionManagementServiceImpl();
  -           manager.setCollection(this);
  -           registerService(manager);
  -
  -           // CollectionManagementServiceImpl provides both standard access 
as a
  -           // CollectionManagementService and Xindice specific access as a
  -           // CollectionManager and DatabaseInstanceManager.
  -           // We need to register it explicitly to make it available
  -           services.put("CollectionManager" + manager.getVersion(), manager);
  -           services.put("DatabaseInstanceManager" + manager.getVersion(), 
manager);           
  -        }
  -        catch (Exception e) {
  -           throw FaultCodes.createXMLDBException(e);
  -        }
       }
   
  -     /**
  -      * Returns the list of Services supported by this Collection.
  -      *
  -      * @return A list of supported Services
  -      * @exception XMLDBException
  -      */
  -     public org.xmldb.api.base.Service[] getServices() throws XMLDBException 
{
  -        checkOpen();
  -
  -        Enumeration e = services.elements();
  -        Service[] result = new Service[services.size()];
  -
  -        int i = 0;
  -        while (e.hasMoreElements()) {
  -           result[i] = (Service) e.nextElement();
  -           i++;
  -        }
  -
  -        return result;
  -     }
  -
  -     /**
  -      * Get a Service instance based on the name and version.
  -      *
  -      * @param name The Service instance to retrieve
  -      * @param version The version of the service to retrieve.
  -      * @return The Service instance or null if no service was found.
  -      * @exception XMLDBException
  -      */
  -     public org.xmldb.api.base.Service getService(String name, String 
version) throws XMLDBException {
  -        checkOpen();
  -
  -        Service result = (Service) services.get(name + version);
  -
  -        return result;
  -     }
  -
  -     /**
  -      * Registers a new Service with this Collection.
  -      *
  -      * @param service Description of Parameter
  -      * @exception XMLDBException
  -      */
  -     public void registerService(org.xmldb.api.base.Service service) throws 
XMLDBException {
  -        checkOpen();
  -
  -        service.setCollection(this);
  -        services.put(service.getName() + service.getVersion(), service);
  -     }
  -     
       /**
        * Submits a command for RPC to database server
        *
  @@ -356,39 +268,6 @@
       }
       
       /**
  -     * Throws an exception if collection is no longer open
  -     *
  -     * @exception XMLDBException thrown if collection is closed
  -     */
  -    private void checkOpen() throws XMLDBException {
  -       
  -        if (!isOpen()) {
  -            
  -            throw new XMLDBException(ErrorCodes.COLLECTION_CLOSED);
  -        }
  -    }
  -    
  -    /**
  -     * Returns this collection's name
  -     *
  -     * @return collection name
  -     */
  -    public String getName() {
  -
  -        return collPath.substring(collPath.lastIndexOf('/') + 1);
  -    }
  -        
  -    /**
  -     * Returns complete path to collection
  -     *
  -     * @return the collection path
  -     */
  -    public String getCanonicalName() {
  -        
  -        return collPath;
  -    }
  -    
  -    /**
        * Returns XML:DB URI that would retrieve this collection
        *
        * @return a complete XML:DB URI
  @@ -451,39 +330,6 @@
       }
       
       /**
  -     * Constructs a new resource that will belong in this collection.
  -     *
  -     * Only XML resources are supported. To save the resource to the 
database, you
  -     * must first set the resource's XML data, and then call
  -     * <code>storeResource()</code>.
  -     *
  -     * @param name name for new resource. If empty or <code>null</code>, a 
name
  -     *        will be assigned when storing the resource in the database.
  -     * @param type must be <code>XMLResource</code>.
  -     * @exception XMLDBException thrown in case of an invalid resource type 
or name
  -     */
  -    public Resource createResource(String name, String type) throws 
XMLDBException {
  -        if (name == null) {
  -
  -            name = "";
  -        }
  -        
  -        if (name.indexOf('/') != -1) {
  -            
  -            throw new XMLDBException(ErrorCodes.INVALID_RESOURCE, 
  -                    "Name cannot contain '/'");
  -        }
  -        
  -        if (!"XMLResource".equals(type)) {
  -            
  -            throw new XMLDBException(ErrorCodes.UNKNOWN_RESOURCE_TYPE,
  -                    "only XMLResources supported");
  -        }
  -        
  -        return new XMLResourceImpl(name, this);
  -    }
  -    
  -    /**
        * Returns the parent collection, if any, of this collection
        *
        * @return the parent collectionm
  @@ -595,22 +441,6 @@
               throw new XMLDBException(ErrorCodes.UNKNOWN_ERROR, 
e.getMessage());
           }   
       }  
  -
  -    /**
  -     * Queries the entire collection and resturns the result
  -     *
  -     * @param name name of document to query
  -     * @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 queryLang, String query, Hashtable nsMap)
  -            throws XMLDBException {
  -                
  -        return query(null, queryLang, query, nsMap);
  -    }
   
       /**
        * Queries a specific document or the entire collection and returns 
result
  
  
  

Reply via email to