|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.jbeans.JavaBean
This class can be used to facilitate getting and setting of JavaBean properties. It is an object representation of a JavaBean and allows the developer to add new properties, get property values and set property values. This class also models indexed and nested JavaBeans properties as well as nested JavaBeans themselves.
Nested JavaBeans are when a JavaBean property is another JavaBean. In normal Java code, retrieval would look something like:
bean1.getProperty().getProperty2()...getPropertyN().
The bean1 instance is the base JavaBean for this example. Within this JavaBean there is a property named property1, whose return type is another JavaBean. This is repeated until a leaf property is hit. Leaf properties return object instances that do not contain any JavaBean properties. Although all leaf properties do not meet this requirement a property that does is automatically a leaf property.
A property might return an instance of an object that does contain JavaBean properties, but in the context of a particular application, these are not accessed using the JBeans package or through reflection. These properties are also considered leaf properties.
Using this class these properties can be retrieved using the standard JavaBean notation of property.property2...propertyN (for the example above)
It should also be noted that the properties already accessed or added are stored so that continued access is quicker than using the NestedBeanProperty class. This also means that this class will only store the information about the properties and nested JavaBeans requested. It does NOT build a complete list of the properties and nested JavaBeans of a particular class at any time. It is not recommended that this class be heavily used because of the space usage of storing all the properties and nested JavaBeans. If it the local and nested properties are relatively few, then this class can offer speed benefits. If not, this class is not a good solution because of its memory consumption.
NOTE:
When this class creates new JavaBean instances for nested properties, the
new instances have the same value for the strict property as the parent
JavaBean instance.
Field Summary | |
protected Class |
beanClass
|
protected Map |
children
|
protected Map |
properties
|
protected boolean |
strict
|
Constructor Summary | |
JavaBean(Class beanClass)
Creates new JavaBean using the given bean class object and with strict set to false. |
|
JavaBean(Class beanClass,
boolean strict)
Creates new JavaBean using the given bean class object and the given strict value. |
|
JavaBean(String beanClass)
Creates new JavaBean using the given fully qualified name of the bean class object and with strict set to false. |
|
JavaBean(String beanClass,
boolean strict)
Creates new JavaBean using the given fully qualified name of the bean class object and the given strict value. |
Method Summary | |
void |
addProperty(String propertyName)
Adds the given property to this JavaBean object. |
void |
checkBeanProperty(String propertyName,
Class type)
Checks if the given bean property is a valid bean property for this JavaBean or a child JavaBean. |
Class |
getBeanClass()
Gets the bean class that this JavaBean is for |
BeanProperty |
getBeanProperty(String propertyName)
Returns the bean property described by the propertyName String parameter. |
JavaBean |
getChildJavaBean(String propertyName)
Returns the child JavaBean described by the propertyName String parameter. |
IndexedBeanProperty |
getIndexedBeanProperty(String propertyName)
Returns the indexed bean property described by the propertyName String parameter. |
Object |
getPropertyValue(String propertyName,
Object bean)
Retrieves the local or nested bean property using the property name, the bean object (which will be used to retrieve and/or store child objects). |
Object |
getPropertyValue(String propertyName,
Object bean,
int[] indices)
Retrieves the local or nested bean property using the property name, the bean object (which will be used to retrieve and/or store child objects) and the list of indices which will be used for any indexed properties. |
Object |
getPropertyValue(String propertyName,
Object bean,
List indices)
Retrieves the local or nested bean property using the property name, the bean object (which will be used to retrieve and/or store child objects) and the list of indices which will be used for any indexed properties. |
Object |
instantiate()
Returns a new instance of the Java bean class that this JavaBean instance was cosntructed for. |
boolean |
isBeanPropertyIndexed(String propertyName)
Returns whether or not the property described by the propertyName String parameter is an indexed bean property or not. |
boolean |
isStrict()
Retrieves the value of the strict property |
void |
setPropertyValue(String propertyName,
Object bean,
int[] indices,
Object value,
boolean convert)
Sets the local or nested property using the property name, the bean object (which will be used to retrieve and/or store the child objects if this is a nested property), the array of indices for any indexed properties, the value with which to set the property, the convert flag to determine whether or not to convert the value to the appropriate type before setting. |
void |
setPropertyValue(String propertyName,
Object bean,
List indices,
Object value,
boolean convert)
Sets the local or nested property using the property name, the bean object (which will be used to retrieve and/or store the child objects if this is a nested property), the list of indices for any indexed properties, the value with which to set the property, the convert flag to determine whether or not to convert the value to the appropriate type before setting. |
void |
setPropertyValue(String propertyName,
Object bean,
Object value)
Sets the local or nested property to the given value on the given bean instance. |
void |
setPropertyValue(String propertyName,
Object bean,
Object value,
boolean convert)
Sets the local or nested property using the property name, the bean object (which will be used to retrieve and/or store the child objects if this is a nested property), the value with which to set the property, the convert flag to determine whether or not to convert the value to the appropriate type before setting. |
void |
setStrict(boolean value)
Sets the value of the strict property for this JavaBean only. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected Class beanClass
protected Map properties
protected Map children
protected boolean strict
Constructor Detail |
public JavaBean(Class beanClass)
beanClass
- The Class object used to find the properties and nested
JavaBeanspublic JavaBean(String beanClass) throws BeanException
beanClass
- The fully qualified name of the bean class used to find
properties and nested JavaBeansBeanException
- If the class name is not a valid class in the classpathpublic JavaBean(Class beanClass, boolean strict)
beanClass
- The Class object used to find the properties and nested
JavaBeansstrict
- Determines how this class handles cases when setting and
retrieving property values and a child bean is nullpublic JavaBean(String beanClass, boolean strict) throws BeanException
beanClass
- The fully qualified name of the bean class used to find
properties and nested JavaBeansstrict
- Determines how this class handles cases when setting and
retrieving property values and a child bean is nullBeanException
- If the class name is not a valid class in the classpathMethod Detail |
public boolean isStrict()
public void setStrict(boolean value)
value
- The value to set for the strictness of this and only this JavaBeanpublic Class getBeanClass()
public void addProperty(String propertyName) throws BeanException
It is not necessary to add properties before they are accessed using the
getPropertyValue()
or the setPropertyValue()
methods. You can also retrieve BeanProperties from the
getBeanProperty()
method without adding
them.
This method allows the JavaBean to be constructed with the properties that will be used in the future so that access time in the future is faster (ie nothing needs to be constructed in order to access a property).
propertyName
- The name of the local or nested property to addBeanException
- If the propertyName is not a valid property of this
JavaBeanpublic BeanProperty getBeanProperty(String propertyName) throws BeanException
If the BeanProperty has not been added to either this JavaBean or a child JavaBean, it will be created and likewise, any JavaBean children that do not exist yet, will also be created and added. This is done in order to allow access to the BeanProperty. Not that if the BeanProperty does not exist in the Class of this JavaBean or a child JavaBean an exception is thrown.
propertyName
- The name of the property that is a local or nested propertyBeanException
- If there was a problem finding or creating the bean
propertypublic IndexedBeanProperty getIndexedBeanProperty(String propertyName) throws BeanException
If the IndexedBeanProperty has not been added to either this JavaBean or a child JavaBean, it will be created and likewise, any JavaBean children that do not exist yet, will also be created and added. This is done in order to allow access to the IndexedBeanProperty. Not that if the property does not exist in the Class of this JavaBean or a child JavaBean or it is not indexed an exception is thrown.
propertyName
- The name of the property that is a local or nested indexed
propertyBeanException
- If there was a problem finding or creating the indexed bean
propertypublic boolean isBeanPropertyIndexed(String propertyName) throws BeanException
If the property was not added to the JavaBean yet, then this method adds it so that it can determine whether or not it is indexed. Also, if the propertyName is not valid, then an exception is thrown.
propertyName
- The name of the property that is a local or nested property
and is being check to see if it is indexed or notBeanException
- If the propertyName is not a valid local or nested
propertypublic void checkBeanProperty(String propertyName, Class type) throws BeanException
propertyName
- The property to check and possibly add to this the java beantype
- The type to check against the propertyBeanException
- If the property does not exist in this java bean or
if the property type is not the same as or assignable to the given
typepublic JavaBean getChildJavaBean(String propertyName) throws BeanException
propertyName
- The name of the property that is a child bean or the name
of a nested property that is a child bean of one of this beans childrenBeanException
- If there was a problem finding the sub-bean or there
was a problem creating BeanProperty objects for properties of this
bean or one of its children or problems creating JavaBean obejcts
for one of this beans child beanspublic Object instantiate() throws BeanException
BeanException
- If there was a problem creating the instancepublic Object getPropertyValue(String propertyName, Object bean) throws BeanException
propertyName
- The name of the property to retrievebean
- The bean to retrieve the property value fromBeanException
- If there was a problem retrieving the valuepublic Object getPropertyValue(String propertyName, Object bean, int[] indices) throws BeanException
If this is a nested property and a child JavaBean is ever null, this method throws an exception based on the strictness of this JavaBean. Otherwise, null is returned.
propertyName
- The name of the property to retrievebean
- The bean to retrieve the property value fromindices
- (Optional) The list of indices used for indexed propertiesBeanException
- If there was a problem retrieving the valuepublic Object getPropertyValue(String propertyName, Object bean, List indices) throws BeanException
If this is a nested property and a child JavaBean is ever null, this method throws an exception based on the strictness of this JavaBean. Otherwise, null is returned.
propertyName
- The name of the property to retrievebean
- The bean to retrieve the property value fromindices
- (Optional) The list of indices used for indexed propertiesBeanException
- If there was a problem retrieving the valuepublic void setPropertyValue(String propertyName, Object bean, Object value) throws BeanException
propertyName
- The name of the property to set (local or nested)bean
- The bean to set the property onvalue
- The value to set the property toBeanException
- If there was a problem setting the property or
converting the value or creating child objectspublic void setPropertyValue(String propertyName, Object bean, Object value, boolean convert) throws BeanException
propertyName
- The name of the property to set (local or nested)bean
- The bean to set the property onvalue
- The value to set the property toconvert
- Determines whether or not to convert the value to the type
of the propertyBeanException
- If there was a problem setting the property or
converting the value or creating child objectspublic void setPropertyValue(String propertyName, Object bean, int[] indices, Object value, boolean convert) throws BeanException
Based on the strictness of this JavaBean, if a null property is encountered in a nested property an exception may be thrown. If strict is set to true, then an exception is thrown. If it is set to false, then a new instance of the property is created and set.
propertyName
- The name of the property to set (local or nested)bean
- The bean to set the property onindices
- (Optional) The array of indices that will be used for any
indexed propertiesvalue
- The value to set the property toconvert
- Determines whether or not to convert the value to the type
of the propertyBeanException
- If there was a problem setting the property or
converting the value or creating child objectspublic void setPropertyValue(String propertyName, Object bean, List indices, Object value, boolean convert) throws BeanException
Based on the strictness of this JavaBean, if a null property is encountered in a nested property an exception may be thrown. If strict is set to true, then an exception is thrown. If it is set to false, then a new instance of the property is created and set.
propertyName
- The name of the property to set (local or nested)bean
- The bean to set the property onindices
- (Optional) The array of indices that will be used for any
indexed propertiesvalue
- The value to set the property toconvert
- Determines whether or not to convert the value to the type
of the propertyBeanException
- If there was a problem setting the property or
converting the value or creating child objects
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |