You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2003/06/18 13:06:32 UTC
cvs commit: cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap ComponentsSelector.java SitemapLanguage.java
cziegeler 2003/06/18 04:06:31
Modified: . status.xml
src/java/org/apache/cocoon/components
ExtendedComponentSelector.java
CocoonComponentManager.java
src/java/org/apache/cocoon/components/treeprocessor/sitemap
ComponentsSelector.java SitemapLanguage.java
Added: src/java/org/apache/cocoon/components ParentAware.java
ComponentLocatorImpl.java ComponentLocator.java
Log:
Adding the concept of parent aware components (designed by Sylvain)
Revision Changes Path
1.57 +4 -0 cocoon-2.1/status.xml
Index: status.xml
===================================================================
RCS file: /home/cvs/cocoon-2.1/status.xml,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -r1.56 -r1.57
--- status.xml 17 Jun 2003 13:41:25 -0000 1.56
+++ status.xml 18 Jun 2003 11:06:31 -0000 1.57
@@ -181,6 +181,10 @@
<changes>
<release version="@version@" date="@date@">
+ <action dev="CZ" type="add">
+ Adding concept of parent-aware components, making e.g. the usage of
+ selectors with a component manager hierarchy much easier.
+ </action>
<action dev="JH" type="fix" fixes-bug="15365" due-to="Maciek Kaminski" due-to-email=" maciejka@tiger.com.pl">
Added/fixed internationalization support for HSSFSerializer by setting the output encoding
hardcoded to UTF-16. It's obviously only a hack, but so it's at least usable for more people.
1.2 +39 -10 cocoon-2.1/src/java/org/apache/cocoon/components/ExtendedComponentSelector.java
Index: ExtendedComponentSelector.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/ExtendedComponentSelector.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ExtendedComponentSelector.java 9 Mar 2003 00:08:46 -0000 1.1
+++ ExtendedComponentSelector.java 18 Jun 2003 11:06:31 -0000 1.2
@@ -50,19 +50,18 @@
*/
package org.apache.cocoon.components;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.avalon.excalibur.component.ExcaliburComponentSelector;
+import org.apache.avalon.excalibur.component.RoleManager;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentSelector;
-
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
-import org.apache.avalon.excalibur.component.ExcaliburComponentSelector;
-import org.apache.avalon.excalibur.component.RoleManager;
-
-import java.util.*;
-
/**
* An extension of <code>ExcaliburComponentSelector</code> that can have a parent
* and accepts a wider variety of configurations.
@@ -71,7 +70,9 @@
* @version CVS $Id$
*/
-public class ExtendedComponentSelector extends ExcaliburComponentSelector {
+public class ExtendedComponentSelector
+ extends ExcaliburComponentSelector
+ implements ParentAware {
/** The role manager */
protected RoleManager roles;
@@ -79,6 +80,9 @@
/** The parent selector, if any */
protected ComponentSelector parentSelector;
+ /** The parent locator, if any */
+ protected ComponentLocator parentLocator;
+
/** The class loader to use */
protected ClassLoader classLoader;
@@ -162,14 +166,14 @@
* @param parent the parent selector
* @throws IllegalStateException if parent is already set
*/
- public void setParentSelector(ComponentSelector parent) {
+/* public void setParentSelector(ComponentSelector parent) {
if (this.parentSelector != null) {
throw new IllegalStateException("Parent selector is already set");
}
this.parentSelector = parent;
this.parentComponents = new HashSet();
}
-
+*/
/**
* Get the role name for this selector. This is called by <code>configure()</code>
* to set the value of <code>this.roleName</code>.
@@ -323,6 +327,31 @@
exists = this.parentSelector.hasComponent( hint );
}
return exists;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.components.ParentAware#setParentInformation(org.apache.avalon.framework.component.ComponentManager, java.lang.String)
+ */
+ public void setParentLocator(ComponentLocator locator)
+ throws ComponentException {
+ if (this.parentSelector != null) {
+ throw new ComponentException("Parent selector is already set");
+ }
+ this.parentLocator = locator;
+ this.parentSelector = (ComponentSelector) locator.lookup();
+ this.parentComponents = new HashSet();
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.avalon.framework.activity.Disposable#dispose()
+ */
+ public void dispose() {
+ super.dispose();
+ if ( this.parentLocator != null ) {
+ this.parentLocator.release( this.parentSelector );
+ this.parentLocator = null;
+ this.parentSelector = null;
+ }
}
}
1.12 +32 -3 cocoon-2.1/src/java/org/apache/cocoon/components/CocoonComponentManager.java
Index: CocoonComponentManager.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/CocoonComponentManager.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- CocoonComponentManager.java 29 Apr 2003 10:45:22 -0000 1.11
+++ CocoonComponentManager.java 18 Jun 2003 11:06:31 -0000 1.12
@@ -51,11 +51,13 @@
package org.apache.cocoon.components;
import java.io.IOException;
+import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+
import org.apache.avalon.excalibur.component.ExcaliburComponentManager;
import org.apache.avalon.excalibur.component.RoleManager;
import org.apache.avalon.framework.component.Component;
@@ -63,12 +65,11 @@
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.component.ComponentSelector;
import org.apache.avalon.framework.component.Recomposable;
+import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.Processor;
import org.apache.cocoon.environment.Environment;
-
-import java.net.MalformedURLException;
import org.apache.excalibur.source.Source;
import org.apache.excalibur.source.SourceException;
import org.apache.excalibur.source.SourceResolver;
@@ -108,6 +109,9 @@
/** The {@link SitemapConfigurationHolder}s */
private Map sitemapConfigurationHolders = new HashMap(15);
+ /** The parent component manager for implementing parent aware components */
+ private ComponentManager parentManager;
+
/** Create the ComponentManager */
public CocoonComponentManager() {
super( null, Thread.currentThread().getContextClassLoader() );
@@ -121,11 +125,13 @@
/** Create the ComponentManager with a Classloader and parent ComponentManager */
public CocoonComponentManager(final ComponentManager manager, final ClassLoader loader) {
super( manager, loader );
+ this.parentManager = manager;
}
/** Create the ComponentManager with a parent ComponentManager */
public CocoonComponentManager(final ComponentManager manager) {
super( manager);
+ this.parentManager = manager;
}
/**
@@ -455,6 +461,29 @@
*/
public void release( final Source source ) {
this.sourceResolver.release( source );
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.avalon.excalibur.component.ExcaliburComponentManager#addComponent(java.lang.String, java.lang.Class, org.apache.avalon.framework.configuration.Configuration)
+ */
+ public void addComponent(String role, Class clazz, Configuration conf)
+ throws ComponentException {
+ super.addComponent(role, clazz, conf);
+ if ( ParentAware.class.isAssignableFrom( clazz ) ) {
+ if ( parentManager != null && parentManager.hasComponent( role ) ) {
+ // lookup new component
+ Component component = null;
+ try {
+ component = this.lookup( role );
+ ((ParentAware)component).setParentLocator( new ComponentLocatorImpl(this.parentManager, role ));
+ } catch (ComponentException ignore) {
+ // we don't set the parent then
+ } finally {
+ this.release( component );
+ }
+
+ }
+ }
}
}
1.1 cocoon-2.1/src/java/org/apache/cocoon/components/ParentAware.java
Index: ParentAware.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Apache Cocoon" and "Apache Software Foundation" must not be
used to endorse or promote products derived from this software without
prior written permission. For written permission, please contact
apache@apache.org.
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
Stefano Mazzocchi <st...@apache.org>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.cocoon.components;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.thread.ThreadSafe;
/**
* Components acception this marker interface indicate that they want
* to have a reference to their parent.
* This is for example used for selectors.
* Note: For the current implementation to work, the parent aware
* component and the parent have to be both ThreadSafe!
*
* @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
* @version CVS $Id: ParentAware.java,v 1.1 2003/06/18 11:06:31 cziegeler Exp $
*/
public interface ParentAware
extends ThreadSafe {
/**
* Set the parent component manager and the role name
*/
void setParentLocator(ComponentLocator locator)
throws ComponentException;
}
1.1 cocoon-2.1/src/java/org/apache/cocoon/components/ComponentLocatorImpl.java
Index: ComponentLocatorImpl.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Apache Cocoon" and "Apache Software Foundation" must not be
used to endorse or promote products derived from this software without
prior written permission. For written permission, please contact
apache@apache.org.
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
Stefano Mazzocchi <st...@apache.org>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.cocoon.components;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentManager;
/**
* This object is set to a {@link ParentAware} component and allows
* access to the parent component.
*
* @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
* @version CVS $Id: ComponentLocatorImpl.java,v 1.1 2003/06/18 11:06:31 cziegeler Exp $
*/
public class ComponentLocatorImpl
implements ComponentLocator {
protected ComponentManager manager;
protected String role;
public ComponentLocatorImpl(ComponentManager manager, String role) {
this.manager = manager;
this.role = role;
}
public Object lookup()
throws ComponentException {
return this.manager.lookup( this.role );
}
public void release(Object parent) {
this.manager.release( (Component) parent);
}
}
1.1 cocoon-2.1/src/java/org/apache/cocoon/components/ComponentLocator.java
Index: ComponentLocator.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Apache Cocoon" and "Apache Software Foundation" must not be
used to endorse or promote products derived from this software without
prior written permission. For written permission, please contact
apache@apache.org.
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
Stefano Mazzocchi <st...@apache.org>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.cocoon.components;
import org.apache.avalon.framework.component.ComponentException;
/**
* This object is set to a {@link ParentAware} component and allows
* access to the parent component.
*
* @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
* @version CVS $Id: ComponentLocator.java,v 1.1 2003/06/18 11:06:31 cziegeler Exp $
*/
public interface ComponentLocator {
Object lookup()
throws ComponentException;
void release(Object parent);
}
1.3 +18 -12 cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap/ComponentsSelector.java
Index: ComponentsSelector.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap/ComponentsSelector.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ComponentsSelector.java 18 Mar 2003 15:23:28 -0000 1.2
+++ ComponentsSelector.java 18 Jun 2003 11:06:31 -0000 1.3
@@ -50,18 +50,22 @@
*/
package org.apache.cocoon.components.treeprocessor.sitemap;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.StringTokenizer;
+
import org.apache.avalon.framework.CascadingRuntimeException;
import org.apache.avalon.framework.component.ComponentException;
-import org.apache.avalon.framework.component.ComponentSelector;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
-
+import org.apache.cocoon.acting.Action;
+import org.apache.cocoon.components.ExtendedComponentSelector;
+import org.apache.cocoon.components.ComponentLocator;
import org.apache.cocoon.components.pipeline.OutputComponentSelector;
import org.apache.cocoon.components.pipeline.ProcessingPipeline;
-import org.apache.cocoon.components.ExtendedComponentSelector;
-
-import org.apache.cocoon.acting.Action;
import org.apache.cocoon.generation.Generator;
import org.apache.cocoon.matching.Matcher;
import org.apache.cocoon.reading.Reader;
@@ -70,8 +74,6 @@
import org.apache.cocoon.sitemap.SitemapComponentSelector;
import org.apache.cocoon.transformation.Transformer;
-import java.util.*;
-
/**
* Component selector for sitemap components.
*
@@ -133,11 +135,15 @@
/** The parent selector, if it's of the current class */
private SitemapComponentSelector parentSitemapSelector;
- public void setParentSelector(ComponentSelector selector) {
- super.setParentSelector(selector);
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.components.ParentAware#setParentInformation(org.apache.avalon.framework.component.ComponentManager, java.lang.String)
+ */
+ public void setParentLocator(ComponentLocator locator)
+ throws ComponentException {
+ super.setParentLocator(locator);
- if (selector instanceof SitemapComponentSelector) {
- this.parentSitemapSelector = (SitemapComponentSelector)selector;
+ if (this.parentSelector instanceof SitemapComponentSelector) {
+ this.parentSitemapSelector = (SitemapComponentSelector)this.parentSelector;
}
}
1.4 +3 -40 cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
Index: SitemapLanguage.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SitemapLanguage.java 1 Apr 2003 21:25:09 -0000 1.3
+++ SitemapLanguage.java 18 Jun 2003 11:06:31 -0000 1.4
@@ -50,13 +50,13 @@
*/
package org.apache.cocoon.components.treeprocessor.sitemap;
+import java.util.*;
+
import org.apache.avalon.framework.component.ComponentManager;
-import org.apache.avalon.framework.component.ComponentSelector;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.cocoon.components.CocoonComponentManager;
-import org.apache.cocoon.components.ExtendedComponentSelector;
import org.apache.cocoon.components.LifecycleHelper;
import org.apache.cocoon.components.treeprocessor.CategoryNode;
import org.apache.cocoon.components.treeprocessor.CategoryNodeBuilder;
@@ -69,8 +69,6 @@
import org.apache.cocoon.util.StringUtils;
import org.apache.regexp.RE;
-import java.util.*;
-
/**
* The tree builder for the sitemap language.
*
@@ -111,41 +109,6 @@
this.logKit,
config
);
-
- // Set parent of all selectors.
- if (this.parentManager != null) {
-
- for (int i = 0; i < ComponentsSelector.SELECTOR_ROLES.length; i++) {
-
- String role = ComponentsSelector.SELECTOR_ROLES[i];
-
- ComponentSelector parentSelector = null;
- try {
- parentSelector = (ComponentSelector)this.parentManager.lookup(role);
- } catch(Exception e) {
- // ignore and keep it null
- }
-
- if (parentSelector != null) {
-
- ExtendedComponentSelector localSelector = null;
- try {
- localSelector = (ExtendedComponentSelector)manager.lookup(role);
-
- if (localSelector != parentSelector) {
- // local selector wasn't given by chaining to the parent manager
- localSelector.setParentSelector(parentSelector);
- }
- manager.release(localSelector);
-
- } catch(Exception e) {
- // ignore
- }
-
- parentManager.release(parentSelector);
- }
- }
- }
return manager;
}