/** * Set an attribute of an object (oid) to the given value. * @param id The identifier of the object. * @param attribute The attribute identifier. * @param value The value (basic, object id or java object). */ public void setAttributeValue(Object id, OAVAttributeType attribute, Object value) { // #ifndef MIDP assert nocheck || generator.isId(id); assert nocheck || checkValidStateObject(id): id+" "+attribute+" "+value; assert nocheck || checkValidStateValue(value); assert nocheck || checkTypeHasAttribute(id, attribute); assert nocheck || checkMultiplicity(id, attribute, OAVAttributeType.NONE); assert nocheck || checkValueCompatibility(id, attribute, value); // #endif Map theobject = getObject(id); Object oldvalue = theobject.put(attribute, value); // Notification before removal in order to be capable to save the oldvalue reference. if(!equals(oldvalue, value)) { eventhandler.objectModified(id, getType(id), attribute, oldvalue, value); removeObjectUsage(id, attribute, oldvalue, null, false); addObjectUsage(id, attribute, value); } }
/** * Impl of root/non-root object creation. */ protected Object createObject(OAVObjectType type, boolean root) { // #ifndef MIDP assert nocheck || checkTypeDefined(type); // #endif Object ret = generator.createId(this, type); // Map content = new LinkedHashMap(); // objects.put(ret, content); Map content = internalCreateObject(ret); content.put(TYPE, type); // System.out.println("Created object of type: "+type); eventhandler.objectAdded(ret, type, root); if(root) this.rootobjects.add(ret); return ret; }
/** * Test if the object is a valid state object (oid). * @param id The object (oid). * @return True, if valid. */ protected boolean checkValidStateObject(Object id) { // #ifndef MIDP assert nocheck || generator.isId(id); // #endif return containsObject(id); }
/** * Test if reading the object (oid) is allowed. * Reading is allowed on removed objects as long as there are external references. * @param id The object (oid). * @return True, if valid. */ protected boolean checkValidStateObjectRead(Object id) { // #ifndef MIDP assert nocheck || generator.isId(id); // #endif return checkValidStateObject(id) || isExternallyUsed(id); }
assert nocheck || checkValidStateObject(id); assert nocheck || checkValidStateValue(value) : value; assert nocheck || checkTypeHasAttribute(id, attribute); assert nocheck || checkMultiplicity(id, attribute, OAVAttributeType.MULTIPLICITIES_MULT); assert nocheck || checkValueCompatibility(id, attribute, value); Map theobject = getObject(id); Object tmp = theobject.get(attribute); if(keyattr==null) throw new RuntimeException("Index attribute not specified: "+attribute); Object key = getAttributeValue(value, keyattr); if(key==null) throw new RuntimeException("Null key not allowed: "+attribute); map.put(key, value); addObjectUsage(id, attribute, key); addObjectUsage(id, attribute, value); eventhandler.objectModified(id, getType(id), attribute, null, value);
assert nocheck || checkValidStateObjectRead(id); assert nocheck || checkTypeHasAttribute(id, attribute); assert nocheck || checkMultiplicity(id, attribute, OAVAttributeType.MULTIPLICITIES_MAPS); Map theobject = getObject0(id);
assert nocheck || checkValidStateObject(id); assert nocheck || checkValidStateValue(value); assert nocheck || checkTypeHasAttribute(id, attribute); assert nocheck || checkMultiplicity(id, attribute, OAVAttributeType.MULTIPLICITIES_MULT); Map theobject = getObject(id); Object tmp = theobject.get(attribute); if(tmp==null) eventhandler.objectModified(id, getType(id), attribute, value, null); removeObjectUsage(id, attribute, value, null, false); eventhandler.objectModified(id, getType(id), attribute, value, null); removeObjectUsage(id, attribute, key, null, false); removeObjectUsage(id, attribute, value, null, false);
if(isManaged(value)) addExternalObjectUsage(value, this); Map usages = getObjectUsages(value); if(usages==null) throw new RuntimeException("Reference not found: "+whichid+" "+whichattr.getName()+" "+value); if(internalContainsObject(value) && !rootobjects.contains(value) && (dropset==null || !dropset.contains(value))) internalDropObject(value, dropset, keepalive); deregisterValue(java_type, value);
assert nocheck || checkValidStateObject(id); Map refs = getObjectUsages(id); if(refs!=null && !refs.isEmpty()) if(attr.getMultiplicity().equals(OAVAttributeType.NONE)) setAttributeValue(uid, attr, null); removeAttributeValue(uid, attr, id); internalDropObject(id, null, false); // Required for root objects and other unreferenced objects.
/** * Test if the object is a valid state value, meaning * that is either a state object or a java value. * @param value The value. * @return True, if valid. */ protected boolean checkValidStateValue(Object value) { // No state object (i.e. Java object) or object in state. return !generator.isId(value) || checkValidStateObject(value); }
assert nocheck || checkValidStateObject(id); assert nocheck || checkValidStateValue(value) : value; assert nocheck || checkTypeHasAttribute(id, attribute); assert nocheck || checkMultiplicity(id, attribute, OAVAttributeType.MULTIPLICITIES_MULT); assert nocheck || checkValueCompatibility(id, attribute, value); Map theobject = getObject(id); Object tmp = theobject.get(attribute); if(keyattr==null) throw new RuntimeException("Index attribute not specified: "+attribute); Object key = getAttributeValue(value, keyattr); if(key==null) throw new RuntimeException("Null key not allowed: "+attribute); map.put(key, value); addObjectUsage(id, attribute, key); addObjectUsage(id, attribute, value); eventhandler.objectModified(id, getType(id), attribute, null, value);
assert nocheck || checkValidStateObjectRead(id); assert nocheck || checkTypeHasAttribute(id, attribute); assert nocheck || checkMultiplicity(id, attribute, OAVAttributeType.MULTIPLICITIES_MAPS); Map theobject = getObject0(id);
assert nocheck || checkValidStateObject(id); assert nocheck || checkValidStateValue(value); assert nocheck || checkTypeHasAttribute(id, attribute); assert nocheck || checkMultiplicity(id, attribute, OAVAttributeType.MULTIPLICITIES_MULT); Map theobject = getObject(id); Object tmp = theobject.get(attribute); if(tmp==null) eventhandler.objectModified(id, getType(id), attribute, value, null); removeObjectUsage(id, attribute, value, null, false); eventhandler.objectModified(id, getType(id), attribute, value, null); removeObjectUsage(id, attribute, key, null, false); removeObjectUsage(id, attribute, value, null, false);
if(isManaged(value)) addExternalObjectUsage(value, this); Map usages = getObjectUsages(value); if(usages==null) throw new RuntimeException("Reference not found: "+whichid+" "+whichattr.getName()+" "+value); if(internalContainsObject(value) && !rootobjects.contains(value) && (dropset==null || !dropset.contains(value))) internalDropObject(value, dropset, keepalive); deregisterValue(java_type, value);
assert nocheck || checkValidStateObject(id); Map refs = getObjectUsages(id); if(refs!=null && !refs.isEmpty()) if(attr.getMultiplicity().equals(OAVAttributeType.NONE)) setAttributeValue(uid, attr, null); removeAttributeValue(uid, attr, id); internalDropObject(id, null, false); // Required for root objects and other unreferenced objects.
/** * Test if reading the object (oid) is allowed. * Reading is allowed on removed objects as long as there are external references. * @param id The object (oid). * @return True, if valid. */ protected boolean checkValidStateObjectRead(Object id) { // #ifndef MIDP assert nocheck || generator.isId(id); // #endif return checkValidStateObject(id) || isExternallyUsed(id); }
/** * Test if the object is a valid state value, meaning * that is either a state object or a java value. * @param value The value. * @return True, if valid. */ protected boolean checkValidStateValue(Object value) { // No state object (i.e. Java object) or object in state. return !generator.isId(value) || checkValidStateObject(value); }
/** * Set an attribute of an object (oid) to the given value. * @param id The identifier of the object. * @param attribute The attribute identifier. * @param value The value (basic, object id or java object). */ public void setAttributeValue(Object id, OAVAttributeType attribute, Object value) { // #ifndef MIDP assert nocheck || generator.isId(id); assert nocheck || checkValidStateObject(id): id+" "+attribute+" "+value; assert nocheck || checkValidStateValue(value); assert nocheck || checkTypeHasAttribute(id, attribute); assert nocheck || checkMultiplicity(id, attribute, OAVAttributeType.NONE); assert nocheck || checkValueCompatibility(id, attribute, value); // #endif Map theobject = getObject(id); Object oldvalue = theobject.put(attribute, value); // Notification before removal in order to be capable to save the oldvalue reference. if(!equals(oldvalue, value)) { eventhandler.objectModified(id, getType(id), attribute, oldvalue, value); removeObjectUsage(id, attribute, oldvalue, null, false); addObjectUsage(id, attribute, value); } }
assert nocheck || checkValidStateObjectRead(id); assert nocheck || checkTypeHasAttribute(id, attribute); assert nocheck || checkMultiplicity(id, attribute, OAVAttributeType.MULTIPLICITIES_MAPS); Map theobject = getObject0(id);
/** * Impl of root/non-root object creation. */ protected Object createObject(OAVObjectType type, boolean root) { // #ifndef MIDP assert nocheck || checkTypeDefined(type); // #endif Object ret = generator.createId(this, type); // Map content = new LinkedHashMap(); // objects.put(ret, content); Map content = internalCreateObject(ret); content.put(TYPE, type); // System.out.println("Created object of type: "+type); eventhandler.objectAdded(ret, type, root); if(root) this.rootobjects.add(ret); return ret; }