org.loom.binding
Class PropertyWrapper

java.lang.Object
  extended by org.loom.binding.PropertyWrapper
All Implemented Interfaces:
AnnotationContainer

public class PropertyWrapper
extends java.lang.Object
implements AnnotationContainer

Wraps a property, allowing to read and write it in an encapsulated way


Constructor Summary
PropertyWrapper(java.lang.Class<?> containerClass, java.lang.String propertyName)
           
 
Method Summary
 void addAnnotations(java.lang.reflect.AnnotatedElement element)
          Adds the element annotations to this property wrapper
protected  java.lang.Object get(java.lang.Object container)
           
 java.lang.Object get(java.lang.Object container, boolean createIfNull)
          Gets the property value
<T extends java.lang.annotation.Annotation>
T
getAnnotation(java.lang.Class<T> annotationClass)
           
 java.lang.annotation.Annotation[] getAnnotations()
           
 java.lang.Class<?> getContainerClass()
           
 java.lang.String getDisplayName()
           
 java.lang.reflect.Field getField()
           
 java.lang.reflect.Method getGetter()
           
 ImplementationFactory<?> getImplementationFactory()
           
 ItemMetadata getItemMetadata()
           
 ItemMetadata getItemMetadata(int index)
           
 int getItemMetadataSize()
           
 java.lang.String getName()
           
 java.lang.Class<?> getNextPropertyClass()
           
 java.lang.Object getNullValue()
           
 java.lang.Class<?> getPropertyClass()
           
 java.lang.String getPropertyName()
           
 java.lang.reflect.Method getSetter()
           
 java.lang.Class<?> guessCollectionGenericType()
          Guess the collection generic type of this property, if possible.
 java.lang.Class<?> guessMapGenericKeyType()
          Guess the Map generic type used for the key of this Map property, String.class if it cannot be guessed.
 java.lang.Class<?> guessMapGenericValueType()
          Guess the Map generic type used for the value of this Map property, String.class if it cannot be guessed.
 boolean isCollection()
           
 boolean isMap()
           
 boolean isReadOnly()
           
 boolean isSet()
           
 void set(java.lang.Object container, java.lang.Object value)
          Sets a value to this property in the specified container
 void setContainerClass(java.lang.Class<?> containerClass)
           
 void setField(java.lang.reflect.Field field)
           
 void setGetter(java.lang.reflect.Method getter)
           
 void setImplementationFactory(ImplementationFactory<?> valueFactory)
           
 void setItemMetadata(ItemMetadata itemMetadata)
           
 void setItemMetadata(ItemMetadata[] itemMetadata)
           
 void setNullValue(java.lang.Object nullValue)
           
 void setPropertyClass(java.lang.Class<?> propertyClass)
           
 void setPropertyName(java.lang.String propertyName)
           
 void setSetter(java.lang.reflect.Method setter)
           
 java.lang.String toString()
          for debugging purposes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PropertyWrapper

public PropertyWrapper(java.lang.Class<?> containerClass,
                       java.lang.String propertyName)
Method Detail

getAnnotation

public <T extends java.lang.annotation.Annotation> T getAnnotation(java.lang.Class<T> annotationClass)
Specified by:
getAnnotation in interface AnnotationContainer
Returns:
the given Annotation if it's assigned to this property, null if none

addAnnotations

public void addAnnotations(java.lang.reflect.AnnotatedElement element)
Adds the element annotations to this property wrapper

Parameters:
element -

get

public java.lang.Object get(java.lang.Object container,
                            boolean createIfNull)
Gets the property value

Parameters:
container - The object that contains the property
createIfNull - if true, creates a new instance if the property value is null
Returns:
The property value

setField

public void setField(java.lang.reflect.Field field)

setGetter

public void setGetter(java.lang.reflect.Method getter)

setSetter

public void setSetter(java.lang.reflect.Method setter)

get

protected java.lang.Object get(java.lang.Object container)
Returns:
the value to this property in the specified container

set

public void set(java.lang.Object container,
                java.lang.Object value)
Sets a value to this property in the specified container


isCollection

public boolean isCollection()
Specified by:
isCollection in interface AnnotationContainer
Returns:
true if this property is a List, Set or Array

isMap

public boolean isMap()
Specified by:
isMap in interface AnnotationContainer
Returns:
true if this property is a Map

isSet

public boolean isSet()

getField

public java.lang.reflect.Field getField()

getGetter

public java.lang.reflect.Method getGetter()

getSetter

public java.lang.reflect.Method getSetter()

isReadOnly

public boolean isReadOnly()

getAnnotations

public java.lang.annotation.Annotation[] getAnnotations()
Specified by:
getAnnotations in interface AnnotationContainer
Returns:
the array of annotations associated to the property

getContainerClass

public java.lang.Class<?> getContainerClass()

getPropertyClass

public java.lang.Class<?> getPropertyClass()
Specified by:
getPropertyClass in interface AnnotationContainer
Returns:
the class of this property/parameter

getPropertyName

public java.lang.String getPropertyName()

getName

public java.lang.String getName()
Specified by:
getName in interface AnnotationContainer
Returns:
the name of this method or property

setContainerClass

public void setContainerClass(java.lang.Class<?> containerClass)

setPropertyClass

public void setPropertyClass(java.lang.Class<?> propertyClass)

getDisplayName

public java.lang.String getDisplayName()
Specified by:
getDisplayName in interface AnnotationContainer
Returns:
the name used to display error or informational messages

setPropertyName

public void setPropertyName(java.lang.String propertyName)

getImplementationFactory

public ImplementationFactory<?> getImplementationFactory()

setImplementationFactory

public void setImplementationFactory(ImplementationFactory<?> valueFactory)

toString

public java.lang.String toString()
for debugging purposes

Overrides:
toString in class java.lang.Object

getNullValue

public java.lang.Object getNullValue()

setNullValue

public void setNullValue(java.lang.Object nullValue)

setItemMetadata

public void setItemMetadata(ItemMetadata itemMetadata)

setItemMetadata

public void setItemMetadata(ItemMetadata[] itemMetadata)

getItemMetadata

public ItemMetadata getItemMetadata()

getItemMetadata

public ItemMetadata getItemMetadata(int index)
Specified by:
getItemMetadata in interface AnnotationContainer

getItemMetadataSize

public int getItemMetadataSize()
Specified by:
getItemMetadataSize in interface AnnotationContainer

getNextPropertyClass

public java.lang.Class<?> getNextPropertyClass()
Returns:
the container class for the next node in a property chain. For simple nodes this would be the same as the property class, but collections will return the item class, and Maps the value class.

guessCollectionGenericType

public java.lang.Class<?> guessCollectionGenericType()
Guess the collection generic type of this property, if possible. Return null if it cannot be guessed.

Specified by:
guessCollectionGenericType in interface AnnotationContainer

guessMapGenericKeyType

public java.lang.Class<?> guessMapGenericKeyType()
Guess the Map generic type used for the key of this Map property, String.class if it cannot be guessed.

Specified by:
guessMapGenericKeyType in interface AnnotationContainer

guessMapGenericValueType

public java.lang.Class<?> guessMapGenericValueType()
Guess the Map generic type used for the value of this Map property, String.class if it cannot be guessed.

Specified by:
guessMapGenericValueType in interface AnnotationContainer