You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by sy...@apache.org on 2004/07/13 18:00:12 UTC
cvs commit: cocoon-2.1/src/java/org/apache/cocoon/i18n BundleFactory.java XMLResourceBundleFactory.java
sylvain 2004/07/13 09:00:12
Modified: src/java/org/apache/cocoon/transformation
I18nTransformer.java
src/java/org/apache/cocoon/i18n BundleFactory.java
XMLResourceBundleFactory.java
Log:
Remove BundleFactory "extends ComponentSelector", as it is not a selector. The parent DefaultComponentSelector class was actually just used as a hashmap to store cached bundles.
Revision Changes Path
1.27 +8 -7 cocoon-2.1/src/java/org/apache/cocoon/transformation/I18nTransformer.java
Index: I18nTransformer.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/transformation/I18nTransformer.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- I18nTransformer.java 17 Jun 2004 14:55:24 -0000 1.26
+++ I18nTransformer.java 13 Jul 2004 16:00:12 -0000 1.27
@@ -44,7 +44,8 @@
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.caching.CacheableProcessingComponent;
-import org.apache.cocoon.components.treeprocessor.variables.PreparedVariableResolver;
+import org.apache.cocoon.components.treeprocessor.variables.VariableResolver;
+import org.apache.cocoon.components.treeprocessor.variables.VariableResolverFactory;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.i18n.Bundle;
import org.apache.cocoon.i18n.BundleFactory;
@@ -2151,17 +2152,17 @@
* usage. It is important that releaseCatalog is called when the transformer is recycled.
*/
private final class CatalogueInfo {
- PreparedVariableResolver name;
- PreparedVariableResolver[] locations;
+ VariableResolver name;
+ VariableResolver[] locations;
String resolvedName;
String[] resolvedLocations;
Bundle catalogue;
public CatalogueInfo(String name, String[] locations) throws PatternException {
- this.name = new PreparedVariableResolver(name, manager);
- this.locations = new PreparedVariableResolver[locations.length];
+ this.name = VariableResolverFactory.getResolver(name, manager);
+ this.locations = new VariableResolver[locations.length];
for (int i=0; i < locations.length; ++i) {
- this.locations[i] = new PreparedVariableResolver(locations[i], manager);
+ this.locations[i] = VariableResolverFactory.getResolver(locations[i], manager);
}
}
1.9 +5 -2 cocoon-2.1/src/java/org/apache/cocoon/i18n/BundleFactory.java
Index: BundleFactory.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/i18n/BundleFactory.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- BundleFactory.java 5 Mar 2004 13:02:56 -0000 1.8
+++ BundleFactory.java 13 Jul 2004 16:00:12 -0000 1.9
@@ -17,6 +17,7 @@
import java.util.Locale;
+import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentSelector;
@@ -28,7 +29,7 @@
* @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
* @version CVS $Id$
*/
-public interface BundleFactory extends ComponentSelector {
+public interface BundleFactory extends Component {
/**
* Bundle factory ROLE name
@@ -100,4 +101,6 @@
* @exception ComponentException if a bundle is not found
*/
Bundle select(String bundleName, Locale locale) throws ComponentException;
+
+ void release(Bundle bundle);
}
1.15 +14 -9 cocoon-2.1/src/java/org/apache/cocoon/i18n/XMLResourceBundleFactory.java
Index: XMLResourceBundleFactory.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/i18n/XMLResourceBundleFactory.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- XMLResourceBundleFactory.java 29 Apr 2004 01:00:43 -0000 1.14
+++ XMLResourceBundleFactory.java 13 Jul 2004 16:00:12 -0000 1.15
@@ -16,6 +16,7 @@
package org.apache.cocoon.i18n;
import java.io.IOException;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
@@ -29,6 +30,7 @@
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.logger.LogEnabled;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.service.ServiceException;
@@ -51,9 +53,11 @@
* @author <a href="mailto:kpiroumian@apache.org">Konstantin Piroumian</a>
* @version CVS $Id$
*/
-public class XMLResourceBundleFactory extends DefaultComponentSelector
- implements BundleFactory, Serviceable, Configurable, Disposable, ThreadSafe, LogEnabled {
+public class XMLResourceBundleFactory
+ implements BundleFactory, Serviceable, Configurable, Disposable, ThreadSafe, LogEnabled {
+ protected Map cache = Collections.synchronizedMap(new HashMap());
+
/**
* Should we load bundles to cache on startup or not?
*/
@@ -108,7 +112,7 @@
}
public void dispose() {
- Iterator i = getComponentMap().values().iterator();
+ Iterator i = this.cache.values().iterator();
while (i.hasNext()) {
Object bundle = i.next();
if (bundle instanceof Disposable) {
@@ -321,7 +325,7 @@
return null;
}
- public void release(Component component) {
+ public void release(Bundle bundle) {
// Do nothing
}
@@ -406,17 +410,18 @@
*/
protected XMLResourceBundle selectCached(String fileName) {
XMLResourceBundle bundle = null;
- try {
- bundle = (XMLResourceBundle)super.select(fileName);
+ bundle = (XMLResourceBundle)cache.get(fileName);
+ if (bundle != null) {
bundle.update(fileName);
if (getLogger().isDebugEnabled()) {
getLogger().debug("Returning from cache: " + fileName);
}
- } catch (ComponentException e) {
+ } else {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Not found in cache: " + fileName);
}
}
+
return bundle;
}
@@ -456,7 +461,7 @@
if (getLogger().isDebugEnabled()) {
getLogger().debug("Updating cache: " + fileName);
}
- super.put(fileName, bundle);
+ this.cache.put(fileName, bundle);
}
}
}