JAC project
AOPSYS
CEDRIC & LIP6 labs

org.objectweb.jac.core
Class ACManager

java.lang.Object
  |
  +--org.objectweb.jac.util.Repository
        |
        +--org.objectweb.jac.util.OrderedRepository
              |
              +--org.objectweb.jac.core.ACManager
All Implemented Interfaces:
BaseProgramListener

public class ACManager
extends OrderedRepository
implements BaseProgramListener

This class manages all the aspect components that are present in the JAC system.

When a new aspect component is registered, it is woven regarding its weaving properties. Once woven, the aspect component manager dispatches all the events of the BaseProgramListener to it.

See Also:
AspectComponent, BaseProgramListener

Field Summary
protected static ACManager acManager
          Stores the sole instance of Aspect Component Manager.
protected  Hashtable declaredACs
          Stores all the declared aspect components.
 boolean registering
          A internally-used flag to bootstrap the AC manager.
 
Fields inherited from class org.objectweb.jac.util.OrderedRepository
orderedNames, orderedObjects, repository
 
Fields inherited from class org.objectweb.jac.util.Repository
names, objects
 
Fields inherited from interface org.objectweb.jac.core.BaseProgramListener
FOUND_OBJECT
 
Constructor Summary
ACManager()
          The default constructor will set the acManager field to the right value and bind the JAC internal MOP to it so that it will be notified of the base program events.
 
Method Summary
 void afterApplicationStarted()
          Dispatch this event to all the registered Aspect Components that are woven.
 void afterRunningWrapper(Wrapper wrapper, String wrappingMethod)
          Upcall the beforeRunningWrapper method of all the aspect component that owns the wrapper.
 void afterWrap(Wrappee wrappee, Wrapper wrapper, String[] wrapping_methods, String[][] wrapped_methods)
          Upcall the beforeRunningWrapper method of all the aspect component that owns the wrapper.
 void afterWrappeeInit(Wrappee wrappee)
          This method should be called by the GUI system after an object has been created and initialized (tells the other aspects that the object is now regular).
 Object attr(String name)
           
 void attrdef(String name, Object value)
           
 boolean beforeRunningWrapper(Wrapper wrapper, String wrappingMethod)
          Forward this event to the aspect component that owns the wrapper.
 void beforeWrappeeInit(Wrappee wrappee)
          This method should be called by the GUI system before an object is being created and initialized (but the process is not finished yet).
 void declareAC(String name, String path)
          Declares a new aspect component.
static Repository get()
          Get the sole instance of Aspect Component Manager for this JAC container.
 AspectComponent getAC(String name)
          Returns an AC of a given name for the current application.
 AspectComponent getACFromFullName(String fullName)
          Returns an AC of a given name
static ACManager getACM()
           
 String getACPathFromName(String acName)
          Gets a declared aspect component path from its name.
 AspectComponent[] getAspectComponents()
           
 Set getDeclaredACs()
          Gets the declared aspect components.
 boolean isACDeclared(String name)
           
static void main(String[] args)
          Called by the JAC launcher to create and declare the aspect components defined in jac.prop.
 void onExit()
          This method is upcalled when the system exits.
 boolean register(String name, Object aspectComponent)
          Register a new aspect component.
 AspectComponent registerDeclaredAC(String name)
          Registers a declared aspect as is (not linked to an application and with no configuration).
 boolean registerWithName(String name, String className)
          A resister method that can be used by a UI.
 void reloadAspect(String aspect)
          Reload an aspect for the current application
 void reloadAspect(String application, String aspect)
          Reload an aspect for an application
 void simulateUsingNewInstance(Wrappee wrappee)
          Apply all the woven aspect components to the given wrappee.
 void unregister(String name)
          Unregister a given aspect component (it is then unwoven).
 void weave(AspectComponent ac)
          Register (if not allready registered) and weaves a new Aspect Component.
 void whenClone(Wrappee cloned, Wrappee clone)
          Dispatch this event to all the registered Aspect Components that are woven.
 void whenCloseDisplay(Display display)
          Dispatch this event to all the registered Aspect Components that are woven.
 void whenDeleted(Wrappee object)
          Upcalled when an object is deleted.
 Wrappee whenDeserialized(SerializedJacObject orgObject, Wrappee finalObject)
          Dispatch this event to all the woven Aspect Components.
 void whenFree(Wrappee object)
          Upcalled when an object is freed from the memory.
 void whenGetObjects(Collection objects, ClassItem cl)
          Calls whenGetObjects on all aspects.
 String whenNameObject(Object object, String name)
          Upcalled when the naming aspect names an object.
 void whenObjectMiss(String name)
          Upcalled when an object is been seeked within the name repository and is not found.
 void whenRemoteInstantiation(Wrappee newInstance, String name)
          Dispatch this event to all the registered Aspect Components.
 Wrappee whenSerialized(Wrappee orgObject, SerializedJacObject finalObject)
          Dispatch this event to all the woven Aspect Components.
 void whenTopologyChanged()
          Dispatch this event to all the registered Aspect Components that are woven.
 void whenUsingNewClass(ClassItem cl)
          This method is upcalled by JAC when a static method is called for the first time.
 void whenUsingNewInstance(Interaction interaction)
          Dispatch this event to all the registered Aspect Components that are woven.
 
Methods inherited from class org.objectweb.jac.util.OrderedRepository
getNames, getObjects, getPrintableString
 
Methods inherited from class org.objectweb.jac.util.Repository
dump, getName, getObject, isRegistered, unregisterObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

registering

public boolean registering
A internally-used flag to bootstrap the AC manager.


acManager

protected static ACManager acManager
Stores the sole instance of Aspect Component Manager.


declaredACs

protected Hashtable declaredACs
Stores all the declared aspect components.

Constructor Detail

ACManager

public ACManager()
The default constructor will set the acManager field to the right value and bind the JAC internal MOP to it so that it will be notified of the base program events.

See Also:
BaseProgramListener
Method Detail

get

public static Repository get()
Get the sole instance of Aspect Component Manager for this JAC container.

If this instance does not exist yet, then it is created.

This method returns a Repository so that the result must be casted to used specific method of ACManager.

Returns:
the aspect component manager of the local container
See Also:
Repository

getACM

public static ACManager getACM()

getAspectComponents

public AspectComponent[] getAspectComponents()

declareAC

public void declareAC(String name,
                      String path)
Declares a new aspect component.

Parameters:
name - the name of the aspect component
path - its path (must be accessible from the current classpath)

isACDeclared

public boolean isACDeclared(String name)

getACPathFromName

public String getACPathFromName(String acName)
Gets a declared aspect component path from its name.

Parameters:
acName - the name of the AC
Returns:
the corresponding path, null if not declared

getDeclaredACs

public Set getDeclaredACs()
Gets the declared aspect components.

Returns:
the set of the declared aspect components names

registerDeclaredAC

public AspectComponent registerDeclaredAC(String name)
Registers a declared aspect as is (not linked to an application and with no configuration).

Parameters:
name - the aspect name

main

public static void main(String[] args)
                 throws Throwable
Called by the JAC launcher to create and declare the aspect components defined in jac.prop.

Throwable

getAC

public AspectComponent getAC(String name)
Returns an AC of a given name for the current application.

Parameters:
name - aspect's name

getACFromFullName

public AspectComponent getACFromFullName(String fullName)
Returns an AC of a given name

Parameters:
fullName - aspect's full name (.)

whenRemoteInstantiation

public final void whenRemoteInstantiation(Wrappee newInstance,
                                          String name)
Dispatch this event to all the registered Aspect Components.

Specified by:
whenRemoteInstantiation in interface BaseProgramListener
Parameters:
newInstance - the remotly created instance
name - the original remote name
See Also:
AspectComponent.whenRemoteInstantiation(Wrappee,String), BaseProgramListener.whenRemoteInstantiation(Wrappee,String)

whenUsingNewInstance

public final void whenUsingNewInstance(Interaction interaction)
Dispatch this event to all the registered Aspect Components that are woven.

Specified by:
whenUsingNewInstance in interface BaseProgramListener
Parameters:
interaction - the interaction that triggered the whenUsingNewInstance event (usually a constructor invocation)
See Also:
AspectComponent.whenUsingNewInstance(Interaction), BaseProgramListener.whenUsingNewInstance(Interaction)

whenUsingNewClass

public final void whenUsingNewClass(ClassItem cl)
Description copied from interface: BaseProgramListener
This method is upcalled by JAC when a static method is called for the first time.

Specified by:
whenUsingNewClass in interface BaseProgramListener
Parameters:
cl - the class that is used for the first time.
See Also:
CollaborationParticipant, #whenUsingNewInstance()

whenSerialized

public final Wrappee whenSerialized(Wrappee orgObject,
                                    SerializedJacObject finalObject)
Dispatch this event to all the woven Aspect Components.

Note: the current collaboration contains an attribute called "orgObject" and that is a reference to the object that is currently serialized.

Specified by:
whenSerialized in interface BaseProgramListener
Parameters:
finalObject - the corresponding serialized structure.
orgObject - the object being serialized
Returns:
the object being serialized (usually orgObject, but not necessarily).
See Also:
AspectComponent.whenSerialized(Wrappee,SerializedJacObject), BaseProgramListener.whenSerialized(Wrappee,SerializedJacObject)

whenDeserialized

public final Wrappee whenDeserialized(SerializedJacObject orgObject,
                                      Wrappee finalObject)
Dispatch this event to all the woven Aspect Components.

Note: the current collaboration contains an attribute called "finalObject" and that is a reference to the object that is will be finally deserialized.

Specified by:
whenDeserialized in interface BaseProgramListener
Parameters:
orgObject - the corresponding serialized structure.
finalObject - the object being deserialized
Returns:
the object being deserialized (usually finalObject but not necessarily)
See Also:
AspectComponent.whenDeserialized(SerializedJacObject,Wrappee), BaseProgramListener.whenDeserialized(SerializedJacObject,Wrappee)

simulateUsingNewInstance

public final void simulateUsingNewInstance(Wrappee wrappee)
Apply all the woven aspect components to the given wrappee.

Parameters:
wrappee - the wrappee that have to be treated

whenClone

public final void whenClone(Wrappee cloned,
                            Wrappee clone)
Dispatch this event to all the registered Aspect Components that are woven.

Specified by:
whenClone in interface BaseProgramListener
Parameters:
cloned - the wrappee that is being cloned
clone - the new clone of cloned
See Also:
AspectComponent.whenClone(Wrappee,Wrappee), BaseProgramListener.whenClone(Wrappee,Wrappee)

whenDeleted

public final void whenDeleted(Wrappee object)
Description copied from interface: BaseProgramListener
Upcalled when an object is deleted.

Specified by:
whenDeleted in interface BaseProgramListener

whenFree

public final void whenFree(Wrappee object)
Description copied from interface: BaseProgramListener
Upcalled when an object is freed from the memory.

Specified by:
whenFree in interface BaseProgramListener

afterApplicationStarted

public final void afterApplicationStarted()
Dispatch this event to all the registered Aspect Components that are woven.

Specified by:
afterApplicationStarted in interface BaseProgramListener
See Also:
AspectComponent.afterApplicationStarted()

onExit

public final void onExit()
Description copied from interface: BaseProgramListener
This method is upcalled when the system exits.

Specified by:
onExit in interface BaseProgramListener

whenTopologyChanged

public final void whenTopologyChanged()
Dispatch this event to all the registered Aspect Components that are woven.

Specified by:
whenTopologyChanged in interface BaseProgramListener
See Also:
AspectComponent.whenTopologyChanged()

whenCloseDisplay

public final void whenCloseDisplay(Display display)
Dispatch this event to all the registered Aspect Components that are woven.

Specified by:
whenCloseDisplay in interface BaseProgramListener
Parameters:
display - the closing display
See Also:
AspectComponent.whenCloseDisplay(Display)

beforeRunningWrapper

public final boolean beforeRunningWrapper(Wrapper wrapper,
                                          String wrappingMethod)
Forward this event to the aspect component that owns the wrapper.

Specified by:
beforeRunningWrapper in interface BaseProgramListener
Parameters:
wrapper - the wrapper that is going to be runned
wrappingMethod - the name of the may-be runned wrapping
Returns:
a boolean that tells if the wrapper has to be runned (true) or not (false)
See Also:
AspectComponent.beforeRunningWrapper(Wrapper,String), BaseProgramListener.beforeRunningWrapper(Wrapper,String)

afterRunningWrapper

public final void afterRunningWrapper(Wrapper wrapper,
                                      String wrappingMethod)
Upcall the beforeRunningWrapper method of all the aspect component that owns the wrapper.

Specified by:
afterRunningWrapper in interface BaseProgramListener
Parameters:
wrapper - the wrapper that has just been runned
wrappingMethod - the name of the runned wrapping method
See Also:
AspectComponent.afterRunningWrapper(Wrapper,String), BaseProgramListener.afterRunningWrapper(Wrapper,String)

afterWrap

public final void afterWrap(Wrappee wrappee,
                            Wrapper wrapper,
                            String[] wrapping_methods,
                            String[][] wrapped_methods)
Upcall the beforeRunningWrapper method of all the aspect component that owns the wrapper.

Specified by:
afterWrap in interface BaseProgramListener
See Also:
AspectComponent.afterWrap(Wrappee,Wrapper,String[],String[][])

whenGetObjects

public void whenGetObjects(Collection objects,
                           ClassItem cl)
Description copied from interface: BaseProgramListener
Calls whenGetObjects on all aspects.

Specified by:
whenGetObjects in interface BaseProgramListener
Parameters:
objects - list of objects already in memory
cl - return only instances of this class

whenNameObject

public String whenNameObject(Object object,
                             String name)
Description copied from interface: BaseProgramListener
Upcalled when the naming aspect names an object.

Specified by:
whenNameObject in interface BaseProgramListener
Parameters:
object - the object to name
name - current name of the object or null
Returns:
the proposed name for the object

whenObjectMiss

public void whenObjectMiss(String name)
Description copied from interface: BaseProgramListener
Upcalled when an object is been seeked within the name repository and is not found.

The finally found object is a contextual attribute called FOUND_OBJECT.

Specified by:
whenObjectMiss in interface BaseProgramListener
Parameters:
name - the name that has not been found
See Also:
BaseProgramListener.FOUND_OBJECT

register

public final boolean register(String name,
                              Object aspectComponent)
Register a new aspect component.

When a new aspect component is registered, the allWoven flag is set to false. And the checkWeaving method will be called for each base method call until all the aspect components are woven.

Overrides:
register in class OrderedRepository
Parameters:
name - the aspect component key for the AC manager
aspectComponent - the registered aspect component
Returns:
true if the object registered, false if already registered
See Also:
AspectComponent.weave()

registerWithName

public final boolean registerWithName(String name,
                                      String className)
A resister method that can be used by a UI.

This method creates a new aspect component with the name of the given class and registers it. It will be woven immediatly.

Parameters:
name - the aspect component key for the AC manager
className - the aspect component class name
See Also:
register(String,Object), AspectComponent.weave()

weave

public final void weave(AspectComponent ac)
Register (if not allready registered) and weaves a new Aspect Component.

Parameters:
ac - the aspect component to weave
See Also:
register(String,Object), AspectComponent.weave()

unregister

public final void unregister(String name)
Unregister a given aspect component (it is then unwoven).

Overrides:
unregister in class OrderedRepository
Parameters:
name - the aspect component key for the AC manager
See Also:
register(String,Object), AspectComponent.unweave()

attrdef

public final void attrdef(String name,
                          Object value)

attr

public final Object attr(String name)

reloadAspect

public void reloadAspect(String application,
                         String aspect)
Reload an aspect for an application

Parameters:
application - the application's name
aspect - the aspect's name

reloadAspect

public void reloadAspect(String aspect)
                  throws Exception
Reload an aspect for the current application

Parameters:
aspect - the aspect's name
Exception

beforeWrappeeInit

public final void beforeWrappeeInit(Wrappee wrappee)
Description copied from interface: BaseProgramListener
This method should be called by the GUI system before an object is being created and initialized (but the process is not finished yet).

Then, some aspects should deal differently with this object thant with already created objects (for instance, the GUI aspect should not show the object to other users, or a remote access aspect should disable forwarding.

Specified by:
beforeWrappeeInit in interface BaseProgramListener

afterWrappeeInit

public final void afterWrappeeInit(Wrappee wrappee)
Description copied from interface: BaseProgramListener
This method should be called by the GUI system after an object has been created and initialized (tells the other aspects that the object is now regular).

Specified by:
afterWrappeeInit in interface BaseProgramListener

Contact JAC development team:
Renaud Pawlak
Lionel Seinturier
Laurent Martelli