org.objectweb.jac.core.rtti
Class ClassRepository

java.lang.Object
  extended byorg.objectweb.jac.core.rtti.ClassRepository
All Implemented Interfaces:
LoadtimeRTTI

public class ClassRepository
extends Object
implements LoadtimeRTTI

This class defines the class repository of the rtti aspect.

It contains class items that are field and method items agregates.

Author:
Renaud Pawlak, Laurent Martelli
See Also:
ClassItem, MethodItem, FieldItem, CollectionItem

Field Summary
protected static ClassRepository classRepository
          Store the sole instance of class repository.
 Hashtable names
          Reverse hashtable to find an class item from its name
 Hashtable objects
          Link class items to their names
static Class wrappeeClass
          Stores the Wrappee class.
 
Constructor Summary
ClassRepository()
          The default constructor will set the classRepository field to the right value (singleton pattern).
 
Method Summary
static void addAccessedFields(Class cl, String methodName, String[] fieldNames)
          Adds a set of accessed fields to a method.
static void addAddedCollections(Class cl, String methodName, String[] collectionNames)
          Adds a set of added collections to a method.
 void addInvokedMethod(String className, String methodSign, InvokeInfo invokeInfo)
          Tells that a method invokes another method
 void addltAccessedField(String className, String methodSign, String fieldName)
          Adds an accessed field for a given method.
 void addltAddedCollection(String className, String methodSign, String fieldName)
          Tells that a method calls add on a collection field
 void addltModifiedCollection(String className, String methodSign, String fieldName)
          Tells that a method calls modifies the content of a collection field
 void addltModifiedField(String className, String methodSign, String fieldName)
          Adds a modified field for a given method.
 void addltRemovedCollection(String className, String methodSign, String fieldName)
          Tells that a method calls remove on a collection field
 void addltReturnedField(String className, String methodSign, String fieldName)
          Tells that a method returns the value of field
 void addltSetField(String className, String methodSign, String fieldName)
          Tells that a method is the setter of a field (sets the field with the value of a parameter)
static void addRemovedCollections(Class cl, String methodName, String[] collectionNames)
          Adds a set of removed collections to a method.
static void addWrittenFields(Class cl, String methodName, String[] fieldNames)
          Adds a set of written fields to a method.
 void buildDefaultFieldRTTI(ClassItem cli)
           
 ClassItem buildDefaultRTTI(Class cl)
          This method builds the default RTTI for a given class name and returns a corresponding class item.
 void dump()
          Dump all the registered classes in this class repository.
static void fillDirectFieldAccess(Class cl)
          Fill the direct access to fields hashtable for a given class.
static Hashtable fillDirectMethodAccess(Class cl)
          Fill the direct access to methods hashtable for a given class.
static ClassRepository get()
          Get the sole instance of class repository.
 FieldItem getActualField(Object substance, FieldItem field)
          Returns a field whose owning class is the class of an object
 ClassItem getClass(Class cl)
          This method returns the class item that corresponds to the given class.
 ClassItem getClass(Object object)
          This method returns the class item that corresponds to the given object class.
 ClassItem getClass(String name)
          This method returns an existing class from its name.
 Object[] getClasses()
          Return all the registered classes as an array.
 ClassInfo getClassInfo(String className)
          Returns the class info of a class
static Hashtable getDirectFieldAccess(Class cl)
          Returns a Hashtable that maps fields with their names.
static Method[] getDirectMethodAccess(Class cl, String name)
          Return an array of methods that correspond to the given class and given method name.
static String[] getGettersNames(Class cl)
          Get getter names.
 MethodInfo getMethodInfo(String className, String method)
           
static String[] getMethodsName(Class cl)
          Gets the method names of a class
static String[] getModifiersNames(Class cl)
          Get modifiers names.
 String getName(Object object)
          Returns the name of a registered class.
 Object[] getNames()
          Return the names of the registered classes as an array.
 ClassItem getNonPrimitiveClass(String className)
           
 Object getObject(String logicalName)
          Return a registered classes for a given logical name.
 MetaItem getVirtualClass(String name)
          Returns a ClassItem or a VirtualClassItem from its name.
 VirtualClassItem getVirtualClassStrict(String name)
          Returns a VirtualClassItem from its name.
 void ignoreFields(String packageExpr)
           
static Object instantiate(Class type, String value)
           
static Object invokeDirect(Class cl, String methodName, Object o, Object[] params)
          Call a directly acceded method.
static boolean isDefaultConstructorAdded(Class cl)
          Returns true is this class defautlt constructor (the one with no parameter) has been added by JAC at class load-time.
static boolean isJacField(String fieldName)
          Return true if the field is added by JAC at class load-time.
static boolean isJacMethod(String methodName)
          Return true if the method is added by JAC at class load-time.
 boolean isRegistered(String logicalName)
          Returns true if a class is registered with this name.
static boolean isSystemField(String fieldName)
          Tells if the field is a "system" field, such as a field added by the compiler for class objects.
 void register(String logicalName, Object object)
          Register a new class into the class repository.
 void setCallSuper(String className, String method)
          Tells that a method calls the super method
 void setClassInfo(String className, ClassInfo classInfo)
           
 void setCollectionIndexArgument(String className, String methodSign, int argument)
          Tells that a method's parameter is used as an index of a collection field
 void setCollectionItemArgument(String className, String methodSign, int argument)
          Tells that a method's parameter is used as an item to be added to a collection field
 void setltIsGetter(String className, String methodSign, boolean isGetter)
          Tells wether a method is a getter of a field or not
 void unregister(String logicalName)
          Unregister a class from the repository.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

classRepository

protected static transient ClassRepository classRepository
Store the sole instance of class repository.


wrappeeClass

public static Class wrappeeClass
Stores the Wrappee class.


objects

public Hashtable objects
Link class items to their names


names

public Hashtable names
Reverse hashtable to find an class item from its name

Constructor Detail

ClassRepository

public ClassRepository()
The default constructor will set the classRepository field to the right value (singleton pattern).

Method Detail

getClassInfo

public ClassInfo getClassInfo(String className)
Description copied from interface: LoadtimeRTTI
Returns the class info of a class

Specified by:
getClassInfo in interface LoadtimeRTTI

setClassInfo

public void setClassInfo(String className,
                         ClassInfo classInfo)
Specified by:
setClassInfo in interface LoadtimeRTTI

getMethodInfo

public MethodInfo getMethodInfo(String className,
                                String method)

addltModifiedField

public void addltModifiedField(String className,
                               String methodSign,
                               String fieldName)
Adds a modified field for a given method.

This method is automatically called at load-time by the JAC classloader through bytecode analysis.

Specified by:
addltModifiedField in interface LoadtimeRTTI
Parameters:
methodSign - the method signature of the form packagepath.classname.methodname
fieldName - the name of the field that is modified by the method

addltSetField

public void addltSetField(String className,
                          String methodSign,
                          String fieldName)
Description copied from interface: LoadtimeRTTI
Tells that a method is the setter of a field (sets the field with the value of a parameter)

Specified by:
addltSetField in interface LoadtimeRTTI

addltAccessedField

public void addltAccessedField(String className,
                               String methodSign,
                               String fieldName)
Adds an accessed field for a given method.

This method is automatically called at load-time by the JAC classloader through bytecode analysis.

Specified by:
addltAccessedField in interface LoadtimeRTTI
Parameters:
methodSign - the method signature of the form packagepath.classname.methodname
fieldName - the name of the field that is accessed by the method

addltReturnedField

public void addltReturnedField(String className,
                               String methodSign,
                               String fieldName)
Description copied from interface: LoadtimeRTTI
Tells that a method returns the value of field

Specified by:
addltReturnedField in interface LoadtimeRTTI

setltIsGetter

public void setltIsGetter(String className,
                          String methodSign,
                          boolean isGetter)
Description copied from interface: LoadtimeRTTI
Tells wether a method is a getter of a field or not

Specified by:
setltIsGetter in interface LoadtimeRTTI

addltAddedCollection

public void addltAddedCollection(String className,
                                 String methodSign,
                                 String fieldName)
Description copied from interface: LoadtimeRTTI
Tells that a method calls add on a collection field

Specified by:
addltAddedCollection in interface LoadtimeRTTI

addltRemovedCollection

public void addltRemovedCollection(String className,
                                   String methodSign,
                                   String fieldName)
Description copied from interface: LoadtimeRTTI
Tells that a method calls remove on a collection field

Specified by:
addltRemovedCollection in interface LoadtimeRTTI

addltModifiedCollection

public void addltModifiedCollection(String className,
                                    String methodSign,
                                    String fieldName)
Description copied from interface: LoadtimeRTTI
Tells that a method calls modifies the content of a collection field

Specified by:
addltModifiedCollection in interface LoadtimeRTTI

setCollectionIndexArgument

public void setCollectionIndexArgument(String className,
                                       String methodSign,
                                       int argument)
Description copied from interface: LoadtimeRTTI
Tells that a method's parameter is used as an index of a collection field

Specified by:
setCollectionIndexArgument in interface LoadtimeRTTI

setCollectionItemArgument

public void setCollectionItemArgument(String className,
                                      String methodSign,
                                      int argument)
Description copied from interface: LoadtimeRTTI
Tells that a method's parameter is used as an item to be added to a collection field

Specified by:
setCollectionItemArgument in interface LoadtimeRTTI

addInvokedMethod

public void addInvokedMethod(String className,
                             String methodSign,
                             InvokeInfo invokeInfo)
Description copied from interface: LoadtimeRTTI
Tells that a method invokes another method

Specified by:
addInvokedMethod in interface LoadtimeRTTI

setCallSuper

public void setCallSuper(String className,
                         String method)
Description copied from interface: LoadtimeRTTI
Tells that a method calls the super method

Specified by:
setCallSuper in interface LoadtimeRTTI

get

public static ClassRepository get()
Get the sole instance of class repository.

Returns:
the class repository

fillDirectMethodAccess

public static Hashtable fillDirectMethodAccess(Class cl)
Fill the direct access to methods hashtable for a given class.

This is used to optimize the method calls when you only have the method name.

Parameters:
cl - the class to treat.
See Also:
getDirectMethodAccess(Class,String)

fillDirectFieldAccess

public static void fillDirectFieldAccess(Class cl)
Fill the direct access to fields hashtable for a given class.

This is used to optimize the access of protected and private fields.

Parameters:
cl - the class to treat.

getDirectFieldAccess

public static Hashtable getDirectFieldAccess(Class cl)
Returns a Hashtable that maps fields with their names.

For efficiency, the programmer should use this method instead of using the Java refection API to retrives values of protected or private fields within a class and all its superclasses.

Parameters:
cl - the class
Returns:
a Map (String(field name) -> Field)
See Also:
fillDirectFieldAccess(Class)

invokeDirect

public static Object invokeDirect(Class cl,
                                  String methodName,
                                  Object o,
                                  Object[] params)
                           throws NoSuchMethodException,
                                  InvocationTargetException,
                                  IllegalAccessException
Call a directly acceded method.

Parameters:
cl - the class that supports the method
methodName - the method to call
o - the object to call the method on
params - the arguments
Throws:
NoSuchMethodException
InvocationTargetException
IllegalAccessException
See Also:
getDirectMethodAccess(Class,String)

getDirectMethodAccess

public static Method[] getDirectMethodAccess(Class cl,
                                             String name)
Return an array of methods that correspond to the given class and given method name.

For efficiency, the programmer should use this method instead of using the Java refection API.

Parameters:
cl - the class where the method is supposed to be
name - the method name
Returns:
an array containing the matching methods (homonyms), a one array element with null inside if none method matched (this ugly result was introduced for backward compatibility)
See Also:
fillDirectMethodAccess(Class)

isDefaultConstructorAdded

public static boolean isDefaultConstructorAdded(Class cl)
Returns true is this class defautlt constructor (the one with no parameter) has been added by JAC at class load-time.

Parameters:
cl - the class to test
Returns:
true if added, false if programmer defined

isJacMethod

public static boolean isJacMethod(String methodName)
Return true if the method is added by JAC at class load-time.

Parameters:
methodName - the method to check
Returns:
true if added at load-time

isJacField

public static boolean isJacField(String fieldName)
Return true if the field is added by JAC at class load-time.

Parameters:
fieldName - name of the field

isSystemField

public static boolean isSystemField(String fieldName)
Tells if the field is a "system" field, such as a field added by the compiler for class objects.

Parameters:
fieldName - name of the field

getMethodsName

public static String[] getMethodsName(Class cl)
Gets the method names of a class

Parameters:
cl - the class
Returns:
the method names as an array of strings

getModifiersNames

public static String[] getModifiersNames(Class cl)
Get modifiers names.

Parameters:
cl - the class
Returns:
the modifiers method names as an array of strings

getGettersNames

public static String[] getGettersNames(Class cl)
Get getter names.

Parameters:
cl - the class
Returns:
the modifiers names as an array of strings

addWrittenFields

public static void addWrittenFields(Class cl,
                                    String methodName,
                                    String[] fieldNames)
Adds a set of written fields to a method.

This method shortcuts the writting of RTTI aspects for programs. Equivalent effects can be achieved by using the RTTI aspect API.

Parameters:
cl - the involved class
methodName - the method name
fieldNames - the set of fields that are written by this method
See Also:
AbstractMethodItem.addWrittenField(FieldItem)

addAccessedFields

public static void addAccessedFields(Class cl,
                                     String methodName,
                                     String[] fieldNames)
Adds a set of accessed fields to a method.

This method shortcuts the writting of RTTI aspects for programs. Equivalent effects can be achieved by using the RTTI aspect API.

Parameters:
cl - the involved class
methodName - the method name
fieldNames - the set of fields that are accessed by this method
See Also:
MethodItem.addAccessedField(FieldItem)

addAddedCollections

public static void addAddedCollections(Class cl,
                                       String methodName,
                                       String[] collectionNames)
Adds a set of added collections to a method.

This method shortcuts the writting of RTTI aspects for programs. Equivalent effects can be achieved by using the RTTI aspect API.

Parameters:
cl - the involved class
methodName - the method name
collectionNames - the set of collections that are added by this method
See Also:
MethodItem.addAddedCollection(CollectionItem)

addRemovedCollections

public static void addRemovedCollections(Class cl,
                                         String methodName,
                                         String[] collectionNames)
Adds a set of removed collections to a method.

This method shortcuts the writting of RTTI aspects for programs. Equivalent effects can be achieved by using the RTTI aspect API.

Parameters:
cl - the involved class
methodName - the method name
collectionNames - the set of collections that are removed by this method
See Also:
MethodItem.addRemovedCollection(CollectionItem)

getClass

public ClassItem getClass(String name)
This method returns an existing class from its name.

If the class is not registered yet, the class repository automatically builds default runtime informations (using naming conventions), and seamlessly registers the new ClassItem instance into the class repository.

Note: in case of manual class registrations, a class must be registered with its full name to avoid name conflicts.

Parameters:
name - the name of the class to get
Returns:
the class if exist, null otherwise
See Also:
getVirtualClass(String)

getVirtualClass

public MetaItem getVirtualClass(String name)
Returns a ClassItem or a VirtualClassItem from its name. It first tries to find a ClassItem, and if it fails, it returns a VirtualClassItem.

Parameters:
name - the name of the class to find
Returns:
a ClassItem or a VirtualClassItem
See Also:
getClass(String), getVirtualClassStrict(String)

getVirtualClassStrict

public VirtualClassItem getVirtualClassStrict(String name)
Returns a VirtualClassItem from its name.

Parameters:
name - the name of the class to find
Returns:
the VirtualClassItem with the requested name
See Also:
getClass(String), getVirtualClass(String)

getClass

public ClassItem getClass(Object object)
This method returns the class item that corresponds to the given object class.

Parameters:
object - the object to get the class item
Returns:
the class item
See Also:
getClass(String)

getClass

public ClassItem getClass(Class cl)
This method returns the class item that corresponds to the given class.

Parameters:
cl - the class to get the class item of
Returns:
the class item
See Also:
getClass(String)

getNonPrimitiveClass

public ClassItem getNonPrimitiveClass(String className)

ignoreFields

public void ignoreFields(String packageExpr)

buildDefaultRTTI

public ClassItem buildDefaultRTTI(Class cl)
This method builds the default RTTI for a given class name and returns a corresponding class item.

Parameters:
cl - the class to build
Returns:
the corresponding class item, null if the given name is not a class name

buildDefaultFieldRTTI

public void buildDefaultFieldRTTI(ClassItem cli)

register

public void register(String logicalName,
                     Object object)
Register a new class into the class repository.

Parameters:
logicalName - the key that allows to find the class
object - the class to register
Returns:
true if the class registered, false if already registered
See Also:
unregister(String)

unregister

public void unregister(String logicalName)
Unregister a class from the repository.

Parameters:
logicalName - the class name
See Also:
register(String,Object)

isRegistered

public boolean isRegistered(String logicalName)
Returns true if a class is registered with this name.

Parameters:
logicalName - the key that allows to find the class
See Also:
register(String,Object)

getClasses

public Object[] getClasses()
Return all the registered classes as an array.

Reverse operation is getNames().

Returns:
the registered classes in this repository
See Also:
register(String,Object), getNames()

getNames

public Object[] getNames()
Return the names of the registered classes as an array.

Returns:
the registered classes names in this repository
See Also:
register(String,Object)

getObject

public Object getObject(String logicalName)
Return a registered classes for a given logical name.

Return null if the name does not correspond to any registered class or if logicalName is null.

Reverse operation is getName(Object).

Parameters:
logicalName - the key that allows to find the class
Returns:
the corresponding object, null if not registered
See Also:
register(String,Object), getName(Object)

getName

public String getName(Object object)
Returns the name of a registered class. Null if not registered.

Reverse operation is getObject(String).

Parameters:
object - the class to get the name of
Returns:
the class name, null if not registered
See Also:
register(String,Object), getObject(String)

getActualField

public FieldItem getActualField(Object substance,
                                FieldItem field)
Returns a field whose owning class is the class of an object

Parameters:
substance - the object whose class to user
field - the field to return

dump

public void dump()
Dump all the registered classes in this class repository.


instantiate

public static Object instantiate(Class type,
                                 String value)