public class

BeanModel

extends Object
java.lang.Object
   ↳ org.odata4j.producer.inmemory.BeanModel

Class Overview

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.

Summary

Fields
private final Class<?> beanClass
private final Map<String, Class<?>> collections
private final Map<String, Method> getters
private final Map<String, Method> setters
private final Map<String, Class<?>> types
Public Constructors
BeanModel(Class<?> beanClass)
Constructs the abstract bean representation of a class.
Public Methods
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> 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.
<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
[Expand]
Inherited Methods
From class java.lang.Object

Fields

private final Class<?> beanClass

private final Map<String, Class<?>> collections

private final Map<String, Method> getters

private final Map<String, Method> setters

private final Map<String, Class<?>> types

Public Constructors

public BeanModel (Class<?> beanClass)

Constructs the abstract bean representation of a class.

Parameters
beanClass The class to introspect

Public Methods

public boolean canRead (String propertyName)

Returns true if the property has a getter.

Parameters
propertyName

public boolean canWrite (String propertyName)

Returns true if the property has a setter.

Parameters
propertyName

public Class<?> getBeanClass ()

Recovers the original class on which this metadata is based.

Returns
  • the original class

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

public Iterable<String> getCollectionNames ()

Returns the list of properties that have collection types.

Returns
  • the list of properties

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

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

public Class<?> getPropertyType (String propertyName)

Discovers the type of a property.

Parameters
propertyName The property you are interested in
Returns
  • the type of the property

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

public 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

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