/** * Get the parametertypes as classes. * @return the parametertypes. */ public Class<?>[] getParameterTypes(ClassLoader cl) { Class<?>[] typeclasses = new Class<?>[parametertypes.length]; for (int i = 0; i < parametertypes.length; ++i) { typeclasses[i] = parametertypes[i].getType(cl); } return typeclasses; }
public void customResultAvailable(ClassLoader cl) { ret.setResult(sid.getServiceType().getType(cl)); } });
/** * Create a required service proxy. */ protected static <T> T createRequiredProxy(IInternalAccess component, T ser, ClassInfo type) { return createRequiredProxy(component, ser, type.getType(component.getClassLoader())); }
/** * Create a required service proxies. */ protected static <T> Collection<T> createRequiredProxies(IInternalAccess component, Collection<T> sers, ClassInfo type) { return createRequiredProxies(component, sers, type.getType(component.getClassLoader())); }
/** * Create a new invocation handler. */ public MultiServiceInvocationHandler(IInternalAccess agent, String reqname, Class<?> muxservicetype) { this.agent = agent; this.reqname = reqname; RequiredServiceInfo reqs = agent.getServiceContainer().getRequiredServiceInfo(reqname); if(reqs==null) throw new RuntimeException("Required service not found: "+reqname); this.servicetype = reqs.getType().getType(agent.getClassLoader()); this.muxservicetype = muxservicetype; }
/** * Factory method constructor for instance level. */ public MicroPojoComponentFeature(IInternalAccess component, ComponentCreationInfo cinfo) { super(component, cinfo); try { // Create the pojo agent MicroModel model = (MicroModel)getComponent().getModel().getRawModel(); this.pojoagent = model.getPojoClass().getType(model.getClassloader()).newInstance(); } catch(Exception e) { throw new RuntimeException(e); } }
/** * Create a service implementation from description. */ protected Object createServiceImplementation(ProvidedServiceInfo info, IModelInfo model) { // Support special case that BDI should implement provided service with plans. Object ret = null; ProvidedServiceImplementation impl = info.getImplementation(); if(impl!=null && impl.getClazz()!=null && impl.getClazz().getType(getClassLoader()).equals(BDIAgent.class)) { Class<?> iface = info.getType().getType(getClassLoader()); ret = Proxy.newProxyInstance(getClassLoader(), new Class[]{iface}, new BDIServiceInvocationHandler(this, iface)); } else { ret = super.createServiceImplementation(info, model); } return ret; }
/** * Create a new invocation handler. */ public MultiServiceInvocationHandler(IInternalAccess agent, String reqname, Class<?> muxservicetype) { this.agent = agent; this.reqname = reqname; RequiredServiceInfo reqs = agent.getComponentFeature(IRequiredServicesFeature.class).getRequiredServiceInfo(reqname); if(reqs==null) throw new RuntimeException("Required service not found: "+reqname); this.servicetype = reqs.getType().getType(agent.getClassLoader(), agent.getModel().getAllImports()); this.muxservicetype = muxservicetype; }
/** * Get the class of a value. */ protected Class<?> getClazz() { MParameter mparam = (MParameter)getModelElement(); return mparam.getClazz().getType(agent.getClassLoader(), agent.getModel().getAllImports()); }
/** * */ public MethodInfo getAbortedMethod(ClassLoader cl) { if(clazz!=null) { if(abortedmethod==null && !MI_NOTFOUND.equals(abortedmethod)) { synchronized(this) { if(abortedmethod==null && !MI_NOTFOUND.equals(abortedmethod)) { Class<?> body = clazz.getType(cl); abortedmethod = getMethod(body, PlanAborted.class, cl); if(abortedmethod==null) abortedmethod = MI_NOTFOUND; } } } } return MI_NOTFOUND.equals(abortedmethod)? null: abortedmethod; }
/** * */ public MethodInfo getPreconditionMethod(ClassLoader cl) { if(clazz!=null) { if(preconditionmethod==null && !MI_NOTFOUND.equals(preconditionmethod)) { synchronized(this) { if(preconditionmethod==null && !MI_NOTFOUND.equals(preconditionmethod)) { Class<?> body = clazz.getType(cl); preconditionmethod = getMethod(body, PlanPrecondition.class, cl); if(preconditionmethod==null) preconditionmethod = MI_NOTFOUND; } } } } return MI_NOTFOUND.equals(preconditionmethod)? null: preconditionmethod; }
/** * */ public MethodInfo getAbortedMethod(ClassLoader cl) { if(clazz!=null) { if(abortedmethod==null && !MI_NOTFOUND.equals(abortedmethod)) { synchronized(this) { if(abortedmethod==null && !MI_NOTFOUND.equals(abortedmethod)) { Class<?> body = clazz.getType(cl); abortedmethod = getMethod(body, PlanAborted.class); if(abortedmethod==null) abortedmethod = MI_NOTFOUND; } } } } return MI_NOTFOUND.equals(abortedmethod)? null: abortedmethod; }
/** * Add a value to a parameter set. * @param value The new value. */ public void addValue(Object value) { testWriteOK((MParameter)getModelElement()); if(value!=null && getModelElement()!=null) { Class<?> clazz = ((MParameter)getModelElement()).getClazz().getType(getAgent().getClassLoader(), getAgent().getModel().getAllImports()); if(!SReflect.isSupertype(clazz, value.getClass())) { throw new IllegalArgumentException("Incompatible value for parameter set "+getName()+": "+value); } value = SReflect.convertWrappedValue(value, clazz); } internalGetValues().add(value); }
/** * Get or generate a proxy class. */ protected Class<?> getProxyClass(IServiceIdentifier serviceid, ClassLoader classloader, Class<?> baseclass, Map<String, Object> mapprops) throws Exception { Class<?> iface = serviceid.getServiceType().getType(classloader); Class<?> ret = proxyclasses.get(new Tuple2<Class<?>, Class<?>>(iface, baseclass)); if(ret==null) { List<RestMethodInfo> rmis = generator.generateRestMethodInfos(serviceid, classloader, baseclass, mapprops); ret = createProxyClass(serviceid, classloader, baseclass, mapprops, rmis); proxyclasses.put(new Tuple2<Class<?>, Class<?>>(iface, baseclass), ret); } return ret; }
/** * Set the value without check. */ protected void internalSetValue(Object value) { if(value!=null && getModelElement()!=null) { Class<?> clazz = ((MParameter)getModelElement()).getClazz().getType(getAgent().getClassLoader(), getAgent().getModel().getAllImports()); if(!SReflect.isSupertype(clazz, value.getClass())) { throw new IllegalArgumentException("Incompatible value for parameter "+getName()+": "+value); } value = SReflect.convertWrappedValue(value, clazz); } Object oldvalue = this.value; this.value = value; publisher.entryChanged(oldvalue, value, -1); }
/** * Static method for creating a delegation service proxy for * provided service that is not offered by the component itself. */ public static IInternalService createDelegationProvidedServiceProxy(IInternalAccess ia, IComponentAdapter adapter, IServiceIdentifier sid, RequiredServiceInfo info, RequiredServiceBinding binding, ClassLoader classloader, boolean realtime) { BasicServiceInvocationHandler handler = new BasicServiceInvocationHandler(ia, sid, adapter.getLogger(), realtime, ia.getComponentDescription().getCause(), false); handler.addFirstServiceInterceptor(new MethodInvocationInterceptor()); handler.addFirstServiceInterceptor(new DelegationInterceptor(ia, info, binding, null, sid, realtime)); handler.addFirstServiceInterceptor(new DecouplingReturnInterceptor(/*ea, null,*/)); // return (IInternalService)Proxy.newProxyInstance(ea.getModel().getClassLoader(), new Class[]{IInternalService.class, sid.getServiceType()}, handler); return (IInternalService)Proxy.newProxyInstance(classloader, new Class[]{IInternalService.class, info.getType().getType(classloader)}, handler); //sid.getServiceType() }
public Object postProcess(IContext context, Object object) { ApplicationModelInfo mi = (ApplicationModelInfo)object; if(mi.getExtensionTypes().length>0) { boolean found = false; for(ProvidedServiceInfo pi: mi.getProvidedServices()) { if(IEnvironmentService.class.equals(pi.getType().getType(context.getClassLoader(), mi.getAllImports()))) { found = true; break; } } if(!found) { mi.addProvidedService(new ProvidedServiceInfo(null, IEnvironmentService.class, new ProvidedServiceImplementation(EnvironmentService.class, null, null, null, null), null, null, null)); } } return null; }
/** * Get or generate a proxy class. */ protected Class<?> getProxyClass(IService service, ClassLoader classloader, Class<?> baseclass, Map<String, Object> mapprops) throws Exception { Class<?> iface = service.getServiceIdentifier().getServiceType().getType(classloader); Class<?> ret = proxyclasses.get(new Tuple2<Class<?>, Class<?>>(iface, baseclass)); if(ret==null) { List<RestMethodInfo> rmis = generator.generateRestMethodInfos(service, classloader, baseclass, mapprops); ret = createProxyClass(service, classloader, baseclass, mapprops, rmis); proxyclasses.put(new Tuple2<Class<?>, Class<?>>(iface, baseclass), ret); } return ret; }
/** * Static method for creating a delegation service proxy for * provided service that is not offered by the component itself. */ public static IInternalService createDelegationProvidedServiceProxy(IInternalAccess ia, IServiceIdentifier sid, RequiredServiceInfo info, RequiredServiceBinding binding, ClassLoader classloader, boolean realtime) { BasicServiceInvocationHandler handler = new BasicServiceInvocationHandler(ia, sid, ia.getLogger(), realtime, ia.getComponentDescription().getCause(), false); handler.addFirstServiceInterceptor(new MethodInvocationInterceptor()); handler.addFirstServiceInterceptor(new DelegationInterceptor(ia, info, binding, null, sid, realtime)); handler.addFirstServiceInterceptor(new DecouplingReturnInterceptor(/*ea, null,*/)); // return (IInternalService)Proxy.newProxyInstance(ea.getModel().getClassLoader(), new Class[]{IInternalService.class, sid.getServiceType()}, handler); return (IInternalService)Proxy.newProxyInstance(classloader, new Class[]{IInternalService.class, info.getType().getType(classloader, ia.getModel().getAllImports())}, handler); //sid.getServiceType() }
/** * Get a required service. * @return The service. */ public <T> IFuture<T> getRequiredService(RequiredServiceInfo info, RequiredServiceBinding binding, boolean rebind, IRemoteFilter<T> filter) { if(shutdowned) { return new Future<T>(new ComponentTerminatedException(id)); } if(info.getMultiplexType()!=null) { T ms = getMultiService(info.getName(), (Class<T>)info.getMultiplexType().getType(instance.getClassLoader())); return new Future<T>(ms); } IFuture<T> fut = super.getRequiredService(info, binding, rebind, filter); return FutureFunctionality.getDelegationFuture(fut, new ComponentFutureFunctionality(instance.getExternalAccess(), adapter)); }