/** * Get the set of matching type nodes for a (sub)type. * @param type The object type. * @return The set of type nodes for that object type. */ protected Set getTypeNodes(OAVObjectType type) { Set ret = (Set)typenodesets.get(type); if(ret==null) { synchronized(this) { ret = (Set)typenodesets.get(type); if(ret==null) { ret = new HashSet(); for(Iterator it=typenodes.values().iterator(); it.hasNext(); ) { TypeNode tnode = (TypeNode)it.next(); if(type.isSubtype(tnode.getObjectType())) ret.add(tnode); } typenodesets.put(type, ret); } } } return ret; }
/** * Get the set of matching type nodes for a (sub)type. * @param type The object type. * @return The set of type nodes for that object type. */ protected Set getTypeNodes(OAVObjectType type) { Set ret = (Set)typenodesets.get(type); if(ret==null) { synchronized(this) { ret = (Set)typenodesets.get(type); if(ret==null) { ret = new HashSet(); for(Iterator it=typenodes.values().iterator(); it.hasNext(); ) { TypeNode tnode = (TypeNode)it.next(); if(type.isSubtype(tnode.getObjectType())) ret.add(tnode); } typenodesets.put(type, ret); } } } return ret; }
/** * Test if this object is same type or subtype of this type. * @param object The object to test. * @return True, if object is same type or subtype. */ public boolean isSubtype(OAVObjectType type) { return type instanceof OAVJavaType ? SReflect.isSupertype(((OAVJavaType)type).getClazz(), clazz) : super.isSubtype(type); }
/** * Test if this object is same type or subtype of this type. * @param object The object to test. * @return True, if object is same type or subtype. */ public boolean isSubtype(OAVObjectType type) { return type instanceof OAVJavaType ? SReflect.isSupertype(((OAVJavaType)type).getClazz(), clazz) : super.isSubtype(type); }
/** * Evaluate two objects with respect to the * operator semantics. * @param state The state. * @param val1 The first object. * @param val2 The second object. * @return True, if objects fit wrt. the operator semantics. */ public boolean evaluate(IOAVState state, Object val1, Object val2) { val1 = val1 instanceof ILazyValue? ((ILazyValue)val1).getValue(): val1; val2 = val2 instanceof ILazyValue? ((ILazyValue)val2).getValue(): val2; boolean ret; if(val2 instanceof Class) { ret = ((Class)val2).isAssignableFrom(val1 instanceof Class? (Class)val1: val1.getClass()); } else //if(val2 instanceof OAVObjectType) { ret = val1 instanceof OAVObjectType? ((OAVObjectType)val1).isSubtype((OAVObjectType)val2) :state.getType(val1).isSubtype((OAVObjectType)val2); } return ret; }
/** * Evaluate two objects with respect to the * operator semantics. * @param state The state. * @param val1 The first object. * @param val2 The second object. * @return True, if objects fit wrt. the operator semantics. */ public boolean evaluate(IOAVState state, Object val1, Object val2) { val1 = val1 instanceof ILazyValue? ((ILazyValue)val1).getValue(): val1; val2 = val2 instanceof ILazyValue? ((ILazyValue)val2).getValue(): val2; boolean ret; if(val2 instanceof Class) { ret = ((Class)val2).isAssignableFrom(val1 instanceof Class? (Class)val1: val1.getClass()); } else //if(val2 instanceof OAVObjectType) { ret = val1 instanceof OAVObjectType? ((OAVObjectType)val1).isSubtype((OAVObjectType)val2) :state.getType(val1).isSubtype((OAVObjectType)val2); } return ret; }
/** * */ public static boolean isSucceeded(IOAVState state, Object handle) { boolean ret; Object pstate = state.getAttributeValue(handle, OAVBDIRuntimeModel.goal_has_processingstate); Object mgoal = state.getAttributeValue(handle, OAVBDIRuntimeModel.element_has_model); if(state.getType(mgoal).isSubtype(OAVBDIMetaModel.maintaingoal_type)) ret = OAVBDIRuntimeModel.GOALPROCESSINGSTATE_IDLE.equals(pstate); else ret = OAVBDIRuntimeModel.GOALPROCESSINGSTATE_SUCCEEDED.equals(pstate); return ret; }
/** * Test if a value is compatible with the defined typeinfo. */ protected boolean isTypeCompatible(Object object, ObjectInfo info, IContext context) { boolean ret = true; if(info!=null && info.getTypeInfo() instanceof OAVObjectType) { OAVObjectType otype = (OAVObjectType)info.getTypeInfo(); ret = ((IOAVState)context).getType(object).isSubtype(otype); } return ret; }
/** * Test if a value is compatible with the defined typeinfo. */ protected boolean isTypeCompatible(Object object, ObjectInfo info, IContext context) { boolean ret = true; if(info!=null && info.getTypeInfo() instanceof OAVObjectType) { OAVObjectType otype = (OAVObjectType)info.getTypeInfo(); ret = ((IOAVState)context).getType(object).isSubtype(otype); } return ret; }
/** * 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 object, OAVAttributeType attribute, Object value) { 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: "+object+" "+attribute+" "+value); } else if(!getType(value).isSubtype(atype)) { throw new RuntimeException("Value not of suitable type: "+object+" "+attribute+" "+value); } } 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 object, OAVAttributeType attribute, Object value) { 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: "+object+" "+attribute+" "+value); } else if(!getType(value).isSubtype(atype)) { throw new RuntimeException("Value not of suitable type: "+object+" "+attribute+" "+value); } } return true; }
public String getObjectName(Object obj) { String name = null; if(state.getType(obj).isSubtype(OAVBDIMetaModel.modelelement_type)) { name = (String)state.getAttributeValue(obj, OAVBDIMetaModel.modelelement_has_name); } if(name==null && state.getType(obj).isSubtype(OAVBDIMetaModel.elementreference_type)) { name = (String)state.getAttributeValue(obj, OAVBDIMetaModel.elementreference_has_concrete); } if(name==null && state.getType(obj).isSubtype(OAVBDIMetaModel.expression_type)) { IParsedExpression exp =(IParsedExpression)state.getAttributeValue(obj, OAVBDIMetaModel.expression_has_parsed); String text = (String)state.getAttributeValue(obj, OAVBDIMetaModel.expression_has_text); name = exp!=null ? exp.getExpressionText() : text!=null ? text.trim() : null; } if(name==null) { name = ""+obj; } return obj instanceof String ? (String)obj : state.getType(obj).getName().substring(1) + " " + name; } }
/** * 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; }
/** * Get the type name (name of the modelelement). */ public static String getTypeName(IOAVState state, Object handle) { // Only called from synchronized code -> no agent invocation necessary String ret = "unknown"; try { if(handle!=null && state.getType(handle).isSubtype(OAVBDIRuntimeModel.element_type)) { Object me = state.getAttributeValue(handle, OAVBDIRuntimeModel.element_has_model); if(me!=null) ret = (String)state.getAttributeValue(me, OAVBDIMetaModel.modelelement_has_name); } } catch(RuntimeException e) { } return ret; }
/** * 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; }
/** * Schedule a plan instance candidate. */ public static void schedulePlanInstanceCandidate(IOAVState state, Object dispelem, Object rplan, Object rcapa)//Object cand) { // System.out.println("schedulePlanInstanceCandidate: Setting plan to ready: " // +BDIInterpreter.getInterpreter(state).getAgentAdapter().getComponentIdentifier().getLocalName() // +", "+rplan); // Object rplan = state.getAttributeValue(cand, OAVBDIRuntimeModel.plancandidate_has_plan); // Object rcapa = state.getAttributeValue(cand, OAVBDIRuntimeModel.plancandidate_has_rcapa); state.setAttributeValue(rplan, OAVBDIRuntimeModel.plan_has_processingstate, OAVBDIRuntimeModel.PLANPROCESSINGTATE_READY); state.setAttributeValue(rplan, OAVBDIRuntimeModel.plan_has_dispatchedelement, dispelem); PlanRules.cleanupPlanWait(state, rcapa, rplan, false); if(dispelem!=null && state.getType(dispelem).isSubtype(OAVBDIRuntimeModel.processableelement_type)) { state.setAttributeValue(dispelem, OAVBDIRuntimeModel.processableelement_has_state, OAVBDIRuntimeModel.PROCESSABLEELEMENT_CANDIDATESSELECTED); } }
/** * Dispatch a new subgoal. * @param subgoal The new subgoal. * Note: plan step is interrupted after call. */ public void dispatchSubgoal(IGoal subgoal) { Object rgoal = ((GoalFlyweight)subgoal).getHandle(); Object scope = ((GoalFlyweight)subgoal).getScope(); interpreter.startMonitorConsequences(); GoalLifecycleRules.adoptGoal(state, scope, rgoal); state.addAttributeValue(rplan, OAVBDIRuntimeModel.plan_has_subgoals, rgoal); state.setAttributeValue(rgoal, OAVBDIRuntimeModel.goal_has_parentplan, rplan); // Protect goal, if necessary. Object planstate = state.getAttributeValue(rplan, OAVBDIRuntimeModel.plan_has_lifecyclestate); Object reason = state.getAttributeValue(rplan, OAVBDIRuntimeModel.plan_has_reason); boolean protectgoal = OAVBDIRuntimeModel.PLANLIFECYCLESTATE_PASSED.equals(planstate) || OAVBDIRuntimeModel.PLANLIFECYCLESTATE_FAILED.equals(planstate) || OAVBDIRuntimeModel.PLANLIFECYCLESTATE_ABORTED.equals(planstate); if(!protectgoal && reason!=null && state.getType(reason).isSubtype(OAVBDIRuntimeModel.goal_type)) { protectgoal = ((Boolean)state.getAttributeValue(reason, OAVBDIRuntimeModel.goal_has_protected)).booleanValue(); } if(protectgoal) { state.setAttributeValue(rgoal, OAVBDIRuntimeModel.goal_has_protected, Boolean.TRUE); } interpreter.endMonitorConsequences(); }
/** * Resolve the parameter class. */ public static Class resolveClazz(IOAVState state, Object mparamelem, String name) { Class clazz = null; // Object mparamelem = state.getAttributeValue(parameterelement, OAVBDIRuntimeModel.element_has_model); Object mparam = state.getAttributeValue(mparamelem, OAVBDIMetaModel.parameterelement_has_parameters, name); if(mparam!=null) { clazz = (Class)state.getAttributeValue(mparam, OAVBDIMetaModel.typedelement_has_class); } else if(state.getType(mparamelem).isSubtype(OAVBDIMetaModel.messageevent_type)) { MessageType mt = MessageEventRules.getMessageEventType(state, mparamelem); ParameterSpecification ps = mt.getParameter(name); clazz = ps.getClazz(); } if(clazz==null) clazz = Object.class; return clazz; }
if(state.getType(rpe).isSubtype(OAVBDIRuntimeModel.goal_type)) state.setAttributeValue(state.getAttributeValue(cand, OAVBDIRuntimeModel.waitqueuecandidate_has_plan) , OAVBDIRuntimeModel.plan_has_waitqueuecandidate, cand); if(state.getType(rpe).isSubtype(OAVBDIRuntimeModel.goal_type)) state.setAttributeValue(rplan, OAVBDIRuntimeModel.plan_has_plancandidate, cand); if(state.getType(rpe).isSubtype(OAVBDIRuntimeModel.goal_type))
/** * Resolve the parameterset class. */ protected Class resolveClazz() { Class clazz = null; Object mparamelem = getState().getAttributeValue(pe, OAVBDIRuntimeModel.element_has_model); Object mparamset = getState().getAttributeValue(mparamelem, OAVBDIMetaModel.parameterelement_has_parametersets, name); if(mparamset!=null) { clazz = (Class)getState().getAttributeValue(mparamset, OAVBDIMetaModel.typedelement_has_class); } else if(getState().getType(mparamelem).isSubtype(OAVBDIMetaModel.messageevent_type)) { MessageType mt = MessageEventRules.getMessageEventType(getState(), mparamelem); ParameterSpecification ps = mt.getParameter(name); clazz = ps.getClazz(); } if(clazz==null) clazz = Object.class; return clazz; }