org.ops4j.pax.reflector.impl
Class ReflectorImpl

java.lang.Object
  extended by org.ops4j.pax.reflector.impl.ReflectorImpl
All Implemented Interfaces:
ReflectorService, ReflectorProvider

public final class ReflectorImpl
extends Object
implements ReflectorService, ReflectorProvider

The Reflector Implementation is capable of digging through any Java application that is added as a root object.


Method Summary
 void addRootObject(String name, Object obj)
          Adds a Root Object to the Reflector instance.
 void addTypeHandler(TypeHandler handler)
          Adds a TypeHandler.
 String append(Object container, String containerpart, String namepart)
          Appends the name to the container name.
 void dispose()
           
 String extractContainerPart(String objectname)
          Returns the container part of the objectname.
 String extractNamePart(String objectname)
          Returns the Name part of the objectname.
 String[] getAllRootNames()
           
 String getMember(String object)
          Returns the human readable form of the object instance traversed from the objectname argument.
 Class getMemberClass(Object container, String memberName)
          Returns the Class of the member identified by the membername in the provided container.
 Class getMemberClass(String name)
          Returns the Class of the member identified by the membername argument.
 String getMemberClassName(Object container, String memberName)
          Returns the name of the Class of the member identified by the membername in the provided container.
 String getMemberClassName(String name)
          Returns the name of the Class of the member identified by the objectname argument.
 String[] getMemberNames(Object container)
          Returns all the membernames found in the object.
 String[] getMemberNames(String object)
          Returns all the membernames found in the member identified by membername argument.
 Object getMemberObject(Object container, String memberName)
          Returns the object of the member by the given membername, starting at the provided container.
 Object getMemberObject(String object)
          Returns the object of the member by the given membername.
 Object getRootObject(String name)
           
 Map getRootObjects()
           
 List<TypeHandler> getTypeHandlers()
           
 boolean isMemberSettable(Object container, String memberName)
          Checks with the member of the given membername can be set to a value.
 boolean isMemberSettable(String name)
          Checks with the member of the given objectname can be set to a value.
static ReflectorImpl newInstance()
           
 void removeRootObject(String name)
          Removes the root object with registered under the provided name.
 void removeTypeHandler(TypeHandler handler)
          Removes a TypeHandler from the ReflectorProvider.
 void setMember(String object, String value)
          Assigns the value to the member identified by the membername argument.
 void setMemberObject(Object container, String member, Object value)
          Assigns the value to the member identified by the membername starting at the container object.
 void setMemberObject(String objectname, Object object)
          Assigns the value to the member identified by the membername argument.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newInstance

public static ReflectorImpl newInstance()

getTypeHandlers

public List<TypeHandler> getTypeHandlers()

addTypeHandler

public void addTypeHandler(TypeHandler handler)
Description copied from interface: ReflectorProvider
Adds a TypeHandler.

TypeHandlers must be added in the priority order with the least high priority first, such as the default ObjectTypeHandler, and highly specialized type handlers last.

There is no support for adding a lower priority TypeHandler after a higher priority one.

Specified by:
addTypeHandler in interface ReflectorProvider
Parameters:
handler - The TypeHandler to be added.

removeTypeHandler

public void removeTypeHandler(TypeHandler handler)
Description copied from interface: ReflectorProvider
Removes a TypeHandler from the ReflectorProvider.

Specified by:
removeTypeHandler in interface ReflectorProvider
Parameters:
handler - The TypeHandler instance to be removed.

addRootObject

public void addRootObject(String name,
                          Object obj)
Description copied from interface: ReflectorService
Adds a Root Object to the Reflector instance.

The name must also be unique and no other root object may have been registered with the same name. The ReflectorService will hold on to the root objects with a hard reference, so it is imperative that objects are removed explicitly with a removeRootObject() method call.

Specified by:
addRootObject in interface ReflectorService
Parameters:
name - The name of the Root Object. The name may only contain valid Java characters, as reported by Character.isJavaIdentifierPart(char ch).
obj - The object instance to be registered at the provided name.

removeRootObject

public void removeRootObject(String name)
Description copied from interface: ReflectorService
Removes the root object with registered under the provided name.

If there is no root object registered under the provided name, this method will simply return.

Specified by:
removeRootObject in interface ReflectorService
Parameters:
name - The name under which the root object was previously registered.

getRootObject

public Object getRootObject(String name)

getRootObjects

public Map getRootObjects()

getAllRootNames

public String[] getAllRootNames()

getMemberNames

public String[] getMemberNames(String object)
                        throws ReflectionException
Description copied from interface: ReflectorService
Returns all the membernames found in the member identified by membername argument.

If the membername is an empty string, all root object names are returned.

Specified by:
getMemberNames in interface ReflectorService
Parameters:
object - The name of the member to query for its members.
Returns:
The members that are found in the object identified by membername.
Throws:
ReflectionException - If the member identified by the membername does not exist.

getMemberNames

public String[] getMemberNames(Object container)
Description copied from interface: ReflectorService
Returns all the membernames found in the object.

Specified by:
getMemberNames in interface ReflectorService
Parameters:
container - The Java instance to query for its members.
Returns:
The members that are found in the object.

getMember

public String getMember(String object)
                 throws ReflectionException
Description copied from interface: ReflectorService
Returns the human readable form of the object instance traversed from the objectname argument.

Specified by:
getMember in interface ReflectorService
Parameters:
object - The name of the object of interested.
Returns:
The toString() value of the member value object.
Throws:
ReflectionException - if the member does not exist.

setMember

public void setMember(String object,
                      String value)
               throws ReflectionException
Description copied from interface: ReflectorService
Assigns the value to the member identified by the membername argument.

Specified by:
setMember in interface ReflectorService
Parameters:
object - The name of the member to be assigned a value.
value - The value to be assigned to the member. For primitives, the value is converted according to normal Java rules, but additionally a fully-qualified classname can be given, in which case the reflector will try to instantiate such class through the default constructor, and if successful assign the instance to the member.
Throws:
ReflectionException - If the value is not assignable to the member type or the member does not exist.

getMemberObject

public Object getMemberObject(String object)
                       throws ReflectionException
Description copied from interface: ReflectorService
Returns the object of the member by the given membername.

Specified by:
getMemberObject in interface ReflectorService
Parameters:
object - The name of the object to traverse to and return.
Returns:
The object that is returned as the value of the member, either by getter, fields or special handling, such as the value of entries of Maps and Collections.
Throws:
ReflectionException - if the member does not exist.

getMemberObject

public Object getMemberObject(Object container,
                              String memberName)
                       throws ReflectionException
Description copied from interface: ReflectorService
Returns the object of the member by the given membername, starting at the provided container.

Specified by:
getMemberObject in interface ReflectorService
Parameters:
container - The object which has a member of the memberName.
memberName - The name of the object to traverse to and return.
Returns:
The object that is returned as the value of the member, either by getter, fields or special handling, such as the value of entries of Maps and Collections.
Throws:
ReflectionException - if the member does not exist.

setMemberObject

public void setMemberObject(String objectname,
                            Object object)
                     throws ReflectionException
Description copied from interface: ReflectorService
Assigns the value to the member identified by the membername argument.

Specified by:
setMemberObject in interface ReflectorService
Parameters:
objectname - The name of the member to be assigned a value.
object - The value to be assigned to the member.
Throws:
ReflectionException - If the value is not assignable to the member type.

setMemberObject

public void setMemberObject(Object container,
                            String member,
                            Object value)
                     throws ReflectionException
Description copied from interface: ReflectorService
Assigns the value to the member identified by the membername starting at the container object.

Specified by:
setMemberObject in interface ReflectorService
Parameters:
container - The object which has a member of the memberName.
member - The name of the member to be assigned a value.
value - The value to be assigned to the member.
Throws:
ReflectionException - If the value is not assignable to the member type.

extractContainerPart

public String extractContainerPart(String objectname)
Description copied from interface: ReflectorService
Returns the container part of the objectname.

This method must correctly return the container part of the full objectname. For instance; getContainerPart( "someRoot.Abc.Def" ), must return "someRoot.Abc", getContainerPart( "someRoot.Abc['Def']" ), must return "someRoot.Abc", and getContainerPart( "someRoot.Abc['Def'].Rst" ), must return "someRoot.Abc['Def']".

Specified by:
extractContainerPart in interface ReflectorService
Parameters:
objectname - The objectname to be worked upon.
Returns:
The container part of the objectname.

extractNamePart

public String extractNamePart(String objectname)
Description copied from interface: ReflectorService
Returns the Name part of the objectname.

This method must correctly return the Name part of the full objectname. For instance; getContainerPart( "someRoot.Abc.Def" ), must return "Def", getContainerPart( "someRoot.Abc['Def']" ), must return "['Def']", and getContainerPart( "someRoot.Abc['Def'].Rst" ), must return "Rst".

Specified by:
extractNamePart in interface ReflectorService
Parameters:
objectname - The objectname to be worked upon.
Returns:
The name part of the objectname.

append

public String append(Object container,
                     String containerpart,
                     String namepart)
Description copied from interface: ReflectorService
Appends the name to the container name.

Specified by:
append in interface ReflectorService
Parameters:
container - The actual container so that the type can be determined.
containerpart - The name of the container.
namepart - The name part to append to the containerpart.
Returns:
The container+containerpart+namepart appended together in a safe manner.

getMemberClassName

public String getMemberClassName(String name)
                          throws ReflectionException
Description copied from interface: ReflectorService
Returns the name of the Class of the member identified by the objectname argument.

Specified by:
getMemberClassName in interface ReflectorService
Parameters:
name - The name of the member to query for its Class.
Returns:
The name of the Class of the named object.
Throws:
ReflectionException - if the named object does not exist.

getMemberClassName

public String getMemberClassName(Object container,
                                 String memberName)
                          throws ReflectionException
Description copied from interface: ReflectorService
Returns the name of the Class of the member identified by the membername in the provided container.

Specified by:
getMemberClassName in interface ReflectorService
Parameters:
container - The object which has a member of the memberName.
memberName - The name of the member of the container to query for its Class.
Returns:
The name of the Class of the object instance identified by the objectname in the container.
Throws:
ReflectionException - if the objectname does not exist as a member in the container.

getMemberClass

public Class getMemberClass(String name)
                     throws ReflectionException
Description copied from interface: ReflectorService
Returns the Class of the member identified by the membername argument.

Specified by:
getMemberClass in interface ReflectorService
Parameters:
name - The name of the object to query for its Class.
Returns:
The class of the named object.
Throws:
ReflectionException - if the named object does not exist.

getMemberClass

public Class getMemberClass(Object container,
                            String memberName)
                     throws ReflectionException
Description copied from interface: ReflectorService
Returns the Class of the member identified by the membername in the provided container.

Specified by:
getMemberClass in interface ReflectorService
Parameters:
container - The object which has a member of the memberName.
memberName - The name of the member of the container to query for its Class.
Returns:
The class of the named object.
Throws:
ReflectionException - if the named object does not exist.

isMemberSettable

public boolean isMemberSettable(String name)
                         throws ReflectionException
Description copied from interface: ReflectorService
Checks with the member of the given objectname can be set to a value.

Specified by:
isMemberSettable in interface ReflectorService
Parameters:
name - The member to be tested if it can be set by a setMemberObject() method call.
Returns:
true if the object identified by the objectname can be set.
Throws:
ReflectionException - if the objectname does not identify an existing object reference.

isMemberSettable

public boolean isMemberSettable(Object container,
                                String memberName)
                         throws ReflectionException
Description copied from interface: ReflectorService
Checks with the member of the given membername can be set to a value.

Specified by:
isMemberSettable in interface ReflectorService
Parameters:
container - The container from where we should test if a member can be set to a value, by calling the setMemberObject() method.
memberName - The member in the provided container to be tested if it can be set by a setMemberObject() method call.
Returns:
true if the object identified by the membername can be set in the container.
Throws:
ReflectionException - if the membername does not exist as a member in the container.

dispose

public void dispose()


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