vgritsenko 2003/01/24 18:24:27
Modified: src/deprecated/java/org/apache/cocoon/generation
XMLDBCollectionGenerator.java XMLDBGenerator.java
Log:
conf in configure() never null. realign code.
Revision Changes Path
1.2 +111 -141
xml-cocoon2/src/deprecated/java/org/apache/cocoon/generation/XMLDBCollectionGenerator.java
Index: XMLDBCollectionGenerator.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/deprecated/java/org/apache/cocoon/generation/XMLDBCollectionGenerator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XMLDBCollectionGenerator.java 26 Dec 2002 18:38:57 -0000 1.1
+++ XMLDBCollectionGenerator.java 25 Jan 2003 02:24:27 -0000 1.2
@@ -94,12 +94,11 @@
* @version CVS $Id$
* @deprecated Use the XML:DB pseudo protocol instead.
*/
-
- public class XMLDBCollectionGenerator extends ComposerGenerator
- implements CacheableProcessingComponent, Configurable,Initializable {
+public class XMLDBCollectionGenerator extends ComposerGenerator
+ implements CacheableProcessingComponent, Configurable,Initializable {
protected static final String URI =
- "http://apache.org/cocoon/xmldb/1.0";
+ "http://apache.org/cocoon/xmldb/1.0";
protected static final String PREFIX = "collection";
protected static final String RESOURCE_COUNT_ATTR = "resources";
protected static final String COLLECTION_COUNT_ATTR = "collections";
@@ -113,7 +112,7 @@
protected String col;
protected Database database;
protected Collection collection;
- protected AttributesImpl attributes = new AttributesImpl();
+ protected final AttributesImpl attributes = new AttributesImpl();
public void compose(ComponentManager manager) throws ComponentException {
super.compose(manager);
@@ -122,14 +121,11 @@
/**
* Recycle the component, keep only the configuration variables
* and the database instance for reuse.
- *
*/
-
public void recycle() {
super.recycle();
this.col = null;
this.collection = null;
- //this.attributes = null;
}
/**
@@ -146,115 +142,93 @@
*
* @exception ConfigurationException (configuration invalid or missing)
*/
-
- public void configure(Configuration conf)
- throws ConfigurationException {
- if (conf != null) {
- this.driver = conf.getChild("driver").getValue();
- this.base = conf.getChild("base").getValue();
- } else {
- throw new ConfigurationException("XMLDB configuration not found");
- }
- }
+ public void configure(Configuration conf) throws ConfigurationException {
+ this.driver = conf.getChild("driver").getValue();
+ this.base = conf.getChild("base").getValue();
+ }
/**
* Initialize the component getting a database instance.
*
* @exception Exception if an error occurs
*/
-
- public void initialize() throws Exception {
- try {
-
- Class c = Class.forName(driver);
- database = (Database)c.newInstance();
- DatabaseManager.registerDatabase(database);
-
- } catch (XMLDBException xde) {
-
- this.getLogger().error("Unable to connect to the XML:DB database");
- throw new ProcessingException("Unable to connect to the XML DB"
- + xde.getMessage());
-
- } catch (Exception e) {
-
- this.getLogger().error("There was a problem setting up the connection");
- this.getLogger().error("Make sure that your driver is available");
- throw new ProcessingException("Problem setting up the connection: "
- + e.getMessage());
-
- }
- }
+ public void initialize() throws Exception {
+ try {
+ Class c = Class.forName(driver);
+ database = (Database)c.newInstance();
+ DatabaseManager.registerDatabase(database);
+ } catch (XMLDBException xde) {
+ this.getLogger().error("Unable to connect to the XML:DB database");
+ throw new ProcessingException("Unable to connect to the XML DB"
+ + xde.getMessage());
+ } catch (Exception e) {
+ this.getLogger().error("There was a problem setting up the connection");
+ this.getLogger().error("Make sure that your driver is available");
+ throw new ProcessingException("Problem setting up the connection: "
+ + e.getMessage());
+ }
+ }
public void setup(SourceResolver resolver,
Map objectModel,
String src,
Parameters par)
- throws ProcessingException, SAXException,IOException {
-
- super.setup(resolver, objectModel, src, par);
-
+ throws ProcessingException, SAXException,IOException {
+ super.setup(resolver, objectModel, src, par);
}
/**
* The component isn't cached (yet)
*/
public SourceValidity getValidity() {
- return null;
+ return null;
}
/**
* The component isn't cached (yet)
*/
public SourceValidity generateValidity() {
- return null;
+ return null;
}
/**
* The component isn't cached (yet)
*/
public java.io.Serializable generateKey() {
- return null;
+ return null;
}
- /**
- * Parse the requested URI, connect to the XML:DB database
- * and fetch the requested resource.
- *
- * @exception ProcessingException something unexpected happened with the DB
- */
+ /**
+ * Parse the requested URI, connect to the XML:DB database
+ * and fetch the requested resource.
+ *
+ * @exception ProcessingException something unexpected happened with the DB
+ */
public void generate()
- throws IOException, SAXException, ProcessingException {
- //String col = "/";
-
- //if (source.indexOf('/') != -1)
- col = source;
-
-
- try {
- collection = DatabaseManager.getCollection(base + col);
-
- if (collection == null)
- throw new ResourceNotFoundException("Collection " + col +
- " not found");
-
- collectionToSAX(collection);
-
- collection.close();
-
- } catch (XMLDBException xde) {
-
- throw new ProcessingException("Unable to fetch content '"
- + source + "':" + xde.getMessage());
-
- } catch (NullPointerException npe) {
+ throws IOException, SAXException, ProcessingException {
+ //String col = "/";
- this.getLogger().error("The XML:DB driver raised an exception");
- this.getLogger().error("probably the document was not found");
- throw new ProcessingException("Null pointer exception while " +
- "retrieving document : " + npe.getMessage());
+ //if (source.indexOf('/') != -1)
+ col = source;
- }
+ try {
+ collection = DatabaseManager.getCollection(base + col);
+ if (collection == null) {
+ throw new ResourceNotFoundException("Collection " + col +
+ " not found");
+ }
+
+ collectionToSAX(collection);
+ collection.close();
+ } catch (XMLDBException xde) {
+ throw new ProcessingException("Unable to fetch content '"
+ + source + "':" + xde.getMessage());
+ } catch (NullPointerException npe) {
+ this.getLogger().error("The XML:DB driver raised an exception");
+ this.getLogger().error("probably the document was not found");
+ throw new ProcessingException("Null pointer exception while " +
+ "retrieving document : " +
npe.getMessage());
+ }
}
/**
@@ -262,65 +236,61 @@
*
* @exception SAXException
*/
-
public void collectionToSAX(Collection collection)
- throws SAXException {
-
- String ncollections;
- String nresources;
- String[] resources;
- String[] collections;
-
- try {
- ncollections = Integer.toString(collection.getChildCollectionCount());
- nresources = Integer.toString(collection.getResourceCount());
-
- attributes.clear();
- attributes.addAttribute("", RESOURCE_COUNT_ATTR,
- RESOURCE_COUNT_ATTR, "CDATA", nresources);
- attributes.addAttribute("", COLLECTION_COUNT_ATTR,
- COLLECTION_COUNT_ATTR, "CDATA", ncollections);
-
- collections = collection.listChildCollections();
- resources = collection.listResources();
-
- this.xmlConsumer.startDocument();
- this.xmlConsumer.startPrefixMapping(PREFIX, URI);
-
- this.xmlConsumer.startElement(URI, "collections",
- "collection:collections", attributes);
-
- // Print child collections
-
- for (int i = 0; i < collections.length; i++) {
- attributes.clear();
- attributes.addAttribute("", "name", "name", "CDATA", collections[i]);
- this.xmlConsumer.startElement(URI, COLLECTION,
- QCOLLECTION, attributes);
- this.xmlConsumer.endElement(URI, COLLECTION, COLLECTION);
- }
-
- // Print child resources
+ throws SAXException {
- for (int i = 0; i < resources.length; i++) {
- attributes.clear();
- attributes.addAttribute("", "name", "name", "CDATA", resources[i]);
- this.xmlConsumer.startElement(URI, RESOURCE,
- QRESOURCE, attributes);
- this.xmlConsumer.endElement(URI, RESOURCE, RESOURCE);
+ String ncollections;
+ String nresources;
+ String[] resources;
+ String[] collections;
+
+ try {
+ ncollections = Integer.toString(collection.getChildCollectionCount());
+ nresources = Integer.toString(collection.getResourceCount());
+
+ attributes.clear();
+ attributes.addAttribute("", RESOURCE_COUNT_ATTR,
+ RESOURCE_COUNT_ATTR, "CDATA", nresources);
+ attributes.addAttribute("", COLLECTION_COUNT_ATTR,
+ COLLECTION_COUNT_ATTR, "CDATA", ncollections);
+
+ collections = collection.listChildCollections();
+ resources = collection.listResources();
+
+ this.xmlConsumer.startDocument();
+ this.xmlConsumer.startPrefixMapping(PREFIX, URI);
+
+ this.xmlConsumer.startElement(URI, "collections",
+ "collection:collections", attributes);
+
+ // Print child collections
+
+ for (int i = 0; i < collections.length; i++) {
+ attributes.clear();
+ attributes.addAttribute("", "name", "name", "CDATA",
collections[i]);
+ this.xmlConsumer.startElement(URI, COLLECTION,
+ QCOLLECTION, attributes);
+ this.xmlConsumer.endElement(URI, COLLECTION, COLLECTION);
+ }
+
+ // Print child resources
+
+ for (int i = 0; i < resources.length; i++) {
+ attributes.clear();
+ attributes.addAttribute("", "name", "name", "CDATA", resources[i]);
+ this.xmlConsumer.startElement(URI, RESOURCE,
+ QRESOURCE, attributes);
+ this.xmlConsumer.endElement(URI, RESOURCE, RESOURCE);
+ }
+
+ this.xmlConsumer.endElement(URI, "collections",
+ "collection:collections");
+
+ this.xmlConsumer.endPrefixMapping(PREFIX);
+ this.xmlConsumer.endDocument();
+ } catch (XMLDBException xde) {
+ this.getLogger().warn("Collection listing failed" + xde.getMessage());
+ throw new SAXException("Collection listing failed" + xde.getMessage());
}
-
- this.xmlConsumer.endElement(URI, "collections",
- "collection:collections");
-
- this.xmlConsumer.endPrefixMapping(PREFIX);
- this.xmlConsumer.endDocument();
-
- } catch (XMLDBException xde) {
- this.getLogger().warn("Collection listing failed" + xde.getMessage());
- throw new SAXException("Collection listing failed" + xde.getMessage());
- }
-
}
-
}
1.2 +73 -98
xml-cocoon2/src/deprecated/java/org/apache/cocoon/generation/XMLDBGenerator.java
Index: XMLDBGenerator.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/deprecated/java/org/apache/cocoon/generation/XMLDBGenerator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XMLDBGenerator.java 26 Dec 2002 18:38:57 -0000 1.1
+++ XMLDBGenerator.java 25 Jan 2003 02:24:27 -0000 1.2
@@ -94,9 +94,8 @@
* @version CVS $Id$
* @deprecated Use the XML:DB pseudo protocol instead.
*/
-
- public class XMLDBGenerator extends ComposerGenerator
- implements CacheableProcessingComponent, Configurable,Initializable {
+public class XMLDBGenerator extends ComposerGenerator
+ implements CacheableProcessingComponent, Configurable,Initializable {
protected String driver;
protected String base;
@@ -113,9 +112,7 @@
/**
* Recycle the component, keep only the configuration variables
* and the database instance for reuse.
- *
*/
-
public void recycle() {
super.recycle();
this.col = null;
@@ -124,130 +121,108 @@
this.collection = null;
}
- /**
- * Configure the component. This class is expecting a configuration
- * like the following one:
- * <pre>
- * <driver>org.dbxml.client.xmldb.DatabaseImpl</driver>
- * <base>xmldb:dbxml:///db/</base>
- * </pre>
- * NOTE: the driver can be any DB:XML compliant driver (although this
- * component has been tested only with
- * <a href="http://www.dbxml.org">dbXML</a>, and the trailing
- * slash in the base tag is important!
- *
- * @exception ConfigurationException (configuration invalid or missing)
- */
-
- public void configure(Configuration conf)
- throws ConfigurationException {
- if (conf != null) {
+ /**
+ * Configure the component. This class is expecting a configuration
+ * like the following one:
+ * <pre>
+ * <driver>org.dbxml.client.xmldb.DatabaseImpl</driver>
+ * <base>xmldb:dbxml:///db/</base>
+ * </pre>
+ * NOTE: the driver can be any DB:XML compliant driver (although this
+ * component has been tested only with
+ * <a href="http://www.dbxml.org">dbXML</a>, and the trailing
+ * slash in the base tag is important!
+ *
+ * @exception ConfigurationException (configuration invalid or missing)
+ */
+ public void configure(Configuration conf) throws ConfigurationException {
this.driver = conf.getChild("driver").getValue();
this.base = conf.getChild("base").getValue();
- } else {
- throw new ConfigurationException("XML:DB configuration not found");
- }
}
- /**
- * Initialize the component getting a database instance.
- *
- * @exception Exception if an error occurs
- */
-
+ /**
+ * Initialize the component getting a database instance.
+ *
+ * @exception Exception if an error occurs
+ */
public void initialize() throws Exception {
- try {
-
- Class c = Class.forName(driver);
- database = (Database)c.newInstance();
- DatabaseManager.registerDatabase(database);
-
- } catch (XMLDBException xde) {
-
- this.getLogger().error("Unable to connect to the XML:DB database");
- throw new ProcessingException("Unable to connect to the XMLDB database"
- + xde.getMessage());
-
- } catch (Exception e) {
-
- this.getLogger().error("There was a problem setting up the connection");
- this.getLogger().error("Make sure that your driver is available");
- throw new ProcessingException("Problem setting up the connection: "
- + e.getMessage());
-
- }
+ try {
+ Class c = Class.forName(driver);
+ database = (Database)c.newInstance();
+ DatabaseManager.registerDatabase(database);
+ } catch (XMLDBException xde) {
+ this.getLogger().error("Unable to connect to the XML:DB database");
+ throw new ProcessingException("Unable to connect to the XMLDB database:
"
+ + xde.getMessage());
+ } catch (Exception e) {
+ this.getLogger().error("There was a problem setting up the connection");
+ this.getLogger().error("Make sure that your driver is available");
+ throw new ProcessingException("Problem setting up the connection: "
+ + e.getMessage());
+ }
}
public void setup(SourceResolver resolver,
Map objectModel,
String src,
Parameters par)
- throws ProcessingException, SAXException,IOException {
-
- super.setup(resolver, objectModel, src, par);
-
+ throws ProcessingException, SAXException,IOException {
+ super.setup(resolver, objectModel, src, par);
}
/**
* The component isn't cached (yet)
*/
public SourceValidity getValidity() {
- return null;
+ return null;
}
/**
* The component isn't cached (yet)
*/
public SourceValidity generateValidity() {
- return null;
+ return null;
}
/**
* The component isn't cached (yet)
*/
public java.io.Serializable generateKey() {
- return null;
+ return null;
}
- /**
- * Parse the requested URI, connect to the XML:DB database
- * and fetch the requested resource.
- *
- * @exception ProcessingException something unexpected happened with the DB
- */
+ /**
+ * Parse the requested URI, connect to the XML:DB database
+ * and fetch the requested resource.
+ *
+ * @exception ProcessingException something unexpected happened with the DB
+ */
public void generate()
- throws IOException, SAXException, ProcessingException {
- String col = "/";
-
- if (source.indexOf('/') != -1)
- col = "/" + source.substring(0, source.lastIndexOf('/'));
- res = source.substring(source.lastIndexOf('/') + 1);
-
- try {
- collection = DatabaseManager.getCollection(base + col);
- xmlResource = (XMLResource) collection.getResource(res);
-
- if (xmlResource == null)
- throw new ResourceNotFoundException("Document " + col + "/" + res +
- " not found");
-
- xmlResource.getContentAsSAX(this.xmlConsumer);
-
- collection.close();
-
- } catch (XMLDBException xde) {
-
- throw new ProcessingException("Unable to fetch content: " +
- xde.getMessage());
-
- } catch (NullPointerException npe) {
-
- this.getLogger().error("The XML:DB driver raised an exception");
- this.getLogger().error("probably the document was not found");
-
- throw new ProcessingException("Null pointer exception while " +
- "retrieving document : " + npe.getMessage());
+ throws IOException, SAXException, ProcessingException {
+ String col = "/";
- }
+ if (source.indexOf('/') != -1)
+ col = "/" + source.substring(0, source.lastIndexOf('/'));
+ res = source.substring(source.lastIndexOf('/') + 1);
+
+ try {
+ collection = DatabaseManager.getCollection(base + col);
+ xmlResource = (XMLResource) collection.getResource(res);
+ if (xmlResource == null) {
+ throw new ResourceNotFoundException("Document " + col + "/" + res +
+ " not found");
+ }
+
+ xmlResource.getContentAsSAX(this.xmlConsumer);
+ collection.close();
+ } catch (XMLDBException xde) {
+ throw new ProcessingException("Unable to fetch content: " +
+ xde.getMessage());
+ } catch (NullPointerException npe) {
+ this.getLogger().error("The XML:DB driver raised an exception");
+ this.getLogger().error("probably the document was not found");
+ throw new ProcessingException("Null pointer exception while " +
+ "retrieving document : " +
npe.getMessage());
+ }
}
}
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]