org.objectweb.jac.core.rtti
Class RttiAC

java.lang.Object
  |
  +--org.objectweb.jac.core.AspectComponent
        |
        +--org.objectweb.jac.core.rtti.RttiAC
All Implemented Interfaces:
BaseProgramListener, RttiConf, Serializable

public class RttiAC
extends AspectComponent
implements RttiConf

This class defines the rtti aspect.

It allows the programmer to add some runtime type informations on the classes of its applications.

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

Field Summary
static String AUTHORIZED_VALUES
           
static String CLONED_FIELDS
           
static String CONSTRAINTS
           
static String DYNAMIC_FIELD_TYPE
           
static String FIELD_TYPE
           
static String FORBIDDEN_VALUES
           
static String INDEXED_FIELD
           
static String IS_INDEX
           
static String NULL_ALLOWED
           
static String NULL_ALLOWED_PARAMETERS
           
static String OPPOSITE_ROLE
           
static String PARAMETER_TYPES
           
static String PARAMETERS_FIELDS
           
static String PRIMARY_KEY
           
static String REPOSITORY_COLLECTION
           
static String REPOSITORY_NAME
           
 
Fields inherited from class org.objectweb.jac.core.AspectComponent
application, blockKeywords, cr, currentConfigMethod, currentImports, firstCall, NOT_SHARED, SHARED, startWeavingCCount, startWeavingCount, startWeavingMethod, startWeavingType, systemListener, wrappers
 
Fields inherited from interface org.objectweb.jac.core.BaseProgramListener
FOUND_OBJECT
 
Constructor Summary
RttiAC()
           
 
Method Summary
 void addAccessedFields(MethodItem method, String[] accessedFields)
          Adds some accessed fields to a given method.
 void addAdder(CollectionItem collection, String methodName)
          Adds an adding method for a collection
 void addAllowedCast(ClassItem src, ClassItem dest)
          Specify that a type can be safely casted into another type.
 void addDependentField(FieldItem field, String dependentField)
          Declares a field dependency.
 void addFieldDependency(FieldItem field, FieldItem dependentField)
          Tells that when field changes, dependentField changes too.
 void addMixinMethod(ClassItem cli, MethodItem method)
          Adds a mixin method to a class.
 void addRemover(CollectionItem collection, String methodName)
          Adds a removing method for a collection
 void addWrittenFields(AbstractMethodItem method, String[] writtenFields)
          Adds some written fields to a given method.
static Object convert(Object value, Class type)
          Tries to convert an object into a given type If type is String, toString() is called on value.
 void declareAssociation(FieldItem roleA, FieldItem roleB)
          Declares an association made of two roles.
 void declareCalculatedField(ClassItem cl, String fieldName, String getterName)
          Declare a calculated field, which is a field with only a getter and no actual field.
 void definePrimaryKey(CollectionItem collection, String[] fields)
          Defines primary keys for a collection.
 void defineRepository(ClassItem type, String repositoryName, CollectionItem repositoryCollection)
          Declare a repository to get instances of a class from, instead of fetching all instances of the class, when ObjectRepository.getObjects(ClassItem) is called.
 Set getClassesWithAssociations()
           
 String[] getDefaultConfigs()
          Returns defaults configuration files that must be loaded before the user's configuration
static MetaItem getFieldType(FieldItem field)
          Gets the type of a field.
static MetaItem getFieldType(FieldItem field, Object substance)
          Gets the type of a field for a given object.
static FieldItem getIndexFied(CollectionItem collection)
           
 void ignoreFields(String packageExpr)
           
static boolean isCastAllowed(Class src, Class dest)
           
static boolean isCastAllowed(ClassItem src, ClassItem dest)
           
static boolean isCollectionType(Class type)
          Tells wether a given type represents a collection
static boolean isIndex(CollectionItem collection)
           
static boolean isNullAllowed(FieldItem field)
           
static boolean isNullAllowedParameter(AbstractMethodItem method, int i)
           
 void newVirtualClass(String className, ClassItem actualType)
          Create a new virtual class.
 void setAdder(CollectionItem collection, String methodName)
          Sets the adder of a collection.
 void setAggregation(FieldItem field, boolean isAggregation)
          Tells wether a relation is an aggregation or not.
 void setClass(ClassItem cli, String className)
          Sets a user defined class on a class.
 void setClass(MemberItem member, String className)
          Sets a user defined class on a class' member.
 void setClonedFields(String className, String[] fields)
          This configuration method tells that the fields (references or collections) must be cloned when the class is cloned.
 void setComponentType(CollectionItem collection, String type)
          Sets the component type of a collection, i.e. the type of objects it contains.
 void setDynamicFieldType(FieldItem field, MethodItem method)
          Use a method to dynamically determine the type of a field
 void setFieldType(FieldItem field, String type)
          Declares a field to be of a given type
 void setGetter(FieldItem field, String getterName)
          Sets the getter of a field
 void setIndexedField(CollectionItem collection, FieldItem indexedField)
          Tells that a Map implementing a collection indexes a field of the contained objects.
 void setIsIndex(CollectionItem collection, boolean isIndex)
          Specify wether a Map implementing a collection is a mere index for the collection (this is not the default).
 void setNullAllowed(FieldItem field)
          This configuration method tells that the field can be set to null (forbidden by default)
 void setNullAllowed(FieldItem field, boolean allowed)
          This configuration method tells wether the field can be set to null or not.
 void setNullAllowedParameters(AbstractMethodItem method, boolean[] nulls)
          Tells if JAC object-typed (references) arguments of a method can take null value while the method's invocation or if they should be choosen in existing instances list.
 void setOppositeRole(FieldItem field, FieldItem oppositeRole)
          Sets the opposite role of a reference or collection field
 void setParametersFields(AbstractMethodItem method, FieldItem[] fields)
          Specifies that the parameters of a method will be assigned to a given field.
 void setParametersType(AbstractMethodItem method, String[] types)
          Declare a method's parameters to be of a given type
 void setRemover(CollectionItem collection, String methodName)
          Sets the remover of a collection.
 void setSetter(FieldItem field, String setterName)
          Sets the setter of a field
 void whenClone(Wrappee cloned, Wrappee clone)
          This method is automatically called when a Jac Object is cloned.
 
Methods inherited from class org.objectweb.jac.core.AspectComponent
addWrapper, afterApplicationStarted, afterRunningWrapper, afterWrap, afterWrappeeInit, attr, attrdef, beforeConfiguration, beforeReload, beforeRunningWrapper, beforeWrappeeInit, configure, defines, defineTimer, doRegister, doUnregister, error, getAC, getApplication, getBlockKeywords, getConfigurationMethods, getConfigurationMethodsName, getConfigurationMethodsName, getName, getNameCounters, getWrappers, init, isConfigurationMethod, isSystemListener, onExit, pointcut, pointcut, pointcut, pointcut, pointcut, pointcut, pointcut, pointcut, setApplication, setAttribute, setAttribute, setAttribute, setSystemListener, simulateUsingNewInstance, unweave, unwrapAll, updateNameCounters, warning, weave, whenCloseDisplay, whenConfigured, whenDeleted, whenDeserialized, whenFree, whenGetObjects, whenNameObject, whenObjectMiss, whenReload, whenRemoteInstantiation, whenSerialized, whenTopologyChanged, whenUsingNewClass, whenUsingNewInstance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OPPOSITE_ROLE

public static final String OPPOSITE_ROLE
See Also:
Constant Field Values

FIELD_TYPE

public static final String FIELD_TYPE
See Also:
Constant Field Values

DYNAMIC_FIELD_TYPE

public static final String DYNAMIC_FIELD_TYPE
See Also:
Constant Field Values

PARAMETER_TYPES

public static final String PARAMETER_TYPES
See Also:
Constant Field Values

CLONED_FIELDS

public static final String CLONED_FIELDS
See Also:
Constant Field Values

REPOSITORY_NAME

public static final String REPOSITORY_NAME
See Also:
Constant Field Values

REPOSITORY_COLLECTION

public static final String REPOSITORY_COLLECTION
See Also:
Constant Field Values

NULL_ALLOWED_PARAMETERS

public static final String NULL_ALLOWED_PARAMETERS
See Also:
Constant Field Values

NULL_ALLOWED

public static final String NULL_ALLOWED
See Also:
Constant Field Values

IS_INDEX

public static final String IS_INDEX
See Also:
Constant Field Values

INDEXED_FIELD

public static final String INDEXED_FIELD
See Also:
Constant Field Values

AUTHORIZED_VALUES

public static final String AUTHORIZED_VALUES
See Also:
Constant Field Values

FORBIDDEN_VALUES

public static final String FORBIDDEN_VALUES
See Also:
Constant Field Values

CONSTRAINTS

public static final String CONSTRAINTS
See Also:
Constant Field Values

PARAMETERS_FIELDS

public static final String PARAMETERS_FIELDS
See Also:
Constant Field Values

PRIMARY_KEY

public static final String PRIMARY_KEY
See Also:
Constant Field Values
Constructor Detail

RttiAC

public RttiAC()
Method Detail

addWrittenFields

public void addWrittenFields(AbstractMethodItem method,
                             String[] writtenFields)
Description copied from interface: RttiConf
Adds some written fields to a given method.

This configuration method must be used when a method changes some field values and does not follow the naming conventions (it is not a setter or an adder for instance).

Specified by:
addWrittenFields in interface RttiConf
Parameters:
method - the method
writtenFields - some new fields the method writes

declareCalculatedField

public void declareCalculatedField(ClassItem cl,
                                   String fieldName,
                                   String getterName)
Description copied from interface: RttiConf
Declare a calculated field, which is a field with only a getter and no actual field.

Specified by:
declareCalculatedField in interface RttiConf
Parameters:
cl - the class item of te calculated field
fieldName - the name of the calculated field
getterName - the name of the getter method
See Also:
RttiConf.addDependentField(FieldItem,String)

setSetter

public void setSetter(FieldItem field,
                      String setterName)
Description copied from interface: RttiConf
Sets the setter of a field

Specified by:
setSetter in interface RttiConf
Parameters:
field - the field
setterName - name of the setter method

setGetter

public void setGetter(FieldItem field,
                      String getterName)
Description copied from interface: RttiConf
Sets the getter of a field

Specified by:
setGetter in interface RttiConf
Parameters:
field - the field
getterName - name of the getter method

addDependentField

public void addDependentField(FieldItem field,
                              String dependentField)
Description copied from interface: RttiConf
Declares a field dependency. It will cause the field to be refreshed when the dependent field's value changes.

Specified by:
addDependentField in interface RttiConf
Parameters:
field - the field to refresh
dependentField - the name of the field it depends on. It must be in the same class as field.
See Also:
RttiConf.declareCalculatedField(ClassItem,String,String)

addFieldDependency

public void addFieldDependency(FieldItem field,
                               FieldItem dependentField)
Description copied from interface: RttiConf
Tells that when field changes, dependentField changes too.

Specified by:
addFieldDependency in interface RttiConf

addAdder

public void addAdder(CollectionItem collection,
                     String methodName)
Description copied from interface: RttiConf
Adds an adding method for a collection

Specified by:
addAdder in interface RttiConf
Parameters:
collection - the collection's name
methodName - the name of the adding method

setAdder

public void setAdder(CollectionItem collection,
                     String methodName)
Description copied from interface: RttiConf
Sets the adder of a collection.

Specified by:
setAdder in interface RttiConf
Parameters:
collection - the collection
methodName - the name of the adder method

addRemover

public void addRemover(CollectionItem collection,
                       String methodName)
Description copied from interface: RttiConf
Adds a removing method for a collection

Specified by:
addRemover in interface RttiConf
Parameters:
collection - the collection
methodName - the name of the removing method

setRemover

public void setRemover(CollectionItem collection,
                       String methodName)
Description copied from interface: RttiConf
Sets the remover of a collection.

Specified by:
setRemover in interface RttiConf
Parameters:
collection - the collection
methodName - the name of the remover method

addAccessedFields

public void addAccessedFields(MethodItem method,
                              String[] accessedFields)
Description copied from interface: RttiConf
Adds some accessed fields to a given method.

This configuration method must be used when a method reads some field values and does not follow the naming conventions (it is not a getter for instance).

Specified by:
addAccessedFields in interface RttiConf
Parameters:
method - the method
accessedFields - some new fields the method reads

setFieldType

public void setFieldType(FieldItem field,
                         String type)
Description copied from interface: RttiConf
Declares a field to be of a given type

Specified by:
setFieldType in interface RttiConf
Parameters:
field - the field
type - the type
See Also:
RttiConf.setDynamicFieldType(FieldItem,MethodItem)

setDynamicFieldType

public void setDynamicFieldType(FieldItem field,
                                MethodItem method)
Description copied from interface: RttiConf
Use a method to dynamically determine the type of a field

Specified by:
setDynamicFieldType in interface RttiConf
Parameters:
field - the field
method - a static method taking as arguments a FieldItem and an Object (holder of the field), and return a ClassItem or a VirtualClassItem or a String.
See Also:
RttiConf.setFieldType(FieldItem,String)

setComponentType

public void setComponentType(CollectionItem collection,
                             String type)
Description copied from interface: RttiConf
Sets the component type of a collection, i.e. the type of objects it contains.

Specified by:
setComponentType in interface RttiConf
Parameters:
collection - the collection
type - the component type of the collection

getFieldType

public static MetaItem getFieldType(FieldItem field)
Gets the type of a field. May return a ClassItem, a VirtualClassItem or a MethodItem.

Parameters:
field - a field

getFieldType

public static MetaItem getFieldType(FieldItem field,
                                    Object substance)
Gets the type of a field for a given object. May return a ClassItem, a VirtualClassItem.

Parameters:
field - a field
substance - the object holding the field

setParametersType

public void setParametersType(AbstractMethodItem method,
                              String[] types)
Description copied from interface: RttiConf
Declare a method's parameters to be of a given type

Specified by:
setParametersType in interface RttiConf
Parameters:
method - the method
types - the types of each parameteropf the method

newVirtualClass

public void newVirtualClass(String className,
                            ClassItem actualType)
Description copied from interface: RttiConf
Create a new virtual class. Virtual classes allow you extend and refine the types used by the application, so that aspects can behave differently.

Specified by:
newVirtualClass in interface RttiConf
Parameters:
className - name of the new class
actualType - the actual primitive type that is extended

defineRepository

public void defineRepository(ClassItem type,
                             String repositoryName,
                             CollectionItem repositoryCollection)
Description copied from interface: RttiConf
Declare a repository to get instances of a class from, instead of fetching all instances of the class, when ObjectRepository.getObjects(ClassItem) is called.

Specified by:
defineRepository in interface RttiConf
Parameters:
type - the type of objects to add in the repository
repositoryName - the name of the object holding the repository
repositoryCollection - the collection to get the objects from. Any expression field can be used.
See Also:
ObjectRepository.getObjects(ClassItem)

setClonedFields

public void setClonedFields(String className,
                            String[] fields)
Description copied from interface: RttiConf
This configuration method tells that the fields (references or collections) must be cloned when the class is cloned.

Specified by:
setClonedFields in interface RttiConf
Parameters:
className - the class name
fields - the names of the fields that are cloned

whenClone

public void whenClone(Wrappee cloned,
                      Wrappee clone)
Description copied from class: AspectComponent
This method is automatically called when a Jac Object is cloned.

Specified by:
whenClone in interface BaseProgramListener
Overrides:
whenClone in class AspectComponent
Parameters:
cloned - the object that is being cloned
clone - the new object (the clone of cloned)

ignoreFields

public void ignoreFields(String packageExpr)

setClass

public void setClass(MemberItem member,
                     String className)
Description copied from interface: RttiConf
Sets a user defined class on a class' member. This can be used by aspects user-defined configuration.

Specified by:
setClass in interface RttiConf
Parameters:
member - the member whose type to redefine
className - the new class name

setClass

public void setClass(ClassItem cli,
                     String className)
Description copied from interface: RttiConf
Sets a user defined class on a class. This can be used by aspects user-defined configuration.

Specified by:
setClass in interface RttiConf
Parameters:
cli - the class to redefine
className - the new class name

setParametersFields

public void setParametersFields(AbstractMethodItem method,
                                FieldItem[] fields)
Description copied from interface: RttiConf
Specifies that the parameters of a method will be assigned to a given field.

Other aspects (such as the GUI aspect) may use this information to provide better default behaviour for the paramters.

Specified by:
setParametersFields in interface RttiConf
Parameters:
method - the of the method
fields - an array of field items, one per parameter of the method. Elements of this array may be null if some parameters are not assigned to any field.

setNullAllowed

public void setNullAllowed(FieldItem field)
Description copied from interface: RttiConf
This configuration method tells that the field can be set to null (forbidden by default)

Specified by:
setNullAllowed in interface RttiConf
Parameters:
field - the field
See Also:
RttiConf.setNullAllowed(FieldItem,boolean)

setNullAllowed

public void setNullAllowed(FieldItem field,
                           boolean allowed)
Description copied from interface: RttiConf
This configuration method tells wether the field can be set to null or not. (forbidden by default)

Specified by:
setNullAllowed in interface RttiConf
Parameters:
field - the field
allowed - wether to allow null values
See Also:
RttiConf.setNullAllowed(FieldItem)

isNullAllowed

public static boolean isNullAllowed(FieldItem field)

setNullAllowedParameters

public void setNullAllowedParameters(AbstractMethodItem method,
                                     boolean[] nulls)
Description copied from interface: RttiConf
Tells if JAC object-typed (references) arguments of a method can take null value while the method's invocation or if they should be choosen in existing instances list.

Specified by:
setNullAllowedParameters in interface RttiConf
Parameters:
method - the method
nulls - a flags array that tells for each parameter whether it can be null (true) or not (false). It has no effect if the parameter is not a JAC object (a reference)

isNullAllowedParameter

public static boolean isNullAllowedParameter(AbstractMethodItem method,
                                             int i)

setAggregation

public void setAggregation(FieldItem field,
                           boolean isAggregation)
Description copied from interface: RttiConf
Tells wether a relation is an aggregation or not. By default, relations are not aggregations.

Specified by:
setAggregation in interface RttiConf
Parameters:
field - the relation
isAggregation - wether the relation is an aggregations or not.

setIndexedField

public void setIndexedField(CollectionItem collection,
                            FieldItem indexedField)
Description copied from interface: RttiConf
Tells that a Map implementing a collection indexes a field of the contained objects.

Specified by:
setIndexedField in interface RttiConf
Parameters:
collection - the collection
indexedField - the field which is indexed by the map
See Also:
RttiConf.setIsIndex(CollectionItem,boolean), CollectionItem.getActualCollection(Object), CollectionItem.getActualCollectionThroughAccessor(Object)

setIsIndex

public void setIsIndex(CollectionItem collection,
                       boolean isIndex)
Description copied from interface: RttiConf
Specify wether a Map implementing a collection is a mere index for the collection (this is not the default). In this case, CollectionItem.getActualCollection() returns the values contained in the hashtable, otherwise the (key,values) entries are returned.

Specified by:
setIsIndex in interface RttiConf
Parameters:
collection - the collection
isIndex - wether the map is an index
See Also:
RttiConf.setIndexedField(CollectionItem,FieldItem), CollectionItem.getActualCollection(Object), CollectionItem.getActualCollectionThroughAccessor(Object)

getIndexFied

public static FieldItem getIndexFied(CollectionItem collection)

isIndex

public static boolean isIndex(CollectionItem collection)

getDefaultConfigs

public String[] getDefaultConfigs()
Description copied from class: AspectComponent
Returns defaults configuration files that must be loaded before the user's configuration

Overrides:
getDefaultConfigs in class AspectComponent

definePrimaryKey

public void definePrimaryKey(CollectionItem collection,
                             String[] fields)
Description copied from interface: RttiConf
Defines primary keys for a collection.

It is used to check for double entries in the collection by checking the precised fields (it is the same as primary keys in a database).

Specified by:
definePrimaryKey in interface RttiConf

isCollectionType

public static boolean isCollectionType(Class type)
Tells wether a given type represents a collection


addAllowedCast

public void addAllowedCast(ClassItem src,
                           ClassItem dest)
Description copied from interface: RttiConf

Specify that a type can be safely casted into another type.

It can be useful it you changed the type of a field to a subclass of the original type that only adds new methods, and a persistence aspect complains that it cannot load this field anymore. dest should have constructor which takes a value of type src as the only argument.

Specified by:
addAllowedCast in interface RttiConf
Parameters:
src - type of the value to be casted
dest - type the value should be casted to

isCastAllowed

public static boolean isCastAllowed(ClassItem src,
                                    ClassItem dest)

isCastAllowed

public static boolean isCastAllowed(Class src,
                                    Class dest)

getClassesWithAssociations

public Set getClassesWithAssociations()

setOppositeRole

public void setOppositeRole(FieldItem field,
                            FieldItem oppositeRole)
Description copied from interface: RttiConf
Sets the opposite role of a reference or collection field

Specified by:
setOppositeRole in interface RttiConf
Parameters:
field - the field whose opposite role to set
oppositeRole - the opposite role of the fieldb
See Also:
RttiConf.declareAssociation(FieldItem,FieldItem)

declareAssociation

public void declareAssociation(FieldItem roleA,
                               FieldItem roleB)
Description copied from interface: RttiConf
Declares an association made of two roles.

When declared, the relations that constitutes the association's roles are tagged in the RTTI by the RttiAC.OPPOSITE_RELATION attribute (then they can be interpreted by other aspects such as Integrity, GUI or Persistence).

For instance, if you have a Customer class and an Order class:

    ,----------. 1    n ,-------.
    | Customer |--------| Order |
    `----------'        `-------'
 

Specified by:
declareAssociation in interface RttiConf
Parameters:
roleA - the starting role (e.g. Customer.orders)
roleB - the ending role (e.g. Order.customer)

convert

public static Object convert(Object value,
                             Class type)
                      throws InstantiationException,
                             IllegalAccessException,
                             InvocationTargetException,
                             NoSuchMethodException
Tries to convert an object into a given type

If type is String, toString() is called on value. If type Integer or Long (or int or long), and the value is numeric type (float,Float,double or Double) an Integer or Long is returned. Otherwise, isCastAllowed() is called, and if it returns true, we try to invoke a constructor take value as a parameter.

Parameters:
value - the value to convert
type - the type to convert the value into
Returns:
an instance of type built from value, or value
InstantiationException
IllegalAccessException
InvocationTargetException
NoSuchMethodException
See Also:
isCastAllowed(Class,Class)

addMixinMethod

public void addMixinMethod(ClassItem cli,
                           MethodItem method)
                    throws InvalidDelegateException
Description copied from interface: RttiConf
Adds a mixin method to a class.

A mixin method of class is a method which is not defined in the code of that class, but which will be made available on that class's ClassItem.

Specified by:
addMixinMethod in interface RttiConf
Parameters:
cli - a class
method - a static method whose 1st argument must be cli.
InvalidDelegateException
See Also:
MixinMethodItem.invoke(Object,Object[])