/** * create the callback proxy with cglib. use the same * JDKCallbackInvocationHandler as JDKProxyService. */ public <T> T createCallbackProxy(Class<T> interfaze, final List<? extends Invocable> wires) throws ProxyCreationException { ServiceReferenceImpl<T> callbackReference = new ServiceReferenceImpl(interfaze, wires.get(0), null); return callbackReference != null ? createCallbackProxy(callbackReference) : null; }
public <T> T createProxy(final Class<T> interfaze, Invocable invocable) throws ProxyCreationException { if (invocable instanceof RuntimeEndpoint) { Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(interfaze); enhancer.setCallback(new CglibMethodInterceptor<T>(interfaze, invocable)); Object proxy = enhancer.create(); return interfaze.cast(proxy); } ServiceReference<T> serviceReference = new ServiceReferenceImpl(interfaze, invocable, null); return createProxy(serviceReference); }
@SuppressWarnings("unchecked") public <B, R extends ServiceReference<B>> R cast(B target) throws IllegalArgumentException { if (isProxyClass(target.getClass())) { Factory factory = (Factory)target; Callback[] callbacks = factory.getCallbacks(); if (callbacks.length != 1 || !(callbacks[0] instanceof CglibMethodInterceptor)) { throw new IllegalArgumentException("The object is not a known proxy."); } CglibMethodInterceptor interceptor = (CglibMethodInterceptor)callbacks[0]; return (R)interceptor.invocationHandler.getCallableReference(); } else { throw new IllegalArgumentException("The object is not a known proxy."); } }
public JavaImplementationProviderFactory(ExtensionPointRegistry registry) { FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class); MessageFactory messageFactory = factories.getFactory(MessageFactory.class); UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class); InterfaceContractMapper interfaceContractMapper = utilities.getUtility(InterfaceContractMapper.class); ProxyFactoryExtensionPoint proxyFactories = registry.getExtensionPoint(ProxyFactoryExtensionPoint.class); try { proxyFactories.setClassProxyFactory(new CglibProxyFactory(messageFactory, interfaceContractMapper)); } catch (NoClassDefFoundError e) { logger.log(Level.WARNING, "Class-based proxy is not supported", e); } databindings = registry.getExtensionPoint(DataBindingExtensionPoint.class); propertyValueFactory = factories.getFactory(PropertyValueFactory.class); ContextFactoryExtensionPoint contextFactories = registry.getExtensionPoint(ContextFactoryExtensionPoint.class); componentContextFactory = contextFactories.getFactory(ComponentContextFactory.class); requestContextFactory = contextFactories.getFactory(RequestContextFactory.class); proxyFactory = ExtensibleProxyFactory.getInstance(registry); }