vgritsenko 2003/12/22 06:08:07
Modified: java/src/org/apache/xindice/client/xmldb
XindiceCollection.java
Log:
createResource: Support BinaryResource
Revision Changes Path
1.14 +32 -25
xml-xindice/java/src/org/apache/xindice/client/xmldb/XindiceCollection.java
Index: XindiceCollection.java
===================================================================
RCS file:
/home/cvs/xml-xindice/java/src/org/apache/xindice/client/xmldb/XindiceCollection.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- XindiceCollection.java 15 Aug 2003 04:34:54 -0000 1.13
+++ XindiceCollection.java 22 Dec 2003 14:08:07 -0000 1.14
@@ -60,6 +60,7 @@
package org.apache.xindice.client.xmldb;
import org.apache.xindice.client.xmldb.resources.XMLResourceImpl;
+import org.apache.xindice.client.xmldb.resources.BinaryResourceImpl;
import
org.apache.xindice.client.xmldb.services.CollectionManagementServiceImpl;
import org.apache.xindice.client.xmldb.services.MetaService;
import org.apache.xindice.client.xmldb.services.XPathQueryServiceImpl;
@@ -90,14 +91,21 @@
* @version CVS $Revision$, $Date$
*/
public abstract class XindiceCollection extends CommonConfigurable
implements Collection {
- /* Instantiated named services map */
- protected Hashtable services = null;
- /* Xindice query result meta-info namespace */
+ /**
+ * Xindice query result meta-info namespace
+ */
public static final String QUERY_NS =
"http://xml.apache.org/xindice/Query";
- /* path to collection on target server */
- protected String collPath;
+ /**
+ * Instantiated named services map
+ */
+ protected final Hashtable services = new Hashtable();
+
+ /**
+ * Path to the collection on target server
+ */
+ protected final String collPath;
/**
* Creates new <code>CollectionImpl</code> instance representing
connection
@@ -108,28 +116,25 @@
* collection with path <code>collPath</code> could be
located.
*/
public XindiceCollection(String collPath) throws XMLDBException {
-
this.collPath = collPath.endsWith("/") ? collPath.substring(0,
collPath.length() - 1) : collPath;
- services = new Hashtable();
-
// Register all services supported by this collection implementation.
- XPathQueryServiceImpl xpath = new XPathQueryServiceImpl();
+ final XPathQueryServiceImpl xpath = new XPathQueryServiceImpl();
xpath.setCollection(this);
- // xpath.setSymbolDeserializer(syms);
+ // xpath.setSymbolDeserializer(syms);
registerService(xpath);
- XUpdateQueryServiceImpl xupdate = new XUpdateQueryServiceImpl();
+ final XUpdateQueryServiceImpl xupdate = new
XUpdateQueryServiceImpl();
xupdate.setCollection(this);
registerService(xupdate);
// TODO if (this.col.isMetaEnabled()) {
- MetaService meta = new MetaService();
+ final MetaService meta = new MetaService();
meta.setCollection(this);
registerService(meta);
try {
- CollectionManagementServiceImpl manager = new
CollectionManagementServiceImpl();
+ final CollectionManagementServiceImpl manager = new
CollectionManagementServiceImpl();
manager.setCollection(this);
registerService(manager);
@@ -198,7 +203,6 @@
* @exception XMLDBException
*/
public void registerService(org.xmldb.api.base.Service service) throws
XMLDBException {
- //checkOpen();
service.setCollection(this);
services.put(service.getName() + service.getVersion(), service);
@@ -218,7 +222,6 @@
* @exception XMLDBException thrown if collection is closed
*/
protected void checkOpen() throws XMLDBException {
-
if (!isOpen()) {
throw new XMLDBException(ErrorCodes.COLLECTION_CLOSED);
}
@@ -239,7 +242,6 @@
* @return the collection path
*/
public String getCanonicalName() {
-
return collPath;
}
@@ -257,14 +259,15 @@
* must first set the resource's XML data, and then call
* <code>storeResource()</code>.
*
- * @param name name for new resource. If empty or <code>null</code>, a
name
+ * @param name Name for the new resource. If it is empty or
<code>null</code>, a name
* will be assigned when storing the resource in the database.
- * @param type must be <code>XMLResource</code>.
+ * @param type Type must be either <code>XMLResource</code> or
<code>BinaryResource</code>.
* @exception XMLDBException thrown in case of an invalid resource type
or name
*/
public Resource createResource(String name, String type) throws
XMLDBException {
- if (!"XMLResource".equals(type)) {
- throw new XMLDBException(ErrorCodes.UNKNOWN_RESOURCE_TYPE, "only
XMLResources supported");
+ if (!"XMLResource".equals(type) && !"BinaryResource".equals(type)) {
+ throw new XMLDBException(ErrorCodes.UNKNOWN_RESOURCE_TYPE,
+ "Only XMLResource and BinaryResource
supported");
}
if (name == null || name.length() == 0) {
@@ -272,10 +275,15 @@
// "If id is null or its value is empty then an id is generated
by calling createId()."
name = createId();
} else if (name.indexOf('/') != -1) {
- throw new XMLDBException(ErrorCodes.INVALID_RESOURCE, "Name
cannot contain '/'");
+ throw new XMLDBException(ErrorCodes.INVALID_RESOURCE,
+ "Name cannot contain '/'");
}
- return new XMLResourceImpl(name, this);
+ if ("XMLResource".equals(type)) {
+ return new XMLResourceImpl(name, this);
+ } else {
+ return new BinaryResourceImpl(name, null, this);
+ }
}
/**
@@ -288,7 +296,6 @@
* @throws XMLDBException thrown in case of invalid query or other error
*/
public ResourceSet query(String queryLang, String query, Hashtable
nsMap) throws XMLDBException {
-
return query(null, queryLang, query, nsMap);
}