public <CB> CB getCallback() { ServiceReference<CB> cb = getCallbackReference(); if (cb == null) { return null; } return cb.getService(); }
/** * @see org.ow2.frascati.tinfi.control.component.ComponentContextMixin#cast(B) */ public <B> ServiceReference<B> cast(B target) throws IllegalArgumentException { if (!(target instanceof ServiceReference<?> )) { String msg = "Not a reference: " + target; throw new IllegalArgumentException(msg); } ServiceReference<?> ci = ((ServiceReference<?> )(target)); Class<?> businessInterface = ci.getBusinessInterface(); Object service = ci.getService(); String signature = businessInterface.getName(); String clname = signature + "FcSR"; try { Class<?> cl = Class.forName(clname); Constructor<?> [] ctrs = cl.getConstructors(); Constructor<?> ctr = ctrs[0]; Object sr = ctr.newInstance(businessInterface ,service); @SuppressWarnings(value = "unchecked") ServiceReference<B> ret = ((ServiceReference<B> )(sr)); return ret; } catch (Exception e) { throw new IllegalArgumentException(e); } }
public JDKInvocationHandler(MessageFactory messageFactory, ServiceReference<?> callableReference) { this.messageFactory = messageFactory; this.callableReference = (ServiceReferenceExt<?>)callableReference; if (callableReference != null) { this.businessInterface = callableReference.getBusinessInterface(); this.source = (RuntimeEndpointReference) this.callableReference.getEndpointReference(); } }
/** * create the proxy with cglib. use the same JDKInvocationHandler as * JDKProxyService. */ public <T> T createProxy(ServiceReference<T> callableReference) throws ProxyCreationException { Enhancer enhancer = new Enhancer(); Class<T> interfaze = callableReference.getBusinessInterface(); enhancer.setSuperclass(interfaze); enhancer.setCallback(new CglibMethodInterceptor<T>(callableReference)); Object proxy = enhancer.create(); ((ServiceReferenceImpl)callableReference).setProxy(proxy); return interfaze.cast(proxy); }
public <B> B getService(Class<B> businessInterface, String referenceName) throws IllegalArgumentException { B service = null; ServiceReference<B> serviceRef = getServiceReference(businessInterface, referenceName); if (serviceRef != null) { service = serviceRef.getService(); } return service; }
public <B> ServiceReference<B> cast( B target ) throws IllegalArgumentException { if( !(target instanceof ServiceReference<?>) ) { String msg = "Not a reference: "+target; throw new IllegalArgumentException(msg); } ServiceReference<?> ci = (ServiceReference<?>) target; Class<?> businessInterface = ci.getBusinessInterface(); Object service = ci.getService(); // Create a ServiceReference String signature = businessInterface.getName(); String clname = signature+"FcSR"; try { Class<?> cl = Class.forName(clname); Constructor<?>[] ctrs = cl.getConstructors(); Constructor<?> ctr = ctrs[0]; Object sr = ctr.newInstance(businessInterface,service); @SuppressWarnings("unchecked") ServiceReference<B> ret = (ServiceReference<B>) sr; return ret; } catch (Exception e) { throw new IllegalArgumentException(e); } }
/** * create the callback proxy with cglib. use the same * JDKCallbackInvocationHandler as JDKProxyService. */ public <T> T createCallbackProxy(ServiceReference<T> callbackReference) throws ProxyCreationException { Enhancer enhancer = new Enhancer(); Class<T> interfaze = callbackReference.getBusinessInterface(); enhancer.setSuperclass(interfaze); enhancer.setCallback(new CglibMethodInterceptor<T>(callbackReference)); Object object = enhancer.create(); T proxy = interfaze.cast(object); ((ServiceReferenceExt<T>)callbackReference).setProxy(proxy); return proxy; }
/** * @see ComponentContext#getServices(Class<B>, String) */ public <B> Collection<B> getServices(Class<B> businessInterface, String referenceName) { ArrayList<B> services = new ArrayList<B>(); Collection<ServiceReference<B>> serviceRefs = getServiceReferences(businessInterface, referenceName); for (ServiceReference<B> serviceRef : serviceRefs) { services.add(serviceRef.getService()); } return services; }
/** * @see org.ow2.frascati.tinfi.control.component.ComponentContextMixin#cast(B) */ public <B> org.oasisopen.sca.ServiceReference<B> cast(B target) throws java.lang.IllegalArgumentException { if (!(target instanceof org.oasisopen.sca.ServiceReference<?>)) { java.lang.String msg = "Not a reference: " + target; throw new java.lang.IllegalArgumentException(msg); } org.oasisopen.sca.ServiceReference<?> ci = ((org.oasisopen.sca.ServiceReference<?>) (target)); java.lang.Class<?> businessInterface = ci.getBusinessInterface(); java.lang.Object service = ci.getService(); java.lang.String signature = businessInterface.getName(); java.lang.String clname = signature + "FcSR"; try { java.lang.Class<?> cl = java.lang.Class.forName(clname); java.lang.reflect.Constructor<?>[] ctrs = cl.getConstructors(); java.lang.reflect.Constructor<?> ctr = ctrs[0]; java.lang.Object sr = ctr.newInstance(businessInterface, service); @java.lang.SuppressWarnings("unchecked") org.oasisopen.sca.ServiceReference<B> ret = ((org.oasisopen.sca.ServiceReference<B>) (sr)); return ret; } catch (java.lang.Exception e) { throw new java.lang.IllegalArgumentException(e); } }
public <T> T createCallbackProxy(ServiceReference<T> callbackReference) throws ProxyCreationException { assert callbackReference != null; final Class<T> interfaze = callbackReference.getBusinessInterface(); InvocationHandler handler = new JDKCallbackInvocationHandler(messageFactory, callbackReference); ClassLoader cl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { public ClassLoader run() { return interfaze.getClassLoader(); } }); T proxy = interfaze.cast(newProxyInstance(cl, new Class[] {interfaze}, handler)); ((ServiceReferenceExt<T>)callbackReference).setProxy(proxy); return proxy; }
public <CB> CB getCallback() { CallbackManager cm = CallbackManager.get(); ServiceReference<CB> cr = (ServiceReference<CB>) cm.peek(); CB service = cr.getService(); return service; }
public <T> T createProxy(ServiceReference<T> callableReference) throws ProxyCreationException { assert callableReference != null; final Class<T> interfaze = callableReference.getBusinessInterface(); InvocationHandler handler; // TUSCANY-3659 - Always install a asynch handler regardless of whether ref is sync or async // needs tidying // if (isAsync(interfaze)) { handler = new AsyncJDKInvocationHandler(registry, messageFactory, callableReference); // } else { // handler = new JDKInvocationHandler(messageFactory, callableReference); // } // Allow privileged access to class loader. Requires RuntimePermission in security policy. ClassLoader cl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { public ClassLoader run() { return interfaze.getClassLoader(); } }); T proxy = interfaze.cast(newProxyInstance(cl, new Class[] {interfaze}, handler)); ((ServiceReferenceExt<T>)callableReference).setProxy(proxy); return proxy; }
public <B> B getService(Class<B> businessInterface, String serviceName) { ServiceReference<B> serviceReference = getServiceReference(businessInterface, serviceName); if (serviceReference == null) { throw new ServiceRuntimeException("Service not found: " + serviceName); } return serviceReference.getService(); }
public <T> T createCallbackProxy(ServiceReference<T> callbackReference) throws ProxyCreationException { ProxyFactory interfaceFactory = proxyFactories.getInterfaceProxyFactory(); ProxyFactory classFactory = proxyFactories.getClassProxyFactory(); if (callbackReference.getBusinessInterface().isInterface()) { return interfaceFactory.createCallbackProxy(callbackReference); } else { return classFactory.createCallbackProxy(callbackReference); } }
public <B> B getService(Class<B> businessInterface, String serviceName) { ServiceReference<B> serviceReference = getServiceReference(businessInterface, serviceName); if (serviceReference == null) { throw new ServiceRuntimeException("Service not found: " + serviceName); } return serviceReference.getService(); }
public <T> T createProxy(ServiceReference<T> callableReference) throws ProxyCreationException { ProxyFactory interfaceFactory = proxyFactories.getInterfaceProxyFactory(); ProxyFactory classFactory = proxyFactories.getClassProxyFactory(); if (callableReference.getBusinessInterface().isInterface()) { return interfaceFactory.createProxy(callableReference); } else { return classFactory.createProxy(callableReference); } }
@Override public int doEndTag() throws JspException { ServletContext servletContext = pageContext.getServletContext(); RuntimeComponent component = (RuntimeComponent)servletContext.getAttribute("org.apache.tuscany.sca.implementation.web.RuntimeComponent"); if (component == null) { throw new JspException("No Web component found. Is there an <implementation.web> missing?"); } Class<?> typeClass; try { typeClass = Class.forName(type, true, Thread.currentThread().getContextClassLoader()); } catch (ClassNotFoundException e) { throw new JspException("Reference '" + name + "' type class not found: " + type); } try { setInterfaceContract(component, typeClass); } catch (InvalidInterfaceException e) { throw new JspException("Exception creating interface", e); } ServiceReference<?> sr = component.getComponentContext().getServiceReference(typeClass, name); if (sr == null) { throw new JspException("Reference '" + name + "' undefined"); } pageContext.setAttribute(name, sr.getService(), scope); return EVAL_PAGE; }
if( ! cm.isEmpty() ) { ServiceReference<?> cr = cm.peek(); Class<?> businessItf = cr.getBusinessInterface();
@Override public int doEndTag() throws JspException { ServletContext servletContext = pageContext.getServletContext(); RuntimeComponent component = (RuntimeComponent)servletContext.getAttribute("org.apache.tuscany.sca.implementation.web.RuntimeComponent"); if (component == null) { throw new JspException("No Web component found. Is there an <implementation.web> missing?"); } Class<?> typeClass; try { typeClass = Class.forName(type, true, Thread.currentThread().getContextClassLoader()); } catch (ClassNotFoundException e) { throw new JspException("Reference '" + name + "' type class not found: " + type); } try { setInterfaceContract(component, typeClass); } catch (InvalidInterfaceException e) { throw new JspException("Exception creating interface", e); } ServiceReference<?> sr = component.getComponentContext().getServiceReference(typeClass, name); if (sr == null) { throw new JspException("Reference '" + name + "' undefined"); } pageContext.setAttribute(name, sr.getService(), scope); return EVAL_PAGE; }
public static <T> T getReference(String name, Class<T> type, ServletContext sc) { ServiceReference<T> sr = getComponentContext(sc).getServiceReference(type, name); if (sr == null) { throw new ServiceRuntimeException("Reference '" + name + "' undefined"); } return sr.getService(); }