org.odata4j.producer.inmemory
Class BeanModel

java.lang.Object
  extended by org.odata4j.producer.inmemory.BeanModel

public class BeanModel
extends Object

An abstract representation of the "bean" nature of a class. This class caches up-front analysis of a class to locate the getters and setters it will need in order to operate on instances.

Instances of this class can then be used in place of reflection.


Constructor Summary
BeanModel(Class<?> beanClass)
          Constructs the abstract bean representation of a class.
BeanModel(Class<?> beanClass, boolean flatten)
          Constructs the abstract bean representation of a class.
 
Method Summary
 boolean canRead(String propertyName)
          Returns true if the property has a getter.
 boolean canWrite(String propertyName)
          Returns true if the property has a setter.
 Class<?> getBeanClass()
          Recovers the original class on which this metadata is based.
 Class<?> getCollectionElementType(String collectionName)
          For any given collection type, identifies the type of the elements of the collection.
 Iterable<String> getCollectionNames()
          Returns the list of properties that have collection types.
 Iterable<?> getCollectionValue(Object target, String collectionName)
          Returns a collection from a property in an instance.
 Iterable<String> getDeclaredCollectionNames()
          Get the collection names that were defined in this.beanClass only (i.e.
 Iterable<String> getDeclaredPropertyNames()
          Get the property names that were defined in this.beanClass only (i.e.
 Iterable<String> getPropertyNames()
          Returns the list of all properties identified on this class.
 Class<?> getPropertyType(String propertyName)
          Discovers the type of a property.
 Object getPropertyValue(Object target, String propertyName)
          Interrogates an instance of the target class and discovers the value of a given property.
 BeanModel getSuperClassModel()
          Returns the BeanModel for the superclass of this.beanClass
<T> void
setCollectionValue(Object target, String collectionName, Collection<T> collectionValue)
          Updates a collection property.
 void setPropertyValue(Object target, String propertyName, Object propertyValue)
          Updates an instance to set a property to a given value This method is only intended to be used for simple properties
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeanModel

public BeanModel(Class<?> beanClass)
Constructs the abstract bean representation of a class. Flattens inheritance.

Parameters:
beanClass - the class to introspect

BeanModel

public BeanModel(Class<?> beanClass,
                 boolean flatten)
Constructs the abstract bean representation of a class.

Parameters:
beanClass - the class to introspect
flatten - flatten inheritance or not (@see BeanBasePropertyModel)
Method Detail

canRead

public boolean canRead(String propertyName)
Returns true if the property has a getter.


canWrite

public boolean canWrite(String propertyName)
Returns true if the property has a setter.


getBeanClass

public Class<?> getBeanClass()
Recovers the original class on which this metadata is based.

Returns:
the original class

getCollectionElementType

public Class<?> getCollectionElementType(String collectionName)
For any given collection type, identifies the type of the elements of the collection.

Parameters:
collectionName - the name of the collection
Returns:
the type of the elements of the named collection

getCollectionNames

public Iterable<String> getCollectionNames()
Returns the list of properties that have collection types.

Returns:
the list of properties

getCollectionValue

public Iterable<?> getCollectionValue(Object target,
                                      String collectionName)
Returns a collection from a property in an instance.

Parameters:
target - the instance to look at
collectionName - the name of the property on the instance which holds the collection
Returns:
an iterable containing the elements of the collection

getDeclaredCollectionNames

public Iterable<String> getDeclaredCollectionNames()
Get the collection names that were defined in this.beanClass only (i.e. does not include inherited collection names)

Returns:
collection names

getDeclaredPropertyNames

public Iterable<String> getDeclaredPropertyNames()
Get the property names that were defined in this.beanClass only (i.e. does not include inherited property names)

Returns:
property names

getPropertyNames

public Iterable<String> getPropertyNames()
Returns the list of all properties identified on this class.

A property is any field that has a simple value type (i.e. not a collection type) and either has a getter or a setter defined on it.

Returns:
the list of identified properties

getPropertyType

public Class<?> getPropertyType(String propertyName)
Discovers the type of a property. Will walk up the inheritance hierarchy

Parameters:
propertyName - the property you are interested in
Returns:
the type of the property

getPropertyValue

public Object getPropertyValue(Object target,
                               String propertyName)
Interrogates an instance of the target class and discovers the value of a given property. This method is only intended to be used for simple properties.

Parameters:
target - the instance of the class
propertyName - the name of the property to fetch
Returns:
the value of the property in the given object

getSuperClassModel

public BeanModel getSuperClassModel()
Returns the BeanModel for the superclass of this.beanClass

Returns:
the superclass of this.beanClass

setCollectionValue

public <T> void setCollectionValue(Object target,
                                   String collectionName,
                                   Collection<T> collectionValue)
Updates a collection property.

Parameters:
target - the instance to look at
collectionName - the name of the property on the instance which holds the collection
collectionValue - the new collection

setPropertyValue

public void setPropertyValue(Object target,
                             String propertyName,
                             Object propertyValue)
Updates an instance to set a property to a given value This method is only intended to be used for simple properties

Parameters:
target - the instance to update
propertyName - the name of the property
propertyValue - the value to set in the property


http://odata4j.org