org.objectweb.jac.aspects.integrity
Class IntegrityAC

java.lang.Object
  |
  +--org.objectweb.jac.core.AspectComponent
        |
        +--org.objectweb.jac.aspects.integrity.IntegrityAC
All Implemented Interfaces:
BaseProgramListener, IntegrityConf, Serializable

public class IntegrityAC
extends AspectComponent
implements IntegrityConf

This aspect handle different kinds of data integrity among objects sets.

See Also:
Serialized Form

Field Summary
static String CONSTRAINTS
           
static String DISABLE_ADD_TO_REPOSITORY
           
static String DISABLE_ROLE_UPDATES
           
 
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
IntegrityAC()
           
 
Method Summary
 void addPostCondition(FieldItem field, MethodItem constraint, Object[] params, String errorMsg)
          Use this configuration method to add a postcondition on a object's field.
 void addPreCondition(FieldItem field, MethodItem constraint, Object[] params, String errorMsg)
          Use this configuration method to add a precondition on a object's field.
 void declareAssociation(ClassItem classA, String fieldA, ClassItem classB, String fieldB)
           
 void declareAssociation(FieldItem roleA, FieldItem roleB)
           
 void declareConstraint(FieldItem relation, FieldItem target, String constraint)
          Declare a referential integrity contraint.
 void declareDirectionalAssociation(ClassItem classA, String fieldA, ClassItem classB, String fieldB)
           
 void declareDirectionalAssociation(FieldItem roleA, FieldItem roleB)
           
 void declareRepository(String repositoryName, CollectionItem collection, FieldItem field)
          This method declares a repository collection.
static void disableAddToRepository(CollectionItem collection)
          Disables adding objects to a repository collection.
static void disableRoleUpdates()
           
protected  void doCheck()
          Activates constraints checking.
static void enableAddToRepository(CollectionItem collection)
          Enables adding objects to a repository collection.
static void enableRoleUpdates()
           
protected static List getDisabled()
          Gets the list of disabled repository
static boolean isAddToRepositoryEnabled(CollectionItem collection)
          Tells wether adding objects to a repository collection is enabled or not.
 void updateAssociations()
          Tells that the integrity aspect should maintain integrity between the roles of associations.
 void whenConfigured()
          This method should be defined by the programmer when specific actions are needed once the aspect component has be configured.
 
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, getDefaultConfigs, 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, whenClone, whenCloseDisplay, 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

CONSTRAINTS

public static final String CONSTRAINTS
See Also:
Constant Field Values

DISABLE_ROLE_UPDATES

public static final String DISABLE_ROLE_UPDATES
See Also:
Constant Field Values

DISABLE_ADD_TO_REPOSITORY

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

IntegrityAC

public IntegrityAC()
Method Detail

declareRepository

public void declareRepository(String repositoryName,
                              CollectionItem collection,
                              FieldItem field)
Description copied from interface: IntegrityConf
This method declares a repository collection.

When an object is added to a relation, it will be automatically added to the collection of the repository.

Specified by:
declareRepository in interface IntegrityConf
Parameters:
repositoryName - the JAC object's name of the repository
collection - the collection to add into (on the instance given as the first parameter)
field - objects that are set or added to this field are added to the repository

declareConstraint

public void declareConstraint(FieldItem relation,
                              FieldItem target,
                              String constraint)
Description copied from interface: IntegrityConf

Declare a referential integrity contraint.

When an object is removed from the target collection, it will be checked wether it can be allowed.

Suppose you have Customer class and an Invoice class :

  ,-----------. 1   * ,----------. 1       * ,---------.
  | Customers |-------| Customer |-----------| Invoice |
  `-----------'       `----------'           `---------'
 

You do not want to allow the removal of a customer from the Customers repository if there are invoices for that customer. So you would add the following constraint:

declareConstraint Invoice.customer Customers.customers FORBIDDEN;

Specified by:
declareConstraint in interface IntegrityConf
Parameters:
relation -
target - the collection on which checking will occur on remove, or the reference on which checking will occur when setting another value.
constraint - the type of the constraint. It may be "DELETE_CASCADE" (delete the object holding the reference on the object to be deleted), "SET_NULL" (set the reference to null, or remove the object from the collection), FORBIDDEN" (raise an exception).

addPostCondition

public void addPostCondition(FieldItem field,
                             MethodItem constraint,
                             Object[] params,
                             String errorMsg)
Description copied from interface: IntegrityConf
Use this configuration method to add a postcondition on a object's field.

It means that the final value of the field will be tested with the added constraint and if it is not valid, it will be rejected.

Constraint methods must return a Boolean that is Boolean.TRUE if the test has been validated (passed), Boolean.FALSE else. The class org.objectweb.jac.aspects.integrity.GenericConditions contains basic tests such as forbiddenValues or authorizedValues.

Specified by:
addPostCondition in interface IntegrityConf
Parameters:
field - the field to constrain
constraint - the constraint method used to check the field's value
params - the parameters passed to the contraint method
errorMsg - the error message displayed if the checking has not been passed
See Also:
IntegrityConf.addPreCondition(FieldItem,MethodItem,Object[],String)

addPreCondition

public void addPreCondition(FieldItem field,
                            MethodItem constraint,
                            Object[] params,
                            String errorMsg)
Description copied from interface: IntegrityConf
Use this configuration method to add a precondition on a object's field.

It means that the initial value of the field will be tested with the added constraint and if it is not valid, it will be rejected.

Constraint methods must return a Boolean that is Boolean.TRUE if the test has been validated (passed), Boolean.FALSE else. The class org.objectweb.jac.aspects.integrity.GenericConditions contains basic tests such as forbiddenValues or authorizedValues.

Specified by:
addPreCondition in interface IntegrityConf
Parameters:
field - the field to constrain
constraint - the constraint method used to check the field's value
params - the parameters passed to the contraint method
errorMsg - the error message displayed if the checking has not been passed
See Also:
IntegrityConf.addPostCondition(FieldItem,MethodItem,Object[],String)

doCheck

protected void doCheck()
Activates constraints checking.

This method must be called once after all calls to addPreCondition and addPostCondition to effectively add pointcuts for these methods.

See Also:
addPreCondition(FieldItem,MethodItem,Object[],String), addPostCondition(FieldItem,MethodItem,Object[],String)

updateAssociations

public void updateAssociations()
Description copied from interface: IntegrityConf
Tells that the integrity aspect should maintain integrity between the roles of associations.

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

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

You can declare an association made of Cutomer.orders and Order.customer, so that setting the cutomer of an order will automatically add this order in the customer's list of orders. And vice-versa.

Specified by:
updateAssociations in interface IntegrityConf
See Also:
RttiAC.declareAssociation(FieldItem,FieldItem)

declareAssociation

public void declareAssociation(FieldItem roleA,
                               FieldItem roleB)

declareAssociation

public void declareAssociation(ClassItem classA,
                               String fieldA,
                               ClassItem classB,
                               String fieldB)

declareDirectionalAssociation

public void declareDirectionalAssociation(FieldItem roleA,
                                          FieldItem roleB)

declareDirectionalAssociation

public void declareDirectionalAssociation(ClassItem classA,
                                          String fieldA,
                                          ClassItem classB,
                                          String fieldB)

whenConfigured

public void whenConfigured()
Description copied from class: AspectComponent
This method should be defined by the programmer when specific actions are needed once the aspect component has be configured.

Overrides:
whenConfigured in class AspectComponent

isAddToRepositoryEnabled

public static boolean isAddToRepositoryEnabled(CollectionItem collection)
Tells wether adding objects to a repository collection is enabled or not.

Parameters:
collection - the repository collection to test

disableAddToRepository

public static void disableAddToRepository(CollectionItem collection)
Disables adding objects to a repository collection.

Parameters:
collection - the repository collection to disable

enableAddToRepository

public static void enableAddToRepository(CollectionItem collection)
Enables adding objects to a repository collection.

Parameters:
collection - the repository collection to enable

getDisabled

protected static List getDisabled()
Gets the list of disabled repository


disableRoleUpdates

public static void disableRoleUpdates()

enableRoleUpdates

public static void enableRoleUpdates()