config.setProxyName(initialContextClassName + "$$$$Proxy" + PROXY_ID.incrementAndGet()); config.setProtectionDomain(context.getClass().getProtectionDomain()); ProxyFactory<?> factory = new ProxyFactory<Object>(config); return (Context) factory.newInstance(new CachedContext(context));
/** * Adds an interceptor factory to all methods of a view * * @param interceptorFactory The factory to add * @param priority The interceptor order */ public void addViewInterceptor(InterceptorFactory interceptorFactory, int priority) { for (Method method : proxyFactory.getCachedMethods()) { addViewInterceptor(method, interceptorFactory, priority); } }
@Override public Class<?> getProxyClass() { return proxyFactory.defineClass(); }
private MessageEndpoint createEndpoint(ProxyFactory<Object> factory, MessageEndpointInvocationHandler handler) { try { return (MessageEndpoint) factory.newInstance(handler); } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } }
public JBossMessageEndpointFactory(final ClassLoader classLoader, final MessageEndpointService<?> service, final Class<Object> ejbClass, final Class<?> messageListenerInterface) { // todo: generics bug; only Object.class is a Class<Object>. Everything else is Class<? extends Object> aka Class<?> this.service = service; final ProxyConfiguration<Object> configuration = new ProxyConfiguration<Object>() .setClassLoader(classLoader) .setProxyName(ejbClass.getName() + "$$$endpoint" + PROXY_ID.incrementAndGet()) .setSuperClass(ejbClass) .setProtectionDomain(ejbClass.getProtectionDomain()) .addAdditionalInterface(MessageEndpoint.class) .addAdditionalInterface(messageListenerInterface); this.factory = new ProxyFactory<Object>(configuration); this.endpointClass = ejbClass; }
/** {@inheritDoc} */ @Override protected void generateClass() { classFile.addField(AccessFlag.PRIVATE, INVOCATION_HANDLER_FIELD, InvocationHandler.class); classFile.addField(AccessFlag.PRIVATE, CONSTRUCTED_GUARD, "Z"); if (serializableProxyClass != null) { createWriteReplace(); } MethodBodyCreator creator = getDefaultMethodOverride(); overrideAllMethods(creator); for (Class<?> iface : additionalInterfaces) { addInterface(creator, iface); } overrideToString(creator); overrideEquals(creator); overrideHashcode(creator); createConstructorDelegates(new ProxyConstructorBodyCreator()); finalizeStaticConstructor(); for (Annotation annotation : this.getSuperClass().getDeclaredAnnotations()) { classFile.getRuntimeVisibleAnnotationsAttribute().addAnnotation(annotation); } }
/** * Create a new proxy, initialising it with the given invocation handler. * * @param handler the invocation handler to use * @return the new proxy instance * @throws IllegalAccessException if the constructor is not accessible * @throws InstantiationException if instantiation failed due to an exception */ public T newInstance(InvocationHandler handler) throws InstantiationException, IllegalAccessException { T ret = newInstance(); setInvocationHandler(ret, handler); return ret; }
final ComponentClientInstance instance = new ComponentClientInstance(); try { proxy = proxyFactory.newInstance(new ProxyInvocationHandler(clientInterceptors, instance, componentView)); } catch (InstantiationException e) { InstantiationError error = new InstantiationError(e.getMessage());
proxyConfiguration.setSuperClass(Object.class); proxyConfiguration.addAdditionalInterface(viewClass); viewConfiguration = view.createViewConfiguration(viewClass, configuration, new ProxyFactory(proxyConfiguration)); } else { proxyConfiguration.setSuperClass(viewClass); viewConfiguration = view.createViewConfiguration(viewClass, configuration, new ProxyFactory(proxyConfiguration));
/** * Adds a client interceptor factory to all methods of a view * * @param interceptorFactory The factory to add * @param priority The interceptor order */ public void addClientInterceptor(InterceptorFactory interceptorFactory, int priority) { for (Method method : proxyFactory.getCachedMethods()) { addClientInterceptor(method, interceptorFactory, priority); } }
config.setProxyName(initialContextClassName + "$$$$Proxy" + PROXY_ID.incrementAndGet()); config.setProtectionDomain(context.getClass().getProtectionDomain()); ProxyFactory<?> factory = new ProxyFactory<Object>(config); return (Context) factory.newInstance(new CachedContext(context));
proxy = proxyFactory.newInstance(new ProxyInvocationHandler(clientEntryPoints, component, componentView)); } catch (InstantiationException e) { InstantiationError error = new InstantiationError(e.getMessage());
proxyConfiguration.setSuperClass(Object.class); proxyConfiguration.addAdditionalInterface(viewClass); viewConfiguration = view.createViewConfiguration(viewClass, configuration, new ProxyFactory(proxyConfiguration)); } else { proxyConfiguration.setSuperClass(viewClass); viewConfiguration = view.createViewConfiguration(viewClass, configuration, new ProxyFactory(proxyConfiguration));
@Override public Class<?> getProxyClass() { return proxyFactory.defineClass(); }
@Override public void configure(DeploymentPhaseContext context, ComponentConfiguration componentConfiguration, ViewDescription description, ViewConfiguration configuration) throws DeploymentUnitProcessingException { //add equals/hashCode interceptor for (Method method : configuration.getProxyFactory().getCachedMethods()) { if ((method.getName().equals("hashCode") && method.getParameterTypes().length == 0) || method.getName().equals("equals") && method.getParameterTypes().length == 1 && method.getParameterTypes()[0] == Object.class) { configuration.addClientInterceptor(method, ComponentTypeIdentityInterceptorFactory.INSTANCE, InterceptorOrder.Client.EJB_EQUALS_HASHCODE); } } // add the singleton component instance associating interceptor configuration.addViewInterceptor(SingletonComponentInstanceAssociationInterceptor.FACTORY, InterceptorOrder.View.ASSOCIATING_INTERCEPTOR); } });
config.setProxyName(initialContextClassName + "$$$$Proxy" + PROXY_ID.incrementAndGet()); config.setProtectionDomain(context.getClass().getProtectionDomain()); ProxyFactory<?> factory = new ProxyFactory<Object>(config); return (Context) factory.newInstance(new CachedContext(context));
final ComponentClientInstance instance = new ComponentClientInstance(); try { proxy = proxyFactory.newInstance(new ProxyInvocationHandler(clientInterceptors, instance, componentView)); } catch (InstantiationException e) { InstantiationError error = new InstantiationError(e.getMessage());
proxyConfiguration.setSuperClass(Object.class); proxyConfiguration.addAdditionalInterface(viewClass); viewConfiguration = view.createViewConfiguration(viewClass, configuration, new ProxyFactory(proxyConfiguration)); } else { proxyConfiguration.setSuperClass(viewClass); viewConfiguration = view.createViewConfiguration(viewClass, configuration, new ProxyFactory(proxyConfiguration));
@Override public Class<?> getProxyClass() { return proxyFactory.defineClass(); }
@Override public void configure(DeploymentPhaseContext context, ComponentConfiguration componentConfiguration, ViewDescription description, ViewConfiguration configuration) throws DeploymentUnitProcessingException { //add equals/hashCode interceptor //add equals/hashCode interceptor for (Method method : configuration.getProxyFactory().getCachedMethods()) { if ((method.getName().equals("hashCode") && method.getParameterTypes().length == 0) || method.getName().equals("equals") && method.getParameterTypes().length == 1 && method.getParameterTypes()[0] == Object.class) { configuration.addClientInterceptor(method, ComponentTypeIdentityInterceptorFactory.INSTANCE, InterceptorOrder.Client.EJB_EQUALS_HASHCODE); } } // add the stateless component instance associating interceptor configuration.addViewInterceptor(StatelessComponentInstanceAssociatingFactory.instance(), InterceptorOrder.View.ASSOCIATING_INTERCEPTOR); } });