|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface ReflectorService
The ReflectorService allows you to traverse object instances in a running application.
The ReflectorService operates with a cascaded dot-notation to identify object instances in
running memory. That means that by providing a name such as "abc.Def.Rst.Name" the equivalent
of (provided no special TypeHandlers kick in);
is called, if the JavaBeans-styled accessor methods are found. Also, public member fields will
also be looked for (higer priority) and accessed when possible.
abc.getDef().getRst().getName()
Examples of syntaxes, and equivalents in direct Java code.
dot notation | Java | Comment |
---|---|---|
someRoot.Abc | someRoot.getAbc() | |
someRoot.Abc.Def | someRoot.getAbc().getDef() | |
someRoot.Abc['0'] | someRoot.getAbc()[0] | If getAbc() returns an Array. |
someRoot.Abc['0'] | someRoot.getAbc().getAt(0) | If getAbc() returns a Collection |
someRoot.Abc['Def'] | someRoot.getAbc().get("Def") | If getAbc() returns a Map or Dictionary. |
someRoot.Abc['0'].Rst | someRoot.getAbc().getAt(0).getRst() | If getAbc() returns a Collection |
someRoot.Abc['Def'].Rst | someRoot.getAbc().get("Def").getRst() | If getAbc() returns a Map or Dictionary. |
empty string | Only valid for getMemberNames() which will return all root object names. |
Method Summary | |
---|---|
void |
addRootObject(String name,
Object object)
Adds a Root Object to the Reflector instance. |
String |
append(Object container,
String containerpart,
String namepart)
Appends the name to the container name. |
String |
extractContainerPart(String objectname)
Returns the container part of the objectname. |
String |
extractNamePart(String objectname)
Returns the Name part of the objectname. |
String |
getMember(String membername)
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 objectname)
Returns the Class of the member identified by the membername argument. |
String |
getMemberClassName(Object container,
String objectname)
Returns the name of the Class of the member identified by the membername in the provided
container . |
String |
getMemberClassName(String objectname)
Returns the name of the Class of the member identified by the objectname argument. |
String[] |
getMemberNames(Object object)
Returns all the membernames found in the object . |
String[] |
getMemberNames(String membername)
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 membername)
Returns the object of the member by the given membername. |
boolean |
isMemberSettable(Object container,
String membername)
Checks with the member of the given membername can be set to a value. |
boolean |
isMemberSettable(String objectname)
Checks with the member of the given objectname can be set to a value. |
void |
removeRootObject(String name)
Removes the root object with registered under the provided name. |
void |
setMember(String membername,
String value)
Assigns the value to the member identified by the membername argument. |
void |
setMemberObject(Object container,
String memberName,
Object value)
Assigns the value to the member identified by the membername starting at the
container object. |
void |
setMemberObject(String membername,
Object value)
Assigns the value to the member identified by the membername argument. |
Method Detail |
---|
String getMember(String membername) throws ReflectionException
objectname
argument.
membername
- The name of the object of interested.
ReflectionException
- if the member does not exist.Object getMemberObject(String membername) throws ReflectionException
membername
- The name of the object to traverse to and return.
ReflectionException
- if the member does not exist.Object getMemberObject(Object container, String memberName) throws ReflectionException
container
- The object which has a member of the memberName.memberName
- The name of the object to traverse to and return.
ReflectionException
- if the member does not exist.void setMember(String membername, String value) throws ReflectionException
value
to the member identified by the membername
argument.
membername
- 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.
ReflectionException
- If the value is not assignable to the member type or the member does not exist.void setMemberObject(String membername, Object value) throws ReflectionException
value
to the member identified by the membername
argument.
membername
- The name of the member to be assigned a value.value
- The value to be assigned to the member.
ReflectionException
- If the value is not assignable to the member type.void setMemberObject(Object container, String memberName, Object value) throws ReflectionException
value
to the member identified by the membername
starting at the
container
object.
container
- The object which has a member of the memberName.memberName
- The name of the member to be assigned a value.value
- The value to be assigned to the member.
ReflectionException
- If the value is not assignable to the member type.String[] getMemberNames(String membername) throws ReflectionException
membername
argument.
If the membername
is an empty string, all root object names are returned.
membername
- The name of the member to query for its members.
membername
.
ReflectionException
- If the member identified by the membername
does not exist.String[] getMemberNames(Object object)
object
.
object
- The Java instance to query for its members.
object
.Class getMemberClass(String objectname) throws ReflectionException
membername
argument.
objectname
- The name of the object to query for its Class.
ReflectionException
- if the named object does not exist.Class getMemberClass(Object container, String memberName) throws ReflectionException
membername
in the provided
container
.
container
- The object which has a member of the memberName.memberName
- The name of the member of the container
to query for its Class.
ReflectionException
- if the named object does not exist.String getMemberClassName(String objectname) throws ReflectionException
objectname
argument.
objectname
- The name of the member to query for its Class.
ReflectionException
- if the named object does not exist.String getMemberClassName(Object container, String objectname) throws ReflectionException
membername
in the provided
container
.
container
- The object which has a member of the memberName.objectname
- The name of the member of the container
to query for its Class.
objectname
in the container
.
ReflectionException
- if the objectname
does not exist as a member in the container
.boolean isMemberSettable(String objectname) throws ReflectionException
objectname
- The member to be tested if it can be set by a setMemberObject() method call.
objectname
can be set.
ReflectionException
- if the objectname
does not identify an existing object reference.boolean isMemberSettable(Object container, String membername) throws ReflectionException
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.
membername
can be set in the container
.
ReflectionException
- if the membername
does not exist as a member in the container.String extractContainerPart(String 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']".
objectname
- The objectname to be worked upon.
objectname
.String extractNamePart(String 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".
objectname
- The objectname to be worked upon.
objectname
.String append(Object container, String containerpart, String namepart)
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.
void addRootObject(String name, Object object) throws IllegalArgumentException
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.
name
- The name of the Root Object. The name may only contain valid Java characters, as
reported by Character.isJavaIdentifierPart(char ch).object
- The object instance to be registered at the provided name.
IllegalArgumentException
- if the name is not valid, or if there has already been a root object
registered with the same name previously.void removeRootObject(String name)
If there is no root object registered under the provided name, this method will simply return.
name
- The name under which the root object was previously registered.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |