/** * Check if an object is a java object but not a value. */ protected boolean isJavaNonValue(Object obj) { return obj!=null && types.get(obj)==null && !tmodel.getJavaType(obj.getClass()).getKind().equals(OAVJavaType.KIND_VALUE); }
/** * Check if an object is a java object but not a value. */ protected boolean isJavaNonValue(Object obj) { return obj!=null && types.get(obj)==null && !tmodel.getJavaType(obj.getClass()).getKind().equals(OAVJavaType.KIND_VALUE); }
/** * Test if two values are equal * according to current identity/equality * settings. */ public boolean equals(Object a, Object b) { // When a!=b && javaidentity use equals() only for ids or java values. return a==b || a!=null && (javaidentity ? ((generator.isId(a) || tmodel.getJavaType(a.getClass()).getKind().equals(OAVJavaType.KIND_VALUE)) && a.equals(b)) : a.equals(b)); }
/** * Get the type of an object. * @param object The object identifier. */ public OAVObjectType getType(Object object) { OAVObjectType ret; Object obj = copy.get(object); if(obj instanceof Map) { ret = (OAVObjectType)((Map)obj).get("type"); } else { ret = getTypeModel().getJavaType(object.getClass()); } return ret; }
/** * Test if two values are equal * according to current identity/equality * settings. */ public boolean equals(Object a, Object b) { // When a!=b && javaidentity use equals() only for ids or java values. return a==b || a!=null && (javaidentity ? ((generator.isId(a) || tmodel.getJavaType(a.getClass()).getKind().equals(OAVJavaType.KIND_VALUE)) && a.equals(b)) : a.equals(b)); }
/** * Add a Java object as root object. * @param object The Java object. */ public void addJavaRootObject(Object object) { assert nocheck || !rootobjects.contains(object); this.rootobjects.add(object); OAVJavaType java_type = tmodel.getJavaType(object.getClass()); if(OAVJavaType.KIND_BEAN.equals(java_type.getKind())) registerValue(java_type, object); eventhandler.objectAdded(object, java_type, true); }
/** * 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); }
/** * Add a Java object as root object. * @param object The Java object. */ public void addJavaRootObject(Object object) { assert nocheck || !rootobjects.contains(object); this.rootobjects.add(object); OAVJavaType java_type = tmodel.getJavaType(object.getClass()); if(OAVJavaType.KIND_BEAN.equals(java_type.getKind())) registerValue(java_type, object); eventhandler.objectAdded(object, java_type, true); }
/** * 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); }
/** * Check if a value (oid or java object) is managed by the state. * Returns true for attribute values which are directly contained oav objects * or mutable java objects, e.g. not simple values such as strings or intergers. */ protected boolean isManaged(Object value) { // Value is a directly contained object or java bean/object (i.e. not basic value) return value!=null && !tmodel.getJavaType(value.getClass()).getKind().equals(OAVJavaType.KIND_VALUE) && (!generator.isId(value) || internalContainsObject(value)); // return value!=null && // (!generator.isId(value) && !tmodel.getJavaType(value.getClass()).getKind().equals(OAVJavaType.KIND_VALUE) // || internalContainsObject(value)); }
/** * Check if a value (oid or java object) is managed by the state. * Returns true for attribute values which are directly contained oav objects * or mutable java objects, e.g. not simple values such as strings or intergers. */ protected boolean isManaged(Object value) { // Value is a directly contained object or java bean/object (i.e. not basic value) return value!=null && !tmodel.getJavaType(value.getClass()).getKind().equals(OAVJavaType.KIND_VALUE) && (!generator.isId(value) || internalContainsObject(value)); // return value!=null && // (!generator.isId(value) && !tmodel.getJavaType(value.getClass()).getKind().equals(OAVJavaType.KIND_VALUE) // || internalContainsObject(value)); }
/** * Drop a Java object from root objects. * @param object The Java object. */ public void removeJavaRootObject(Object object) { // #ifndef MIDP assert nocheck || !generator.isId(object); assert nocheck || rootobjects.contains(object) && javaobjects.contains(object); // #endif OAVJavaType java_type = tmodel.getJavaType(object.getClass()); if(OAVJavaType.KIND_VALUE.equals(java_type.getKind())) throw new RuntimeException("Value types not supported for Java root objects: "+java_type+", "+object); this.rootobjects.remove(object); if(!objectusages.containsKey(object)) // Todo: java objects in nested states. { javaobjects.remove(object); if(OAVJavaType.KIND_BEAN.equals(java_type.getKind())) deregisterValue(java_type, object); eventhandler.objectRemoved(object, java_type); } }
/** * Drop a Java object from root objects. * @param object The Java object. */ public void removeJavaRootObject(Object object) { // #ifndef MIDP assert nocheck || !generator.isId(object); assert nocheck || rootobjects.contains(object) && javaobjects.contains(object); // #endif OAVJavaType java_type = tmodel.getJavaType(object.getClass()); if(OAVJavaType.KIND_VALUE.equals(java_type.getKind())) throw new RuntimeException("Value types not supported for Java root objects: "+java_type+", "+object); this.rootobjects.remove(object); if(!objectusages.containsKey(object)) // Todo: java objects in nested states. { javaobjects.remove(object); if(OAVJavaType.KIND_BEAN.equals(java_type.getKind())) deregisterValue(java_type, object); eventhandler.objectRemoved(object, java_type); } }
/** * Ensure that a type has an attribute. * @param object The object. * @param attribute The attribute. * @throws RuntimeException if value is not allowed. */ protected boolean checkTypeHasAttribute(Object object, OAVAttributeType attribute) { if(attribute==null) throw new IllegalArgumentException("Attribute must not null."); OAVObjectType type = attribute.getObjectType() instanceof OAVJavaType ? tmodel.getJavaType(object.getClass()) : (OAVObjectType)types.get(object); if(type==null) throw new RuntimeException("Unknown object type of: "+object); 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 object The object. * @param attribute The attribute. * @throws RuntimeException if value is not allowed. */ protected boolean checkTypeHasAttribute(Object object, OAVAttributeType attribute) { if(attribute==null) throw new IllegalArgumentException("Attribute must not null."); OAVObjectType type = attribute.getObjectType() instanceof OAVJavaType ? tmodel.getJavaType(object.getClass()) : (OAVObjectType)types.get(object); if(type==null) throw new RuntimeException("Unknown object type of: "+object); OAVAttributeType attr = type.getAttributeType(attribute.getName()); if(!attribute.equals(attr)) throw new RuntimeException("Attribute must belong to object type: "+attribute+", "+type); return true; }
/** * Add a Java object as root object. * @param object The Java object. */ public void addJavaRootObject(Object object) { // #ifndef MIDP assert nocheck || !generator.isId(object); assert nocheck || !rootobjects.contains(object); // #endif OAVJavaType java_type = tmodel.getJavaType(object.getClass()); if(OAVJavaType.KIND_VALUE.equals(java_type.getKind())) throw new RuntimeException("Value types not supported for Java root objects: "+java_type+", "+object); this.rootobjects.add(object); if(this.javaobjects.add(object)) // Todo: java objects in nested states. { if(OAVJavaType.KIND_BEAN.equals(java_type.getKind())) registerValue(java_type, object); eventhandler.objectAdded(object, java_type, true); } }
/** * */ public static Object createExpression(IOAVState state, Object scope, final String expression, final String[] paramnames, final Class[] paramtypes) { // Hack!!! Should be configurable. IExpressionParser exp_parser = new JavaCCExpressionParser(); // Object mcapa = state.getAttributeValue(scope, OAVBDIRuntimeModel.element_has_model); // String[] imports = OAVBDIMetaModel.getImports(state, mcapa); Map params = null; if(paramnames!=null) { params = new HashMap(); for(int i=0; i<paramnames.length; i++) { params.put(paramnames[i], state.getTypeModel().getJavaType(paramtypes[i])); } } IParsedExpression pex = exp_parser.parseExpression(expression, null, params, Thread.currentThread().getContextClassLoader()); return new ExpressionNoModel(state, scope, pex); }
/** * Create a java type if it does not already exist. * Required because some (user) Java types are created * on the fly when loading agent models * (e.g. Map in TranslationC1). */ protected static OAVJavaType createJavaType(Class clazz, String kind) { OAVJavaType ret; if(bdi_rt_model.contains(new OAVJavaType(clazz, kind, bdi_rt_model))) { ret = bdi_rt_model.getJavaType(clazz); } else { ret = bdi_rt_model.createJavaType(clazz, kind); } return ret; } }
/** * 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; }