org.ops4j.pax.reflector.typehandlers
Class MapTypeHandler

java.lang.Object
  extended by org.ops4j.pax.reflector.typehandlers.MapTypeHandler
All Implemented Interfaces:
TypeHandler

public final class MapTypeHandler
extends Object
implements TypeHandler


Field Summary
protected  SystemSettings m_SystemSettings
           
 
Constructor Summary
MapTypeHandler()
           
 
Method Summary
 boolean canHandle(Object container)
          Query if this TypeHandler can deal with the container argument.
 Class getMemberClass(Object container, String membername)
          Returns the Class of the member.
 String[] getMemberNames(Object object)
          Returns the names of all the accessible members in the container.
 Object getMemberObject(Object container, String membername)
          Returns the object that is assigned to the member of the provided container.
 String getSeparator()
          Returns the separator string between container part and the name part.
 SystemSettings getSystemSettings()
          Returns the System Settings that has been set to the TypeHandler.
 boolean isMemberSettable(Object container, String membername)
          Returns true if the member is settable.
 void setMemberObject(Object container, String membername, Object value)
          Sets the member of a container to the provided value.
 void setSystemSettings(SystemSettings settings)
          Sets the SystemSettings to this TypeHandler.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_SystemSettings

protected SystemSettings m_SystemSettings
Constructor Detail

MapTypeHandler

public MapTypeHandler()
Method Detail

getSystemSettings

public SystemSettings getSystemSettings()
Returns the System Settings that has been set to the TypeHandler.

Specified by:
getSystemSettings in interface TypeHandler
Returns:
The SystemSettings instance that has previously been set.

setSystemSettings

public void setSystemSettings(SystemSettings settings)
Sets the SystemSettings to this TypeHandler. This method is called when the TypeHandler is added to the ReflectorService.

Specified by:
setSystemSettings in interface TypeHandler
Parameters:
settings - The SystemSettings currently in use.

canHandle

public boolean canHandle(Object container)
Query if this TypeHandler can deal with the container argument.

If this TypeHandler is not able to handle the provided container the ReflectorProvider implementation must continue to query the lower priority TypeHandlers. It is important that there is a TypeHandler that can handle "everything else", if this query falls through all the way.

The implementation in this class does;

   return container instanceof Map;
 
to determine if the container can be handled by this TypeHandler.

Specified by:
canHandle in interface TypeHandler
Parameters:
container - The container that is being tested.
Returns:
true if this TypeHandler is capable of handling the provided container, false otherwise.

getMemberNames

public String[] getMemberNames(Object object)
Returns the names of all the accessible members in the container.

The names returned are in such format that they can be appended to the container, after a getSeparator() string.

This TypeHandler treats the keys in the Map as the member names and return those. The order is determined by the Map itself, as the members are fetched via;

   Iterator it = container.keySet().iterator();
 

Specified by:
getMemberNames in interface TypeHandler
Parameters:
object - the container to query for the names.
Returns:
The names of the members in the container object.

getMemberObject

public Object getMemberObject(Object container,
                              String membername)
                       throws ReflectionException
Description copied from interface: TypeHandler
Returns the object that is assigned to the member of the provided container.

Specified by:
getMemberObject in interface TypeHandler
Parameters:
container - The container that is being queried.
membername - The name of the member for which the value is requested.
Returns:
The object assigned to the member of the container.
Throws:
ReflectionException - if a member with the provided name does not exist, or if an exception is thrown while accessing the container.

setMemberObject

public void setMemberObject(Object container,
                            String membername,
                            Object value)
                     throws ReflectionException
Description copied from interface: TypeHandler
Sets the member of a container to the provided value.

Specified by:
setMemberObject in interface TypeHandler
Parameters:
container - The container that is being queried.
membername - The name of the member to have the value set to.
value - The value object to be assigned to the member of the container.
Throws:
ReflectionException - if a member with the provided name does not exist, or if an exception is thrown while accessing the container.

getMemberClass

public Class getMemberClass(Object container,
                            String membername)
                     throws ReflectionException
Description copied from interface: TypeHandler
Returns the Class of the member.

The Class return is the type of the field or return type of the member and not the Class of the assigned object to that member.

Specified by:
getMemberClass in interface TypeHandler
Parameters:
container - The container that is being queried.
membername - The member of the container, for which the Class is to be return.
Returns:
The Class of the member in the provided container.
Throws:
ReflectionException

isMemberSettable

public boolean isMemberSettable(Object container,
                                String membername)
                         throws ReflectionException
Description copied from interface: TypeHandler
Returns true if the member is settable.

Specified by:
isMemberSettable in interface TypeHandler
Parameters:
container - The container of interest.
membername - The name of the member in the provided container to be checked for if it is settable.
Returns:
true if the member can be set by calling setMemberObject().
Throws:
ReflectionException

getSeparator

public String getSeparator()
Returns the separator string between container part and the name part.

This implementation returns an empty String.

Specified by:
getSeparator in interface TypeHandler
Returns:
the String used to separate the container from the name. Typically this is a dot '.', but can be others including an empty string.


Copyright © 2006-2012 OPS4J - Open Participation Software for Java. All Rights Reserved.