/** * Load a model. * @param name The original name (i.e. not filename). * @param info The resource info. */ protected ICacheableModel doLoadModel(String name, String[] imports, ResourceInfo info, ClassLoader classloader, Object context) throws Exception { // if(name.indexOf("HelloWorldAgent")!=-1) // System.out.println("cache miss: "+name); return (ICacheableModel)reader.read(name, imports, classloader, (IResourceIdentifier)((Object[])context)[0], (IComponentIdentifier)((Object[])context)[1], (List<IComponentFeatureFactory>)((Object[])context)[2]); }
/** * Create a new BPMN model loader. */ public MicroModelLoader() { super(new String[]{FILE_EXTENSION_MICRO}); this.reader = new MicroClassReader(); }
/** * */ public <T extends Annotation> T getAnnotation(Class<?> clazz, Class<T> anclazz, ClassLoader cl1, ClassLoader cl2) { return getProxyAnnotation(clazz.getAnnotation((Class<T>)getClass(anclazz, cl1)), cl2); }
if(isAnnotationPresent(cma, Agent.class, cl)) Agent val = getAnnotation(cma, Agent.class, cl); Boolean susp = val.suspend().toBoolean(); Boolean mast = val.master().toBoolean(); if(isAnnotationPresent(iface, Service.class, cl)) if(isAnnotationPresent(cma, Description.class, cl) && modelinfo.getDescription()==null) Description val = getAnnotation(cma, Description.class, cl); modelinfo.setDescription(val.value()); if(isAnnotationPresent(cma, Imports.class, cl)) String[] tmp = getAnnotation(cma, Imports.class, cl).value(); Set<String> imports = (Set)getOrCreateSet("imports", toset); for(int i=0; i<tmp.length; i++) if(!featdone && isAnnotationPresent(cma, Features.class, cl)) Features fs = getAnnotation(cma, Features.class, cl); Feature[] tmp = fs.value(); featdone = fs.replace(); if(!propdone && isAnnotationPresent(cma, Properties.class, cl)) Properties val = (Properties)getAnnotation(cma, Properties.class, cl); NameValue[] vals = val.value();
while(cma!=null && !cma.equals(Object.class) && !cma.equals(getClass(MicroAgent.class, cl))) if(isAnnotationPresent(cma, Agent.class, cl)) Agent val = getAnnotation(cma, Agent.class, cl); Boolean susp = val.suspend().toBoolean(); Boolean mast = val.master().toBoolean(); if(isAnnotationPresent(iface, Service.class, cl)) if(isAnnotationPresent(cma, Description.class, cl) && modelinfo.getDescription()==null) Description val = getAnnotation(cma, Description.class, cl); modelinfo.setDescription(val.value()); if(isAnnotationPresent(cma, Imports.class, cl)) String[] tmp = getAnnotation(cma, Imports.class, cl).value(); Set<String> imports = (Set<String>)toset.get("imports"); if(imports==null) if(!propdone && isAnnotationPresent(cma, Properties.class, cl)) Properties val = (Properties)getAnnotation(cma, Properties.class, cl); NameValue[] vals = val.value(); propdone = val.replace(); if(!nfpropsdone && isAnnotationPresent(cma, NFProperties.class, cl))
Method m = an.getClass().getMethod(method.getName(), getClassArray(method.getParameterTypes(), cl)); Object ret = m.invoke(an, nargs); if(ret!=null && !isClassLoaderCompatible(ret.getClass(), cl)) ret = getProxyAnnotation((Annotation)ret, cl); Class<?> arclazz = MicroClassReader.this.getClass(ret.getClass().getComponentType(), cl); Object nret = Array.newInstance(arclazz, len); for(int i=0; i<len; i++) Array.set(nret, i, getProxyAnnotation((Annotation)Array.get(ret, i), cl));
/** * Load a model. * @param model The model (e.g. file name). * @param The imports (if any). * @return The loaded model. */ public MicroModel read(String model, String[] imports, ClassLoader classloader, IResourceIdentifier rid, IComponentIdentifier root) { // System.out.println("loading micro: "+model); String clname = model; // Note: it is ok if it is an absolute path with dots even it looks strange. // getMicroAgentClass will strip away parts until the model name is clear. // Hack! for extracting clear classname if(clname.endsWith(".class")) clname = model.substring(0, model.indexOf(".class")); clname = clname.replace('\\', '.'); clname = clname.replace('/', '.'); Class cma = getMicroAgentClass(clname, imports, classloader); return read(model, cma, classloader, rid, root); }
/** * Create a service implementation. */ protected ProvidedServiceImplementation createImplementation(Implementation impl) { return new ProvidedServiceImplementation(!impl.value().equals(Object.class)? impl.value(): null, impl.expression().length()>0? impl.expression(): null, impl.proxytype(), createBinding(impl.binding()), createUnparsedExpressions(impl.interceptors())); }
/** * */ public static Class<?>[] getClassArray(Class<?>[] clazzes, ClassLoader cl) { Class<?>[] ret = new Class[clazzes.length]; for(int i=0; i<clazzes.length; i++) { ret[i] = getClass(clazzes[i], cl); } return ret; }
/** * Create a service binding. */ protected RequiredServiceBinding createBinding(Binding bd) { return bd==null || Implementation.BINDING_NULL.equals(bd.name()) ? null: new RequiredServiceBinding(bd.name(), bd.componentname().length()==0? null: bd.componentname(), bd.componenttype().length()==0? null: bd.componenttype(), bd.dynamic(), bd.scope(), bd.create(), bd.recover(), createUnparsedExpressions(bd.interceptors()), bd.proxytype(), bd.creationinfo().type().length()>0? createComponentInstanceInfo(bd.creationinfo()): null); }
if(isClassLoaderCompatible(an.getClass(), cl)) for(int i=0; i<in.length; i++) nin[i] = getClass(in[i], cl);
/** * Create a required service info and add it to the map. */ protected RequiredServiceInfo createRequiredServiceInfo(RequiredService rs, ClassLoader cl) { RequiredServiceBinding binding = createBinding(rs.binding()); List<NFRPropertyInfo> nfprops = createNFRProperties(rs.nfprops()); for(NFRProperty prop: rs.nfprops()) { nfprops.add(new NFRPropertyInfo(prop.name(), new ClassInfo(prop.value().getName()), new MethodInfo(prop.methodname(), prop.methodparametertypes()))); } RequiredServiceInfo rsis = new RequiredServiceInfo(rs.name(), rs.type(), rs.multiple(), Object.class.equals(rs.multiplextype())? null: rs.multiplextype(), binding, nfprops, Arrays.asList(rs.tags())); return rsis; }
fillMicroModelFromAnnotations(ret, model, cma, classloader);
if(args.length>0) UnparsedExpression[] exps = createUnparsedExpressions(args); ret.setArguments(exps);
for(int k=0; k<binds.length; k++) bds[k] = createBinding(binds[k]);
Method m = an.getClass().getMethod(method.getName(), getClassArray(method.getParameterTypes(), cl)); Object ret = m.invoke(an, nargs); if(ret!=null && !isClassLoaderCompatible(ret.getClass(), cl)) ret = getProxyAnnotation((Annotation)ret, cl); Class<?> arclazz = MicroClassReader.getClass(ret.getClass().getComponentType(), cl); Object nret = Array.newInstance(arclazz, len); for(int i=0; i<len; i++) Array.set(nret, i, getProxyAnnotation((Annotation)Array.get(ret, i), cl));
/** * Load a model. * @param model The model (e.g. file name). * @param The imports (if any). * @return The loaded model. */ public MicroModel read(String model, String[] imports, ClassLoader classloader, IResourceIdentifier rid, IComponentIdentifier root, List<IComponentFeatureFactory> features) { // System.out.println("loading micro: "+model); String clname = model; // Note: it is ok if it is an absolute path with dots even it looks strange. // getMicroAgentClass will strip away parts until the model name is clear. // Hack! for extracting clear classname if(clname.endsWith(".class")) clname = model.substring(0, model.indexOf(".class")); clname = clname.replace('\\', '.'); clname = clname.replace('/', '.'); Class<?> cma = getMicroAgentClass(clname, imports, classloader); return read(model, cma, classloader, rid, root, features); }
/** * Create a service implementation. */ protected ProvidedServiceImplementation createImplementation(Implementation impl, Class<?> cma) { Class<?> cl = impl.value(); String exp = impl.expression().length()>0? impl.expression(): null; // If not specified (Object is default) or if user accidentally used pojo class -> ignore if(cl.equals(Object.class)) { cl = null; } else if(cl.equals(cma)) { cl = null; exp = "$pojoagent!=null? $pojoagent: $component"; System.out.println("Warning: ignoring implementation class because agent is service implementation"); } return new ProvidedServiceImplementation(cl, exp, impl.proxytype(), createBinding(impl.binding()), createUnparsedExpressions(impl.interceptors())); }
/** * */ public static Class<?>[] getClassArray(Class<?>[] clazzes, ClassLoader cl) { Class<?>[] ret = new Class[clazzes.length]; for(int i=0; i<clazzes.length; i++) { ret[i] = getClass(clazzes[i], cl); } return ret; }
/** * Create a service binding. */ protected RequiredServiceBinding createBinding(Binding bd) { return bd==null || Implementation.BINDING_NULL.equals(bd.name()) ? null: new RequiredServiceBinding(bd.name(), bd.componentname().length()==0? null: bd.componentname(), bd.componenttype().length()==0? null: bd.componenttype(), bd.dynamic(), bd.scope(), bd.create(), bd.recover(), createUnparsedExpressions(bd.interceptors()), bd.proxytype(), bd.creationinfo().type().length()>0? createComponentInstanceInfo(bd.creationinfo()): null); }