org.ops4j.pax.reflector.spi
Interface TypeHandler

All Known Implementing Classes:
AbstractObjectTypeHandler, ArrayTypeHandler, CollectionTypeHandler, DictionaryTypeHandler, MapTypeHandler, ObjectTypeHandler

public interface TypeHandler

TypeHandler interface which allows for extending the special types handling.

A TypeHandler is reponsible for resolving names, retrieval and settings of the members of a container of a particular type.

A TypeHandler implementation is free to obtain the information in any way it wishes, but all default types are using the Java Reflection API to do so, in various ways.


Method Summary
 boolean canHandle(Object container)
          A query method made by the ReflectorService implementation to determine if this TypeHandler should be used for the provided container.
 Class getMemberClass(Object container, String memberName)
          Returns the Class of the member.
 String[] getMemberNames(Object container)
          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.
 

Method Detail

getSystemSettings

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

Returns:
The SystemSettings instance that has previously been set.

setSystemSettings

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

Parameters:
settings - The SystemSettings currently in use.

canHandle

boolean canHandle(Object container)
A query method made by the ReflectorService implementation to determine if this TypeHandler should be used for the provided container.

If the 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.

Parameters:
container - The container that is being tested.
Returns:
true if this TypeHandler is capable of dealing with the provided container, otherwise false.

getMemberNames

String[] getMemberNames(Object container)
                        throws IllegalArgumentException
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.

Parameters:
container - the container to query for the names.
Returns:
The names of the members in the container object.
Throws:
IllegalArgumentException - If the TypeHandler does not support the container type provided.

getMemberObject

Object getMemberObject(Object container,
                       String membername)
                       throws ReflectionException
Returns the object that is assigned to the member of the provided container.

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

void setMemberObject(Object container,
                     String membername,
                     Object value)
                     throws ReflectionException
Sets the member of a container to the provided value.

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

Class getMemberClass(Object container,
                     String memberName)
                     throws ReflectionException
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.

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

boolean isMemberSettable(Object container,
                         String memberName)
                         throws ReflectionException
Returns true if the member is settable.

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

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

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.