cziegeler 01/12/13 03:50:47
Modified: . changes.xml
src/org/apache/cocoon/components/url URLFactory.java
URLFactoryImpl.java
Log:
URLFactories can now be Configurable.
Revision Changes Path
1.56 +4 -1 xml-cocoon2/changes.xml
Index: changes.xml
===================================================================
RCS file: /home/cvs/xml-cocoon2/changes.xml,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -r1.55 -r1.56
--- changes.xml 2001/12/10 12:56:22 1.55
+++ changes.xml 2001/12/13 11:50:47 1.56
@@ -4,7 +4,7 @@
<!--
History of Cocoon changes
- $Id: changes.xml,v 1.55 2001/12/10 12:56:22 sylvain Exp $
+ $Id: changes.xml,v 1.56 2001/12/13 11:50:47 cziegeler Exp $
-->
<changes title="History of Changes">
@@ -28,6 +28,9 @@
</devs>
<release version="2.1-dev" date="@date@">
+ <action dev="CZ" type="update">
+ Added support for configurable URLFactories.
+ </action>
<action dev="SW" type="fix">
Made the cach work again by updating cocoon.roles, sitemap.roles and making
EventPipeline
and StreamPipeline implement Recomposable instead of just Composable.
1.6 +2 -2 xml-cocoon2/src/org/apache/cocoon/components/url/URLFactory.java
Index: URLFactory.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/components/url/URLFactory.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- URLFactory.java 2001/10/11 07:28:19 1.5
+++ URLFactory.java 2001/12/13 11:50:47 1.6
@@ -14,9 +14,9 @@
/**
* @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
- * @version $Id: URLFactory.java,v 1.5 2001/10/11 07:28:19 cziegeler Exp $
+ * @version $Id: URLFactory.java,v 1.6 2001/12/13 11:50:47 cziegeler Exp $
*/
-public interface URLFactory extends ThreadSafe {
+public interface URLFactory extends Component {
String ROLE = "org.apache.cocoon.components.url.URLFactory";
/**
1.10 +69 -9
xml-cocoon2/src/org/apache/cocoon/components/url/URLFactoryImpl.java
Index: URLFactoryImpl.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/components/url/URLFactoryImpl.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- URLFactoryImpl.java 2001/10/11 07:28:19 1.9
+++ URLFactoryImpl.java 2001/12/13 11:50:47 1.10
@@ -7,7 +7,11 @@
*****************************************************************************/
package org.apache.cocoon.components.url;
+import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.component.Component;
+import org.apache.avalon.framework.component.ComponentException;
+import org.apache.avalon.framework.component.ComponentManager;
+import org.apache.avalon.framework.component.Composable;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
@@ -16,6 +20,7 @@
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.logger.AbstractLoggable;
import org.apache.avalon.framework.logger.Loggable;
+import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.Constants;
import org.apache.cocoon.environment.http.HttpContext;
import org.apache.cocoon.util.ClassUtils;
@@ -30,9 +35,11 @@
/**
* @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
- * @version $Id: URLFactoryImpl.java,v 1.9 2001/10/11 07:28:19 cziegeler Exp $
+ * @version $Id: URLFactoryImpl.java,v 1.10 2001/12/13 11:50:47 cziegeler Exp $
*/
-public class URLFactoryImpl extends AbstractLoggable implements URLFactory,
Component, Configurable, Contextualizable {
+public class URLFactoryImpl
+extends AbstractLoggable
+implements ThreadSafe, Configurable, Disposable, Composable, Contextualizable,
URLFactory {
/**
* The context
@@ -44,6 +51,9 @@
*/
protected Map factories;
+ /** The component manager */
+ private ComponentManager manager;
+
/**
* Create a URL from a location. This method supports specific
* pseudo-protocol as defined in its configuration
@@ -123,7 +133,8 @@
/**
* Configure the URLFactories
*/
- public void configure(final Configuration conf) throws ConfigurationException {
+ public void configure(final Configuration conf)
+ throws ConfigurationException {
try {
getLogger().debug("Getting the URLFactories");
factories = new HashMap();
@@ -132,14 +143,12 @@
String protocol = null;
for (int i = 0; i < configs.length; i++) {
protocol = configs[i].getAttribute("name");
+ if (factories.containsKey(protocol) == true) {
+ throw new ConfigurationException("URLFactory defined twice for
protocol: " + protocol);
+ }
getLogger().debug("\tfor protocol: " + protocol + " " +
configs[i].getAttribute("class"));
urlFactory = (URLFactory)
ClassUtils.newInstance(configs[i].getAttribute("class"));
- if (urlFactory instanceof Contextualizable) {
- ((Contextualizable) urlFactory).contextualize (this.context);
- }
- if (urlFactory instanceof Loggable) {
- ((Loggable) urlFactory).setLogger(getLogger());
- }
+ this.init(urlFactory, configs[i]);
factories.put(protocol, urlFactory);
}
} catch (Exception e) {
@@ -148,4 +157,55 @@
e.getMessage());
}
}
+
+ /**
+ * Set the current <code>ComponentManager</code> instance used by this
+ * <code>Composable</code>.
+ */
+ public void compose(ComponentManager manager)
+ throws ComponentException {
+ this.manager = manager;
+ }
+
+ /**
+ * Dispose
+ */
+ public void dispose() {
+ Iterator iter = this.factories.values().iterator();
+ URLFactory current;
+ while (iter.hasNext() == true) {
+ current = (URLFactory) iter.next();
+ this.deinit(current);
+ }
+ this.factories = null;
+ }
+
+ /**
+ * Init a url factory
+ */
+ private void init(URLFactory factory, Configuration config)
+ throws ContextException, ComponentException, ConfigurationException {
+ if (factory instanceof Loggable) {
+ ((Loggable) factory).setLogger(getLogger());
+ }
+ if (factory instanceof Contextualizable) {
+ ((Contextualizable) factory).contextualize (this.context);
+ }
+ if (factory instanceof Composable) {
+ ((Composable) factory).compose(this.manager);
+ }
+ if (config != null && factory instanceof Configurable) {
+ ((Configurable) factory).configure(config);
+ }
+ }
+
+ /**
+ * Deinit a url factory
+ */
+ private void deinit(URLFactory factory) {
+ if (factory instanceof Disposable) {
+ ((Disposable) factory).dispose();
+ }
+ }
+
}
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]