You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2012/12/15 20:41:26 UTC
svn commit: r1422326 - in /commons/proper/configuration/trunk/src:
main/java/org/apache/commons/configuration/builder/combined/
test/java/org/apache/commons/configuration/builder/combined/ test/resources/
Author: oheger
Date: Sat Dec 15 19:41:22 2012
New Revision: 1422326
URL: http://svn.apache.org/viewvc?rev=1422326&view=rev
Log:
CombinedConfigurationBuilder now supports the declaration of an entity resolver in the definition configuration. This property is inherited by included XML configuration sources.
Added:
commons/proper/configuration/trunk/src/test/resources/testCCEntityResolver.xml (with props)
Modified:
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/BaseConfigurationBuilderProvider.java
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedConfigurationBuilder.java
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestBaseConfigurationBuilderProvider.java
Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/BaseConfigurationBuilderProvider.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/BaseConfigurationBuilderProvider.java?rev=1422326&r1=1422325&r2=1422326&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/BaseConfigurationBuilderProvider.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/BaseConfigurationBuilderProvider.java Sat Dec 15 19:41:22 2012
@@ -231,7 +231,10 @@ public class BaseConfigurationBuilderPro
* Initializes the parameter objects with data stored in the current bean
* declaration. This method is called before the newly created builder
* instance is configured with the parameter objects. It maps attributes of
- * the bean declaration to properties of parameter objects.
+ * the bean declaration to properties of parameter objects. In addition,
+ * it invokes the parent {@code CombinedConfigurationBuilder} so that the
+ * parameters object can inherit properties already defined for this
+ * builder.
*
* @param decl the current {@code ConfigurationDeclaration}
* @param params the collection with (uninitialized) parameter objects
@@ -240,11 +243,32 @@ public class BaseConfigurationBuilderPro
protected void initializeParameterObjects(ConfigurationDeclaration decl,
Collection<BuilderParameters> params) throws Exception
{
+ inheritParentBuilderProperties(decl, params);
MultiWrapDynaBean wrapBean = new MultiWrapDynaBean(params);
BeanHelper.initBean(wrapBean, decl);
}
/**
+ * Passes all parameter objects to the parent
+ * {@code CombinedConfigurationBuilder} so that properties already defined
+ * for the parent builder can be added. This method is called before the
+ * parameter objects are initialized from the definition configuration. This
+ * way properties from the parent builder are inherited, but can be
+ * overridden for child configurations.
+ *
+ * @param decl the current {@code ConfigurationDeclaration}
+ * @param params the collection with (uninitialized) parameter objects
+ */
+ protected void inheritParentBuilderProperties(
+ ConfigurationDeclaration decl, Collection<BuilderParameters> params)
+ {
+ for (BuilderParameters p : params)
+ {
+ decl.getConfigurationBuilder().initChildBuilderParameters(p);
+ }
+ }
+
+ /**
* Creates a new, uninitialized instance of the builder class managed by
* this provider. This implementation determines the builder class to be
* used by delegating to {@code determineBuilderClass()}. It then calls the
Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedConfigurationBuilder.java?rev=1422326&r1=1422325&r2=1422326&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedConfigurationBuilder.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedConfigurationBuilder.java Sat Dec 15 19:41:22 2012
@@ -30,6 +30,7 @@ import org.apache.commons.configuration.
import org.apache.commons.configuration.CombinedConfiguration;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.FileSystem;
import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.configuration.SubnodeConfiguration;
import org.apache.commons.configuration.SystemConfiguration;
@@ -43,9 +44,12 @@ import org.apache.commons.configuration.
import org.apache.commons.configuration.builder.ConfigurationBuilder;
import org.apache.commons.configuration.builder.FileBasedBuilderParametersImpl;
import org.apache.commons.configuration.builder.FileBasedConfigurationBuilder;
+import org.apache.commons.configuration.builder.XMLBuilderParametersImpl;
+import org.apache.commons.configuration.resolver.CatalogResolver;
import org.apache.commons.configuration.tree.DefaultExpressionEngine;
import org.apache.commons.configuration.tree.OverrideCombiner;
import org.apache.commons.configuration.tree.UnionCombiner;
+import org.xml.sax.EntityResolver;
/**
* <p>
@@ -399,7 +403,7 @@ public class CombinedConfigurationBuilde
private static final ConfigurationBuilderProvider XML_PROVIDER =
new BaseConfigurationBuilderProvider(FILE_BUILDER, RELOADING_BUILDER,
"org.apache.commons.configuration.XMLConfiguration",
- Arrays.asList(FILE_PARAMS));
+ Arrays.asList("org.apache.commons.configuration.builder.XMLBuilderParametersImpl"));
/** Constant for the provider for JNDI sources. */
private static final BaseConfigurationBuilderProvider JNDI_PROVIDER =
@@ -492,6 +496,9 @@ public class CombinedConfigurationBuilde
/** Stores the current parameters object. */
private CombinedBuilderParametersImpl currentParameters;
+ /** The current XML parameters object. */
+ private XMLBuilderParametersImpl currentXMLParameters;
+
/** Stores the base path to the configuration sources to load. */
private String configurationBasePath;
@@ -571,7 +578,6 @@ public class CombinedConfigurationBuilde
throws ConfigurationException
{
initFileSystem();
- configureEntityResolver();
registerConfiguredLookups();
// CombinedConfiguration result = createResultConfiguration();
@@ -650,6 +656,7 @@ public class CombinedConfigurationBuilde
definitionBuilder = null;
definitionConfiguration = null;
currentParameters = null;
+ currentXMLParameters = null;
if (sourceData != null)
{
@@ -767,8 +774,10 @@ public class CombinedConfigurationBuilde
initNodeCombinerListNodes(result, config, KEY_OVERRIDE_LIST);
registerConfiguredProviders(config);
initSystemProperties(config);
- ConfigurationSourceData data = getSourceData();
+ setUpCurrentXMLParameters();
+ configureEntityResolver(config, currentXMLParameters);
+ ConfigurationSourceData data = getSourceData();
createAndAddConfigurations(result, data.getOverrideBuilders(), data);
if (!data.getUnionBuilders().isEmpty())
{
@@ -861,17 +870,40 @@ public class CombinedConfigurationBuilde
}
}
- protected void configureEntityResolver() throws ConfigurationException
+ /**
+ * Creates and initializes a default {@code EntityResolver} if the
+ * definition configuration contains a corresponding declaration.
+ *
+ * @param config the definition configuration
+ * @param xmlParams the (already partly initialized) object with XML
+ * parameters; here the new resolver is to be stored
+ * @throws ConfigurationException if an error occurs
+ */
+ protected void configureEntityResolver(HierarchicalConfiguration config,
+ XMLBuilderParametersImpl xmlParams) throws ConfigurationException
{
-// if (getMaxIndex(KEY_ENTITY_RESOLVER) == 0)
-// {
-// XMLBeanDeclaration decl = new XMLBeanDeclaration(this, KEY_ENTITY_RESOLVER, true);
-// EntityResolver resolver = (EntityResolver) BeanHelper.createBean(decl, CatalogResolver.class);
-// BeanHelper.setProperty(resolver, "fileSystem", getFileSystem());
-// BeanHelper.setProperty(resolver, "baseDir", getBasePath());
-// BeanHelper.setProperty(resolver, "substitutor", getSubstitutor());
-// setEntityResolver(resolver);
-// }
+ if (config.getMaxIndex(KEY_ENTITY_RESOLVER) == 0)
+ {
+ XMLBeanDeclaration decl =
+ new XMLBeanDeclaration(config, KEY_ENTITY_RESOLVER, true);
+ EntityResolver resolver =
+ (EntityResolver) BeanHelper.createBean(decl,
+ CatalogResolver.class);
+ FileSystem fileSystem = xmlParams.getFileHandler().getFileSystem();
+ if (fileSystem != null)
+ {
+ BeanHelper.setProperty(resolver, "fileSystem", fileSystem);
+ }
+ String basePath = xmlParams.getFileHandler().getBasePath();
+ if (basePath != null)
+ {
+ BeanHelper.setProperty(resolver, "baseDir", basePath);
+ }
+ // BeanHelper.setProperty(resolver, "substitutor",
+ // getSubstitutor());
+ // setEntityResolver(resolver);
+ xmlParams.setEntityResolver(resolver);
+ }
}
/**
@@ -912,6 +944,25 @@ public class CombinedConfigurationBuilde
}
/**
+ * Initializes a parameters object for a child builder. This combined
+ * configuration builder has a bunch of properties which may be inherited by
+ * child configurations, e.g. the base path, the file system, etc. While
+ * processing the builders for child configurations, this method is called
+ * for each parameters object for a child builder. It initializes some
+ * properties of the passed in parameters objects which are derived from
+ * this parent builder.
+ *
+ * @param params the parameters object to be initialized
+ */
+ protected void initChildBuilderParameters(BuilderParameters params)
+ {
+ if (params instanceof XMLBuilderParametersImpl)
+ {
+ initChildXMLParameters((XMLBuilderParametersImpl) params);
+ }
+ }
+
+ /**
* Initializes the current parameters object. This object has either been
* passed at builder configuration time or it is newly created. In any
* case, it is manipulated during result creation.
@@ -924,6 +975,29 @@ public class CombinedConfigurationBuilde
}
/**
+ * Sets up an XML parameters object which is used to store properties
+ * related to XML and file-based configurations during creation of the
+ * result configuration. The properties stored in this object can be
+ * inherited to child configurations.
+ */
+ private void setUpCurrentXMLParameters()
+ {
+ currentXMLParameters = new XMLBuilderParametersImpl();
+ }
+
+ /**
+ * Initializes a parameters object for an XML configuration with properties
+ * already set for this parent builder. Only properties that are not set in
+ * the parameters object are updated.
+ *
+ * @param params the parameters object
+ */
+ private void initChildXMLParameters(XMLBuilderParametersImpl params)
+ {
+ params.setEntityResolver(currentXMLParameters.getEntityResolver());
+ }
+
+ /**
* Obtains the data object for the configuration sources and the
* corresponding builders. This object is created on first access and reset
* when the definition builder sends a change event. This method is called
@@ -940,6 +1014,7 @@ public class CombinedConfigurationBuilde
if (currentParameters == null)
{
setUpCurrentParameters();
+ setUpCurrentXMLParameters();
}
sourceData = createSourceData();
}
Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestBaseConfigurationBuilderProvider.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestBaseConfigurationBuilderProvider.java?rev=1422326&r1=1422325&r2=1422326&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestBaseConfigurationBuilderProvider.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestBaseConfigurationBuilderProvider.java Sat Dec 15 19:41:22 2012
@@ -29,6 +29,7 @@ import org.apache.commons.configuration.
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.configuration.builder.BasicBuilderParameters;
import org.apache.commons.configuration.builder.BasicConfigurationBuilder;
+import org.apache.commons.configuration.builder.BuilderParameters;
import org.apache.commons.configuration.builder.ConfigurationBuilder;
import org.apache.commons.configuration.builder.FileBasedBuilderParametersImpl;
import org.apache.commons.configuration.builder.FileBasedConfigurationBuilder;
@@ -70,8 +71,24 @@ public class TestBaseConfigurationBuilde
private ConfigurationDeclaration createDeclaration(
HierarchicalConfiguration declConfig)
{
+ CombinedConfigurationBuilder parentBuilder =
+ new CombinedConfigurationBuilder()
+ {
+ @Override
+ protected void initChildBuilderParameters(
+ BuilderParameters params)
+ {
+ // set a property value; this should be overridden by
+ // child builders
+ if (params instanceof BasicBuilderParameters)
+ {
+ ((BasicBuilderParameters) params)
+ .setListDelimiter('!');
+ }
+ }
+ };
ConfigurationDeclaration decl =
- new ConfigurationDeclaration(null, declConfig)
+ new ConfigurationDeclaration(parentBuilder, declConfig)
{
@Override
protected Object interpolate(Object value)
Added: commons/proper/configuration/trunk/src/test/resources/testCCEntityResolver.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/resources/testCCEntityResolver.xml?rev=1422326&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/test/resources/testCCEntityResolver.xml (added)
+++ commons/proper/configuration/trunk/src/test/resources/testCCEntityResolver.xml Sat Dec 15 19:41:22 2012
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<!--
+ 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.
+-->
+<!-- Test configuration definition file that contains a declaration of an
+ entity resolver.
+ $Id$
+-->
+
+<configuration>
+ <header>
+ <entity-resolver
+ config-class="org.apache.commons.configuration.builder.combined.TestCombinedConfigurationBuilder$EntityResolverTestImpl"/>
+ </header>
+ <xml fileName="test.xml" config-name="xml"/>
+</configuration>
Propchange: commons/proper/configuration/trunk/src/test/resources/testCCEntityResolver.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/configuration/trunk/src/test/resources/testCCEntityResolver.xml
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/proper/configuration/trunk/src/test/resources/testCCEntityResolver.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml