vgritsenko 2003/08/08 19:44:23
Modified: java/src/org/apache/xindice/client/xmldb/embed
DatabaseImpl.java
java/src/org/apache/xindice/client/xmldb/managed
ManagedDatabaseImpl.java
java/src/org/apache/xindice/client/xmldb/xmlrpc
DatabaseImpl.java
Log:
Sync up driver implementations.
Should driver through an exception on unknown database?
Revision Changes Path
1.18 +50 -33
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.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- DatabaseImpl.java 8 Aug 2003 22:38:18 -0000 1.17
+++ DatabaseImpl.java 9 Aug 2003 02:44:23 -0000 1.18
@@ -89,11 +89,19 @@
private static final Log log = LogFactory.getLog(DatabaseImpl.class);
- /** prefix used to denote XML:DB URI's that should use this driver */
+ /**
+ * Prefix used to denote XML:DB URI's that should use this driver
+ */
public static final String DRIVER_NAME = "xindice-embed";
- /** XML:DB conformance level of this driver */
+ /**
+ * XML:DB conformance level of this driver
+ */
private String CONFORMANCE_LEVEL = "0";
+
+ /**
+ * Database instance
+ */
private Database database;
/**
@@ -108,12 +116,14 @@
*/
public DatabaseImpl() throws FileNotFoundException, XindiceException {
Configuration config = loadConfiguration();
- this.database = Database.getDatabase(config);
+ this.database = Database.getDatabase(config);
if (null == this.database) {
log.fatal("Unable to configure database");
throw new XindiceException("Unable to configure database");
- } else {
+ }
+
+ if (log.isDebugEnabled()) {
log.info("Database name: '" + this.database.getName() + "'");
}
}
@@ -204,7 +214,8 @@
/* TODO: introduce authentication some day */
if (!acceptsURI(uri)) {
- throw new XMLDBException(ErrorCodes.INVALID_URI, "Invalid URL: "
+ uri);
+ throw new XMLDBException(ErrorCodes.INVALID_URI,
+ "Invalid URL: " + uri);
}
/* Chop off driver prefix, and '://' */
@@ -213,43 +224,49 @@
/* Extract host name & port, if present */
int firstSlash = uri.indexOf('/');
if (firstSlash == -1) {
- throw new XMLDBException(ErrorCodes.INVALID_URI, "Invalid URL: "
+ uri);
+ throw new XMLDBException(ErrorCodes.INVALID_URI,
+ "Invalid URL (must have '/'): " + uri);
}
+ /* Extract collection name */
String collPath = uri.substring(firstSlash);
+ if (!collPath.startsWith("/")) {
+ throw new XMLDBException(ErrorCodes.INVALID_URI,
+ "Invalid URL (collection name must
start with '/'): " + uri);
+ }
- // 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);
+ // find the database name. We just skip the first slash
+ int colIndex = collPath.indexOf('/', 1);
- // The rest of the name locates the collection
- colName = collPath.substring(colIndex);
- }
+ // 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 = "/";
}
+ }
+
+ // TODO: Is this correct behavior?
+ if (!database.getName().equals(dbName)) {
+ throw new XMLDBException(ErrorCodes.NO_SUCH_DATABASE,
+ "Unknown database (must be '" +
database.getName() + "'): " + uri);
+ }
- try {
- return new CollectionImpl(database, colName);
- } catch (XMLDBException e) {
- if (e.errorCode == ErrorCodes.NO_SUCH_COLLECTION) {
- // per getCollection contract, return null if not found
- return null;
- }
- throw e;
+ try {
+ return new CollectionImpl(database, colName);
+ } catch (XMLDBException e) {
+ if (e.errorCode == ErrorCodes.NO_SUCH_COLLECTION) {
+ // per getCollection contract, return null if not found
+ return null;
}
- } else {
- throw new XMLDBException(ErrorCodes.INVALID_URI, "Collection
name must begin with a '/'");
+ throw e;
}
}
1.5 +62 -34
xml-xindice/java/src/org/apache/xindice/client/xmldb/managed/ManagedDatabaseImpl.java
Index: ManagedDatabaseImpl.java
===================================================================
RCS file:
/home/cvs/xml-xindice/java/src/org/apache/xindice/client/xmldb/managed/ManagedDatabaseImpl.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ManagedDatabaseImpl.java 7 Aug 2003 20:13:20 -0000 1.4
+++ ManagedDatabaseImpl.java 9 Aug 2003 02:44:23 -0000 1.5
@@ -89,6 +89,9 @@
*/
public class ManagedDatabaseImpl extends CommonConfigurable implements
org.xmldb.api.base.Database {
+ /**
+ * Logger used by this class
+ */
private static final Log log =
LogFactory.getLog(ManagedDatabaseImpl.class);
/**
@@ -96,6 +99,15 @@
*/
public static final String DRIVER_NAME = "xindice-managed";
+ /**
+ * Default database name in case none was specified via
+ * [EMAIL PROTECTED] #DATABASE_NAME_PROPERTY} property
+ */
+ public static final String DATABASE_NAME = "db";
+
+ /**
+ * System property storing the name of the database to connect to
+ */
public static final String DATABASE_NAME_PROPERTY =
"xindice.drivers.managed.db";
/**
@@ -103,17 +115,20 @@
*/
public static final String CONFORMANCE_LEVEL = "0";
- protected Database db;
+ /**
+ * Database instance
+ */
+ protected Database database;
public ManagedDatabaseImpl() throws FileNotFoundException,
XindiceException {
- this(System.getProperty(DATABASE_NAME_PROPERTY, "db"));
+ this(System.getProperty(DATABASE_NAME_PROPERTY, DATABASE_NAME));
}
public ManagedDatabaseImpl(String databaseName) throws
FileNotFoundException, XindiceException {
- this.db = Database.getDatabase(databaseName);
+ this.database = Database.getDatabase(databaseName);
- if (null == db) {
+ if (null == database) {
log.fatal("The database " + databaseName + " has not been
created.");
throw new XindiceException("The " + getName() + " driver
requires that the database "
+ "instance be created and available
in the JVM");
@@ -133,8 +148,11 @@
* documentation for DatabaseManager.getCollection().<p/>
*/
public Collection getCollection(String uri, String username, String
password) throws XMLDBException {
+ /* TODO: introduce authentication some day */
+
if (!acceptsURI(uri)) {
- throw new XMLDBException(ErrorCodes.INVALID_URI, "Invalid URL: "
+ uri);
+ throw new XMLDBException(ErrorCodes.INVALID_URI,
+ "Invalid URL: " + uri);
}
/* Chop off driver prefix, and '://' */
@@ -143,40 +161,50 @@
/* Extract host name & port, if present */
int firstSlash = uri.indexOf('/');
if (firstSlash == -1) {
- throw new XMLDBException(ErrorCodes.INVALID_URI, "Invalid URL: "
+ uri);
+ throw new XMLDBException(ErrorCodes.INVALID_URI,
+ "Invalid URL (must have '/'): " + uri);
}
+ /* Extract collection name */
String collPath = uri.substring(firstSlash);
+ if (!collPath.startsWith("/")) {
+ throw new XMLDBException(ErrorCodes.INVALID_URI,
+ "Invalid URL (collection name must
start with '/'): " + uri);
+ }
+
+ // find the database name. We just skip the first slash
+ int colIndex = collPath.indexOf('/', 1);
- // 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 colName = "/";
-
- // if colIndex isn't -1 then we need to pick out the db and
collection
- if (colIndex != -1) {
- // The rest of the name locates the collection
- colName = collPath.substring(colIndex);
-
- if (colName.equals("")) {
- colName = "/";
- }
+ // 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 = "/";
}
+ }
+
+ // TODO: Is this correct behavior?
+ if (!database.getName().equals(dbName)) {
+ throw new XMLDBException(ErrorCodes.NO_SUCH_DATABASE,
+ "Unknown database (must be '" +
database.getName() + "'): " + uri);
+ }
- try {
- return new CollectionImpl(db, colName);
- } catch (XMLDBException xmldbe) {
- if (xmldbe.errorCode == ErrorCodes.NO_SUCH_COLLECTION) {
- return null;
- } else {
- throw xmldbe;
- }
+ try {
+ return new CollectionImpl(database, colName);
+ } catch (XMLDBException xmldbe) {
+ if (xmldbe.errorCode == ErrorCodes.NO_SUCH_COLLECTION) {
+ // per getCollection contract, return null if not found
+ return null;
+ } else {
+ throw xmldbe;
}
- } else {
- throw new XMLDBException(ErrorCodes.INVALID_URI, "Collection
name must begin with a '/'");
}
}
1.15 +10 -10
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.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- DatabaseImpl.java 7 Aug 2003 20:13:20 -0000 1.14
+++ DatabaseImpl.java 9 Aug 2003 02:44:23 -0000 1.15
@@ -163,11 +163,10 @@
* 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)) {
- throw new XMLDBException(ErrorCodes.INVALID_URI);
+ if (!acceptsURI(uri)) {
+ throw new XMLDBException(ErrorCodes.INVALID_URI, "Invalid URL: "
+ uri);
}
/* Chop off driver prefix, and '://' */
@@ -176,21 +175,22 @@
/* Extract host name & port, if present */
int firstSlash = uri.indexOf('/');
if (firstSlash == -1) {
-
- throw new XMLDBException(ErrorCodes.INVALID_URI);
+ throw new XMLDBException(ErrorCodes.INVALID_URI, "Invalid URL
(must have '/'): " + uri);
}
- String hostPort = uri.substring(0, firstSlash);
String collPath = uri.substring(firstSlash);
+ String hostPort = uri.substring(0, firstSlash);
/* Absent host defaults to localhost and standard Xindice HTTP port
*/
if (hostPort.equals("")) {
hostPort = "127.0.0.1:8888";
- log.debug("Using default host and port: '"+hostPort+"'");
+ if (log.isDebugEnabled()) {
+ log.debug("Using default host and port: '"+hostPort+"'");
+ }
}
try {
- return new CollectionImpl(hostPort,
this.getProperty(PROP_SERVICE_LOCATION), this.getProperty(PROP_XMLRPC_DRIVER),
collPath);
+ return new CollectionImpl(hostPort,
getProperty(PROP_SERVICE_LOCATION), getProperty(PROP_XMLRPC_DRIVER), collPath);
} catch (XMLDBException e) {
if (e.errorCode == ErrorCodes.NO_SUCH_COLLECTION) {
// per getCollection contract, return null if not found