vgritsenko 02/01/07 21:44:54
Modified: src/java/org/apache/cocoon/i18n XMLResourceBundle.java
XMLResourceBundleFactory.java
src/java/org/apache/cocoon/transformation
I18nTransformer.java
Log:
Fixing NPE in i18n transformer:
- transformer handles lifecycle of factory only
- factory handles lifecycle of bundle
Todo:
- factory's dispose
Revision Changes Path
1.2 +7 -6
xml-cocoon2/src/java/org/apache/cocoon/i18n/XMLResourceBundle.java
Index: XMLResourceBundle.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/i18n/XMLResourceBundle.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XMLResourceBundle.java 3 Jan 2002 12:31:17 -0000 1.1
+++ XMLResourceBundle.java 8 Jan 2002 05:44:54 -0000 1.2
@@ -32,7 +32,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Mike Engelhart</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Neeme Praks</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Oleg Podolsky</a>
- * @version $Id: XMLResourceBundle.java,v 1.1 2002/01/03 12:31:17 giacomo Exp $
+ * @version $Id: XMLResourceBundle.java,v 1.2 2002/01/08 05:44:54 vgritsenko Exp $
*/
public class XMLResourceBundle
extends ResourceBundle
@@ -78,6 +78,12 @@
}
}
+ public void dispose()
+ {
+ this.manager.release((Component)this.processor);
+ this.processor = null;
+ }
+
/**
* Initalize the bundle
*
@@ -477,10 +483,5 @@
public Enumeration getKeys()
{
return cache.keys();
- }
-
- public void dispose()
- {
- this.manager.release((Component)this.processor);
}
}
1.2 +25 -5
xml-cocoon2/src/java/org/apache/cocoon/i18n/XMLResourceBundleFactory.java
Index: XMLResourceBundleFactory.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/i18n/XMLResourceBundleFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XMLResourceBundleFactory.java 3 Jan 2002 12:31:17 -0000 1.1
+++ XMLResourceBundleFactory.java 8 Jan 2002 05:44:54 -0000 1.2
@@ -8,9 +8,12 @@
//package org.apache.avalon.excalibur.i18n;
package org.apache.cocoon.i18n;
+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.DefaultComponentSelector;
+import org.apache.avalon.framework.component.Composable;
+import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
@@ -30,12 +33,12 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Mike Engelhart</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Neeme Praks</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Oleg Podolsky</a>
- * @version $Id: XMLResourceBundleFactory.java,v 1.1 2002/01/03 12:31:17 giacomo
Exp $
+ * @version $Id: XMLResourceBundleFactory.java,v 1.2 2002/01/08 05:44:54 vgritsenko
Exp $
*/
public class XMLResourceBundleFactory
extends DefaultComponentSelector
- implements Configurable, Loggable, ThreadSafe
+ implements Configurable, Composable, Loggable, Disposable, ThreadSafe
{
/** Should we load bundles to cache on startup or not? */
protected boolean cacheAtStartup = false;
@@ -49,6 +52,9 @@
/** The logger */
protected Logger logger;
+ /** Component Manager */
+ protected ComponentManager manager = null;
+
/** Constants for configuration keys */
public static class ConfigurationKeys
{
@@ -63,6 +69,15 @@
{
}
+ public void compose(ComponentManager manager) {
+ this.manager = manager;
+ }
+
+ public void dispose() {
+ // FIXME: Need to go through all bundles and call dispose() on them
+ this.manager = null;
+ }
+
/**
* Set the logger.
*
@@ -277,19 +292,24 @@
parentBundle = (XMLResourceBundle) selectParent(name, loc);
bundle = new XMLResourceBundle();
bundle.setLogger(logger);
+ bundle.compose(this.manager);
bundle.init(name, fileName, loc, parentBundle, cacheAtStartup);
+ return bundle;
}
catch (SAXParseException e)
{
if (logger.isInfoEnabled()) logger.info("Resource loading failed: " +
e.getMessage());
- bundle = null;
}
catch (Exception e)
{
logger.error("Error while loading resource: " + name + ", locale " +
loc + ", bundleName " + fileName, e);
- bundle = null;
}
- return bundle;
+ return null;
+ }
+
+ public void release(Component component)
+ {
+ // Do nothing
}
/**
1.3 +18 -8
xml-cocoon2/src/java/org/apache/cocoon/transformation/I18nTransformer.java
Index: I18nTransformer.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/transformation/I18nTransformer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- I18nTransformer.java 7 Jan 2002 13:09:02 -0000 1.2
+++ I18nTransformer.java 8 Jan 2002 05:44:54 -0000 1.3
@@ -10,6 +10,7 @@
package org.apache.cocoon.transformation;
import org.apache.avalon.excalibur.pool.Poolable;
+import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.component.Composable;
import org.apache.avalon.framework.configuration.Configurable;
@@ -188,7 +189,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Michael Enke</a>
*/
public class I18nTransformer extends AbstractTransformer
- implements Composable, Poolable, Configurable, Recyclable {
+ implements Composable, Poolable, Configurable, Recyclable, Disposable {
private static final String FILE = "file:";
@@ -336,6 +337,10 @@
* Dictionary data.
*/
private XMLResourceBundle dictionary;
+
+ // FIXME: Shouldn't factory be the global component?
+ // Now every I18nTransformer have own instance of factory
+ // every of which in turn have own file cache.
private XMLResourceBundleFactory factory = new XMLResourceBundleFactory();
/*
@@ -442,13 +447,10 @@
debug( "using locale " + locale.toString() );
dictionary =
- (XMLResourceBundle) factory.select(
- localCatName == null ? catalogueName : localCatName,
- locale
- );
-
- //FIXME(DIMS): Why should i do this explicitly? Is there an alternative?
- dictionary.compose( this.manager );
+ (XMLResourceBundle) factory.select(
+ localCatName == null ? catalogueName : localCatName,
+ locale
+ );
debug( "selected dictionary " + dictionary );
@@ -504,6 +506,7 @@
public void compose( ComponentManager manager ) {
this.manager = manager;
+ factory.compose( manager );
}
public void startElement( String uri, String name, String raw,
@@ -1201,5 +1204,12 @@
untranslated = globalUntranslated;
debug( "untranslated-text restored to " + untranslated );
}
+ factory.release(dictionary);
+ dictionary = null;
+ }
+
+ public void dispose() {
+ factory.dispose();
+ factory = null;
}
}
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]