vgritsenko 2003/08/15 20:11:08
Modified: java/src/org/apache/xindice/client/xmldb/xmlrpc
CollectionImpl.java DatabaseImpl.java
Log:
Configure static properties of class XmlRpc once. No reason
to configure it on per collection basis.
Revision Changes Path
1.33 +19 -38
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.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- CollectionImpl.java 13 Aug 2003 18:51:15 -0000 1.32
+++ CollectionImpl.java 16 Aug 2003 03:11:08 -0000 1.33
@@ -72,7 +72,6 @@
import org.apache.xindice.xml.TextWriter;
import org.apache.xindice.xml.dom.DOMParser;
import org.apache.xindice.xml.dom.DocumentImpl;
-import org.apache.xmlrpc.XmlRpc;
import org.apache.xmlrpc.XmlRpcClient;
import org.w3c.dom.Document;
@@ -103,19 +102,24 @@
private static final Log log = LogFactory.getLog(CollectionImpl.class);
- /* path to XML-RPC service on database */
- private static String XINDICE_SERVICE_LOCATION = "/xindice/";
+ /**
+ * Default path to the XML-RPC service in the web server
+ */
+ private static final String XINDICE_SERVICE_LOCATION = "/xindice/";
- /* host and port number of server */
+ /**
+ * Host and port number of the database server
+ */
private String hostPort;
- /* location of the XML-RPC service in the web server */
+ /**
+ * Location of the XML-RPC service in the web server
+ */
private String serviceLocation;
- /* SAX parser the XML-RPC service will use */
- private String xmlrpcDriver;
-
- /* the XML-RPC client stub, connected to server */
+ /**
+ * The XML-RPC client stub, connected to the server
+ */
private XmlRpcClient client = null;
/**
@@ -134,34 +138,11 @@
* because of URL syntax errors, or connection failure, or if
no
* collection with path <code>collPath</code> could be
located.
*/
- public CollectionImpl(String hostPort, String serviceLocation, String
xmlrpcDriver, String collPath) throws XMLDBException {
+ public CollectionImpl(String hostPort, String serviceLocation, String
collPath) throws XMLDBException {
super(collPath);
+
this.hostPort = hostPort;
this.serviceLocation = serviceLocation;
- this.xmlrpcDriver = xmlrpcDriver;
-
- XmlRpc.setEncoding("UTF8");
-
- /*
- * Determine the SAXparser the xmlrpc client will use.
- * In priority order:
- * DatabaseImpl xmlrpc-driver property
- * (passed in the xmlrpcDriver parameter)
- * System property "xindice.xmlrpc.driver"
- * Default value "xerces"
- */
- if (xmlrpcDriver == null) {
- xmlrpcDriver = System.getProperty("xindice.xmlrpc.driver");
- }
- if (xmlrpcDriver == null) {
- xmlrpcDriver = "xerces";
- }
- XmlRpc.setKeepAlive(true);
- try {
- XmlRpc.setDriver(xmlrpcDriver);
- } catch (Exception e) {
- throw new XMLDBException(ErrorCodes.VENDOR_ERROR, "Xerces
needed", e);
- }
/*
* Determine the path in the web server to the XML-RPC service.
@@ -379,7 +360,7 @@
}
try {
- return new CollectionImpl(hostPort, serviceLocation,
xmlrpcDriver, collPath + "/" + name);
+ return new CollectionImpl(hostPort, serviceLocation, collPath +
"/" + name);
} catch (XMLDBException e) {
if (e.errorCode == ErrorCodes.NO_SUCH_COLLECTION) {
@@ -453,7 +434,7 @@
}
try {
- return new CollectionImpl(hostPort, serviceLocation,
xmlrpcDriver, collPath.substring(0, collPath.lastIndexOf('/')));
+ return new CollectionImpl(hostPort, serviceLocation,
collPath.substring(0, collPath.lastIndexOf('/')));
} catch (XMLDBException e) {
if (e.errorCode == ErrorCodes.NO_SUCH_COLLECTION) {
// per getParentCollection contract, return null if no parent
1.16 +79 -15
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.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- DatabaseImpl.java 9 Aug 2003 02:44:23 -0000 1.15
+++ DatabaseImpl.java 16 Aug 2003 03:11:08 -0000 1.16
@@ -63,6 +63,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.xmlrpc.XmlRpc;
+
import org.xmldb.api.base.Collection;
import org.xmldb.api.base.Database;
import org.xmldb.api.base.ErrorCodes;
@@ -83,30 +85,45 @@
private static final Log log = LogFactory.getLog(DatabaseImpl.class);
/**
- * Prefix used to denote XML:DB URI's that should use this driver
+ * Property name for the xml-rpc service location.
*/
- static String DRIVER_NAME = "xindice";
+ private static final String PROP_SERVICE_LOCATION = "service-location";
/**
- * XML:DB conformance level of this driver
+ * Property name for the SAX parser xml-rpc will use.
*/
- private String CONFORMANCE_LEVEL = "0";
+ private static final String PROP_XMLRPC_DRIVER = "xmlrpc-driver";
/**
- * Property name for the xml-rpc service location.
+ * System property name for the SAX parser xml-rpc will use in case
+ * there were no configuration property passed
*/
- private static final String PROP_SERVICE_LOCATION = "service-location";
+ private static final String SYSPROP_XMLRPC_DRIVER =
"xindice.xmlrpc.driver";
/**
- * Property name for the SAX parser xml-rpc will use.
+ * Default value of the xmlrpc-driver property
*/
- private static final String PROP_XMLRPC_DRIVER = "xmlrpc-driver";
+ private static final String DEFAULT_XMLRPC_DRIVER = "xerces";
+
+ /**
+ * Prefix used to denote XML:DB URI's that should use this driver
+ */
+ static String DRIVER_NAME = "xindice";
+
+ /**
+ * XML:DB conformance level of this driver
+ */
+ private String CONFORMANCE_LEVEL = "0";
+ /**
+ * Ensures that XML-RPC initialized just once
+ */
+ private static boolean xmlRpcInitialized;
/**
* Create a new DatabaseImpl object.
*/
- public DatabaseImpl() {
+ public DatabaseImpl() throws XMLDBException {
super();
}
@@ -114,11 +131,11 @@
* Create a new DatabaseImpl object with a copy of the properties
* from the DatabaseImpl parameter.
*
- * @param commonConfigurable from which the initial parameters for this
+ * @param config from which the initial parameters for this
* DatabaseImpl object are copied.
*/
- public DatabaseImpl(CommonConfigurable commonConfigurable) {
- super(commonConfigurable);
+ public DatabaseImpl(CommonConfigurable config) throws XMLDBException {
+ super(config);
}
/**
@@ -139,6 +156,46 @@
}
/**
+ * Initialize XML-RPC static properties: encoding, keep-alive, SAX
driver.
+ *
+ * @throws XMLDBException if specified (or default, if none specified)
SAX drvier
+ * class could not be loaded
+ */
+ private void initialize() throws XMLDBException {
+ synchronized(getClass()) {
+ if (!xmlRpcInitialized) {
+ XmlRpc.setEncoding("UTF8");
+ XmlRpc.setKeepAlive(true);
+
+ /*
+ * Determine the SAXparser the xmlrpc client will use.
+ * In priority order:
+ * DatabaseImpl xmlrpc-driver property
+ * (passed in the xmlrpcDriver parameter)
+ * System property "xindice.xmlrpc.driver"
+ * Default value "xerces"
+ */
+ String xmlrpcDriver = getProperty(PROP_XMLRPC_DRIVER);
+ if (xmlrpcDriver == null) {
+ xmlrpcDriver = System.getProperty(SYSPROP_XMLRPC_DRIVER);
+ if (xmlrpcDriver == null) {
+ xmlrpcDriver = DEFAULT_XMLRPC_DRIVER;
+ }
+ }
+
+ try {
+ XmlRpc.setDriver(xmlrpcDriver);
+ } catch (Exception e) {
+ throw new XMLDBException(ErrorCodes.VENDOR_ERROR,
+ "SAX Driver " + xmlrpcDriver +
" is not available", e);
+ }
+ }
+
+ xmlRpcInitialized = true;
+ }
+ }
+
+ /**
* Retrieves a <code>Collection</code> instance based on the URI provided
* in the <code>uri</code> parameter. The format of the URI is defined
in the
* documentation for DatabaseManager.getCollection().<p/>
@@ -187,10 +244,17 @@
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
+ initialize();
+
try {
- return new CollectionImpl(hostPort,
getProperty(PROP_SERVICE_LOCATION), getProperty(PROP_XMLRPC_DRIVER), collPath);
+ return new CollectionImpl(hostPort,
getProperty(PROP_SERVICE_LOCATION), collPath);
} catch (XMLDBException e) {
if (e.errorCode == ErrorCodes.NO_SUCH_COLLECTION) {
// per getCollection contract, return null if not found