|
Framework Professional Edition Package |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.prosyst.util.beans.Introspector
public class Introspector
The Introspector is much more advanced tool comparing to BeanUtils that supports transparent type conversion and deep, nested or even indexed properties.
Even if you don't use nested properties, it is much simpler to use
Introspector.getInstance().setProperty(key, value, bean);instead of
BeanProperty bp = BeanUtils.getBeanProperty(key, beanClass);
if (bp != null) {
Method m = bp.getWriteMethod();
if (m != null) {
m.invoke(bean, new Object[] {
value
});
}
}
This tool will also allow you to use properties like car.color.red
and car.door[5].open. This, along with the build in
conversion from String to Simple Type, makes this class a valuable tool for
web developers.
| Method Summary | |
|---|---|
static java.lang.Object |
convert(java.lang.Object fromValue,
java.lang.Class toType)
This is an utility method which is very useful for converting simple types. |
static java.lang.Long |
decodeLong(java.lang.String nm)
|
static Introspector |
getInstance()
This method return a singleton. |
static java.lang.Class |
getPrimitiveWrapperClass(java.lang.Class type)
This method looks for the wrapper class of the primitive object. |
java.lang.Object |
getProperty(java.lang.String key,
java.lang.Object bean)
This method returns the value of and bean property. |
void |
setProperty(java.lang.String key,
java.lang.Object value,
java.lang.Object bean)
Sets a property of the bean to the specified value. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static Introspector getInstance()
public void setProperty(java.lang.String key,
java.lang.Object value,
java.lang.Object bean)
throws java.lang.IllegalArgumentException,
java.lang.IllegalAccessException,
java.lang.reflect.InvocationTargetException,
BeanException
When the key is car.manufacturer.url this method will
execute the following sequence
bean.getCar().getManufacturer().setUrl(value);
You can also specify an index: car.doors[3].open which will
be usually interpreted to getCar().getDoors(3).setOpen(value).
In addition, if you didn't declared method getDoors(index)
but you have getDoors() that returns an array or Vector
the previous example will be interpreted to:
getCar().getDoors()[3].setOpen(value) or getCar().getDoors().elementAt(3).setOpen(value)
respectively for array or Vector
key - the name of the propertyvalue - the value which will be setbean - the target
java.lang.IllegalArgumentException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
BeanExceptionMethod.invoke(java.lang.Object, java.lang.Object[])
public java.lang.Object getProperty(java.lang.String key,
java.lang.Object bean)
throws java.lang.IllegalArgumentException,
java.lang.IllegalAccessException,
java.lang.reflect.InvocationTargetException,
BeanException
setProperty method this one allows deep, property search
and indexed values.
key - the name of the property to readbean - the source
null if it cannot be
read
java.lang.IllegalArgumentException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
BeanExceptionsetProperty(String, Object, Object)
public static java.lang.Object convert(java.lang.Object fromValue,
java.lang.Class toType)
Additionally if the toType is java.lang.Number it converts
the value to Integer.
If the fromValue is array and toType class equals the array elements type, this method will return the first element in the array.
fromValue - the value that is going to be convertedtoType - the desired type
public static java.lang.Long decodeLong(java.lang.String nm)
throws java.lang.NumberFormatException
java.lang.NumberFormatExceptionpublic static java.lang.Class getPrimitiveWrapperClass(java.lang.Class type)
type parameter
type - the type of the (primitive) class
type
|
Framework Professional Edition Package |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||