Package jadex.rules.tools.stateviewer
Class CopyState
- java.lang.Object
-
- jadex.rules.tools.stateviewer.CopyState
-
- All Implemented Interfaces:
IOAVState
public class CopyState extends java.lang.Object implements IOAVState
A copy state allows to decouple a state from the user (e.g. a local or remote gui tool). Changes to the original state will be represented in the copy state, but synchronized to a user environment (e.g. swing thread). Therefore, a synchronizator needs to be set.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.MapcopyThe state copy.protected IOAVStateListenerlistenerThe listener on the original state.protected java.util.ListlistenersThe listeners.protected java.util.SetrootobjectsThe root objects.protected IOAVStatestateThe original state.protected ISynchronizatorsynchronizatorThe synchronizator (e.g. swing sync.).protected OAVTypeModeltmodelThe typemodel.
-
Constructor Summary
Constructors Constructor Description CopyState(IOAVState state, ISynchronizator synchronizator)Create a local copy state.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAttributeValue(java.lang.Object object, OAVAttributeType attribute, java.lang.Object value)Add an attribute of an object to the given value.voidaddExternalObjectUsage(java.lang.Object id, java.lang.Object external)Add an external usage of a state object.voidaddJavaRootObject(java.lang.Object object)Add a Java object as root object.voidaddStateListener(IOAVStateListener listener, boolean bunch)Add a new state listener.voidaddSubstate(IOAVState substate)Add a substate.booleancontainsKey(java.lang.Object object, OAVAttributeType attribute, java.lang.Object key)Test if a key is contained in the map attribute.booleancontainsObject(java.lang.Object object)Test if the state contains a specific object.protected static java.util.MapcopyObject(IOAVState state, java.lang.Object id, OAVObjectType type)Copy an OAV object into a map.java.lang.ObjectcreateObject(OAVObjectType type)Create an object.java.lang.ObjectcreateRootObject(OAVObjectType type)Create a root object.voiddispose()Dispose the state.voiddropObject(java.lang.Object object)Drop an object from the state.booleanequals(java.lang.Object a, java.lang.Object b)Test if two values are equal according to current identity/equality settings.voidexpungeStaleObjects()Expunge stale objects.java.util.ListfindCycle(java.util.Collection objects)Find a cycle in a given set of objects.java.util.CollectiongetAttributeKeys(java.lang.Object object, OAVAttributeType attribute)Get the keys of an attribute of an object.java.lang.ObjectgetAttributeValue(java.lang.Object object, OAVAttributeType attribute)Get an attribute value of an object.java.lang.ObjectgetAttributeValue(java.lang.Object object, OAVAttributeType attribute, java.lang.Object key)Get an attribute value of an object.java.util.CollectiongetAttributeValues(java.lang.Object object, OAVAttributeType attribute)Get the values of an attribute of an object.java.util.IteratorgetDeepObjects()Get all objects in the state and its substates.java.util.IteratorgetObjects()Get all objects in the state.IProfilergetProfiler()Get the profiler.java.util.CollectiongetReferencingObjects(java.lang.Object value)Get those objects referencing a given object.java.util.IteratorgetRootObjects()Get the root objects of the state.intgetSize()Get the number of objects in the state.IOAVState[]getSubstates()Get the substates.ISynchronizatorgetSynchronizator()Get the synchronizator (if any).OAVObjectTypegetType(java.lang.Object object)Get the type of an object.OAVTypeModelgetTypeModel()Get the type model.java.util.CollectiongetUnreferencedObjects()Get all unreferenced objects.booleanisIdentifier(java.lang.Object object)Test if the object represents an identifier.booleanisJavaIdentity()Flag indicating that java objects are stored by identity instead of equality.voidnotifyEventListeners()Throw collected events and notify the listeners.voidremoveAttributeValue(java.lang.Object object, OAVAttributeType attribute, java.lang.Object value)Remove an attribute of an object to the given value.voidremoveExternalObjectUsage(java.lang.Object id, java.lang.Object external)Remove an external usage of a state object.voidremoveJavaRootObject(java.lang.Object object)Remove a Java object from root objects.voidremoveStateListener(IOAVStateListener listener)Remove a state listener.voidsetAttributeValue(java.lang.Object object, OAVAttributeType attribute, java.lang.Object value)Set an attribute of an object to the given value.voidsetProfiler(IProfiler profiler)Set the profiler.voidsetSynchronizator(ISynchronizator synchronizator)Set the synchronizator.
-
-
-
Field Detail
-
copy
protected java.util.Map copy
The state copy.
-
tmodel
protected OAVTypeModel tmodel
The typemodel.
-
rootobjects
protected java.util.Set rootobjects
The root objects.
-
synchronizator
protected ISynchronizator synchronizator
The synchronizator (e.g. swing sync.).
-
state
protected IOAVState state
The original state.
-
listener
protected IOAVStateListener listener
The listener on the original state.
-
listeners
protected java.util.List listeners
The listeners.
-
-
Constructor Detail
-
CopyState
public CopyState(IOAVState state, ISynchronizator synchronizator)
Create a local copy state.- Parameters:
state- The original state.synchronizator- The synchronizator used to reflect changes in the copy state.
-
-
Method Detail
-
copyObject
protected static java.util.Map copyObject(IOAVState state, java.lang.Object id, OAVObjectType type)
Copy an OAV object into a map.
-
getTypeModel
public OAVTypeModel getTypeModel()
Get the type model.- Specified by:
getTypeModelin interfaceIOAVState- Returns:
- The type model.
-
createObject
public java.lang.Object createObject(OAVObjectType type)
Create an object. Creates an object identifier that can be used to store/retrieve attribute values. May reuse old object identifiers for performance.- Specified by:
createObjectin interfaceIOAVState- Parameters:
type- The object type (null for defining meta types).- Returns:
- An object identifier.
-
createRootObject
public java.lang.Object createRootObject(OAVObjectType type)
Create a root object. A root object will not be automatically garbage collected when no references point to this object any longer. Creates an object identifier that can be used to store/retrieve attribute values. May reuse old object identifiers for performance.- Specified by:
createRootObjectin interfaceIOAVState- Returns:
- An object identifier.
-
dropObject
public void dropObject(java.lang.Object object)
Drop an object from the state. Recursively removes the object and all connected objects that are not referenced elsewhere.- Specified by:
dropObjectin interfaceIOAVState- Parameters:
object- The identifier of the object to remove.
-
addJavaRootObject
public void addJavaRootObject(java.lang.Object object)
Add a Java object as root object.- Specified by:
addJavaRootObjectin interfaceIOAVState- Parameters:
object- The Java object.
-
removeJavaRootObject
public void removeJavaRootObject(java.lang.Object object)
Remove a Java object from root objects.- Specified by:
removeJavaRootObjectin interfaceIOAVState- Parameters:
object- The Java object.
-
containsObject
public boolean containsObject(java.lang.Object object)
Test if the state contains a specific object.- Specified by:
containsObjectin interfaceIOAVState- Parameters:
object- The object identifier.- Returns:
- True, if contained.
-
isIdentifier
public boolean isIdentifier(java.lang.Object object)
Test if the object represents an identifier.- Specified by:
isIdentifierin interfaceIOAVState- Parameters:
object- The suspected object identifier.- Returns:
- True, if object identifier.
-
getType
public OAVObjectType getType(java.lang.Object object)
Get the type of an object.
-
getObjects
public java.util.Iterator getObjects()
Get all objects in the state.- Specified by:
getObjectsin interfaceIOAVState
-
getDeepObjects
public java.util.Iterator getDeepObjects()
Get all objects in the state and its substates.- Specified by:
getDeepObjectsin interfaceIOAVState
-
getRootObjects
public java.util.Iterator getRootObjects()
Get the root objects of the state.- Specified by:
getRootObjectsin interfaceIOAVState
-
getSize
public int getSize()
Get the number of objects in the state. Optional operation used for debugging only.
-
getUnreferencedObjects
public java.util.Collection getUnreferencedObjects()
Get all unreferenced objects.- Specified by:
getUnreferencedObjectsin interfaceIOAVState- Returns:
- All unreferenced objects of the state.
-
findCycle
public java.util.List findCycle(java.util.Collection objects)
Find a cycle in a given set of objects.
-
getReferencingObjects
public java.util.Collection getReferencingObjects(java.lang.Object value)
Get those objects referencing a given object.- Specified by:
getReferencingObjectsin interfaceIOAVState
-
addExternalObjectUsage
public void addExternalObjectUsage(java.lang.Object id, java.lang.Object external)Add an external usage of a state object. This prevents the oav object of being garbage collected as long as external references are present.- Specified by:
addExternalObjectUsagein interfaceIOAVState- Parameters:
id- The oav object id.external- The user object.
-
removeExternalObjectUsage
public void removeExternalObjectUsage(java.lang.Object id, java.lang.Object external)Remove an external usage of a state object. This allows the oav object of being garbage collected when no further external references and no internal references are present.- Specified by:
removeExternalObjectUsagein interfaceIOAVState- Parameters:
id- The oav object id.external- The state external object.
-
getAttributeValue
public java.lang.Object getAttributeValue(java.lang.Object object, OAVAttributeType attribute)Get an attribute value of an object.- Specified by:
getAttributeValuein interfaceIOAVState- Parameters:
object- The identifier of the object.attribute- The attribute identifier.- Returns:
- The value (basic, object id or java object).
-
setAttributeValue
public void setAttributeValue(java.lang.Object object, OAVAttributeType attribute, java.lang.Object value)Set an attribute of an object to the given value.- Specified by:
setAttributeValuein interfaceIOAVState- Parameters:
object- The identifier of the object.attribute- The attribute identifier.value- The value (basic, object id or java object).
-
getAttributeValues
public java.util.Collection getAttributeValues(java.lang.Object object, OAVAttributeType attribute)Get the values of an attribute of an object.- Specified by:
getAttributeValuesin interfaceIOAVState- Parameters:
object- The identifier of the object.attribute- The attribute identifier.- Returns:
- The values (basic, object ids or java objects).
-
getAttributeKeys
public java.util.Collection getAttributeKeys(java.lang.Object object, OAVAttributeType attribute)Get the keys of an attribute of an object.- Specified by:
getAttributeKeysin interfaceIOAVState- Parameters:
object- The identifier of the object.attribute- The attribute identifier.- Returns:
- The keys for which values are stored.
-
getAttributeValue
public java.lang.Object getAttributeValue(java.lang.Object object, OAVAttributeType attribute, java.lang.Object key)Get an attribute value of an object. Method only applicable for map attribute type.- Specified by:
getAttributeValuein interfaceIOAVState- Parameters:
object- The identifier of the object.attribute- The attribute identifier.key- The key.- Returns:
- The value (basic, object id or java object).
-
containsKey
public boolean containsKey(java.lang.Object object, OAVAttributeType attribute, java.lang.Object key)Test if a key is contained in the map attribute.- Specified by:
containsKeyin interfaceIOAVState- Parameters:
object- The identifier of the object.attribute- The attribute identifier.key- The key.- Returns:
- True if key is available.
-
addAttributeValue
public void addAttributeValue(java.lang.Object object, OAVAttributeType attribute, java.lang.Object value)Add an attribute of an object to the given value.- Specified by:
addAttributeValuein interfaceIOAVState- Parameters:
object- The identifier of the object.attribute- The attribute identifier.value- The value (basic, object id or java object).
-
removeAttributeValue
public void removeAttributeValue(java.lang.Object object, OAVAttributeType attribute, java.lang.Object value)Remove an attribute of an object to the given value.- Specified by:
removeAttributeValuein interfaceIOAVState- Parameters:
object- The identifier of the object.attribute- The attribute identifier.value- The value (basic, object id or java object).
-
addStateListener
public void addStateListener(IOAVStateListener listener, boolean bunch)
Add a new state listener.- Specified by:
addStateListenerin interfaceIOAVState- Parameters:
listener- The state listener.bunch- True, for adding a bunch listener.
-
removeStateListener
public void removeStateListener(IOAVStateListener listener)
Remove a state listener.- Specified by:
removeStateListenerin interfaceIOAVState- Parameters:
listener- The state listener.
-
notifyEventListeners
public void notifyEventListeners()
Throw collected events and notify the listeners. Necessary if in event collecting mode.- Specified by:
notifyEventListenersin interfaceIOAVState
-
expungeStaleObjects
public void expungeStaleObjects()
Expunge stale objects.- Specified by:
expungeStaleObjectsin interfaceIOAVState
-
setSynchronizator
public void setSynchronizator(ISynchronizator synchronizator)
Set the synchronizator. For the copy state, setting a synchronizator is required, as it is used to forward changes of the original state to the copy.- Specified by:
setSynchronizatorin interfaceIOAVState
-
getSynchronizator
public ISynchronizator getSynchronizator()
Get the synchronizator (if any). The synchronizator (if available) can be used to synchronize access to the state with internal and external modifications.- Specified by:
getSynchronizatorin interfaceIOAVState
-
getProfiler
public IProfiler getProfiler()
Get the profiler.- Specified by:
getProfilerin interfaceIOAVState
-
setProfiler
public void setProfiler(IProfiler profiler)
Set the profiler.- Specified by:
setProfilerin interfaceIOAVState
-
addSubstate
public void addSubstate(IOAVState substate)
Add a substate. Read accesses will be transparently mapped to substates. Write accesses to substates need not be supported and may generate UnsupportedOperationException. Also it can not be assumed that addition of substates will generate object added events.- Specified by:
addSubstatein interfaceIOAVState
-
getSubstates
public IOAVState[] getSubstates()
Get the substates.- Specified by:
getSubstatesin interfaceIOAVState
-
equals
public boolean equals(java.lang.Object a, java.lang.Object b)Test if two values are equal according to current identity/equality settings.
-
isJavaIdentity
public boolean isJavaIdentity()
Flag indicating that java objects are stored by identity instead of equality.- Specified by:
isJavaIdentityin interfaceIOAVState
-
-