Package jadex.rules.state.javaimpl
Class OAVWeakState
- java.lang.Object
- 
- jadex.rules.state.javaimpl.OAVWeakState
 
- 
- 
Field SummaryFields Modifier and Type Field Description protected OAVEventHandlereventhandlerThe OAV event handler.protected IOAVIdGeneratorgeneratorThe id generator.protected booleannocheckThe flag to disable type checking.protected java.util.MapobjectsThe objects table (id -> map).protected java.util.MapobjectusagesThe usages of object ids (object id -> usages).protected static java.lang.Class[]PCLThe argument types for property change listener adding/removal (cached for speed).protected java.util.MappclsThe Java beans property change listeners.protected IProfilerprofilerThe profiler.protected java.lang.ref.ReferenceQueuequeueThe reference queue for stale objects.protected java.util.SetrootobjectsThe root objects (will not be cleaned up when usages==0).protected ISynchronizatorsynchronizatorThe synchronizator (if any).protected OAVTypeModeltmodelThe type models.protected java.util.MaptypesThe object types (object -> type).
 - 
Constructor SummaryConstructors Constructor Description OAVWeakState(OAVTypeModel tmodel)Create a new empty OAV state representation.
 - 
Method SummaryAll 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.protected voidaddJavaObjectUsage(java.lang.Object whichid, OAVAttributeType whichattr, java.lang.Object value)When it is a Java object, it is not created in state, so we have to notify object addition to listeners on first usage.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.protected booleancheckMultiplicity(java.lang.Object object, OAVAttributeType attribute, java.lang.String allowedmult)Ensure that multiplicity is ok.protected booleancheckMultiplicity(java.lang.Object object, OAVAttributeType attribute, java.util.Set allowedmults)Ensure that multiplicity is ok.protected booleancheckTypeDefined(OAVObjectType type)Test if a type is defined in one of the models.protected booleancheckTypeHasAttribute(java.lang.Object object, OAVAttributeType attribute)Ensure that a type has an attribute.protected booleancheckValidStateObject(java.lang.Object object)Test if the object is a valid state object, meaning that is either a root object or a non-root object with at least one usage.protected booleancheckValueCompatibility(java.lang.Object object, OAVAttributeType attribute, java.lang.Object value)Check if it is allowed to set or add an attribute value.java.lang.ObjectcloneObject(java.lang.Object object, IOAVState targetstate)Clone an object in the state (deep copy).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 id)Test if the state contains a specific object.java.lang.ObjectcreateObject(OAVObjectType type)Create an object.java.lang.ObjectcreateRootObject(OAVObjectType type)Create a root object.protected voidderegisterValue(java.lang.Object value)Deregister a value for observation.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.protected java.lang.ObjectgetClonedOAVObject(IOAVState targetstate, java.util.Map handles, java.util.List todo, java.lang.Object oldval)Get or create a clone of an oav object.java.util.IteratorgetDeepObjects()Get all objects in the state.protected OAVWeakIdGenerator.OAVInternalObjectIdgetInternalId(java.lang.Object id)Get the internal object id.protected java.util.MapgetJavaObjectUsages(java.lang.Object id)Get all object usages.protected java.util.MapgetObject(java.lang.Object id)Get an object map for its id.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 id)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.protected booleanisJavaNonValue(java.lang.Object obj)Check if an object is a java object but not a value.voidnotifyEventListeners()Throw collected events and notify the listeners.protected voidregisterValue(OAVJavaType type, java.lang.Object value)Register a value for observation.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.protected voidremoveJavaObjectUsage(java.lang.Object whichid, OAVAttributeType whichattr, java.lang.Object value)Remove an object usage.voidremoveJavaRootObject(java.lang.Object object)Drop 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.java.lang.StringtoString()Get the string representation of the object.
 
- 
- 
- 
Field Detail- 
PCLprotected static java.lang.Class[] PCL The argument types for property change listener adding/removal (cached for speed).
 - 
tmodelprotected OAVTypeModel tmodel The type models.
 - 
objectsprotected java.util.Map objects The objects table (id -> map).
 - 
typesprotected java.util.Map types The object types (object -> type).
 - 
generatorprotected IOAVIdGenerator generator The id generator.
 - 
nocheckprotected boolean nocheck The flag to disable type checking.
 - 
objectusagesprotected java.util.Map objectusages The usages of object ids (object id -> usages).
 - 
rootobjectsprotected java.util.Set rootobjects The root objects (will not be cleaned up when usages==0).
 - 
pclsprotected java.util.Map pcls The Java beans property change listeners.
 - 
eventhandlerprotected OAVEventHandler eventhandler The OAV event handler.
 - 
queueprotected java.lang.ref.ReferenceQueue queue The reference queue for stale objects.
 - 
synchronizatorprotected ISynchronizator synchronizator The synchronizator (if any).
 - 
profilerprotected IProfiler profiler The profiler.
 
- 
 - 
Constructor Detail- 
OAVWeakStatepublic OAVWeakState(OAVTypeModel tmodel) Create a new empty OAV state representation.
 
- 
 - 
Method Detail- 
getTypeModelpublic OAVTypeModel getTypeModel() Get the type model.- Specified by:
- getTypeModelin interface- IOAVState
- Returns:
- The type model.
 
 - 
createObjectpublic 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 interface- IOAVState
- Parameters:
- type- The object type (null for defining meta types).
- Returns:
- An object identifier.
 
 - 
createRootObjectpublic 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 interface- IOAVState
- Returns:
- An object identifier.
 
 - 
dropObjectpublic 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 interface- IOAVState
- Parameters:
- object- The identifier of the object to remove.
 
 - 
addJavaRootObjectpublic void addJavaRootObject(java.lang.Object object) Add a Java object as root object.- Specified by:
- addJavaRootObjectin interface- IOAVState
- Parameters:
- object- The Java object.
 
 - 
removeJavaRootObjectpublic void removeJavaRootObject(java.lang.Object object) Drop a Java object from root objects.- Specified by:
- removeJavaRootObjectin interface- IOAVState
- Parameters:
- object- The Java object.
 
 - 
cloneObjectpublic java.lang.Object cloneObject(java.lang.Object object, IOAVState targetstate)Clone an object in the state (deep copy).- Parameters:
- object- The handle to the object to be cloned.
- targetstate- The target state in which the clone should be created.
- Returns:
- The identifier of the newly created clone.
 
 - 
getClonedOAVObjectprotected java.lang.Object getClonedOAVObject(IOAVState targetstate, java.util.Map handles, java.util.List todo, java.lang.Object oldval) Get or create a clone of an oav object.- Parameters:
- targetstate- The target state.
- handles- The handles.
- todo- The todo list.
- oldval- The old object.
 
 - 
containsObjectpublic boolean containsObject(java.lang.Object id) Test if the state contains a specific object.- Specified by:
- containsObjectin interface- IOAVState
- Parameters:
- id- The object id.
- Returns:
- True, if contained.
 
 - 
isIdentifierpublic boolean isIdentifier(java.lang.Object object) Test if the object represents an identifier.- Specified by:
- isIdentifierin interface- IOAVState
- Parameters:
- object- The suspected object identifier.
- Returns:
- True, if object identifier.
 
 - 
getTypepublic OAVObjectType getType(java.lang.Object id) Get the type of an object.
 - 
getObjectspublic java.util.Iterator getObjects() Get all objects in the state.- Specified by:
- getObjectsin interface- IOAVState
 
 - 
getDeepObjectspublic java.util.Iterator getDeepObjects() Get all objects in the state.- Specified by:
- getDeepObjectsin interface- IOAVState
 
 - 
getRootObjectspublic java.util.Iterator getRootObjects() Get the root objects of the state.- Specified by:
- getRootObjectsin interface- IOAVState
 
 - 
getSizepublic int getSize() Get the number of objects in the state. Optional operation used for debugging only.
 - 
getUnreferencedObjectspublic java.util.Collection getUnreferencedObjects() Get all unreferenced objects.- Specified by:
- getUnreferencedObjectsin interface- IOAVState
- Returns:
- All unreferenced objects of the state.
 
 - 
findCyclepublic java.util.List findCycle(java.util.Collection objects) Find a cycle in a given set of objects.
 - 
getReferencingObjectspublic java.util.Collection getReferencingObjects(java.lang.Object value) Get those objects referencing a given object.- Specified by:
- getReferencingObjectsin interface- IOAVState
 
 - 
getAttributeValuepublic java.lang.Object getAttributeValue(java.lang.Object object, OAVAttributeType attribute)Get an attribute value of an object.- Specified by:
- getAttributeValuein interface- IOAVState
- Parameters:
- object- The identifier of the object.
- attribute- The attribute identifier.
- Returns:
- The value (basic, object id or java object).
 
 - 
setAttributeValuepublic 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 interface- IOAVState
- Parameters:
- object- The identifier of the object.
- attribute- The attribute identifier.
- value- The value (basic, object id or java object).
 
 - 
isJavaNonValueprotected boolean isJavaNonValue(java.lang.Object obj) Check if an object is a java object but not a value.
 - 
getAttributeValuespublic java.util.Collection getAttributeValues(java.lang.Object object, OAVAttributeType attribute)Get the values of an attribute of an object.- Specified by:
- getAttributeValuesin interface- IOAVState
- Parameters:
- object- The identifier of the object.
- attribute- The attribute identifier.
- Returns:
- The values (basic, object ids or java objects).
 
 - 
getAttributeKeyspublic java.util.Collection getAttributeKeys(java.lang.Object object, OAVAttributeType attribute)Get the keys of an attribute of an object.- Specified by:
- getAttributeKeysin interface- IOAVState
- Parameters:
- object- The identifier of the object.
- attribute- The attribute identifier.
- Returns:
- The keys for which values are stored.
 
 - 
getAttributeValuepublic 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 interface- IOAVState
- Parameters:
- object- The identifier of the object.
- attribute- The attribute identifier.
- key- The key.
- Returns:
- The value (basic, object id or java object).
 
 - 
containsKeypublic 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 interface- IOAVState
- Parameters:
- object- The identifier of the object.
- attribute- The attribute identifier.
- key- The key.
- Returns:
- True if key is available.
 
 - 
addAttributeValuepublic 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 interface- IOAVState
- Parameters:
- object- The identifier of the object.
- attribute- The attribute identifier.
- value- The value (basic, object id or java object).
 
 - 
removeAttributeValuepublic 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 interface- IOAVState
- Parameters:
- object- The identifier of the object.
- attribute- The attribute identifier.
- value- The value (basic, object id or java object).
 
 - 
addStateListenerpublic void addStateListener(IOAVStateListener listener, boolean bunch) Add a new state listener.- Specified by:
- addStateListenerin interface- IOAVState
- Parameters:
- listener- The state listener.
- bunch- True, for adding a bunch listener.
 
 - 
removeStateListenerpublic void removeStateListener(IOAVStateListener listener) Remove a state listener.- Specified by:
- removeStateListenerin interface- IOAVState
- Parameters:
- listener- The state listener.
 
 - 
notifyEventListenerspublic void notifyEventListeners() Throw collected events and notify the listeners.- Specified by:
- notifyEventListenersin interface- IOAVState
 
 - 
expungeStaleObjectspublic void expungeStaleObjects() Expunge stale objects.- Specified by:
- expungeStaleObjectsin interface- IOAVState
 
 - 
addExternalObjectUsagepublic 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 interface- IOAVState
- Parameters:
- id- The oav object id.
- external- The user object.
 
 - 
removeExternalObjectUsagepublic 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 interface- IOAVState
- Parameters:
- id- The oav object id.
- external- The state external object.
 
 - 
getProfilerpublic IProfiler getProfiler() Get the profiler.- Specified by:
- getProfilerin interface- IOAVState
 
 - 
setProfilerpublic void setProfiler(IProfiler profiler) Set the profiler.- Specified by:
- setProfilerin interface- IOAVState
 
 - 
setSynchronizatorpublic void setSynchronizator(ISynchronizator synchronizator) Set the synchronizator. The optional synchronizator is used to synchronize external modifications to the state (e.g. from bean changes). The synchronizator should only be set once, before the state is used.- Specified by:
- setSynchronizatorin interface- IOAVState
 
 - 
getSynchronizatorpublic 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 interface- IOAVState
 
 - 
toStringpublic java.lang.String toString() Get the string representation of the object.- Overrides:
- toStringin class- java.lang.Object
- Returns:
- The string representation.
 
 - 
getObjectprotected java.util.Map getObject(java.lang.Object id) Get an object map for its id.- Parameters:
- id- The id.
- Returns:
- The object map.
 
 - 
checkValueCompatibilityprotected boolean checkValueCompatibility(java.lang.Object object, OAVAttributeType attribute, java.lang.Object value)Check if it is allowed to set or add an attribute value. For this purpose it is checked if the value is either a) a ObjectId -> type check via OAVObjectType b) a normal Java object -> type check via OAVJavaType Additionally multiplicity is checked.- Throws:
- java.lang.RuntimeException- if value is not allowed.
 
 - 
checkTypeHasAttributeprotected boolean checkTypeHasAttribute(java.lang.Object object, OAVAttributeType attribute)Ensure that a type has an attribute.- Parameters:
- object- The object.
- attribute- The attribute.
- Throws:
- java.lang.RuntimeException- if value is not allowed.
 
 - 
checkMultiplicityprotected boolean checkMultiplicity(java.lang.Object object, OAVAttributeType attribute, java.util.Set allowedmults)Ensure that multiplicity is ok.- Parameters:
- object- The object.
- attribute- The attribute.
- multiplicity- The multiplicity.
- Throws:
- java.lang.RuntimeException- if value is not allowed.
 
 - 
checkMultiplicityprotected boolean checkMultiplicity(java.lang.Object object, OAVAttributeType attribute, java.lang.String allowedmult)Ensure that multiplicity is ok.- Parameters:
- object- The object.
- attribute- The attribute.
- multiplicity- The multiplicity.
- Throws:
- java.lang.RuntimeException- if value is not allowed.
 
 - 
checkTypeDefinedprotected boolean checkTypeDefined(OAVObjectType type) Test if a type is defined in one of the models.- Parameters:
- type- The type.
- Returns:
- True, if is defined.
 
 - 
checkValidStateObjectprotected boolean checkValidStateObject(java.lang.Object object) Test if the object is a valid state object, meaning that is either a root object or a non-root object with at least one usage.- Parameters:
- object- The object.
- Returns:
- True, if valid.
 
 - 
addJavaObjectUsageprotected void addJavaObjectUsage(java.lang.Object whichid, OAVAttributeType whichattr, java.lang.Object value)When it is a Java object, it is not created in state, so we have to notify object addition to listeners on first usage.
 - 
removeJavaObjectUsageprotected void removeJavaObjectUsage(java.lang.Object whichid, OAVAttributeType whichattr, java.lang.Object value)Remove an object usage.- Parameters:
- whichid- The object that references the object.
- whichattr- The attribute which references the object.
- value- The object id/value to remove.
- dropset- Already dropped objects in recursive drop (or null if none).
 
 - 
getJavaObjectUsagesprotected java.util.Map getJavaObjectUsages(java.lang.Object id) Get all object usages.- Returns:
- The usages for an object.
 
 - 
registerValueprotected void registerValue(OAVJavaType type, java.lang.Object value) Register a value for observation. If its an expression then add the action, if its a bean then add the property listener.
 - 
deregisterValueprotected void deregisterValue(java.lang.Object value) Deregister a value for observation. If its an expression then clear the action, if its a bean then remove the property listener.
 - 
getInternalIdprotected OAVWeakIdGenerator.OAVInternalObjectId getInternalId(java.lang.Object id) Get the internal object id.- Parameters:
- id- The id.
- Returns:
- The internal id.
 
 - 
addSubstatepublic 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.- Specified by:
- addSubstatein interface- IOAVState
 
 - 
getSubstatespublic IOAVState[] getSubstates() Get the substates.- Specified by:
- getSubstatesin interface- IOAVState
 
 - 
isJavaIdentitypublic boolean isJavaIdentity() Flag indicating that java objects are stored by identity instead of equality.- Specified by:
- isJavaIdentityin interface- IOAVState
 
 
- 
 
-