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 2006/02/20 19:57:58 UTC

svn commit: r379200 - in /cocoon/trunk: cocoon-blocks-fw/cocoon-blocks-fw-ecm-impl/src/main/java/org/apache/cocoon/components/ cocoon-blocks-fw/cocoon-blocks-fw-ecm-impl/src/main/java/org/apache/cocoon/components/container/ cocoon-blocks-fw/cocoon-bloc...

Author: cziegeler
Date: Mon Feb 20 10:57:53 2006
New Revision: 379200

URL: http://svn.apache.org/viewcvs?rev=379200&view=rev
Log:
Move ECM++ out of core

Added:
    cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-ecm-impl/src/main/java/org/apache/cocoon/components/
    cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-ecm-impl/src/main/java/org/apache/cocoon/components/ComponentInfo.java
      - copied unchanged from r378888, cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/ComponentInfo.java
    cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-ecm-impl/src/main/java/org/apache/cocoon/components/container/
    cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-ecm-impl/src/main/java/org/apache/cocoon/components/container/CocoonServiceManager.java
      - copied, changed from r378888, cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/container/CocoonServiceManager.java
    cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-ecm-impl/src/main/java/org/apache/cocoon/components/treeprocessor/
    cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-ecm-impl/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/
    cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-ecm-impl/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ComponentsSelector.java
      - copied unchanged from r378888, cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ComponentsSelector.java
    cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-ecm-impl/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ProcessorComponentInfo.java   (with props)
    cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-ecm-impl/src/main/java/org/apache/cocoon/core/
    cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-ecm-impl/src/main/java/org/apache/cocoon/core/container/
    cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-ecm-impl/src/main/java/org/apache/cocoon/core/container/ComponentEnvironment.java
      - copied unchanged from r378888, cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/ComponentEnvironment.java
    cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-ecm-impl/src/main/java/org/apache/cocoon/core/container/ComponentFactory.java
      - copied unchanged from r378888, cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/ComponentFactory.java
    cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-ecm-impl/src/main/java/org/apache/cocoon/core/container/CoreServiceManager.java
      - copied unchanged from r379105, cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/CoreServiceManager.java
    cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-ecm-impl/src/main/java/org/apache/cocoon/core/container/DefaultServiceSelector.java
      - copied unchanged from r378888, cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/DefaultServiceSelector.java
    cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-ecm-impl/src/main/java/org/apache/cocoon/core/container/RoleManager.java
      - copied unchanged from r378888, cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/RoleManager.java
    cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-ecm-impl/src/main/java/org/apache/cocoon/core/container/RoleManagerOwner.java
      - copied unchanged from r378888, cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/RoleManagerOwner.java
    cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-ecm-impl/src/main/java/org/apache/cocoon/core/container/ServiceNotFoundException.java
      - copied unchanged from r378888, cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/ServiceNotFoundException.java
    cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-ecm-impl/src/main/java/org/apache/cocoon/core/container/SingleComponentServiceManager.java
      - copied unchanged from r378888, cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/SingleComponentServiceManager.java
    cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-ecm-impl/src/main/java/org/apache/cocoon/core/container/StandaloneServiceSelector.java
      - copied unchanged from r378888, cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/StandaloneServiceSelector.java
    cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-ecm-impl/src/main/java/org/apache/cocoon/core/container/handler/
      - copied from r378888, cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/handler/
    cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-ecm-impl/src/main/java/org/apache/cocoon/util/
    cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-ecm-impl/src/main/java/org/apache/cocoon/util/JMXUtils.java
      - copied unchanged from r378888, cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/util/JMXUtils.java
    cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/StandaloneServiceSelector.java   (with props)
Removed:
    cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/ComponentInfo.java
    cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/container/CocoonServiceManager.java
    cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ComponentsSelector.java
    cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/ComponentEnvironment.java
    cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/ComponentFactory.java
    cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/CoreServiceManager.java
    cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/DefaultServiceSelector.java
    cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/RoleManager.java
    cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/RoleManagerOwner.java
    cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/ServiceNotFoundException.java
    cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/SingleComponentServiceManager.java
    cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/StandaloneServiceSelector.java
    cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/handler/
    cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/servlet/LoggerUtil.java
    cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/util/JMXUtils.java
Modified:
    cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-servlet-impl/src/main/java/org/apache/cocoon/blocks/servlet/BlocksManager.java
    cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/container/DefaultSitemapConfigurationHolder.java
    cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/DefaultTreeBuilder.java
    cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/ProcessorComponentInfo.java
    cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ApplicationContextFactory.java
    cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonXmlWebApplicationContext.java

Copied: cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-ecm-impl/src/main/java/org/apache/cocoon/components/container/CocoonServiceManager.java (from r378888, cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/container/CocoonServiceManager.java)
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-ecm-impl/src/main/java/org/apache/cocoon/components/container/CocoonServiceManager.java?p2=cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-ecm-impl/src/main/java/org/apache/cocoon/components/container/CocoonServiceManager.java&p1=cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/container/CocoonServiceManager.java&r1=378888&r2=379200&rev=379200&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/container/CocoonServiceManager.java (original)
+++ cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-ecm-impl/src/main/java/org/apache/cocoon/components/container/CocoonServiceManager.java Mon Feb 20 10:57:53 2006
@@ -16,17 +16,17 @@
  */
 package org.apache.cocoon.components.container;
 
-import java.util.HashMap;
-import java.util.Map;
+//import java.util.HashMap;
+//import java.util.Map;
 
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.cocoon.components.ComponentInfo;
-import org.apache.cocoon.components.SitemapConfigurable;
+//import org.apache.cocoon.components.SitemapConfigurable;
 import org.apache.cocoon.components.SitemapConfigurationHolder;
-import org.apache.cocoon.components.treeprocessor.ProcessorComponentInfo;
+import org.apache.cocoon.components.treeprocessor.sitemap.ProcessorComponentInfo;
 import org.apache.cocoon.core.container.CoreServiceManager;
 
 /**
@@ -37,7 +37,7 @@
 public class CocoonServiceManager extends CoreServiceManager {
     
     /** The {@link SitemapConfigurationHolder}s */
-    private Map sitemapConfigurationHolders = new HashMap(15);
+    //private Map sitemapConfigurationHolders = new HashMap(15);
     
     private ProcessorComponentInfo info;
 
@@ -86,6 +86,7 @@
      */
     protected void initialize(String role, Object component) throws ServiceException {
         super.initialize(role, component);
+        /*
         if ( null != component && component instanceof SitemapConfigurable) {
 
             // FIXME: how can we prevent that this is called over and over again?
@@ -104,5 +105,6 @@
                 throw new ServiceException(role, "Exception during setup of SitemapConfigurable.", ce);
             }
         }
+        */
     }
 }

Added: cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-ecm-impl/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ProcessorComponentInfo.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-ecm-impl/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ProcessorComponentInfo.java?rev=379200&view=auto
==============================================================================
--- cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-ecm-impl/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ProcessorComponentInfo.java (added)
+++ cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-ecm-impl/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ProcessorComponentInfo.java Mon Feb 20 10:57:53 2006
@@ -0,0 +1,95 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.components.treeprocessor.sitemap;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
+import org.apache.cocoon.acting.Action;
+import org.apache.cocoon.components.ComponentInfo;
+import org.apache.cocoon.components.pipeline.ProcessingPipeline;
+import org.apache.cocoon.core.container.DefaultServiceSelector;
+import org.apache.cocoon.generation.Generator;
+import org.apache.cocoon.matching.Matcher;
+import org.apache.cocoon.reading.Reader;
+import org.apache.cocoon.selection.Selector;
+import org.apache.cocoon.serialization.Serializer;
+import org.apache.cocoon.transformation.Transformer;
+
+/**
+ * Holds informations defined in <map:components> such as default hint, labels and mime-types
+ * that are needed when building a processor and to manage inheritance when building child processors.
+ * <p>
+ * In previous versions of the sitemap engine, these informations where store in specialized
+ * extensions of ComponentSelector (<code>SitemapComponentSelector</code> and
+ * <code>OutputComponentSelector</code>), which led to a strong dependency on the chosen component
+ * container implementation. This is now a regular component that also "listens" to modifications
+ * of the service manager when it is built.
+ * 
+ * @version $Id$
+ */
+public class ProcessorComponentInfo extends org.apache.cocoon.components.treeprocessor.ProcessorComponentInfo {
+    
+    protected static final String PIPELINE_PREFIX = ProcessingPipeline.ROLE + "/";
+    
+    protected static final Set DEFAULT_ROLES = new HashSet(Arrays.asList(new String[] {
+            Generator.ROLE + "/" + DefaultServiceSelector.DEFAULT_HINT,
+            Transformer.ROLE + "/" + DefaultServiceSelector.DEFAULT_HINT,
+            Serializer.ROLE + "/" + DefaultServiceSelector.DEFAULT_HINT,
+            Reader.ROLE + "/" + DefaultServiceSelector.DEFAULT_HINT,
+            ProcessingPipeline.ROLE + "/" + DefaultServiceSelector.DEFAULT_HINT,
+            Matcher.ROLE + "/" + DefaultServiceSelector.DEFAULT_HINT,
+            Selector.ROLE + "/" + DefaultServiceSelector.DEFAULT_HINT,
+            Action.ROLE + "/" + DefaultServiceSelector.DEFAULT_HINT
+    }));
+    
+    public ProcessorComponentInfo(ProcessorComponentInfo parent) {
+        super(parent);
+    }
+    
+    /**
+     * Prepares the configuration for pooled sitemap components:
+     * Per default pooled components are proxied - we override this
+     * for generators, transformers, serializers, readers and pipes
+     * @param role the component's role
+     * @param clazz the component's class
+     * @param config the component's configuration
+     */
+    public void prepareConfig(String role, String clazz, Configuration config) {
+        if (role.startsWith(GENERATOR_PREFIX)
+            || role.startsWith(TRANSFORMER_PREFIX)
+            || role.startsWith(SERIALIZER_PREFIX)
+            || role.startsWith(READER_PREFIX)
+            || role.startsWith(PIPELINE_PREFIX)) {
+            
+            ((DefaultConfiguration)config).setAttribute("model", ComponentInfo.TYPE_NON_THREAD_SAFE_POOLED);
+        }
+    }
+
+    public void roleAliased(String existingRole, String newRole) {
+        if (DEFAULT_ROLES.contains(newRole)) {
+            // A default role for a sitemap component has been added
+            int pos = existingRole.indexOf('/');
+            String role = existingRole.substring(0, pos);
+            String hint = existingRole.substring(pos+1);
+            
+            this.setDefaultType(role, hint);
+        }
+    }
+}
\ No newline at end of file

Propchange: cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-ecm-impl/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ProcessorComponentInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-ecm-impl/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ProcessorComponentInfo.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-servlet-impl/src/main/java/org/apache/cocoon/blocks/servlet/BlocksManager.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-servlet-impl/src/main/java/org/apache/cocoon/blocks/servlet/BlocksManager.java?rev=379200&r1=379199&r2=379200&view=diff
==============================================================================
--- cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-servlet-impl/src/main/java/org/apache/cocoon/blocks/servlet/BlocksManager.java (original)
+++ cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-servlet-impl/src/main/java/org/apache/cocoon/blocks/servlet/BlocksManager.java Mon Feb 20 10:57:53 2006
@@ -48,8 +48,8 @@
 import org.apache.cocoon.components.LifecycleHelper;
 import org.apache.cocoon.components.source.SourceUtil;
 import org.apache.cocoon.components.source.impl.DelayedRefreshSourceWrapper;
+import org.apache.cocoon.core.container.spring.ApplicationContextFactory;
 import org.apache.cocoon.core.servlet.CoreUtil;
-import org.apache.cocoon.core.servlet.LoggerUtil;
 import org.apache.excalibur.source.Source;
 import org.apache.excalibur.source.impl.URLSource;
 import org.xml.sax.InputSource;
@@ -85,9 +85,7 @@
             throw new ServletException("Could not parse " + contextURL0, e);
         }
         
-        LoggerUtil loggerUtil =
-            new LoggerUtil(this.getServletConfig(), BlockConstants.WIRING);
-        this.logger = loggerUtil.getCocoonLogger();
+        this.logger = ApplicationContextFactory.createRootLogger(this.getServletConfig().getServletContext(), "cocoon");
         this.getLogger().debug("Initializing the Blocks Manager");
         
         InputSource is = null;

Modified: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/container/DefaultSitemapConfigurationHolder.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/container/DefaultSitemapConfigurationHolder.java?rev=379200&r1=379199&r2=379200&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/container/DefaultSitemapConfigurationHolder.java (original)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/container/DefaultSitemapConfigurationHolder.java Mon Feb 20 10:57:53 2006
@@ -22,7 +22,6 @@
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.cocoon.components.ChainedConfiguration;
 import org.apache.cocoon.components.SitemapConfigurationHolder;
-import org.apache.cocoon.core.container.RoleManager;
 import org.apache.cocoon.environment.internal.EnvironmentHelper;
 
 /**
@@ -36,14 +35,14 @@
     private final String role;
     
     /** The role manager */
-    private final RoleManager roleManager;
+//    private final RoleManager roleManager;
 
     /** The prepared configurations indexed by the ChainedConfiguration */
     private Map preparedConfigurations;
     
-    public DefaultSitemapConfigurationHolder(String role, RoleManager manager) {
+    public DefaultSitemapConfigurationHolder(String role/*, RoleManager manager*/) {
         this.role = role;
-        this.roleManager = manager;
+        //this.roleManager = manager;
     }
     
     protected Map convert(Configuration[] configs, int index) {
@@ -64,7 +63,7 @@
             // and now check for new configurations
             for(int m = 0; m < childs.length; m++) {
 
-                final String r = this.roleManager.getRoleForName(childs[m].getName());
+                final String r = null;//this.roleManager.getRoleForName(childs[m].getName());
                 sitemapComponentConfigurations.put(r, new ChainedConfiguration(childs[m],
                                                                  (ChainedConfiguration)sitemapComponentConfigurations.get(r)));
             }

Modified: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/DefaultTreeBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/DefaultTreeBuilder.java?rev=379200&r1=379199&r2=379200&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/DefaultTreeBuilder.java (original)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/DefaultTreeBuilder.java Mon Feb 20 10:57:53 2006
@@ -37,7 +37,6 @@
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.avalon.framework.service.ServiceSelector;
 import org.apache.avalon.framework.service.Serviceable;
-import org.apache.cocoon.core.container.StandaloneServiceSelector;
 import org.apache.cocoon.components.LifecycleHelper;
 import org.apache.cocoon.components.source.SourceUtil;
 import org.apache.cocoon.components.treeprocessor.variables.VariableResolverFactory;
@@ -391,15 +390,8 @@
 
         // Create & initialize the NodeBuilder selector.
         {
-            StandaloneServiceSelector selector = new StandaloneServiceSelector() {
-                protected String getComponentInstanceName() {
-                    return "node";
-                }
-
-                protected String getClassAttributeName() {
-                    return "builder";
-                }
-            };
+            StandaloneServiceSelector selector = new StandaloneServiceSelector();
+
             // Load the builder config file
             SourceResolver resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
             String url = getBuilderConfigURL();

Modified: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/ProcessorComponentInfo.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/ProcessorComponentInfo.java?rev=379200&r1=379199&r2=379200&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/ProcessorComponentInfo.java (original)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/ProcessorComponentInfo.java Mon Feb 20 10:57:53 2006
@@ -15,23 +15,13 @@
  */
 package org.apache.cocoon.components.treeprocessor;
 
-import java.util.Arrays;
 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.configuration.Configuration;
-import org.apache.avalon.framework.configuration.DefaultConfiguration;
-import org.apache.cocoon.acting.Action;
-import org.apache.cocoon.components.ComponentInfo;
-import org.apache.cocoon.components.pipeline.ProcessingPipeline;
-import org.apache.cocoon.core.container.DefaultServiceSelector;
 import org.apache.cocoon.generation.Generator;
-import org.apache.cocoon.matching.Matcher;
 import org.apache.cocoon.reading.Reader;
-import org.apache.cocoon.selection.Selector;
 import org.apache.cocoon.serialization.Serializer;
 import org.apache.cocoon.transformation.Transformer;
 
@@ -48,31 +38,20 @@
  * @version $Id$
  */
 public class ProcessorComponentInfo {
-    
+
+    /** The role to lookup this component. */
     public static final String ROLE = ProcessorComponentInfo.class.getName();
     
-    private static final String GENERATOR_PREFIX = Generator.ROLE + "/";
-    private static final String TRANSFORMER_PREFIX = Transformer.ROLE + "/";
-    private static final String SERIALIZER_PREFIX = Serializer.ROLE + "/";
-    private static final String READER_PREFIX = Reader.ROLE + "/";
-    private static final String PIPELINE_PREFIX = ProcessingPipeline.ROLE + "/";
-    
-    private static final Set DEFAULT_ROLES = new HashSet(Arrays.asList(new String[] {
-            Generator.ROLE + "/" + DefaultServiceSelector.DEFAULT_HINT,
-            Transformer.ROLE + "/" + DefaultServiceSelector.DEFAULT_HINT,
-            Serializer.ROLE + "/" + DefaultServiceSelector.DEFAULT_HINT,
-            Reader.ROLE + "/" + DefaultServiceSelector.DEFAULT_HINT,
-            ProcessingPipeline.ROLE + "/" + DefaultServiceSelector.DEFAULT_HINT,
-            Matcher.ROLE + "/" + DefaultServiceSelector.DEFAULT_HINT,
-            Selector.ROLE + "/" + DefaultServiceSelector.DEFAULT_HINT,
-            Action.ROLE + "/" + DefaultServiceSelector.DEFAULT_HINT
-    }));
+    protected static final String GENERATOR_PREFIX = Generator.ROLE + "/";
+    protected static final String TRANSFORMER_PREFIX = Transformer.ROLE + "/";
+    protected static final String SERIALIZER_PREFIX = Serializer.ROLE + "/";
+    protected static final String READER_PREFIX = Reader.ROLE + "/";
     
     /** Component info for the parent processor */
-    ProcessorComponentInfo parent;
+    protected ProcessorComponentInfo parent;
     
     /** Lock that prevents further modification */
-    private boolean locked = false;
+    protected boolean locked = false;
     
     /**
      * Component-related data (see methods below for key names). We use a single Map
@@ -110,37 +89,7 @@
         }
     }
     
-    /**
-     * Prepares the configuration for pooled sitemap components:
-     * Per default pooled components are proxied - we override this
-     * for generators, transformers, serializers, readers and pipes
-     * @param role the component's role
-     * @param clazz the component's class
-     * @param config the component's configuration
-     */
-    public void prepareConfig(String role, String clazz, Configuration config) {
-        if (role.startsWith(GENERATOR_PREFIX)
-            || role.startsWith(TRANSFORMER_PREFIX)
-            || role.startsWith(SERIALIZER_PREFIX)
-            || role.startsWith(READER_PREFIX)
-            || role.startsWith(PIPELINE_PREFIX)) {
-            
-            ((DefaultConfiguration)config).setAttribute("model", ComponentInfo.TYPE_NON_THREAD_SAFE_POOLED);
-        }
-    }
-
-    public void roleAliased(String existingRole, String newRole) {
-        if (DEFAULT_ROLES.contains(newRole)) {
-            // A default role for a sitemap component has been added
-            int pos = existingRole.indexOf('/');
-            String role = existingRole.substring(0, pos);
-            String hint = existingRole.substring(pos+1);
-            
-            this.setDefaultType(role, hint);
-        }
-    }
-    
-    private void setupLabelAndPipelineHint(String role, Configuration config) {
+    protected void setupLabelAndPipelineHint(String role, Configuration config) {
 
         // Labels
         String label = config.getAttribute("label", null);
@@ -161,7 +110,7 @@
         setPipelineHint(role, pipelineHint);
     }
 
-    private void setupMimeType(String role, Configuration config) {
+    protected void setupMimeType(String role, Configuration config) {
         setMimeType(role, config.getAttribute("mime-type", null));
     }
 
@@ -193,7 +142,7 @@
         this.locked = true;
     }
     
-    private void setDefaultType(String role, String hint) {
+    public void setDefaultType(String role, String hint) {
         setData("defaultType/" + role, hint);
     }
     

Added: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/StandaloneServiceSelector.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/StandaloneServiceSelector.java?rev=379200&view=auto
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/StandaloneServiceSelector.java (added)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/StandaloneServiceSelector.java Mon Feb 20 10:57:53 2006
@@ -0,0 +1,411 @@
+/* 
+ * Copyright 2002-2005 The Apache Software Foundation
+ * Licensed  under the  Apache License,  Version 2.0  (the "License");
+ * you may not use  this file  except in  compliance with the License.
+ * You may obtain a copy of the License at 
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed  under the  License is distributed on an "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.components.treeprocessor;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.activity.Initializable;
+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.container.ContainerUtil;
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.Contextualizable;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.parameters.Parameterizable;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.ServiceSelector;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.cocoon.components.Preloadable;
+import org.apache.cocoon.core.container.spring.ComponentInfo;
+import org.apache.cocoon.util.ClassUtils;
+
+/**
+ * Default component selector for Cocoon's components.
+ *
+ * @version $Id$
+ * @since 2.2
+ */
+public class StandaloneServiceSelector
+    extends AbstractLogEnabled
+    implements Preloadable,
+               ServiceSelector,
+               Serviceable,
+               Configurable,
+               Disposable,
+               Initializable,
+               Contextualizable {
+
+    /** The application context for components
+     */
+    protected ServiceManager serviceManager;
+
+    /** The role of this selector. Set in <code>configure()</code>. */
+    protected String roleName;
+
+    /** The default key */
+    protected String defaultKey;
+
+    /** The application context for components */
+    protected Context context;
+
+    /** Used to map roles to ComponentHandlers. */
+    protected final Map componentHandlers = Collections.synchronizedMap(new HashMap());
+
+    /** Is the Manager disposed or not? */
+    protected boolean disposed;
+
+    /** Is the Manager initialized? */
+    protected boolean initialized;
+
+    /**
+     * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
+     */
+    public void contextualize( final Context context ) {
+        this.context = context;
+    }
+
+    /**
+     * Obtain a new ComponentHandler for the specified component. 
+     * 
+     * @param role the component's role.
+     * @param componentClass Class of the component for which the handle is
+     *                       being requested.
+     * @param configuration The configuration for this component.
+     * @param serviceManager The service manager which will be managing the Component.
+     *
+     * @throws Exception If there were any problems obtaining a ComponentHandler
+     */
+    protected ComponentInfo getComponentHandler( final String role,
+                                                    final Class componentClass,
+                                                    final Configuration configuration,
+                                                    final ServiceManager serviceManager)
+    throws Exception {
+        ComponentInfo info;
+        info = new ComponentInfo();
+        info.fill(configuration);
+        info.setRole(role);
+        info.setConfiguration(configuration);
+        info.setComponentClassName(componentClass.getName());
+        info.setModel(ComponentInfo.MODEL_SINGLETON);
+        return info;
+    }
+
+    protected void addComponent(String className,
+                                String role,
+                                Configuration configuration) 
+    throws ConfigurationException {
+        try {
+            if( this.getLogger().isDebugEnabled() ) {
+                this.getLogger().debug( "Adding component (" + role + " = " + className + ")" );
+            }
+            // FIXME - use different classloader
+            final Class clazz = this.getClass().getClassLoader().loadClass( className );
+            this.addComponent( role, clazz, configuration );
+        } catch( final ClassNotFoundException cnfe ) {
+            final String message = "Could not get class (" + className + ") for role "
+                                 + role + " at " + configuration.getLocation();
+
+            if( this.getLogger().isErrorEnabled() ) {
+                this.getLogger().error( message, cnfe );
+            }
+
+            throw new ConfigurationException( message, cnfe );
+        } catch( final ServiceException ce ) {
+            final String message = "Cannot setup class "+ className + " for role " + role
+                                 + " at " + configuration.getLocation();
+
+            if( this.getLogger().isErrorEnabled() ) {
+                this.getLogger().error( message, ce );
+            }
+
+            throw new ConfigurationException( message, ce );
+        } catch( final Exception e ) {
+            final String message = "Unexpected exception when setting up role " + role + " at " + configuration.getLocation();
+            if( this.getLogger().isErrorEnabled() ) {
+                this.getLogger().error( message, e );
+            }
+            throw new ConfigurationException( message, e );
+        }        
+    }
+
+    /**
+     * @see org.apache.avalon.framework.service.ServiceSelector#select(java.lang.Object)
+     */
+    public Object select( Object hint )
+    throws ServiceException {
+        final String key;
+        if (hint == null) {
+            key = this.defaultKey;
+        } else {
+            key = hint.toString();
+        }
+
+        if( !this.initialized ) {
+            if( this.getLogger().isWarnEnabled() ) {
+                this.getLogger().warn( "Selecting a component on an uninitialized service selector "
+                    + "with key [" + key + "]" );
+            }
+        }
+
+        if( this.disposed ) {
+            throw new IllegalStateException(
+                "You cannot select a component from a disposed service selector." );
+        }
+
+        Object component = this.componentHandlers.get( key );
+
+        // Retrieve the instance of the requested component
+        if( null == component ) {
+            final String message = this.roleName
+                + ": service selector could not find the component for key [" + key + "]";
+            if( this.getLogger().isDebugEnabled() ) {
+                this.getLogger().debug( message );
+            }
+            throw new ServiceException( key, message );
+        }
+
+        return component;
+    }
+
+    /**
+     * @see org.apache.avalon.framework.service.ServiceSelector#isSelectable(java.lang.Object)
+     */
+    public boolean isSelectable( Object hint ) {
+        final String key;
+        if (hint == null) {
+            key = this.defaultKey;
+        } else {
+            key = hint.toString();
+        }
+
+        if( !this.initialized ) return false;
+        if( this.disposed ) return false;
+
+        boolean exists = false;
+
+        try {
+            Object component = this.componentHandlers.get( key );
+            exists = (component != null);
+        } catch( Throwable t ) {
+            // We can safely ignore all exceptions
+        }
+
+        return exists;
+    }
+
+    /**
+     * @see org.apache.avalon.framework.service.ServiceSelector#release(java.lang.Object)
+     */
+    public void release( final Object component ) {
+        // nothing to do as we only serve singletons
+    }
+
+    /**
+     * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
+     */
+    public void service( final ServiceManager componentManager )
+    throws ServiceException {
+        this.serviceManager = componentManager;
+    }
+
+    /**
+     * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
+     */
+    public void configure( final Configuration config )
+    throws ConfigurationException {
+        this.roleName = getRoleName(config);
+
+        // Get default key
+        this.defaultKey = config.getAttribute(this.getDefaultKeyAttributeName(), null);
+
+        // Add components
+        String compInstanceName = getComponentInstanceName();
+
+        Configuration[] instances = config.getChildren();
+
+        for (int i = 0; i < instances.length; i++) {
+
+            Configuration instance = instances[i];
+            String key = instance.getAttribute("name").trim();
+
+            String classAttr = instance.getAttribute(getClassAttributeName(), null);
+            String className;
+
+            // component-instances names explicitly defined
+            if (compInstanceName.equals(instance.getName())) {
+                className = (classAttr == null) ? null : classAttr.trim();
+            } else {
+                className = null;
+            }
+
+            if (className == null) {
+                String message = "Unable to determine class name for component named '" + key +
+                    "' at " + instance.getLocation();
+
+                getLogger().error(message);
+                throw new ConfigurationException(message);
+            }
+
+            this.addComponent( className, key, instance );
+        }
+    }
+
+    /**
+     * @see org.apache.avalon.framework.activity.Initializable#initialize()
+     */
+    public void initialize() 
+    throws Exception {
+        this.initialized = true;
+
+        List keys = new ArrayList( this.componentHandlers.keySet() );
+        final Map components = new HashMap();
+
+        for( int i = 0; i < keys.size(); i++ ) {
+            final Object key = keys.get( i );
+            final ComponentInfo handler =
+                (ComponentInfo)this.componentHandlers.get( key );
+
+            try {
+                Object component = ClassUtils.newInstance(handler.getComponentClassName());
+                ContainerUtil.enableLogging(component, this.getLogger());
+                ContainerUtil.contextualize(component, this.context);
+                ContainerUtil.service(component, this.serviceManager);
+                ContainerUtil.configure(component, handler.getConfiguration());
+                if ( component instanceof Parameterizable ) {
+                    ContainerUtil.parameterize(component, Parameters.fromConfiguration(handler.getConfiguration()));
+                }
+                ContainerUtil.initialize(component);
+                components.put(key, component);
+            } catch( Exception e ) {
+                if( this.getLogger().isDebugEnabled() ) {
+                    this.getLogger().debug( "Caught an exception trying to initialize "
+                        + "of the component handler.", e );
+                }
+            }
+        }
+        this.componentHandlers.clear();
+        this.componentHandlers.putAll(components);
+    }
+
+    /**
+     * @see org.apache.avalon.framework.activity.Disposable#dispose()
+     */
+    public void dispose() {
+        Iterator iter = this.componentHandlers.values().iterator();
+        while( iter.hasNext() ) {
+            final Object current = iter.next();
+            ContainerUtil.dispose(current);
+        }
+        this.componentHandlers.clear();
+        this.disposed = true;
+    }
+
+    /** Add a new component to the manager.
+     * @param key the key for the new component.
+     * @param component the class of this component.
+     * @param configuration the configuration for this component.
+     */
+    public void addComponent( final String key,
+                              final Class component,
+                              final Configuration configuration)
+    throws ServiceException {
+        if( this.initialized ) {
+            throw new ServiceException( key,
+                "Cannot add components to an initialized service selector" );
+        }
+
+        try {
+            final ComponentInfo handler = getComponentHandler( null,
+                                                               component,
+                                                               configuration,
+                                                               this.serviceManager);
+
+            this.componentHandlers.put( key, handler );
+
+            if( this.getLogger().isDebugEnabled() ) {
+                this.getLogger().debug(
+                    "Adding " + component.getName() + " for key [" + key + "]" );
+            }
+        } catch (ServiceException se) {
+            throw se;
+        } catch( final Exception e ) {
+            final String message =
+                "Could not set up component for key [ " + key + "]";
+            if( this.getLogger().isErrorEnabled() ) {
+                this.getLogger().error( message, e );
+            }
+
+            throw new ServiceException(key, message, e );
+        }
+    }
+
+    /**
+     * Get the name for component-instance elements (i.e. components not defined
+     * by their role shortcut. If <code>null</code>, any element having a 'class'
+     * attribute will be considered as a component instance.
+     * <p>
+     * The default here is to return <code>null</code>, and subclasses can redefine
+     * this method to return particular values.
+     *
+     * @return <code>null</code>, but can be changed by subclasses
+     */
+    protected String getComponentInstanceName() {
+        return "node";
+    }
+
+    /**
+     * Get the name of the attribute giving the class name of a component.
+     * The default here is "class", but this can be overriden in subclasses.
+     *
+     * @return "<code>class</code>", but can be changed by subclasses
+     */
+    protected String getClassAttributeName() {
+        return "builder";
+    }
+
+    /**
+     * Get the name of the attribute giving the default key to use if
+     * none is given. The default here is "default", but this can be
+     * overriden in subclasses. If this method returns <code>null</code>,
+     * no default key can be specified.
+     *
+     * @return "<code>default</code>", but can be changed by subclasses
+     */
+    protected String getDefaultKeyAttributeName() {
+        return "default";
+    }
+
+    /**
+     * Get the role name for this selector. This is called by <code>configure()</code>
+     * to set the value of <code>this.roleName</code>.
+     *
+     * @return the role name, or <code>null<code> if it couldn't be determined.
+     */
+    protected String getRoleName(Configuration config) {
+        // Get the role for this selector
+        return config.getAttribute("role", null);
+    }
+}

Propchange: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/StandaloneServiceSelector.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/StandaloneServiceSelector.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ApplicationContextFactory.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ApplicationContextFactory.java?rev=379200&r1=379199&r2=379200&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ApplicationContextFactory.java (original)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ApplicationContextFactory.java Mon Feb 20 10:57:53 2006
@@ -159,7 +159,7 @@
         if ( component != null ) {
             final String defaultComponent = component.getConfiguration().getAttribute("default", null);
             if ( defaultComponent != null ) {
-                info.roleAliased(category + "/" + defaultComponent, category + "/$default$");
+                info.setDefaultType(category, defaultComponent);
             }
         }
     }

Modified: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonXmlWebApplicationContext.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonXmlWebApplicationContext.java?rev=379200&r1=379199&r2=379200&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonXmlWebApplicationContext.java (original)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonXmlWebApplicationContext.java Mon Feb 20 10:57:53 2006
@@ -55,6 +55,7 @@
 /**
  * This is a Cocoon specific implementation of a Spring {@link ApplicationContext}.
  *
+ * TODO - Support for SitemapConfigurable
  * @since 2.2
  * @version $Id$
  */