You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-dev@xml.apache.org by jb...@apache.org on 2002/05/07 15:14:40 UTC

cvs commit: xml-xindice/java/scratchpad/src/org/apache/xindice/client/rpc/modules CollectionManagementServiceImpl.java

jbates      02/05/07 06:14:40

  Modified:    java/scratchpad/src/org/apache/xindice/client/rpc/base
                        CollectionImpl.java
  Added:       java/scratchpad/src/org/apache/xindice/client/rpc/modules
                        CollectionManagementServiceImpl.java
  Log:
  Added basic collection management service
  
  Revision  Changes    Path
  1.3       +54 -2     xml-xindice/java/scratchpad/src/org/apache/xindice/client/rpc/base/CollectionImpl.java
  
  Index: CollectionImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xindice/java/scratchpad/src/org/apache/xindice/client/rpc/base/CollectionImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CollectionImpl.java	7 May 2002 12:30:01 -0000	1.2
  +++ CollectionImpl.java	7 May 2002 13:14:39 -0000	1.3
  @@ -54,7 +54,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    *
  - * $Id: CollectionImpl.java,v 1.2 2002/05/07 12:30:01 jbates Exp $
  + * $Id: CollectionImpl.java,v 1.3 2002/05/07 13:14:39 jbates Exp $
    */
   
   package org.apache.xindice.client.rpc.base;
  @@ -94,7 +94,8 @@
       /* Named service classes map to instantiate for each collection */
       private static String[] serviceClassesMap =
       {  "org.apache.xindice.client.rpc.modules.XPathQueryServiceImpl",
  -      "org.apache.xindice.client.rpc.modules.XUpdateQueryServiceImpl" };
  +      "org.apache.xindice.client.rpc.modules.XUpdateQueryServiceImpl",
  +      "org.apache.xindice.client.rpc.modules.CollectionManagementServiceImpl" };
         
       /* Instantiated named services map */
       private Hashtable servicesMap = new Hashtable();
  @@ -646,4 +647,55 @@
                       "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 Collection createCollection(String childName)
  +            throws XMLDBException {
  +
  +        checkOpen();
  +        try {
  +            
  +            Hashtable params = new Hashtable();
  +            params.put(RPCDefaultMessage.COLLECTION, collPath);
  +            params.put(RPCDefaultMessage.NAME, childName);
  +            runRemoteCommand("CreateCollection", params);
  +            
  +            return getChildCollection(childName);
  +        } 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 {
  +            
  +            Hashtable params = new Hashtable();
  +            params.put(RPCDefaultMessage.COLLECTION, collPath);
  +            params.put(RPCDefaultMessage.NAME, childName);
  +            runRemoteCommand("RemoveCollection", params);
  +        } catch (Exception e) {
  +            
  +            throw new XMLDBException(ErrorCodes.INVALID_COLLECTION,
  +                    "Cannot remove child collection: " + e.getMessage());
  +        }
  +    }
  +    
   }
  
  
  
  1.1                  xml-xindice/java/scratchpad/src/org/apache/xindice/client/rpc/modules/CollectionManagementServiceImpl.java
  
  Index: CollectionManagementServiceImpl.java
  ===================================================================
  /*
   * 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 apache@apache.org.
   *
   * 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/05/07 13:14:40 jbates Exp $
   */
  package org.apache.xindice.client.rpc.modules;
  
  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.rpc.base.CommonConfigurable;
  import org.apache.xindice.client.rpc.base.CollectionImpl;
  
  /**
   * XML:DB CollectionManagementService implementation using XML-RPC to
   * communicate with Xindice.
   *
   * @author James Bates <ja...@amplexor.com>
   * @version 1.0
   */
  public class CollectionManagementServiceImpl extends CommonConfigurable
          implements CollectionManagementService {
  
      /* 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;
      }    
  }