com.claritysys.util
Class JavaBean

java.lang.Object
  extended by com.claritysys.util.JavaBean

public final class JavaBean
extends java.lang.Object

Provides methods for setting bean properties using reflection.

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.

Version:
$Revision: 2348 $ $Date: 2004-12-01 16:12:21 -0800 (Wed, 01 Dec 2004) $

Constructor Summary
JavaBean()
           
 
Method Summary
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JavaBean

public JavaBean()
Method Detail

setProperties

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
Set the given beans properties from the given Properties.

Parameters:
bean - The bean to set properties on.
properties - The properties containing name-value pairs.
Throws:
java.beans.IntrospectionException
java.util.NoSuchElementException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

convertType

public static java.lang.Object convertType(java.lang.String value,
                                           java.lang.Class target)
                                    throws java.lang.IllegalArgumentException
Convert the given String into the given type and return it as an object.

Primitive types are converted to their object counterparts, which is appropriate for reflective method invocation since it will automatically unwrap them.

Parameters:
value - The String value to convert.
target - The target type as a Class, such as Integer.class or Integer.TYPE.
Returns:
The converted String.
Throws:
java.lang.IllegalArgumentException - If asked to convert to an unsupported type.

dumpPublicFields

public static void dumpPublicFields(java.lang.Object o)
                             throws java.lang.Exception
Dump the given object's public fields to System.out.

Parameters:
o - The object to inspect.
Throws:
java.lang.Exception


Copyright ? 2002 Clarity Systems Group, LLC. All Rights Reserved.