org.pfsw.reflect
Class MappedObject

java.lang.Object
  extended by org.pfsw.reflect.MappedObject
All Implemented Interfaces:
java.util.Map<java.lang.String,java.lang.Object>

public class MappedObject
extends java.lang.Object
implements java.util.Map<java.lang.String,java.lang.Object>

This is a wrapper for an arbitrary object to allow accessing its field through the Map interface where the field names are the keys.

The contained object can be replaced whenever needed.


Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Constructor Summary
MappedObject(java.lang.Object object)
          Creates an instance on the given object and ignores problems silently.
MappedObject(java.lang.Object object, boolean silent)
          Creates an instance on the given object and handles problems silently if silent is true, otherwise problems will cause a ReflectionException.
 
Method Summary
 void clear()
          Does nothing.
 boolean containsKey(java.lang.Object fieldName)
           
 boolean containsValue(java.lang.Object value)
           
 java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> entrySet()
           
 java.lang.Object get(java.lang.Object fieldName)
           
protected  FieldProxy<java.lang.Object> getFieldAccessor(java.lang.String fieldName)
           
protected  java.util.Map<java.lang.String,FieldProxy<java.lang.Object>> getFieldAccessors()
           
 java.lang.Object getObject()
          Returns the original object wrapped by this to a Map interface.
 java.lang.Class<?> getObjectType()
          Returns the type of the wrapped object.
protected  void handleProblem(java.lang.String message, java.lang.Object... args)
          Ignores the problem if silent=true, otherwise throws a ReflectionException.
protected  void initFieldAccessors()
           
 boolean isEmpty()
           
 boolean isNull()
          Returns whether or not the underlying object is null.
 boolean isSilent()
          Returns true if this object has been configured to ignore exceptions silently.
 java.util.Set<java.lang.String> keySet()
          Returns all field names of the underlying object.
 java.lang.Object put(java.lang.String fieldName, java.lang.Object value)
           
 void putAll(java.util.Map<? extends java.lang.String,? extends java.lang.Object> map)
           
 java.lang.Object remove(java.lang.Object fieldName)
          Returns the value for the given fieldName, but does not remove anything.
 void setObject(java.lang.Object object)
          Sets the object to be wrapped for allowing it being used as Map.
protected  void setSilent(boolean silent)
           
 int size()
           
 java.util.Collection<java.lang.Object> values()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

MappedObject

public MappedObject(java.lang.Object object)
Creates an instance on the given object and ignores problems silently.

Parameters:
object - The object to be wrapped (may be null).

MappedObject

public MappedObject(java.lang.Object object,
                    boolean silent)
Creates an instance on the given object and handles problems silently if silent is true, otherwise problems will cause a ReflectionException.

Parameters:
object - The object to be wrapped (may be null).
silent - Defines whether or not problems should silently be ignored.
Method Detail

getObject

public java.lang.Object getObject()
Returns the original object wrapped by this to a Map interface.


setObject

public void setObject(java.lang.Object object)
Sets the object to be wrapped for allowing it being used as Map.

Parameters:
object - The object to be wrapped (may be null).

getObjectType

public java.lang.Class<?> getObjectType()
Returns the type of the wrapped object. In the case of null object it returns Void.TYPE.


get

public java.lang.Object get(java.lang.Object fieldName)
Specified by:
get in interface java.util.Map<java.lang.String,java.lang.Object>

put

public java.lang.Object put(java.lang.String fieldName,
                            java.lang.Object value)
Specified by:
put in interface java.util.Map<java.lang.String,java.lang.Object>

putAll

public void putAll(java.util.Map<? extends java.lang.String,? extends java.lang.Object> map)
Specified by:
putAll in interface java.util.Map<java.lang.String,java.lang.Object>

keySet

public java.util.Set<java.lang.String> keySet()
Returns all field names of the underlying object.

Specified by:
keySet in interface java.util.Map<java.lang.String,java.lang.Object>

entrySet

public java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> entrySet()
Specified by:
entrySet in interface java.util.Map<java.lang.String,java.lang.Object>

values

public java.util.Collection<java.lang.Object> values()
Specified by:
values in interface java.util.Map<java.lang.String,java.lang.Object>

containsValue

public boolean containsValue(java.lang.Object value)
Specified by:
containsValue in interface java.util.Map<java.lang.String,java.lang.Object>

containsKey

public boolean containsKey(java.lang.Object fieldName)
Specified by:
containsKey in interface java.util.Map<java.lang.String,java.lang.Object>

size

public int size()
Specified by:
size in interface java.util.Map<java.lang.String,java.lang.Object>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Map<java.lang.String,java.lang.Object>

remove

public java.lang.Object remove(java.lang.Object fieldName)
Returns the value for the given fieldName, but does not remove anything. Actually this method works identical to get(Object).

Specified by:
remove in interface java.util.Map<java.lang.String,java.lang.Object>
Throws:
ReflectionException - if the filed cannot be found and silent is false.

clear

public void clear()
Does nothing.

Specified by:
clear in interface java.util.Map<java.lang.String,java.lang.Object>

isNull

public boolean isNull()
Returns whether or not the underlying object is null.


isSilent

public boolean isSilent()
Returns true if this object has been configured to ignore exceptions silently.


getFieldAccessor

protected FieldProxy<java.lang.Object> getFieldAccessor(java.lang.String fieldName)

initFieldAccessors

protected void initFieldAccessors()

handleProblem

protected void handleProblem(java.lang.String message,
                             java.lang.Object... args)
Ignores the problem if silent=true, otherwise throws a ReflectionException.


setSilent

protected void setSilent(boolean silent)

getFieldAccessors

protected java.util.Map<java.lang.String,FieldProxy<java.lang.Object>> getFieldAccessors()