cziegeler 2003/03/20 04:28:45
Modified: src/java/org/apache/cocoon/components/modules/input
SitemapVariableHolder.java
. changes.xml
src/java/org/apache/cocoon/components
DefaultSitemapConfigurationHolder.java
Log:
Finishing refactoring SitemapConfigurable
Revision Changes Path
1.4 +28 -40
cocoon-2.1/src/java/org/apache/cocoon/components/modules/input/SitemapVariableHolder.java
Index: SitemapVariableHolder.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/modules/input/SitemapVariableHolder.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SitemapVariableHolder.java 20 Mar 2003 11:45:58 -0000 1.3
+++ SitemapVariableHolder.java 20 Mar 2003 12:28:45 -0000 1.4
@@ -54,12 +54,13 @@
import java.util.Iterator;
import java.util.Map;
-import org.apache.avalon.excalibur.pool.Recyclable;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.cocoon.components.ChainedConfiguration;
import org.apache.cocoon.components.SitemapConfigurable;
import org.apache.cocoon.components.SitemapConfigurationHolder;
@@ -72,7 +73,7 @@
*/
public final class SitemapVariableHolder
extends AbstractLogEnabled
- implements Component, Configurable, SitemapConfigurable, Recyclable
+ implements Component, Configurable, SitemapConfigurable, ThreadSafe
{
public static final String ROLE = SitemapVariableHolder.class.getName();
@@ -81,10 +82,10 @@
* Stores (global) configuration parameters as <code>key</code> /
* <code>value</code> pairs from the component configuration
*/
- private Map values;
+ private Map globalValues;
/** Manager for sitemap/sub sitemap configuration */
- private Manager manager;
+ private SitemapConfigurationHolder holder;
/**
* Configures the database access helper.
@@ -98,13 +99,12 @@
* */
public void configure(Configuration conf)
throws ConfigurationException {
- this.manager = new Manager();
final Configuration[] parameters = conf.getChildren();
- this.values = new HashMap(parameters.length);
+ this.globalValues = new HashMap(parameters.length);
for (int i = 0; i < parameters.length; i++) {
final String key = parameters[i].getName();
final String value = parameters[i].getValue();
- this.values.put(key, value);
+ this.globalValues.put(key, value);
}
}
@@ -113,61 +113,49 @@
*/
public void configure(SitemapConfigurationHolder holder)
throws ConfigurationException {
- // add sitemap configuration
- this.manager.add(holder.getConfiguration());
- }
-
- /**
- * Recyclable
- */
- public void recycle() {
- // clear sitemap configuration
- this.manager.init(this.values);
+ this.holder = holder;
}
/**
* Get a value
*/
public Object get(String key) {
- return this.manager.get(key);
+ return this.getValues().get(key);
}
/**
* Get keys
*/
public Iterator getKeys() {
- return this.manager.getKeys();
+ return this.getValues().keySet().iterator();
}
-}
-
-final class Manager {
- private Map values = new HashMap();
-
- void init(Map newValues) {
- this.values.clear();
- this.values.putAll(newValues);
+ protected Map getValues() {
+ Map values = (Map)this.holder.getPreparedConfiguration();
+ if ( null == values ) {
+ values = new HashMap(this.globalValues);
+ ChainedConfiguration conf = this.holder.getConfiguration();
+ this.prepare(conf, values);
+ this.holder.setPreparedConfiguration(conf, values);
+ }
+ return values;
}
- void add(Configuration conf)
- throws ConfigurationException {
+ protected void prepare(ChainedConfiguration conf, Map values) {
+ ChainedConfiguration parent = conf.getParent();
+ if ( null != parent) {
+ this.prepare(parent, values);
+ }
final Configuration[] parameters = conf.getChildren();
final int len = parameters.length;
- this.values = new HashMap( len );
for ( int i = 0; i < len; i++) {
final String key = parameters[i].getName();
- final String value = parameters[i].getValue();
+ final String value = parameters[i].getValue("");
if ( key != null && value != null) {
- this.values.put(key, value);
+ values.put(key, value);
}
}
}
- Object get(String key) {
- return this.values.get(key);
- }
-
- Iterator getKeys() {
- return this.values.keySet().iterator();
- }
}
+
1.11 +6 -1 cocoon-2.1/changes.xml
Index: changes.xml
===================================================================
RCS file: /home/cvs/cocoon-2.1/changes.xml,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- changes.xml 19 Mar 2003 15:42:13 -0000 1.10
+++ changes.xml 20 Mar 2003 12:28:45 -0000 1.11
@@ -43,6 +43,11 @@
<release version="@version@" date="@date@">
<action dev="CZ" type="update">
+ Refactored SitemapConfigurable. A sitemap configurable component can
+ now be ThreadSafe and has access to the sitemap configuration at any time
+ through a SitemapConfigurationHolder.
+ </action>
+ <action dev="CZ" type="update">
Correcting method names of new CacheableProcessingComponent interface.
It's now possible to write components that support the 2.0.x and the
2.1.x caching algorithm.
1.2 +18 -2
cocoon-2.1/src/java/org/apache/cocoon/components/DefaultSitemapConfigurationHolder.java
Index: DefaultSitemapConfigurationHolder.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/DefaultSitemapConfigurationHolder.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DefaultSitemapConfigurationHolder.java 20 Mar 2003 11:45:58 -0000 1.1
+++ DefaultSitemapConfigurationHolder.java 20 Mar 2003 12:28:45 -0000 1.2
@@ -50,6 +50,7 @@
*/
package org.apache.cocoon.components;
+import java.util.HashMap;
import java.util.Map;
/**
@@ -60,8 +61,12 @@
public final class DefaultSitemapConfigurationHolder
implements SitemapConfigurationHolder {
+ /** The role of the sitemap component */
private String role;
+ /** The prepared configurations indexed by the ChainedConfiguration */
+ private Map preparedConfigurations;
+
public DefaultSitemapConfigurationHolder(String role) {
this.role = role;
}
@@ -78,13 +83,24 @@
* @see
org.apache.cocoon.components.SitemapConfigurationHolder#getPreparedConfiguration()
*/
public Object getPreparedConfiguration() {
+ if ( null != this.preparedConfigurations ) {
+ ChainedConfiguration conf = this.getConfiguration();
+ if ( null != conf ) {
+ return this.preparedConfigurations.get( conf );
+ }
+ }
return null;
}
/**
* @see
org.apache.cocoon.components.SitemapConfigurationHolder#setPreparedConfiguration(java.lang.Object)
*/
- public void setPreparedConfiguration(ChainedConfiguration configuration, Object
preparedConfig) {
+ public void setPreparedConfiguration(ChainedConfiguration configuration,
+ Object preparedConfig) {
+ if ( null == this.preparedConfigurations ) {
+ this.preparedConfigurations = new HashMap(5);
+ }
+ this.preparedConfigurations.put(configuration, preparedConfig);
}
}