vgritsenko    2003/08/15 20:47:36

  Modified:    java/src/org/apache/xindice/client/xmldb/xmlrpc
                        CollectionImpl.java DatabaseImpl.java
  Log:
  Initialize serviceLocation in DatabaseImpl, not CollectionImpl as this is 
global
  to database property.
  
  Revision  Changes    Path
  1.34      +15 -43    
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.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- CollectionImpl.java       16 Aug 2003 03:11:08 -0000      1.33
  +++ CollectionImpl.java       16 Aug 2003 03:47:36 -0000      1.34
  @@ -84,8 +84,8 @@
   import org.xmldb.api.modules.XMLResource;
   
   import javax.xml.parsers.DocumentBuilderFactory;
  -import java.io.StringReader;
   import java.io.IOException;
  +import java.io.StringReader;
   import java.net.MalformedURLException;
   import java.util.Hashtable;
   import java.util.Vector;
  @@ -103,11 +103,6 @@
       private static final Log log = LogFactory.getLog(CollectionImpl.class);
   
       /**
  -     * Default path to the XML-RPC service in the web server
  -     */
  -    private static final String XINDICE_SERVICE_LOCATION = "/xindice/";
  -
  -    /**
        * Host and port number of the database server
        */
       private String hostPort;
  @@ -143,34 +138,12 @@
   
           this.hostPort = hostPort;
           this.serviceLocation = serviceLocation;
  -
  -        /*
  -         * Determine the path in the web server to the XML-RPC service.
  -         * In priority order:
  -         *   DatabaseImpl service-location property
  -         *      (passed in the serviceLocation parameter)
  -         *   System property "xindice.xmlrpc.service-location"
  -         *   Default value "/xindice/"
  -         */
  -        if (serviceLocation == null) {
  -            serviceLocation = 
System.getProperty("xindice.xmlrpc.service-location");
  -        }
  -        if (serviceLocation == null) {
  -            serviceLocation = XINDICE_SERVICE_LOCATION;
  -        }
  -
  -        if (!serviceLocation.startsWith("/")) {
  -            serviceLocation = "/" + serviceLocation;
  -        }
  -        if (!serviceLocation.endsWith("/")) {
  -            serviceLocation = serviceLocation + "/";
  -        }
  -
  -        log.debug("serviceLocation=<" + serviceLocation + ">");
  -        String xmlrpcURI = "http://"; + hostPort + serviceLocation;
  -
  +        String xmlRpcURL = "http://"; + hostPort + serviceLocation;
           try {
  -            client = new XmlRpcClient(xmlrpcURI);
  +            if (log.isDebugEnabled()) {
  +                log.debug("Using URL: '" + "http://"; + hostPort + 
serviceLocation + "'");
  +            }
  +            client = new XmlRpcClient(xmlRpcURL);
   
               /* Just check the collection does actually exist */
               Hashtable params = new Hashtable();
  @@ -178,7 +151,8 @@
               String exists = (String) 
runRemoteCommand("GetCollectionConfiguration", params);
   
               if (!"yes".equals(exists)) {
  -                throw new XMLDBException(ErrorCodes.NO_SUCH_COLLECTION, 
"Collection not found: " + collPath);
  +                throw new XMLDBException(ErrorCodes.NO_SUCH_COLLECTION,
  +                                         "Collection not found: " + 
collPath);
               }
           } catch (MalformedURLException e) {
               client = null;
  @@ -188,11 +162,13 @@
           } catch (IOException e) {
               client = null;
               // TODO: What is appropriate error code?
  -            throw new XMLDBException(ErrorCodes.UNKNOWN_ERROR, "Cannot 
communicate with the server: " + xmlrpcURI, e);
  +            throw new XMLDBException(ErrorCodes.UNKNOWN_ERROR,
  +                                     "Cannot communicate with the server: " 
+ xmlRpcURL, e);
           } catch (Exception e) {
               client = null;
               // TODO: What is appropriate error code?
  -            throw new XMLDBException(ErrorCodes.NO_SUCH_COLLECTION, 
"Collection not found: " + collPath, e);
  +            throw new XMLDBException(ErrorCodes.NO_SUCH_COLLECTION,
  +                                     "Collection not found: " + collPath, e);
           }
       }
   
  @@ -300,14 +276,12 @@
       public void storeResource(Resource res) throws XMLDBException {
   
           if (!(res instanceof XMLResource)) {
  -
               throw new XMLDBException(ErrorCodes.INVALID_RESOURCE, "Only XML 
resources supported");
           }
  -
           if (res.getContent() == null) {
  -
               throw new XMLDBException(ErrorCodes.INVALID_RESOURCE, "no 
resource data");
           }
  +
           checkOpen();
           try {
   
  @@ -330,13 +304,11 @@
   
       /* see superclass for documentation */
       public boolean isOpen() {
  -
           return (client != null);
       }
   
       /* see superclass for documentation */
       public String getURI() {
  -
           return "xmldb:" + DatabaseImpl.DRIVER_NAME + "://" + hostPort + 
collPath;
       }
   
  
  
  
  1.17      +55 -18    
xml-xindice/java/src/org/apache/xindice/client/xmldb/xmlrpc/DatabaseImpl.java
  
  Index: DatabaseImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/src/org/apache/xindice/client/xmldb/xmlrpc/DatabaseImpl.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- DatabaseImpl.java 16 Aug 2003 03:11:08 -0000      1.16
  +++ DatabaseImpl.java 16 Aug 2003 03:47:36 -0000      1.17
  @@ -59,10 +59,9 @@
   
   package org.apache.xindice.client.xmldb.xmlrpc;
   
  -import org.apache.xindice.client.xmldb.CommonConfigurable;
  -
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  +import org.apache.xindice.client.xmldb.CommonConfigurable;
   import org.apache.xmlrpc.XmlRpc;
   
   import org.xmldb.api.base.Collection;
  @@ -95,6 +94,11 @@
       private static final String PROP_XMLRPC_DRIVER = "xmlrpc-driver";
   
       /**
  +     * System property name for the service location
  +     */
  +    private static final String SYSPROP_SERVICE_LOCATION = 
"xindice.xmlrpc.service-location";
  +
  +    /**
        * System property name for the SAX parser xml-rpc will use in case
        * there were no configuration property passed
        */
  @@ -106,6 +110,11 @@
       private static final String DEFAULT_XMLRPC_DRIVER = "xerces";
   
       /**
  +     * Default path to the XML-RPC service in the web server
  +     */
  +    private static final String DEFAULT_SERVICE_LOCATION = "/xindice/";
  +
  +    /**
        * Prefix used to denote XML:DB URI's that should use this driver
        */
       static String DRIVER_NAME = "xindice";
  @@ -121,6 +130,11 @@
       private static boolean xmlRpcInitialized;
   
       /**
  +     * Location of the XML-RPC service in the web server
  +     */
  +    private String serviceLocation;
  +
  +    /**
        * Create a new DatabaseImpl object.
        */
       public DatabaseImpl() throws XMLDBException {
  @@ -157,9 +171,10 @@
   
       /**
        * Initialize XML-RPC static properties: encoding, keep-alive, SAX 
driver.
  +     * Initialize XML-RPC service location.
        *
  -     * @throws XMLDBException if specified (or default, if none specified) 
SAX drvier
  -     * class could not be loaded
  +     * @throws XMLDBException if specified (or default, if none specified) 
SAX driver
  +     *         class could not be loaded
        */
       private void initialize() throws XMLDBException {
           synchronized(getClass()) {
  @@ -184,6 +199,9 @@
                   }
   
                   try {
  +                    if (log.isDebugEnabled()) {
  +                        log.debug("Using SAX Driver: '" + xmlrpcDriver + 
"'");
  +                    }
                       XmlRpc.setDriver(xmlrpcDriver);
                   } catch (Exception e) {
                       throw new XMLDBException(ErrorCodes.VENDOR_ERROR,
  @@ -193,6 +211,35 @@
   
               xmlRpcInitialized = true;
           }
  +
  +        if (this.serviceLocation == null) {
  +            /*
  +             * Determine the path in the web server to the XML-RPC service.
  +             * In priority order:
  +             *   DatabaseImpl service-location property
  +             *      (passed in the serviceLocation parameter)
  +             *   System property "xindice.xmlrpc.service-location"
  +             *   Default value "/xindice/"
  +             */
  +            serviceLocation = getProperty(PROP_SERVICE_LOCATION);
  +            if (serviceLocation == null) {
  +                serviceLocation = 
System.getProperty(SYSPROP_SERVICE_LOCATION);
  +                if (serviceLocation == null) {
  +                    serviceLocation = DEFAULT_SERVICE_LOCATION;
  +                }
  +            }
  +
  +            if (!serviceLocation.startsWith("/")) {
  +                serviceLocation = "/" + serviceLocation;
  +            }
  +            if (!serviceLocation.endsWith("/")) {
  +                serviceLocation = serviceLocation + "/";
  +            }
  +
  +            if (log.isDebugEnabled()) {
  +                log.debug("Using Service Location: '" + serviceLocation + 
"'");
  +            }
  +        }
       }
   
       /**
  @@ -241,20 +288,13 @@
           /* Absent host defaults to localhost and standard Xindice HTTP port 
*/
           if (hostPort.equals("")) {
               hostPort = "127.0.0.1:8888";
  -            if (log.isDebugEnabled()) {
  -                log.debug("Using default host and port: '"+hostPort+"'");
  -            }
  -        } else {
  -            if (log.isDebugEnabled()) {
  -                log.debug("Using host and port: '"+hostPort+"'");
  -            }
           }
   
  -        // Init XML-RPC in case it is not initialized yet
  +        // Init XML-RPC in case it is not initialized yet. Initialize 
serviceLocation
           initialize();
   
           try {
  -            return new CollectionImpl(hostPort, 
getProperty(PROP_SERVICE_LOCATION), collPath);
  +            return new CollectionImpl(hostPort, serviceLocation, collPath);
           } catch (XMLDBException e) {
               if (e.errorCode == ErrorCodes.NO_SUCH_COLLECTION) {
                   // per getCollection contract, return null if not found
  @@ -274,7 +314,6 @@
        *  specific errors that occur.<br />
        */
       public String getName() throws XMLDBException {
  -
           return DRIVER_NAME;
       }
   
  @@ -289,8 +328,6 @@
        *  specific errors that occur.<br />
        */
       public String getConformanceLevel() throws XMLDBException {
  -
           return CONFORMANCE_LEVEL;
       }
  -
   }
  
  
  

Reply via email to