vgritsenko 2003/12/14 10:02:15
Modified: . status.xml java/src/org/apache/xindice/client/xmldb/embed DatabaseImpl.java java/src/org/apache/xindice/client/xmldb DatabaseImpl.java Log: Properties PROP_XINDICE_CONFIGURATION, PROP_XINDICE_DB_HOME for embed driver can now be passed when driver is instantiated by org.apache.xindice.client.xmldb.DatabaseImpl Revision Changes Path 1.18 +5 -0 xml-xindice/status.xml Index: status.xml =================================================================== RCS file: /home/cvs/xml-xindice/status.xml,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- status.xml 13 Dec 2003 03:22:42 -0000 1.17 +++ status.xml 14 Dec 2003 18:02:14 -0000 1.18 @@ -61,6 +61,11 @@ <!-- Add new releases here --> <release version="1.1-dev" date="December 11 2003"> <action dev="VG" type="update"> + Properties PROP_XINDICE_CONFIGURATION, PROP_XINDICE_DB_HOME for + embed driver can now be passed when driver is instantiated by + org.apache.xindice.client.xmldb.DatabaseImpl + </action> + <action dev="VG" type="update"> Upgrade libraries: Xerces to version 2.6.0, Xalan to version 2.5.2. </action> <action dev="VG" type="fix" fixes-bug="21765"> 1.21 +53 -5 xml-xindice/java/src/org/apache/xindice/client/xmldb/embed/DatabaseImpl.java Index: DatabaseImpl.java =================================================================== RCS file: /home/cvs/xml-xindice/java/src/org/apache/xindice/client/xmldb/embed/DatabaseImpl.java,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- DatabaseImpl.java 19 Aug 2003 21:08:27 -0000 1.20 +++ DatabaseImpl.java 14 Dec 2003 18:02:14 -0000 1.21 @@ -108,13 +108,40 @@ * Creates new <code>DatabaseImpl</code> instance. The configuration is * loaded from the file defined in the PROP_XINDICE_CONFIGURATION system * variable. + */ + public DatabaseImpl() throws IOException, XindiceException { + init(); + } + + /** + * Create a new DatabaseImpl object with a copy of the properties + * from the DatabaseImpl parameter. + * + * This allows to pass properties such as PROP_XINDICE_CONFIGURATION + * to this instance. Usually this is done by instantiating not this + * class, but <code>org.apache.xindice.client.xmldb.DatabaseImpl</code>, + * set all the necessary parameters, and then get a collection. + * + * @param config from which the initial parameters for this + * DatabaseImpl object are copied. + */ + public DatabaseImpl(CommonConfigurable config) throws IOException, XindiceException { + super(config); + init(); + } + + /** + * Init this database instance. * * This is only a temporarly solution since the question of a new init * method is raised in the xmldb:api group. Another solution could be to * use the Configurable interface and only create the database when the * getCollection method is called. + * + * @throws IOException + * @throws XindiceException */ - public DatabaseImpl() throws IOException, XindiceException { + private void init() throws IOException, XindiceException { Configuration config = loadConfiguration(); this.database = Database.getDatabase(config); @@ -131,7 +158,18 @@ protected Configuration loadConfiguration() throws IOException, XindiceException { Configuration config; String configDir = null; - String configFile = System.getProperty(Xindice.PROP_XINDICE_CONFIGURATION); + + String configFile = null; + try { + // Try configuration first + configFile = getProperty(Xindice.PROP_XINDICE_CONFIGURATION); + } catch (XMLDBException ignored) { + } + if (configFile == null) { + // Fallback to system property + configFile = System.getProperty(Xindice.PROP_XINDICE_CONFIGURATION); + } + if (configFile != null && !configFile.equals("")) { if (log.isInfoEnabled()) { log.info("Specified configuration file: '" + configFile + "'"); @@ -153,7 +191,17 @@ String dbRoot = config.getAttribute(Database.DBROOT, Database.DBROOT_DEFAULT); if (!new File(dbRoot).isAbsolute()) { // Let's see if the property was specified. - String home = System.getProperty(Xindice.PROP_XINDICE_DB_HOME); + String home = null; + try { + // Try configuration first + home = getProperty(Xindice.PROP_XINDICE_DB_HOME); + } catch (XMLDBException ignored) { + } + if (home == null) { + // Fallback to system property + home = System.getProperty(Xindice.PROP_XINDICE_DB_HOME); + } + if (home != null) { dbRoot = new File(home + File.separator + dbRoot).getCanonicalPath(); } else if (configDir != null) { 1.23 +4 -5 xml-xindice/java/src/org/apache/xindice/client/xmldb/DatabaseImpl.java Index: DatabaseImpl.java =================================================================== RCS file: /home/cvs/xml-xindice/java/src/org/apache/xindice/client/xmldb/DatabaseImpl.java,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- DatabaseImpl.java 13 Aug 2003 03:10:54 -0000 1.22 +++ DatabaseImpl.java 14 Dec 2003 18:02:14 -0000 1.23 @@ -156,7 +156,6 @@ public org.xmldb.api.base.Collection getCollection(String uri, String username, String password) throws XMLDBException { createDriver(uri); - return driver.getCollection(uri, username, password); } @@ -191,7 +190,7 @@ */ public boolean acceptsURI(String uri) throws XMLDBException { if (uri != null && uri.length() > 0 && knownPrefix(uri)) { - // ensure the driver is initialised + // Ensure the driver is initialised createDriver(uri); return driver.acceptsURI(uri); } @@ -214,7 +213,7 @@ */ driver = new org.apache.xindice.client.xmldb.xmlrpc.DatabaseImpl(this); } else if (uri.startsWith(EMBED_URI)) { - driver = new org.apache.xindice.client.xmldb.embed.DatabaseImpl(); + driver = new org.apache.xindice.client.xmldb.embed.DatabaseImpl(this); } else if (uri.startsWith(MANAGED_URI)) { driver = new ManagedDatabaseImpl(); }