public abstract class OAVAbstractState extends java.lang.Object implements IOAVState
Modifier and Type | Field and Description |
---|---|
protected int |
beanlistenercnt
Counter for number of registered bean listeners.
|
protected java.util.Map |
deletedobjects
The deleted objects (only available in event notifications) (oid -> content map).
|
protected OAVEventHandler |
eventhandler
The OAV event handler.
|
protected IOAVIdGenerator |
generator
The id generator.
|
protected boolean |
javaidentity
Flag to enable identity handling of java objects (instead of equality).
|
protected java.util.Set |
javaobjects
The java objects set.
|
protected boolean |
nocheck
The flag to disable type checking.
|
protected java.util.Map |
objectusages
The usages of object ids (object id -> usages[map] (objectusage -> cnt)).
|
protected static java.lang.Class[] |
PCL
The argument types for property change listener adding/removal (cached for speed).
|
protected java.util.Map |
pcls
The Java beans property change listeners.
|
protected IProfiler |
profiler
The profiler.
|
protected java.util.Set |
rootobjects
The root objects (will not be cleaned up when usages==0) (oids + java objects).
|
protected IOAVState[] |
substates
List of substates (if any).
|
protected jadex.commons.concurrent.ISynchronizator |
synchronizator
The synchronizator (if any).
|
protected OAVTypeModel |
tmodel
The type models.
|
protected static java.lang.String |
TYPE
The type identifier.
|
Constructor and Description |
---|
OAVAbstractState(OAVTypeModel tmodel)
Create a new empty OAV state representation.
|
Modifier and Type | Method and Description |
---|---|
void |
addAttributeValue(java.lang.Object id,
OAVAttributeType attribute,
java.lang.Object value)
Add an attribute of an object (oid) to the given value.
|
abstract void |
addExternalObjectUsage(java.lang.Object id,
java.lang.Object external)
Add an external usage of a state object (oid).
|
void |
addJavaRootObject(java.lang.Object object)
Add a Java object as root object.
|
protected void |
addObjectUsage(java.lang.Object whichid,
OAVAttributeType whichattr,
java.lang.Object value)
Add an object (oid of java object) usage.
|
void |
addStateListener(IOAVStateListener listener,
boolean bunch)
Add a new state listener.
|
void |
addSubstate(IOAVState substate)
Add a substate.
|
protected boolean |
checkMultiplicity(java.lang.Object id,
OAVAttributeType attribute,
java.util.Set allowedmults)
Ensure that multiplicity is ok.
|
protected boolean |
checkMultiplicity(java.lang.Object id,
OAVAttributeType attribute,
java.lang.String allowedmult)
Ensure that multiplicity is ok.
|
protected boolean |
checkTypeDefined(OAVObjectType type)
Test if a type is defined in one of the models.
|
protected boolean |
checkTypeHasAttribute(java.lang.Object id,
OAVAttributeType attribute)
Ensure that a type has an attribute.
|
protected boolean |
checkValidStateObject(java.lang.Object id)
Test if the object is a valid state object (oid).
|
protected boolean |
checkValidStateObjectRead(java.lang.Object id)
Test if reading the object (oid) is allowed.
|
protected boolean |
checkValidStateValue(java.lang.Object value)
Test if the object is a valid state value, meaning
that is either a state object or a java value.
|
protected boolean |
checkValueCompatibility(java.lang.Object id,
OAVAttributeType attribute,
java.lang.Object value)
Check if it is allowed to set or add an attribute value.
|
boolean |
containsKey(java.lang.Object id,
OAVAttributeType attribute,
java.lang.Object key)
Test if a key is contained in the map attribute.
|
boolean |
containsObject(java.lang.Object id)
Test if the state contains a specific object (oid).
|
IOAVIdGenerator |
createIdGenerator()
Create an id generator.
|
java.lang.Object |
createObject(OAVObjectType type)
Create an object.
|
protected java.lang.Object |
createObject(OAVObjectType type,
boolean root)
Impl of root/non-root object creation.
|
java.lang.Object |
createRootObject(OAVObjectType type)
Create a root object.
|
protected void |
deregisterValue(OAVJavaType type,
java.lang.Object value)
Deregister a value for observation.
|
void |
dispose()
Dispose the state.
|
void |
dropObject(java.lang.Object id)
Drop an object (oid) from the state.
|
boolean |
equals(java.lang.Object a,
java.lang.Object b)
Test if two values are equal
according to current identity/equality
settings.
|
void |
expungeStaleObjects()
Expunge stale objects.
|
java.util.List |
findCycle(java.util.Collection oids)
Find a cycle in a given set of objects (oids).
|
protected java.util.List |
findCycleForValue(java.util.Collection oids,
java.util.Set checked,
java.util.Map edges,
java.util.List subgraph,
java.lang.Object current,
java.lang.Object next,
OAVAttributeType attr)
Step for one edge of the find cycle algorithm.
|
java.util.Collection |
getAttributeKeys(java.lang.Object id,
OAVAttributeType attribute)
Get the keys of an attribute of an object.
|
java.lang.Object |
getAttributeValue(java.lang.Object id,
OAVAttributeType attribute)
Get an attribute value of an object (oid).
|
java.lang.Object |
getAttributeValue(java.lang.Object id,
OAVAttributeType attribute,
java.lang.Object key)
Get an attribute value of an object (oid).
|
java.util.Collection |
getAttributeValues(java.lang.Object id,
OAVAttributeType attribute)
Get the values of an attribute of an object (oid).
|
java.util.Iterator |
getDeepObjects()
Get all objects (oids and java objects) in the state and its substates.
|
protected java.util.Map |
getObject(java.lang.Object id)
Get an object map for its id.
|
protected java.util.Map |
getObject0(java.lang.Object id)
Get an object map for its id.
|
java.util.Iterator |
getObjects()
Get all objects (oids and java objects) in the state.
|
protected java.util.Map |
getObjectUsages(java.lang.Object object)
Get all object usages.
|
IProfiler |
getProfiler()
Get the profiler.
|
java.util.Collection |
getReferencingObjects(java.lang.Object value)
Get those objects referencing a given object (java object or oid).
|
java.util.Iterator |
getRootObjects()
Get the root objects (oids and java objects) of the state.
|
int |
getSize()
Get the number of objects (oids and java objects) in the state.
|
IOAVState[] |
getSubstates()
Get the substates.
|
jadex.commons.concurrent.ISynchronizator |
getSynchronizator()
Get the synchronizator (if any).
|
OAVObjectType |
getType(java.lang.Object object)
Get the type of an object (oid or java object).
|
OAVTypeModel |
getTypeModel()
Get the type model.
|
java.util.Collection |
getUnreferencedObjects()
Get all unreferenced objects (oids).
|
protected abstract boolean |
internalContainsObject(java.lang.Object id)
Test if an object is contained in the state.
|
protected abstract java.util.Map |
internalCreateObject(java.lang.Object id)
Internally create an object.
|
protected void |
internalDropObject(java.lang.Object id,
java.util.Set dropset,
boolean keepalive)
Internal drop method for avoiding cycles in to be dropped
objects during a recursive drop operation.
|
protected abstract java.util.Map |
internalGetObjectContent(java.lang.Object id)
Get the object content of an object.
|
protected abstract java.util.Set |
internalGetObjects()
Get a set of the internal state objects.
|
protected abstract int |
internalObjectsSize()
Test how many object are contained in the state.
|
protected abstract java.util.Map |
internalRemoveObject(java.lang.Object id)
Remove an object from the state objects.
|
protected abstract boolean |
isExternallyUsed(java.lang.Object id)
Test if an object is externally used.
|
boolean |
isIdentifier(java.lang.Object object)
Test if the object represents an identifier.
|
boolean |
isJavaIdentity()
Flag indicating that java objects are
stored by identity instead of equality.
|
protected boolean |
isManaged(java.lang.Object value)
Check if a value (oid or java object) is managed by the state.
|
protected boolean |
isReachable(java.lang.Object id,
java.util.Set tested)
Test if an object (oid) can be reached from some root or external object.
|
void |
notifyEventListeners()
Throw collected events and notify the listeners.
|
protected void |
registerValue(OAVJavaType type,
java.lang.Object value)
Register a value for observation.
|
void |
removeAttributeValue(java.lang.Object id,
OAVAttributeType attribute,
java.lang.Object value)
Remove an attribute of an object (oid) to the given value.
|
abstract void |
removeExternalObjectUsage(java.lang.Object id,
java.lang.Object external)
Remove an external usage of a state object (oid).
|
void |
removeJavaRootObject(java.lang.Object object)
Drop a Java object from root objects.
|
protected void |
removeObject(java.lang.Object id)
Ultimately remove an object (oid), when there are no more external or internal references.
|
protected void |
removeObjectUsage(java.lang.Object whichid,
OAVAttributeType whichattr,
java.lang.Object value,
java.util.Set dropset,
boolean keepalive)
Remove an object (oid or java object) usage.
|
void |
removeStateListener(IOAVStateListener listener)
Remove a state listener.
|
void |
setAttributeValue(java.lang.Object id,
OAVAttributeType attribute,
java.lang.Object value)
Set an attribute of an object (oid) to the given value.
|
void |
setProfiler(IProfiler profiler)
Set the profiler.
|
void |
setSynchronizator(jadex.commons.concurrent.ISynchronizator synchronizator)
Set the synchronizator.
|
java.lang.String |
toString()
Get the string representation of the object.
|
protected static final java.lang.Class[] PCL
protected static final java.lang.String TYPE
protected OAVTypeModel tmodel
protected java.util.Set rootobjects
protected java.util.Map deletedobjects
protected java.util.Set javaobjects
protected IOAVIdGenerator generator
protected boolean nocheck
protected java.util.Map objectusages
protected java.util.Map pcls
protected OAVEventHandler eventhandler
protected IOAVState[] substates
protected jadex.commons.concurrent.ISynchronizator synchronizator
protected int beanlistenercnt
protected boolean javaidentity
protected IProfiler profiler
public OAVAbstractState(OAVTypeModel tmodel)
public IOAVIdGenerator createIdGenerator()
public OAVTypeModel getTypeModel()
getTypeModel
in interface IOAVState
public java.lang.Object createObject(OAVObjectType type)
createObject
in interface IOAVState
type
- The object type (null for defining meta types).public java.lang.Object createRootObject(OAVObjectType type)
createRootObject
in interface IOAVState
protected java.lang.Object createObject(OAVObjectType type, boolean root)
public void dropObject(java.lang.Object id)
dropObject
in interface IOAVState
id
- The identifier of the object to remove.public void addJavaRootObject(java.lang.Object object)
addJavaRootObject
in interface IOAVState
object
- The Java object.public void removeJavaRootObject(java.lang.Object object)
removeJavaRootObject
in interface IOAVState
object
- The Java object.protected void internalDropObject(java.lang.Object id, java.util.Set dropset, boolean keepalive)
id
- The object (oid) to be dropped.dropset
- A set of already dropped objects (to avoid infinite recursion).keepalive
- A flag indicating that at least one object in the path is externally referenced
(object usages will not be removed, but set to external).protected void removeObject(java.lang.Object id)
public boolean containsObject(java.lang.Object id)
containsObject
in interface IOAVState
id
- The object id.public boolean isIdentifier(java.lang.Object object)
isIdentifier
in interface IOAVState
object
- The suspected object identifier.public OAVObjectType getType(java.lang.Object object)
public java.util.Iterator getObjects()
getObjects
in interface IOAVState
public java.util.Iterator getDeepObjects()
getDeepObjects
in interface IOAVState
public java.util.Iterator getRootObjects()
getRootObjects
in interface IOAVState
public int getSize()
public java.util.Collection getUnreferencedObjects()
getUnreferencedObjects
in interface IOAVState
protected boolean isReachable(java.lang.Object id, java.util.Set tested)
id
- The objecttested
- The objects already traversed (to avoid endless loops).public java.util.List findCycle(java.util.Collection oids)
protected java.util.List findCycleForValue(java.util.Collection oids, java.util.Set checked, java.util.Map edges, java.util.List subgraph, java.lang.Object current, java.lang.Object next, OAVAttributeType attr)
current
- The current node (oid).next
- The next node (oid).public java.util.Collection getReferencingObjects(java.lang.Object value)
getReferencingObjects
in interface IOAVState
public java.lang.Object getAttributeValue(java.lang.Object id, OAVAttributeType attribute)
getAttributeValue
in interface IOAVState
id
- The identifier of the object.attribute
- The attribute identifier.public void setAttributeValue(java.lang.Object id, OAVAttributeType attribute, java.lang.Object value)
setAttributeValue
in interface IOAVState
id
- The identifier of the object.attribute
- The attribute identifier.value
- The value (basic, object id or java object).public java.util.Collection getAttributeValues(java.lang.Object id, OAVAttributeType attribute)
getAttributeValues
in interface IOAVState
id
- The identifier of the object.attribute
- The attribute identifier.public java.util.Collection getAttributeKeys(java.lang.Object id, OAVAttributeType attribute)
getAttributeKeys
in interface IOAVState
id
- The identifier of the object.attribute
- The attribute identifier.public java.lang.Object getAttributeValue(java.lang.Object id, OAVAttributeType attribute, java.lang.Object key)
getAttributeValue
in interface IOAVState
id
- The identifier of the object.attribute
- The attribute identifier.key
- The key.public boolean containsKey(java.lang.Object id, OAVAttributeType attribute, java.lang.Object key)
containsKey
in interface IOAVState
id
- The identifier of the object.attribute
- The attribute identifier.key
- The key.public void addAttributeValue(java.lang.Object id, OAVAttributeType attribute, java.lang.Object value)
addAttributeValue
in interface IOAVState
id
- The identifier of the object.attribute
- The attribute identifier.value
- The value (basic, object id or java object).public void removeAttributeValue(java.lang.Object id, OAVAttributeType attribute, java.lang.Object value)
removeAttributeValue
in interface IOAVState
id
- The identifier of the object.attribute
- The attribute identifier.value
- The value (basic, object id or java object).public void addStateListener(IOAVStateListener listener, boolean bunch)
addStateListener
in interface IOAVState
listener
- The state listener.bunch
- True, for adding a bunch listener.public void removeStateListener(IOAVStateListener listener)
removeStateListener
in interface IOAVState
listener
- The state listener.public void notifyEventListeners()
notifyEventListeners
in interface IOAVState
public IProfiler getProfiler()
getProfiler
in interface IOAVState
public void setProfiler(IProfiler profiler)
setProfiler
in interface IOAVState
public void expungeStaleObjects()
expungeStaleObjects
in interface IOAVState
public void setSynchronizator(jadex.commons.concurrent.ISynchronizator synchronizator)
setSynchronizator
in interface IOAVState
public jadex.commons.concurrent.ISynchronizator getSynchronizator()
getSynchronizator
in interface IOAVState
public abstract void addExternalObjectUsage(java.lang.Object id, java.lang.Object external)
addExternalObjectUsage
in interface IOAVState
id
- The oav object id.external
- The user object.public abstract void removeExternalObjectUsage(java.lang.Object id, java.lang.Object external)
removeExternalObjectUsage
in interface IOAVState
id
- The oav object id.external
- The state external object.public java.lang.String toString()
toString
in class java.lang.Object
protected java.util.Map getObject(java.lang.Object id)
id
- The id.protected java.util.Map getObject0(java.lang.Object id)
id
- The id.protected boolean checkValueCompatibility(java.lang.Object id, OAVAttributeType attribute, java.lang.Object value)
java.lang.RuntimeException
- if value is not allowed.protected boolean checkTypeHasAttribute(java.lang.Object id, OAVAttributeType attribute)
id
- The object (oid).attribute
- The attribute.java.lang.RuntimeException
- if value is not allowed.protected boolean checkMultiplicity(java.lang.Object id, OAVAttributeType attribute, java.util.Set allowedmults)
id
- The object (oid).attribute
- The attribute.multiplicity
- The multiplicity.java.lang.RuntimeException
- if value is not allowed.protected boolean checkMultiplicity(java.lang.Object id, OAVAttributeType attribute, java.lang.String allowedmult)
id
- The object (oid).attribute
- The attribute.multiplicity
- The multiplicity.java.lang.RuntimeException
- if value is not allowed.protected boolean checkTypeDefined(OAVObjectType type)
type
- The type.protected boolean checkValidStateObject(java.lang.Object id)
id
- The object (oid).protected boolean checkValidStateObjectRead(java.lang.Object id)
id
- The object (oid).protected boolean checkValidStateValue(java.lang.Object value)
value
- The value.protected void addObjectUsage(java.lang.Object whichid, OAVAttributeType whichattr, java.lang.Object value)
whichid
- The object (oid) that references the value.whichattr
- The attribute which references the object.value
- The value (id of the referenced object or java object).protected void removeObjectUsage(java.lang.Object whichid, OAVAttributeType whichattr, java.lang.Object value, java.util.Set dropset, boolean keepalive)
whichid
- The object that references the value.whichattr
- The attribute which references the value.value
- The object id/java value to remove.dropset
- Already dropped objects in recursive drop (or null if none).keepalive
- A flag indicating that at least one object in the path is externally referenced
(all contained unused objects are set to externally referenced, too).protected boolean isManaged(java.lang.Object value)
protected java.util.Map getObjectUsages(java.lang.Object object)
protected void registerValue(OAVJavaType type, java.lang.Object value)
protected void deregisterValue(OAVJavaType type, java.lang.Object value)
protected abstract boolean isExternallyUsed(java.lang.Object id)
id
- The id.public void addSubstate(IOAVState substate)
addSubstate
in interface IOAVState
public IOAVState[] getSubstates()
getSubstates
in interface IOAVState
public boolean isJavaIdentity()
isJavaIdentity
in interface IOAVState
public boolean equals(java.lang.Object a, java.lang.Object b)
protected abstract java.util.Map internalCreateObject(java.lang.Object id)
id
- The id.protected abstract java.util.Map internalRemoveObject(java.lang.Object id)
id
- The id.protected abstract java.util.Map internalGetObjectContent(java.lang.Object id)
id
- The id.protected abstract boolean internalContainsObject(java.lang.Object id)
id
- The id.protected abstract int internalObjectsSize()
protected abstract java.util.Set internalGetObjects()