public final class JavaBean
extends java.lang.Object
Given a bean and a Properties containing name-value pairs, where each name is a property name and each value is a String, the setProperties method will convert each string value into the target data type and invoke the corresponding set<Name> method.
Constructor and Description |
---|
JavaBean() |
Modifier and Type | Method and Description |
---|---|
static java.lang.Object |
convertType(java.lang.String value,
java.lang.Class target)
Convert the given String into the given type and return it as
an object.
|
static void |
dumpPublicFields(java.lang.Object o)
Dump the given object's public fields to System.out.
|
static void |
setProperties(java.lang.Object bean,
java.util.Properties properties)
Set the given beans properties from the given Properties.
|
public static void setProperties(java.lang.Object bean, java.util.Properties properties) throws java.beans.IntrospectionException, java.util.NoSuchElementException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
bean
- The bean to set properties on.properties
- The properties containing name-value pairs.java.beans.IntrospectionException
java.util.NoSuchElementException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
public static java.lang.Object convertType(java.lang.String value, java.lang.Class target) throws java.lang.IllegalArgumentException
Primitive types are converted to their object counterparts, which is appropriate for reflective method invocation since it will automatically unwrap them.
value
- The String value to convert.target
- The target type as a Class, such as Integer.class or
Integer.TYPE.java.lang.IllegalArgumentException
- If asked to convert to an unsupported
type.public static void dumpPublicFields(java.lang.Object o) throws java.lang.Exception
o
- The object to inspect.java.lang.Exception
Copyright ? 2002 Clarity Systems Group, LLC. All Rights Reserved.