net.sf.morph.reflect.reflectors
Class MapReflector

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

public class MapReflector
extends BaseReflector
implements InstantiatingReflector, SizableReflector, GrowableContainerReflector, BeanReflector

Reflector for Maps that allows a map to be treated both as a container and as a bean.

Since:
Nov 27, 2004
Author:
Matt Sgarlata

Field Summary
static java.lang.String DEFAULT_MAP_TREATMENT
          The default treatment for Maps (which is to extract the values in the Map).
static java.lang.String EXTRACT_ENTRIES
          Indicates that the entrySet of the source map should be copied to the destination container object.
static java.lang.String EXTRACT_KEYS
          Indicates that the keySet of the source map should be copied to the destination container object.
static java.lang.String EXTRACT_VALUES
          Indicates that the values of the source map should be copied to the destination container object.
static java.lang.String IMPLICIT_PROPERTY_ENTRIES
          Implicit entries property
static java.lang.String IMPLICIT_PROPERTY_KEYS
          Implicit keys property
static java.lang.String IMPLICIT_PROPERTY_VALUES
          Implicit values property
protected static java.lang.String[] MAP_TREATMENTS
          All of the allowed map treatments.
 
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
 
Constructor Summary
MapReflector()
          Create a new MapReflector using the default map treatment.
MapReflector(java.lang.String mapTreatment)
          Create a new MapReflector.
 
Method Summary
protected  boolean addImpl(java.lang.Object container, java.lang.Object value)
          Implementation of GrowableContainer.add(Object).
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)
          Implementation of BeanReflector.get(Object, String).
protected  java.util.Iterator getIteratorImpl(java.lang.Object container)
          Implementation of ContainerReflector.getIterator(Object).
protected  java.util.Map getMap(java.lang.Object container)
          Get the specified container as a Map.
 java.lang.String getMapTreatment()
          Get the map treatment in use.
protected  java.lang.String[] getPropertyNamesImpl(java.lang.Object bean)
          Implementation of BeanReflector.getPropertyNames(Object).
 java.lang.Class[] getReflectableClassesImpl()
          Implementation of Reflector.getReflectableClasses().
protected  int getSizeImpl(java.lang.Object container)
          Implementation of SizableReflector.getSize(Object).
protected  java.lang.Class getTypeImpl(java.lang.Object bean, java.lang.String propertyName)
          Implementation of BeanReflector.getType(Object, String).
 boolean isExtractEntries()
          Learn whether this reflector extracts map entries.
 boolean isExtractKeys()
          Learn whether this reflector extracts map keys.
 boolean isExtractValues()
          Learn whether this reflector extracts map values.
protected  boolean isReadableImpl(java.lang.Object bean, java.lang.String propertyName)
          Implementation of BeanReflector.isReadable(Object, String).
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 interfaceClass, java.lang.Object parameters)
          Implementation of InstantiatingReflector.newInstance(Class, Object).
protected  void setImpl(java.lang.Object bean, java.lang.String propertyName, java.lang.Object value)
          Implementation of BeanReflector.set(Object, String, Object).
 void setMapTreatment(java.lang.String mapTreatment)
          Sets how maps are treated by this reflector.
 
Methods inherited from class net.sf.morph.reflect.reflectors.BaseReflector
add, checkIndex, checkIsReflectable, createWrapperInvocationHandler, get, get, getContainedType, getImpl, getIterator, getPropertyNames, getReflectableCallCache, getReflectableClasses, getReflectorName, getSize, getType, getWrapper, getWrapperImpl, initialize, initializeImpl, isCachingIsReflectableCalls, isInitialized, isPerformingLogging, isReadable, isReflectable, isReflectable, isReflectableImpl, isReflectableImpl, isStrictlyTyped, 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.GrowableContainerReflector
add
 
Methods inherited from interface net.sf.morph.reflect.ContainerReflector
getContainedType, getIterator
 
Methods inherited from interface net.sf.morph.reflect.BeanReflector
get, getPropertyNames, getType, isReadable, isWriteable, set
 

Field Detail

IMPLICIT_PROPERTY_ENTRIES

public static final java.lang.String IMPLICIT_PROPERTY_ENTRIES
Implicit entries property

See Also:
Constant Field Values

IMPLICIT_PROPERTY_KEYS

public static final java.lang.String IMPLICIT_PROPERTY_KEYS
Implicit keys property

See Also:
Constant Field Values

IMPLICIT_PROPERTY_VALUES

public static final java.lang.String IMPLICIT_PROPERTY_VALUES
Implicit values property

See Also:
Constant Field Values

EXTRACT_VALUES

public static final java.lang.String EXTRACT_VALUES
Indicates that the values of the source map should be copied to the destination container object.

See Also:
Map.values(), Constant Field Values

EXTRACT_ENTRIES

public static final java.lang.String EXTRACT_ENTRIES
Indicates that the entrySet of the source map should be copied to the destination container object. For example, if the destination container object is a List, then each Map.Entry in the source map will be copied to the destination List

See Also:
Map.entrySet(), Constant Field Values

EXTRACT_KEYS

public static final java.lang.String EXTRACT_KEYS
Indicates that the keySet of the source map should be copied to the destination container object. For example, if the destination container object is a List, then each key in the source map will be copied to the destination List.

See Also:
Map.keySet(), Constant Field Values

DEFAULT_MAP_TREATMENT

public static final java.lang.String DEFAULT_MAP_TREATMENT
The default treatment for Maps (which is to extract the values in the Map).

See Also:
ContainerCopier#EXTRACT_VALUES, Constant Field Values

MAP_TREATMENTS

protected static java.lang.String[] MAP_TREATMENTS
All of the allowed map treatments.

Constructor Detail

MapReflector

public MapReflector()
Create a new MapReflector using the default map treatment.


MapReflector

public MapReflector(java.lang.String mapTreatment)
Create a new MapReflector.

Parameters:
mapTreatment - to use
Method Detail

getMap

protected java.util.Map getMap(java.lang.Object container)
Get the specified container as a Map.

Parameters:
container - to get
Returns:
Map

getSizeImpl

protected int getSizeImpl(java.lang.Object container)
                   throws java.lang.Exception
Implementation of SizableReflector.getSize(Object).

Overrides:
getSizeImpl 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

getReflectableClassesImpl

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

Specified by:
getReflectableClassesImpl in class BaseReflector

newInstanceImpl

protected java.lang.Object newInstanceImpl(java.lang.Class interfaceClass,
                                           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

addImpl

protected boolean addImpl(java.lang.Object container,
                          java.lang.Object value)
                   throws java.lang.Exception
Implementation of GrowableContainer.add(Object).

Overrides:
addImpl 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

getPropertyNamesImpl

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

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

getTypeImpl

protected java.lang.Class getTypeImpl(java.lang.Object bean,
                                      java.lang.String propertyName)
                               throws java.lang.Exception
Implementation of 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 BaseReflector.get(Object, String).

Overrides:
getTypeImpl in class BaseReflector
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
Implementation of BeanReflector.get(Object, String). Implementation automatically provided for IndexedContainerReflectors. For other reflectors, throws an UnsupportedOperationException.

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

setImpl

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

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

getMapTreatment

public java.lang.String getMapTreatment()
Get the map treatment in use.

Returns:
String

setMapTreatment

public void setMapTreatment(java.lang.String mapTreatment)
                     throws ReflectionException
Sets how maps are treated by this reflector.

Parameters:
mapTreatment - how maps are treated by this reflector
Throws:
ReflectionException - if an invalid map treatment is specified

isExtractEntries

public boolean isExtractEntries()
Learn whether this reflector extracts map entries.

Returns:
boolean

isExtractKeys

public boolean isExtractKeys()
Learn whether this reflector extracts map keys.

Returns:
boolean

isExtractValues

public boolean isExtractValues()
Learn whether this reflector extracts map values.

Returns:
boolean


Copyright © 2004-2008.