kstaken     2002/07/10 01:55:56

  Modified:    java/scratchpad/src/org/apache/xindice/client/rpc/base
                        CollectionImpl.java DatabaseImpl.java
               java/scratchpad/src/org/apache/xindice/client/rpc/modules
                        CollectionManagementServiceImpl.java
                        XMLResourceImpl.java
               java/scratchpad/src/org/apache/xindice/server/rpc
                        RPCDefaultMessage.java
               java/scratchpad/src/org/apache/xindice/server/rpc/messages
                        RemoveCollection.java
               java/scratchpad/tests/src CollectionTest.java
                        XMLRPCAPITestCase.java
               java/src/org/apache/xindice/client/xmldb/resources
                        XMLResourceImpl.java
               java/src/org/apache/xindice/core CollectionManager.java
  Log:
  Fixing XML-RPC based XML:DB API so it passes the API test suite.
  
  Revision  Changes    Path
  1.4       +20 -33    
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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- CollectionImpl.java       7 May 2002 13:14:39 -0000       1.3
  +++ CollectionImpl.java       10 Jul 2002 08:55:55 -0000      1.4
  @@ -139,7 +139,7 @@
               
               throw new XMLDBException(ErrorCodes.VENDOR_ERROR, "Xerces 
needed");
           }
  -        
  +     
           try {
               
               client = new XmlRpcClient(xmlrpcURI);
  @@ -152,7 +152,7 @@
               
               throw new XMLDBException(ErrorCodes.INVALID_URI);
           } catch (Exception e) {
  -            
  +            e.printStackTrace();
               throw new XMLDBException(ErrorCodes.NO_SUCH_COLLECTION, 
collPath);
           }
           
  @@ -171,15 +171,15 @@
                   servicesMap.put(s.getName() + s.getVersion(), s);
               } catch (InstantiationException e) {
               
  -                throw new XMLDBException(ErrorCodes.VENDOR_ERROR, "Coudln't 
create "
  +                throw new XMLDBException(ErrorCodes.VENDOR_ERROR, "Couldn't 
create "
                          + serviceClassesMap[i] + " service: " + 
e.getMessage());
               } catch (ClassNotFoundException e) {
                   
  -                throw new XMLDBException(ErrorCodes.VENDOR_ERROR, "Coudln't 
create "
  +                throw new XMLDBException(ErrorCodes.VENDOR_ERROR, "Couldn't 
create "
                          + serviceClassesMap[i] + " service: " + 
e.getMessage());
               } catch (IllegalAccessException e) {
                   
  -                throw new XMLDBException(ErrorCodes.VENDOR_ERROR, "Coudln't 
create "
  +                throw new XMLDBException(ErrorCodes.VENDOR_ERROR, "Couldn't 
create "
                          + serviceClassesMap[i] + " service: " + 
e.getMessage());
               }
           } 
  @@ -221,9 +221,6 @@
        *
        * @param resourceName resource name
        * @return the resource
  -     * @exception XMLDBException thrown if there is no resource named
  -     *            <code>resourceName</code> or if some other error condition
  -     *            occurs.
        */
       public Resource getResource(String resourceName) throws XMLDBException {
   
  @@ -238,8 +235,7 @@
               
               return new XMLResourceImpl(resourceName, xml, this);
           } catch (Exception e) {
  -            
  -            throw new XMLDBException(ErrorCodes.NO_SUCH_RESOURCE, 
e.getMessage());
  +            return null;
           }
       }
       
  @@ -257,7 +253,7 @@
               
               Hashtable params = new Hashtable();
               params.put(RPCDefaultMessage.COLLECTION, collPath);
  -            return ((Long) runRemoteCommand(
  +            return ((Integer) runRemoteCommand(
                       "GetDocumentCount", params)).intValue();
           } catch (Exception e) {
               
  @@ -306,16 +302,10 @@
        *
        * @param name service name
        * @param version service version
  -     * @exception XMLDBException thrown if no mactching service
  -     *            could be located.
        */
       public Service getService(String name, String version) throws 
XMLDBException {
           
           Service s = (Service) servicesMap.get(name + version);
  -        if (s == null) {
  -            
  -            throw new XMLDBException(ErrorCodes.NO_SUCH_SERVICE);
  -        }
           
           return s;
       }
  @@ -439,6 +429,10 @@
        * @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) {
               
  @@ -452,11 +446,6 @@
                       "only XMLResources supported");
           }
           
  -        if (name == null) {
  -            
  -            name = "";
  -        }
  -        
           return new XMLResourceImpl(name, this);
       }
       
  @@ -468,13 +457,12 @@
        *            has no parent), or in case of some other unknown error.
        */
       public Collection getParentCollection() throws XMLDBException {
  -        
  -        if (collPath == "/") {
  -            
  -            throw new XMLDBException(ErrorCodes.NO_SUCH_COLLECTION,
  -                    "root collection has no parent");
  +
  +        // If there's only one slash then it's the root.
  +        if (collPath.lastIndexOf("/") == 0) {
  +            return null;            
           }
  -        
  +  
           return new CollectionImpl(hostPort, collPath.substring(0,
                   collPath.lastIndexOf('/')));
       }
  @@ -504,8 +492,7 @@
               params.put(RPCDefaultMessage.COLLECTION, collPath);
               params.put(RPCDefaultMessage.NAME, resource.getId());
               runRemoteCommand("RemoveDocument", params);
  -        } catch (Exception e) {
  -            
  +        } catch (Exception e) {            
               throw new XMLDBException(ErrorCodes.NO_SUCH_RESOURCE, 
e.getMessage());
           }
       }
  @@ -545,10 +532,10 @@
               
               Hashtable params = new Hashtable();
               params.put(RPCDefaultMessage.COLLECTION, collPath);
  -            return ((Long) runRemoteCommand("GetCollectionsCount", 
params)).intValue();
  +            Integer result = (Integer) 
runRemoteCommand("GetCollectionCount", params);
  +            return result.intValue();
               
           } catch (Exception e) {
  -            
               throw new XMLDBException(ErrorCodes.UNKNOWN_ERROR, 
e.getMessage());
           }   
       }
  
  
  
  1.2       +4 -4      
xml-xindice/java/scratchpad/src/org/apache/xindice/client/rpc/base/DatabaseImpl.java
  
  Index: DatabaseImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/scratchpad/src/org/apache/xindice/client/rpc/base/DatabaseImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DatabaseImpl.java 6 May 2002 14:43:02 -0000       1.1
  +++ DatabaseImpl.java 10 Jul 2002 08:55:55 -0000      1.2
  @@ -135,10 +135,10 @@
           String hostPort = xmldbURI.substring(0, firstSlash);
           String collPath = xmldbURI.substring(firstSlash);
   
  -        /* Absent host defaults to localhost and standard HTTP port */
  +        /* Absent host defaults to localhost and standard Xindice HTTP port 
*/
           if (hostPort.equals("")) {
  -            
  -            hostPort = "127.0.0.1";
  +
  +            hostPort = "127.0.0.1:4080";
           }
           
           return new CollectionImpl(hostPort, collPath);
  
  
  
  1.2       +2 -3      
xml-xindice/java/scratchpad/src/org/apache/xindice/client/rpc/modules/CollectionManagementServiceImpl.java
  
  Index: CollectionManagementServiceImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/scratchpad/src/org/apache/xindice/client/rpc/modules/CollectionManagementServiceImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CollectionManagementServiceImpl.java      7 May 2002 13:14:40 -0000       
1.1
  +++ CollectionManagementServiceImpl.java      10 Jul 2002 08:55:55 -0000      
1.2
  @@ -118,8 +118,7 @@
        * @param childCollName name of child collection to remove
        */
       public void removeCollection(String childCollName) throws XMLDBException 
{
  -        
  -         if (coll == null) {
  +        if (coll == null) {
               
               throw new XMLDBException(ErrorCodes.INVALID_COLLECTION,
                   "Must set collection for this service");
  
  
  
  1.2       +3 -5      
xml-xindice/java/scratchpad/src/org/apache/xindice/client/rpc/modules/XMLResourceImpl.java
  
  Index: XMLResourceImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/scratchpad/src/org/apache/xindice/client/rpc/modules/XMLResourceImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XMLResourceImpl.java      6 May 2002 14:43:02 -0000       1.1
  +++ XMLResourceImpl.java      10 Jul 2002 08:55:55 -0000      1.2
  @@ -69,6 +69,7 @@
   import org.xml.sax.InputSource;
   import java.io.StringReader;
   import org.xmldb.api.base.ErrorCodes;
  +import org.xmldb.api.sdk.modules.SetContentHandler;
   import org.xml.sax.XMLReader;
   import org.xml.sax.helpers.DefaultHandler;
   import org.apache.xindice.xml.TextWriter;
  @@ -128,10 +129,7 @@
       
       public org.xml.sax.ContentHandler setContentAsSAX() throws 
org.xmldb.api.base.XMLDBException {
           
  -        /* TODO: return string serializer that sets content in
  -         * <code>endDocument</code>
  -         */
  -        return null;
  +        return new SetContentHandler(this);
       }
       
       public Object getContent() {
  
  
  
  1.6       +6 -1      
xml-xindice/java/scratchpad/src/org/apache/xindice/server/rpc/RPCDefaultMessage.java
  
  Index: RPCDefaultMessage.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/scratchpad/src/org/apache/xindice/server/rpc/RPCDefaultMessage.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- RPCDefaultMessage.java    11 Jun 2002 01:21:04 -0000      1.5
  +++ RPCDefaultMessage.java    10 Jul 2002 08:55:56 -0000      1.6
  @@ -101,6 +101,11 @@
       * @author kstaken
       */
      protected Collection getCollection( String name ) throws Exception {
  +      // 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
  
  
  
  1.4       +8 -3      
xml-xindice/java/scratchpad/src/org/apache/xindice/server/rpc/messages/RemoveCollection.java
  
  Index: RemoveCollection.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/scratchpad/src/org/apache/xindice/server/rpc/messages/RemoveCollection.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- RemoveCollection.java     11 Jun 2002 01:26:02 -0000      1.3
  +++ RemoveCollection.java     10 Jul 2002 08:55:56 -0000      1.4
  @@ -76,11 +76,16 @@
   
      public Hashtable execute(Hashtable message) throws Exception {
   
  -      if(!message.containsKey(COLLECTION)) {
  +      if ( ! message.containsKey(COLLECTION) ) {
            throw new Exception(MISSING_COLLECTION_PARAM);
         }
   
  -      Collection col = getCollection( (String) message.get(COLLECTION) );
  +      if ( ! message.containsKey(NAME) ) {
  +         throw new Exception(MISSING_NAME_PARAM);
  +      }
  +      
  +      Collection col = getCollection( (String) message.get(COLLECTION)
  +                                      + "/" + (String) message.get(NAME));
         col.dropCollection( col );
   
         Hashtable result = new Hashtable();
  
  
  
  1.5       +2 -1      xml-xindice/java/scratchpad/tests/src/CollectionTest.java
  
  Index: CollectionTest.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/scratchpad/tests/src/CollectionTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- CollectionTest.java       18 Jun 2002 03:36:41 -0000      1.4
  +++ CollectionTest.java       10 Jul 2002 08:55:56 -0000      1.5
  @@ -232,6 +232,7 @@
         try {
            result = (Hashtable) client.execute("run", params);
         } catch(Exception e) {
  +          System.out.println("Error");
            fail( e.getMessage() );
         }
   
  
  
  
  1.4       +3 -2      
xml-xindice/java/scratchpad/tests/src/XMLRPCAPITestCase.java
  
  Index: XMLRPCAPITestCase.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/scratchpad/tests/src/XMLRPCAPITestCase.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XMLRPCAPITestCase.java    12 Jun 2002 02:12:25 -0000      1.3
  +++ XMLRPCAPITestCase.java    10 Jul 2002 08:55:56 -0000      1.4
  @@ -139,7 +139,8 @@
         Hashtable message = new Hashtable();
   
         message.put("message", "RemoveCollection");
  -      message.put("collection", "/" + INSTANCE_NAME + "/" + 
TEST_COLLECTION_NAME + "/" + collection);
  +      message.put("collection", "/" + INSTANCE_NAME + "/" + 
TEST_COLLECTION_NAME);
  +      message.put("name", collection);
   
         Vector params = new Vector();
   
  
  
  
  1.2       +2 -2      
xml-xindice/java/src/org/apache/xindice/client/xmldb/resources/XMLResourceImpl.java
  
  Index: XMLResourceImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/src/org/apache/xindice/client/xmldb/resources/XMLResourceImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XMLResourceImpl.java      6 Dec 2001 19:33:54 -0000       1.1
  +++ XMLResourceImpl.java      10 Jul 2002 08:55:56 -0000      1.2
  @@ -78,7 +78,7 @@
    * XMLResourceImpl provides an implementation to handle XML resources and
    * convert easily between Text, DOM or SAX presentations.
    * <p />
  - * Note: SAX is not yet implemented.
  + *
    */
   public class XMLResourceImpl
      implements org.xmldb.api.modules.XMLResource {
  
  
  
  1.3       +2 -2      
xml-xindice/java/src/org/apache/xindice/core/CollectionManager.java
  
  Index: CollectionManager.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/src/org/apache/xindice/core/CollectionManager.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CollectionManager.java    30 Apr 2002 13:10:14 -0000      1.2
  +++ CollectionManager.java    10 Jul 2002 08:55:56 -0000      1.3
  @@ -110,7 +110,7 @@
       * @param path The Collection path
       * @return The Collection (or null)
       */
  -   public Collection getCollection(String path) throws DBException {
  +   public Collection getCollection(String path) throws DBException {     
         if ( path.indexOf("/") != -1 ) {
            CollectionManager cm = this;
            StringTokenizer st = new StringTokenizer(path, "/");
  
  
  

Reply via email to