/** * Convert an object to another type of object. */ public Object convertContentObject(String value, QName tag, AReadContext context) throws Exception { Object ret = value; if(tag.getNamespaceURI().startsWith(SXML.PROTOCOL_TYPEINFO)) { String clazzname = tag.getNamespaceURI().substring(SXML.PROTOCOL_TYPEINFO.length())+"."+tag.getLocalPart(); Class clazz = SReflect.classForName0(clazzname, context.getClassLoader()); if(clazz!=null) { if(BasicTypeConverter.isBuiltInType(clazz)) { ret = BasicTypeConverter.getBasicStringConverter(clazz).convertString(value, context); } else { ret = null; context.getReporter().report("No converter known for: "+clazz, "content error", context, context.getLocation()); } } } return ret; }
public Object postProcess(IContext context, Object object) { try { BDIXModel model = (BDIXModel)context.getRootObject(); MCapability mcapa = model.getCapability(); AReadContext ar = (AReadContext)context; Map<String, String> rawattrs = ar.getTopStackElement().getRawAttributes(); String service = rawattrs.get("class"); String method = rawattrs.get("method"); MGoal mgoal = (MGoal)ar.getStackElement(ar.getStackSize()-2).getObject(); Class<?> iface = SReflect.findClass(service, model.getAllImports(), ar.getClassLoader()); ClassInfo ci = new ClassInfo(iface.getName()); // Just use first method if no name is given if(method==null) method = iface.getDeclaredMethods()[0].getName(); mcapa.addGoalPublication(ci, mgoal, method); } catch(Exception e) { throw new RuntimeException(e); } return null; }
public void linkObject(Object object, Object parent, Object linkinfo, QName[] pathname, AReadContext context) throws Exception { // Exchange parent for OAV children of root object. Map user = (Map)context.getUserContext(); IOAVState state = (IOAVState)user.get(OAVObjectReaderHandler.CONTEXT_STATE); if(state.isIdentifier(object)) { parent = getOAVRoot(uri, context, user, state); } context.getTopStackElement().getReaderHandler().linkObject(object, parent, linkinfo, pathname, context); } };
public void linkObject(Object object, Object parent, Object linkinfo, QName[] pathname, AReadContext context) throws Exception { StackElement se = context.getStackElement(context.getStackSize()-2); String name = se.getRawAttributes().containsKey("ref") ? se.getRawAttributes().get("ref") : se.getRawAttributes().get("cref"); ((UnparsedExpression)object).setName(MElement.internalName(name)); ((MConfigParameterElement)parent).addParameter((UnparsedExpression)object); // super add would required additional support for parameterset (subobjectinfo on all MConfigParameterElement elems // super.linkObject(object, parent, linkinfo, pathname, context); } };
public Object postProcess(IContext context, Object object) { MParameter mparam = (MParameter)object; mparam.setMulti(multi); // Init events. AReadContext ar = (AReadContext)context; MParameterElement pe = null; for(StackElement se: ar.getStack()) { if(se.getObject() instanceof MParameterElement) { pe = (MParameterElement)se.getObject(); } } mparam.initEvents(pe); return mparam; }
context.getReporter().report("Conversion to target no possible: "+targetclass+" "+vals, "convert error", context, context.getLocation());
return; IOAVState state = (IOAVState)((Map)context.getUserContext()).get(CONTEXT_STATE); StackElement se = context.getTopStackElement(); context.getReporter().report("Unknown attribute info: "+attrinfo, "attribute error", context, se.getLocation()); StackElement se = context.getTopStackElement(); context.getReporter().report(e.toString(), "attribute error", context, se.getLocation()); StackElement se = context.getTopStackElement(); context.getReporter().report("Unhandled attribute: "+object+", "+xmlattrname+", "+attrpath, "unhandled attribute", context, se.getLocation());
IOAVState state = (IOAVState)((Map)context.getUserContext()).get(CONTEXT_STATE); context.getReporter().report("Could not link: "+elem+" "+parent, "Could not link", context, context.getLocation());
for(StackElement se: ar.getStack()) String bels = ar.getTopStackElement().getRawAttributes()==null? null: ar.getTopStackElement().getRawAttributes().get("beliefs"); if(bels!=null) String params = ar.getTopStackElement().getRawAttributes()==null? null: ar.getTopStackElement().getRawAttributes().get("parameters"); if(params!=null) String goals = ar.getTopStackElement().getRawAttributes()==null? null: ar.getTopStackElement().getRawAttributes().get("goals"); if(goals!=null) String rawevs = ar.getTopStackElement().getRawAttributes()==null? null: ar.getTopStackElement().getRawAttributes().get("rawevents"); if(rawevs!=null)
int cnt = context.getArrayCount(parent); context.getReporter().report("Could not link: "+object+" "+parent, "link error", context, context.getLocation());
public void linkObject(Object object, Object parent, Object linkinfo, QName[] pathname, AReadContext context) throws Exception if(context.getStackElement(context.getStackSize()-1).getTag().equals(new QName(uri, "match"))) MTrigger mtrig = (MTrigger)context.getStackElement(context.getStackSize()-3).getObject(); String ref = (String)context.getStackElement(context.getStackSize()-2).getRawAttributes().get("ref"); if(ref==null) ref = (String)context.getStackElement(context.getStackSize()-2).getRawAttributes().get("cref"); else if(context.getTopStackElement().getTag().equals(new QName(uri, "factadded"))) MTrigger mtrig = (MTrigger)context.getStackElement(context.getStackSize()-2).getObject(); mtrig.addFactAdded(MElement.internalName((String)object)); else if(context.getTopStackElement().getTag().equals(new QName(uri, "factremoved"))) MTrigger mtrig = (MTrigger)context.getStackElement(context.getStackSize()-2).getObject(); mtrig.addFactRemoved(MElement.internalName((String)object)); else if(context.getTopStackElement().getTag().equals(new QName(uri, "factchanged"))) MTrigger mtrig = (MTrigger)context.getStackElement(context.getStackSize()-2).getObject(); mtrig.addFactChanged(MElement.internalName((String)object)); context.getTopStackElement().getReaderHandler().linkObject(object, parent, linkinfo, pathname, context);
Class clazz = SReflect.classForName0(clazzname, context.getClassLoader()); if(clazz!=null)
public void linkObject(Object object, Object parent, Object linkinfo, QName[] pathname, AReadContext context) throws Exception { if(object instanceof MCondition) { MGoal mgoal = (MGoal)parent; String condtype = pathname[pathname.length-1].getLocalPart(); condtype = condtype.substring(0, condtype.length()-9); mgoal.addCondition(condtype, (MCondition)object); } else if(object instanceof String && parent instanceof MGoal && context.getStackElement(context.getStackSize()-4).getObject() instanceof BDIXModel) { BDIXModel model = (BDIXModel)context.getStackElement(context.getStackSize()-4).getObject(); model.getCapability().addGoalReference(MElement.internalName((String)object), ((MElement)parent).getName()); } else { context.getDefaultHandler().linkObject(object, parent, linkinfo, pathname, context); } } };
public void linkObject(Object object, Object parent, Object linkinfo, QName[] pathname, AReadContext context) throws Exception { if(object instanceof MElementRef && pathname[0].getLocalPart().equals("goals")) { ((BDIXModel)parent).getCapability().addGoalReference(((MElementRef)object).getName(), ((MElementRef)object).getRef()); } else if(object instanceof MElementRef && pathname[0].getLocalPart().equals("events")) { ((BDIXModel)parent).getCapability().addEventReference(((MElementRef)object).getName(), ((MElementRef)object).getRef()); } else if(object instanceof MElementRef && pathname[0].getLocalPart().equals("expressions")) { ((BDIXModel)parent).getCapability().addExpressionReference(((MElementRef)object).getName(), ((MElementRef)object).getRef()); } else { if(object instanceof MBelief || object instanceof MGoal || object instanceof MPlan || object instanceof MMessageEvent || object instanceof MInternalEvent || object instanceof MCapabilityReference || object instanceof MElementRef || (object instanceof UnparsedExpression && pathname[pathname.length-1].getLocalPart().equals("expression")) // hack for bdi expressions || (object instanceof MCondition && pathname[pathname.length-1].getLocalPart().equals("condition"))) { parent = ((BDIXModel)parent).getCapability(); } context.getTopStackElement().getReaderHandler().linkObject(object, parent, linkinfo, pathname, context); } } };
((AReadContext)context).getReporter().report("Type not found: "+typename, null, null, null);
IOAVState state = (IOAVState)((Map)context.getUserContext()).get(CONTEXT_STATE);
protected static Object getOAVRoot(String uri, AReadContext context, Map user, IOAVState state) { Object parent = user.get(OAVBDIModelLoader.CONTEXT_OAVROOT); if(parent==null) { parent = context.getStackElement(0).getTag().equals(new QName(uri, "agent")) ? state.createObject(OAVBDIMetaModel.agent_type) : state.createObject(OAVBDIMetaModel.capability_type); user.put(OAVBDIModelLoader.CONTEXT_OAVROOT, parent); state.setAttributeValue(parent, OAVBDIMetaModel.modelelement_has_name, ((IModelInfo)context.getRootObject()).getName()); state.setAttributeValue(parent, OAVBDIMetaModel.modelelement_has_description, ((IModelInfo)context.getRootObject()).getDescription()); } return parent; }
public Object postProcess(IContext context, Object object) { ConfigurationInfo app = (ConfigurationInfo)object; IModelInfo mapp = (IModelInfo)context.getRootObject(); UnparsedExpression[] margs = app.getArguments(); for(int i=0; i<margs.length; i++) { try { Argument arg = (Argument)mapp.getArgument(margs[i].getName()); if(arg==null) throw new RuntimeException("Overridden argument not declared in component type: "+margs[i].getName()); // Object val = overridenarg.getParsedValue().getValue(null); // arg.setDefaultValue(app.getName(), val); } catch(RuntimeException e) { Object se = new Tuple(((AReadContext)context).getStack()); MultiCollection report = (MultiCollection)context.getUserContext(); report.put(se, e.toString()); } } return null; }
/** * Initiate the bulk link calls. */ protected void handleBulkLinking(List childs, Object parent, AReadContext context, QName[] pathname, List linkdatas, int startidx) throws Exception { if(childs.size()>1) { try { bulkLinkObjects(childs, parent, ((LinkData)linkdatas.get(startidx)).getLinkinfo(), pathname, context); } catch(Exception e) { context.getReporter().report("Warning. Bulk link initiated but not successful: "+childs+" "+parent+" "+e, "warning", context, context.getLocation()); for(int i=0; i<childs.size(); i++) { linkObject(childs.get(i), parent, ((LinkData)linkdatas.get(startidx+i)).getLinkinfo(), pathname, context); } } } else { linkObject(childs.get(0), parent, ((LinkData)linkdatas.get(startidx)).getLinkinfo(), pathname, context); } }
return; IOAVState state = (IOAVState)((Map)context.getUserContext()).get(CONTEXT_STATE); StackElement se = context.getTopStackElement(); context.getReporter().report("Unknown attribute info: "+attrinfo, "attribute error", context, se.getLocation()); StackElement se = context.getTopStackElement(); context.getReporter().report(e.toString(), "attribute error", context, se.getLocation()); StackElement se = context.getTopStackElement(); context.getReporter().report("Unhandled attribute: "+object+", "+xmlattrname+", "+attrpath, "unhandled attribute", context, se.getLocation());