|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.morph.reflect.reflectors.BaseReflector
public abstract class BaseReflector
Convenient base class for Reflectors. Validates arguments and takes care of logging and exception handling. Also, automatically implements some methods for certain types of reflectors. Most notably, the BeanReflector interface is automatically implemented for reflectors that implement MutableIndexedContainerReflector. See method JavaDoc for more information.
Field Summary | |
---|---|
protected org.apache.commons.logging.Log |
log
Protected Log instance |
Constructor Summary | |
---|---|
BaseReflector()
Create a new BaseReflector. |
Method Summary | |
---|---|
boolean |
add(java.lang.Object container,
java.lang.Object value)
GrowableContainerReflector.add(Object, Object) |
protected boolean |
addImpl(java.lang.Object container,
java.lang.Object value)
Implementation of GrowableContainer.add(Object) . |
protected void |
checkIndex(java.lang.Object container,
int index)
Validate index into container . |
protected void |
checkIsReflectable(java.lang.Object object)
Throws an exception if a the given object is not reflectable by this reflector. |
protected WrapperInvocationHandler |
createWrapperInvocationHandler(java.lang.Object object)
Create a WrapperInvocationHandler for the specified Object. |
java.lang.Object |
get(java.lang.Object container,
int index)
IndexedContainerReflector.get(Object, int) |
java.lang.Object |
get(java.lang.Object bean,
java.lang.String propertyName)
BeanReflector.get(Object, String) |
java.lang.Class |
getContainedType(java.lang.Class clazz)
ContainerReflector.getContainedType(Class) |
protected java.lang.Class |
getContainedTypeImpl(java.lang.Class clazz)
Implementation of ContainerReflector.getContainedType(Class) . |
protected java.lang.Object |
getImpl(java.lang.Object container,
int index)
Implementation of IndexedContainerReflector.get(Object, int) . |
protected java.lang.Object |
getImpl(java.lang.Object bean,
java.lang.String propertyName)
Implementation of BeanReflector.get(Object, String) . |
java.util.Iterator |
getIterator(java.lang.Object container)
ContainerReflector.getIterator(Object) |
protected java.util.Iterator |
getIteratorImpl(java.lang.Object container)
Implementation of ContainerReflector.getIterator(Object) . |
java.lang.String[] |
getPropertyNames(java.lang.Object bean)
BeanReflector.getPropertyNames(Object) |
protected java.lang.String[] |
getPropertyNamesImpl(java.lang.Object bean)
Implementation of BeanReflector.getPropertyNames(Object) . |
protected java.util.Map |
getReflectableCallCache()
Get the isReflectable(Class) call cache. |
java.lang.Class[] |
getReflectableClasses()
Defines which classes are reflectable by this reflector. |
protected abstract java.lang.Class[] |
getReflectableClassesImpl()
Implementation of Reflector.getReflectableClasses() . |
java.lang.String |
getReflectorName()
Get the reflectorName. |
int |
getSize(java.lang.Object container)
SizableReflector.getSize(Object) |
protected int |
getSizeImpl(java.lang.Object container)
Implementation of SizableReflector.getSize(Object) . |
java.lang.Class |
getType(java.lang.Object bean,
java.lang.String propertyName)
BeanReflector.getType(Object, String) |
protected java.lang.Class |
getTypeImpl(java.lang.Object bean,
java.lang.String propertyName)
Implementation of BeanReflector.getType(Object, String) . |
Wrapper |
getWrapper(java.lang.Object object)
Optional operation: returns a wrapper for the given object. |
protected Wrapper |
getWrapperImpl(java.lang.Object object)
Implementation of Reflector.getWrapper(Object) . |
protected void |
initialize()
Initialize this Reflector. |
protected void |
initializeImpl()
Implementation of initialize() . |
boolean |
isCachingIsReflectableCalls()
Learn whether this Reflector is caching isReflectable(Class) calls. |
protected boolean |
isInitialized()
Learn whether this Reflector is initialized. |
protected boolean |
isPerformingLogging()
Indicates whether this reflector is writing log messages |
boolean |
isReadable(java.lang.Object bean,
java.lang.String propertyName)
BeanReflector.isReadable(Object, String) |
protected boolean |
isReadableImpl(java.lang.Object bean,
java.lang.String propertyName)
Implementation of BeanReflector.isReadable(Object, String) . |
boolean |
isReflectable(java.lang.Class reflectedType)
Indicates whether the given type is reflectable by this reflector. |
boolean |
isReflectable(java.lang.Class reflectedType,
java.lang.Class reflectorType)
DecoratedReflector.isReflectable(Class) |
protected boolean |
isReflectableImpl(java.lang.Class reflectedType)
Implementation of DecoratedReflector.isReflectable(Class) . |
protected boolean |
isReflectableImpl(java.lang.Class reflectedType,
java.lang.Class reflectorType)
Implementation of isReflectable(Class, Class) . |
boolean |
isStrictlyTyped()
Indicates whether this reflector is strictly typed. |
protected boolean |
isValidIndex(java.lang.Object bean,
java.lang.String propertyName)
Learn whether propertyName denotes a valid numeric property index for bean . |
protected boolean |
isWrappingRuntimeExceptions()
Indicates whether runtime exceptions should be wrapped as ReflectionException s. |
boolean |
isWriteable(java.lang.Object bean,
java.lang.String propertyName)
BeanReflector.isWriteable(Object, String) |
protected boolean |
isWriteableImpl(java.lang.Object bean,
java.lang.String propertyName)
Implementation of BeanReflector.isWriteable(Object, String) . |
java.lang.Object |
newInstance(java.lang.Class clazz,
java.lang.Object parameters)
InstantiatingReflector.newInstance(Class, Object) |
protected java.lang.Object |
newInstanceImpl(java.lang.Class clazz)
Deprecated. Use newInstanceImpl(Class, Object) instead. Calls to this method will fail with an UnsupportedOperationException |
protected java.lang.Object |
newInstanceImpl(java.lang.Class clazz,
java.lang.Object parameters)
Implementation of InstantiatingReflector.newInstance(Class, Object) . |
java.lang.Object |
set(java.lang.Object container,
int index,
java.lang.Object propertyValue)
MutableIndexedContainerReflector.set(Object, int, Object) |
void |
set(java.lang.Object bean,
java.lang.String propertyName,
java.lang.Object propertyValue)
BeanReflector.set(Object, String, Object) |
void |
setCachingIsReflectableCalls(boolean cachingIsReflectableCalls)
Set whether this Reflector is caching isReflectable(Class) calls. |
protected java.lang.Object |
setImpl(java.lang.Object container,
int index,
java.lang.Object propertyValue)
Implementation of MutableIndexedContainerReflector.set(Object, int, Object) . |
protected void |
setImpl(java.lang.Object bean,
java.lang.String propertyName,
java.lang.Object value)
Implementation of BeanReflector.set(Object, String, Object) . |
protected void |
setInitialized(boolean initialized)
Set the initialization status of this Reflector. |
protected void |
setReflectableCallCache(java.util.Map reflectableCallCache)
Set the isReflectable(Class) call cache. |
void |
setReflectorName(java.lang.String reflectorName)
Set the reflectorName. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected transient org.apache.commons.logging.Log log
Constructor Detail |
---|
public BaseReflector()
Method Detail |
---|
protected void initializeImpl() throws java.lang.Exception
initialize()
.
java.lang.Exception
protected final void initialize() throws ReflectionException
ReflectionException
public final java.lang.Class[] getReflectableClasses()
getReflectableClasses
in interface Reflector
Reflector.getReflectableClasses()
protected abstract java.lang.Class[] getReflectableClassesImpl() throws java.lang.Exception
Reflector.getReflectableClasses()
.
java.lang.Exception
public final Wrapper getWrapper(java.lang.Object object)
getWrapper
in interface Reflector
object
- the object for which a wrapper is desired
Reflector.getWrapper(java.lang.Object)
protected Wrapper getWrapperImpl(java.lang.Object object) throws java.lang.Exception
Reflector.getWrapper(Object)
.
java.lang.Exception
protected WrapperInvocationHandler createWrapperInvocationHandler(java.lang.Object object)
object
-
public final boolean isReflectable(java.lang.Class reflectedType) throws ReflectionException
isReflectable
in interface DecoratedReflector
reflectedType
- the type to test
true
, if this reflector can reflect the given
class or false
, if this reflector cannot reflect the given
class
ReflectionException
- if an error occurrsDecoratedReflector.isReflectable(java.lang.Class)
protected boolean isReflectableImpl(java.lang.Class reflectedType) throws java.lang.Exception
DecoratedReflector.isReflectable(Class)
.
java.lang.Exception
public final boolean isReflectable(java.lang.Class reflectedType, java.lang.Class reflectorType) throws ReflectionException
DecoratedReflector.isReflectable(Class)
reflectedType
- reflectorType
-
ReflectionException
protected boolean isReflectableImpl(java.lang.Class reflectedType, java.lang.Class reflectorType) throws java.lang.Exception
isReflectable(Class, Class)
.
java.lang.Exception
protected void checkIsReflectable(java.lang.Object object) throws ReflectionException
object
- the object to test
ReflectionException
- if the given object is not reflectable by this reflectorpublic final java.lang.Object newInstance(java.lang.Class clazz, java.lang.Object parameters)
InstantiatingReflector.newInstance(Class, Object)
clazz
- parameters
- protected final java.lang.Object newInstanceImpl(java.lang.Class clazz) throws java.lang.Exception
newInstanceImpl(Class, Object)
instead. Calls to this method will fail with an UnsupportedOperationException
java.lang.Exception
protected java.lang.Object newInstanceImpl(java.lang.Class clazz, java.lang.Object parameters) throws java.lang.Exception
InstantiatingReflector.newInstance(Class, Object)
.
Default implementation returns a new instance of the given class by
calling Class#newInstance())
.
java.lang.Exception
public final java.lang.String[] getPropertyNames(java.lang.Object bean) throws ReflectionException
BeanReflector.getPropertyNames(Object)
bean
-
ReflectionException
protected java.lang.String[] getPropertyNamesImpl(java.lang.Object bean) throws java.lang.Exception
BeanReflector.getPropertyNames(Object)
.
Implementation automatically provided for
IndexedContainerReflectors. For other reflectors, throws an
UnsupportedOperationException.
java.lang.Exception
public final boolean isReadable(java.lang.Object bean, java.lang.String propertyName) throws ReflectionException
BeanReflector.isReadable(Object, String)
bean
- propertyName
-
ReflectionException
protected boolean isReadableImpl(java.lang.Object bean, java.lang.String propertyName) throws java.lang.Exception
BeanReflector.isReadable(Object, String)
.
Default implementation assumes that all properties of the bean specified
by BeanReflector.getPropertyNames(Object)
are readable.
java.lang.Exception
public final boolean isWriteable(java.lang.Object bean, java.lang.String propertyName)
BeanReflector.isWriteable(Object, String)
bean
- propertyName
-
protected boolean isWriteableImpl(java.lang.Object bean, java.lang.String propertyName) throws java.lang.Exception
BeanReflector.isWriteable(Object, String)
.
Default implementation assumes that all readable properties are also
writeable. One exception to this is when this reflector is an
IndexedContainerReflector but not a MutableIndexedContainerReflector, in
which case no properties are considered writeable.
java.lang.Exception
protected boolean isValidIndex(java.lang.Object bean, java.lang.String propertyName) throws ReflectionException
propertyName
denotes a valid numeric property index for bean
.
bean
- propertyName
-
ReflectionException
public final void set(java.lang.Object bean, java.lang.String propertyName, java.lang.Object propertyValue) throws ReflectionException
BeanReflector.set(Object, String, Object)
bean
- propertyName
- propertyValue
-
ReflectionException
protected void setImpl(java.lang.Object bean, java.lang.String propertyName, java.lang.Object value) throws java.lang.Exception
BeanReflector.set(Object, String, Object)
.
Implementation automatically provided for
MutableIndexedContainerReflectors. For other reflectors, throws an
UnsupportedOperationException.
java.lang.Exception
public final java.lang.Object get(java.lang.Object bean, java.lang.String propertyName) throws ReflectionException
BeanReflector.get(Object, String)
bean
- propertyName
-
ReflectionException
protected java.lang.Object getImpl(java.lang.Object bean, java.lang.String propertyName) throws java.lang.Exception
BeanReflector.get(Object, String)
.
Implementation automatically provided for
IndexedContainerReflectors. For other reflectors, throws an
UnsupportedOperationException.
java.lang.Exception
public final java.lang.Class getType(java.lang.Object bean, java.lang.String propertyName) throws ReflectionException
BeanReflector.getType(Object, String)
bean
- propertyName
-
ReflectionException
protected java.lang.Class getTypeImpl(java.lang.Object bean, java.lang.String propertyName) throws java.lang.Exception
BeanReflector.getType(Object, String)
.
Default implementation provided. For IndexedContainerReflectors,
returns the type by calling
ContainerReflector.getContainedType(Class)
.
For other reflectors, checks the type of the property by calling
get(Object, String)
.
java.lang.Exception
public final java.lang.Class getContainedType(java.lang.Class clazz) throws ReflectionException
ContainerReflector.getContainedType(Class)
clazz
-
ReflectionException
protected java.lang.Class getContainedTypeImpl(java.lang.Class clazz) throws java.lang.Exception
ContainerReflector.getContainedType(Class)
.
java.lang.Exception
public final java.util.Iterator getIterator(java.lang.Object container) throws ReflectionException
ContainerReflector.getIterator(Object)
container
-
ReflectionException
protected java.util.Iterator getIteratorImpl(java.lang.Object container) throws java.lang.Exception
ContainerReflector.getIterator(Object)
.
java.lang.Exception
protected void checkIndex(java.lang.Object container, int index) throws ReflectionException
index
into container
.
container
- index
-
ReflectionException
public final int getSize(java.lang.Object container) throws ReflectionException
SizableReflector.getSize(Object)
container
-
ReflectionException
protected int getSizeImpl(java.lang.Object container) throws java.lang.Exception
SizableReflector.getSize(Object)
.
java.lang.Exception
public final java.lang.Object get(java.lang.Object container, int index) throws ReflectionException
IndexedContainerReflector.get(Object, int)
container
- index
-
ReflectionException
protected java.lang.Object getImpl(java.lang.Object container, int index) throws java.lang.Exception
IndexedContainerReflector.get(Object, int)
.
java.lang.Exception
public final java.lang.Object set(java.lang.Object container, int index, java.lang.Object propertyValue) throws ReflectionException
MutableIndexedContainerReflector.set(Object, int, Object)
container
- index
- propertyValue
-
ReflectionException
protected java.lang.Object setImpl(java.lang.Object container, int index, java.lang.Object propertyValue) throws java.lang.Exception
MutableIndexedContainerReflector.set(Object, int, Object)
.
java.lang.Exception
public final boolean add(java.lang.Object container, java.lang.Object value) throws ReflectionException
GrowableContainerReflector.add(Object, Object)
container
- value
-
ReflectionException
protected boolean addImpl(java.lang.Object container, java.lang.Object value) throws java.lang.Exception
GrowableContainer.add(Object)
.
java.lang.Exception
protected boolean isPerformingLogging()
public boolean isStrictlyTyped()
getType(Object, String)
method will throw
an exception if the requested property name is not a valid property
of the object. Default implementation returns false
.
false
.protected boolean isInitialized()
protected void setInitialized(boolean initialized)
initialized
- public boolean isCachingIsReflectableCalls()
isReflectable(Class)
calls.
Default true
.
public void setCachingIsReflectableCalls(boolean cachingIsReflectableCalls)
isReflectable(Class)
calls.
cachingIsReflectableCalls
- protected java.util.Map getReflectableCallCache()
isReflectable(Class)
call cache.
protected void setReflectableCallCache(java.util.Map reflectableCallCache)
isReflectable(Class)
call cache.
protected boolean isWrappingRuntimeExceptions()
ReflectionException
s. By default, this method returns
true
.
Simple Reflectors in Morph will usually set this value to true
so that they throw ReflectionExceptions if problems occur. User-written
Reflectors are encouraged to return false
so that runtime
exceptions are not wrapped. This way, problems accessing data will be
expressed by the native API of a user's domain objects and avoid the need to
catch Morph-specific exceptions (assuming the use of runtime exceptions in said
domain objects).
true
public java.lang.String getReflectorName()
public void setReflectorName(java.lang.String reflectorName)
reflectorName
- the String to setpublic java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |