org.sadun.util
Class ObjectPropertyManager

java.lang.Object
  extended byorg.sadun.util.ObjectPropertyManager
All Implemented Interfaces:
java.io.Serializable

public class ObjectPropertyManager
extends java.lang.Object
implements java.io.Serializable

This class allows to set and retrieve properties, by name, by any object using introspection and JavaBeans conventions.

In particular, it supports automatic value conversion from String denotation.

Author:
Cristiano Sadun
See Also:
Serialized Form

Nested Class Summary
static class ObjectPropertyManager.NoSuchPropertyException
          An exception thrown when the ObjectPropertyManager cannot find a property in a bean.
 
Constructor Summary
ObjectPropertyManager(java.lang.Object targetObject)
          Create an object manager which can set or get properties from the given target object
 
Method Summary
 java.lang.String describe()
          Describe the current object.
 java.lang.String describe(boolean recurse)
          Describe the current object.
 java.lang.String describe(int indent)
          Describe the current object.
 java.lang.String describe(int indent, boolean recurse)
          Describe the current object.
 boolean getBooleanProperty(java.lang.String name)
          Return the value of the property as a boolean, operating promotions when possible
 byte getByteProperty(java.lang.String name)
          Return the value of the property as a byte, operating promotions when possible
 char getCharProperty(java.lang.String name)
          Return the value of the property as a char
static java.lang.String getDescription(java.lang.Object obj, int indent, boolean recurse, boolean shortForm, boolean showType)
           
 double getDoubleProperty(java.lang.String name)
          Return the value of the property as a double, operating promotions when possible
 float getFloatProperty(java.lang.String name)
          Return the value of the property as a float, operating promotions when possible
 int getIntProperty(java.lang.String name)
          Return the value of the property as an integer, operating promotions when possible
 long getLongProperty(java.lang.String name)
          Return the value of the property as a long, operating promotions when possible
 java.lang.Object getProperty(java.lang.String name)
          Return the value of the given property on the wrapped targetObject.
 java.lang.String[] getPropertyNames()
          Return the names of the available read/write properties of the wrapped targetObject.
 java.lang.String[] getPropertyNames(boolean mustBeWritable, boolean mustBeReadable)
          Return the names of the available properties of the wrapped targetObject
 short getShortProperty(java.lang.String name)
          Return the value of the property as a short, operating promotions when possible
 java.lang.String getStringProperty(java.lang.String name)
          Return the value of the property as a String
 java.lang.Object getTargetObject()
          Return the managed object
 boolean isShortForm()
           
 boolean isShowType()
           
 void setProperties(java.util.Properties properties)
           
 void setProperty(java.lang.String name, boolean value)
          Set the given property with the given value on the wrapped targetObject.
 void setProperty(java.lang.String name, byte value)
          Set the given property with the given value on the wrapped targetObject.
 void setProperty(java.lang.String name, char value)
          Set the given property with the given value on the wrapped targetObject.
 void setProperty(java.lang.String name, double value)
          Set the given property with the given value on the wrapped targetObject.
 void setProperty(java.lang.String name, float value)
          Set the given property with the given value on the wrapped targetObject.
 void setProperty(java.lang.String name, int value)
          Set the given property with the given value on the wrapped targetObject.
 void setProperty(java.lang.String name, long value)
          Set the given property with the given value on the wrapped targetObject.
 void setProperty(java.lang.String name, java.lang.Object value)
          Set the given property with the given value on the wrapped targetObject.
 void setProperty(java.lang.String name, short value)
          Set the given property with the given value on the wrapped targetObject.
 void setShortForm(boolean shortForm)
           
 void setShowType(boolean showType)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectPropertyManager

public ObjectPropertyManager(java.lang.Object targetObject)
Create an object manager which can set or get properties from the given target object

Parameters:
targetObject - the managed object
Method Detail

setProperties

public void setProperties(java.util.Properties properties)
                   throws java.beans.IntrospectionException,
                          ObjectPropertyManager.NoSuchPropertyException
Throws:
java.beans.IntrospectionException
ObjectPropertyManager.NoSuchPropertyException

setProperty

public void setProperty(java.lang.String name,
                        byte value)
                 throws java.beans.IntrospectionException,
                        ObjectPropertyManager.NoSuchPropertyException
Set the given property with the given value on the wrapped targetObject.
The property must be exposed by following JavaBeans conventions.

Parameters:
name - the name of the property to set
value - the value of the property
Throws:
ObjectPropertyManager.NoSuchPropertyException
java.beans.IntrospectionException

setProperty

public void setProperty(java.lang.String name,
                        short value)
                 throws java.beans.IntrospectionException,
                        ObjectPropertyManager.NoSuchPropertyException
Set the given property with the given value on the wrapped targetObject.
The property must be exposed by following JavaBeans conventions.

Parameters:
name - the name of the property to set
value - the value of the property
Throws:
ObjectPropertyManager.NoSuchPropertyException
java.beans.IntrospectionException

setProperty

public void setProperty(java.lang.String name,
                        int value)
                 throws java.beans.IntrospectionException,
                        ObjectPropertyManager.NoSuchPropertyException
Set the given property with the given value on the wrapped targetObject.
The property must be exposed by following JavaBeans conventions.

Parameters:
name - the name of the property to set
value - the value of the property
Throws:
ObjectPropertyManager.NoSuchPropertyException
java.beans.IntrospectionException

setProperty

public void setProperty(java.lang.String name,
                        long value)
                 throws java.beans.IntrospectionException,
                        ObjectPropertyManager.NoSuchPropertyException
Set the given property with the given value on the wrapped targetObject.
The property must be exposed by following JavaBeans conventions.

Parameters:
name - the name of the property to set
value - the value of the property
Throws:
ObjectPropertyManager.NoSuchPropertyException
java.beans.IntrospectionException

setProperty

public void setProperty(java.lang.String name,
                        char value)
                 throws java.beans.IntrospectionException,
                        ObjectPropertyManager.NoSuchPropertyException
Set the given property with the given value on the wrapped targetObject.
The property must be exposed by following JavaBeans conventions.

Parameters:
name - the name of the property to set
value - the value of the property
Throws:
ObjectPropertyManager.NoSuchPropertyException
java.beans.IntrospectionException

setProperty

public void setProperty(java.lang.String name,
                        float value)
                 throws java.beans.IntrospectionException,
                        ObjectPropertyManager.NoSuchPropertyException
Set the given property with the given value on the wrapped targetObject.
The property must be exposed by following JavaBeans conventions.

Parameters:
name - the name of the property to set
value - the value of the property
Throws:
ObjectPropertyManager.NoSuchPropertyException
java.beans.IntrospectionException

setProperty

public void setProperty(java.lang.String name,
                        double value)
                 throws java.beans.IntrospectionException,
                        ObjectPropertyManager.NoSuchPropertyException
Set the given property with the given value on the wrapped targetObject.
The property must be exposed by following JavaBeans conventions.

Parameters:
name - the name of the property to set
value - the value of the property
Throws:
ObjectPropertyManager.NoSuchPropertyException
java.beans.IntrospectionException

setProperty

public void setProperty(java.lang.String name,
                        boolean value)
                 throws java.beans.IntrospectionException,
                        ObjectPropertyManager.NoSuchPropertyException
Set the given property with the given value on the wrapped targetObject.
The property must be exposed by following JavaBeans conventions.

Parameters:
name - the name of the property to set
value - the value of the property
Throws:
ObjectPropertyManager.NoSuchPropertyException
java.beans.IntrospectionException

setProperty

public void setProperty(java.lang.String name,
                        java.lang.Object value)
                 throws java.beans.IntrospectionException,
                        ObjectPropertyManager.NoSuchPropertyException
Set the given property with the given value on the wrapped targetObject.
The property must be exposed by following JavaBeans conventions.

Parameters:
name - the name of the property to set
value - the value of the property
Throws:
ObjectPropertyManager.NoSuchPropertyException
java.beans.IntrospectionException

getProperty

public java.lang.Object getProperty(java.lang.String name)
                             throws java.beans.IntrospectionException,
                                    ObjectPropertyManager.NoSuchPropertyException
Return the value of the given property on the wrapped targetObject.
The property must be exposed by following JavaBeans conventions.

Parameters:
name - the name of the property to get
Throws:
ObjectPropertyManager.NoSuchPropertyException
java.beans.IntrospectionException

getPropertyNames

public java.lang.String[] getPropertyNames(boolean mustBeWritable,
                                           boolean mustBeReadable)
                                    throws java.beans.IntrospectionException
Return the names of the available properties of the wrapped targetObject

Parameters:
mustBeReadable - excludes properties which have no read method
mustBeWritable - excludes properties which have no write method
Returns:
the array of property names exposed by the targetObject
Throws:
java.beans.IntrospectionException

getPropertyNames

public java.lang.String[] getPropertyNames()
                                    throws java.beans.IntrospectionException
Return the names of the available read/write properties of the wrapped targetObject.

Returns:
the names of the available read/write properties of the wrapped targetObject.
Throws:
java.beans.IntrospectionException

getBooleanProperty

public boolean getBooleanProperty(java.lang.String name)
                           throws java.beans.IntrospectionException,
                                  ObjectPropertyManager.NoSuchPropertyException
Return the value of the property as a boolean, operating promotions when possible

Returns:
Throws:
ObjectPropertyManager.NoSuchPropertyException
java.beans.IntrospectionException

getByteProperty

public byte getByteProperty(java.lang.String name)
                     throws java.beans.IntrospectionException,
                            ObjectPropertyManager.NoSuchPropertyException
Return the value of the property as a byte, operating promotions when possible

Returns:
Throws:
ObjectPropertyManager.NoSuchPropertyException
java.beans.IntrospectionException

getShortProperty

public short getShortProperty(java.lang.String name)
                       throws java.beans.IntrospectionException,
                              ObjectPropertyManager.NoSuchPropertyException
Return the value of the property as a short, operating promotions when possible

Returns:
Throws:
ObjectPropertyManager.NoSuchPropertyException
java.beans.IntrospectionException

getIntProperty

public int getIntProperty(java.lang.String name)
                   throws java.beans.IntrospectionException,
                          ObjectPropertyManager.NoSuchPropertyException
Return the value of the property as an integer, operating promotions when possible

Returns:
Throws:
ObjectPropertyManager.NoSuchPropertyException
java.beans.IntrospectionException

getLongProperty

public long getLongProperty(java.lang.String name)
                     throws java.beans.IntrospectionException,
                            ObjectPropertyManager.NoSuchPropertyException
Return the value of the property as a long, operating promotions when possible

Returns:
Throws:
ObjectPropertyManager.NoSuchPropertyException
java.beans.IntrospectionException

getFloatProperty

public float getFloatProperty(java.lang.String name)
                       throws java.beans.IntrospectionException,
                              ObjectPropertyManager.NoSuchPropertyException
Return the value of the property as a float, operating promotions when possible

Returns:
Throws:
ObjectPropertyManager.NoSuchPropertyException
java.beans.IntrospectionException

getDoubleProperty

public double getDoubleProperty(java.lang.String name)
                         throws java.beans.IntrospectionException,
                                ObjectPropertyManager.NoSuchPropertyException
Return the value of the property as a double, operating promotions when possible

Returns:
Throws:
ObjectPropertyManager.NoSuchPropertyException
java.beans.IntrospectionException

getStringProperty

public java.lang.String getStringProperty(java.lang.String name)
                                   throws java.beans.IntrospectionException,
                                          ObjectPropertyManager.NoSuchPropertyException
Return the value of the property as a String

Returns:
Throws:
ObjectPropertyManager.NoSuchPropertyException
java.beans.IntrospectionException

getCharProperty

public char getCharProperty(java.lang.String name)
                     throws java.beans.IntrospectionException,
                            ObjectPropertyManager.NoSuchPropertyException
Return the value of the property as a char

Returns:
Throws:
ObjectPropertyManager.NoSuchPropertyException
java.beans.IntrospectionException

getTargetObject

public java.lang.Object getTargetObject()
Return the managed object

Returns:
the managed object

describe

public java.lang.String describe()
                          throws java.beans.IntrospectionException
Describe the current object.

Returns:
aq description of the object
Throws:
java.beans.IntrospectionException - if introspection fails

describe

public java.lang.String describe(boolean recurse)
                          throws java.beans.IntrospectionException
Describe the current object.

Parameters:
recurse - if true, member objects will be described as well
Returns:
aq description of the object
Throws:
java.beans.IntrospectionException - if introspection fails

describe

public java.lang.String describe(int indent)
                          throws java.beans.IntrospectionException
Describe the current object.

Parameters:
indent - the indentation of the description
Returns:
aq description of the object
Throws:
java.beans.IntrospectionException - if introspection fails

describe

public java.lang.String describe(int indent,
                                 boolean recurse)
                          throws java.beans.IntrospectionException
Describe the current object.

Parameters:
indent - the indentation of the description
recurse - if true, member objects will be described as well
Returns:
aq description of the object
Throws:
java.beans.IntrospectionException - if introspection fails

isShortForm

public boolean isShortForm()

setShortForm

public void setShortForm(boolean shortForm)

isShowType

public boolean isShowType()

setShowType

public void setShowType(boolean showType)

getDescription

public static java.lang.String getDescription(java.lang.Object obj,
                                              int indent,
                                              boolean recurse,
                                              boolean shortForm,
                                              boolean showType)
                                       throws java.beans.IntrospectionException
Returns:
Throws:
java.beans.IntrospectionException