org.clazzes.util.reflect
Class POJOFieldAccessor

java.lang.Object
  extended by org.clazzes.util.reflect.POJOFieldAccessor
All Implemented Interfaces:
FieldAccessor

public class POJOFieldAccessor
extends java.lang.Object
implements FieldAccessor

Author:
wglas

Constructor Summary
POJOFieldAccessor(java.lang.Class clazz, java.lang.String property)
          Instantiates a field accessor for a property of a given POJO.
POJOFieldAccessor(java.lang.reflect.Field field)
          Instantiates a field accessor for a field of a given POJO.
POJOFieldAccessor(java.lang.reflect.Method getter)
          Instantiates a field accessor for a property of a given POJO specified through the supplied getter method.
 
Method Summary
 boolean checkMandatory()
          Parse all relevant Annotations and try to retrieve a Column -Annotation and test it's nullable() value.
 boolean checkUpdatable()
          Parse all relevant Annotations and try to retrieve a Column -Annotation and test it's updatable() value.
<T extends java.lang.annotation.Annotation>
T
getAnnotation(java.lang.Class<T> type)
           
 java.lang.annotation.Annotation[] getAnnotations()
           
 java.lang.Class getDeclaringClass()
           
 FieldAccessor getIdAccessor()
          Get the accessor used to access the ID-Field of the same POJO this FieldAccessor belongs to.
 java.lang.String getName()
           
 java.lang.Class getType()
           
 java.lang.Object getValueOf(java.lang.Object pojo)
          Gets the associated field value of the given instance of the underlying class.
 void setIdAccessor(FieldAccessor idAccessor)
          Set the accessor used to access the ID-Field of the same POJO this FieldAccessor belongs to.
 void setValueOn(java.lang.Object pojo, java.lang.Object value)
          Sets the associated field value on the given instance of the underlying class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

POJOFieldAccessor

public POJOFieldAccessor(java.lang.reflect.Field field)
Instantiates a field accessor for a field of a given POJO.


POJOFieldAccessor

public POJOFieldAccessor(java.lang.Class clazz,
                         java.lang.String property)
                  throws java.lang.NoSuchMethodException,
                         java.lang.SecurityException
Instantiates a field accessor for a property of a given POJO.

Parameters:
clazz - The class for which to access the property
property - The property name to access.
Throws:
java.lang.NoSuchMethodException - If no getter for the given property is found.
java.lang.SecurityException - If the security context does not allow access to the getter.

POJOFieldAccessor

public POJOFieldAccessor(java.lang.reflect.Method getter)
                  throws java.lang.NoSuchMethodException
Instantiates a field accessor for a property of a given POJO specified through the supplied getter method.

Parameters:
clazz - The class for which to access the property
property - The property name to access.
Throws:
java.lang.NoSuchMethodException - If the supplied method is not valid getter method.
Method Detail

getValueOf

public java.lang.Object getValueOf(java.lang.Object pojo)
                            throws java.lang.IllegalArgumentException,
                                   java.lang.IllegalAccessException,
                                   java.lang.reflect.InvocationTargetException
Description copied from interface: FieldAccessor
Gets the associated field value of the given instance of the underlying class.

Specified by:
getValueOf in interface FieldAccessor
Parameters:
pojo - The object of which to get the field value.
Returns:
The value of the associated field.
Throws:
java.lang.IllegalArgumentException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

setValueOn

public void setValueOn(java.lang.Object pojo,
                       java.lang.Object value)
                throws java.lang.IllegalArgumentException,
                       java.lang.IllegalAccessException,
                       java.lang.reflect.InvocationTargetException
Description copied from interface: FieldAccessor
Sets the associated field value on the given instance of the underlying class.

Specified by:
setValueOn in interface FieldAccessor
Parameters:
pojo - The object on which to set the field value.
value - The value of the associated field.
Throws:
java.lang.IllegalArgumentException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

getAnnotation

public <T extends java.lang.annotation.Annotation> T getAnnotation(java.lang.Class<T> type)
Specified by:
getAnnotation in interface FieldAccessor
Parameters:
type - The annotation type to request for.
Returns:
The annotation of the given field or property getter of the given type or null, if no such annotation exists.

getAnnotations

public java.lang.annotation.Annotation[] getAnnotations()
Specified by:
getAnnotations in interface FieldAccessor
Returns:
All annotations of the given field or property getter or null, if no annotations exists.

getName

public java.lang.String getName()
Specified by:
getName in interface FieldAccessor
Returns:
The name of the field or property accessed.

getType

public java.lang.Class getType()
Specified by:
getType in interface FieldAccessor
Returns:
The type of the field or property accessed.

getDeclaringClass

public java.lang.Class getDeclaringClass()
Specified by:
getDeclaringClass in interface FieldAccessor
Returns:
The class which contains the field or property accessed.

checkMandatory

public boolean checkMandatory()
Description copied from interface: FieldAccessor
Parse all relevant Annotations and try to retrieve a Column -Annotation and test it's nullable() value.

Specified by:
checkMandatory in interface FieldAccessor
Returns:
true for primitives,
(!Column.nullable()) if a Column -Annotation could be found,
false otherwise.

checkUpdatable

public boolean checkUpdatable()
Description copied from interface: FieldAccessor
Parse all relevant Annotations and try to retrieve a Column -Annotation and test it's updatable() value.

Specified by:
checkUpdatable in interface FieldAccessor
Returns:
true for primitives,
Column.updatable() if a Column -Annotation could be found,
true otherwise.

setIdAccessor

public void setIdAccessor(FieldAccessor idAccessor)
Description copied from interface: FieldAccessor
Set the accessor used to access the ID-Field of the same POJO this FieldAccessor belongs to.

Specified by:
setIdAccessor in interface FieldAccessor
Parameters:
idAccessor - The FieldAccessor for the ID-Field.

getIdAccessor

public FieldAccessor getIdAccessor()
Description copied from interface: FieldAccessor
Get the accessor used to access the ID-Field of the same POJO this FieldAccessor belongs to.

Specified by:
getIdAccessor in interface FieldAccessor
Returns:
The FieldAccessor for the ID-Field (may be null).


Copyright © 2010. All Rights Reserved.