You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-dev@xml.apache.org by vg...@apache.org on 2004/02/19 14:14:26 UTC
cvs commit: xml-xindice/java/src/org/apache/xindice/client/xmldb/xmlrpc CollectionImpl.java
vgritsenko 2004/02/19 05:14:26
Modified: java/src/org/apache/xindice/client/xmldb DatabaseImpl.java
java/src/org/apache/xindice/client/xmldb/xmlrpc
CollectionImpl.java
Log:
Improving exception handling
Revision Changes Path
1.27 +31 -27 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.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- DatabaseImpl.java 12 Feb 2004 03:12:18 -0000 1.26
+++ DatabaseImpl.java 19 Feb 2004 13:14:26 -0000 1.27
@@ -20,7 +20,9 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.xindice.core.FaultCodes;
+import org.xmldb.api.base.Collection;
import org.xmldb.api.base.Database;
import org.xmldb.api.base.ErrorCodes;
import org.xmldb.api.base.XMLDBException;
@@ -70,6 +72,7 @@
*/
public static final String CONFORMANCE_LEVEL = "0";
+
/**
* Constructor for the DatabaseImpl object
*/
@@ -129,8 +132,7 @@
* @return The Collection value
* @exception XMLDBException
*/
- public org.xmldb.api.base.Collection getCollection(String uri, String username, String password) throws XMLDBException {
-
+ public Collection getCollection(String uri, String username, String password) throws XMLDBException {
createDriver(uri);
return driver.getCollection(uri, username, password);
}
@@ -177,31 +179,33 @@
protected void createDriver(String uri) throws XMLDBException {
// Determine which driver was requested.
if (driver == null) {
- try {
- if (uri.startsWith(XMLRPC_URI)) {
- /*
- * The only way that a particular instance of xmlrpc.DatabaseImpl
- * can be informed of the path to the XML-RPC service in the
- * web server is by setting a property on the DatabaseImpl object
- * which is in turn passed to the CollectionImpl object. Whew!
- * Since the user never sees the actual xmlrpc.DatabaseImpl object,
- * this is the only way to make sure that they can set that property.
- */
- 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(this);
- } else if (uri.startsWith(MANAGED_URI)) {
- driver = new org.apache.xindice.client.xmldb.managed.DatabaseImpl(this);
- }
- } catch (Exception e) {
- log.error("Exception during creation of the Database", e);
- throw new XMLDBException(ErrorCodes.INVALID_URI, uri, e);
+ if (uri == null) {
+ throw new XMLDBException(ErrorCodes.INVALID_URI,
+ FaultCodes.URI_NULL,
+ "The URI is null");
}
- // moved to avoid double catching a creation exception
- if (null == driver) {
- log.warn("The uri '" + uri + "' is not handled be xindice");
- throw new XMLDBException(ErrorCodes.INVALID_URI, uri);
+ if (uri.startsWith(XMLRPC_URI)) {
+ /*
+ * The only way that a particular instance of xmlrpc.DatabaseImpl
+ * can be informed of the path to the XML-RPC service in the
+ * web server is by setting a property on the DatabaseImpl object
+ * which is in turn passed to the CollectionImpl object. Whew!
+ * Since the user never sees the actual xmlrpc.DatabaseImpl object,
+ * this is the only way to make sure that they can set that property.
+ */
+ 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(this);
+ } else if (uri.startsWith(MANAGED_URI)) {
+ driver = new org.apache.xindice.client.xmldb.managed.DatabaseImpl(this);
+ } else {
+ if (log.isInfoEnabled()) {
+ log.info("The URI '" + uri + "' is not handled by Xindice");
+ }
+ throw new XMLDBException(ErrorCodes.INVALID_URI,
+ FaultCodes.URI,
+ "The URI '" + uri + "' is not handled by Xindice");
}
}
}
1.46 +7 -4 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.45
retrieving revision 1.46
diff -u -r1.45 -r1.46
--- CollectionImpl.java 19 Feb 2004 03:05:14 -0000 1.45
+++ CollectionImpl.java 19 Feb 2004 13:14:26 -0000 1.46
@@ -89,6 +89,7 @@
if (!"yes".equals(exists)) {
throw new XMLDBException(ErrorCodes.NO_SUCH_COLLECTION,
+ FaultCodes.COL_COLLECTION_NOT_FOUND,
"Collection not found: " + collPath);
}
}
@@ -142,8 +143,8 @@
* method has been called on the <code>Collection</code><br />
*/
public Resource getResource(String id) throws XMLDBException {
-
checkOpen();
+
try {
if (id == null) {
return null;
@@ -156,17 +157,19 @@
Object result = runRemoteCommand("GetResource", params);
- // If we get a Hashtable back then the result is compressed.
if (result == null) {
// No resource found
return null;
} else if (result instanceof Hashtable) {
+ // Result is compressed XML.
Hashtable compressed = (Hashtable) result;
SymbolDeserializer symbolDeserial = new SymbolDeserializer();
return new XMLResourceImpl(id, id, this, symbolDeserial.getSymbols(compressed), (byte[]) compressed.get("document"));
} else if (result instanceof byte[]) {
+ // Result is binary.
return new BinaryResourceImpl(id, this, (byte[]) result);
} else {
+ // Result is XML.
return new XMLResourceImpl(id, this, (String) result);
}