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/03/25 22:12:49 UTC
svn commit: r388833 - in
/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon:
components/treeprocessor/sitemap/ core/container/spring/
Author: cziegeler
Date: Sat Mar 25 13:12:47 2006
New Revision: 388833
URL: http://svn.apache.org/viewcvs?rev=388833&view=rev
Log:
Create component for creating bean factories
Added:
cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryFactory.java
cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryFactoryImpl.java (with props)
Modified:
cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryUtil.java
Modified: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java?rev=388833&r1=388832&r2=388833&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java (original)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java Sat Mar 25 13:12:47 2006
@@ -26,8 +26,6 @@
import java.util.Map;
import java.util.Set;
-import javax.servlet.ServletConfig;
-
import org.apache.avalon.excalibur.pool.Recyclable;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.activity.Initializable;
@@ -46,7 +44,6 @@
import org.apache.avalon.framework.service.Serviceable;
import org.apache.cocoon.Constants;
import org.apache.cocoon.ProcessingUtil;
-import org.apache.cocoon.components.ContextHelper;
import org.apache.cocoon.components.LifecycleHelper;
import org.apache.cocoon.components.source.SourceUtil;
import org.apache.cocoon.components.treeprocessor.AbstractProcessingNode;
@@ -62,18 +59,11 @@
import org.apache.cocoon.components.treeprocessor.TreeBuilder;
import org.apache.cocoon.components.treeprocessor.variables.VariableResolver;
import org.apache.cocoon.components.treeprocessor.variables.VariableResolverFactory;
-import org.apache.cocoon.core.Settings;
-import org.apache.cocoon.core.container.spring.AvalonEnvironment;
-import org.apache.cocoon.core.container.spring.BeanFactoryUtil;
-import org.apache.cocoon.core.container.spring.CocoonBeanFactory;
-import org.apache.cocoon.core.container.spring.ConfigReader;
-import org.apache.cocoon.core.container.spring.ConfigurationInfo;
+import org.apache.cocoon.core.container.spring.BeanFactoryFactoryImpl;
import org.apache.cocoon.environment.Environment;
-import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.internal.EnvironmentHelper;
import org.apache.cocoon.generation.Generator;
import org.apache.cocoon.serialization.Serializer;
-import org.apache.cocoon.servlet.CocoonServlet;
import org.apache.cocoon.sitemap.EnterSitemapEventListener;
import org.apache.cocoon.sitemap.LeaveSitemapEventListener;
import org.apache.cocoon.sitemap.PatternException;
@@ -385,7 +375,10 @@
// a configuration
// FIXME: Internal configurations doesn't work in a non bean factory
// environment
- this.itsBeanFactory = this.createBeanFactory(this.itsContext, componentConfig);
+ // TODO Get factory from spring
+ BeanFactoryFactoryImpl factory = new BeanFactoryFactoryImpl();
+ factory.setBeanFactory(this.beanFactory);
+ this.itsBeanFactory = factory.createBeanFactory(this.getLogger(), componentConfig, this.itsContext, this.processor.getSourceResolver());
this.itsManager = (ServiceManager) this.itsBeanFactory.getBean(ProcessingUtil.SERVICE_MANAGER_ROLE);
if (componentConfig != null) {
// only register listeners if a new bean factory is created
@@ -631,38 +624,6 @@
this.viewsNode = null;
this.isBuildingView = false;
this.isBuildingErrorHandler = false;
- }
-
- /**
- * Build a component manager with the contents of the <map:components>
- * element of the tree.
- */
- protected ConfigurableListableBeanFactory createBeanFactory(Context context,
- Configuration config)
- throws Exception {
- // setup spring container
- // first, get the correct parent
- ConfigurableListableBeanFactory parentFactory = this.beanFactory;
- final Request request = ContextHelper.getRequest(context);
- if (request.getAttribute(CocoonBeanFactory.BEAN_FACTORY_REQUEST_ATTRIBUTE, Request.REQUEST_SCOPE) != null) {
- parentFactory = (ConfigurableListableBeanFactory) request
- .getAttribute(CocoonBeanFactory.BEAN_FACTORY_REQUEST_ATTRIBUTE, Request.REQUEST_SCOPE);
- }
-
- if ( config != null ) {
- final AvalonEnvironment ae = new AvalonEnvironment();
- ae.context = context;
- ae.logger = this.getLogger();
- ae.servletContext = ((ServletConfig) context.get(CocoonServlet.CONTEXT_SERVLET_CONFIG))
- .getServletContext();
- ae.settings = (Settings) this.beanFactory.getBean(Settings.ROLE);
- final ConfigurationInfo parentConfigInfo = (ConfigurationInfo) parentFactory
- .getBean(ConfigurationInfo.class.getName());
- final ConfigurationInfo ci = ConfigReader.readConfiguration(config, parentConfigInfo, ae, this.processor.getSourceResolver());
-
- return BeanFactoryUtil.createBeanFactory(ae, ci, parentFactory, false);
- }
- return parentFactory;
}
/**
Added: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryFactory.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryFactory.java?rev=388833&view=auto
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryFactory.java (added)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryFactory.java Sat Mar 25 13:12:47 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.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.excalibur.source.SourceResolver;
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+
+/**
+ * Component to set up a new (per sitemap) bean factory.
+ *
+ * @since 2.2
+ * @version $Id$
+ */
+public interface BeanFactoryFactory {
+
+ /**
+ * Build a bean factory with the contents of the <map:components> element of
+ * the tree.
+ */
+ ConfigurableListableBeanFactory createBeanFactory(Logger sitemapLogger,
+ Configuration config,
+ Context sitemapContext,
+ SourceResolver resolver)
+ throws Exception;
+}
Added: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryFactoryImpl.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryFactoryImpl.java?rev=388833&view=auto
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryFactoryImpl.java (added)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryFactoryImpl.java Sat Mar 25 13:12:47 2006
@@ -0,0 +1,88 @@
+/*
+ * 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 javax.servlet.ServletConfig;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.cocoon.ProcessingUtil;
+import org.apache.cocoon.components.ContextHelper;
+import org.apache.cocoon.core.Settings;
+import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.servlet.CocoonServlet;
+import org.apache.excalibur.source.SourceResolver;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.BeanFactoryAware;
+import org.springframework.beans.factory.BeanInitializationException;
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+
+/**
+ * @see BeanFactoryFactory
+ * @since 2.2
+ * @version $Id$
+ */
+public class BeanFactoryFactoryImpl
+ implements BeanFactoryFactory, BeanFactoryAware {
+
+ protected ConfigurableListableBeanFactory beanFactory;
+
+ public void setBeanFactory(BeanFactory factory) throws BeansException {
+ if ( !(factory instanceof ConfigurableListableBeanFactory) ) {
+ throw new BeanInitializationException("BeanFactory is not a configurable listable bean factory: " + factory);
+ }
+ this.beanFactory = (ConfigurableListableBeanFactory)factory;
+ }
+
+ /**
+ * @see org.apache.cocoon.core.container.spring.BeanFactoryFactory#createBeanFactory(org.apache.avalon.framework.logger.Logger, org.apache.avalon.framework.configuration.Configuration, org.apache.avalon.framework.context.Context, org.apache.excalibur.source.SourceResolver)
+ */
+ public ConfigurableListableBeanFactory createBeanFactory(Logger sitemapLogger,
+ Configuration config,
+ Context sitemapContext,
+ SourceResolver resolver)
+ throws Exception {
+ // setup spring container
+ // first, get the correct parent
+ ConfigurableListableBeanFactory parentFactory = this.beanFactory;
+ final Request request = ContextHelper.getRequest(sitemapContext);
+ if (request.getAttribute(CocoonBeanFactory.BEAN_FACTORY_REQUEST_ATTRIBUTE, Request.REQUEST_SCOPE) != null) {
+ parentFactory = (ConfigurableListableBeanFactory) request
+ .getAttribute(CocoonBeanFactory.BEAN_FACTORY_REQUEST_ATTRIBUTE, Request.REQUEST_SCOPE);
+ }
+
+ if ( config != null ) {
+ final AvalonEnvironment ae = new AvalonEnvironment();
+ ae.context = sitemapContext;
+ if ( sitemapLogger != null ) {
+ ae.logger = sitemapLogger;
+ } else {
+ ae.logger = (Logger)parentFactory.getBean(ProcessingUtil.LOGGER_ROLE);
+ }
+ ae.servletContext = ((ServletConfig) sitemapContext.get(CocoonServlet.CONTEXT_SERVLET_CONFIG))
+ .getServletContext();
+ ae.settings = (Settings) this.beanFactory.getBean(Settings.ROLE);
+ final ConfigurationInfo parentConfigInfo = (ConfigurationInfo) parentFactory
+ .getBean(ConfigurationInfo.class.getName());
+ final ConfigurationInfo ci = ConfigReader.readConfiguration(config, parentConfigInfo, ae, resolver);
+
+ return BeanFactoryUtil.createBeanFactory(ae, ci, parentFactory, false);
+ }
+ return parentFactory;
+ }
+}
Propchange: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryFactoryImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryFactoryImpl.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryUtil.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryUtil.java?rev=388833&r1=388832&r2=388833&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryUtil.java (original)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryUtil.java Sat Mar 25 13:12:47 2006
@@ -46,6 +46,7 @@
import org.apache.cocoon.serialization.Serializer;
import org.apache.cocoon.servlet.CocoonServlet;
import org.apache.cocoon.transformation.Transformer;
+import org.apache.excalibur.source.SourceResolver;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;
@@ -260,17 +261,18 @@
* Build a bean factory with the contents of the <map:components> element of
* the tree.
*/
- protected ConfigurableListableBeanFactory createBeanFactory(Logger sitemapLogger,
- Configuration config,
- Context sitemapContext)
+ public ConfigurableListableBeanFactory createBeanFactory(Logger sitemapLogger,
+ Configuration config,
+ Context sitemapContext,
+ SourceResolver resolver)
throws Exception {
// setup spring container
// first, get the correct parent
ConfigurableListableBeanFactory parentFactory = this.beanFactory;
final Request request = ContextHelper.getRequest(sitemapContext);
- if (request.getAttribute(CocoonBeanFactory.BEAN_FACTORY_REQUEST_ATTRIBUTE) != null) {
+ if (request.getAttribute(CocoonBeanFactory.BEAN_FACTORY_REQUEST_ATTRIBUTE, Request.REQUEST_SCOPE) != null) {
parentFactory = (ConfigurableListableBeanFactory) request
- .getAttribute(CocoonBeanFactory.BEAN_FACTORY_REQUEST_ATTRIBUTE);
+ .getAttribute(CocoonBeanFactory.BEAN_FACTORY_REQUEST_ATTRIBUTE, Request.REQUEST_SCOPE);
}
if ( config != null ) {
@@ -286,7 +288,7 @@
ae.settings = (Settings) this.beanFactory.getBean(Settings.ROLE);
final ConfigurationInfo parentConfigInfo = (ConfigurationInfo) parentFactory
.getBean(ConfigurationInfo.class.getName());
- final ConfigurationInfo ci = ConfigReader.readConfiguration(config, parentConfigInfo, ae, null);
+ final ConfigurationInfo ci = ConfigReader.readConfiguration(config, parentConfigInfo, ae, resolver);
return BeanFactoryUtil.createBeanFactory(ae, ci, parentFactory, false);
}