assert nocheck || checkTypeHasAttribute(object, attribute); assert nocheck || checkMultiplicity(object, attribute, OAVAttributeType.NONE); assert nocheck || checkValueCompatibility(object, attribute, value); assert nocheck || checkValidStateObject(object): object+" "+attribute+" "+value; assert object instanceof OAVExternalObjectId; Map theobject = getObject(object); Object oldvalue = theobject.put(attribute, value); if(isJavaNonValue(oldvalue)) removeJavaObjectUsage(object, attribute, oldvalue); if(isJavaNonValue(value)) addJavaObjectUsage(object, attribute, value); eventhandler.objectModified(((OAVExternalObjectId)object).getInternalId().getPhantomExternalId(), getType(object), attribute, oldvalue, value);
/** * Dispose the state. */ public void dispose() { Object[] roots = rootobjects.toArray(); for(int i=0; i<roots.length; i++) dropObject(roots[i]); }
/** * Test if a key is contained in the map attribute. * @param object The identifier of the object. * @param attribute The attribute identifier. * @param key The key. * @return True if key is available. */ public boolean containsKey(Object object, OAVAttributeType attribute, Object key) { assert nocheck || checkTypeHasAttribute(object, attribute); assert nocheck || checkMultiplicity(object, attribute, OAVAttributeType.MULTIPLICITIES_MAPS); assert object instanceof OAVExternalObjectId; Map theobject = getObject(object); Map map = (Map)theobject.get(attribute); return map==null? false: map.containsKey(key); }
/** * Get an attribute value of an object. Method only applicable for * map attribute type. * @param object The identifier of the object. * @param attribute The attribute identifier. * @param key The key. * @return The value (basic, object id or java object). */ public Object getAttributeValue(Object object, OAVAttributeType attribute, Object key) { assert nocheck || checkTypeHasAttribute(object, attribute); assert nocheck || checkMultiplicity(object, attribute, OAVAttributeType.MULTIPLICITIES_MAPS); assert nocheck || checkValidStateObject(object); assert object instanceof OAVExternalObjectId; Map theobject = getObject(object); Map map = (Map)theobject.get(attribute); // todo: enable check again by adding containsKey(key) method to state // if(map==null || !map.containsKey(key)) // throw new RuntimeException("Key not available in map: "+key+" "+map); Object ret = map==null? null: map.get(key); assert ret==null || ret instanceof OAVExternalObjectId; return ret; }
assert nocheck || checkTypeHasAttribute(object, attribute); assert nocheck || checkMultiplicity(object, attribute, OAVAttributeType.MULTIPLICITIES_MULT); assert nocheck || checkValidStateObject(object); assert object instanceof OAVExternalObjectId; Map theobject = getObject(object); Object tmp = theobject.get(attribute); if(tmp==null) if(isJavaNonValue(key)) removeJavaObjectUsage(object, attribute, key); if(isJavaNonValue(value)) removeJavaObjectUsage(object, attribute, value); eventhandler.objectModified(((OAVExternalObjectId)object).getInternalId().getPhantomExternalId(), getType(object), attribute, value, null);
Map usages = getJavaObjectUsages(value); if(usages==null) throw new RuntimeException("Reference not found: "+whichid+" "+whichattr.getName()+" "+value); deregisterValue(value);
/** * Drop a Java object from root objects. * @param object The Java object. */ public void removeJavaRootObject(Object object) { assert nocheck || rootobjects.contains(object); this.rootobjects.remove(object); OAVJavaType java_type = tmodel.getJavaType(object.getClass()); if(OAVJavaType.KIND_BEAN.equals(java_type.getKind())) deregisterValue(object); eventhandler.objectRemoved(object, java_type); }
/** * Drop an object from the state. * Recursively removes the object and all connected objects that are not * referenced elsewhere. * @param object The identifier of the object to remove. */ public void dropObject(Object object) { assert nocheck || checkValidStateObject(object); assert rootobjects.contains(object); assert object instanceof OAVExternalObjectId; rootobjects.remove(object); // internalDropObject(object, null); }
/** * 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. * @return An object identifier. */ public Object createRootObject(OAVObjectType type) { Object ret = createObject(type); this.rootobjects.add(ret); eventhandler.objectAdded(((OAVExternalObjectId)ret).getInternalId().getPhantomExternalId(), type, true); assert ret instanceof OAVExternalObjectId; return ret; }
/** * Create an object. * Creates an object identifier that can be used * to store/retrieve attribute values. * May reuse old object identifiers for performance. * @return An object identifier. */ public Object createObject(OAVObjectType type) { assert nocheck || checkTypeDefined(type); OAVInternalObjectId ret = (OAVInternalObjectId)generator.createId(this, type); objects.put(ret, new LinkedHashMap()); types.put(ret, type); //System.out.println("Adding type: "+type); // Event should be thrown once the object is used somewhere in the state? eventhandler.objectAdded(ret.getPhantomExternalId(), type, false); return ret.getWeakExternalId(); }
/** * Get an attribute value of an object. Method only applicable for * map attribute type. * @param object The identifier of the object. * @param attribute The attribute identifier. * @param key The key. * @return The value (basic, object id or java object). */ public Object getAttributeValue(Object object, OAVAttributeType attribute, Object key) { assert nocheck || checkTypeHasAttribute(object, attribute); assert nocheck || checkMultiplicity(object, attribute, OAVAttributeType.MULTIPLICITIES_MAPS); assert nocheck || checkValidStateObject(object); assert object instanceof OAVExternalObjectId; Map theobject = getObject(object); Map map = (Map)theobject.get(attribute); // todo: enable check again by adding containsKey(key) method to state // if(map==null || !map.containsKey(key)) // throw new RuntimeException("Key not available in map: "+key+" "+map); Object ret = map==null? null: map.get(key); assert ret==null || ret instanceof OAVExternalObjectId; return ret; }
assert nocheck || checkTypeHasAttribute(object, attribute); assert nocheck || checkMultiplicity(object, attribute, OAVAttributeType.MULTIPLICITIES_MULT); assert nocheck || checkValidStateObject(object); assert object instanceof OAVExternalObjectId; Map theobject = getObject(object); Object tmp = theobject.get(attribute); if(tmp==null) if(isJavaNonValue(key)) removeJavaObjectUsage(object, attribute, key); if(isJavaNonValue(value)) removeJavaObjectUsage(object, attribute, value); eventhandler.objectModified(((OAVExternalObjectId)object).getInternalId().getPhantomExternalId(), getType(object), attribute, value, null);
/** * Test if a key is contained in the map attribute. * @param object The identifier of the object. * @param attribute The attribute identifier. * @param key The key. * @return True if key is available. */ public boolean containsKey(Object object, OAVAttributeType attribute, Object key) { assert nocheck || checkTypeHasAttribute(object, attribute); assert nocheck || checkMultiplicity(object, attribute, OAVAttributeType.MULTIPLICITIES_MAPS); assert object instanceof OAVExternalObjectId; Map theobject = getObject(object); Map map = (Map)theobject.get(attribute); return map==null? false: map.containsKey(key); }
Map usages = getJavaObjectUsages(value); if(usages==null) throw new RuntimeException("Reference not found: "+whichid+" "+whichattr.getName()+" "+value); deregisterValue(value);
/** * Drop a Java object from root objects. * @param object The Java object. */ public void removeJavaRootObject(Object object) { assert nocheck || rootobjects.contains(object); this.rootobjects.remove(object); OAVJavaType java_type = tmodel.getJavaType(object.getClass()); if(OAVJavaType.KIND_BEAN.equals(java_type.getKind())) deregisterValue(object); eventhandler.objectRemoved(object, java_type); }
/** * Drop an object from the state. * Recursively removes the object and all connected objects that are not * referenced elsewhere. * @param object The identifier of the object to remove. */ public void dropObject(Object object) { assert nocheck || checkValidStateObject(object); assert rootobjects.contains(object); assert object instanceof OAVExternalObjectId; rootobjects.remove(object); // internalDropObject(object, null); }
/** * 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. * @return An object identifier. */ public Object createRootObject(OAVObjectType type) { Object ret = createObject(type); this.rootobjects.add(ret); eventhandler.objectAdded(((OAVExternalObjectId)ret).getInternalId().getPhantomExternalId(), type, true); assert ret instanceof OAVExternalObjectId; return ret; }
/** * Create an object. * Creates an object identifier that can be used * to store/retrieve attribute values. * May reuse old object identifiers for performance. * @return An object identifier. */ public Object createObject(OAVObjectType type) { assert nocheck || checkTypeDefined(type); OAVInternalObjectId ret = (OAVInternalObjectId)generator.createId(this, type); objects.put(ret, new LinkedHashMap()); types.put(ret, type); //System.out.println("Adding type: "+type); // Event should be thrown once the object is used somewhere in the state? eventhandler.objectAdded(ret.getPhantomExternalId(), type, false); return ret.getWeakExternalId(); }
assert nocheck || checkTypeHasAttribute(object, attribute); assert nocheck || checkMultiplicity(object, attribute, OAVAttributeType.NONE); assert nocheck || checkValueCompatibility(object, attribute, value); assert nocheck || checkValidStateObject(object): object+" "+attribute+" "+value; assert object instanceof OAVExternalObjectId; Map theobject = getObject(object); Object oldvalue = theobject.put(attribute, value); if(isJavaNonValue(oldvalue)) removeJavaObjectUsage(object, attribute, oldvalue); if(isJavaNonValue(value)) addJavaObjectUsage(object, attribute, value); eventhandler.objectModified(((OAVExternalObjectId)object).getInternalId().getPhantomExternalId(), getType(object), attribute, oldvalue, value);
/** * Get an attribute value of an object. * @param object The identifier of the object. * @param attribute The attribute identifier. * @return The value (basic, object id or java object). */ public Object getAttributeValue(Object object, OAVAttributeType attribute) { assert nocheck || checkTypeHasAttribute(object, attribute); assert nocheck || checkMultiplicity(object, attribute, OAVAttributeType.NONE); assert nocheck || checkValidStateObject(object); assert object instanceof OAVExternalObjectId: object; Map theobject = getObject(object); Object ret = theobject.get(attribute); if(ret==null && !theobject.containsKey(attribute)) ret = attribute.getDefaultValue(); if(ret instanceof Collection) throw new IllegalArgumentException("Attribute "+attribute+" is not single valued."); return ret; }