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/12/31 12:32:12 UTC
svn commit: r491402 - in
/cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main:
java/org/apache/cocoon/spring/configurator/impl/
resources/org/apache/cocoon/spring/configurator/schema/
Author: cziegeler
Date: Sun Dec 31 03:32:10 2006
New Revision: 491402
URL: http://svn.apache.org/viewvc?view=rev&rev=491402
Log:
Unify global and child settings element parsing and configuration
Added:
cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/AbstractSettingsElementParser.java (with props)
Modified:
cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/ChildSettingsElementParser.java
cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/SettingsElementParser.java
cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/resources/org/apache/cocoon/spring/configurator/schema/cocoon-configurator-1.0.xsd
Added: cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/AbstractSettingsElementParser.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/AbstractSettingsElementParser.java?view=auto&rev=491402
==============================================================================
--- cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/AbstractSettingsElementParser.java (added)
+++ cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/AbstractSettingsElementParser.java Sun Dec 31 03:32:10 2006
@@ -0,0 +1,99 @@
+/*
+ * 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.spring.configurator.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.w3c.dom.Element;
+
+/**
+ * Abstract class for the settings element parsers.
+ *
+ * @see ChildSettingsElementParser
+ * @see SettingsElementParser
+ * @version $Id$
+ * @since 1.0
+ */
+public abstract class AbstractSettingsElementParser extends AbstractElementParser {
+
+ /**
+ * Get additonal includes of property directories.
+ */
+ protected List getPropertyIncludes(Element childSettingsElement) {
+ List propertyDirs = null;
+ if ( childSettingsElement != null ) {
+ final Element[] propertyDirConfigs = this.getChildElements(childSettingsElement, "include-properties");
+ if ( propertyDirConfigs != null && propertyDirConfigs.length > 0 ) {
+ propertyDirs = new ArrayList();
+ for(int i=0; i < propertyDirConfigs.length; i++) {
+ propertyDirs.add(this.getAttributeValue(propertyDirConfigs[i], "dir", null));
+ }
+ }
+ }
+ return propertyDirs;
+ }
+
+ /**
+ * Get additional properties.
+ */
+ protected Properties getAdditionalProperties(Element childSettingsElement) {
+ Properties variables = null;
+ final Element[] properties = this.getChildElements(childSettingsElement, "property");
+ if ( properties != null && properties.length > 0 ) {
+ variables = new Properties();
+ for(int i=0; i<properties.length; i++) {
+ variables.setProperty(this.getAttributeValue(properties[i], "name", null),
+ this.getAttributeValue(properties[i], "value", null));
+ }
+ }
+ return variables;
+ }
+
+ /**
+ * Get additional includes of bean configurations.
+ */
+ protected List getBeanIncludes(Element childSettingsElement) {
+ final List includes = new ArrayList();
+ // search for includes
+ if ( childSettingsElement.hasChildNodes() ) {
+ final Element[] includeElements = this.getChildElements(childSettingsElement, "include-beans");
+ if ( includeElements != null ) {
+ for(int i = 0 ; i < includeElements.length; i++ ) {
+ final String dir = this.getAttributeValue(includeElements[i], "dir", null);
+ final boolean optional = Boolean.valueOf(this.getAttributeValue(includeElements[i], "optional", "false")).booleanValue();
+
+ includes.add(new IncludeInfo(dir, optional));
+ }
+ }
+ }
+ return includes;
+ }
+
+ protected static final class IncludeInfo {
+ public final String dir;
+ public final boolean optional;
+
+ public IncludeInfo(String d, boolean o) {
+ this.dir = d;
+ this.optional = o;
+ }
+ }
+}
Propchange: cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/AbstractSettingsElementParser.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/AbstractSettingsElementParser.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/ChildSettingsElementParser.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/ChildSettingsElementParser.java?view=diff&rev=491402&r1=491401&r2=491402
==============================================================================
--- cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/ChildSettingsElementParser.java (original)
+++ cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/ChildSettingsElementParser.java Sun Dec 31 03:32:10 2006
@@ -41,39 +41,7 @@
* @version $Id$
* @since 1.0
*/
-public class ChildSettingsElementParser extends AbstractElementParser {
-
- protected List getPropertyIncludes(Element childSettingsElement)
- throws Exception {
- List propertyDirs = null;
- if ( childSettingsElement != null ) {
- final Element[] propertyDirConfigs = this.getChildElements(childSettingsElement, "include-properties");
- if ( propertyDirConfigs != null && propertyDirConfigs.length > 0 ) {
- propertyDirs = new ArrayList();
- for(int i=0; i < propertyDirConfigs.length; i++) {
- propertyDirs.add(this.getAttributeValue(propertyDirConfigs[i], "dir", null));
- }
- }
- }
- return propertyDirs;
- }
-
- /**
- * Get additional properties.
- */
- protected Properties getAdditionalProperties(Element childSettingsElement)
- throws Exception {
- Properties variables = null;
- final Element[] properties = this.getChildElements(childSettingsElement, "property");
- if ( properties != null && properties.length > 0 ) {
- variables = new Properties();
- for(int i=0; i<properties.length; i++) {
- variables.setProperty(this.getAttributeValue(properties[i], "name", null),
- this.getAttributeValue(properties[i], "value", null));
- }
- }
- return variables;
- }
+public class ChildSettingsElementParser extends AbstractSettingsElementParser {
/**
* @see org.springframework.beans.factory.xml.BeanDefinitionParser#parse(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext)
@@ -83,78 +51,52 @@
final WebApplicationContext rootAppContext = WebAppContextUtils.getCurrentWebApplicationContext();
// get running mode from root settings
final String runningMode = ((Settings)rootAppContext.getBean(Settings.ROLE)).getRunningMode();
- try {
- // Get bean includes
- final List beanIncludes = this.getBeanIncludes(element);
-
- // If there are bean includes for a directory, we register a property placeholder configurer
- if ( beanIncludes.size() > 0 ) {
- // we need a list of directories
- final List dirs = new ArrayList(beanIncludes.size());
- final Iterator i = beanIncludes.iterator();
- while ( i.hasNext() ) {
- dirs.add(((IncludeInfo)i.next()).dir);
- }
- this.registerPropertyOverrideConfigurer(parserContext, dirs);
- }
- // Create definition for child settings
- RootBeanDefinition def = this.createBeanDefinition(ChildSettingsBeanFactoryPostProcessor.class.getName(),
- "init",
- false);
- def.getPropertyValues().addPropertyValue("name", element.getAttribute("name"));
-
- final Properties additionalProps = this.getAdditionalProperties(element);
- if ( additionalProps != null ) {
- def.getPropertyValues().addPropertyValue("additionalProperties", additionalProps);
- }
+ // Get bean includes
+ final List beanIncludes = this.getBeanIncludes(element);
- final List propertiesIncludes = this.getPropertyIncludes(element);
- if ( propertiesIncludes != null ) {
- def.getPropertyValues().addPropertyValue("directories", propertiesIncludes);
+ // If there are bean includes for a directory, we register a property placeholder configurer
+ if ( beanIncludes.size() > 0 ) {
+ // we need a list of directories
+ final List dirs = new ArrayList(beanIncludes.size());
+ final Iterator i = beanIncludes.iterator();
+ while ( i.hasNext() ) {
+ dirs.add(((IncludeInfo)i.next()).dir);
}
+ this.registerPropertyOverrideConfigurer(parserContext, dirs);
+ }
- // process bean includes!
- final Iterator beanIncludeIterator = beanIncludes.iterator();
- while ( beanIncludeIterator.hasNext() ) {
- final IncludeInfo info = (IncludeInfo)beanIncludeIterator.next();
-
- this.handleBeanInclude(parserContext, info.dir, info.optional);
- this.handleBeanInclude(parserContext, info.dir + "/" + runningMode, true);
- }
+ // Create definition for child settings
+ RootBeanDefinition def = this.createBeanDefinition(ChildSettingsBeanFactoryPostProcessor.class.getName(),
+ "init",
+ false);
+ def.getPropertyValues().addPropertyValue("name", element.getAttribute("name"));
+
+ final Properties additionalProps = this.getAdditionalProperties(element);
+ if ( additionalProps != null ) {
+ def.getPropertyValues().addPropertyValue("additionalProperties", additionalProps);
+ }
- // and now we register the child settings
- this.register(def, Settings.ROLE, parserContext.getRegistry());
- } catch (Exception e) {
- throw new BeanDefinitionStoreException("Unable to process child settings element.", e);
+ final List propertiesIncludes = this.getPropertyIncludes(element);
+ if ( propertiesIncludes != null ) {
+ def.getPropertyValues().addPropertyValue("directories", propertiesIncludes);
}
- return null;
- }
- protected List getBeanIncludes(Element childSettingsElement) {
- final List includes = new ArrayList();
- // search for includes
- if ( childSettingsElement.hasChildNodes() ) {
- final Element[] includeElements = this.getChildElements(childSettingsElement, "include-beans");
- if ( includeElements != null ) {
- for(int i = 0 ; i < includeElements.length; i++ ) {
- final String dir = this.getAttributeValue(includeElements[i], "dir", null);
- final boolean optional = Boolean.valueOf(this.getAttributeValue(includeElements[i], "optional", "false")).booleanValue();
+ // process bean includes!
+ final Iterator beanIncludeIterator = beanIncludes.iterator();
+ while ( beanIncludeIterator.hasNext() ) {
+ final IncludeInfo info = (IncludeInfo)beanIncludeIterator.next();
- includes.add(new IncludeInfo(dir, optional));
- }
+ try {
+ this.handleBeanInclude(parserContext, info.dir, info.optional);
+ this.handleBeanInclude(parserContext, info.dir + "/" + runningMode, true);
+ } catch (Exception e) {
+ throw new BeanDefinitionStoreException("Unable to read spring configurations from " + info.dir, e);
}
}
- return includes;
- }
- protected static final class IncludeInfo {
- public final String dir;
- public final boolean optional;
-
- public IncludeInfo(String d, boolean o) {
- this.dir = d;
- this.optional = o;
- }
+ // and now we register the child settings
+ this.register(def, Settings.ROLE, parserContext.getRegistry());
+ return null;
}
}
Modified: cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/SettingsElementParser.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/SettingsElementParser.java?view=diff&rev=491402&r1=491401&r2=491402
==============================================================================
--- cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/SettingsElementParser.java (original)
+++ cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/SettingsElementParser.java Sun Dec 31 03:32:10 2006
@@ -19,7 +19,9 @@
package org.apache.cocoon.spring.configurator.impl;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
+import java.util.Properties;
import javax.servlet.ServletContext;
@@ -39,37 +41,87 @@
* @version $Id$
* @since 1.0
*/
-public class SettingsElementParser extends AbstractElementParser {
+public class SettingsElementParser extends AbstractSettingsElementParser {
/** The name of the configuration attribute to specify the running mode. */
public static final String RUNNING_MODE_ATTR = "runningMode";
+ /** The name of the configuration attribute to specify if configurations are read from the classpath. */
+ public static final String READ_FROM_CLASSPATH_ATTR = "readFromClasspath";
+
+ /** The name of the configuration attribute to specify if configurations are read from the global location. */
+ public static final String READ_FROM_GLOBAL_LOCATION_ATTR = "readFromGlobalLocation";
+
/**
- * @see org.springframework.beans.factory.xml.BeanDefinitionParser#parse(org.w3c.dom.Element,
- * org.springframework.beans.factory.xml.ParserContext)
+ * Create and register the settings bean factory post processor.
*/
- public BeanDefinition parse(Element element, ParserContext parserContext) {
-
+ protected void createSettingsBeanFactoryPostProcessor(Element element,
+ ParserContext parserContext,
+ String runningMode) {
// create bean definition for settings object
final RootBeanDefinition beanDef = this.createBeanDefinition(SettingsBeanFactoryPostProcessor.class.getName(), "init", false);
+ // add additional properties
+ final Properties additionalProps = this.getAdditionalProperties(element);
+ if ( additionalProps != null ) {
+ beanDef.getPropertyValues().addPropertyValue("additionalProperties", additionalProps);
+ }
+
+ // add additional property directories
+ final List propertiesIncludes = this.getPropertyIncludes(element);
+ if ( propertiesIncludes != null ) {
+ beanDef.getPropertyValues().addPropertyValue("directories", propertiesIncludes);
+ }
+
+ // check for boolean settings
+ final Boolean readFromClasspath = Boolean.valueOf(this.getAttributeValue(element, READ_FROM_CLASSPATH_ATTR, "true"));
+ final Boolean readFromGlobalLocation = Boolean.valueOf(this.getAttributeValue(element, READ_FROM_GLOBAL_LOCATION_ATTR, "true"));
+
+ beanDef.getPropertyValues().addPropertyValue(READ_FROM_CLASSPATH_ATTR, readFromClasspath);
+ beanDef.getPropertyValues().addPropertyValue(READ_FROM_GLOBAL_LOCATION_ATTR, readFromGlobalLocation);
+
// if running mode is specified add it as a property
- final String runningMode = RunningModeHelper.determineRunningMode( this.getAttributeValue(element, RUNNING_MODE_ATTR, null) );
if (runningMode != null) {
- beanDef.getPropertyValues().addPropertyValue("runningMode", runningMode);
+ beanDef.getPropertyValues().addPropertyValue(RUNNING_MODE_ATTR, runningMode);
}
+
// register settings bean
- this.register(beanDef, Settings.ROLE, parserContext.getRegistry());
+ this.register(beanDef, Settings.ROLE, parserContext.getRegistry());
+ }
+
+ /**
+ * @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) {
+ final String runningMode = RunningModeHelper.determineRunningMode( this.getAttributeValue(element, RUNNING_MODE_ATTR, null) );
+ this.createSettingsBeanFactoryPostProcessor(element, parserContext, runningMode);
+
+ // Get bean includes
+ final List beanIncludes = this.getBeanIncludes(element);
// register a PropertyPlaceholderConfigurer
// we create a list with the default locations and add the optional location attribute
- final List locations = new ArrayList();
- locations.add(Constants.CLASSPATH_SPRING_CONFIGURATION_LOCATION);
- locations.add(Constants.GLOBAL_SPRING_CONFIGURATION_LOCATION);
- final String springConfigLocation = this.getAttributeValue(element, "location", null);
- if ( springConfigLocation != null ) {
- locations.add(springConfigLocation);
+ final List dirs = new ArrayList();
+ // check for boolean settings
+ final boolean readFromClasspath = Boolean.valueOf(this.getAttributeValue(element, READ_FROM_CLASSPATH_ATTR, "true")).booleanValue();
+ final boolean readFromGlobalLocation = Boolean.valueOf(this.getAttributeValue(element, READ_FROM_GLOBAL_LOCATION_ATTR, "true")).booleanValue();
+ if ( readFromClasspath ) {
+ dirs.add(Constants.CLASSPATH_SPRING_CONFIGURATION_LOCATION);
+ }
+ if ( readFromGlobalLocation ) {
+ dirs.add(Constants.GLOBAL_SPRING_CONFIGURATION_LOCATION);
+ }
+ // If there are bean includes for a directory, we register them as well
+ if ( beanIncludes.size() > 0 ) {
+ // we need a list of directories
+ final Iterator i = beanIncludes.iterator();
+ while ( i.hasNext() ) {
+ dirs.add(((IncludeInfo)i.next()).dir);
+ }
+ }
+ if ( dirs.size() > 0 ) {
+ this.registerPropertyOverrideConfigurer(parserContext, dirs);
}
- this.registerPropertyOverrideConfigurer(parserContext, locations);
// add the servlet context as a bean
this.addComponent(ServletContextFactoryBean.class.getName(),
@@ -81,22 +133,24 @@
BlockResourcesHolder.class.getName(),
"init", true, parserContext.getRegistry());
- // handle includes
- try {
- this.handleBeanInclude(parserContext, Constants.CLASSPATH_SPRING_CONFIGURATION_LOCATION, true);
- this.handleBeanInclude(parserContext, Constants.CLASSPATH_SPRING_CONFIGURATION_LOCATION + "/" + runningMode, true);
- } catch (Exception e) {
- throw new BeanDefinitionStoreException("Unable to read spring configurations from " + Constants.CLASSPATH_SPRING_CONFIGURATION_LOCATION, e);
+ // handle includes - add default location
+ if ( readFromClasspath ) {
+ beanIncludes.add(0, new IncludeInfo(Constants.CLASSPATH_SPRING_CONFIGURATION_LOCATION, true));
}
- if ( springConfigLocation != null ) {
+ // process bean includes!
+ final Iterator beanIncludeIterator = beanIncludes.iterator();
+ while ( beanIncludeIterator.hasNext() ) {
+ final IncludeInfo info = (IncludeInfo)beanIncludeIterator.next();
+
try {
- this.handleBeanInclude(parserContext, springConfigLocation, true);
- this.handleBeanInclude(parserContext, springConfigLocation + "/" + runningMode, true);
+ this.handleBeanInclude(parserContext, info.dir, info.optional);
+ this.handleBeanInclude(parserContext, info.dir + "/" + runningMode, true);
} catch (Exception e) {
- throw new BeanDefinitionStoreException("Unable to read spring configurations from " + springConfigLocation, e);
+ throw new BeanDefinitionStoreException("Unable to read spring configurations from " + info.dir, e);
}
}
+
return null;
}
}
Modified: cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/resources/org/apache/cocoon/spring/configurator/schema/cocoon-configurator-1.0.xsd
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/resources/org/apache/cocoon/spring/configurator/schema/cocoon-configurator-1.0.xsd?view=diff&rev=491402&r1=491401&r2=491402
==============================================================================
--- cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/resources/org/apache/cocoon/spring/configurator/schema/cocoon-configurator-1.0.xsd (original)
+++ cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/resources/org/apache/cocoon/spring/configurator/schema/cocoon-configurator-1.0.xsd Sun Dec 31 03:32:10 2006
@@ -23,8 +23,14 @@
<xsd:element name="settings">
<xsd:complexType>
- <xsd:attribute name="runningMode" type="xsd:string" use="optional"></xsd:attribute>
- <xsd:attribute name="location" type="xsd:string" use="optional"></xsd:attribute>
+ <xsd:sequence>
+ <xsd:element ref="include-beans" minOccurs="0" maxOccurs="unbounded"/>
+ <xsd:element ref="include-properties" minOccurs="0" maxOccurs="unbounded"/>
+ <xsd:element ref="property" minOccurs="0" maxOccurs="unbounded"/>
+ </xsd:sequence>
+ <xsd:attribute name="runningMode" type="xsd:string" use="optional"/>
+ <xsd:attribute name="readFromClasspath" type="xsd:boolean" use="optional"/>
+ <xsd:attribute name="readFromGlobalLocation" type="xsd:boolean" use="optional"/>
</xsd:complexType>
</xsd:element>