Return-Path: Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: (qmail 38373 invoked from network); 31 Dec 2006 11:33:39 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 31 Dec 2006 11:33:39 -0000 Received: (qmail 67932 invoked by uid 500); 31 Dec 2006 11:33:45 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 67877 invoked by uid 500); 31 Dec 2006 11:33:45 -0000 Mailing-List: contact cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@cocoon.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list cvs@cocoon.apache.org Received: (qmail 67866 invoked by uid 99); 31 Dec 2006 11:33:45 -0000 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 31 Dec 2006 03:33:44 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id B040A1A981A; Sun, 31 Dec 2006 03:32:12 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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/ Date: Sun, 31 Dec 2006 11:32:12 -0000 To: cvs@cocoon.apache.org From: cziegeler@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061231113212.B040A1A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 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 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 @@ - - + + + + + + + +