@Override public int hashCode() { return methodIdentifier.hashCode(); } }
@Override public Class<?> getProxyClass() { return proxyFactory.defineClass(); }
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; }
@Override public void configure(DeploymentPhaseContext context, ComponentConfiguration componentConfiguration, ViewDescription description, ViewConfiguration configuration) throws DeploymentUnitProcessingException { final StatefulComponentDescription statefulComponentDescription = (StatefulComponentDescription) componentConfiguration.getComponentDescription(); final Collection<StatefulRemoveMethod> removeMethods = statefulComponentDescription.getRemoveMethods(); if (removeMethods.isEmpty()) { return; } for (final Method viewMethod : configuration.getProxyFactory().getCachedMethods()) { final MethodIdentifier viewMethodIdentifier = MethodIdentifier.getIdentifierForMethod(viewMethod); for (final StatefulRemoveMethod removeMethod : removeMethods) { if (removeMethod.methodIdentifier.equals(viewMethodIdentifier)) { //we do not want to add this if it is the Ejb(Local)Object.remove() method, as that is handed elsewhere final boolean object = EJBObject.class.isAssignableFrom(configuration.getViewClass()) || EJBLocalObject.class.isAssignableFrom(configuration.getViewClass()); if (!object || !viewMethodIdentifier.getName().equals("remove") || viewMethodIdentifier.getParameterTypes().length != 0) { configuration.addViewInterceptor(viewMethod, new ImmediateInterceptorFactory(new StatefulRemoveInterceptor(removeMethod.retainIfException)), InterceptorOrder.View.SESSION_REMOVE_INTERCEPTOR); } break; } } } } });
public Set<MethodIdentifier> getTimerMethods() { final Set<MethodIdentifier> methods = new HashSet<MethodIdentifier>(); if (timeoutMethod != null) { methods.add(MethodIdentifier.getIdentifierForMethod(timeoutMethod)); } for (Method method : scheduleMethods.keySet()) { methods.add(MethodIdentifier.getIdentifierForMethod(method)); } return methods; }
@Override public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException { final SessionBeanComponentDescription componentDescription = (SessionBeanComponentDescription) componentConfiguration.getComponentDescription(); for (final Method method : configuration.getProxyFactory().getCachedMethods()) { //we need the component method to get the correct declaring class final Method componentMethod = ClassReflectionIndexUtil.findMethod(deploymentReflectionIndex, componentClass, method); if (componentMethod != null) { if (componentDescription.getAsynchronousClasses().contains(componentMethod.getDeclaringClass().getName())) { addAsyncInterceptor(configuration, method, isSecurityDomainKnown); configuration.addAsyncMethod(method); } else { MethodIdentifier id = MethodIdentifier.getIdentifierForMethod(method); if (componentDescription.getAsynchronousMethods().contains(id)) { addAsyncInterceptor(configuration, method, isSecurityDomainKnown); configuration.addAsyncMethod(method); } } } } } });
private MethodIdentifier getMethodIdentifier(Type[] args, MethodInfo methodInfo){ if (args.length == 0) { return MethodIdentifier.getIdentifier(Void.TYPE, methodInfo.name()); } else { return MethodIdentifier.getIdentifier(methodInfo.returnType().name().toString(), methodInfo.name(), InvocationContext.class.getName()); } } }
/** * 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); } }
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); } } }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; StatefulRemoveMethod that = (StatefulRemoveMethod) o; if (!methodIdentifier.equals(that.methodIdentifier)) return false; return true; }
public int getTransactionTimeout(final MethodIntf methodIntf, final Method method) { return getTransactionTimeout(methodIntf, MethodIdentifier.getIdentifierForMethod(method)); }
private MethodIdentifier getMethodIdentifier(final AnnotationTarget target) { final MethodInfo methodInfo = MethodInfo.class.cast(target); final String[] args = new String[methodInfo.args().length]; for (int i = 0; i < methodInfo.args().length; i++) { args[i] = methodInfo.args()[i].name().toString(); } return MethodIdentifier.getIdentifier(methodInfo.returnType().name().toString(), methodInfo.name(), args); }
/** * 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); } }
@Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; final MethodTransactionAttributeKey that = (MethodTransactionAttributeKey) o; if (!methodIdentifier.equals(that.methodIdentifier)) return false; if (methodIntf != that.methodIntf) return false; return true; }
@Override public int hashCode() { int result = methodIntf.hashCode(); result = 31 * result + methodIdentifier.hashCode(); return result; } }
public TransactionAttributeType getTransactionAttributeType(final MethodIntf methodIntf, final Method method) { return getTransactionAttributeType(methodIntf, MethodIdentifier.getIdentifierForMethod(method)); }
@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); } });
protected void handleAnnotations(final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final StatefulComponentDescription componentConfiguration) throws DeploymentUnitProcessingException { final RuntimeAnnotationInformation<Boolean> removeMethods = MethodAnnotationAggregator.runtimeAnnotationInformation(componentClass, applicationClasses, deploymentReflectionIndex, Remove.class); for (Map.Entry<Method, List<Boolean>> entry : removeMethods.getMethodAnnotations().entrySet()) { if (!entry.getValue().isEmpty()) { final Boolean retainIfException = entry.getValue().get(0); final MethodIdentifier removeMethodIdentifier = MethodIdentifier.getIdentifierForMethod(entry.getKey()); componentConfiguration.addRemoveMethod(removeMethodIdentifier, retainIfException); } } }
@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); } });
@Override protected void handleAnnotations(final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final SessionBeanComponentDescription description) throws DeploymentUnitProcessingException { final RuntimeAnnotationInformation<Boolean> data = MethodAnnotationAggregator.runtimeAnnotationInformation(componentClass, applicationClasses, deploymentReflectionIndex, Asynchronous.class); for (final Map.Entry<String, List<Boolean>> entry : data.getClassAnnotations().entrySet()) { if (!entry.getValue().isEmpty()) { description.addAsynchronousClass(entry.getKey()); } } for (final Map.Entry<Method, List<Boolean>> entry : data.getMethodAnnotations().entrySet()) { if (!entry.getValue().isEmpty()) { description.addAsynchronousMethod(MethodIdentifier.getIdentifierForMethod(entry.getKey())); } } }