|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.taursys.model.PropertyAccessor
This is a helper class which provides access to value object properties. This class is constructed by with the class of the target value object and the name of the target property within the value object. As part of construction, introspection sets up the methods for reading and writing the property.
This class provides two primary methods, getPropertyValue and setPropertyValue which provide access to the property in the given value object. The valueObject passed to these methods must be the same class that was used to create this property accessor.
The readMethods or writeMethod may be null if the valueObject does not have a cooresponding get or set method. This method uses reflection and draws information from the valueObject's BeanInfo and PropertyDescriptors.
The property name should follow JavaBean naming conventions. If the property you want to access is in a nested class, then separate the property names by periods.
Example: propertyName="color": then it expects getColor and setColor will be the method names in the valueObject.
Example: propertyName="address.city": Assumes your value object contains an address property which in turn contains a city property. Accessing the property will result in a call: getAddress().getCity() or getAddress().setCity(...)
Constructor Summary | |
PropertyAccessor(java.lang.Class valueObjectClass,
java.lang.String propertyName)
|
Method Summary | |
int |
getJavaDateType()
Returns the JavaDataType of the property in the valueObject. |
protected java.beans.PropertyDescriptor |
getProperty(java.lang.Class c,
java.lang.String propName)
Searches the given class for the given property name and returns the PropertyDescriptor. |
java.lang.String |
getPropertyName()
Returns the name of the property to access in the valueObjectClass. |
java.lang.Object |
getPropertyValue(java.lang.Object valueObject)
Returns a property value from the valueObject based on the propertyName. |
protected java.lang.reflect.Method[] |
getReadMethods()
Returns the Methods used to get/read the target property. |
java.lang.Class |
getValueObjectClass()
Returns the class of the ValueObject(or parent ValueObject) where the value resides. |
protected java.lang.reflect.Method |
getWriteMethod()
Returns the Method used to get/read the target property. |
protected java.lang.Object |
invokeReadMethod(int i,
java.lang.Object target)
Invokes the i(th) read method on the given target and returns results. |
protected void |
invokeWriteMethod(java.lang.Object target,
java.lang.Object value)
Invokes the write method on the given target. |
protected boolean |
isPrimative()
Indicates that the property is a primative data type. |
protected void |
setAccessorMethods()
Sets the javaDataType, readMethods and writeMethod properties. |
void |
setPropertyValue(java.lang.Object valueObject,
java.lang.Object value)
Sets a property of the valueObject to the given value based on the propertyName. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public PropertyAccessor(java.lang.Class valueObjectClass, java.lang.String propertyName) throws ModelException
Method Detail |
protected void setAccessorMethods() throws ModelException
ModelException
- if valueObjectClass is null, propertyName is null/blank,
property not found in class, or an IntrospectionException occurs.protected java.beans.PropertyDescriptor getProperty(java.lang.Class c, java.lang.String propName) throws ModelPropertyAccessorException
ModelPropertyAccessorException
- if property is not found, or if an
IntrospectionException occurs.public java.lang.Object getPropertyValue(java.lang.Object valueObject) throws ModelException
ModelException
- if property has no read method defined or if an
IllegalAccessException or IllegalArgumentException occurs.
ModelInvocationTargetException
- if the invoked read method throws an
Exception.public void setPropertyValue(java.lang.Object valueObject, java.lang.Object value) throws ModelException
ModelException
- if property has no write method defined or if an
IllegalAccessException or IllegalArgumentException occurs.
ModelInvocationTargetException
- if the invoked read method throws an
Exception.protected java.lang.Object invokeReadMethod(int i, java.lang.Object target) throws ModelException
ModelException
- if property has no read method defined or if an
IllegalAccessException occurs.
ModelInvocationTargetException
- if the invoked read method throws an
Exception.protected void invokeWriteMethod(java.lang.Object target, java.lang.Object value) throws ModelException
ModelException
- if property has no write method defined or if an
IllegalAccessException or IllegalArgumentException occurs.
ModelInvocationTargetException
- if the invoked read method throws an
Exception.public int getJavaDateType()
public java.lang.String getPropertyName()
Example: propertyName="color": then it expects getColor and setColor will be the method names in the valueObject.
Example: propertyName="address.city": Assumes your value object contains an address property which in turn contains a city property. Accessing the property will result in a call: getAddress().getCity() or getAddress().setCity(...)
protected java.lang.reflect.Method[] getReadMethods()
protected java.lang.reflect.Method getWriteMethod()
public java.lang.Class getValueObjectClass()
protected boolean isPrimative()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |