net.sf.morph.reflect.reflectors
Class ObjectReflector

java.lang.Object
  extended by net.sf.morph.reflect.reflectors.BaseReflector
      extended by net.sf.morph.reflect.reflectors.BaseBeanReflector
          extended by net.sf.morph.reflect.reflectors.ObjectReflector
All Implemented Interfaces:
net.sf.composite.Component, BeanReflector, ContainerReflector, DecoratedReflector, InstantiatingReflector, Reflector, SizableReflector

public class ObjectReflector
extends BaseBeanReflector
implements InstantiatingReflector, ContainerReflector

A Reflector that exposes the properties of any Object as they are defined by the JavaBeans specification. Also exposes any Object as a container.

When an object is exposed as a container, the getContainer method returns an iterator that just iterates over the one reflected object. The getType method returns the type as specified by the property's setter method, if one is available. If no mutator is available, the getType method returns the type as specified by the property's getter method.

Since:
Nov 7, 2004
Author:
Matt Sgarlata, Alexander Volanis

Field Summary
 
Fields inherited from class net.sf.morph.reflect.reflectors.BaseReflector
log
 
Fields inherited from interface net.sf.morph.reflect.BeanReflector
IMPLICIT_PROPERTY_CLASS, IMPLICIT_PROPERTY_PROPERTY_NAMES, IMPLICIT_PROPERTY_THIS
 
Fields inherited from interface net.sf.morph.reflect.SizableReflector
IMPLICIT_PROPERTY_SIZE
 
Constructor Summary
ObjectReflector()
           
 
Method Summary
protected  java.lang.Class getContainedTypeImpl(java.lang.Class clazz)
          Implementation of ContainerReflector.getContainedType(Class).
protected  java.lang.Object getImpl(java.lang.Object bean, java.lang.String propertyName)
          Retrieves the value of the property propertyName in bean bean.
protected  java.util.Iterator getIteratorImpl(java.lang.Object container)
          Implementation of ContainerReflector.getIterator(Object).
protected  java.lang.String[] getPropertyNamesImpl(java.lang.Object bean)
          Template method must be overridden.
 java.lang.Class[] getReflectableClassesImpl()
          Implementation of Reflector.getReflectableClasses().
protected  ReflectionInfo getReflectionInfo(java.lang.Class clazz)
          Get the ReflectionInfo for the given Class.
protected  java.lang.Class getTypeImpl(java.lang.Object bean, java.lang.String propertyName)
          Returns the type of the property based on the parameter type for the property's setter method.
 boolean isAllowNullPrimitiveAssignment()
          Indicates whether primitive assignments to null are allowed.
protected  boolean isPrimitiveSetter(java.lang.Object bean, java.lang.String propertyName)
          Learn whether the mutator/setter method for the given property is primitive.
protected  boolean isReadableImpl(java.lang.Object bean, java.lang.String propertyName)
          Implementation of BeanReflector.isReadable(Object, String).
 boolean isStrictlyTyped()
          Returns true.
protected  boolean isWriteableImpl(java.lang.Object bean, java.lang.String propertyName)
          Implementation of BeanReflector.isWriteable(Object, String).
protected  java.lang.Object newInstanceImpl(java.lang.Class clazz, java.lang.Object parameters)
          Implementation of InstantiatingReflector.newInstance(Class, Object).
 void setAllowNullPrimitiveAssignment(boolean allowNullPrimitiveAssignment)
          Sets whether primitive assignments to null are allowed.
protected  void setImpl(java.lang.Object bean, java.lang.String propertyName, java.lang.Object value)
          Template method must be overridden.
 
Methods inherited from class net.sf.morph.reflect.reflectors.BaseReflector
add, addImpl, checkIndex, checkIsReflectable, createWrapperInvocationHandler, get, get, getContainedType, getImpl, getIterator, getPropertyNames, getReflectableCallCache, getReflectableClasses, getReflectorName, getSize, getSizeImpl, getType, getWrapper, getWrapperImpl, initialize, initializeImpl, isCachingIsReflectableCalls, isInitialized, isPerformingLogging, isReadable, isReflectable, isReflectable, isReflectableImpl, isReflectableImpl, isValidIndex, isWrappingRuntimeExceptions, isWriteable, newInstance, newInstanceImpl, set, set, setCachingIsReflectableCalls, setImpl, setInitialized, setReflectableCallCache, setReflectorName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.morph.reflect.InstantiatingReflector
newInstance
 
Methods inherited from interface net.sf.morph.reflect.Reflector
getReflectableClasses, getWrapper
 
Methods inherited from interface net.sf.morph.reflect.ContainerReflector
getContainedType, getIterator
 
Methods inherited from interface net.sf.morph.reflect.Reflector
getReflectableClasses, getWrapper
 
Methods inherited from interface net.sf.morph.reflect.BeanReflector
get, getPropertyNames, getType, isReadable, isWriteable, set
 
Methods inherited from interface net.sf.morph.reflect.SizableReflector
getSize
 

Constructor Detail

ObjectReflector

public ObjectReflector()
Method Detail

getReflectableClassesImpl

public java.lang.Class[] getReflectableClassesImpl()
Implementation of Reflector.getReflectableClasses().

Specified by:
getReflectableClassesImpl in class BaseReflector

getPropertyNamesImpl

protected java.lang.String[] getPropertyNamesImpl(java.lang.Object bean)
                                           throws java.lang.Exception
Template method must be overridden. Implementation of BeanReflector.getPropertyNames(Object). Implementation automatically provided for IndexedContainerReflectors. For other reflectors, throws an UnsupportedOperationException.

Specified by:
getPropertyNamesImpl in class BaseBeanReflector
Throws:
java.lang.Exception

getTypeImpl

protected java.lang.Class getTypeImpl(java.lang.Object bean,
                                      java.lang.String propertyName)
                               throws java.lang.Exception
Returns the type of the property based on the parameter type for the property's setter method. If there is no setter method available, returns the return type of the property accessor method.

Specified by:
getTypeImpl in class BaseBeanReflector
Throws:
java.lang.Exception

isReadableImpl

protected boolean isReadableImpl(java.lang.Object bean,
                                 java.lang.String propertyName)
                          throws java.lang.Exception
Implementation of BeanReflector.isReadable(Object, String). Default implementation assumes that all properties of the bean specified by BeanReflector.getPropertyNames(Object) are readable.

Overrides:
isReadableImpl in class BaseReflector
Throws:
java.lang.Exception

isWriteableImpl

protected boolean isWriteableImpl(java.lang.Object bean,
                                  java.lang.String propertyName)
                           throws java.lang.Exception
Implementation of 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.

Overrides:
isWriteableImpl in class BaseReflector
Throws:
java.lang.Exception

getImpl

protected java.lang.Object getImpl(java.lang.Object bean,
                                   java.lang.String propertyName)
                            throws java.lang.Exception
Retrieves the value of the property propertyName in bean bean. If the property is an indexed property that is only accessible via an indexed getter method of the form get(int), this implementation is O(n). Otherwise, this implementation is O(1).

Specified by:
getImpl in class BaseBeanReflector
Throws:
java.lang.Exception

setImpl

protected void setImpl(java.lang.Object bean,
                       java.lang.String propertyName,
                       java.lang.Object value)
                throws java.lang.Exception
Template method must be overridden. Implementation of BeanReflector.set(Object, String, Object). Implementation automatically provided for MutableIndexedContainerReflectors. For other reflectors, throws an UnsupportedOperationException.

Specified by:
setImpl in class BaseBeanReflector
Throws:
java.lang.Exception

newInstanceImpl

protected java.lang.Object newInstanceImpl(java.lang.Class clazz,
                                           java.lang.Object parameters)
                                    throws java.lang.Exception
Implementation of InstantiatingReflector.newInstance(Class, Object). Default implementation returns a new instance of the given class by calling Class#newInstance()).

Overrides:
newInstanceImpl in class BaseReflector
Throws:
java.lang.Exception

getContainedTypeImpl

protected java.lang.Class getContainedTypeImpl(java.lang.Class clazz)
                                        throws java.lang.Exception
Implementation of ContainerReflector.getContainedType(Class).

Overrides:
getContainedTypeImpl in class BaseReflector
Throws:
java.lang.Exception

getIteratorImpl

protected java.util.Iterator getIteratorImpl(java.lang.Object container)
                                      throws java.lang.Exception
Implementation of ContainerReflector.getIterator(Object).

Overrides:
getIteratorImpl in class BaseReflector
Throws:
java.lang.Exception

isPrimitiveSetter

protected boolean isPrimitiveSetter(java.lang.Object bean,
                                    java.lang.String propertyName)
                             throws java.lang.Exception
Learn whether the mutator/setter method for the given property is primitive.

Parameters:
bean -
propertyName -
Returns:
boolean
Throws:
java.lang.Exception

getReflectionInfo

protected ReflectionInfo getReflectionInfo(java.lang.Class clazz)
Get the ReflectionInfo for the given Class.

Parameters:
clazz -
Returns:
ReflectionInfo

isStrictlyTyped

public boolean isStrictlyTyped()
Returns true.

Overrides:
isStrictlyTyped in class BaseReflector
Returns:
true

isAllowNullPrimitiveAssignment

public boolean isAllowNullPrimitiveAssignment()
Indicates whether primitive assignments to null are allowed. If they are allowed, primitive assignments to null will be ignored. If they are not allowed, a ReflectionException will be thrown.

Returns:
whether primitive assignments to null are allowed

setAllowNullPrimitiveAssignment

public void setAllowNullPrimitiveAssignment(boolean allowNullPrimitiveAssignment)
Sets whether primitive assignments to null are allowed. If they are allowed, primitive assignments to null will be ignored. If they are not allowed, a ReflectionException will be thrown.

Parameters:
allowNullPrimitiveAssignment - whether primitive assignments to null are allowed


Copyright © 2004-2008.