public void run() { object = getState().getTypeModel().getClassLoader(); } };
/** * Get the class loader of the agent. * The agent class loader is required to avoid incompatible class issues, * when changing the platform class loader while agents are running. * This may occur e.g. when decoding messages and instantiating parameter values. * @return The agent class loader. */ public ClassLoader getClassLoader() { // return model.getModelInfo().getClassLoader(); return model.getState().getTypeModel().getClassLoader(); }
/** * Parse an expression in the given scope. * @param expression The expression. * @param language The language or null for default java-like language. * @param state The state. * @param scope The scope. * @return The parsed expression */ public static IParsedExpression parseExpression(String expression, String language, IOAVState state, Object scope) { if(language!=null && !"java".equals(language)) { throw new UnsupportedOperationException("Only java currently supported."); } IExpressionParser exp_parser = new JavaCCExpressionParser(); // Hack!!! Map language to parser somewhere? IParsedExpression pexp = exp_parser.parseExpression(expression, null, null, state.getTypeModel().getClassLoader()); return pexp; }
/** * Get an object type while considering imports for Java types. * @param tmodel The type model. * @param typename The name of the type to search for. * @param imports The imports (if any). * @param loader The class loader. * @return The type. */ protected static OAVObjectType getObjectType(OAVTypeModel tmodel, String typename, String[] imports) { OAVObjectType ret = null; try { ret = tmodel.getObjectType(typename); } catch(Exception e){} // If not found, search for class in imports. if(ret==null) { Class clazz = SReflect.findClass0(typename, imports, tmodel.getClassLoader()); if(clazz==null) throw new RuntimeException("Type not found in type model: "+typename); ret = tmodel.getJavaType(clazz); } return ret; } }
/** * Get an object type while considering imports for Java types. * @param tmodel The type model. * @param typename The name of the type to search for. * @param imports The imports (if any). * @param loader The class loader. * @return The type. */ protected static OAVObjectType getObjectType(OAVTypeModel tmodel, String typename, String[] imports) { OAVObjectType ret = null; try { ret = tmodel.getObjectType(typename); } catch(Exception e){} // If not found, search for class in imports. if(ret==null) { Class clazz = SReflect.findClass0(typename, imports, tmodel.getClassLoader()); if(clazz==null) throw new RuntimeException("Type not found in type model: "+typename); ret = tmodel.getJavaType(clazz); } return ret; } }
/** * Load class. */ public Object postProcess(IContext context, Object object) { Map ouc = (Map)context.getUserContext(); IOAVState state = (IOAVState)ouc.get(OAVObjectReaderHandler.CONTEXT_STATE); String value = (String)state.getAttributeValue(object, classnameattr); if(value!=null) { try { Class clazz = SReflect.findClass(value, ((IModelInfo)context.getRootObject()).getAllImports(), state.getTypeModel().getClassLoader()); state.setAttributeValue(object, classattr, clazz); } catch(Exception e) { reportError(context, e.toString()); } } return null; }
Class clazz = SReflect.findClass0(fn, imports, tmodel.getClassLoader()); IFunction func = null; if(MethodCallFunction.class.equals(clazz)) clazz = SReflect.findClass0(clazzname, imports, tmodel.getClassLoader()); Method[] methods = SReflect.getMethods(clazz, methodname); Method method = null;
Class clazz = SReflect.findClass0(fn, imports, tmodel.getClassLoader()); IFunction func = null; if(MethodCallFunction.class.equals(clazz)) clazz = SReflect.findClass0(clazzname, imports, tmodel.getClassLoader()); Method[] methods = SReflect.getMethods(clazz, methodname); Method method = null;
/** * Get the classloader. * @return The classloader. */ public ClassLoader getClassLoader() { if(getInterpreter().getComponentAdapter().isExternalThread()) { AgentInvocation invoc = new AgentInvocation() { public void run() { object = getState().getTypeModel().getClassLoader(); } }; return (ClassLoader)invoc.object; } else { return getState().getTypeModel().getClassLoader(); } }
if(clname!=null) Class clazz = SReflect.findClass(clname, interpreter.getModel(rcapability).getAllImports(), state.getTypeModel().getClassLoader());
ret = exp_parser.parseExpression(value, ((IModelInfo)context.getRootObject()).getAllImports(), null, state.getTypeModel().getClassLoader());
Class clazz = SReflect.findClass0(typename, imports, tmodel.getClassLoader()); if(clazz!=null)
message.put(name, codec.encode(value, state.getTypeModel().getClassLoader(), null, null));
Class clazz = SReflect.findClass0(typename, imports, tmodel.getClassLoader()); if(clazz!=null)
interpreter.setPlanThread(thread); ClassLoader oldcl = thread.getContextClassLoader(); assert interpreter.getState().getTypeModel().getClassLoader()!=null; thread.setContextClassLoader(interpreter.getState().getTypeModel().getClassLoader());
Class clazz = SReflect.findClass0(name, imports, helper.getBuildContext().getTypeModel().getClassLoader()); if(clazz!=null) otype = helper.getBuildContext().getTypeModel().getJavaType(clazz); Class clazz = SReflect.findClass0(name, imports, helper.getBuildContext().getTypeModel().getClassLoader()); if(clazz!=null) otype = helper.getBuildContext().getTypeModel().getJavaType(clazz);
Class clazz = SReflect.findClass0(name, imports, helper.getBuildContext().getTypeModel().getClassLoader()); if(clazz!=null) otype = helper.getBuildContext().getTypeModel().getJavaType(clazz); Class clazz = SReflect.findClass0(name, imports, helper.getBuildContext().getTypeModel().getClassLoader()); if(clazz!=null) otype = helper.getBuildContext().getTypeModel().getJavaType(clazz);
/** * Create a component instance. * @param adapter The component adapter. * @param model The component model. * @param config The name of the configuration (or null for default configuration) * @param arguments The arguments for the agent as name/value pairs. * @param parent The parent component (if any). * @return An instance of a component. */ public Tuple2<IComponentInstance, IComponentAdapter> createComponentInstance(IComponentDescription desc, IComponentAdapterFactory factory, OAVAgentModel amodel, String config, Map<String, Object> arguments, IExternalAccess parent, RequiredServiceBinding[] bindings, boolean copy, boolean realtime, IIntermediateResultListener<Tuple2<String, Object>> resultlistener, Future<Void> ret) { // Create type model for agent instance (e.g. holding dynamically loaded java classes). OAVTypeModel tmodel = new OAVTypeModel(desc.getName().getLocalName()+"_typemodel", amodel.getState().getTypeModel().getClassLoader()); // OAVTypeModel tmodel = new OAVTypeModel(model.getName()+"_typemodel", ((OAVAgentModel)model).getTypeModel().getClassLoader()); tmodel.addTypeModel(amodel.getState().getTypeModel()); tmodel.addTypeModel(OAVBDIRuntimeModel.bdi_rt_model); IOAVState state = OAVStateFactory.createOAVState(tmodel); state.addSubstate(amodel.getState()); // BDIInterpreter bdii = new BDIInterpreter(desc, factory, state, amodel, config, arguments, parent, bindings, getPropertyMap(), copy, realtime, resultlistener, ret); BDIInterpreter bdii = new BDIInterpreter(desc, factory, state, amodel, config, arguments, parent, bindings, myprops, copy, realtime, resultlistener, ret); return new Tuple2<IComponentInstance, IComponentAdapter>(bdii, bdii.getAgentAdapter()); }
OAVTypeModel tmodel = new OAVTypeModel(desc.getName().getLocalName()+"_typemodel", amodel.getState().getTypeModel().getClassLoader());
public void customResultAvailable(ClassLoader cl) { try { // OAVAgentModel amodel = (OAVAgentModel)model; OAVAgentModel amodel = (OAVAgentModel)loader.loadModel(modelinfo.getFilename(), null, cl, new Object[]{modelinfo.getResourceIdentifier(), root}); // Create type model for agent instance (e.g. holding dynamically loaded java classes). OAVTypeModel tmodel = new OAVTypeModel(desc.getName().getLocalName()+"_typemodel", amodel.getState().getTypeModel().getClassLoader()); // OAVTypeModel tmodel = new OAVTypeModel(model.getName()+"_typemodel", ((OAVAgentModel)model).getTypeModel().getClassLoader()); tmodel.addTypeModel(amodel.getState().getTypeModel()); tmodel.addTypeModel(OAVBDIRuntimeModel.bdi_rt_model); IOAVState state = OAVStateFactory.createOAVState(tmodel); state.addSubstate(amodel.getState()); // BDIInterpreter bdii = new BDIInterpreter(desc, factory, state, amodel, config, arguments, parent, bindings, getPropertyMap(), copy, realtime, resultlistener, init); BDIInterpreter bdii = new BDIInterpreter(desc, factory, state, amodel, config, arguments, parent, bindings, myprops, copy, realtime, resultlistener, init); ret.setResult(new Tuple2<IComponentInstance, IComponentAdapter>(bdii, bdii.getAgentAdapter())); } catch(Exception e) { ret.setException(e); } } });