You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by sg...@apache.org on 2007/05/04 16:38:13 UTC
svn commit: r535262 - in /jakarta/turbine/fulcrum/trunk/yaafi:
src/java/org/apache/fulcrum/yaafi/framework/configuration/
src/java/org/apache/fulcrum/yaafi/framework/container/
src/java/org/apache/fulcrum/yaafi/framework/util/ src/test/ xdocs/
xdocs/sp...
Author: sgoeschl
Date: Fri May 4 07:38:12 2007
New Revision: 535262
URL: http://svn.apache.org/viewvc?view=rev&rev=535262
Log:
Added support for componentConfiguration.properties to provide values to be expanded in the componentConfiguration.xml. This allows to simplify the configuration if a few highly volatile configuration values are put into a separate configuration file.
Added:
jakarta/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/configuration/
jakarta/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/configuration/ComponentConfigurationPropertiesResolver.java
jakarta/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/configuration/ComponentConfigurationPropertiesResolverBaseImpl.java
jakarta/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/configuration/ComponentConfigurationPropertiesResolverImpl.java
jakarta/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/util/ConfigurationUtil.java
jakarta/turbine/fulcrum/trunk/yaafi/src/test/TestComponentConfig.properties
Modified:
jakarta/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/container/ServiceConstants.java
jakarta/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/container/ServiceContainerImpl.java
jakarta/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/util/StringUtils.java
jakarta/turbine/fulcrum/trunk/yaafi/src/test/TestYaafiContainerConfig.xml
jakarta/turbine/fulcrum/trunk/yaafi/xdocs/changes.xml
jakarta/turbine/fulcrum/trunk/yaafi/xdocs/index.xml
jakarta/turbine/fulcrum/trunk/yaafi/xdocs/specification/container.xml
Added: jakarta/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/configuration/ComponentConfigurationPropertiesResolver.java
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/configuration/ComponentConfigurationPropertiesResolver.java?view=auto&rev=535262
==============================================================================
--- jakarta/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/configuration/ComponentConfigurationPropertiesResolver.java (added)
+++ jakarta/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/configuration/ComponentConfigurationPropertiesResolver.java Fri May 4 07:38:12 2007
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2002-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.
+ */
+package org.apache.fulcrum.yaafi.framework.configuration;
+
+import java.util.Properties;
+
+/**
+ * This interface allows to resolve component configuration properties. These
+ * properties are used to expand variables found in the componentConfiguration.xml.
+ * The main motivation for this interface is to allow users to hook up
+ * commons-configuration to resolve global parameters easily without
+ * coupling this implementation to any external libraries.
+ *
+ * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
+ */
+public interface ComponentConfigurationPropertiesResolver
+{
+ /** default file name of the component config property file */
+ String COMPONENT_CONFIG_PROPERTIES_VALUE = "/componentConfiguration.properties";
+
+ /**
+ * Resolve custom properties
+ *
+ * @param defaults the default properties
+ * @return the custom properties
+ */
+ Properties resolve(Properties defaults) throws Exception;
+}
Added: jakarta/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/configuration/ComponentConfigurationPropertiesResolverBaseImpl.java
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/configuration/ComponentConfigurationPropertiesResolverBaseImpl.java?view=auto&rev=535262
==============================================================================
--- jakarta/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/configuration/ComponentConfigurationPropertiesResolverBaseImpl.java (added)
+++ jakarta/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/configuration/ComponentConfigurationPropertiesResolverBaseImpl.java Fri May 4 07:38:12 2007
@@ -0,0 +1,186 @@
+/*
+ * Copyright 2002-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.
+ */
+package org.apache.fulcrum.yaafi.framework.configuration;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.context.Contextualizable;
+import org.apache.avalon.framework.logger.LogEnabled;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.fulcrum.yaafi.framework.constant.AvalonYaafiConstants;
+import org.apache.fulcrum.yaafi.framework.util.InputStreamLocator;
+
+/**
+ * Base class to expand the value and all attributes. This class is intentend
+ * to be sub-classed if you hook up your own configuration mechanism.
+ *
+ * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
+ */
+public abstract class ComponentConfigurationPropertiesResolverBaseImpl
+ implements ComponentConfigurationPropertiesResolver, LogEnabled, Contextualizable, Configurable
+{
+ /** the logger of the container */
+ private Logger logger;
+
+ /** the Avalon context */
+ private Context context;
+
+ /** the container configuration */
+ private Configuration configuration;
+
+ /*
+ * @see org.apache.avalon.framework.logger.LogEnabled#enableLogging(org.apache.avalon.framework.logger.Logger)
+ */
+ public void enableLogging(Logger logger)
+ {
+ this.logger = logger;
+ }
+
+ /*
+ * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
+ */
+ public void contextualize(Context context) throws ContextException
+ {
+ this.context = context;
+ }
+
+ /**
+ * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
+ */
+ public void configure(Configuration configuration) throws ConfigurationException
+ {
+ this.configuration = configuration;
+ }
+
+ /**
+ * @return Returns the logger.
+ */
+ protected Logger getLogger()
+ {
+ return logger;
+ }
+
+ /**
+ * @return Returns the context.
+ */
+ protected Context getContext()
+ {
+ return context;
+ }
+
+ /**
+ * @return the home directory of the application
+ */
+ protected File getApplicationRootDir()
+ {
+ try
+ {
+ return (File) this.getContext().get(AvalonYaafiConstants.URN_AVALON_HOME);
+ }
+ catch(Exception e)
+ {
+ throw new RuntimeException(e.getMessage());
+ }
+ }
+
+ /**
+ * @return Returns the configuration.
+ */
+ protected Configuration getConfiguration()
+ {
+ return configuration;
+ }
+
+ /**
+ * @return Returns the componentConfigurationPropertiesLocation.
+ */
+ protected String getLocation()
+ {
+ return configuration.getChild("location").getValue(COMPONENT_CONFIG_PROPERTIES_VALUE );
+ }
+
+ /**
+ * Creates an InputStream using a Locator.
+ * @return the InputStrem or null if the resource was not found
+ */
+ protected InputStream createInputStream(String location) throws IOException
+ {
+ InputStreamLocator locator = new InputStreamLocator(this.getApplicationRootDir(), this.getLogger());
+ return locator.locate(location);
+ }
+
+ /**
+ * Add the Avalon context variables.
+ */
+ protected void addAvalonContext(Properties properties) throws ContextException
+ {
+ properties.put(
+ AvalonYaafiConstants.URN_AVALON_NAME,
+ this.getContext().get(AvalonYaafiConstants.URN_AVALON_NAME)
+ );
+
+ properties.put(
+ AvalonYaafiConstants.URN_AVALON_PARTITION,
+ this.getContext().get(AvalonYaafiConstants.URN_AVALON_PARTITION)
+ );
+
+ properties.put(
+ AvalonYaafiConstants.URN_AVALON_HOME,
+ this.getContext().get(AvalonYaafiConstants.URN_AVALON_HOME)
+ );
+
+ properties.put(
+ AvalonYaafiConstants.URN_AVALON_TEMP,
+ this.getContext().get(AvalonYaafiConstants.URN_AVALON_TEMP)
+ );
+ }
+
+ protected Properties loadProperties(String location) throws Exception
+ {
+ Properties result = new Properties();
+ InputStream is = this.createInputStream(location);
+
+ try
+ {
+ if(is != null)
+ {
+ result.load(is);
+ is.close();
+ is = null;
+ }
+ else
+ {
+ this.getLogger().debug("Unable to load the following optional file :" + location);
+ }
+
+ return result;
+ }
+ catch ( Exception e )
+ {
+ String msg = "Unable to parse the following file : " + location;
+ this.getLogger().error( msg , e );
+ throw e;
+ }
+ }
+}
Added: jakarta/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/configuration/ComponentConfigurationPropertiesResolverImpl.java
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/configuration/ComponentConfigurationPropertiesResolverImpl.java?view=auto&rev=535262
==============================================================================
--- jakarta/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/configuration/ComponentConfigurationPropertiesResolverImpl.java (added)
+++ jakarta/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/configuration/ComponentConfigurationPropertiesResolverImpl.java Fri May 4 07:38:12 2007
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2002-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.
+ */
+package org.apache.fulcrum.yaafi.framework.configuration;
+
+import java.util.Properties;
+
+/**
+ * A implementation to provide out-of-the-box component configuration properties
+ * using the following algorithm:
+ *
+ * <ul>
+ * <li>add the user-supplied defaults to the result<li>
+ * <li>add the system properties to the result<li>
+ * <li>add the Merlin context entries to the result<li>
+ * </ul>
+ *
+ * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
+ */
+public class ComponentConfigurationPropertiesResolverImpl
+ extends ComponentConfigurationPropertiesResolverBaseImpl
+{
+ /**
+ * @see org.apache.fulcrum.yaafi.framework.configuration.ComponentConfigurationPropertiesResolver#resolve(java.util.Properties)
+ */
+ public Properties resolve(Properties defaults) throws Exception
+ {
+ String location = this.getLocation();
+ Properties result = this.loadProperties(location);
+
+ if(defaults != null)
+ {
+ result.putAll(defaults);
+ }
+
+ result.putAll(System.getProperties());
+ this.addAvalonContext(result);
+
+ return result;
+ }
+}
Modified: jakarta/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/container/ServiceConstants.java
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/container/ServiceConstants.java?view=diff&rev=535262&r1=535261&r2=535262
==============================================================================
--- jakarta/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/container/ServiceConstants.java (original)
+++ jakarta/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/container/ServiceConstants.java Fri May 4 07:38:12 2007
@@ -45,6 +45,9 @@
/** property to lookup the component config file */
String COMPONENT_CONFIG_KEY = "componentConfiguration";
+ /** property to lookup the component config property file */
+ String COMPONENT_CONFIG_PROPERTIES_KEY = "componentConfigurationProperties";
+
/** property to lookup the component role file */
String COMPONENT_ROLE_KEYS = "componentRoles";
Modified: jakarta/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/container/ServiceContainerImpl.java
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/container/ServiceContainerImpl.java?view=diff&rev=535262&r1=535261&r2=535262
==============================================================================
--- jakarta/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/container/ServiceContainerImpl.java (original)
+++ jakarta/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/container/ServiceContainerImpl.java Fri May 4 07:38:12 2007
@@ -28,7 +28,9 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
+import org.apache.avalon.framework.container.ContainerUtil;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.context.DefaultContext;
@@ -40,12 +42,15 @@
import org.apache.fulcrum.jce.crypto.CryptoStreamFactoryImpl;
import org.apache.fulcrum.yaafi.framework.component.AvalonServiceComponentImpl;
import org.apache.fulcrum.yaafi.framework.component.ServiceComponent;
+import org.apache.fulcrum.yaafi.framework.configuration.ComponentConfigurationPropertiesResolver;
+import org.apache.fulcrum.yaafi.framework.configuration.ComponentConfigurationPropertiesResolverImpl;
import org.apache.fulcrum.yaafi.framework.constant.AvalonYaafiConstants;
import org.apache.fulcrum.yaafi.framework.context.AvalonToYaafiContextMapper;
import org.apache.fulcrum.yaafi.framework.context.YaafiToAvalonContextMapper;
import org.apache.fulcrum.yaafi.framework.role.RoleConfigurationParser;
import org.apache.fulcrum.yaafi.framework.role.RoleConfigurationParserImpl;
import org.apache.fulcrum.yaafi.framework.role.RoleEntry;
+import org.apache.fulcrum.yaafi.framework.util.ConfigurationUtil;
import org.apache.fulcrum.yaafi.framework.util.InputStreamLocator;
import org.apache.fulcrum.yaafi.framework.util.ReadWriteLock;
import org.apache.fulcrum.yaafi.framework.util.StringUtils;
@@ -136,6 +141,9 @@
/** Read/Write lock to synchronize acess to services */
private ReadWriteLock readWriteLock;
+ /** the configuration for running the ComponentConfigurationPropertiesResolver */
+ private Configuration componentConfigurationPropertiesResolverConfig;
+
/////////////////////////////////////////////////////////////////////////
// Avalon Service Lifecycle
/////////////////////////////////////////////////////////////////////////
@@ -289,7 +297,14 @@
currComponentConfiguration.getChild(COMPONENT_ISENCRYPTED_KEY).getValue(
"false" )
);
-
+
+
+ // get the configuration for componentConfigurationPropertiesResolver
+
+ this.componentConfigurationPropertiesResolverConfig = configuration.getChild(
+ COMPONENT_CONFIG_PROPERTIES_KEY
+ );
+
// evaluate parameters
Configuration currParameters = configuration.getChild(COMPONENT_PARAMETERS_KEY);
@@ -373,6 +388,18 @@
this.isComponentConfigurationEncrypted()
);
+ // create the configuration properties
+
+ Properties componentConfigurationProperties = this.loadComponentConfigurationProperties();
+
+ // expand the componentConfiguration using the componentConfigurationProperties
+
+ ConfigurationUtil.expand(
+ this.getLogger(),
+ (DefaultConfiguration) this.serviceConfiguration,
+ componentConfigurationProperties
+ );
+
// create the default parameters
if( this.getParameters() == null )
@@ -492,9 +519,17 @@
lock = this.getWriteLock();
// 2) store the new configuration
-
+
this.serviceConfiguration = configuration;
-
+
+ Properties componentConfigurationProperties = this.loadComponentConfigurationProperties();
+
+ ConfigurationUtil.expand(
+ this.getLogger(),
+ (DefaultConfiguration) this.serviceConfiguration,
+ componentConfigurationProperties
+ );
+
// 3) reconfigure the services
for( int i=0; i<this.getServiceList().size(); i++ )
@@ -1208,6 +1243,44 @@
this.getLogger().error( msg , e );
throw e;
}
+ }
+
+ return result;
+ }
+
+ /**
+ * Load a configuration property file either from a file or using the class loader.
+ * @param location the location of the file
+ * @return The loaded proeperty file
+ * @throws ConfigurationException Something went wrong
+ */
+ private Properties loadComponentConfigurationProperties()
+ throws ConfigurationException
+ {
+ Properties result = new Properties();
+ ComponentConfigurationPropertiesResolver resolver = null;
+
+ String className = this.componentConfigurationPropertiesResolverConfig.getChild("resolver").getValue(
+ ComponentConfigurationPropertiesResolverImpl.class.getName()
+ );
+
+ try
+ {
+ Class resolverClass = this.getClassLoader().loadClass( className );
+ resolver = (ComponentConfigurationPropertiesResolver) resolverClass.newInstance();
+ ContainerUtil.enableLogging(resolver, this.getLogger());
+ ContainerUtil.contextualize(resolver, this.getContext());
+ ContainerUtil.configure(resolver, this.componentConfigurationPropertiesResolverConfig);
+
+ result = resolver.resolve(null);
+
+ this.getLogger().debug("Using the following componentConfigurationProperties: " + result);
+ }
+ catch (Exception e)
+ {
+ String msg = "Resolving componentConfigurationProperties failed using the following class : " + className;
+ this.getLogger().error(msg, e);
+ throw new ConfigurationException(msg, e);
}
return result;
Added: jakarta/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/util/ConfigurationUtil.java
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/util/ConfigurationUtil.java?view=auto&rev=535262
==============================================================================
--- jakarta/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/util/ConfigurationUtil.java (added)
+++ jakarta/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/util/ConfigurationUtil.java Fri May 4 07:38:12 2007
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2002-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.
+ */
+package org.apache.fulcrum.yaafi.framework.util;
+
+import java.util.Map;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
+import org.apache.avalon.framework.logger.Logger;
+
+/**
+ * Helper class to expand the value and all attributes.
+ *
+ * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
+ */
+public class ConfigurationUtil
+{
+ /**
+ * Expand place holders found in values or attrbute values with the
+ * content of the given variables. The implementation assumes that
+ * the given configuration can be cast to a DefaultConfiguration
+ * otherwise we can't use any setters.
+ *
+ * @param logger the logger to write diagnostic messages
+ * @param defaultConfiguration the configuration
+ * @param vars the map holding the variables
+ * @throws ConfigurationException parsing the configuration failed
+ */
+ public static void expand(Logger logger, DefaultConfiguration defaultConfiguration, Map vars) throws ConfigurationException
+ {
+ if((vars == null) || (vars.size() == 0))
+ {
+ return;
+ }
+
+ // update the value of the configuration element
+
+ if(defaultConfiguration.getValue(null) != null)
+ {
+ String oldValue = defaultConfiguration.getValue();
+ String newValue = ConfigurationUtil.expand(oldValue, vars);
+ defaultConfiguration.setValue(newValue);
+
+ if(oldValue.equals(newValue) == false)
+ {
+ logger.debug("Changed element <"
+ + defaultConfiguration.getName()
+ + "> from '"
+ + oldValue
+ + "' ==> '"
+ + newValue
+ + "'"
+ );
+ }
+ }
+
+ // update all attributes
+
+ String attributeName = null;
+ String[] attributeNames = defaultConfiguration.getAttributeNames();
+
+ for(int i=0; i<attributeNames.length; i++)
+ {
+ attributeName = attributeNames[i];
+ String oldAttributeValue = defaultConfiguration.getAttribute(attributeName);
+ String newAttributeValue = ConfigurationUtil.expand(oldAttributeValue, vars);
+ defaultConfiguration.setAttribute(attributeName, newAttributeValue);
+
+ if(oldAttributeValue.equals(newAttributeValue) == false)
+ {
+ logger.debug("Changed attribute '"
+ + defaultConfiguration.getName() + "@" + attributeName
+ + "' from '"
+ + oldAttributeValue
+ + "' ==> '"
+ + newAttributeValue
+ + "'"
+ );
+ }
+ }
+
+ // and now recurse through all children (children are in general a lot of work)
+
+ Configuration[] children = defaultConfiguration.getChildren();
+
+ for(int i=0; i<children.length; i++)
+ {
+ ConfigurationUtil.expand(logger, ((DefaultConfiguration) children[i]), vars);
+ }
+ }
+
+ /**
+ * @return the expand a string
+ */
+ private static String expand(String value, Map vars)
+ {
+ return StringUtils.stringSubstitution(value, vars, true).toString();
+ }
+}
Modified: jakarta/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/util/StringUtils.java
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/util/StringUtils.java?view=diff&rev=535262&r1=535261&r2=535262
==============================================================================
--- jakarta/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/util/StringUtils.java (original)
+++ jakarta/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/util/StringUtils.java Fri May 4 07:38:12 2007
@@ -16,6 +16,8 @@
package org.apache.fulcrum.yaafi.framework.util;
+import java.util.Map;
+
/**
* A subset of the utilities available in commons-lang-2.1 StringUtils.
@@ -252,5 +254,88 @@
public static boolean isEmpty(String str)
{
return str == null || str.length() == 0;
+ }
+
+ /**
+ * Perform a series of substitutions. The substitions
+ * are performed by replacing ${variable} in the target
+ * string with the value of provided by the key "variable"
+ * in the provided hashtable.
+ *
+ * @param argStr target string
+ * @param vars name/value pairs used for substitution
+ * @param isLenient ignore failures
+ * @return String target string with replacements.
+ */
+ public static StringBuffer stringSubstitution(String argStr, Map vars, boolean isLenient)
+ {
+ StringBuffer argBuf = new StringBuffer();
+ int argStrLength = argStr.length();
+
+ for (int cIdx = 0 ; cIdx < argStrLength;)
+ {
+ char ch = argStr.charAt(cIdx);
+ char del = ' ';
+
+ switch (ch)
+ {
+ case '$':
+ StringBuffer nameBuf = new StringBuffer();
+ del = argStr.charAt(cIdx+1);
+ if( del == '{')
+ {
+ cIdx++;
+
+ for (++cIdx ; cIdx < argStr.length(); ++cIdx)
+ {
+ ch = argStr.charAt(cIdx);
+ if (ch != '}')
+ nameBuf.append(ch);
+ else
+ break;
+ }
+
+ if (nameBuf.length() > 0)
+ {
+ Object value = vars.get(nameBuf.toString());
+
+ if (value != null)
+ {
+ argBuf.append(value.toString());
+ }
+ else
+ {
+ if (!isLenient)
+ {
+ throw new RuntimeException("No value found for : " + nameBuf );
+ }
+ }
+
+ del = argStr.charAt(cIdx);
+
+ if( del != '}')
+ {
+ throw new RuntimeException("Delimineter not found for : " + nameBuf );
+ }
+ }
+
+ cIdx++;
+ }
+ else
+ {
+ argBuf.append(ch);
+ ++cIdx;
+ }
+
+ break;
+
+ default:
+ argBuf.append(ch);
+ ++cIdx;
+ break;
+ }
+ }
+
+ return argBuf;
}
}
Added: jakarta/turbine/fulcrum/trunk/yaafi/src/test/TestComponentConfig.properties
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/yaafi/src/test/TestComponentConfig.properties?view=auto&rev=535262
==============================================================================
--- jakarta/turbine/fulcrum/trunk/yaafi/src/test/TestComponentConfig.properties (added)
+++ jakarta/turbine/fulcrum/trunk/yaafi/src/test/TestComponentConfig.properties Fri May 4 07:38:12 2007
@@ -0,0 +1,2 @@
+testComponent.FOO=FOO
+reconfigurationService.interval=5000
Modified: jakarta/turbine/fulcrum/trunk/yaafi/src/test/TestYaafiContainerConfig.xml
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/yaafi/src/test/TestYaafiContainerConfig.xml?view=diff&rev=535262&r1=535261&r2=535262
==============================================================================
--- jakarta/turbine/fulcrum/trunk/yaafi/src/test/TestYaafiContainerConfig.xml (original)
+++ jakarta/turbine/fulcrum/trunk/yaafi/src/test/TestYaafiContainerConfig.xml Fri May 4 07:38:12 2007
@@ -8,6 +8,10 @@
<componentConfiguration>
<location>./src/test/TestComponentConfig.xml</location>
</componentConfiguration>
+ <componentConfigurationProperties>
+ <resolver>org.apache.fulcrum.yaafi.framework.configuration.ComponentConfigurationPropertiesResolverImpl</resolver>
+ <location>./src/test/TestComponentConfig.properties</location>
+ </componentConfigurationProperties>
<parameters>
<location>./src/test/TestParameters.properties</location>
</parameters>
Modified: jakarta/turbine/fulcrum/trunk/yaafi/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/yaafi/xdocs/changes.xml?view=diff&rev=535262&r1=535261&r2=535262
==============================================================================
--- jakarta/turbine/fulcrum/trunk/yaafi/xdocs/changes.xml (original)
+++ jakarta/turbine/fulcrum/trunk/yaafi/xdocs/changes.xml Fri May 4 07:38:12 2007
@@ -8,6 +8,11 @@
<body>
<release version="1.0.5-dev" date="as in SVN">
<action dev="sgoeschl" type="add">
+ Added componentConfiguration.properties to resolve custom properties
+ used for expanding the componentConfiguration.xml. Furthermore added
+ a resolver functionality to allow to use commons-configuration.
+ </action>
+ <action dev="sgoeschl" type="add">
Added JamonInterceptorService to capture statistical performance data
</action>
<action dev="sgoeschl" type="update">
Modified: jakarta/turbine/fulcrum/trunk/yaafi/xdocs/index.xml
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/yaafi/xdocs/index.xml?view=diff&rev=535262&r1=535261&r2=535262
==============================================================================
--- jakarta/turbine/fulcrum/trunk/yaafi/xdocs/index.xml (original)
+++ jakarta/turbine/fulcrum/trunk/yaafi/xdocs/index.xml Fri May 4 07:38:12 2007
@@ -50,6 +50,7 @@
<li>support for early or on-demand initialization</li>
<li>support for encrypted configuration files</li>
<li>dynamic proxies and service interceptors</li>
+ <li>dynamic expansion of variables found in the component configuration file</li>
</ul>
</p>
</subsection>
Modified: jakarta/turbine/fulcrum/trunk/yaafi/xdocs/specification/container.xml
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/yaafi/xdocs/specification/container.xml?view=diff&rev=535262&r1=535261&r2=535262
==============================================================================
--- jakarta/turbine/fulcrum/trunk/yaafi/xdocs/specification/container.xml (original)
+++ jakarta/turbine/fulcrum/trunk/yaafi/xdocs/specification/container.xml Fri May 4 07:38:12 2007
@@ -87,6 +87,32 @@
</td>
</tr>
<tr>
+ <td>componentConfigurationProperties</td>
+ <td>Tree</td>
+ <td>[0|1]</td>
+ <td>
+ Information about the component configuration proeprties used
+ to resolve variables in the componentConfiguration
+ </td>
+ </tr>
+ <tr>
+ <td>componentConfigurationProperties/location</td>
+ <td>String</td>
+ <td>[0|1]</td>
+ <td>
+ The location of the component configuration property file. The
+ default value is "/componentConfiguration.properties"
+ </td>
+ </tr>
+ <tr>
+ <td>componentConfigurationProperties/resolver</td>
+ <td>String</td>
+ <td>[0|1]</td>
+ <td>
+ The resolver class name to load the componentConfiguration.properties.
+ </td>
+ </tr>
+ <tr>
<td>parameters</td>
<td>Tree</td>
<td>[0|1]</td>
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org