ARoad0.gWork
Class RightsMediatorImpl

java.lang.Object
  extended by ARoad0.gWork.RightsMediatorImpl
All Implemented Interfaces:
AlgorithmInterpreter, RightsMediator, RightsNetworkObserver, MVC_Controller, java.beans.PropertyChangeListener, java.util.EventListener

public class RightsMediatorImpl
extends java.lang.Object
implements RightsMediator

This class is a change event adaptor for all the BaseObjects associated to a view, and it is responsible to manage the paths search algorithms for each view. It takes account of the AcsAddons.

This is a component of the event management pattern for the views. This class informs the view GraphicViewBaselistenerImpl when the rights may have changed. It is independant to the graphic view, which may be deleted and created several times by GraphicViewBaselistenerImpl. This responsability implies, for each view-related object and through the method setRightsNetwork(), to follow:

- every ACS bridge change,

- every bound property change, including the AclEntry rights,

- every deleted BaseObject which is in an AccessControlLink,

- every new ACS userID with 'root' rights,

- every new ACS actor belonging to its userID, its groupID,

or to a groupID which contains its userID, its groupID,

- every new ACS userID belonging to its groupID,

or to a groupID which contains its userID, its groupID,

- every new ACS actor executed through 'other' rights with a current account or group,

- every PrivilegeForLinks change in the sources and the targets,

- every specific property change from an AcsAddon object,

but to not follow a view-related object when it is a new element of the view, since it is handled directly by the BaseListener. The AclEntries and external linked Privileges are switched when their ACS is saved (see gBase.BaseManagerImpl). To avoid useless right analysis, ActionSave and ActionSaveAll unregister this class before any ACS saving, to not process the property changes from the AclEntries and Privileges. The Gui2.GraphicViewBaseListenerImpl instance that works with the RightsMediatorImpl instance must register itself as a PropertyChangeListener of this instance. It must have a ViewInBase as main event source. The interface methods ACSObjectAddon.getAddonInnerPropertiesToListen() and getAddonParentPropertiesToListen() are used to handle the AcsAddon property change events. The aim is to update any view which contains a node from such an AcsAddon. These methods are ridden by ARoad0.UtilityImpl that is invoked by RightsMediatorImpl.

The second responsibility of this class is the selection of algorithms. Following the design pattern Interpreter in the GoF collection, this class manages the path search algorithms of EPRViewInBase, NoThanViewInBase and SketchViewInBase. Each view uses dedicated instances of 8 generic gWork classes and 1 generic gBase class that implement the core algorithms. Each view uses, for each view node and each intermediate node in an access path, one instance of NodeRights and one instance of LinkRights. All these objects are created and managed by this RightsMediatorImpl class. For an EPRViewInBase and a NoThanViewInBase, the instances for the old view nodes are never removed, including the NoThanViewInBase first target, nor the instances for the old intermediate nodes. This is to be ready to the changes in the access paths.

An AcsAddon may include some subclasses of NodeRightsImpl and LinkRightsImpl, and they are selected by RightsMediatorImpl when a node from this AcsAddon is implied. The detection of the AcsAddon packages follows the name pattern of these packages. If there is no NodeRights or LinkRights implementation in the AcsAddon gWork package, the generic class is selected.

All the algorithm class instances in the gWork and AcsAddon.gWork packages that are necessary in the access paths search are stored in 3 dedicated maps in RightsMediatorImpl. They are called by RightsFactory_Facade - which calls the core algorithm classes - and by the core algorithm classes themself.

The instances of this class are created by Gui2.ViewModel and ViewInBase_Facade.createSketchView(). Gui2.GraphicViewBaseListenerImpl is the single listener of an instance.


Field Summary
private  int count_
           
private static int INITIAL_CAPACITY
           
private  java.util.Set l_RightsChangeSupport_
          list of PropertyChangeListeners.
protected  java.util.Set l_RightsNetwork_
          Set of hidden BaseObjects which are implied in the rights analysis for the view
private  java.beans.PropertyChangeEvent lastEvent_
          last property change event received by propertyChange()
private  java.util.Map m_CoreAlgorithms_
          Map of the one instance for each of the 5 classes gWork.xxxRightsFactoryImpl, the 2 gWork.yyyUtilities and gWork.UtilityImpl.
private  java.util.Map<ImmutableName,LinkRights> m_LinkRights_
          Map of the instances of the LinkRights or its subclasses for the view nodes and the analyzed or intermediate nodes.
private  java.util.Map<ImmutableName,NodeRights> m_NodeRights_
          Map of the instances of the NodeRights or its subclasses for the view nodes and the analyzed or intermediate nodes.
private static int PRIME
           
protected  ViewInBase view_
          The BaseListener main event source which defines the rights network is a ViewInBase
 
Fields inherited from interface ARoad0.gWorkInterface.AlgorithmInterpreter
L_CORE_ALGORITHMS_KEYS
 
Constructor Summary
RightsMediatorImpl(ViewInBase _view)
          The view GraphicViewBaseListener must register itself as a PropertyChangeListener of this RightsNetworkObserver instance.
 
Method Summary
 NodeRights addInstancesForNode(BaseObject _node)
          Creates a new NodeRights and a new LinkRights instances for a view node, an analyzed or an intermediate node.
 void addPropertyChangeListener(java.beans.PropertyChangeListener _l)
          Registers a listener for the PropertyChange event The class will fire a PropertyChange value whenever the rights have to be updated.
 void finalizeForProcess()
          Finalizes the instance.
private  void firePropertyChange()
          Fires an event without name to every registered listener, in any order, with null old and null new properties.
 java.util.Collection<LinkRights> getAllLinkRights(java.util.Collection<DisplayableLinkImpl> _l_dLinks)
          Gets the collection of all the LinkRights associated to the nodes in the DisplayableLinkImpls of a collection.
 CoreAlgorithm getCoreAlgorithm(java.lang.String _key)
          Gets the instance to use for this view for a given core algorithm, as instance of one of the 9 classes RightsFactory_Facade, AclRightsFactoryImpl, AgoRightsFactoryImpl, CompoundRightsFactoryImpl, DisplayableLinkUtilities, PrivilegeRightsFactoryImpl, FactoryUtilities, ThreeNodesRightsFactoryImpl and gBase.UtilityImpl.
 java.util.Map<ImmutableName,LinkRights> getLinkRightsInstances()
          Gets the map of the LinkRights instances to use for each view node, analyzed or intermediate node.
 java.util.Map<ImmutableName,NodeRights> getNodeRightsInstances()
          Gets the map of the NodeRights instances to use for each view node, analyzed or intermediate node.
 BaseObject getSource()
          Gets the ViewInBase.
 void propertyChange(java.beans.PropertyChangeEvent _evt)
          Manages the events fired by the base objects of the rights network, to update the rights while there is no updating of the view base objects.
 void removeInstancesForNode(ImmutableName _name)
          Removes the NodeRights and the LinkRights instances for a view node, an analyzed or intermediate node.
 void removePropertyChangeListener(java.beans.PropertyChangeListener _l)
          Removes a listener for the PropertyChange event Called by ActionSave.save().
 void setRightsNetwork(java.util.Set _l_baseObjects)
          When the view nodes network has changed, registers the instance, as a RightsNetworkObserver to listen the bound property changes in the network of ACSObjects and properties which are implied in the view.
 java.lang.String toString()
          Get the values of the view.
 void updateNonCoreAlgorithmsForViewNodes(boolean _clearIntermediateNodes)
          When the view nodes have changed, this method updates the NodeRightsImpl and the LinkRights instances of the view nodes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PRIME

private static final int PRIME
See Also:
Constant Field Values

INITIAL_CAPACITY

private static final int INITIAL_CAPACITY
See Also:
Constant Field Values

count_

private int count_

view_

protected ViewInBase view_
The BaseListener main event source which defines the rights network is a ViewInBase


l_RightsNetwork_

protected java.util.Set l_RightsNetwork_
Set of hidden BaseObjects which are implied in the rights analysis for the view


l_RightsChangeSupport_

private final java.util.Set l_RightsChangeSupport_
list of PropertyChangeListeners.


lastEvent_

private java.beans.PropertyChangeEvent lastEvent_
last property change event received by propertyChange()


m_CoreAlgorithms_

private java.util.Map m_CoreAlgorithms_
Map of the one instance for each of the 5 classes gWork.xxxRightsFactoryImpl, the 2 gWork.yyyUtilities and gWork.UtilityImpl. This provides to the view a dedicated set of instances for the core algorithms to use in the worker thread of the view. The keys are in L_CORE_ALGORITHMS_KEYS.


m_NodeRights_

private java.util.Map<ImmutableName,NodeRights> m_NodeRights_
Map of the instances of the NodeRights or its subclasses for the view nodes and the analyzed or intermediate nodes. This provides to each node a dedicated instance. The keys are the node names.


m_LinkRights_

private java.util.Map<ImmutableName,LinkRights> m_LinkRights_
Map of the instances of the LinkRights or its subclasses for the view nodes and the analyzed or intermediate nodes. This provides to each node a dedicated instance. The keys are the node names.

Constructor Detail

RightsMediatorImpl

public RightsMediatorImpl(ViewInBase _view)
The view GraphicViewBaseListener must register itself as a PropertyChangeListener of this RightsNetworkObserver instance. It must have a ViewInBase as main event source. All the CoreAlgorithm instances from the gWork and AcsAddon.gWork packages that are necessary in the access path search are created and stored in the maps m_CoreAlgorithms_, m_NodeRights_ and m_LinkRights_. The NodeRightsImpl instance and the LinkRights instance of each node in the view are created. Called by Gui2.ViewModel and ViewInBase_Facade.createSketchView().

Parameters:
_view - is the source for which the rights network is defined
See Also:
ViewModel.createViewRightsMediator(ARoad0.gBaseInterface.ViewInBase)
Method Detail

getSource

public BaseObject getSource()
Gets the ViewInBase.

Specified by:
getSource in interface AlgorithmInterpreter
Specified by:
getSource in interface RightsNetworkObserver
Returns:
the view of this mediator

getCoreAlgorithm

public CoreAlgorithm getCoreAlgorithm(java.lang.String _key)
Gets the instance to use for this view for a given core algorithm, as instance of one of the 9 classes RightsFactory_Facade, AclRightsFactoryImpl, AgoRightsFactoryImpl, CompoundRightsFactoryImpl, DisplayableLinkUtilities, PrivilegeRightsFactoryImpl, FactoryUtilities, ThreeNodesRightsFactoryImpl and gBase.UtilityImpl.

Specified by:
getCoreAlgorithm in interface AlgorithmInterpreter
Parameters:
_key - belongs to AlgorithmInterpreter.L_CORE_ALGORITHMS_KEYS
Returns:
the core algorithm for the view, or null

getNodeRightsInstances

public java.util.Map<ImmutableName,NodeRights> getNodeRightsInstances()
Gets the map of the NodeRights instances to use for each view node, analyzed or intermediate node. This includes the first target of a NoThanViewInBase. The term of 'analyzed' is here applicable to a node that is analyzed by the gWork classes, even if it is not finally detected as an intermediate node to put in a stable DiaplayableLinkImpl.

Specified by:
getNodeRightsInstances in interface AlgorithmInterpreter
Returns:
unmodifiable map of NodeRights instances, where the node names are the keys

getLinkRightsInstances

public java.util.Map<ImmutableName,LinkRights> getLinkRightsInstances()
Gets the map of the LinkRights instances to use for each view node, analyzed or intermediate node. This includes the first target of a NoThanViewInBase. The term of 'analyzed' is here applicable to a node that is analyzed by the gWork classes, even if it is not finally detected as an intermediate node to put in a stable DiaplayableLinkImpl.

Specified by:
getLinkRightsInstances in interface AlgorithmInterpreter
Returns:
unmodifiable map of LinkRights instances, where the node names are the keys

updateNonCoreAlgorithmsForViewNodes

public void updateNonCoreAlgorithmsForViewNodes(boolean _clearIntermediateNodes)
When the view nodes have changed, this method updates the NodeRightsImpl and the LinkRights instances of the view nodes. For a NoThanViewInBase, it manages all the BaseObjects into the view checking perimeter and the view first target.

On the other hand, the analyzed nodes and the intermediate nodes of the view are not processed there. The term of 'analyzed' is here applicable to a node that is processed by the gWork classes in the paths search, even if it is not finally detected as an intermediate node to put in a stable DiaplayableLinkImpl. For an EPRViewInBase and a NoThanViewInBase, the old view nodes are never removed, including the NoThanViewInBase first target, nor the old intermediate nodes. This is to be ready to the possible future changes in the access paths.

Called by the constructor, Gui2.ViewModel.changeNonCoreAlgorithms() and ViewInBase_Facade.populateSketchView(). When the parameter is false, the previous view nodes and the intermediate nodes keep their NodeRights and LinkRights instances to speed up the processing.

Specified by:
updateNonCoreAlgorithmsForViewNodes in interface AlgorithmInterpreter
Parameters:
_clearIntermediateNodes - true only for the sketch view, to finalize the NodeRights and LinkRights instances of all the nodes that are not in the view, including all the previous intermediate nodes

addInstancesForNode

public NodeRights addInstancesForNode(BaseObject _node)
Creates a new NodeRights and a new LinkRights instances for a view node, an analyzed or an intermediate node. The term of 'analyzed' is here applicable to a node that is processed by the gWork classes, even if it is not finally detected as an intermediate node to put in a stable DiaplayableLinkImpl.

The detection of the AcsAddon packages follows the name pattern of these packages, and does not use the method ACS.getM_AcsVocabulary() to get the AcsAddon name. If there is no NodeRights or LinkRights implementation in the AcsAddon gWork package, the generic class is selected. Updates the maps m_LinkRights_ and m_NodeRights_.

Called by updateNonCoreAlgorithmsForViewNodes() and by several methods of ThreeNodesRightsFactoryImpl and CompoundRightsFactoryImpl, each time the instances do not exist for a new processed object. The Gui2.GraphicViewBaseListenerImpl method propertyChange() calls directly this method when it receives a 'FirstAccessTarget' event from a NoThanViewInBase.

Specified by:
addInstancesForNode in interface AlgorithmInterpreter
Parameters:
_node - node of the view (including the first target of a NoThanViewInBase) or intermediate node. Never null. It may be already known.
Returns:
a NodeRights instance

removeInstancesForNode

public void removeInstancesForNode(ImmutableName _name)
Removes the NodeRights and the LinkRights instances for a view node, an analyzed or intermediate node. The term of 'analyzed' is here applicable to a node that is analyzed by the gWork classes, even if it is not finally detected as an intermediate node to put in a stable DiaplayableLinkImpl.

Updates the maps m_LinkRights_ and m_NodeRights_. Finalizes the NodeRightsImpl instance. Called by updateNonCoreAlgorithmsForViewNodes() only for the intermediate nodes of a sketch view.

Specified by:
removeInstancesForNode in interface AlgorithmInterpreter
Parameters:
_name - name of the view node, the analyzed or intermediate node

getAllLinkRights

public final java.util.Collection<LinkRights> getAllLinkRights(java.util.Collection<DisplayableLinkImpl> _l_dLinks)
Gets the collection of all the LinkRights associated to the nodes in the DisplayableLinkImpls of a collection. When several nodes are from the same ACS package (the generic gBase or an AcsAddon package), this method returns only one LinkRights instance. Called by CompoundRightsFactoryImpl.detectHiddenCompoundEpRights().

Specified by:
getAllLinkRights in interface AlgorithmInterpreter
Parameters:
_l_dLinks - DisplayableLinkImpls to analyze, all with the same two ends or not. Not null.
Returns:
the LinkRightsImpl instances. Never null.

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener _l)
Registers a listener for the PropertyChange event The class will fire a PropertyChange value whenever the rights have to be updated. Used by ActionSave.save().

Specified by:
addPropertyChangeListener in interface RightsNetworkObserver
Parameters:
_l - An object to be invoked when a PropertyChange event is fired.

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener _l)
Removes a listener for the PropertyChange event Called by ActionSave.save().

Specified by:
removePropertyChangeListener in interface RightsNetworkObserver
Parameters:
_l - the PropertyChange listener to be removed.

setRightsNetwork

public void setRightsNetwork(java.util.Set _l_baseObjects)
When the view nodes network has changed, registers the instance, as a RightsNetworkObserver to listen the bound property changes in the network of ACSObjects and properties which are implied in the view. The view already ensures the following of the property changes in its view elements.

This method registers for the listening of the intermediate nodes for each access path, and also for the analyzed, non-intermediate nodes which should become intermediates in the future, after a property change.

This listening includes the AclEntries and the PrivilegeForLinks, respectively for their rights/conditional groups and their sources/targets. It includes the listening of the specific events from any AcsAddon ACS, or any of its objects, for which the methods BaseUtilityImpl.add/removeAddonInner/ParentPropertyChangeListener() are called. This implies to follow, for each view-related object:

- every ACS bridge change,

- every bound property change, including the AclEntry rights,

- every deleted BaseObject which is in an AccessControlLink,

- every new ACS userID with 'root' rights,

- every new ACS actor belonging to its userID, its groupID,

or to a groupID which contains its userID, its groupID,

- every new ACS userID belonging to its groupID,

or to a groupID which contains its userID, its groupID,

- every new ACS actor executed through 'other' rights with a current account or group,

- every PrivilegeForLinks change in the sources and the targets,

- every specific property change from an AcsAddon object.

The previous listened objects that are not implied in the view are unregistered. This is the most complex method of the class, and it has to follow the evolutions of the properties in the generic gBase ACSObject classes. Calls AclEntryImpl.getIntermediateGroupsToConditionalGroups(). Called by Gui2.ViewModel.

Specified by:
setRightsNetwork in interface RightsNetworkObserver
Parameters:
_l_baseObjects - the BaseObjects which are intermediate nodes in the detected access paths of the view, or an intermediate-node AclEntry

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent _evt)
Manages the events fired by the base objects of the rights network, to update the rights while there is no updating of the view base objects. Most of the events are simply fired with a null property to the listeners, for updating the graphic view. Filters the events about the new UserID having the order 0 (as super-administrator), from the ACS and the UserIDs. Does not fire the 'ImpliedOpenViews' events. Does not fire a 'InheritedXXXRights' event after a 'FromTheParentXXX' event from the same source. Does not fire a 'InheritedTargetPrivileges' or a 'InheritedTargetAclEntries' event if the last event is from the parent.

To avoid the processing of events from a closing ACS during the closing of its child ACS, this method uses TreeManager.haveAtLeastOneTreeBaseListener() to see if ActionClose.closeInGUI() has already closed the parent ACS tree in the explorer.

Specified by:
propertyChange in interface RightsNetworkObserver
Specified by:
propertyChange in interface java.beans.PropertyChangeListener
Parameters:
_evt - is the event from the gBase objects

finalizeForProcess

public void finalizeForProcess()
Finalizes the instance. Called by Gui2.ViewModel.removeViewRightsMediator().

Specified by:
finalizeForProcess in interface RightsNetworkObserver

toString

public java.lang.String toString()
Get the values of the view.

Specified by:
toString in interface RightsNetworkObserver
Overrides:
toString in class java.lang.Object
Returns:
view.toString() with the name of the class

firePropertyChange

private void firePropertyChange()
Fires an event without name to every registered listener, in any order, with null old and null new properties. The GraphicViewBaseListenerImpl instance of this ViewInBase is the single listener. Called only by propertyChange().