You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by eb...@apache.org on 2004/06/23 13:15:45 UTC
cvs commit: jakarta-commons/configuration/src/java/org/apache/commons/configuration BaseConfiguration.java BaseConfigurationXMLReader.java BasePathConfiguration.java BasePropertiesConfiguration.java ClassPropertiesConfiguration.java ConfigurationFactory.java ConfigurationKey.java ConfigurationUtils.java DatabaseConfiguration.java HierarchicalDOM4JConfiguration.java HierarchicalDOMConfiguration.java JNDIConfiguration.java PropertiesConfiguration.java SubsetConfiguration.java
ebourg 2004/06/23 04:15:45
Modified: configuration project.properties
configuration/src/java/org/apache/commons/configuration
BaseConfiguration.java
BaseConfigurationXMLReader.java
BasePathConfiguration.java
BasePropertiesConfiguration.java
ClassPropertiesConfiguration.java
ConfigurationFactory.java ConfigurationKey.java
ConfigurationUtils.java DatabaseConfiguration.java
HierarchicalDOM4JConfiguration.java
HierarchicalDOMConfiguration.java
JNDIConfiguration.java PropertiesConfiguration.java
SubsetConfiguration.java
Added: configuration/conf checkstyle.xml
Log:
code formatting
Revision Changes Path
1.11 +1 -1 jakarta-commons/configuration/project.properties
Index: project.properties
===================================================================
RCS file: /home/cvs/jakarta-commons/configuration/project.properties,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- project.properties 3 Jun 2004 16:13:01 -0000 1.10
+++ project.properties 23 Jun 2004 11:15:44 -0000 1.11
@@ -15,7 +15,7 @@
compile.optimize = off
compile.deprecation = off
-maven.checkstyle.format = turbine
+maven.checkstyle.properties=conf/checkstyle.xml
maven.junit.fork=true
maven.test.failure.ignore=true
1.1 jakarta-commons/configuration/conf/checkstyle.xml
Index: checkstyle.xml
===================================================================
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.1//EN"
"http://www.puppycrawl.com/dtds/configuration_1_1.dtd">
<!-- Checkstyle configuration that checks the commons-configuration coding conventions -->
<module name="Checker">
<!-- Checks that a package.html file exists for each package. -->
<!-- See http://checkstyle.sf.net/config_javadoc.html#PackageHtml -->
<module name="PackageHtml"/>
<!-- Checks whether files end with a new line. -->
<!-- See http://checkstyle.sf.net/config_misc.html#NewlineAtEndOfFile -->
<module name="NewlineAtEndOfFile"/>
<!-- Checks that property files contain the same keys. -->
<!-- See http://checkstyle.sf.net/config_misc.html#Translation -->
<module name="Translation"/>
<module name="TreeWalker">
<property name="cacheFile" value="${checkstyle.cache.file}"/>
<!-- Checks for Javadoc comments. -->
<!-- See http://checkstyle.sf.net/config_javadoc.html -->
<module name="JavadocMethod"/>
<module name="JavadocType"/>
<module name="JavadocVariable"/>
<!-- Checks for Naming Conventions. -->
<!-- See http://checkstyle.sf.net/config_naming.html -->
<module name="ConstantName"/>
<module name="LocalFinalVariableName"/>
<module name="LocalVariableName"/>
<module name="MemberName"/>
<module name="MethodName"/>
<module name="PackageName"/>
<module name="ParameterName"/>
<module name="StaticVariableName"/>
<module name="TypeName"/>
<!-- Checks for Headers -->
<!-- See http://checkstyle.sf.net/config_header.html -->
<module name="Header">
<!-- The follow property value demonstrates the ability -->
<!-- to have access to ANT properties. In this case it uses -->
<!-- the ${basedir} property to allow Checkstyle to be run -->
<!-- from any directory within a project. -->
<property name="headerFile" value="${checkstyle.header.file}"/>
</module>
<!-- Following interprets the header file as regular expressions. -->
<!-- <module name="RegexpHeader"/> -->
<!-- Checks for imports -->
<!-- See http://checkstyle.sf.net/config_import.html -->
<module name="AvoidStarImport"/>
<module name="IllegalImport"/> <!-- defaults to sun.* packages -->
<module name="RedundantImport"/>
<module name="UnusedImports"/>
<!-- Checks for Size Violations. -->
<!-- See http://checkstyle.sf.net/config_sizes.html -->
<module name="FileLength"/>
<module name="LineLength">
<property name="max" value="120"/>
</module>
<module name="MethodLength"/>
<module name="ParameterNumber"/>
<!-- Checks for whitespace -->
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
<module name="EmptyForIteratorPad"/>
<module name="NoWhitespaceAfter"/>
<module name="NoWhitespaceBefore"/>
<module name="OperatorWrap"/>
<module name="ParenPad"/>
<module name="TabCharacter"/>
<module name="WhitespaceAfter"/>
<module name="WhitespaceAround"/>
<!-- Modifier Checks -->
<!-- See http://checkstyle.sf.net/config_modifiers.html -->
<module name="ModifierOrder"/>
<module name="RedundantModifier"/>
<!-- Checks for blocks. You know, those {}'s -->
<!-- See http://checkstyle.sf.net/config_blocks.html -->
<module name="AvoidNestedBlocks"/>
<module name="EmptyBlock"/>
<module name="LeftCurly">
<property name="option" value="nl"/>
</module>
<module name="NeedBraces"/>
<module name="RightCurly">
<property name="option" value="alone"/>
</module>
<!-- Checks for common coding problems -->
<!-- See http://checkstyle.sf.net/config_coding.html -->
<module name="DoubleCheckedLocking"/> <!-- MY FAVOURITE -->
<module name="EmptyStatement"/>
<module name="EqualsHashCode"/>
<module name="HiddenField"/>
<module name="IllegalInstantiation"/>
<module name="InnerAssignment"/>
<module name="MagicNumber"/>
<module name="MissingSwitchDefault"/>
<module name="RedundantThrows"/>
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>
<!-- Checks for class design -->
<!-- See http://checkstyle.sf.net/config_design.html -->
<module name="FinalClass"/>
<module name="HideUtilityClassConstructor"/>
<module name="InterfaceIsType"/>
<module name="VisibilityModifier"/>
<!-- Miscellaneous other checks. -->
<!-- See http://checkstyle.sf.net/config_misc.html -->
<module name="ArrayTypeStyle"/>
<!--<module name="FinalParameters"/>-->
<module name="GenericIllegalRegexp">
<property name="format" value="\s+$"/>
<property name="message" value="Line has trailing spaces."/>
</module>
<module name="TodoComment"/>
<module name="UpperEll"/>
</module>
</module>
1.6 +12 -12 jakarta-commons/configuration/src/java/org/apache/commons/configuration/BaseConfiguration.java
Index: BaseConfiguration.java
===================================================================
RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/BaseConfiguration.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- BaseConfiguration.java 2 Jun 2004 17:04:51 -0000 1.5
+++ BaseConfiguration.java 23 Jun 2004 11:15:45 -0000 1.6
@@ -37,7 +37,7 @@
{
/** stores the configuration key-value pairs */
private Map store = new LinkedMap();
-
+
/**
* Empty constructor. You must add all the values to this configuration.
*/
@@ -45,7 +45,7 @@
{
super();
}
-
+
/**
* Adds a key/value pair to the map. This routine does no magic morphing.
@@ -58,8 +58,8 @@
{
Object o = getPropertyDirect(key);
Object objAdd = null;
-
- if(o == null)
+
+ if (o == null)
{
objAdd = obj;
}
@@ -84,8 +84,8 @@
objAdd = c;
}
}
-
- if(objAdd != null)
+
+ if (objAdd != null)
{
store.put(key, objAdd);
}
@@ -98,7 +98,7 @@
*
* @return object associated with the given configuration key.
*/
- protected Object getPropertyDirect(String key)
+ protected Object getPropertyDirect(String key)
{
return store.get(key);
}
@@ -118,14 +118,14 @@
* check if the configuration contains the key
*
* @param key the configuration key
- *
+ *
* @return <code>true</code> if Configuration contain given key,
* <code>false</code> otherwise.
*/
public boolean containsKey(String key)
{
return store.containsKey(key);
-
+
}
/**
@@ -137,7 +137,7 @@
{
if (containsKey(key))
{
- store.remove(key);
+ store.remove(key);
}
}
@@ -148,7 +148,7 @@
* @return An Iterator.
*/
public Iterator getKeys()
- {
+ {
return store.keySet().iterator();
}
}
1.4 +12 -5 jakarta-commons/configuration/src/java/org/apache/commons/configuration/BaseConfigurationXMLReader.java
Index: BaseConfigurationXMLReader.java
===================================================================
RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/BaseConfigurationXMLReader.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- BaseConfigurationXMLReader.java 27 Feb 2004 17:41:35 -0000 1.3
+++ BaseConfigurationXMLReader.java 23 Jun 2004 11:15:45 -0000 1.4
@@ -1,5 +1,3 @@
-package org.apache.commons.configuration;
-
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
@@ -16,14 +14,17 @@
* limitations under the License.
*/
+package org.apache.commons.configuration;
/**
* <p>A specialized SAX2 XML parser that processes configuration objects.</p>
+ *
* <p>This class mimics to be a SAX compliant XML parser. It is able to iterate
* over the keys in a configuration object and to generate corresponding SAX
* events. By registering a <code>ContentHandler</code> at an instance
* it is possible to perform XML processing on a configuration object.</p>
*
+ * @author <a href="mailto:oliver.heger@t-online.de">Oliver Heger</a>
* @version $Id$
*/
public class BaseConfigurationXMLReader extends ConfigurationXMLReader
@@ -42,6 +43,7 @@
/**
* Creates a new instance of <code>BaseConfigurationXMLReader</code> and
* sets the configuration object to be parsed.
+ *
* @param conf the configuration to be parsed
*/
public BaseConfigurationXMLReader(Configuration conf)
@@ -52,6 +54,7 @@
/**
* Returns the actual configuration to be processed.
+ *
* @return the actual configuration
*/
public Configuration getConfiguration()
@@ -61,6 +64,7 @@
/**
* Sets the configuration to be processed.
+ *
* @param conf the configuration
*/
public void setConfiguration(Configuration conf)
@@ -70,6 +74,7 @@
/**
* Returns the configuration to be processed.
+ *
* @return the actual configuration
*/
public Configuration getParsedConfiguration()
@@ -99,20 +104,22 @@
{
/**
* Callback for the start of an element.
+ *
* @param name the element name
* @param value the element value
*/
protected void elementStart(String name, Object value)
{
fireElementStart(name, null);
- if(value != null)
+ if (value != null)
{
fireCharacters(value.toString());
- } /* if */
+ }
}
/**
* Callback for the end of an element.
+ *
* @param name the element name
*/
protected void elementEnd(String name)
1.3 +10 -15 jakarta-commons/configuration/src/java/org/apache/commons/configuration/BasePathConfiguration.java
Index: BasePathConfiguration.java
===================================================================
RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/BasePathConfiguration.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- BasePathConfiguration.java 27 Feb 2004 17:41:35 -0000 1.2
+++ BasePathConfiguration.java 23 Jun 2004 11:15:45 -0000 1.3
@@ -1,5 +1,3 @@
-package org.apache.commons.configuration;
-
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
@@ -16,19 +14,19 @@
* limitations under the License.
*/
+package org.apache.commons.configuration;
+
/**
- * This is exactly the same as the BaseConfiguration but the backing
+ * This is exactly the same as the BaseConfiguration but the backing
* store is based on a path (e.g. a file path) from which it is loaded.
*
* @version $Id$
*/
-public abstract class BasePathConfiguration
- extends BaseConfiguration
- implements BasePathLoader
+public abstract class BasePathConfiguration extends BaseConfiguration implements BasePathLoader
{
- /**
- * Base path of the configuration file used to
- * create this Configuration object. Might be null, then a
+ /**
+ * Base path of the configuration file used to
+ * create this Configuration object. Might be null, then a
* "synthetic" PropertyConfiguration has been created which
* is not loaded from a file
*/
@@ -36,7 +34,7 @@
/**
* Returns the Base path from which this Configuration Factory operates.
- * This is never null. If you set the BasePath to null, then "."
+ * This is never null. If you set the BasePath to null, then "."
* is returned.
*
* @return The base Path of this configuration factory.
@@ -48,7 +46,7 @@
/**
* Sets the basePath for all file references from this Configuration
- * Factory. If you pass null in, this is interpreted as "current
+ * Factory. If you pass null in, this is interpreted as "current
* directory".
*
* @param basePath The new basePath to set.
@@ -59,6 +57,3 @@
}
}
-
-
-
1.13 +28 -15 jakarta-commons/configuration/src/java/org/apache/commons/configuration/BasePropertiesConfiguration.java
Index: BasePropertiesConfiguration.java
===================================================================
RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/BasePropertiesConfiguration.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- BasePropertiesConfiguration.java 21 Jun 2004 17:45:29 -0000 1.12
+++ BasePropertiesConfiguration.java 23 Jun 2004 11:15:45 -0000 1.13
@@ -132,8 +132,7 @@
*
* @throws IOException Error while loading the properties file
*/
- protected abstract InputStream getPropertyStream(String resourceName)
- throws IOException;
+ protected abstract InputStream getPropertyStream(String resourceName) throws IOException;
/**
* Load the properties from the given input stream.
@@ -490,9 +489,10 @@
*
* @throws IllegalArgumentException if the Writer is <code>null</code>
*/
- protected static String unescapeJava(String str) {
-
- if (str == null) {
+ protected static String unescapeJava(String str)
+ {
+ if (str == null)
+ {
return null;
}
int sz = str.length();
@@ -500,31 +500,40 @@
StringBuffer unicode = new StringBuffer(4);
boolean hadSlash = false;
boolean inUnicode = false;
- for (int i = 0; i < sz; i++) {
+ for (int i = 0; i < sz; i++)
+ {
char ch = str.charAt(i);
- if (inUnicode) {
+ if (inUnicode)
+ {
// if in unicode, then we're reading unicode
// values in somehow
unicode.append(ch);
- if (unicode.length() == 4) {
+ if (unicode.length() == 4)
+ {
// unicode now contains the four hex digits
// which represents our unicode character
- try {
+ try
+ {
int value = Integer.parseInt(unicode.toString(), 16);
out.append((char) value);
unicode.setLength(0);
inUnicode = false;
hadSlash = false;
- } catch (NumberFormatException nfe) {
+ }
+ catch (NumberFormatException nfe)
+ {
throw new ConfigurationRuntimeException("Unable to parse unicode value: " + unicode, nfe);
}
}
continue;
}
- if (hadSlash) {
+
+ if (hadSlash)
+ {
// handle an escaped value
hadSlash = false;
- switch (ch) {
+ switch (ch)
+ {
case '\\':
out.append('\\');
break;
@@ -564,13 +573,17 @@
break;
}
continue;
- } else if (ch == '\\') {
+ }
+ else if (ch == '\\')
+ {
hadSlash = true;
continue;
}
out.append(ch);
}
- if (hadSlash) {
+
+ if (hadSlash)
+ {
// then we're in the weird case of a \ at the end of the
// string, let's output it anyway.
out.append('\\');
1.7 +18 -25 jakarta-commons/configuration/src/java/org/apache/commons/configuration/ClassPropertiesConfiguration.java
Index: ClassPropertiesConfiguration.java
===================================================================
RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/ClassPropertiesConfiguration.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ClassPropertiesConfiguration.java 2 Jun 2004 16:42:24 -0000 1.6
+++ ClassPropertiesConfiguration.java 23 Jun 2004 11:15:45 -0000 1.7
@@ -1,5 +1,3 @@
-package org.apache.commons.configuration;
-
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
@@ -16,14 +14,16 @@
* limitations under the License.
*/
+package org.apache.commons.configuration;
+
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
/**
* Loads the configuration from the classpath utilizing a specified class to get
- * the classloader from. The properties file will be attempted to be loaded
- * first from the classes package directory and then from the class path in
+ * the classloader from. The properties file will be attempted to be loaded
+ * first from the classes package directory and then from the class path in
* general.
* <p>
* This class does not support an empty constructor and saving of a
@@ -33,9 +33,7 @@
*
* @version $Id$
*/
-public class ClassPropertiesConfiguration
- extends BasePropertiesConfiguration
- implements Configuration
+public class ClassPropertiesConfiguration extends BasePropertiesConfiguration implements Configuration
{
/** Base class, which is used to load all relative class references */
private Class baseClass = null;
@@ -51,27 +49,27 @@
* @param resource The name of the Resource.
* @throws ConfigurationException Error while loading the properties file
*/
- public ClassPropertiesConfiguration(Class baseClass, String resource)
- throws ConfigurationException
+ public ClassPropertiesConfiguration(Class baseClass, String resource) throws ConfigurationException
{
this.baseClass = baseClass;
// According to javadocs, getClassLoader() might return null
// if it represents the "bootstrap class loader"
// Use the System class loader in this case.
- classLoader = (baseClass.getClassLoader() == null)
+ classLoader = (baseClass.getClassLoader() == null)
? ClassLoader.getSystemClassLoader()
: baseClass.getClassLoader();
-
+
setIncludesAllowed(true);
- try {
- load(getPropertyStream(resource));
+ try
+ {
+ load(getPropertyStream(resource));
}
- catch (IOException ioe){
- throw new ConfigurationException("Could not load input stream from resource " + resource,ioe);
+ catch (IOException ioe)
+ {
+ throw new ConfigurationException("Could not load input stream from resource " + resource, ioe);
}
}
-
/**
* Gets a resource relative to the supplied base class or
* from the class loader if it is not found from the supplied base class.
@@ -80,14 +78,13 @@
* @return An Input Stream
* @throws IOException Error while loading the properties file
*/
- protected InputStream getPropertyStream(String resourceName)
- throws IOException
+ protected InputStream getPropertyStream(String resourceName) throws IOException
{
InputStream resource = null;
-
+
//First try to load from within the package of the provided class
resource = baseClass.getResourceAsStream(resourceName);
-
+
if (resource == null)
{
resource = classLoader.getResourceAsStream(resourceName);
@@ -102,7 +99,3 @@
return resource;
}
}
-
-
-
-
1.12 +97 -71 jakarta-commons/configuration/src/java/org/apache/commons/configuration/ConfigurationFactory.java
Index: ConfigurationFactory.java
===================================================================
RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/ConfigurationFactory.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- ConfigurationFactory.java 16 Jun 2004 18:13:53 -0000 1.11
+++ ConfigurationFactory.java 23 Jun 2004 11:15:45 -0000 1.12
@@ -1,4 +1,3 @@
-package org.apache.commons.configuration;
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
@@ -14,6 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
+package org.apache.commons.configuration;
+
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -32,6 +34,7 @@
import org.apache.commons.logging.LogFactory;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
+
/**
* Factory class to create a CompositeConfiguration from a .xml file using
* Digester. By default it can handle the Configurations from commons-
@@ -39,6 +42,9 @@
* digester rules to use. It is also namespace aware, by providing a
* digesterRuleNamespaceURI.
*
+ * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
+ * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
+ * @author <a href="mailto:oliver.heger@t-online.de">Oliver Heger</a>
* @version $Id$
*/
public class ConfigurationFactory implements BasePathLoader
@@ -60,45 +66,51 @@
/** The XML file with the details about the configuration to load */
private String configurationFileName;
- /** The URL to the XML file with the details about the configuration to
- * load.
- */
+
+ /** The URL to the XML file with the details about the configuration to load. */
private URL configurationURL;
+
/**
* The implicit base path for included files. This path is determined by
* the configuration to load and used unless no other base path was
* explicitely specified.
*/
private String implicitBasePath;
+
/** The basePath to prefix file paths for file based property files. */
private String basePath;
+
/** static logger */
private static Log log = LogFactory.getLog(ConfigurationFactory.class);
+
/** URL for xml digester rules file */
private URL digesterRules;
+
/** The digester namespace to parse */
private String digesterRuleNamespaceURI;
+
/**
- * C'tor
+ * Constructor
*/
public ConfigurationFactory()
{
setBasePath(DEF_BASE_PATH);
}
/**
- * C'tor with ConfigurationFile Name passed
+ * Constructor with ConfigurationFile Name passed
*
* @param configurationFileName The path to the configuration file
*/
public ConfigurationFactory(String configurationFileName)
- {
+ {
this.configurationFileName = configurationFileName;
}
+
/**
- * Return the configuration provided by this factory. It
- * loads the configuration file which is a XML description of
- * the actual configurations to load. It can contain various
- * different types of configuration, currently Properties, XML and JNDI.
+ * Return the configuration provided by this factory. It loads the
+ * configuration file which is a XML description of the actual
+ * configurations to load. It can contain various different types of
+ * configuration, currently Properties, XML and JNDI.
*
* @return A Configuration object
* @throws ConfigurationException A generic exception that we had trouble during the
@@ -110,18 +122,19 @@
InputStream input = null;
ConfigurationBuilder builder = new ConfigurationBuilder();
URL url = getConfigurationURL();
- try {
- if(url == null)
+ try
{
- url = ConfigurationUtils.getURL(implicitBasePath,
- getConfigurationFileName());
- } /* if */
- input = url.openStream();
+ if (url == null)
+ {
+ url = ConfigurationUtils.getURL(implicitBasePath,
+ getConfigurationFileName());
+ }
+ input = url.openStream();
}
catch (Exception e)
{
- log.error("Exception caught opening stream to URL", e);
- throw new ConfigurationException("Exception caught opening stream to URL",e);
+ log.error("Exception caught opening stream to URL", e);
+ throw new ConfigurationException("Exception caught opening stream to URL", e);
}
if (getDigesterRules() == null)
@@ -148,15 +161,16 @@
catch (SAXException saxe)
{
log.error("SAX Exception caught", saxe);
- throw new ConfigurationException("SAX Exception caught",saxe);
+ throw new ConfigurationException("SAX Exception caught", saxe);
}
catch (IOException ioe)
{
- log.error("IO Exception caught", ioe);
- throw new ConfigurationException("IO Exception caught",ioe);
+ log.error("IO Exception caught", ioe);
+ throw new ConfigurationException("IO Exception caught", ioe);
}
return builder.getConfiguration();
}
+
/**
* Returns the configurationFile.
*
@@ -166,8 +180,10 @@
{
return configurationFileName;
}
+
/**
* Sets the configurationFile.
+ *
* @param configurationFileName The name of the configurationFile to use.
*/
public void setConfigurationFileName(String configurationFileName)
@@ -179,6 +195,7 @@
/**
* Returns the URL of the configuration file to be loaded.
+ *
* @return the URL of the configuration to load
*/
public URL getConfigurationURL()
@@ -189,6 +206,7 @@
/**
* Sets the URL of the configuration to load. This configuration can be
* either specified by a file name or by a URL.
+ *
* @param url the URL of the configuration to load
*/
public void setConfigurationURL(URL url)
@@ -200,28 +218,32 @@
// compatibility: Per default the base path is set to the current
// directory. For loading from a URL this makes no sense. So
// unless no specific base path was set we clear it.
- if(DEF_BASE_PATH.equals(getBasePath()))
+ if (DEF_BASE_PATH.equals(getBasePath()))
{
setBasePath(null);
- } /* if */
+ }
}
/**
* Returns the digesterRules.
+ *
* @return URL
*/
public URL getDigesterRules()
{
return digesterRules;
}
+
/**
* Sets the digesterRules.
+ *
* @param digesterRules The digesterRules to set
*/
public void setDigesterRules(URL digesterRules)
{
this.digesterRules = digesterRules;
}
+
/**
* Initializes the parsing rules for the default digester
*
@@ -242,13 +264,13 @@
/**
* Sets up digester rules for a specified section of the configuration
* info file.
+ *
* @param digester the current digester instance
* @param matchString specifies the section
* @param additional a flag if rules for the additional section are to be
* added
*/
- protected void initDigesterSectionRules(Digester digester,
- String matchString, boolean additional)
+ protected void initDigesterSectionRules(Digester digester, String matchString, boolean additional)
{
setupDigesterInstance(
digester,
@@ -263,11 +285,11 @@
METH_LOAD,
additional);
setupDigesterInstance(
- digester,
- matchString + "hierarchicalDom4j",
- new BasePathConfigurationFactory(HierarchicalDOM4JConfiguration.class),
- METH_LOAD,
- additional);
+ digester,
+ matchString + "hierarchicalDom4j",
+ new BasePathConfigurationFactory(HierarchicalDOM4JConfiguration.class),
+ METH_LOAD,
+ additional);
setupDigesterInstance(
digester,
matchString + "jndi",
@@ -278,6 +300,7 @@
/**
* Sets up digester rules for a configuration to be loaded.
+ *
* @param digester the current digester
* @param matchString the pattern to match with this rule
* @param factory an ObjectCreationFactory instance to use for creating new
@@ -293,16 +316,16 @@
String method,
boolean additional)
{
- if(additional)
+ if (additional)
{
setupUnionRules(digester, matchString);
- } /* if */
+ }
digester.addFactoryCreate(matchString, factory);
digester.addSetProperties(matchString);
- if(method != null)
+ if (method != null)
{
digester.addCallMethod(matchString, method);
- } /* if */
+ }
digester.addSetNext(
matchString,
"addConfiguration",
@@ -311,6 +334,7 @@
/**
* Sets up rules for configurations in the additional section.
+ *
* @param digester the current digester
* @param matchString the pattern to match with this rule
*/
@@ -322,6 +346,7 @@
digester.addSetNext(matchString, "addAdditionalConfig",
AdditionalConfigurationData.class.getName());
}
+
/**
* Returns the digesterRuleNamespaceURI.
*
@@ -331,6 +356,7 @@
{
return digesterRuleNamespaceURI;
}
+
/**
* Sets the digesterRuleNamespaceURI.
*
@@ -340,6 +366,7 @@
{
this.digesterRuleNamespaceURI = digesterRuleNamespaceURI;
}
+
/**
* Configure the current digester to be namespace aware and to have
* a Configuration object to which all of the other configurations
@@ -369,10 +396,11 @@
*/
public String getBasePath()
{
- String path = StringUtils.isEmpty(basePath) ?
+ String path = StringUtils.isEmpty(basePath) ?
implicitBasePath : basePath;
return StringUtils.isEmpty(path) ? "." : path;
}
+
/**
* Sets the basePath for all file references from this Configuration Factory.
* Normally a base path need not to be set because it is determined by
@@ -394,15 +422,14 @@
* a default class for the objects to be created.
* There will be sub classes for specific configuration implementations.
*/
- public class DigesterConfigurationFactory
- extends AbstractObjectCreationFactory
- implements ObjectCreationFactory
+ public class DigesterConfigurationFactory extends AbstractObjectCreationFactory
{
/** Actual class to use. */
private Class clazz;
/**
* Creates a new instance of <code>DigesterConfigurationFactory</code>.
+ *
* @param clazz the class which we should instantiate
*/
public DigesterConfigurationFactory(Class clazz)
@@ -412,6 +439,7 @@
/**
* Creates an instance of the specified class.
+ *
* @param attribs the attributes (ignored)
* @return the new object
* @throws Exception if object creation fails
@@ -428,8 +456,7 @@
* that already have the correct base Path set.
*
*/
- public class BasePathConfigurationFactory
- extends DigesterConfigurationFactory
+ public class BasePathConfigurationFactory extends DigesterConfigurationFactory
{
/**
* C'tor
@@ -450,8 +477,7 @@
*/
public Object createObject(Attributes attributes) throws Exception
{
- BasePathLoader bpl =
- (BasePathLoader) super.createObject(attributes);
+ BasePathLoader bpl = (BasePathLoader) super.createObject(attributes);
bpl.setBasePath(getBasePath());
return bpl;
}
@@ -462,8 +488,7 @@
* let the digester construct JNDIPathConfiguration objects.
*
*/
- public class JNDIConfigurationFactory
- extends DigesterConfigurationFactory
+ public class JNDIConfigurationFactory extends DigesterConfigurationFactory
{
/**
* C'tor
@@ -550,6 +575,7 @@
/**
* Adds a new configuration to this object. This method is called by
* Digester.
+ *
* @param conf the configuration to be added
*/
public void addConfiguration(Configuration conf)
@@ -560,6 +586,7 @@
/**
* Adds information about an additional configuration. This method is
* called by Digester.
+ *
* @param data the data about the additional configuration
*/
public void addAdditionalConfig(AdditionalConfigurationData data)
@@ -569,20 +596,20 @@
/**
* Returns the final composite configuration.
+ *
* @return the final configuration object
*/
public CompositeConfiguration getConfiguration()
{
- if(!additionalConfigs.isEmpty())
+ if (!additionalConfigs.isEmpty())
{
- Configuration unionConfig =
- createAdditionalConfiguration(additionalConfigs);
- if(unionConfig != null)
+ Configuration unionConfig = createAdditionalConfiguration(additionalConfigs);
+ if (unionConfig != null)
{
addConfiguration(unionConfig);
- } /* if */
+ }
additionalConfigs.clear();
- } /* if */
+ }
return config;
}
@@ -592,41 +619,40 @@
* defined in the <code><additional></code> section. This
* implementation returns a <code>HierarchicalConfiguration</code>
* object.
+ *
* @param configs a collection with
* <code>AdditionalConfigurationData</code> objects
* @return the union configuration (can be <b>null</b>)
*/
- protected Configuration createAdditionalConfiguration(
- Collection configs)
+ protected Configuration createAdditionalConfiguration(Collection configs)
{
HierarchicalConfiguration result = new HierarchicalConfiguration();
- for(Iterator it = configs.iterator(); it.hasNext();)
+ for (Iterator it = configs.iterator(); it.hasNext();)
{
AdditionalConfigurationData cdata =
(AdditionalConfigurationData) it.next();
result.addNodes(cdata.getAt(),
createRootNode(cdata).getChildren().asList());
- } /* for */
+ }
- return (result.isEmpty()) ? null : result;
+ return result.isEmpty() ? null : result;
}
/**
* Creates a configuration root node for the specified configuration.
+ *
* @param cdata the configuration data object
* @return a root node for this configuration
*/
private HierarchicalConfiguration.Node createRootNode(
AdditionalConfigurationData cdata)
{
- if(cdata.getConfiguration() instanceof HierarchicalConfiguration)
+ if (cdata.getConfiguration() instanceof HierarchicalConfiguration)
{
// we can directly use this configuration's root node
- return ((HierarchicalConfiguration) cdata.getConfiguration())
- .getRoot();
- } /* if */
-
+ return ((HierarchicalConfiguration) cdata.getConfiguration()).getRoot();
+ }
else
{
// transform configuration to a hierarchical root node
@@ -634,7 +660,7 @@
new HierarchicalConfigurationNodeConverter();
conv.process(cdata.getConfiguration());
return conv.getRootNode();
- } /* else */
+ }
}
}
@@ -645,8 +671,7 @@
* add additional configuration objects to the hierarchical configuration
* managed by the <code>ConfigurationBuilder</code>.
*/
- static class HierarchicalConfigurationNodeConverter
- extends HierarchicalConfigurationConverter
+ static class HierarchicalConfigurationNodeConverter extends HierarchicalConfigurationConverter
{
/** A stack for constructing the hierarchy.*/
private Stack nodes;
@@ -667,25 +692,25 @@
/**
* Callback for an element start event. Creates a new node and adds
* it to the actual parent.
+ *
* @param name the name of the new node
* @param value the node's value
*/
protected void elementStart(String name, Object value)
{
- HierarchicalConfiguration.Node parent =
- (HierarchicalConfiguration.Node) nodes.peek();
- HierarchicalConfiguration.Node child =
- new HierarchicalConfiguration.Node(name);
- if(value != null)
+ HierarchicalConfiguration.Node parent = (HierarchicalConfiguration.Node) nodes.peek();
+ HierarchicalConfiguration.Node child = new HierarchicalConfiguration.Node(name);
+ if (value != null)
{
child.setValue(value);
- } /* if */
+ }
parent.addChild(child);
nodes.push(child);
}
/**
* Callback for an element end event. Clears the stack.
+ *
* @param name the name of the element
*/
protected void elementEnd(String name)
@@ -695,6 +720,7 @@
/**
* Returns the constructed root node.
+ *
* @return the root node
*/
public HierarchicalConfiguration.Node getRootNode()
1.4 +92 -68 jakarta-commons/configuration/src/java/org/apache/commons/configuration/ConfigurationKey.java
Index: ConfigurationKey.java
===================================================================
RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/ConfigurationKey.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ConfigurationKey.java 27 Feb 2004 17:41:35 -0000 1.3
+++ ConfigurationKey.java 23 Jun 2004 11:15:45 -0000 1.4
@@ -1,5 +1,3 @@
-package org.apache.commons.configuration;
-
/*
* Copyright 2004 The Apache Software Foundation.
*
@@ -16,6 +14,8 @@
* limitations under the License.
*/
+package org.apache.commons.configuration;
+
import java.io.Serializable;
import java.util.Iterator;
import java.util.NoSuchElementException;
@@ -23,15 +23,18 @@
/**
* <p>A simple class that supports creation of and iteration on complex
* configuration keys.</p>
+ *
* <p>For key creation the class works similar to a StringBuffer: There are
* several <code>appendXXXX()</code> methods with which single parts
* of a key can be constructed. All these methods return a reference to the
* actual object so they can be written in a chain. When using this methods
* the exact syntax for keys need not be known.</p>
+ *
* <p>This class also defines a specialized iterator for configuration keys.
* With such an iterator a key can be tokenized into its single parts. For
* each part it can be checked whether it has an associated index.</p>
*
+ * @author <a href="mailto:oliver.heger@t-online.de">Oliver Heger</a>
* @version $Id$
*/
public class ConfigurationKey implements Serializable
@@ -68,6 +71,7 @@
/**
* Creates a new instance of <code>ConfigurationKey</code> and
* initializes it with the given key.
+ *
* @param key the key as a string
*/
public ConfigurationKey(String key)
@@ -79,16 +83,16 @@
/**
* Appends the name of a property to this key. If necessary, a
* property delimiter will be added.
+ *
* @param property the name of the property to be added
* @return a reference to this object
*/
public ConfigurationKey append(String property)
{
- if(keyBuffer.length() > 0 && !hasDelimiter()
- && !isAttributeKey(property))
+ if (keyBuffer.length() > 0 && !hasDelimiter() && !isAttributeKey(property))
{
keyBuffer.append(PROPERTY_DELIMITER);
- } /* if */
+ }
keyBuffer.append(property);
removeTrailingDelimiter();
@@ -97,6 +101,7 @@
/**
* Appends an index to this configuration key.
+ *
* @param index the index to be appended
* @return a reference to this object
*/
@@ -109,6 +114,7 @@
/**
* Appends an attribute to this configuration key.
+ *
* @param attr the name of the attribute to be appended
* @return a reference to this object
*/
@@ -122,6 +128,7 @@
* Checks if the passed in key is an attribute key. Such attribute keys
* start and end with certain marker strings. In some cases they must be
* treated slightly different.
+ *
* @param key the key (part) to be checked
* @return a flag if this key is an attribute key
*/
@@ -135,6 +142,7 @@
/**
* Decorates the given key so that it represents an attribute. Adds
* special start and end markers.
+ *
* @param key the key to be decorated
* @return the decorated attribute key
*/
@@ -149,35 +157,36 @@
* Extracts the name of the attribute from the given attribute key.
* This method removes the attribute markers - if any - from the
* specified key.
+ *
* @param key the attribute key
* @return the name of the corresponding attribute
*/
public static String attributeName(String key)
{
- return (isAttributeKey(key)) ?
- removeAttributeMarkers(key) : key;
+ return isAttributeKey(key) ? removeAttributeMarkers(key) : key;
}
/**
* Helper method for removing attribute markers from a key.
+ *
* @param key the key
* @return the key with removed attribute markers
*/
private static String removeAttributeMarkers(String key)
{
- return key.substring(ATTRIBUTE_START.length(),
- key.length() - ATTRIBUTE_END.length());
+ return key.substring(ATTRIBUTE_START.length(), key.length() - ATTRIBUTE_END.length());
}
/**
* Helper method that checks if the actual buffer ends with a property
* delimiter.
+ *
* @return a flag if there is a trailing delimiter
*/
private boolean hasDelimiter()
{
return keyBuffer.length() > 0
- && keyBuffer.charAt(keyBuffer.length()-1) == PROPERTY_DELIMITER;
+ && keyBuffer.charAt(keyBuffer.length() - 1) == PROPERTY_DELIMITER;
}
/**
@@ -185,15 +194,16 @@
*/
private void removeTrailingDelimiter()
{
- while(hasDelimiter())
+ while (hasDelimiter())
{
- keyBuffer.deleteCharAt(keyBuffer.length()-1);
- } /* while */
+ keyBuffer.deleteCharAt(keyBuffer.length() - 1);
+ }
}
/**
* Returns a string representation of this object. This is the
* configuration key as a plain string.
+ *
* @return a string for this object
*/
public String toString()
@@ -204,6 +214,7 @@
/**
* Returns an iterator for iterating over the single components of
* this configuration key.
+ *
* @return an iterator for this key
*/
public KeyIterator iterator()
@@ -213,6 +224,7 @@
/**
* Returns the actual length of this configuration key.
+ *
* @return the length of this key
*/
public int length()
@@ -225,6 +237,7 @@
* possible to truncate the key, e.g. to return to a state prior calling
* some <code>append()</code> methods. The semantic is the same as
* the <code>setLength()</code> method of <code>StringBuffer</code>.
+ *
* @param len the new length of the key
*/
public void setLength(int len)
@@ -235,21 +248,23 @@
/**
* Checks if two <code>ConfigurationKey</code> objects are equal. The
* method can be called with strings or other objects, too.
+ *
* @param c the object to compare
* @return a flag if both objects are equal
*/
public boolean equals(Object c)
{
- if(c == null)
+ if (c == null)
{
return false;
- } /* if */
+ }
return keyBuffer.toString().equals(c.toString());
}
/**
* Returns the hash code for this object.
+ *
* @return the hash code
*/
public int hashCode()
@@ -260,36 +275,36 @@
/**
* Returns a configuration key object that is initialized with the part
* of the key that is common to this key and the passed in key.
+ *
* @param other the other key
* @return a key object with the common key part
*/
public ConfigurationKey commonKey(ConfigurationKey other)
{
- if(other == null)
+ if (other == null)
{
throw new IllegalArgumentException("Other key must no be null!");
- } /* if */
+ }
ConfigurationKey result = new ConfigurationKey();
KeyIterator it1 = iterator();
KeyIterator it2 = other.iterator();
- while(it1.hasNext() && it2.hasNext()
- && partsEqual(it1, it2))
+ while (it1.hasNext() && it2.hasNext() && partsEqual(it1, it2))
{
- if(it1.isAttribute())
+ if (it1.isAttribute())
{
result.appendAttribute(it1.currentKey());
- } /* if */
+ }
else
{
result.append(it1.currentKey());
- if(it1.hasIndex)
+ if (it1.hasIndex)
{
result.appendIndex(it1.getIndex());
- } /* if */
- } /* else */
- } /* while */
+ }
+ }
+ }
return result;
}
@@ -300,6 +315,7 @@
* the following relation:
* <code>other = key.commonKey(other) + key.differenceKey(other)</code>
* for an arbitrary configuration key <code>key</code>.
+ *
* @param other the key for which the difference is to be calculated
* @return the difference key
*/
@@ -308,27 +324,28 @@
ConfigurationKey common = commonKey(other);
ConfigurationKey result = new ConfigurationKey();
- if(common.length() < other.length())
+ if (common.length() < other.length())
{
String k = other.toString().substring(common.length());
// skip trailing delimiters
int i = 0;
- while(i < k.length() && k.charAt(i) == PROPERTY_DELIMITER)
+ while (i < k.length() && k.charAt(i) == PROPERTY_DELIMITER)
{
i++;
- } /* while */
+ }
- if(i < k.length())
+ if (i < k.length())
{
result.append(k.substring(i));
- } /* if */
- } /* if */
+ }
+ }
return result;
}
/**
* Helper method for comparing two key parts.
+ *
* @param it1 the iterator with the first part
* @param it2 the iterator with the second part
* @return a flag if both parts are equal
@@ -344,7 +361,6 @@
* A specialized iterator class for tokenizing a configuration key.
* This class implements the normal iterator interface. In addition it
* provides some specific methods for configuration keys.
- *
*/
public class KeyIterator implements Iterator, Cloneable
{
@@ -373,38 +389,37 @@
{
startIndex = endIndex;
// skip empty names
- while(startIndex < keyBuffer.length()
+ while (startIndex < keyBuffer.length()
&& keyBuffer.charAt(startIndex) == PROPERTY_DELIMITER)
{
startIndex++;
- } /* while */
+ }
// Key ends with a delimiter?
- if(startIndex >= keyBuffer.length())
+ if (startIndex >= keyBuffer.length())
{
endIndex = keyBuffer.length();
startIndex = endIndex - 1;
- } /* if */
-
+ }
else
{
-
- String s = keyBuffer.toString(); // for compatibility
+ String s = keyBuffer.toString(); // for compatibility
endIndex = s.indexOf(PROPERTY_DELIMITER, startIndex);
- if(endIndex < 0)
+ if (endIndex < 0)
{
- endIndex = s.indexOf(ATTRIBUTE_START, startIndex);
- if(endIndex < 0 || endIndex == startIndex)
+ endIndex = s.indexOf(ATTRIBUTE_START, startIndex);
+ if (endIndex < 0 || endIndex == startIndex)
{
endIndex = keyBuffer.length();
- } /* if */
- } /* if */
+ }
+ }
}
}
/**
* Returns the next key part of this configuration key. This is a short
* form of <code>nextKey(false)</code>.
+ *
* @return the next key part
*/
public String nextKey()
@@ -418,15 +433,16 @@
* affects only attribute keys: if the parameter is <b>false</b>, the
* attribute markers are stripped from the key; if it is <b>true</b>,
* they remain.
+ *
* @param decorated a flag if the decorated key is to be returned
* @return the next key part
*/
public String nextKey(boolean decorated)
{
- if(!hasNext())
+ if (!hasNext())
{
throw new NoSuchElementException("No more key parts!");
- } /* if */
+ }
hasIndex = false;
indexValue = -1;
@@ -434,14 +450,14 @@
String key = keyBuffer.substring(startIndex, endIndex).toString();
attribute = checkAttribute(key);
- if(!attribute)
+ if (!attribute)
{
hasIndex = checkIndex(key);
- if(!hasIndex)
+ if (!hasIndex)
{
current = key;
- } /* if */
- } /* if */
+ }
+ }
return currentKey(decorated);
}
@@ -449,25 +465,27 @@
/**
* Helper method for checking if the passed key is an attribute.
* If this is the case, the internal fields will be set.
+ *
* @param key the key to be checked
* @return a flag if the key is an attribute
*/
private boolean checkAttribute(String key)
{
- if(isAttributeKey(key))
+ if (isAttributeKey(key))
{
current = removeAttributeMarkers(key);
return true;
- } /* if */
+ }
else
{
return false;
- } /* else */
+ }
}
/**
* Helper method for checking if the passed key contains an index.
* If this is the case, internal fields will be set.
+ *
* @param key the key to be checked
* @return a flag if an index is defined
*/
@@ -476,23 +494,24 @@
boolean result = false;
int idx = key.indexOf(INDEX_START);
- if(idx > 0)
+ if (idx > 0)
{
int endidx = key.indexOf(INDEX_END, idx);
- if(endidx > idx + 1)
+ if (endidx > idx + 1)
{
- indexValue = Integer.parseInt(key.substring(idx+1, endidx));
+ indexValue = Integer.parseInt(key.substring(idx + 1, endidx));
current = key.substring(0, idx);
result = true;
- } /* if */
- } /* if */
+ }
+ }
return result;
}
/**
* Checks if there is a next element.
+ *
* @return a flag if there is a next element
*/
public boolean hasNext()
@@ -502,6 +521,7 @@
/**
* Returns the next object in the iteration.
+ *
* @return the next object
*/
public Object next()
@@ -522,6 +542,7 @@
* Returns the current key of the iteration (without skipping to the
* next element). This is the same key the previous <code>next()</code>
* call had returned. (Short form of <code>currentKey(false)</code>.
+ *
* @return the current key
*/
public String currentKey()
@@ -535,18 +556,19 @@
* key should be returned. This affects only attribute keys: if the
* parameter is <b>false</b>, the attribute markers are stripped from
* the key; if it is <b>true</b>, they remain.
+ *
* @param decorated a flag if the decorated key is to be returned
* @return the current key
*/
public String currentKey(boolean decorated)
{
- return (decorated && isAttribute()) ?
- constructAttributeKey(current) : current;
+ return (decorated && isAttribute()) ? constructAttributeKey(current) : current;
}
/**
* Returns a flag if the current key is an attribute. This method can
* be called after <code>next()</code>.
+ *
* @return a flag if the current key is an attribute
*/
public boolean isAttribute()
@@ -558,6 +580,7 @@
* Returns the index value of the current key. If the current key does
* not have an index, return value is -1. This method can be called
* after <code>next()</code>.
+ *
* @return the index value of the current key
*/
public int getIndex()
@@ -568,6 +591,7 @@
/**
* Returns a flag if the current key has an associated index.
* This method can be called after <code>next()</code>.
+ *
* @return a flag if the current key has an index
*/
public boolean hasIndex()
@@ -577,6 +601,7 @@
/**
* Creates a clone of this object.
+ *
* @return a clone of this object
*/
protected Object clone()
@@ -584,13 +609,12 @@
try
{
return super.clone();
- } /* try */
- catch(CloneNotSupportedException cex)
- {
- // should not happen
- return null;
- } /* catch */
+ }
+ catch (CloneNotSupportedException cex)
+ {
+ // should not happen
+ return null;
+ }
}
-
}
}
1.4 +26 -20 jakarta-commons/configuration/src/java/org/apache/commons/configuration/ConfigurationUtils.java
Index: ConfigurationUtils.java
===================================================================
RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/ConfigurationUtils.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ConfigurationUtils.java 28 Mar 2004 14:43:04 -0000 1.3
+++ ConfigurationUtils.java 23 Jun 2004 11:15:45 -0000 1.4
@@ -1,5 +1,3 @@
-package org.apache.commons.configuration;
-
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
@@ -16,6 +14,8 @@
* limitations under the License.
*/
+package org.apache.commons.configuration;
+
import java.io.File;
import java.io.PrintStream;
import java.io.PrintWriter;
@@ -29,8 +29,11 @@
/**
* Miscellaneous utility methods for configurations.
*
+ * @author <a href="mailto:herve.quiroz@esil.univ-mrs.fr">Herve Quiroz</a>
+ * @author <a href="mailto:oliver.heger@t-online.de">Oliver Heger</a>
+ * @version $Revision$, $Date$
*/
-public class ConfigurationUtils
+public final class ConfigurationUtils
{
/** File separator. */
protected static final String fileSeparator = System.getProperty("file.separator");
@@ -48,20 +51,21 @@
*/
public static void dump(Configuration configuration, PrintStream out)
{
- for (Iterator i = configuration.getKeys(); i.hasNext(); )
+ Iterator keys = configuration.getKeys();
+ while (keys.hasNext())
{
- String key = (String) i.next();
+ String key = (String) keys.next();
Object value = configuration.getProperty(key);
out.print(key);
out.print("=");
out.print(value);
- if (i.hasNext())
+ if (keys.hasNext())
{
out.println();
}
}
}
-
+
/**
* Dump the configuration key/value mappings to some writer.
*
@@ -70,15 +74,16 @@
*/
public static void dump(Configuration configuration, PrintWriter out)
{
- for (Iterator i = configuration.getKeys(); i.hasNext();)
+ Iterator keys = configuration.getKeys();
+ while (keys.hasNext())
{
- String key = (String) i.next();
+ String key = (String) keys.next();
Object value = configuration.getProperty(key);
out.print(key);
out.print("=");
out.print(value);
- if (i.hasNext())
+ if (keys.hasNext())
{
out.println();
}
@@ -103,42 +108,43 @@
* Constructs a URL from a base path and a file name. The file name can
* be absolute, relative or a full URL. If necessary the base path URL is
* applied.
+ *
* @param basePath the base path URL (can be <b>null</b>)
* @param file the file name
* @return the resulting URL
* @throws MalformedURLException if URLs are invalid
*/
- public static URL getURL(String basePath, String file)
- throws MalformedURLException
+ public static URL getURL(String basePath, String file) throws MalformedURLException
{
File f = new File(file);
- if(f.isAbsolute()) // already absolute?
+ if (f.isAbsolute()) // already absolute?
{
return f.toURL();
- } /* if */
+ }
try
{
- if(basePath == null)
+ if (basePath == null)
{
return new URL(file);
- } /* if */
+ }
else
{
URL base = new URL(basePath);
return new URL(base, file);
- } /* else */
- } /* try */
- catch(MalformedURLException uex)
+ }
+ }
+ catch (MalformedURLException uex)
{
return constructFile(basePath, file).toURL();
- } /* catch */
+ }
}
/**
* Helper method for constructing a file object from a base path and a
* file name. This method is called if the base path passed to
* <code>getURL()</code> does not seem to be a valid URL.
+ *
* @param basePath the base path
* @param fileName the file name
* @return the resulting file
1.5 +2 -2 jakarta-commons/configuration/src/java/org/apache/commons/configuration/DatabaseConfiguration.java
Index: DatabaseConfiguration.java
===================================================================
RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/DatabaseConfiguration.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DatabaseConfiguration.java 22 Jun 2004 12:56:54 -0000 1.4
+++ DatabaseConfiguration.java 23 Jun 2004 11:15:45 -0000 1.5
@@ -79,7 +79,7 @@
}
/**
- * Build a configuration from a table.
+ * Build a configuration from a table.-
*
* @param datasource the datasource to connect to the database
* @param table the name of the table containing the configurations
1.7 +16 -15 jakarta-commons/configuration/src/java/org/apache/commons/configuration/HierarchicalDOM4JConfiguration.java
Index: HierarchicalDOM4JConfiguration.java
===================================================================
RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/HierarchicalDOM4JConfiguration.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- HierarchicalDOM4JConfiguration.java 21 Jun 2004 18:42:39 -0000 1.6
+++ HierarchicalDOM4JConfiguration.java 23 Jun 2004 11:15:45 -0000 1.7
@@ -32,7 +32,8 @@
* <p>The parsed document will be stored keeping its structure. The
* contained properties can be accessed using all methods supported by
* the base class <code>HierarchicalProperties</code>.
- *
+ *
+ * @author <a href="mailto:oliver.heger@t-online.de">Oliver Heger</a>
* @version $Id$
*/
public class HierarchicalDOM4JConfiguration extends HierarchicalConfiguration implements BasePathLoader
@@ -73,7 +74,7 @@
/**
* Returns the base path.
- *
+ *
* @return the base path
*/
public String getBasePath()
@@ -100,14 +101,14 @@
*/
public void load() throws ConfigurationException
{
- try
+ try
{
- load(ConfigurationUtils.getURL(getBasePath(), getFileName()));
- }
- catch (MalformedURLException e)
+ load(ConfigurationUtils.getURL(getBasePath(), getFileName()));
+ }
+ catch (MalformedURLException e)
{
- throw new ConfigurationException("Could not load from " + getBasePath() + ", " + getFileName(), e);
- }
+ throw new ConfigurationException("Could not load from " + getBasePath() + ", " + getFileName(), e);
+ }
}
/**
@@ -118,14 +119,14 @@
*/
public void load(URL url) throws ConfigurationException
{
- try
+ try
{
- initProperties(new SAXReader().read(url));
- }
- catch (DocumentException e)
+ initProperties(new SAXReader().read(url));
+ }
+ catch (DocumentException e)
{
- throw new ConfigurationException("Could not load from " + url, e);
- }
+ throw new ConfigurationException("Could not load from " + url, e);
+ }
}
/**
1.3 +7 -7 jakarta-commons/configuration/src/java/org/apache/commons/configuration/HierarchicalDOMConfiguration.java
Index: HierarchicalDOMConfiguration.java
===================================================================
RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/HierarchicalDOMConfiguration.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- HierarchicalDOMConfiguration.java 21 Jun 2004 18:44:30 -0000 1.2
+++ HierarchicalDOMConfiguration.java 23 Jun 2004 11:15:45 -0000 1.3
@@ -55,7 +55,7 @@
/**
* Constructs a HierarchicalDOMConfiguration.
*/
- public HierarchicalDOMConfiguration()
+ public HierarchicalDOMConfiguration()
{
super();
}
@@ -64,7 +64,7 @@
* Returns the name of the file to be parsed by this object.
* @return the file to be parsed
*/
- public String getFileName()
+ public String getFileName()
{
return file;
}
@@ -111,7 +111,7 @@
catch (MalformedURLException mue)
{
throw new ConfigurationException(
- "Could not load from " + getBasePath() +
+ "Could not load from " + getBasePath() +
", " + getFileName());
}
}
@@ -167,7 +167,7 @@
constructHierarchy(childNode, child);
node.addChild(childNode);
processAttributes(childNode, child);
- }
+ }
else if (w3cNode instanceof CharacterData)
{
CharacterData data = (CharacterData) w3cNode;
@@ -191,10 +191,10 @@
private void processAttributes(Node node, Element element)
{
NamedNodeMap attributes = element.getAttributes();
- for (int i = 0; i < attributes.getLength(); ++i)
+ for (int i = 0; i < attributes.getLength(); ++i)
{
org.w3c.dom.Node w3cNode = attributes.item(i);
- if (w3cNode instanceof Attr)
+ if (w3cNode instanceof Attr)
{
Attr attr = (Attr) w3cNode;
Node child =
1.14 +8 -6 jakarta-commons/configuration/src/java/org/apache/commons/configuration/JNDIConfiguration.java
Index: JNDIConfiguration.java
===================================================================
RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/JNDIConfiguration.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- JNDIConfiguration.java 15 Jun 2004 15:53:58 -0000 1.13
+++ JNDIConfiguration.java 23 Jun 2004 11:15:45 -0000 1.14
@@ -40,6 +40,7 @@
* UnsupportedOperationException. The clear operations are supported but the
* underlying JNDI data source is not changed.
*
+ * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
* @version $Id$
*/
public class JNDIConfiguration extends AbstractConfiguration
@@ -82,7 +83,7 @@
while (enumeration.hasMoreElements())
{
Object o = enumeration.next();
-
+
NameClassPair nameClassPair = (NameClassPair) o;
StringBuffer newKey = new StringBuffer();
newKey.append(key);
@@ -142,7 +143,7 @@
}
else
{
- context = getStartingContextPoint(keys, getContext(),getContext().list(""));
+ context = getStartingContextPoint(keys, getContext(), getContext().list(""));
}
if (context != null)
@@ -172,7 +173,7 @@
String keyToSearchFor = (String) keys.get(0);
log.debug("Key to search for is " + keyToSearchFor);
while (enumeration.hasMoreElements())
- {
+ {
NameClassPair nameClassPair = (NameClassPair) enumeration.next();
Object o = parentContext.lookup(nameClassPair.getName());
log.debug(
@@ -189,7 +190,7 @@
Context c = (Context) o;
if (!keys.isEmpty())
{
- return getStartingContextPoint(keys,c, c.list(""));
+ return getStartingContextPoint(keys, c, c.list(""));
}
else
{
@@ -317,7 +318,8 @@
}
}
- protected void addPropertyDirect(String key, Object obj) {
+ protected void addPropertyDirect(String key, Object obj)
+ {
throw new UnsupportedOperationException("This operation is not supported");
}
1.10 +27 -27 jakarta-commons/configuration/src/java/org/apache/commons/configuration/PropertiesConfiguration.java
Index: PropertiesConfiguration.java
===================================================================
RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/PropertiesConfiguration.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- PropertiesConfiguration.java 21 Jun 2004 17:45:29 -0000 1.9
+++ PropertiesConfiguration.java 23 Jun 2004 11:15:45 -0000 1.10
@@ -26,17 +26,17 @@
/**
* This is the "classic" Properties loader which loads the values from
* a single or multiple files (which can be chained with "include =".
- * All given path references are either absolute or relative to the
+ * All given path references are either absolute or relative to the
* file name supplied in the Constructor.
* <p>
* In this class, empty PropertyConfigurations can be built, properties
* added and later saved. include statements are (obviously) not supported
* if you don't construct a PropertyConfiguration from a file.
* <p>
- * If you want to use the getResourceAsStream() trick to load your
+ * If you want to use the getResourceAsStream() trick to load your
* resources without an absolute path, please take a look at the
* ClassPropertiesConfiguration which is intended to be used for this.
- *
+ *
* @version $Id$
*/
public class PropertiesConfiguration extends BasePropertiesConfiguration
@@ -44,7 +44,7 @@
/** File separator. */
protected String fileSeparator = System.getProperty("file.separator");
- /**
+ /**
* The name of the file to be loaded. This is used in conjuction with
* the load method. */
protected String fileName = null;
@@ -52,7 +52,7 @@
/**
* Creates an empty PropertyConfiguration object which can be
* used to synthesize a new Properties file by adding values and
- * then saving(). An object constructed by this C'tor can not be
+ * then saving(). An object constructed by this C'tor can not be
* tickled into loading included files because it cannot supply a
* base for relative includes.
*/
@@ -75,7 +75,7 @@
}
/**
- * Load the properties from the fileName set by setFileName
+ * Load the properties from the fileName set by setFileName
*
* @throws ConfigurationException
*/
@@ -92,31 +92,31 @@
*/
public void load(String fileName) throws ConfigurationException
{
- InputStream in = null;
- try
+ InputStream in = null;
+ try
{
- in = getPropertyStream(fileName);
- load(in);
- }
- catch (IOException e)
+ in = getPropertyStream(fileName);
+ load(in);
+ }
+ catch (IOException e)
{
- throw new ConfigurationException("Could not load from file " + fileName, e);
- }
- finally
+ throw new ConfigurationException("Could not load from file " + fileName, e);
+ }
+ finally
{
- // close the input stream
+ // close the input stream
if (in != null)
{
- try
+ try
{
- in.close();
- }
- catch (IOException e)
+ in.close();
+ }
+ catch (IOException e)
{
- e.printStackTrace();
- }
- }
- }
+ e.printStackTrace();
+ }
+ }
+ }
}
/**
@@ -139,7 +139,7 @@
{
InputStream resource = null;
URL url = null;
-
+
try
{
url = ConfigurationUtils.getURL(getBasePath(), resourceName);
@@ -149,7 +149,7 @@
throw new IOException("Cannot obtain URL for resource "
+ resourceName);
} /* catch */
-
+
resource = url.openStream();
setBasePath(url.toString());
1.4 +63 -31 jakarta-commons/configuration/src/java/org/apache/commons/configuration/SubsetConfiguration.java
Index: SubsetConfiguration.java
===================================================================
RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/SubsetConfiguration.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SubsetConfiguration.java 16 Jun 2004 18:13:53 -0000 1.3
+++ SubsetConfiguration.java 23 Jun 2004 11:15:45 -0000 1.4
@@ -31,8 +31,8 @@
* @author Emmanuel Bourg
* @version $Revision$, $Date$
*/
-public class SubsetConfiguration extends AbstractConfiguration {
-
+public class SubsetConfiguration extends AbstractConfiguration
+{
protected Configuration parent;
protected String prefix;
protected String delimiter;
@@ -43,7 +43,8 @@
* @param parent The parent configuration
* @param prefix The prefix used to select the properties.
*/
- public SubsetConfiguration(Configuration parent, String prefix) {
+ public SubsetConfiguration(Configuration parent, String prefix)
+ {
this.parent = parent;
this.prefix = prefix;
}
@@ -55,7 +56,8 @@
* @param prefix The prefix used to select the properties.
* @param delimiter The prefix delimiter
*/
- public SubsetConfiguration(Configuration parent, String prefix, String delimiter) {
+ public SubsetConfiguration(Configuration parent, String prefix, String delimiter)
+ {
this.parent = parent;
this.prefix = prefix;
this.delimiter = delimiter;
@@ -67,10 +69,14 @@
*
* @param key The key in the subset.
*/
- protected String getParentKey(String key) {
- if ("".equals(key) || key == null) {
+ protected String getParentKey(String key)
+ {
+ if ("".equals(key) || key == null)
+ {
return prefix;
- } else {
+ }
+ else
+ {
return delimiter == null ? prefix + key : prefix + delimiter + key;
}
}
@@ -81,14 +87,21 @@
*
* @param key The key in the parent configuration.
*/
- protected String getChildKey(String key) {
- if (!key.startsWith(prefix)) {
+ protected String getChildKey(String key)
+ {
+ if (!key.startsWith(prefix))
+ {
throw new IllegalArgumentException("The parent key '" + key + "' is not in the subset.");
- } else {
+ }
+ else
+ {
String modifiedKey = null;
- if (key.length() == prefix.length()) {
+ if (key.length() == prefix.length())
+ {
modifiedKey = "";
- } else {
+ }
+ else
+ {
int i = prefix.length() + (delimiter != null ? delimiter.length() : 0);
modifiedKey = key.substring(i);
}
@@ -100,63 +113,79 @@
/**
* Return the parent configuation for this subset.
*/
- public Configuration getParent() {
+ public Configuration getParent()
+ {
return parent;
}
/**
* Return the prefix used to select the properties in the parent configuration.
*/
- public String getPrefix() {
+ public String getPrefix()
+ {
return prefix;
}
/**
* Set the prefix used to select the properties in the parent configuration.
*/
- public void setPrefix(String prefix) {
+ public void setPrefix(String prefix)
+ {
this.prefix = prefix;
}
- public Configuration subset(String prefix) {
+ public Configuration subset(String prefix)
+ {
return parent.subset(getParentKey(prefix));
}
- public boolean isEmpty() {
+ public boolean isEmpty()
+ {
return !getKeys().hasNext();
}
- public boolean containsKey(String key) {
+ public boolean containsKey(String key)
+ {
return parent.containsKey(getParentKey(key));
}
- public void addPropertyDirect(String key, Object value) {
+ public void addPropertyDirect(String key, Object value)
+ {
parent.addProperty(getParentKey(key), value);
}
- public void setProperty(String key, Object value) {
+ public void setProperty(String key, Object value)
+ {
parent.setProperty(getParentKey(key), value);
}
- public void clearProperty(String key) {
+ public void clearProperty(String key)
+ {
parent.clearProperty(getParentKey(key));
}
- public Object getPropertyDirect(String key) {
+ public Object getPropertyDirect(String key)
+ {
return parent.getProperty(getParentKey(key));
}
- public Iterator getKeys(String prefix) {
- return new TransformIterator(parent.getKeys(getParentKey(prefix)), new Transformer() {
- public Object transform(Object obj) {
+ public Iterator getKeys(String prefix)
+ {
+ return new TransformIterator(parent.getKeys(getParentKey(prefix)), new Transformer()
+ {
+ public Object transform(Object obj)
+ {
return getChildKey((String) obj);
}
});
}
- public Iterator getKeys() {
- return new TransformIterator(parent.getKeys(prefix), new Transformer() {
- public Object transform(Object obj) {
+ public Iterator getKeys()
+ {
+ return new TransformIterator(parent.getKeys(prefix), new Transformer()
+ {
+ public Object transform(Object obj)
+ {
return getChildKey((String) obj);
}
});
@@ -164,9 +193,12 @@
protected String interpolate(String base)
{
- if (delimiter == null && "".equals(prefix)) {
+ if (delimiter == null && "".equals(prefix))
+ {
return super.interpolate(base);
- } else {
+ }
+ else
+ {
SubsetConfiguration config = new SubsetConfiguration(parent, "");
return config.interpolate(base);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org