ebourg 2004/09/21 10:49:39
Modified: configuration/src/java/org/apache/commons/configuration/beanutils
ConfigurationDynaBean.java
ConfigurationDynaClass.java
Log:
Code formating
Revision Changes Path
1.6 +164 -74
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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ConfigurationDynaBean.java 20 Sep 2004 15:55:08 -0000 1.5
+++ ConfigurationDynaBean.java 21 Sep 2004 17:49:39 -0000 1.6
@@ -27,187 +27,277 @@
import org.apache.commons.logging.LogFactory;
/**
- * <p>The <tt>ConfigurationDynaBean</tt> dynamically reads and
- * writes configurations properties from a wrapped
- * configuration-collection
- * [EMAIL PROTECTED] org.apache.commons.configuration.Configuration}
- * instance. It also implements a [EMAIL PROTECTED] java.util.Map} interface
- * so that it can be used in JSP 2.0 Expression Language
- * expressions.</p>
+ * The <tt>ConfigurationDynaBean</tt> dynamically reads and writes
+ * configurations properties from a wrapped configuration-collection
+ * [EMAIL PROTECTED] org.apache.commons.configuration.Configuration} instance. It
also
+ * implements a [EMAIL PROTECTED] java.util.Map} interface so that it can be used in
+ * JSP 2.0 Expression Language expressions.
*
- * <p>The <code>ConfigurationDynaBean</code> maps nested and mapped
- * properties to the appropriate <code>Configuration</code> subset
- * using the
+ * <p>The <code>ConfigurationDynaBean</code> maps nested and mapped properties
+ * to the appropriate <code>Configuration</code> subset using the
* [EMAIL PROTECTED] org.apache.commons.configuration.Configuration#subset}
- * method. Similarly, indexed properties reference lists of
- * configuration properties using the
+ * method. Similarly, indexed properties reference lists of configuration
+ * properties using the
* [EMAIL PROTECTED] org.apache.commons.configuration.Configuration#getList(String)}
* method. Setting an indexed property always throws an exception.</p>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Ricardo Gladwell</a>
+ * @version $Revision$, $Date$
+ * @since 1.0-rc1
*/
-public class ConfigurationDynaBean implements DynaBean {
-
+public class ConfigurationDynaBean implements DynaBean
+{
private final static Log log = LogFactory.getLog(ConfigurationDynaBean.class);
Configuration configuration;
- public ConfigurationDynaBean(Configuration configuration) {
- if(log.isTraceEnabled())
log.trace("ConfigurationDynaBean("+configuration+")");
+ public ConfigurationDynaBean(Configuration configuration)
+ {
+ if (log.isTraceEnabled()) log.trace("ConfigurationDynaBean(" +
configuration + ")");
this.configuration = configuration;
}
/**
* @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) {
+ 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)
+ {
List list = (List) value;
Iterator iterator = list.iterator();
- while(iterator.hasNext())
- configuration.addProperty(name,iterator.next());
- } else if (value instanceof int[]) {
+ while (iterator.hasNext())
+ {
+ configuration.addProperty(name, iterator.next());
+ }
+ }
+ else if (value instanceof int[])
+ {
int[] array = (int[]) value;
for (int i = 0; i < array.length; i++)
- configuration.addProperty(name,new Integer(array[i]));
- } else if (value instanceof boolean[]) {
+ {
+ configuration.addProperty(name, new Integer(array[i]));
+ }
+ }
+ else if (value instanceof boolean[])
+ {
boolean[] array = (boolean[]) value;
for (int i = 0; i < array.length; i++)
- configuration.addProperty(name,Boolean.valueOf(array[i]));
- } else if (value instanceof char[]) {
+ {
+ configuration.addProperty(name, Boolean.valueOf(array[i]));
+ }
+ }
+ else if (value instanceof char[])
+ {
char[] array = (char[]) value;
for (int i = 0; i < array.length; i++)
- configuration.addProperty(name,new Character(array[i]));
- } else if (value instanceof byte[]) {
+ {
+ configuration.addProperty(name, new Character(array[i]));
+ }
+ }
+ else if (value instanceof byte[])
+ {
byte[] array = (byte[]) value;
for (int i = 0; i < array.length; i++)
- configuration.addProperty(name,new Byte(array[i]));
- } else if (value instanceof short[]) {
+ {
+ configuration.addProperty(name, new Byte(array[i]));
+ }
+ }
+ else if (value instanceof short[])
+ {
short[] array = (short[]) value;
for (int i = 0; i < array.length; i++)
- configuration.addProperty(name,new Short(array[i]));
- } else if (value instanceof int[]) {
+ {
+ configuration.addProperty(name, new Short(array[i]));
+ }
+ }
+ else if (value instanceof int[])
+ {
int[] array = (int[]) value;
for (int i = 0; i < array.length; i++)
- configuration.addProperty(name,new Integer(array[i]));
- } else if (value instanceof long[]) {
+ {
+ configuration.addProperty(name, new Integer(array[i]));
+ }
+ }
+ else if (value instanceof long[])
+ {
long[] array = (long[]) value;
for (int i = 0; i < array.length; i++)
- configuration.addProperty(name,new Long(array[i]));
- } else if (value instanceof float[]) {
+ {
+ configuration.addProperty(name, new Long(array[i]));
+ }
+ }
+ else if (value instanceof float[])
+ {
float[] array = (float[]) value;
for (int i = 0; i < array.length; i++)
- configuration.addProperty(name,new Float(array[i]));
- } else if (value instanceof double[]) {
+ {
+ configuration.addProperty(name, new Float(array[i]));
+ }
+ }
+ else if (value instanceof double[])
+ {
double[] array = (double[]) value;
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++)
- configuration.addProperty(name,array[i]);
- } else
+ {
+ configuration.addProperty(name, array[i]);
+ }
+ }
+ else
+ {
configuration.setProperty(name, value);
+ }
}
/**
* @see org.apache.commons.beanutils.DynaBean#get(java.lang.String)
*/
- public Object get(String name) {
- if (log.isTraceEnabled()) log.trace("get("+name+")");
+ public Object get(String 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())
+ {
result = new ConfigurationDynaBean(configuration.subset(name));
+ }
+ }
+
+ if (log.isDebugEnabled())
+ {
+ log.debug(name + "=[" + result + "]");
}
- if (log.isDebugEnabled()) log.debug(name+"=["+result+"]");
+
if (result == null)
- throw new IllegalArgumentException
- ("Property '" + name +"' does not exist.");
+ {
+ throw new IllegalArgumentException("Property '" + name + "' does not
exist.");
+ }
return result;
}
/**
* @see org.apache.commons.beanutils.DynaBean#contains(java.lang.String,
java.lang.String)
*/
- public boolean contains(String name, String key) {
+ public boolean contains(String name, String key)
+ {
Configuration subset = configuration.subset(name);
if (subset == null)
- throw new IllegalArgumentException
- ("Mapped property '" + name +"' does not exist.");
+ {
+ throw new IllegalArgumentException("Mapped property '" + name + "' does
not exist.");
+ }
+
return subset.containsKey(key);
}
/**
* @see org.apache.commons.beanutils.DynaBean#get(java.lang.String, int)
*/
- public Object get(String name, int index) {
- try {
+ public Object get(String name, int index)
+ {
+ try
+ {
List list = configuration.getList(name);
if (list.isEmpty())
- throw new IllegalArgumentException
- ("Indexed property '" + name +"' does not exist.");
+ {
+ throw new IllegalArgumentException("Indexed property '" + name + "'
does not exist.");
+ }
+
return list.get(index);
- } catch(ConversionException e) {
- throw new IllegalArgumentException("Property '" + name +"' is not
indexed.");
+ }
+ catch (ConversionException e)
+ {
+ throw new IllegalArgumentException("Property '" + name + "' is not
indexed.");
}
}
/**
* @see org.apache.commons.beanutils.DynaBean#get(java.lang.String,
java.lang.String)
*/
- public Object get(String name, String key) {
+ public Object get(String name, String key)
+ {
Configuration subset = configuration.subset(name);
if (subset == null)
- throw new IllegalArgumentException
- ("Mapped property '" + name +"' does not exist.");
+ {
+ throw new IllegalArgumentException("Mapped property '" + name + "' does
not exist.");
+ }
+
return subset.getProperty(key);
}
/**
* @see org.apache.commons.beanutils.DynaBean#getDynaClass()
*/
- public DynaClass getDynaClass() {
+ public DynaClass getDynaClass()
+ {
return new ConfigurationDynaClass(configuration);
}
/**
* @see org.apache.commons.beanutils.DynaBean#remove(java.lang.String,
java.lang.String)
*/
- public void remove(String name, String key) {
+ public void remove(String name, String key)
+ {
Configuration subset = configuration.subset(name);
if (subset == null)
- throw new IllegalArgumentException
- ("Mapped property '" + name +"' does not exist.");
+ {
+ throw new IllegalArgumentException("Mapped property '" + name + "' does
not exist.");
+ }
subset.setProperty(key, null);
}
/**
* @see org.apache.commons.beanutils.DynaBean#set(java.lang.String, int,
java.lang.Object)
*/
- public void set(String name, int index, Object value) {
- try {
+ public void set(String name, int index, Object value)
+ {
+ try
+ {
List list = configuration.getList(name);
if (list == null)
- throw new IllegalArgumentException
- ("Property '" + name +"' does not exist.");
- list.set(index,value);
- } catch(ConversionException e) {
- throw new IllegalArgumentException
- ("Property '" + name +"' is not indexed.");
+ {
+ throw new IllegalArgumentException("Property '" + name + "' does
not exist.");
+ }
+
+ list.set(index, value);
+ }
+ catch (ConversionException e)
+ {
+ throw new IllegalArgumentException("Property '" + name + "' is not
indexed.");
}
}
/**
* @see org.apache.commons.beanutils.DynaBean#set(java.lang.String,
java.lang.String, java.lang.Object)
*/
- public void set(String name, String key, Object value) {
- configuration.setProperty(name+"."+key, value);
+ public void set(String name, String key, Object value)
+ {
+ configuration.setProperty(name + "." + key, value);
}
}
1.4 +81 -40
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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ConfigurationDynaClass.java 20 Sep 2004 09:37:07 -0000 1.3
+++ ConfigurationDynaClass.java 21 Sep 2004 17:49:39 -0000 1.4
@@ -18,6 +18,7 @@
import java.util.Iterator;
import java.util.ArrayList;
+import java.util.List;
import org.apache.commons.beanutils.DynaBean;
import org.apache.commons.beanutils.DynaClass;
@@ -27,16 +28,16 @@
import org.apache.commons.logging.LogFactory;
/**
- * <p>The <tt>ConfigurationDynaClass</tt> dynamically determines
- * properties for a <code>ConfigurationDynaBean</code> from a wrapped
- * configuration-collection
- * [EMAIL PROTECTED] org.apache.commons.configuration.Configuration}
- * instance.</p>
+ * The <tt>ConfigurationDynaClass</tt> dynamically determines properties for
+ * a <code>ConfigurationDynaBean</code> from a wrapped configuration-collection
+ * [EMAIL PROTECTED] org.apache.commons.configuration.Configuration} instance.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Ricardo Gladwell</a>
+ * @version $Revision$, $Date$
+ * @since 1.0-rc1
*/
-public class ConfigurationDynaClass implements DynaClass {
-
+public class ConfigurationDynaClass implements DynaClass
+{
private final static Log log = LogFactory.getLog(ConfigurationDynaClass.class);
Configuration configuration;
@@ -46,77 +47,117 @@
* wrapping the specified <code>Configuration</code> instance.
* @param configuration <code>Configuration</code> instance.
*/
- public ConfigurationDynaClass(Configuration configuration) {
+ public ConfigurationDynaClass(Configuration configuration)
+ {
super();
- if (log.isTraceEnabled())
log.trace("ConfigurationDynaClass("+configuration+")");
+ if (log.isTraceEnabled()) log.trace("ConfigurationDynaClass(" +
configuration + ")");
this.configuration = configuration;
}
/**
* @see org.apache.commons.beanutils.DynaClass#getDynaProperty(java.lang.String)
*/
- public DynaProperty getDynaProperty(String name) {
- if (log.isTraceEnabled()) log.trace("getDynaProperty("+name+")");
+ public DynaProperty getDynaProperty(String name)
+ {
+ if (log.isTraceEnabled())
+ {
+ log.trace("getDynaProperty(" + name + ")");
+ }
+
if (name == null)
- throw new IllegalArgumentException("No such property name=["+name+"]");
+ {
+ throw new IllegalArgumentException("No such property name=[" + name +
"]");
+ }
+
Object value = configuration.getProperty(name);
if (value == null)
+ {
return null;
- else {
+ }
+ 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) {
+ }
+ else if (type == Double.class)
+ {
type = Double.TYPE;
- } else if (type == Float.class) {
+ }
+ else if (type == Float.class)
+ {
type = Float.TYPE;
- } else if (type == Integer.class) {
+ }
+ else if (type == Integer.class)
+ {
type = Integer.TYPE;
- } else if (type == Long.class) {
+ }
+ else if (type == Long.class)
+ {
type = Long.TYPE;
- } else if (type == Short.class) {
+ }
+ else if (type == Short.class)
+ {
type = Short.TYPE;
}
- return new DynaProperty(name,type);
+ return new DynaProperty(name, type);
}
}
/**
* @see org.apache.commons.beanutils.DynaClass#getDynaProperties()
*/
- public DynaProperty[] getDynaProperties() {
- if (log.isTraceEnabled()) log.trace("getDynaProperties()");
+ public DynaProperty[] getDynaProperties()
+ {
+ if (log.isTraceEnabled())
+ {
+ log.trace("getDynaProperties()");
+ }
+
Iterator keys = configuration.getKeys();
- ArrayList properties = new ArrayList();
- while(keys.hasNext()) {
+ List properties = new ArrayList();
+ while (keys.hasNext())
+ {
String key = (String) keys.next();
DynaProperty property = getDynaProperty(key);
properties.add(property);
}
+
DynaProperty[] propertyArray = new DynaProperty[properties.size()];
properties.toArray(propertyArray);
- if (log.isDebugEnabled()) log.debug("Found "+properties.size()+"
properties.");
+ if (log.isDebugEnabled())
+ {
+ log.debug("Found " + properties.size() + " properties.");
+ }
+
return propertyArray;
}
- /**
- * @see org.apache.commons.beanutils.DynaClass#getName()
- */
- public String getName() {
- return ConfigurationDynaBean.class.getName();
- }
-
- /**
- * @see org.apache.commons.beanutils.DynaClass#newInstance()
- */
- public DynaBean newInstance() throws IllegalAccessException,
InstantiationException {
- return new ConfigurationDynaBean(configuration);
- }
+ /**
+ * @see org.apache.commons.beanutils.DynaClass#getName()
+ */
+ public String getName()
+ {
+ return ConfigurationDynaBean.class.getName();
+ }
+
+ /**
+ * @see org.apache.commons.beanutils.DynaClass#newInstance()
+ */
+ public DynaBean newInstance() throws IllegalAccessException,
InstantiationException
+ {
+ return new ConfigurationDynaBean(configuration);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]