bloritsch 2003/10/22 10:38:16
Modified: src/java/org/apache/cocoon/components CocoonContainer.java
src/java/org/apache/cocoon/bean CocoonBean.java
Log:
Finish CocoonContainer and CocoonBean
Revision Changes Path
1.6 +45 -1
cocoon-2.2/src/java/org/apache/cocoon/components/CocoonContainer.java
Index: CocoonContainer.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/components/CocoonContainer.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- CocoonContainer.java 22 Oct 2003 15:37:50 -0000 1.5
+++ CocoonContainer.java 22 Oct 2003 17:38:16 -0000 1.6
@@ -49,19 +49,30 @@
*/
package org.apache.cocoon.components;
+import org.apache.avalon.fortress.impl.AbstractContainer;
import org.apache.avalon.fortress.impl.DefaultContainer;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.service.ServiceException;
import org.apache.cocoon.Constants;
+import java.util.Map;
+
/**
- * CocoonContainer does XYZ
+ * Customize the Fortress container to handle Cocoon semantics.
*
* @author <a href="bloritsch.at.apache.org">Berin Loritsch</a>
* @version CVS $ Revision: 1.1 $
*/
public abstract class CocoonContainer extends DefaultContainer
{
+ /**
+ * Provide some validation for the core Cocoon components
+ *
+ * @param conf The configuration
+ *
+ * @throws ConfigurationException if the coniguration is invalid
+ */
public void configure(Configuration conf) throws ConfigurationException
{
if ( ! "cocoon".equals(conf.getName()) ) throw new
ConfigurationException("Invalid configuration format", conf);
@@ -70,5 +81,38 @@
if ( ! Constants.CONF_VERSION.equals(confVersion) ) throw new
ConfigurationException("Uncompatible configuration format", conf);
super.configure(conf);
+ }
+
+ /**
+ * Ensure that we return the latest and greatest component for the
role/hint combo if possible.
+ * Otherwise default to normal behavior.
+ *
+ * @param role The role of the component we are looking up.
+ * @param hint The hint for the component we are looking up.
+ *
+ * @return The component for the role/hint combo
+ * @throws ServiceException if the role/hint combo cannot be resolved.
+ */
+ public Object get(final String role, final Object hint) throws
ServiceException
+ {
+ Object component = null;
+
+ if (null != hint
+ && !AbstractContainer.DEFAULT_ENTRY.equals(hint)
+ && !AbstractContainer.SELECTOR_ENTRY.equals(hint))
+ {
+ Map implementations = (Map)m_mapper.get(role);
+ if (null != implementations)
+ {
+ component = implementations.get(hint);
+ }
+ }
+
+ if (null == component)
+ {
+ component = super.get(role, hint);
+ }
+
+ return component;
}
}
1.41 +33 -24
cocoon-2.2/src/java/org/apache/cocoon/bean/CocoonBean.java
Index: CocoonBean.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/bean/CocoonBean.java,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -r1.40 -r1.41
--- CocoonBean.java 22 Oct 2003 16:21:16 -0000 1.40
+++ CocoonBean.java 22 Oct 2003 17:38:16 -0000 1.41
@@ -52,6 +52,7 @@
import org.apache.avalon.fortress.ContainerManager;
import org.apache.avalon.fortress.impl.DefaultContainerManager;
import org.apache.avalon.fortress.util.FortressConfig;
+import org.apache.avalon.fortress.util.LifecycleExtensionManager;
import org.apache.avalon.framework.CascadingRuntimeException;
import org.apache.avalon.framework.container.ContainerUtil;
import org.apache.avalon.framework.context.DefaultContext;
@@ -62,6 +63,7 @@
import org.apache.cocoon.CompilingProcessor;
import org.apache.cocoon.Constants;
import org.apache.cocoon.components.CocoonContainer;
+import org.apache.cocoon.components.SitemapConfigurableAccessor;
import java.io.File;
import java.util.*;
@@ -255,6 +257,28 @@
m_classPath = classPath;
}
+ public void setProperty( String key, Object value )
+ {
+ if ( null == value )
+ {
+ m_properties.remove( key );
+ }
+ else
+ {
+ m_properties.put( key, value );
+ }
+ }
+
+ public Object getProperty( String key )
+ {
+ return m_properties.get( key );
+ }
+
+ public void clearAllProperties()
+ {
+ m_properties.clear();
+ }
+
public void initialize() throws Exception
{
// restart....
@@ -276,8 +300,7 @@
m_confBuilder.setCommandFailureHandlerClass(
CocoonCommandFailureHandler.class );
m_confBuilder.setContainerClass(CocoonContainer.class);
- // TODO: implement this.
- //m_confBuilder.setLifecycleExtensionManager( m_lifecycleExtensions
);
+ m_confBuilder.setLifecycleExtensionManager(
getLifecycleExtensionManager() );
DefaultContext initContext = new DefaultContext(
m_confBuilder.getContext() );
Iterator it = m_properties.entrySet().iterator();
@@ -291,6 +314,14 @@
ContainerUtil.initialize( m_contManager );
}
+ private LifecycleExtensionManager getLifecycleExtensionManager()
+ {
+ LifecycleExtensionManager manager = new LifecycleExtensionManager();
+ manager.addAccessorExtension(new SitemapConfigurableAccessor());
+
+ return manager;
+ }
+
private void forceLoadClasses()
{
if ( m_alreadyLoaded ) return;
@@ -327,27 +358,5 @@
{
dispose();
super.finalize();
- }
-
- public void setProperty( String key, Object value )
- {
- if ( null == value )
- {
- m_properties.remove(key);
- }
- else
- {
- m_properties.put(key, value);
- }
- }
-
- public Object getProperty( String key )
- {
- return m_properties.get(key);
- }
-
- public void clearAllProperties()
- {
- m_properties.clear();
}
}