/** * 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 RuntimeException if value is not allowed. */ protected boolean checkValueCompatibility(Object id, OAVAttributeType attribute, Object value) { // #ifndef MIDP assert nocheck || generator.isId(id); // #endif if(value!=null) { OAVObjectType atype = attribute.getType(); if(atype instanceof OAVJavaType) { if(!tmodel.getJavaType(value.getClass()).isSubtype(atype)) throw new RuntimeException("Value not of suitable type: "+id+" "+attribute+" "+value); } else if(!getType(value).isSubtype(atype)) { throw new RuntimeException("Value not of suitable type: "+id+" "+attribute+" "+value); } } return true; }
/** * Ensure that a type has an attribute. * @param id The object (oid). * @param attribute The attribute. * @throws RuntimeException if value is not allowed. */ protected boolean checkTypeHasAttribute(Object id, OAVAttributeType attribute) { // #ifndef MIDP assert nocheck || generator.isId(id); // #endif if(attribute==null) throw new IllegalArgumentException("Attribute must not null."); OAVObjectType type = attribute.getObjectType() instanceof OAVJavaType ? tmodel.getJavaType(id.getClass()) : getType(id); OAVAttributeType attr = type.getAttributeType(attribute.getName()); if(!attribute.equals(attr)) throw new RuntimeException("Attribute must belong to object type: "+attribute+", "+type); return true; }
/** * Ensure that a type has an attribute. * @param id The object (oid). * @param attribute The attribute. * @throws RuntimeException if value is not allowed. */ protected boolean checkTypeHasAttribute(Object id, OAVAttributeType attribute) { // #ifndef MIDP assert nocheck || generator.isId(id); // #endif if(attribute==null) throw new IllegalArgumentException("Attribute must not null."); OAVObjectType type = attribute.getObjectType() instanceof OAVJavaType ? tmodel.getJavaType(id.getClass()) : getType(id); OAVAttributeType attr = type.getAttributeType(attribute.getName()); if(!attribute.equals(attr)) throw new RuntimeException("Attribute must belong to object type: "+attribute+", "+type); return true; }
/** * 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 RuntimeException if value is not allowed. */ protected boolean checkValueCompatibility(Object id, OAVAttributeType attribute, Object value) { // #ifndef MIDP assert nocheck || generator.isId(id); // #endif if(value!=null) { OAVObjectType atype = attribute.getType(); if(atype instanceof OAVJavaType) { if(!tmodel.getJavaType(value.getClass()).isSubtype(atype)) throw new RuntimeException("Value not of suitable type: "+id+" "+attribute+" "+value); } else if(!getType(value).isSubtype(atype)) { throw new RuntimeException("Value not of suitable type: "+id+" "+attribute+" "+value); } } return true; }
eventhandler.objectModified(id, getType(id), attribute, null, value);
eventhandler.objectModified(id, getType(id), attribute, null, 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); } }
/** * 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); } }