kevinross 2003/07/10 14:42:48
Modified: java/src/org/apache/xindice/client/xmldb/embed
DatabaseImpl.java
Log:
formatting, organize imports
Revision Changes Path
1.10 +159 -156
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.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- DatabaseImpl.java 9 Jul 2003 16:35:12 -0000 1.9
+++ DatabaseImpl.java 10 Jul 2003 21:42:48 -0000 1.10
@@ -88,181 +88,184 @@
*/
public class DatabaseImpl extends CommonConfigurable implements
org.xmldb.api.base.Database {
- private static Log log =
LogFactory.getLog("org.apache.xindice.client.embed");
+ private static Log log =
LogFactory.getLog("org.apache.xindice.client.embed");
- /* prefix used to denote XML:DB URI's that should use this driver */
- static String DRIVER_NAME = "xindice-embed";
-
- /* XML:DB conformance level of this driver */
- private String CONFORMANCE_LEVEL = "0";
-
- protected Database db;
-
- /**
- * Creates new <code>DatabaseImpl</code> instance. The configuration is
- * loaded from the file defined in the PROP_XINDICE_CONFIGURATION system
- * variable.
- *
- * 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.
- */
- public DatabaseImpl() throws FileNotFoundException, XindiceException {
- Configuration config;
- config = loadConfiguration();
+ /* prefix used to denote XML:DB URI's that should use this driver */
+ static String DRIVER_NAME = "xindice-embed";
+
+ /* XML:DB conformance level of this driver */
+ private String CONFORMANCE_LEVEL = "0";
+ protected Database db;
+
+ /**
+ * Creates new <code>DatabaseImpl</code> instance. The configuration is
+ * loaded from the file defined in the PROP_XINDICE_CONFIGURATION system
+ * variable.
+ *
+ * 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.
+ */
+ public DatabaseImpl() throws FileNotFoundException, XindiceException {
+
+ Configuration config = loadConfiguration();
this.db = Database.getDatabase(config);
if (null == this.db) {
log.fatal("Unable to configure database");
throw new XindiceException("Unable to configure
database");
- } else if (log.isInfoEnabled()) {
+ }
+ else if (log.isInfoEnabled()) {
log.info("Database name: '" + this.db.getName() + "'");
}
}
protected Configuration loadConfiguration() throws
FileNotFoundException, XindiceException, ReadOnlyException {
Configuration config;
- String configFile =
System.getProperty(Xindice.PROP_XINDICE_CONFIGURATION);
- if (configFile != null && !configFile.equals("")) {
- if (log.isInfoEnabled()) {
- log.info("Specified configuration file: '" + configFile + "'");
- }
- FileInputStream configXMLFile = new FileInputStream(new
File(configFile));
-
- config = new Configuration(DOMParser.toDocument(configXMLFile),
false);
- } else {
- if (log.isInfoEnabled()) {
- log.info("No configuration file specified, going with the
default configuration");
- }
- config = new
Configuration(DOMParser.toDocument(Xindice.DEFAULT_CONFIGURATION), false);
- }
+ String configFile =
System.getProperty(Xindice.PROP_XINDICE_CONFIGURATION);
+ if (configFile != null && !configFile.equals("")) {
+ if (log.isInfoEnabled()) {
+ log.info("Specified configuration file: '" +
configFile + "'");
+ }
+ FileInputStream configXMLFile = new FileInputStream(new
File(configFile));
+
+ config = new
Configuration(DOMParser.toDocument(configXMLFile), false);
+ }
+ else {
+ if (log.isInfoEnabled()) {
+ log.info("No configuration file specified,
going with the default configuration");
+ }
+ config = new
Configuration(DOMParser.toDocument(Xindice.DEFAULT_CONFIGURATION), false);
+ }
- config = config.getChild("root-collection", false);
+ config = config.getChild("root-collection", false);
return config;
- }
+ }
+
+ /**
+ * Determines whether this <code>Database</code> implementation can
handle
+ * the URI. It should return true if the Database instance knows how to
+ * handle the URI and false otherwise.
+ *
+ * @param uri the URI to check for.
+ * @return true if the URI can be handled, false otherwise.
+ * @exception XMLDBException with expected error codes.<br />
+ * <code>ErrorCodes.VENDOR_ERROR</code> for any vendor
+ * specific errors that occur.<br />
+ * <code>ErrroCodes.INVALID_URI</code> If the URI is not in a valid
format. <br />
+ */
+ public boolean acceptsURI(String uri) throws XMLDBException {
- /**
- * Determines whether this <code>Database</code> implementation can
handle
- * the URI. It should return true if the Database instance knows how to
- * handle the URI and false otherwise.
- *
- * @param uri the URI to check for.
- * @return true if the URI can be handled, false otherwise.
- * @exception XMLDBException with expected error codes.<br />
- * <code>ErrorCodes.VENDOR_ERROR</code> for any vendor
- * specific errors that occur.<br />
- * <code>ErrroCodes.INVALID_URI</code> If the URI is not in a valid
format. <br />
- */
- public boolean acceptsURI(String uri) throws XMLDBException {
-
- return ((uri != null) && uri.startsWith(getName() + "://"));
- }
-
- /**
- * 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/>
- *
- * Authentication is handled via username and password however it is not
- * required that the database support authentication. Databases that do
not
- * support authentication MUST ignore the
- * <code>username</code> and <code>password</code> if those provided are
not
- * null.
- *
- * @param uri the URI to use to locate the collection.
- * @param password The password to use for authentication to the database
or
- * null if the database does not support authentication.
- * @return A <code>Collection</code> instance for the requested
collection or
- * null if the collection could not be found.
- * @return The <code>Collection</code> instance
- * @exception XMLDBException with expected error codes.<br />
- * <code>ErrorCodes.VENDOR_ERROR</code> for any vendor
- * specific errors that occur.<br />
- * <code>ErrroCodes.INVALID_URI</code> If the URI is not in a valid
format. <br />
- * <code>ErrroCodes.PERMISSION_DENIED</code> If the <code>username</code>
- * and <code>password</code> were not accepted by the database.
- */
+ return ((uri != null) && uri.startsWith(getName() + "://"));
+ }
+
+ /**
+ * 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/>
+ *
+ * Authentication is handled via username and password however it is not
+ * required that the database support authentication. Databases that do
not
+ * support authentication MUST ignore the
+ * <code>username</code> and <code>password</code> if those provided
are not
+ * null.
+ *
+ * @param uri the URI to use to locate the collection.
+ * @param password The password to use for authentication to the
database or
+ * null if the database does not support authentication.
+ * @return A <code>Collection</code> instance for the requested
collection or
+ * null if the collection could not be found.
+ * @return The <code>Collection</code> instance
+ * @exception XMLDBException with expected error codes.<br />
+ * <code>ErrorCodes.VENDOR_ERROR</code> for any vendor
+ * specific errors that occur.<br />
+ * <code>ErrroCodes.INVALID_URI</code> If the URI is not in a valid
format. <br />
+ * <code>ErrroCodes.PERMISSION_DENIED</code> If the
<code>username</code>
+ * and <code>password</code> were not accepted by the database.
+ */
public Collection getCollection(String uri, String userName, String
password) throws XMLDBException {
- /* TODO: introduce authentication some day */
-
- if (!acceptsURI(uri)) {
+ /* TODO: introduce authentication some day */
+
+ if (!acceptsURI(uri)) {
throw new XMLDBException(ErrorCodes.INVALID_URI,
"Invalid URL: " + uri);
- }
+ }
+
+ /* Chop off driver prefix, and '://' */
+ uri = uri.substring(getName().length() + 3);
+
+ /* Extract host name & port, if present */
+ int firstSlash = uri.indexOf('/');
+ if (firstSlash == -1) {
+ throw new XMLDBException(ErrorCodes.INVALID_URI);
+ }
+
+ String collPath = uri.substring(firstSlash);
- /* Chop off driver prefix, and '://' */
- uri = uri.substring(getName().length() + 3);
-
- /* Extract host name & port, if present */
- int firstSlash = uri.indexOf('/');
- if (firstSlash == -1) {
- throw new XMLDBException(ErrorCodes.INVALID_URI);
- }
-
- String collPath = uri.substring(firstSlash);
-
- // The path must start with a /
- if ( collPath.startsWith( "/" ) ) {
- // find the database name. We just skip the first slash
- int colIndex = collPath.indexOf( '/', 1 );
-
- // We assume there's no collection specified
- String dbName = collPath.substring( 1 );
- String colName = "/";
-
- // if colIndex isn't -1 then we need to pick out the db and
collection
- if ( colIndex != -1 ) {
- dbName = collPath.substring( 1, colIndex );
-
- // The rest of the name locates the collection
- colName = collPath.substring( colIndex );
- }
-
- if ( colName.equals("") ) {
- colName = "/";
- }
-
- try {
- return new CollectionImpl(db, colName);
- } catch (XMLDBException e) {
- if(e.errorCode == ErrorCodes.NO_SUCH_COLLECTION) {
- // per getCollection contract, return null if not found
- return null;
- }
- throw e;
- }
- } else {
+ // The path must start with a /
+ if (collPath.startsWith("/")) {
+ // find the database name. We just skip the first slash
+ int colIndex = collPath.indexOf('/', 1);
+
+ // We assume there's no collection specified
+ String dbName = collPath.substring(1);
+ String colName = "/";
+
+ // if colIndex isn't -1 then we need to pick out the db
and collection
+ if (colIndex != -1) {
+ dbName = collPath.substring(1, colIndex);
+
+ // The rest of the name locates the collection
+ colName = collPath.substring(colIndex);
+ }
+
+ if (colName.equals("")) {
+ colName = "/";
+ }
+
+ try {
+ return new CollectionImpl(db, colName);
+ }
+ catch (XMLDBException e) {
+ if (e.errorCode ==
ErrorCodes.NO_SUCH_COLLECTION) {
+ // per getCollection contract, return
null if not found
+ return null;
+ }
+ throw e;
+ }
+ }
+ else {
throw new XMLDBException(ErrorCodes.INVALID_URI,
"Collection name must begin with a '/'");
- }
- }
+ }
+ }
+
+ /**
+ * Returns the prefix used in XML:DB to denote URI's that this driver
can
+ * handle.
+ *
+ * @return the prefix driver name
+ * @exception XMLDBException with expected error codes.<br />
+ * <code>ErrorCodes.VENDOR_ERROR</code> for any vendor
+ * specific errors that occur.<br />
+ */
+ public String getName() throws XMLDBException {
+ return DRIVER_NAME;
+ }
+
+ /**
+ * Returns the XML:DB API Conformance level for the implementation.
This can
+ * be used by client programs to determine what functionality is
available to
+ * them.
+ *
+ * @return the XML:DB API conformance level for this implementation.
+ * @exception XMLDBException with expected error codes.<br />
+ * <code>ErrorCodes.VENDOR_ERROR</code> for any vendor
+ * specific errors that occur.<br />
+ */
+ public String getConformanceLevel() throws XMLDBException {
+ return CONFORMANCE_LEVEL;
+ }
- /**
- * Returns the prefix used in XML:DB to denote URI's that this driver can
- * handle.
- *
- * @return the prefix driver name
- * @exception XMLDBException with expected error codes.<br />
- * <code>ErrorCodes.VENDOR_ERROR</code> for any vendor
- * specific errors that occur.<br />
- */
- public String getName() throws XMLDBException {
- return DRIVER_NAME;
- }
-
- /**
- * Returns the XML:DB API Conformance level for the implementation. This
can
- * be used by client programs to determine what functionality is
available to
- * them.
- *
- * @return the XML:DB API conformance level for this implementation.
- * @exception XMLDBException with expected error codes.<br />
- * <code>ErrorCodes.VENDOR_ERROR</code> for any vendor
- * specific errors that occur.<br />
- */
- public String getConformanceLevel() throws XMLDBException {
- return CONFORMANCE_LEVEL;
- }
-
}