cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dani...@apache.org
Subject svn commit: r493767 - in /cocoon/trunk/core: cocoon-pipeline/cocoon-pipeline-impl/ cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/components/pipeline/impl/ cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/core/...
Date Sun, 07 Jan 2007 16:34:53 GMT
Author: danielf
Date: Sun Jan  7 08:34:52 2007
New Revision: 493767

URL: http://svn.apache.org/viewvc?view=rev&rev=493767
Log:
Added handling of pipeline component info for Spring managed components. And refactored the
previous mechanism to make it possible.
* ProcessorComponentInfo -> PipelineComponentInfo and moved from the sitemap-impl to the
pipeline-impl module. This was necessary for being able to add the component info to the pipeline
components, without depending on the sitemap modules.
* Component info is added to the pipeline components by inserting the decoration element:
    <pipeline:component mime-type="text/xml" label="foo" hint="bar"/>
* The decoration element setup the pipeline component to depend on an initializer bean that
in turn puts the component info into the PipelineComponentInfo bean.
* The BridgeElementParser, (that handle Avalon definitions) is refactored to use the inititializer
bean.

Added:
    cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/components/pipeline/impl/PipelineComponentInfo.java
    cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/core/
    cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/core/container/
    cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/core/container/spring/
    cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/core/container/spring/pipeline/
    cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/core/container/spring/pipeline/PipelineComponentInfoFactoryBean.java
    cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/core/container/spring/pipeline/PipelineComponentInfoInitializer.java
    cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/core/container/spring/pipeline/PipelineComponentInfoInitializerDecorator.java
    cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/core/container/spring/pipeline/PipelineNamespaceHandler.java
  (with props)
    cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/resources/META-INF/spring.handlers
  (with props)
    cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/resources/META-INF/spring.schemas
  (with props)
    cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/resources/org/
    cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/resources/org/apache/
    cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/resources/org/apache/cocoon/
    cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/resources/org/apache/cocoon/core/
    cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/resources/org/apache/cocoon/core/container/
    cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/resources/org/apache/cocoon/core/container/spring/
    cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/resources/org/apache/cocoon/core/container/spring/pipeline/
    cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/resources/org/apache/cocoon/core/container/spring/pipeline/pipeline.xsd
Removed:
    cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/ProcessorComponentInfo.java
    cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/ProcessorComponentInfoFactoryBean.java
Modified:
    cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/pom.xml
    cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
    cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/BridgeElementParser.java

Modified: cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/pom.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/pom.xml?view=diff&rev=493767&r1=493766&r2=493767
==============================================================================
--- cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/pom.xml (original)
+++ cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/pom.xml Sun Jan  7 08:34:52 2007
@@ -130,6 +130,12 @@
       <artifactId>jakarta-regexp</artifactId>
       <version>1.4</version>
     </dependency>
+    <!-- Spring Framework -->
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-beans</artifactId>
+      <version>2.0.1</version>
+    </dependency>   
     <dependency>
       <groupId>xml-apis</groupId>
       <artifactId>xml-apis</artifactId>

Added: cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/components/pipeline/impl/PipelineComponentInfo.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/components/pipeline/impl/PipelineComponentInfo.java?view=auto&rev=493767
==============================================================================
--- cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/components/pipeline/impl/PipelineComponentInfo.java
(added)
+++ cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/components/pipeline/impl/PipelineComponentInfo.java
Sun Jan  7 08:34:52 2007
@@ -0,0 +1,203 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.pipeline.impl;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.cocoon.generation.Generator;
+import org.apache.cocoon.reading.Reader;
+import org.apache.cocoon.serialization.Serializer;
+import org.apache.cocoon.transformation.Transformer;
+
+/**
+ * Holds informations defined in &lt;map:components&gt; 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: ProcessorComponentInfo.java 490762 2006-12-28 17:03:53Z danielf $
+ */
+public class PipelineComponentInfo {
+
+    /** The role to lookup this component. */
+    public static final String ROLE = PipelineComponentInfo.class.getName();
+    
+    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 */
+    protected PipelineComponentInfo parent;
+    
+    /** Lock that prevents further modification */
+    protected boolean locked = false;
+    
+    /**
+     * Component-related data (see methods below for key names). We use a single Map
+     * to reduce memory usage, as each kind of data has a limited number of entries.
+     */
+    private Map data;
+    
+    public PipelineComponentInfo(PipelineComponentInfo parent) {
+        this.parent = parent;
+    }
+    
+    /**
+     * Grabs on the fly the sitemap-related information on generators, transformers,
+     * serializers and readers when they're declared in the <code>ServiceManager</code>.
+     * <p>
+     * This method is triggered when a component is added on a <code>CocoonServiceManager</code>.
+     * 
+     * @param role the component's role
+     * @param clazz the component's class
+     * @param config the component's configuration
+     */
+    public void componentAdded(String role, String clazz, Configuration config) {
+        if (role.startsWith(GENERATOR_PREFIX)) {
+            setupLabelAndPipelineHint(role, config);
+
+        } else if (role.startsWith(TRANSFORMER_PREFIX)) {
+            setupLabelAndPipelineHint(role, config);
+
+        } else if (role.startsWith(SERIALIZER_PREFIX)) {
+            setupLabelAndPipelineHint(role, config);
+            setupMimeType(role, config);
+
+        } else if (role.startsWith(READER_PREFIX)) {
+            setupMimeType(role, config);
+        }
+    }
+    
+    protected void setupLabelAndPipelineHint(String role, Configuration config) {
+
+        // Labels
+        String label = config.getAttribute("label", null);
+        if (label != null) {
+            StringTokenizer st = new StringTokenizer(label, " ,", false);
+            String[] labels = new String[st.countTokens()];
+            for (int tokenIdx = 0; tokenIdx < labels.length; tokenIdx++) {
+                labels[tokenIdx] = st.nextToken();
+            }
+            setLabels(role, labels);
+        } else {
+            // Set no labels, overriding those defined in the parent sitemap, if any
+            setLabels(role, null);
+        }
+
+        // Pipeline hints
+        String pipelineHint = config.getAttribute("hint", null);
+        setPipelineHint(role, pipelineHint);
+    }
+
+    protected void setupMimeType(String role, Configuration config) {
+        setMimeType(role, config.getAttribute("mime-type", null));
+    }
+
+    /** Store some data, creating the storage map if needed */
+    private void setData(String key, Object value) {
+        if (locked) throw new IllegalStateException("ProcessorComponentInfo is locked");
+        if (this.data == null) this.data = new HashMap();
+        this.data.put(key, value);
+    }
+    
+    /** Get some data, asking the parent if needed */
+    private Object getData(String key) {
+        // Need to check containsKey as the default hint may be unspecified (i.e. no "default"
attribute)
+        if (this.data != null && this.data.containsKey(key)) {
+            return this.data.get(key);
+        } else if (this.parent != null) {
+            // Ask parent
+            return this.parent.getData(key);
+        } else {
+            return null;
+        }
+    }
+    
+    /**
+     * Lock this component info object at the end of processor building to prevent
+     * any further changes.
+     */
+    public void lock() {
+        this.locked = true;
+    }
+    
+    public void setDefaultType(String role, String hint) {
+        setData("defaultType/" + role, hint);
+    }
+    
+    public String getDefaultType(String role) {
+        return (String)getData("defaultType/" + role);
+    }
+    
+    public void setPipelineHint(String role, String hint) {
+        setData("pipelineHint/" + role, hint);
+    }
+    
+    public String getPipelineHint(String role, String type) {
+        return (String)getData("pipelineHint/" + role + "/" + type);
+    }
+    
+    public void setMimeType(String role, String mimeType) {
+        setData("mimeType/" + role, mimeType);
+    }
+    
+    public String getMimeType(String role, String type) {
+        return (String)getData("mimeType/" + role + "/" + type);
+    }
+    
+    public void setLabels(String role, String[] labels) {
+        setData("labels/" + role, labels);
+    }
+    
+    public String[] getLabels(String role, String type) {
+        return (String[])getData("labels/" + role + "/" + type);
+    }
+    
+    public boolean hasLabel(String role, String type, String label) {
+        String[] labels = this.getLabels(role, type);
+        if (labels != null) {
+            for (int i = 0; i < labels.length; i++) {
+                if (labels[i].equals(label))
+                    return true;
+            }
+        }
+        return false;
+    }
+
+    public Map getData() {
+        return this.data;
+    }
+
+    public void setData(Map map) {
+        this.data = map;
+    }
+    
+    public void addData(Map map) {
+        if (this.data == null)
+            this.data = map;
+        else
+            this.data.putAll(map);
+    }
+}
\ No newline at end of file

Added: cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/core/container/spring/pipeline/PipelineComponentInfoFactoryBean.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/core/container/spring/pipeline/PipelineComponentInfoFactoryBean.java?view=auto&rev=493767
==============================================================================
--- cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/core/container/spring/pipeline/PipelineComponentInfoFactoryBean.java
(added)
+++ cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/core/container/spring/pipeline/PipelineComponentInfoFactoryBean.java
Sun Jan  7 08:34:52 2007
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.core.container.spring.pipeline;
+
+import java.util.Map;
+
+import org.apache.cocoon.components.pipeline.impl.PipelineComponentInfo;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.BeanFactoryAware;
+import org.springframework.beans.factory.FactoryBean;
+import org.springframework.beans.factory.HierarchicalBeanFactory;
+
+/**
+ * This spring factory bean adds the processor component info to the bean factory.
+ *
+ * @since 2.2
+ * @version $Id: ProcessorComponentInfoFactoryBean.java 448473 2006-09-21 06:22:51Z crossley
$
+ */
+public class PipelineComponentInfoFactoryBean
+    implements FactoryBean, BeanFactoryAware {
+
+    /** The bean factory. */
+    protected BeanFactory beanFactory;
+
+    protected Map data;
+
+    protected PipelineComponentInfo info;
+
+    /**
+     * @see org.springframework.beans.factory.BeanFactoryAware#setBeanFactory(org.springframework.beans.factory.BeanFactory)
+     */
+    public void setBeanFactory(BeanFactory factory) throws BeansException {
+        this.beanFactory = factory;
+    }
+
+    protected void init()
+    throws Exception {
+        PipelineComponentInfo parent = null;
+        if ( this.beanFactory instanceof HierarchicalBeanFactory ) {
+            BeanFactory parentFactory = ((HierarchicalBeanFactory)this.beanFactory).getParentBeanFactory();
+            if ( parentFactory != null && parentFactory.containsBean(PipelineComponentInfo.ROLE)
) {
+                parent = (PipelineComponentInfo)parentFactory.getBean(PipelineComponentInfo.ROLE);
+            }
+        }
+        this.info = new PipelineComponentInfo(parent);
+        if ( this.data != null ) {
+            info.setData(data);
+        }
+    }
+
+    /**
+     * @see org.springframework.beans.factory.FactoryBean#getObject()
+     */
+    public Object getObject() throws Exception {
+        return this.info;
+    }
+
+    /**
+     * @see org.springframework.beans.factory.FactoryBean#getObjectType()
+     */
+    public Class getObjectType() {
+        return PipelineComponentInfo.class;
+    }
+
+    /**
+     * @see org.springframework.beans.factory.FactoryBean#isSingleton()
+     */
+    public boolean isSingleton() {
+        return true;
+    }
+
+    public Map getData() {
+        return data;
+    }
+
+    public void setData(Map data) {
+        this.data = data;
+    }
+}

Added: cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/core/container/spring/pipeline/PipelineComponentInfoInitializer.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/core/container/spring/pipeline/PipelineComponentInfoInitializer.java?view=auto&rev=493767
==============================================================================
--- cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/core/container/spring/pipeline/PipelineComponentInfoInitializer.java
(added)
+++ cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/core/container/spring/pipeline/PipelineComponentInfoInitializer.java
Sun Jan  7 08:34:52 2007
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.core.container.spring.pipeline;
+
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import org.apache.cocoon.components.pipeline.impl.PipelineComponentInfo;
+
+
+/**
+ * @version $Id$
+ * @since 2.2
+ */
+public class PipelineComponentInfoInitializer {
+    private PipelineComponentInfo info;
+    private String componentName;
+    private String mimeType;
+    private String label;
+    private String hint;
+    private Map data;
+    
+    public void init() {
+        if (this.mimeType != null)
+            this.info.setMimeType(this.componentName, this.mimeType);
+        if (this.label != null) {
+            StringTokenizer st = new StringTokenizer(this.label, " ,", false);
+            String[] labels = new String[st.countTokens()];
+            for (int tokenIdx = 0; tokenIdx < labels.length; tokenIdx++) {
+                labels[tokenIdx] = st.nextToken();
+            }
+            this.info.setLabels(this.componentName, labels);
+        }
+        if (this.hint != null)
+            this.info.setPipelineHint(this.componentName, this.hint);
+        if (this.data != null)
+            this.info.addData(data);
+    }
+
+    /**
+     * @param info
+     */
+    public void setInfo(PipelineComponentInfo info) {
+        this.info = info;
+    }
+
+    /**
+     * @param componentName
+     */
+    public void setComponentName(String componentName) {
+        this.componentName = componentName;
+    }
+    /**
+     * @param hint
+     */
+    public void setHint(String hint) {
+        this.hint = hint;
+    }
+    /**
+     * @param label
+     */
+    public void setLabel(String label) {
+        this.label = label;
+    }
+    /**
+     * @param mimeType
+     */
+    public void setMimeType(String mimeType) {
+        this.mimeType = mimeType;
+    }
+
+    /**
+     * @param data the data to set
+     */
+    public void setData(Map data) {
+        this.data = data;
+    }
+
+}

Added: cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/core/container/spring/pipeline/PipelineComponentInfoInitializerDecorator.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/core/container/spring/pipeline/PipelineComponentInfoInitializerDecorator.java?view=auto&rev=493767
==============================================================================
--- cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/core/container/spring/pipeline/PipelineComponentInfoInitializerDecorator.java
(added)
+++ cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/core/container/spring/pipeline/PipelineComponentInfoInitializerDecorator.java
Sun Jan  7 08:34:52 2007
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.core.container.spring.pipeline;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.cocoon.components.pipeline.impl.PipelineComponentInfo;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.factory.config.BeanDefinitionHolder;
+import org.springframework.beans.factory.support.AbstractBeanDefinition;
+import org.springframework.beans.factory.support.BeanDefinitionBuilder;
+import org.springframework.beans.factory.support.RootBeanDefinition;
+import org.springframework.beans.factory.xml.BeanDefinitionDecorator;
+import org.springframework.beans.factory.xml.ParserContext;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * @version $Id$
+ * @since 2.2
+ */
+public class PipelineComponentInfoInitializerDecorator implements
+        BeanDefinitionDecorator {
+
+    private static final String[] EMPTY_STRING_ARRAY = new String[0];
+    /** Logger  */
+    private final Log logger = LogFactory.getLog(getClass());
+
+    /* (non-Javadoc)
+     * @see org.springframework.beans.factory.xml.BeanDefinitionDecorator#decorate(org.w3c.dom.Node,
org.springframework.beans.factory.config.BeanDefinitionHolder, org.springframework.beans.factory.xml.ParserContext)
+     */
+    public BeanDefinitionHolder decorate(Node source, BeanDefinitionHolder holder, ParserContext
ctx) {
+        registerPipelineComponentInfo(ctx);
+        String initializerBeanName = registerPipelineComponentInfoInitializer(source, holder,
ctx);
+        createDependencyOnPipelineComponentInfoInitializer(holder, initializerBeanName);
+        return holder;
+    }
+
+    private void registerPipelineComponentInfo(ParserContext ctx) {
+        if (!ctx.getRegistry().containsBeanDefinition(PipelineComponentInfo.ROLE)) {
+            BeanDefinitionBuilder defBuilder = BeanDefinitionBuilder.rootBeanDefinition(PipelineComponentInfoFactoryBean.class);

+            defBuilder.setSingleton(true);
+            defBuilder.setLazyInit(false);
+            defBuilder.setInitMethodName("init");
+            ctx.getRegistry().registerBeanDefinition(PipelineComponentInfo.ROLE, defBuilder.getBeanDefinition());
+        }
+    }
+
+    private String registerPipelineComponentInfoInitializer(Node source, BeanDefinitionHolder
holder, ParserContext ctx) {
+        String componentName = holder.getBeanName();
+        String mimeType = ((Element)source).hasAttribute("mime-type") ? ((Element)source).getAttribute("mime-type")
: null;
+        String label = ((Element)source).hasAttribute("label") ? ((Element)source).getAttribute("label")
: null;
+        String hint = ((Element)source).hasAttribute("hint") ? ((Element)source).getAttribute("hint")
: null;
+        
+        BeanDefinitionBuilder initializer = BeanDefinitionBuilder.rootBeanDefinition(PipelineComponentInfoInitializer.class);
+        initializer.addPropertyReference("info", PipelineComponentInfo.ROLE);
+        initializer.addPropertyValue("componentName", componentName);
+        if (mimeType != null)
+            initializer.addPropertyValue("mimeType", mimeType);
+        if (label != null)
+            initializer.addPropertyValue("label", label);
+        if (hint != null)
+            initializer.addPropertyValue("hint", hint);
+        initializer.setInitMethodName("init");
+
+        String beanName = componentName + "/info";
+        ctx.getRegistry().registerBeanDefinition(beanName, initializer.getBeanDefinition());
+        
+        return beanName;
+    }
+
+    private void createDependencyOnPipelineComponentInfoInitializer(BeanDefinitionHolder
holder, String initializerBeanName) {
+        AbstractBeanDefinition definition = ((AbstractBeanDefinition) holder.getBeanDefinition());
+        String[] dependsOn = definition.getDependsOn();
+        if (dependsOn == null) {
+           dependsOn = new String[]{initializerBeanName};
+        } else {
+           List dependencies = new ArrayList(Arrays.asList(dependsOn));
+           dependencies.add(initializerBeanName);
+           dependsOn = (String[]) dependencies.toArray(EMPTY_STRING_ARRAY);
+        }
+        definition.setDependsOn(dependsOn);
+    }
+}

Added: cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/core/container/spring/pipeline/PipelineNamespaceHandler.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/core/container/spring/pipeline/PipelineNamespaceHandler.java?view=auto&rev=493767
==============================================================================
--- cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/core/container/spring/pipeline/PipelineNamespaceHandler.java
(added)
+++ cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/core/container/spring/pipeline/PipelineNamespaceHandler.java
Sun Jan  7 08:34:52 2007
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.core.container.spring.pipeline;
+
+import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
+
+/**
+ * Spring namespace handler for the cocoon pipeline namespace.
+ * Currently this namespace defines the following elements
+ * (in the namespace "http://cocoon.apache.org/schema/pipeline"):
+ * "component" : with optional attributes "mime-type", "label" and "hint".
+ *
+ * @version $Id$
+ * @since 2.2
+ */
+public class PipelineNamespaceHandler extends NamespaceHandlerSupport {
+
+    /* (non-Javadoc)
+     * @see org.springframework.beans.factory.xml.NamespaceHandler#init()
+     */
+    public void init() {
+        this.registerBeanDefinitionDecorator("component", new PipelineComponentInfoInitializerDecorator());
+    }
+
+}

Propchange: cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/core/container/spring/pipeline/PipelineNamespaceHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/core/container/spring/pipeline/PipelineNamespaceHandler.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/resources/META-INF/spring.handlers
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/resources/META-INF/spring.handlers?view=auto&rev=493767
==============================================================================
--- cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/resources/META-INF/spring.handlers
(added)
+++ cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/resources/META-INF/spring.handlers
Sun Jan  7 08:34:52 2007
@@ -0,0 +1,16 @@
+#  Licensed to the Apache Software Foundation (ASF) under one or more
+#  contributor license agreements.  See the NOTICE file distributed with
+#  this work for additional information regarding copyright ownership.
+#  The ASF licenses this file to You 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.
+#
+http\://cocoon.apache.org/schema/pipeline=org.apache.cocoon.core.container.spring.pipeline.PipelineNamespaceHandler

Propchange: cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/resources/META-INF/spring.handlers
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/resources/META-INF/spring.schemas
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/resources/META-INF/spring.schemas?view=auto&rev=493767
==============================================================================
--- cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/resources/META-INF/spring.schemas
(added)
+++ cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/resources/META-INF/spring.schemas
Sun Jan  7 08:34:52 2007
@@ -0,0 +1,16 @@
+#  Licensed to the Apache Software Foundation (ASF) under one or more
+#  contributor license agreements.  See the NOTICE file distributed with
+#  this work for additional information regarding copyright ownership.
+#  The ASF licenses this file to You 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.
+#
+http\://cocoon.apache.org/schema/pipeline/cocoon-pipeline-1.0.xsd=org/apache/cocoon/core/container/spring/pipeline/pipeline.xsd

Propchange: cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/resources/META-INF/spring.schemas
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/resources/org/apache/cocoon/core/container/spring/pipeline/pipeline.xsd
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/resources/org/apache/cocoon/core/container/spring/pipeline/pipeline.xsd?view=auto&rev=493767
==============================================================================
--- cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/resources/org/apache/cocoon/core/container/spring/pipeline/pipeline.xsd
(added)
+++ cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/resources/org/apache/cocoon/core/container/spring/pipeline/pipeline.xsd
Sun Jan  7 08:34:52 2007
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You 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.
+-->
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+        targetNamespace="http://cocoon.apache.org/schema/pipeline"
+        xmlns:tns="http://cocoon.apache.org/schema/pipeline">
+
+    <xsd:element name="component" type="tns:componentType"/>
+
+    <xsd:complexType name="componentType">
+    	<xsd:attribute name="mime-type" type="xsd:string" use="optional"/>
+    	<xsd:attribute name="label" type="xsd:string" use="optional"/>
+        <xsd:attribute name="hint" type="xsd:string" use="optional"/>
+    </xsd:complexType>
+</xsd:schema>
\ No newline at end of file

Modified: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java?view=diff&rev=493767&r1=493766&r2=493767
==============================================================================
--- cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
(original)
+++ cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
Sun Jan  7 08:34:52 2007
@@ -46,6 +46,7 @@
 import org.apache.cocoon.Constants;
 import org.apache.cocoon.classloader.reloading.Monitor;
 import org.apache.cocoon.components.LifecycleHelper;
+import org.apache.cocoon.components.pipeline.impl.PipelineComponentInfo;
 import org.apache.cocoon.components.source.util.SourceUtil;
 import org.apache.cocoon.components.treeprocessor.AbstractProcessingNode;
 import org.apache.cocoon.components.treeprocessor.CategoryNode;
@@ -56,7 +57,6 @@
 import org.apache.cocoon.components.treeprocessor.ParameterizableProcessingNode;
 import org.apache.cocoon.components.treeprocessor.ProcessingNode;
 import org.apache.cocoon.components.treeprocessor.ProcessingNodeBuilder;
-import org.apache.cocoon.components.treeprocessor.ProcessorComponentInfo;
 import org.apache.cocoon.components.treeprocessor.TreeBuilder;
 import org.apache.cocoon.components.treeprocessor.variables.VariableResolver;
 import org.apache.cocoon.components.treeprocessor.variables.VariableResolverFactory;
@@ -142,7 +142,7 @@
     /**
      * The sitemap component information grabbed while building itsMaanger
      */
-    protected ProcessorComponentInfo itsComponentInfo;
+    protected PipelineComponentInfo itsComponentInfo;
 
     /** Optional event listeners for the enter sitemap event */
     protected List enterSitemapEventListeners = new ArrayList();
@@ -360,7 +360,7 @@
         // register listeners
         this.registerListeners();
 
-        this.itsComponentInfo = (ProcessorComponentInfo) this.itsManager.lookup(ProcessorComponentInfo.ROLE);
+        this.itsComponentInfo = (PipelineComponentInfo) this.itsManager.lookup(PipelineComponentInfo.ROLE);
         // Create a helper object to setup components
         this.itsLifecycle = new LifecycleHelper(getLogger(), itsContext, this.itsManager,
null /* configuration */);
 

Modified: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/BridgeElementParser.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/BridgeElementParser.java?view=diff&rev=493767&r1=493766&r2=493767
==============================================================================
--- cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/BridgeElementParser.java
(original)
+++ cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/BridgeElementParser.java
Sun Jan  7 08:34:52 2007
@@ -28,8 +28,10 @@
 import org.apache.avalon.framework.thread.ThreadSafe;
 import org.apache.cocoon.acting.Action;
 import org.apache.cocoon.components.pipeline.ProcessingPipeline;
-import org.apache.cocoon.components.treeprocessor.ProcessorComponentInfo;
+import org.apache.cocoon.components.pipeline.impl.PipelineComponentInfo;
 import org.apache.cocoon.configuration.Settings;
+import org.apache.cocoon.core.container.spring.pipeline.PipelineComponentInfoFactoryBean;
+import org.apache.cocoon.core.container.spring.pipeline.PipelineComponentInfoInitializer;
 import org.apache.cocoon.generation.Generator;
 import org.apache.cocoon.matching.Matcher;
 import org.apache.cocoon.reading.Reader;
@@ -40,6 +42,7 @@
 import org.springframework.beans.factory.BeanDefinitionStoreException;
 import org.springframework.beans.factory.config.BeanDefinition;
 import org.springframework.beans.factory.config.RuntimeBeanReference;
+import org.springframework.beans.factory.support.BeanDefinitionBuilder;
 import org.springframework.beans.factory.support.BeanDefinitionReader;
 import org.springframework.beans.factory.support.BeanDefinitionRegistry;
 import org.springframework.beans.factory.support.RootBeanDefinition;
@@ -272,7 +275,7 @@
 
     protected void registerComponentInfo(ConfigurationInfo      configInfo,
                                          BeanDefinitionRegistry registry) {
-        ProcessorComponentInfo info = new ProcessorComponentInfo(null);
+        PipelineComponentInfo info = new PipelineComponentInfo(null);
         final Iterator i = configInfo.getComponents().values().iterator();
         while (i.hasNext()) {
             final ComponentInfo current = (ComponentInfo) i.next();
@@ -287,13 +290,23 @@
         prepareSelector(info, configInfo, Matcher.ROLE);
         prepareSelector(info, configInfo, Reader.ROLE);
         info.lock();
-        final RootBeanDefinition beanDef = new RootBeanDefinition();
-        beanDef.setBeanClass(ProcessorComponentInfoFactoryBean.class);
-        beanDef.setSingleton(true);
-        beanDef.setLazyInit(false);
-        beanDef.getPropertyValues().addPropertyValue("data", info.getData());
-        beanDef.setInitMethodName("init");
-        this.register(beanDef, ProcessorComponentInfo.ROLE, registry);
+        if (!registry.containsBeanDefinition(PipelineComponentInfo.ROLE)) {
+            final RootBeanDefinition beanDef = new RootBeanDefinition();
+            beanDef.setBeanClass(PipelineComponentInfoFactoryBean.class);
+            beanDef.setSingleton(true);
+            beanDef.setLazyInit(false);
+            beanDef.setInitMethodName("init");
+            this.register(beanDef, PipelineComponentInfo.ROLE, registry);
+        }
+        BeanDefinitionBuilder initDefBuilder =
+            BeanDefinitionBuilder.rootBeanDefinition(PipelineComponentInfoInitializer.class);
+        initDefBuilder.addPropertyReference("info", PipelineComponentInfo.ROLE);
+        initDefBuilder.setSingleton(true);
+        initDefBuilder.setLazyInit(false);
+        initDefBuilder.setInitMethodName("init");
+        initDefBuilder.addPropertyValue("data", info.getData());
+        final String beanName = this.getClass().getName() + "/init";
+        this.register(initDefBuilder.getBeanDefinition(), beanName, registry);
 
         final RootBeanDefinition ciBeanDef = new RootBeanDefinition();
         ciBeanDef.setBeanClass(ConfigurationInfoFactoryBean.class);
@@ -303,7 +316,7 @@
         this.register(ciBeanDef, ConfigurationInfo.class.getName(), registry);
     }
 
-    protected static void prepareSelector(ProcessorComponentInfo info,
+    protected static void prepareSelector(PipelineComponentInfo info,
                                           ConfigurationInfo configInfo,
                                           String category) {
         final ComponentInfo component = (ComponentInfo) configInfo.getComponents().get(category
+ "Selector");



Mime
View raw message