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/08/24 22:29:19 UTC
svn commit: r434510 - in /cocoon/trunk/core:
cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/
cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/
cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/aval...
Author: cziegeler
Date: Thu Aug 24 13:29:17 2006
New Revision: 434510
URL: http://svn.apache.org/viewvc?rev=434510&view=rev
Log:
Nearly there: added own namespace handler to setup Cocoon using Spring
Added:
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonNamespaceHandler.java (with props)
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SettingsElementParser.java (with props)
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonElementParser.java (with props)
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ConfigurationInfoFactoryBean.java (with props)
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ProcessorComponentInfoFactoryBean.java (with props)
cocoon/trunk/core/cocoon-core/src/main/resources/META-INF/spring.handlers
cocoon/trunk/core/cocoon-core/src/main/resources/META-INF/spring.schemas
cocoon/trunk/core/cocoon-core/src/main/resources/org/apache/cocoon/core/container/spring/
cocoon/trunk/core/cocoon-core/src/main/resources/org/apache/cocoon/core/container/spring/cocoon.xsd
Removed:
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonConfigurator.java
cocoon/trunk/core/cocoon-core/src/main/resources/org/apache/cocoon/core/container/handler/
Modified:
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/ProcessorComponentInfo.java
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/AvalonServiceManager.java
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonBeanPostProcessor.java
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonLoggerFactoryBean.java
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ConfigReader.java
cocoon/trunk/core/cocoon-webapp/src/main/webapp/WEB-INF/applicationContext.xml
Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/ProcessorComponentInfo.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/ProcessorComponentInfo.java?rev=434510&r1=434509&r2=434510&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/ProcessorComponentInfo.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/ProcessorComponentInfo.java Thu Aug 24 13:29:17 2006
@@ -184,4 +184,12 @@
}
return false;
}
+
+ public Map getData() {
+ return this.data;
+ }
+
+ public void setData(Map map) {
+ this.data = map;
+ }
}
Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/AvalonServiceManager.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/AvalonServiceManager.java?rev=434510&r1=434509&r2=434510&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/AvalonServiceManager.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/AvalonServiceManager.java Thu Aug 24 13:29:17 2006
@@ -27,7 +27,7 @@
* @since 2.2
* @version $Id$
*/
-final class AvalonServiceManager
+final public class AvalonServiceManager
implements ServiceManager, BeanFactoryAware {
Added: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonNamespaceHandler.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonNamespaceHandler.java?rev=434510&view=auto
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonNamespaceHandler.java (added)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonNamespaceHandler.java Thu Aug 24 13:29:17 2006
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2006 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.core.container.spring;
+
+import org.apache.cocoon.core.container.spring.avalon.AvalonElementParser;
+import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
+
+/**
+ * Spring namespace handler for the cocoon core namespace.
+ * Currently this namespace defines the following elements
+ * (in the namespace "http://org.apache.cocoon/core"):
+ * "settings" : This sets up the Cocoon Settings object (by reading the property
+ * files located under /WEB-INF/cocoon/properties.
+ *
+ * @version $Id$
+ * @since 2.2
+ */
+public class CocoonNamespaceHandler extends NamespaceHandlerSupport {
+
+ /**
+ * @see org.springframework.beans.factory.xml.NamespaceHandler#init()
+ */
+ public void init() {
+ registerBeanDefinitionParser("avalon", new AvalonElementParser());
+ registerBeanDefinitionParser("settings", new SettingsElementParser());
+ }
+}
Propchange: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonNamespaceHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonNamespaceHandler.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SettingsElementParser.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SettingsElementParser.java?rev=434510&view=auto
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SettingsElementParser.java (added)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SettingsElementParser.java Thu Aug 24 13:29:17 2006
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2006 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.core.container.spring;
+
+import org.apache.cocoon.configuration.Settings;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.beans.factory.config.BeanDefinitionHolder;
+import org.springframework.beans.factory.config.RuntimeBeanReference;
+import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
+import org.springframework.beans.factory.support.BeanDefinitionRegistry;
+import org.springframework.beans.factory.support.RootBeanDefinition;
+import org.springframework.beans.factory.xml.BeanDefinitionParser;
+import org.springframework.beans.factory.xml.ParserContext;
+import org.w3c.dom.Element;
+
+/**
+ * @version $Id$
+ * @since 2.2
+ */
+public class SettingsElementParser implements BeanDefinitionParser {
+
+ /**
+ * @see org.springframework.beans.factory.xml.BeanDefinitionParser#parse(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext)
+ */
+ public BeanDefinition parse(Element element, ParserContext parserContext) {
+ this.addComponent(SettingsBeanFactoryPostProcessor.class,
+ Settings.ROLE,
+ "init",
+ false,
+ parserContext.getRegistry());
+ return null;
+ }
+
+ protected void addComponent(Class componentClass,
+ String role,
+ String initMethod,
+ boolean requiresSettings,
+ BeanDefinitionRegistry registry) {
+ RootBeanDefinition beanDef = new RootBeanDefinition();
+ beanDef.setBeanClass(componentClass);
+ beanDef.setSingleton(true);
+ if ( initMethod != null ) {
+ beanDef.setInitMethodName(initMethod);
+ }
+ if ( requiresSettings ) {
+ beanDef.getPropertyValues().addPropertyValue("settings", new RuntimeBeanReference(Settings.ROLE));
+ }
+
+ BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDef, role);
+ BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry);
+ }
+}
Propchange: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SettingsElementParser.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SettingsElementParser.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonBeanPostProcessor.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonBeanPostProcessor.java?rev=434510&r1=434509&r2=434510&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonBeanPostProcessor.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonBeanPostProcessor.java Thu Aug 24 13:29:17 2006
@@ -20,6 +20,8 @@
/**
* This is a Spring BeanPostProcessor adding support for the Avalon lifecycle interfaces.
+ * @version $Id$
+ * @since 2.2
*/
public class AvalonBeanPostProcessor
implements DestructionAwareBeanPostProcessor, BeanFactoryAware {
Added: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonElementParser.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonElementParser.java?rev=434510&view=auto
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonElementParser.java (added)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonElementParser.java Thu Aug 24 13:29:17 2006
@@ -0,0 +1,325 @@
+/*
+ * Copyright 2006 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.core.container.spring.avalon;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.avalon.excalibur.pool.Poolable;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.cocoon.ProcessingUtil;
+import org.apache.cocoon.acting.Action;
+import org.apache.cocoon.components.pipeline.ProcessingPipeline;
+import org.apache.cocoon.components.treeprocessor.ProcessorComponentInfo;
+import org.apache.cocoon.configuration.Settings;
+import org.apache.cocoon.core.container.spring.AvalonServiceManager;
+import org.apache.cocoon.core.container.spring.AvalonServiceSelector;
+import org.apache.cocoon.core.container.spring.ComponentInfo;
+import org.apache.cocoon.core.container.spring.ConfigurationInfo;
+import org.apache.cocoon.core.container.spring.PoolableFactoryBean;
+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;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.factory.BeanDefinitionStoreException;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.beans.factory.config.BeanDefinitionHolder;
+import org.springframework.beans.factory.config.RuntimeBeanReference;
+import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
+import org.springframework.beans.factory.support.BeanDefinitionRegistry;
+import org.springframework.beans.factory.support.RootBeanDefinition;
+import org.springframework.beans.factory.xml.BeanDefinitionParser;
+import org.springframework.beans.factory.xml.ParserContext;
+import org.springframework.core.io.ResourceLoader;
+import org.springframework.util.StringUtils;
+import org.w3c.dom.Element;
+
+/**
+ * @version $Id$
+ * @since 2.2
+ */
+public class AvalonElementParser implements BeanDefinitionParser {
+
+ /** Logger (we use the same logging mechanism as Spring!) */
+ protected final Log logger = LogFactory.getLog(getClass());
+
+ /**
+ * @see org.springframework.beans.factory.xml.BeanDefinitionParser#parse(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext)
+ */
+ public BeanDefinition parse(Element element, ParserContext parserContext) {
+ // TODO: we should first check if there is already a logger configured in spring
+ // add logger
+ this.addComponent(AvalonLoggerFactoryBean.class,
+ ProcessingUtil.LOGGER_ROLE,
+ "init",
+ true,
+ parserContext.getRegistry());
+ // add context
+ this.addComponent(AvalonContextFactoryBean.class,
+ ProcessingUtil.CONTEXT_ROLE,
+ "init",
+ true,
+ parserContext.getRegistry());
+
+ // add service manager
+ this.addComponent(AvalonServiceManager.class,
+ ProcessingUtil.SERVICE_MANAGER_ROLE,
+ null,
+ false,
+ parserContext.getRegistry());
+
+ // read avalon style configuration
+ // the schema ensures that location is never null
+ final String location = element.getAttribute("location");
+ final ResourceLoader resourceLoader = parserContext.getReaderContext().getReader().getResourceLoader();
+ try {
+ final ConfigurationInfo info = ConfigReader.readConfiguration(location, resourceLoader);
+ // first handle includes
+ final Iterator includeIter = info.getImports().iterator();
+ while ( includeIter.hasNext() ) {
+ final String uri = (String)includeIter.next();
+ parserContext.getDelegate().getReaderContext().getReader().loadBeanDefinitions(resourceLoader.getResource(uri));
+ }
+
+ // then create components
+ this.createConfig(info, parserContext.getRegistry());
+
+ // register component infos for child factories
+ this.registerComponentInfo(info, parserContext.getRegistry());
+
+ // and finally add avalon bean post processor
+ final RootBeanDefinition beanDef = new RootBeanDefinition();
+ beanDef.setBeanClass(AvalonBeanPostProcessor.class);
+ beanDef.setSingleton(true);
+ beanDef.setLazyInit(false);
+ beanDef.getPropertyValues().addPropertyValue("logger", new RuntimeBeanReference(ProcessingUtil.LOGGER_ROLE));
+ beanDef.getPropertyValues().addPropertyValue("context", new RuntimeBeanReference(ProcessingUtil.CONTEXT_ROLE));
+ beanDef.getPropertyValues().addPropertyValue("configurationInfo", new RuntimeBeanReference(ConfigurationInfo.class.getName()));
+
+ final BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDef, AvalonBeanPostProcessor.class.getName());
+ BeanDefinitionReaderUtils.registerBeanDefinition(holder, parserContext.getRegistry());
+
+ } catch (Exception e) {
+ throw new BeanDefinitionStoreException("Unable to read Avalon configuration from '" + location + "'.",e);
+ }
+
+ return null;
+ }
+
+ protected void addComponent(Class componentClass,
+ String role,
+ String initMethod,
+ boolean requiresSettings,
+ BeanDefinitionRegistry registry) {
+ final RootBeanDefinition beanDef = new RootBeanDefinition();
+ beanDef.setBeanClass(componentClass);
+ beanDef.setSingleton(true);
+ beanDef.setLazyInit(false);
+ if ( initMethod != null ) {
+ beanDef.setInitMethodName(initMethod);
+ }
+ if ( requiresSettings ) {
+ beanDef.getPropertyValues().addPropertyValue("settings", new RuntimeBeanReference(Settings.ROLE));
+ }
+
+ final BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDef, role);
+ BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry);
+ }
+
+ public void createConfig(ConfigurationInfo info,
+ BeanDefinitionRegistry registry)
+ throws Exception {
+ final Map components = info.getComponents();
+ final List pooledRoles = new ArrayList();
+
+ // Iterate over all definitions
+ final Iterator i = components.entrySet().iterator();
+ while ( i.hasNext() ) {
+ final Map.Entry entry = (Map.Entry)i.next();
+ final ComponentInfo current = (ComponentInfo)entry.getValue();
+ final String role = current.getRole();
+
+ String className = current.getComponentClassName();
+ boolean isSelector = false;
+ boolean singleton = true;
+ boolean poolable = false;
+ // Test for Selector - we just create a wrapper for them to flatten the hierarchy
+ if ( current.isSelector() ) {
+ // Add selector
+ className = AvalonServiceSelector.class.getName();
+ isSelector = true;
+ } else {
+ // test for unknown model
+ if ( current.getModel() == ComponentInfo.MODEL_UNKNOWN ) {
+ try {
+ final Class serviceClass = Class.forName(className);
+ if ( ThreadSafe.class.isAssignableFrom(serviceClass) ) {
+ current.setModel(ComponentInfo.MODEL_SINGLETON);
+ } else if ( Poolable.class.isAssignableFrom(serviceClass) ) {
+ current.setModel(ComponentInfo.MODEL_POOLED);
+ } else {
+ current.setModel(ComponentInfo.MODEL_PRIMITIVE);
+ }
+ } catch (NoClassDefFoundError ncdfe) {
+ throw new ConfigurationException("Unable to create class for component with role " + current.getRole() + " with class: " + className, ncdfe);
+ } catch (ClassNotFoundException cnfe) {
+ throw new ConfigurationException("Unable to create class for component with role " + current.getRole() + " with class: " + className, cnfe);
+ }
+ }
+ if ( current.getModel() == ComponentInfo.MODEL_POOLED ) {
+ poolable = true;
+ singleton = false;
+ } else if ( current.getModel() != ComponentInfo.MODEL_SINGLETON ) {
+ singleton = false;
+ }
+ }
+ final String beanName;
+ if ( !poolable ) {
+ beanName = this.xml(role);
+ } else {
+ beanName = this.xml(role + "Pooled");
+ }
+ final RootBeanDefinition beanDef = new RootBeanDefinition();
+ beanDef.setBeanClassName(className);
+ if ( current.getInitMethodName() != null ) {
+ beanDef.setInitMethodName(current.getInitMethodName());
+ }
+ if ( current.getDestroyMethodName() != null ) {
+ beanDef.setDestroyMethodName(current.getDestroyMethodName());
+ }
+ beanDef.setSingleton(singleton);
+ beanDef.setLazyInit(singleton && current.isLazyInit());
+ if ( isSelector ) {
+ beanDef.getConstructorArgumentValues().addGenericArgumentValue(role.substring(0, role.length()-8), "java.lang.String");
+ if ( current.getDefaultValue() != null ) {
+ beanDef.getPropertyValues().addPropertyValue("default", current.getDefaultValue());
+ }
+ }
+ final BeanDefinitionHolder holder;
+ if ( current.getAlias() == null ) {
+ holder = new BeanDefinitionHolder(beanDef, beanName);
+ } else {
+ holder = new BeanDefinitionHolder(beanDef, beanName, new String[] {current.getAlias()});
+ }
+ BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry);
+
+ if ( poolable ) {
+ // add the factory for poolables
+ final RootBeanDefinition poolableBeanDef = new RootBeanDefinition();
+ poolableBeanDef.setBeanClass(PoolableFactoryBean.class);
+ poolableBeanDef.setSingleton(true);
+ poolableBeanDef.setLazyInit(false);
+ poolableBeanDef.setInitMethodName("initialize");
+ poolableBeanDef.setDestroyMethodName("dispose");
+ poolableBeanDef.getConstructorArgumentValues().addGenericArgumentValue(this.xml(role) + "Pooled", "java.lang.String");
+ poolableBeanDef.getConstructorArgumentValues().addGenericArgumentValue(className, "java.lang.String");
+ if ( current.getConfiguration() != null ) {
+ final int poolMax = current.getConfiguration().getAttributeAsInteger("pool-max", -1);
+ if ( poolMax != -1 ) {
+ poolableBeanDef.getConstructorArgumentValues().addGenericArgumentValue(new Integer(poolMax));
+ }
+ }
+ if ( current.getPoolInMethodName() != null ) {
+ poolableBeanDef.getPropertyValues().addPropertyValue("poolInMethodName", current.getPoolInMethodName());
+ }
+ if ( current.getPoolOutMethodName() != null ) {
+ poolableBeanDef.getPropertyValues().addPropertyValue("poolOutMethodName", current.getPoolOutMethodName());
+ }
+ BeanDefinitionHolder poolableHolder = new BeanDefinitionHolder(poolableBeanDef, this.xml(role));
+ BeanDefinitionReaderUtils.registerBeanDefinition(poolableHolder, registry);
+ pooledRoles.add(role);
+ }
+ }
+
+ // now change roles for pooled components (from {role} to {role}Pooled
+ final Iterator prI = pooledRoles.iterator();
+ while ( prI.hasNext() ) {
+ final String role = (String)prI.next();
+ final Object pooledInfo = components.remove(role);
+ components.put(role + "Pooled", pooledInfo);
+ }
+ }
+
+ protected String xml(String value) {
+ String result;
+ result = StringUtils.replace(value, "&", "&");
+ result = StringUtils.replace(result, "<", "<");
+ result = StringUtils.replace(result, ">", ">");
+ return result;
+ }
+
+ protected void appendAttribute(StringBuffer buffer, String attr, String value) {
+ if ( value != null ) {
+ buffer.append(' ');
+ buffer.append(attr);
+ buffer.append("=\"");
+ buffer.append(value);
+ buffer.append("\"");
+ }
+ }
+
+ protected void registerComponentInfo(ConfigurationInfo configInfo,
+ BeanDefinitionRegistry registry) {
+ ProcessorComponentInfo info = new ProcessorComponentInfo(null);
+ final Iterator i = configInfo.getComponents().values().iterator();
+ while (i.hasNext()) {
+ final ComponentInfo current = (ComponentInfo) i.next();
+ info.componentAdded(current.getRole(), current.getComponentClassName(), current.getConfiguration());
+ }
+ prepareSelector(info, configInfo, Generator.ROLE);
+ prepareSelector(info, configInfo, Transformer.ROLE);
+ prepareSelector(info, configInfo, Serializer.ROLE);
+ prepareSelector(info, configInfo, ProcessingPipeline.ROLE);
+ prepareSelector(info, configInfo, Action.ROLE);
+ prepareSelector(info, configInfo, Selector.ROLE);
+ 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");
+ final BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDef, ProcessorComponentInfo.ROLE);
+ BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry);
+
+ final RootBeanDefinition ciBeanDef = new RootBeanDefinition();
+ ciBeanDef.setBeanClass(ConfigurationInfoFactoryBean.class);
+ ciBeanDef.setSingleton(true);
+ ciBeanDef.setLazyInit(false);
+ ciBeanDef.getPropertyValues().addPropertyValue("configurationInfo", configInfo);
+ final BeanDefinitionHolder ciHolder = new BeanDefinitionHolder(ciBeanDef, ConfigurationInfo.class.getName());
+ BeanDefinitionReaderUtils.registerBeanDefinition(ciHolder, registry);
+ }
+
+ protected static void prepareSelector(ProcessorComponentInfo info,
+ ConfigurationInfo configInfo,
+ String category) {
+ final ComponentInfo component = (ComponentInfo) configInfo.getComponents().get(category + "Selector");
+ if (component != null) {
+ info.setDefaultType(category, component.getDefaultValue());
+ }
+ }
+}
Propchange: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonElementParser.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonElementParser.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonLoggerFactoryBean.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonLoggerFactoryBean.java?rev=434510&r1=434509&r2=434510&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonLoggerFactoryBean.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonLoggerFactoryBean.java Thu Aug 24 13:29:17 2006
@@ -61,7 +61,7 @@
* @param logLevelString
* @return the logger
*/
- protected Logger createBootstrapLogger(ServletContext servletContext, String logLevelString) {
+ protected Logger createBootstrapLogger(String logLevelString) {
// create a bootstrap logger
int logLevel;
if ( "DEBUG".equalsIgnoreCase(logLevelString) ) {
@@ -73,14 +73,14 @@
} else {
logLevel = ServletLogger.LEVEL_INFO;
}
- return new ServletLogger(servletContext, "Cocoon", logLevel);
+ return new ServletLogger(this.servletContext, "Cocoon", logLevel);
}
protected void init()
throws Exception {
// create a bootstrap logger
final String logLevelString = settings.getBootstrapLogLevel();
- final Logger bootstrapLogger = this.createBootstrapLogger(servletContext, logLevelString);
+ final Logger bootstrapLogger = this.createBootstrapLogger(logLevelString);
// create an own context for the logger manager
final DefaultContext subcontext = new SettingsContext(settings);
Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ConfigReader.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ConfigReader.java?rev=434510&r1=434509&r2=434510&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ConfigReader.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ConfigReader.java Thu Aug 24 13:29:17 2006
@@ -27,10 +27,10 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
import org.apache.cocoon.Constants;
import org.apache.cocoon.core.container.spring.ComponentInfo;
import org.apache.cocoon.core.container.spring.ConfigurationInfo;
-import org.apache.cocoon.core.container.util.ConfigurationBuilder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.io.Resource;
@@ -140,7 +140,7 @@
}
protected String getUrl(String url, String base) {
- return url;
+ return this.convertUrl(url);
}
protected void convert(String relativePath)
@@ -149,7 +149,7 @@
this.logger.info("Reading Avalon configuration from " + relativePath);
}
Resource root = this.resolver.getResource(this.convertUrl(relativePath));
- final ConfigurationBuilder b = new ConfigurationBuilder(null);
+ final DefaultConfigurationBuilder b = new DefaultConfigurationBuilder();
final Configuration config = b.build(this.getInputSource(root));
// validate cocoon.xconf
@@ -195,7 +195,7 @@
this.logger.info("Reading additional user roles: " + userRoles);
}
final Resource userRolesSource = this.resolver.getResource(this.getUrl(userRoles, rootUri));
- final ConfigurationBuilder b = new ConfigurationBuilder(null);
+ final DefaultConfigurationBuilder b = new DefaultConfigurationBuilder();
final Configuration userRolesConfig = b.build(this.getInputSource(userRolesSource));
this.parseConfiguration(userRolesConfig, userRolesSource.getURL().toExternalForm(), loadedConfigs);
}
@@ -398,7 +398,7 @@
// load it and store it in the read set
Configuration includeConfig = null;
try {
- ConfigurationBuilder builder = new ConfigurationBuilder(null);
+ DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(null);
includeConfig = builder.build(src.getInputStream(), uri);
} catch (Exception e) {
throw new ConfigurationException("Cannot load '" + uri + "' at " + includeStatement.getLocation(), e);
Added: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ConfigurationInfoFactoryBean.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ConfigurationInfoFactoryBean.java?rev=434510&view=auto
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ConfigurationInfoFactoryBean.java (added)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ConfigurationInfoFactoryBean.java Thu Aug 24 13:29:17 2006
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2006 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.core.container.spring.avalon;
+
+import org.apache.cocoon.core.container.spring.ConfigurationInfo;
+import org.springframework.beans.factory.FactoryBean;
+
+/**
+ * This spring factory bean adds the configuration info to the bean factory.
+ *
+ * @since 2.2
+ * @version $Id$
+ */
+public class ConfigurationInfoFactoryBean
+ implements FactoryBean {
+
+ protected ConfigurationInfo info;
+
+ /**
+ * @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 ConfigurationInfo.class;
+ }
+
+ /**
+ * @see org.springframework.beans.factory.FactoryBean#isSingleton()
+ */
+ public boolean isSingleton() {
+ return true;
+ }
+
+ public ConfigurationInfo getInfo() {
+ return info;
+ }
+
+ public void setInfo(ConfigurationInfo info) {
+ this.info = info;
+ }
+}
Propchange: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ConfigurationInfoFactoryBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ConfigurationInfoFactoryBean.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ProcessorComponentInfoFactoryBean.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ProcessorComponentInfoFactoryBean.java?rev=434510&view=auto
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ProcessorComponentInfoFactoryBean.java (added)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ProcessorComponentInfoFactoryBean.java Thu Aug 24 13:29:17 2006
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2006 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.core.container.spring.avalon;
+
+import java.util.Map;
+
+import org.apache.cocoon.components.treeprocessor.ProcessorComponentInfo;
+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$
+ */
+public class ProcessorComponentInfoFactoryBean
+ implements FactoryBean, BeanFactoryAware {
+
+ /** The bean factory. */
+ protected BeanFactory beanFactory;
+
+ protected Map data;
+
+ protected ProcessorComponentInfo 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 {
+ ProcessorComponentInfo parent = null;
+ if ( this.beanFactory instanceof HierarchicalBeanFactory ) {
+ BeanFactory parentFactory = ((HierarchicalBeanFactory)this.beanFactory).getParentBeanFactory();
+ if ( parentFactory != null && parentFactory.containsBean(ProcessorComponentInfo.ROLE) ) {
+ parent = (ProcessorComponentInfo)parentFactory.getBean(ProcessorComponentInfo.ROLE);
+ }
+ }
+ this.info = new ProcessorComponentInfo(parent);
+ if ( this.data != null ) {
+ info.setData(data);
+ info.lock();
+ }
+ }
+
+ /**
+ * @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 ProcessorComponentInfo.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;
+ }
+}
Propchange: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ProcessorComponentInfoFactoryBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ProcessorComponentInfoFactoryBean.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: cocoon/trunk/core/cocoon-core/src/main/resources/META-INF/spring.handlers
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/resources/META-INF/spring.handlers?rev=434510&view=auto
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/resources/META-INF/spring.handlers (added)
+++ cocoon/trunk/core/cocoon-core/src/main/resources/META-INF/spring.handlers Thu Aug 24 13:29:17 2006
@@ -0,0 +1,19 @@
+# Copyright 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.
+#
+# This file contains the default settings for Cocoon.
+# You should NOT change this file directly. Create your own properties
+# file and put it in the sub directories for the mode you are running
+# Cocoon in.
+http\://org.apache.cocoon/core=org.apache.cocoon.core.container.spring.CocoonNamespaceHandler
Added: cocoon/trunk/core/cocoon-core/src/main/resources/META-INF/spring.schemas
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/resources/META-INF/spring.schemas?rev=434510&view=auto
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/resources/META-INF/spring.schemas (added)
+++ cocoon/trunk/core/cocoon-core/src/main/resources/META-INF/spring.schemas Thu Aug 24 13:29:17 2006
@@ -0,0 +1,19 @@
+# Copyright 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.
+#
+# This file contains the default settings for Cocoon.
+# You should NOT change this file directly. Create your own properties
+# file and put it in the sub directories for the mode you are running
+# Cocoon in.
+http\://org.apache.cocoon/core.xsd=org/apache/cocoon/core/container/spring/cocoon.xsd
Added: cocoon/trunk/core/cocoon-core/src/main/resources/org/apache/cocoon/core/container/spring/cocoon.xsd
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/resources/org/apache/cocoon/core/container/spring/cocoon.xsd?rev=434510&view=auto
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/resources/org/apache/cocoon/core/container/spring/cocoon.xsd (added)
+++ cocoon/trunk/core/cocoon-core/src/main/resources/org/apache/cocoon/core/container/spring/cocoon.xsd Thu Aug 24 13:29:17 2006
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2006 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.
+-->
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://org.apache.cocoon/core"
+ xmlns:tns="http://org.apache.cocoon/core">
+
+ <xsd:element name="settings" type="tns:settingsType"/>
+ <xsd:element name="avalon" type="tns:avalonType"/>
+
+ <xsd:complexType name="avalonType">
+ <xsd:attribute name="location" type="xsd:string"></xsd:attribute>
+ </xsd:complexType>
+
+ <xsd:complexType name="settingsType"/>
+</xsd:schema>
\ No newline at end of file
Modified: cocoon/trunk/core/cocoon-webapp/src/main/webapp/WEB-INF/applicationContext.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-webapp/src/main/webapp/WEB-INF/applicationContext.xml?rev=434510&r1=434509&r2=434510&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-webapp/src/main/webapp/WEB-INF/applicationContext.xml (original)
+++ cocoon/trunk/core/cocoon-webapp/src/main/webapp/WEB-INF/applicationContext.xml Thu Aug 24 13:29:17 2006
@@ -18,27 +18,19 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
+ xmlns:cocoon="http://org.apache.cocoon/core"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
+ http://org.apache.cocoon/core http://org.apache.cocoon/core.xsd">
+ <!-- Load all the properties for Cocoon -->
+ <cocoon:settings/>
+
+ <cocoon:avalon location="/WEB-INF/cocoon/cocoon.xconf"/>
<!-- The following bean definitions will be replaced later on with
the use of the new namespace handling in spring:
<cocoon:settings/>
<cocoon:avalon-logger/>
<cocoon:avalon-support config="/WEB-INF/cocoon/cocoon.xconf"/>
-->
- <bean id="org.apache.cocoon.configuration.Settings"
- class="org.apache.cocoon.core.container.spring.SettingsBeanFactoryPostProcessor"
- singleton="true" init-method="init"/>
-
- <bean id="org.apache.avalon.framework.logger.Logger"
- class="org.apache.cocoon.core.container.spring.avalon.AvalonLoggerFactoryBean"
- singleton="true" init-method="init">
- <property name="settings"><ref bean="org.apache.cocoon.configuration.Settings"/></property>
- </bean>
-
- <bean id="org.apache.avalon.framework.context.Context"
- class="org.apache.cocoon.core.container.spring.avalon.AvalonContextFactoryBean"
- singleton="true" init-method="init">
- <property name="settings"><ref bean="org.apache.cocoon.configuration.Settings"/></property>
- </bean>
</beans>