You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by he...@apache.org on 2004/09/20 11:37:08 UTC
cvs commit: jakarta-commons/configuration/src/java/org/apache/commons/configuration/beanutils ConfigurationDynaBean.java ConfigurationDynaClass.java
henning 2004/09/20 02:37:07
Modified: configuration/src/java/org/apache/commons/configuration
AbstractConfiguration.java
BasePropertiesConfiguration.java
ConfigurationMap.java ConfigurationSet.java
DatabaseConfiguration.java
HierarchicalConfiguration.java
HierarchicalConfigurationConverter.java
XMLConfiguration.java
configuration/src/java/org/apache/commons/configuration/beanutils
ConfigurationDynaBean.java
ConfigurationDynaClass.java
Log:
Findbugs and PMD tests.
Removed Tabs, Spaces and some checkstyle errors.
Revision Changes Path
1.23 +12 -10 jakarta-commons/configuration/src/java/org/apache/commons/configuration/AbstractConfiguration.java
Index: AbstractConfiguration.java
===================================================================
RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/AbstractConfiguration.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- AbstractConfiguration.java 19 Sep 2004 22:01:49 -0000 1.22
+++ AbstractConfiguration.java 20 Sep 2004 09:37:07 -0000 1.23
@@ -50,12 +50,12 @@
protected static final String END_TOKEN = "}";
/** The property delimiter used while parsing (a comma). */
- protected static char DELIMITER = ',';
+ private static char DELIMITER = ',';
/** how big the initial arraylist for splitting up name value pairs */
private static final int INITIAL_LIST_SIZE = 2;
- /**
+ /**
* Whether the configuration should throw NoSuchElementExceptions or simply return null
* when a property does not exist. Defaults to return null.
*/
@@ -66,21 +66,23 @@
* change the delimiter from the default comma (",").
* @param delimiter The new delimiter
*/
- public static void setDelimiter(char delimiter){
+ public static void setDelimiter(char delimiter)
+ {
AbstractConfiguration.DELIMITER = delimiter;
}
-
+
/**
* Retrieve the current delimiter. By default this is a comma (",").
* @return The delimiter in use
*/
- public static char getDelimiter(){
+ public static char getDelimiter()
+ {
return AbstractConfiguration.DELIMITER;
}
/**
* If set to false, missing elements return null if possible (for objects).
- *
+ *
* @param throwExceptionOnMissing The new value for the property
*/
public void setThrowExceptionOnMissing(boolean throwExceptionOnMissing)
@@ -830,7 +832,7 @@
{
return number;
}
- else if(throwExceptionOnMissing)
+ else if (throwExceptionOnMissing)
{
throw new NoSuchElementException(
'\'' + key + "' doesn't map to an existing object");
@@ -884,7 +886,7 @@
{
return number;
}
- else if(throwExceptionOnMissing)
+ else if (throwExceptionOnMissing)
{
throw new NoSuchElementException(
'\'' + key + "' doesn't map to an existing object");
@@ -939,7 +941,7 @@
{
return s;
}
- else if(throwExceptionOnMissing)
+ else if (throwExceptionOnMissing)
{
throw new NoSuchElementException(
'\'' + key + "' doesn't map to an existing object");
1.20 +126 -70 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.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- BasePropertiesConfiguration.java 16 Sep 2004 22:35:35 -0000 1.19
+++ BasePropertiesConfiguration.java 20 Sep 2004 09:37:07 -0000 1.20
@@ -169,68 +169,113 @@
*/
public synchronized void load(InputStream input, String encoding) throws ConfigurationException
{
+ InputStreamReader isr = null;
PropertiesReader reader = null;
- if (encoding != null)
- {
- try
- {
- reader = new PropertiesReader(new InputStreamReader(input, encoding));
- }
- catch (UnsupportedEncodingException e)
- {
- throw new ConfigurationException("Should look up and use default encoding.", e);
- }
- }
-
- if (reader == null)
- {
- reader = new PropertiesReader(new InputStreamReader(input));
- }
try
{
- while (true)
+ if (encoding != null)
{
- String line = reader.readProperty();
-
- if (line == null)
+ try
+ {
+ isr = new InputStreamReader(input, encoding);
+ reader = new PropertiesReader(isr);
+ }
+ catch (UnsupportedEncodingException e)
{
- break; // EOF
+ throw new ConfigurationException("Should look up and use default encoding.", e);
}
+ }
- int equalSign = line.indexOf('=');
- if (equalSign > 0)
+ if (reader == null)
+ {
+ isr = new InputStreamReader(input);
+ reader = new PropertiesReader(isr);
+ }
+
+ try
+ {
+ while (true)
{
- String key = line.substring(0, equalSign).trim();
- String value = line.substring(equalSign + 1).trim();
+ String line = reader.readProperty();
- // Though some software (e.g. autoconf) may produce
- // empty values like foo=\n, emulate the behavior of
- // java.util.Properties by setting the value to the
- // empty string.
+ if (line == null)
+ {
+ break; // EOF
+ }
- if (StringUtils.isNotEmpty(getInclude())
- && key.equalsIgnoreCase(getInclude()))
+ int equalSign = line.indexOf('=');
+ if (equalSign > 0)
{
- if (getIncludesAllowed())
+ String key = line.substring(0, equalSign).trim();
+ String value = line.substring(equalSign + 1).trim();
+
+ // Though some software (e.g. autoconf) may produce
+ // empty values like foo=\n, emulate the behavior of
+ // java.util.Properties by setting the value to the
+ // empty string.
+
+ if (StringUtils.isNotEmpty(getInclude())
+ && key.equalsIgnoreCase(getInclude()))
{
- String [] files = StringUtils.split(value, DELIMITER);
- for (int i = 0; i < files.length; i++)
+ if (getIncludesAllowed())
{
- load(getPropertyStream(files[i].trim()));
+ String [] files = StringUtils.split(value, getDelimiter());
+ for (int i = 0; i < files.length; i++)
+ {
+ InputStream in = null;
+ try
+ {
+ in = getPropertyStream(files[i].trim());
+ load(in);
+ }
+ finally
+ {
+ if (in != null)
+ {
+ in.close();
+ }
+ }
+ }
}
}
- }
- else
- {
- addProperty(key, unescapeJava(value));
+ else
+ {
+ addProperty(key, unescapeJava(value));
+ }
}
}
}
+ catch (IOException ioe)
+ {
+ throw new ConfigurationException("Could not load configuration from input stream.", ioe);
+ }
}
- catch (IOException ioe)
+ finally
{
- throw new ConfigurationException("Could not load configuration from input stream.", ioe);
+ if (isr != null)
+ {
+ try
+ {
+ isr.close();
+ }
+ catch (IOException ie)
+ {
+ // do nothing
+ }
+ }
+
+ if (reader != null)
+ {
+ try
+ {
+ reader.close();
+ }
+ catch (IOException ie)
+ {
+ // do nothing
+ }
+ }
}
}
@@ -267,9 +312,9 @@
writer.close();
}
}
- catch (IOException ioe2)
- {
- throw new ConfigurationException("Could not close writer while saving to file " + filename,ioe2);
+ catch (IOException ioe2)
+ {
+ throw new ConfigurationException("Could not close writer while saving to file " + filename,ioe2);
}
}
}
@@ -303,28 +348,39 @@
*/
public void save(Writer writer) throws IOException
{
- PropertiesWriter out = new PropertiesWriter(writer);
-
- out.writeComment("written by PropertiesConfiguration");
- out.writeComment(new Date().toString());
+ PropertiesWriter out = null;
- Iterator keys = getKeys();
- while (keys.hasNext())
+ try
{
- String key = (String) keys.next();
- Object value = getProperty(key);
+ out = new PropertiesWriter(writer);
+
+ out.writeComment("written by PropertiesConfiguration");
+ out.writeComment(new Date().toString());
- if (value instanceof List)
+ Iterator keys = getKeys();
+ while (keys.hasNext())
{
- out.writeProperty(key, (List) value);
+ String key = (String) keys.next();
+ Object value = getProperty(key);
+
+ if (value instanceof List)
+ {
+ out.writeProperty(key, (List) value);
+ }
+ else
+ {
+ out.writeProperty(key, value);
+ }
}
- else
+ }
+ finally
+ {
+ if (out != null)
{
- out.writeProperty(key, value);
+ out.flush();
+ out.close();
}
}
-
- out.flush();
}
/**
@@ -377,7 +433,7 @@
* backslash sign a the end of the line. This is used to
* concatenate multiple lines for readability.
*/
- class PropertiesReader extends LineNumberReader
+ public static class PropertiesReader extends LineNumberReader
{
/**
* Constructor.
@@ -414,7 +470,7 @@
line = line.trim();
if (StringUtils.isEmpty(line)
- || (line.charAt(0) == '#'))
+ || (line.charAt(0) == '#'))
{
continue;
}
@@ -437,7 +493,7 @@
/**
* This class is used to write properties lines.
*/
- class PropertiesWriter extends FilterWriter
+ public static class PropertiesWriter extends FilterWriter
{
/**
* Constructor.
@@ -463,7 +519,7 @@
if (value != null)
{
String v = StringEscapeUtils.escapeJava(String.valueOf(value));
- v = StringUtils.replace(v, String.valueOf(DELIMITER), "\\" + DELIMITER);
+ v = StringUtils.replace(v, String.valueOf(getDelimiter()), "\\" + getDelimiter());
write(v);
}
@@ -549,8 +605,8 @@
{
// handle an escaped value
hadSlash = false;
-
- if(ch=='\\'){
+
+ if (ch=='\\'){
out.append('\\');
}
else if (ch=='\''){
@@ -574,18 +630,18 @@
else if (ch=='b'){
out.append('\b');
}
- else if (ch==DELIMITER){
+ else if (ch==getDelimiter()){
out.append('\\');
- out.append(DELIMITER);
+ out.append(getDelimiter());
}
else if (ch=='u'){
-// uh-oh, we're in unicode country....
+ // uh-oh, we're in unicode country....
inUnicode = true;
- }
+ }
else {
out.append(ch);
}
-
+
continue;
}
else if (ch == '\\')
1.3 +7 -7 jakarta-commons/configuration/src/java/org/apache/commons/configuration/ConfigurationMap.java
Index: ConfigurationMap.java
===================================================================
RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/ConfigurationMap.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ConfigurationMap.java 12 Aug 2004 17:17:15 -0000 1.2
+++ ConfigurationMap.java 20 Sep 2004 09:37:07 -0000 1.3
@@ -25,7 +25,7 @@
* configuration-collection
* {@link org.apache.commons.configuration.Configuration}
* instance to provide a <code>Map</code> interface.</p>
- *
+ *
* @author <a href="mailto:ricardo.gladwell@btinternet.com">Ricardo Gladwell</a>
*/
public class ConfigurationMap extends AbstractMap {
@@ -46,12 +46,12 @@
this.configuration = configuration;
}
- /**
- * @see java.util.Map#entrySet()
- */
- public Set entrySet() {
- return new ConfigurationSet(configuration);
- }
+ /**
+ * @see java.util.Map#entrySet()
+ */
+ public Set entrySet() {
+ return new ConfigurationSet(configuration);
+ }
/**
* @see java.util.Map#put(java.lang.Object, java.lang.Object)
1.4 +3 -5 jakarta-commons/configuration/src/java/org/apache/commons/configuration/ConfigurationSet.java
Index: ConfigurationSet.java
===================================================================
RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/ConfigurationSet.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ConfigurationSet.java 12 Aug 2004 17:29:53 -0000 1.3
+++ ConfigurationSet.java 20 Sep 2004 09:37:07 -0000 1.4
@@ -26,12 +26,10 @@
*/
class ConfigurationSet extends AbstractSet {
-
class Entry implements Map.Entry {
Object key;
- Object value;
-
+
public Entry(Object key) {
this.key = key;
}
@@ -43,13 +41,13 @@
public Object getValue() {
return configuration.getProperty((String) key);
}
-
+
public Object setValue(Object value) {
Object old = getValue();
configuration.setProperty((String) key, value);
return old;
}
-
+
}
class ConfigurationSetIterator implements Iterator {
1.10 +9 -9 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.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- DatabaseConfiguration.java 20 Aug 2004 13:55:41 -0000 1.9
+++ DatabaseConfiguration.java 20 Sep 2004 09:37:07 -0000 1.10
@@ -73,7 +73,7 @@
* @param name the name of the configuration
*/
public DatabaseConfiguration(DataSource datasource, String table, String nameColumn,
- String keyColumn, String valueColumn, String name)
+ String keyColumn, String valueColumn, String name)
{
this.datasource = datasource;
this.table = table;
@@ -135,14 +135,14 @@
// build a list if there is more than one row in the resultset
if (rs.next())
{
- List results = new ArrayList();
- results.add(result);
- results.add(rs.getObject(valueColumn));
- while (rs.next())
+ List results = new ArrayList();
+ results.add(result);
+ results.add(rs.getObject(valueColumn));
+ while (rs.next())
{
- results.add(rs.getObject(valueColumn));
- }
- result = results;
+ results.add(rs.getObject(valueColumn));
+ }
+ result = results;
}
}
catch (SQLException e)
1.10 +5 -2 jakarta-commons/configuration/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java
Index: HierarchicalConfiguration.java
===================================================================
RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- HierarchicalConfiguration.java 5 Jul 2004 09:54:17 -0000 1.9
+++ HierarchicalConfiguration.java 20 Sep 2004 09:37:07 -0000 1.10
@@ -583,7 +583,10 @@
private Object value;
/** Stores the children of this node.*/
- private Map children;
+ private LinkedMap children; // Explict type here or we
+ // will get a findbugs error
+ // because Map doesn't imply
+ // Serializable
/**
* Creates a new instance of <code>Node</code>.
1.6 +6 -6 jakarta-commons/configuration/src/java/org/apache/commons/configuration/HierarchicalConfigurationConverter.java
Index: HierarchicalConfigurationConverter.java
===================================================================
RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/HierarchicalConfigurationConverter.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- HierarchicalConfigurationConverter.java 23 Aug 2004 08:06:22 -0000 1.5
+++ HierarchicalConfigurationConverter.java 20 Sep 2004 09:37:07 -0000 1.6
@@ -65,13 +65,13 @@
String key = (String) it.next();
if (keySet.contains(key))
{
- // this key has already been processed by openElements
- continue;
+ // this key has already been processed by openElements
+ continue;
}
ConfigurationKey keyAct = new ConfigurationKey(key);
closeElements(keyLast, keyAct);
String elem = openElements(keyLast, keyAct, config, keySet);
- fireValue(elem, config.getProperty(key));
+ fireValue(elem, config.getProperty(key));
keyLast = keyAct;
}
@@ -162,10 +162,10 @@
protected String openElements(ConfigurationKey keyLast, ConfigurationKey keyAct, Configuration config, Set keySet)
{
ConfigurationKey.KeyIterator it = keyLast.differenceKey(keyAct).iterator();
- ConfigurationKey k = keyLast.commonKey(keyAct);
+ ConfigurationKey k = keyLast.commonKey(keyAct);
for (it.nextKey(); it.hasNext(); it.nextKey())
{
- k.append(it.currentKey(true));
+ k.append(it.currentKey(true));
elementStart(it.currentKey(true), config.getProperty(k.toString()));
keySet.add(k.toString());
}
1.13 +37 -31 jakarta-commons/configuration/src/java/org/apache/commons/configuration/XMLConfiguration.java
Index: XMLConfiguration.java
===================================================================
RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/XMLConfiguration.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- XMLConfiguration.java 6 Sep 2004 11:40:34 -0000 1.12
+++ XMLConfiguration.java 20 Sep 2004 09:37:07 -0000 1.13
@@ -54,16 +54,16 @@
/**
* Reads a XML configuration file.
- *
+ *
* To retrieve the value of an attribute of an element, use
* <code>X.Y.Z[@attribute]</code>. The '@' symbol was chosen for consistency
* with XPath.
- *
+ *
* Setting property values will <b>NOT </b> automatically persist changes to
* disk, unless <code>autoSave=true</code>.
- *
+ *
* @since commons-configuration 1.0
- *
+ *
* @author J�rg Schaible
* @author <a href="mailto:kelvint@apache.org">Kelvin Tan </a>
* @author <a href="mailto:dlr@apache.org">Daniel Rall </a>
@@ -117,7 +117,7 @@
/**
* Attempts to load the XML file as a resource from the classpath. The XML
* file must be located somewhere in the classpath.
- *
+ *
* @param resource
* Name of the resource
* @throws ConfigurationException
@@ -130,7 +130,7 @@
/**
* Attempts to load the XML file.
- *
+ *
* @param file
* File object representing the XML file.
* @throws ConfigurationException
@@ -149,13 +149,19 @@
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
document = builder.parse(file);
} catch (IOException de) {
- throw new ConfigurationException("Could not load from " + file.getAbsolutePath(), de);
+ throw new ConfigurationException("Could not load from "
+ + ((file != null)
+ ? file.getAbsolutePath()
+ : "unknown file"), de);
} catch (ParserConfigurationException ex) {
throw new ConfigurationException("Could not configure parser", ex);
} catch (FactoryConfigurationError ex) {
throw new ConfigurationException("Could not create parser", ex);
} catch (SAXException ex) {
- throw new ConfigurationException("Error parsing file " + file.getAbsolutePath(), ex);
+ throw new ConfigurationException("Error parsing file "
+ + ((file != null)
+ ? file.getAbsolutePath()
+ : "unknown file"), ex);
}
initProperties(document.getDocumentElement(), new StringBuffer());
@@ -176,7 +182,7 @@
/**
* Loads and initializes from the XML file.
- *
+ *
* @param element
* The element to start processing from. Callers should supply
* the root element of the document.
@@ -209,7 +215,7 @@
/**
* Helper method for constructing properties for the attributes of the given
* XML element.
- *
+ *
* @param hierarchy
* the actual hierarchy
* @param element
@@ -228,7 +234,7 @@
/**
* Calls super method, and also ensures the underlying {@linkDocument} is
* modified so changes are persisted when saved.
- *
+ *
* @param name
* @param value
*/
@@ -281,7 +287,7 @@
/**
* TODO Add comment.
- *
+ *
* @param nodes
* @return
*/
@@ -342,7 +348,7 @@
/**
* Calls super method, and also ensures the underlying {@linkDocument} is
* modified so changes are persisted when saved.
- *
+ *
* @param name
* @param value
*/
@@ -354,7 +360,7 @@
/**
* Sets the property value in our document tree, auto-saving if appropriate.
- *
+ *
* @param name
* The name of the element to set a value for.
* @param value
@@ -405,7 +411,7 @@
/**
* Adds the property value in our document tree, auto-saving if appropriate.
- *
+ *
* @param name
* The name of the element to set a value for.
* @param value
@@ -442,7 +448,7 @@
/**
* Calls super method, and also ensures the underlying {@link Document}is
* modified so changes are persisted when saved.
- *
+ *
* @param name
* The name of the property to clear.
*/
@@ -519,7 +525,7 @@
/**
* If true, changes are automatically persisted.
- *
+ *
* @param autoSave
*/
public void setAutoSave(boolean autoSave) {
@@ -528,7 +534,7 @@
/**
* Save the configuration to the file specified by the fileName attribute.
- *
+ *
* @throws ConfigurationException
*/
public void save() throws ConfigurationException {
@@ -537,10 +543,10 @@
/**
* Save the configuration to a file.
- *
+ *
* @param filename
* the name of the xml file
- *
+ *
* @throws ConfigurationException
*/
public void save(String filename) throws ConfigurationException {
@@ -564,7 +570,7 @@
/**
* Save the configuration to the specified stream.
- *
+ *
* @param out
* the output stream used to save the configuration
*/
@@ -574,7 +580,7 @@
/**
* Save the configuration to the specified stream.
- *
+ *
* @param out
* the output stream used to save the configuration
* @param encoding
@@ -591,7 +597,7 @@
/**
* Save the configuration to the specified stream.
- *
+ *
* @param writer
* the output stream used to save the configuration
*/
@@ -610,7 +616,7 @@
/**
* Returns the file.
- *
+ *
* @return File
*/
public File getFile() {
@@ -619,7 +625,7 @@
/**
* Sets the file.
- *
+ *
* @param file
* The file to set
*/
@@ -633,7 +639,7 @@
/**
* Returns the fileName.
- *
+ *
* @return String
*/
public String getFileName() {
@@ -653,10 +659,10 @@
/**
* Parse a property key and return an array of the element hierarchy it
* specifies. For example the key "x.y.z[@abc]" will result in [x, y, z].
- *
+ *
* @param key
* the key to parse
- *
+ *
* @return the elements in the key
*/
protected static String[] parseElementNames(String key) {
@@ -677,10 +683,10 @@
/**
* Parse a property key and return the attribute name if it existst.
- *
+ *
* @param key
* the key to parse
- *
+ *
* @return the attribute name, or null if the key doesn't contain one
*/
protected static String parseAttributeName(String key) {
1.4 +36 -36 jakarta-commons/configuration/src/java/org/apache/commons/configuration/beanutils/ConfigurationDynaBean.java
Index: ConfigurationDynaBean.java
===================================================================
RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/beanutils/ConfigurationDynaBean.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ConfigurationDynaBean.java 6 Sep 2004 12:52:12 -0000 1.3
+++ ConfigurationDynaBean.java 20 Sep 2004 09:37:07 -0000 1.4
@@ -35,7 +35,7 @@
* instance. It also implements a {@link java.util.Map} interface
* so that it can be used in JSP 2.0 Expression Language
* expressions.</p>
- *
+ *
* <p>The <code>ConfigurationDynaBean</code> maps nested and mapped
* properties to the appropriate <code>Configuration</code> subset
* using the
@@ -44,7 +44,7 @@
* configuration properties using the
* {@link org.apache.commons.configuration.Configuration#getList(String)}
* method. Setting an indexed property always throws an exception.</p>
- *
+ *
* @author <a href="mailto:ricardo.gladwell@btinternet.com">Ricardo Gladwell</a>
*/
public class ConfigurationDynaBean extends ConfigurationMap implements DynaBean {
@@ -55,7 +55,7 @@
public ConfigurationDynaBean(Configuration configuration) {
super(configuration);
- if(log.isTraceEnabled()) log.trace("ConfigurationDynaBean("+configuration+")");
+ if (log.isTraceEnabled()) log.trace("ConfigurationDynaBean("+configuration+")");
this.configuration = configuration;
}
@@ -63,52 +63,52 @@
* @see org.apache.commons.beanutils.DynaBean#set(java.lang.String, java.lang.Object)
*/
public void set(String name, Object value) {
- if(log.isTraceEnabled()) log.trace("set("+name+","+value+")");
- if(value == null) throw new NullPointerException("Error trying to set property to null.");
- if(value instanceof List) {
+ if (log.isTraceEnabled()) log.trace("set("+name+","+value+")");
+ if (value == null) throw new NullPointerException("Error trying to set property to null.");
+ if (value instanceof List) {
List list = (List) value;
Iterator iterator = list.iterator();
while(iterator.hasNext())
configuration.addProperty(name,iterator.next());
- } else if(value instanceof int[]) {
+ } else if (value instanceof int[]) {
int[] array = (int[]) value;
- for(int i = 0; i < array.length; i++)
+ for (int i = 0; i < array.length; i++)
configuration.addProperty(name,new Integer(array[i]));
- } else if(value instanceof boolean[]) {
+ } else if (value instanceof boolean[]) {
boolean[] array = (boolean[]) value;
- for(int i = 0; i < array.length; i++)
+ for (int i = 0; i < array.length; i++)
configuration.addProperty(name,Boolean.valueOf(array[i]));
- } else if(value instanceof char[]) {
+ } else if (value instanceof char[]) {
char[] array = (char[]) value;
- for(int i = 0; i < array.length; i++)
+ for (int i = 0; i < array.length; i++)
configuration.addProperty(name,new Character(array[i]));
- } else if(value instanceof byte[]) {
+ } else if (value instanceof byte[]) {
byte[] array = (byte[]) value;
- for(int i = 0; i < array.length; i++)
+ for (int i = 0; i < array.length; i++)
configuration.addProperty(name,new Byte(array[i]));
- } else if(value instanceof short[]) {
+ } else if (value instanceof short[]) {
short[] array = (short[]) value;
- for(int i = 0; i < array.length; i++)
+ for (int i = 0; i < array.length; i++)
configuration.addProperty(name,new Short(array[i]));
- } else if(value instanceof int[]) {
+ } else if (value instanceof int[]) {
int[] array = (int[]) value;
- for(int i = 0; i < array.length; i++)
+ for (int i = 0; i < array.length; i++)
configuration.addProperty(name,new Integer(array[i]));
- } else if(value instanceof long[]) {
+ } else if (value instanceof long[]) {
long[] array = (long[]) value;
- for(int i = 0; i < array.length; i++)
+ for (int i = 0; i < array.length; i++)
configuration.addProperty(name,new Long(array[i]));
- } else if(value instanceof float[]) {
+ } else if (value instanceof float[]) {
float[] array = (float[]) value;
- for(int i = 0; i < array.length; i++)
+ for (int i = 0; i < array.length; i++)
configuration.addProperty(name,new Float(array[i]));
- } else if(value instanceof double[]) {
+ } else if (value instanceof double[]) {
double[] array = (double[]) value;
- for(int i = 0; i < array.length; i++)
+ for (int i = 0; i < array.length; i++)
configuration.addProperty(name, new Double(array[i]));
- } else if(value instanceof Object[]) {
+ } else if (value instanceof Object[]) {
Object[] array = (Object[]) value;
- for(int i = 0; i < array.length; i++)
+ for (int i = 0; i < array.length; i++)
configuration.addProperty(name,array[i]);
} else
configuration.setProperty(name, value);
@@ -118,17 +118,17 @@
* @see org.apache.commons.beanutils.DynaBean#get(java.lang.String)
*/
public Object get(String name) {
- if(log.isTraceEnabled()) log.trace("get("+name+")");
+ if (log.isTraceEnabled()) log.trace("get("+name+")");
// get configuration property
Object result = configuration.getProperty(name);
- if(result == null) {
+ if (result == null) {
// otherwise attempt to create bean from configuration subset
Configuration subset = configuration.subset(name);
- if(!subset.isEmpty())
+ if (!subset.isEmpty())
result = new ConfigurationDynaBean(configuration.subset(name));
}
- if(log.isDebugEnabled()) log.debug(name+"=["+result+"]");
- if(result == null)
+ if (log.isDebugEnabled()) log.debug(name+"=["+result+"]");
+ if (result == null)
throw new IllegalArgumentException
("Property '" + name +"' does not exist.");
return result;
@@ -139,7 +139,7 @@
*/
public boolean contains(String name, String key) {
Configuration subset = configuration.subset(name);
- if(subset == null)
+ if (subset == null)
throw new IllegalArgumentException
("Mapped property '" + name +"' does not exist.");
return subset.containsKey(key);
@@ -151,7 +151,7 @@
public Object get(String name, int index) {
try {
List list = configuration.getList(name);
- if(list.isEmpty())
+ if (list.isEmpty())
throw new IllegalArgumentException
("Indexed property '" + name +"' does not exist.");
return list.get(index);
@@ -165,7 +165,7 @@
*/
public Object get(String name, String key) {
Configuration subset = configuration.subset(name);
- if(subset == null)
+ if (subset == null)
throw new IllegalArgumentException
("Mapped property '" + name +"' does not exist.");
return subset.getProperty(key);
@@ -183,7 +183,7 @@
*/
public void remove(String name, String key) {
Configuration subset = configuration.subset(name);
- if(subset == null)
+ if (subset == null)
throw new IllegalArgumentException
("Mapped property '" + name +"' does not exist.");
subset.setProperty(key, null);
@@ -197,7 +197,7 @@
public void set(String name, int index, Object value) {
try {
List list = configuration.getList(name);
- if(list == null)
+ if (list == null)
throw new IllegalArgumentException
("Property '" + name +"' does not exist.");
list.set(index,value);
1.3 +11 -11 jakarta-commons/configuration/src/java/org/apache/commons/configuration/beanutils/ConfigurationDynaClass.java
Index: ConfigurationDynaClass.java
===================================================================
RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/beanutils/ConfigurationDynaClass.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ConfigurationDynaClass.java 12 Aug 2004 17:17:15 -0000 1.2
+++ ConfigurationDynaClass.java 20 Sep 2004 09:37:07 -0000 1.3
@@ -32,7 +32,7 @@
* configuration-collection
* {@link org.apache.commons.configuration.Configuration}
* instance.</p>
- *
+ *
* @author <a href="mailto:ricardo.gladwell@btinternet.com">Ricardo Gladwell</a>
*/
public class ConfigurationDynaClass implements DynaClass {
@@ -48,7 +48,7 @@
*/
public ConfigurationDynaClass(Configuration configuration) {
super();
- if(log.isTraceEnabled()) log.trace("ConfigurationDynaClass("+configuration+")");
+ if (log.isTraceEnabled()) log.trace("ConfigurationDynaClass("+configuration+")");
this.configuration = configuration;
}
@@ -56,20 +56,20 @@
* @see org.apache.commons.beanutils.DynaClass#getDynaProperty(java.lang.String)
*/
public DynaProperty getDynaProperty(String name) {
- if(log.isTraceEnabled()) log.trace("getDynaProperty("+name+")");
- if(name == null)
+ if (log.isTraceEnabled()) log.trace("getDynaProperty("+name+")");
+ if (name == null)
throw new IllegalArgumentException("No such property name=["+name+"]");
Object value = configuration.getProperty(name);
- if(value == null)
+ if (value == null)
return null;
else {
Class type = value.getClass();
- if(type == Byte.class) {
+ if (type == Byte.class) {
type = Byte.TYPE;
- } if(type == Character.class) {
+ } if (type == Character.class) {
type = Character.TYPE;
- } else if(type == Boolean.class) {
+ } else if (type == Boolean.class) {
type = Boolean.TYPE;
} else if (type == Double.class) {
type = Double.TYPE;
@@ -91,7 +91,7 @@
* @see org.apache.commons.beanutils.DynaClass#getDynaProperties()
*/
public DynaProperty[] getDynaProperties() {
- if(log.isTraceEnabled()) log.trace("getDynaProperties()");
+ if (log.isTraceEnabled()) log.trace("getDynaProperties()");
Iterator keys = configuration.getKeys();
ArrayList properties = new ArrayList();
while(keys.hasNext()) {
@@ -101,8 +101,8 @@
}
DynaProperty[] propertyArray = new DynaProperty[properties.size()];
properties.toArray(propertyArray);
- if(log.isDebugEnabled()) log.debug("Found "+properties.size()+" properties.");
- return propertyArray;
+ if (log.isDebugEnabled()) log.debug("Found "+properties.size()+" properties.");
+ return propertyArray;
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org