private InterceptorBindings getInterceptorBindings(final String ejbName, final BeanManagerImpl manager) { InterceptorBindings retVal = null; if (ejbName != null) { retVal = interceptorSupport.getInterceptorBindings(ejbName, manager); } else { // This is a managed bean SlimAnnotatedType<?> type = (SlimAnnotatedType<?>) manager.createAnnotatedType(componentClass); if (!manager.getInterceptorModelRegistry().containsKey(type)) { EnhancedAnnotatedType<?> enhancedType = manager.getServices().get(ClassTransformer.class).getEnhancedAnnotatedType(type); InterceptionModelInitializer.of(manager, enhancedType, null).init(); } InterceptionModel model = manager.getInterceptorModelRegistry().get(type); if (model != null) { retVal = new InterceptorBindingsAdapter(manager.getInterceptorModelRegistry().get(type)); } } return retVal != null ? retVal : NullInterceptorBindings.INSTANCE; }
private void buildInterceptionModel(EnhancedAnnotatedType<T> annotatedType, AbstractInstantiator<T> instantiator) { new InterceptionModelInitializer<>(beanManager, annotatedType, annotatedType.getDeclaredEnhancedConstructor( instantiator.getConstructorInjectionPoint().getSignature()), getBean()).init(); }
this.cache = ComputingCacheBuilder.newBuilder().<Key, Optional<InterceptionFactoryData<?>>> build((key) -> { ClassTransformer classTransformer = beanManager.getServices().get(ClassTransformer.class); UnbackedAnnotatedType<?> slimAnnotatedType = classTransformer.getUnbackedAnnotatedType(key.annotatedType, beanManager.getId(), id); new InterceptionModelInitializer(beanManager, enhancedAnnotatedType, Beans.getBeanConstructor(enhancedAnnotatedType), null).init(); InterceptionModel interceptionModel = beanManager.getInterceptorModelRegistry().get(slimAnnotatedType); if (!interceptionModel.getInterceptors(InterceptionType.AROUND_INVOKE, method.getJavaMember()).isEmpty()) { interceptedMethodSignatures.add(MethodSignatureImpl.of(method)); InterceptedProxyFactory<?> proxyFactory = new InterceptedProxyFactory<>(beanManager.getContextId(), enhancedAnnotatedType.getJavaClass(), Collections.singleton(enhancedAnnotatedType.getJavaClass()), enhancedMethodSignatures, interceptedMethodSignatures, "" + idx);
public void registerCdiInterceptorsForMessageDrivenBeans(BeanDeployerEnvironment environment, BeanManagerImpl manager) { for (InternalEjbDescriptor<?> descriptor : getEjbDescriptors()) { if (descriptor.isMessageDriven()) { EnhancedAnnotatedType<?> type = manager.getServices().getRequired(ClassTransformer.class).getEnhancedAnnotatedType(descriptor.getBeanClass(), manager.getId()); if (!manager.getInterceptorModelRegistry().containsKey(type.slim())) { InterceptionModelInitializer.of(manager, type, null).init(); } InterceptionModel model = manager.getInterceptorModelRegistry().get(type.slim()); if (model != null) { ejbServices.registerInterceptors(descriptor.delegate(), new InterceptorBindingsAdapter(model)); } } } }
public void init() { initTargetClassInterceptors(); businessMethods = Beans.getInterceptableMethods(annotatedType); initEjbInterceptors(); initCdiInterceptors(); InterceptionModel interceptionModel = builder.build(); if (interceptionModel.getAllInterceptors().size() > 0 || hasSerializationOrInvocationInterceptorMethods) { if (annotatedType.isFinal()) { throw BeanLogger.LOG.finalBeanClassWithInterceptorsNotAllowed(annotatedType.getJavaClass()); } if (Reflections.isPrivate(constructor.getJavaMember())) { throw new DeploymentException(ValidatorLogger.LOG.notProxyablePrivateConstructor(annotatedType.getJavaClass().getName(), constructor, annotatedType.getJavaClass())); } manager.getInterceptorModelRegistry().put(annotatedType.slim(), interceptionModel); } }
private void initMethodDeclaredEjbInterceptors(AnnotatedMethod<?> method) { Method javaMethod = method.getJavaMember(); boolean excludeClassInterceptors = method.isAnnotationPresent(interceptorsApi.getExcludeClassInterceptorsAnnotationClass()); if (excludeClassInterceptors) { builder.addMethodIgnoringGlobalInterceptors(javaMethod); } Class<?>[] methodDeclaredInterceptors = interceptorsApi.extractInterceptorClasses(method); if (methodDeclaredInterceptors != null && methodDeclaredInterceptors.length > 0) { if (Reflections.isFinal(method.getJavaMember())) { throw new DeploymentException(BeanLogger.LOG.finalInterceptedBeanMethodNotAllowed(method, methodDeclaredInterceptors[0].getName())); } InterceptionType interceptionType = isTimeoutAnnotationPresentOn(method) ? InterceptionType.AROUND_TIMEOUT : InterceptionType.AROUND_INVOKE; builder.interceptMethod(interceptionType, javaMethod, getMethodDeclaredInterceptorMetadatas(methodDeclaredInterceptors), null); } }
private void initInterceptor(InterceptionType interceptionType, AnnotatedMethod<?> method, Set<Annotation> methodBindingAnnotations) { List<Interceptor<?>> methodBoundInterceptors = manager.resolveInterceptors(interceptionType, methodBindingAnnotations); if (methodBoundInterceptors != null && methodBoundInterceptors.size() > 0) { Method javaMethod = method.getJavaMember(); if (Reflections.isFinal(javaMethod)) { if (configuration.isFinalMethodIgnored(javaMethod.getDeclaringClass().getName())) { BeanLogger.LOG.finalMethodNotIntercepted(javaMethod, methodBoundInterceptors.get(0).getBeanClass().getName()); } else { throw BeanLogger.LOG.finalInterceptedBeanMethodNotAllowed(method, methodBoundInterceptors.get(0).getBeanClass().getName()); } } else { builder.interceptMethod(interceptionType, javaMethod, asInterceptorMetadata(methodBoundInterceptors), methodBindingAnnotations); } } }
private void initCdiBusinessMethodInterceptors(Map<Class<? extends Annotation>, Annotation> classBindingAnnotations) { for (AnnotatedMethod<?> method : businessMethods) { initCdiBusinessMethodInterceptor(method, getMemberBindingAnnotations(classBindingAnnotations, method.getAnnotations())); } }
private void initCdiInterceptors() { Multimap<Class<? extends Annotation>, Annotation> classBindingAnnotations = getClassInterceptorBindings(); // WELD-1742 Set class level interceptor bindings Set<Annotation> bindings = classBindingAnnotations.uniqueValues(); builder.setClassInterceptorBindings(bindings); initCdiLifecycleInterceptors(bindings); initCdiConstructorInterceptors(classBindingAnnotations); initCdiBusinessMethodInterceptors(classBindingAnnotations); }
private void initLifeCycleInterceptor(InterceptionType interceptionType, AnnotatedConstructor<?> constructor, Set<Annotation> annotations) { List<Interceptor<?>> resolvedInterceptors = manager.resolveInterceptors(interceptionType, annotations); if (!resolvedInterceptors.isEmpty()) { if(constructor != null) { builder.interceptGlobal(interceptionType, constructor.getJavaMember(), asInterceptorMetadata(resolvedInterceptors), annotations); } else { builder.interceptGlobal(interceptionType, null, asInterceptorMetadata(resolvedInterceptors), null); } } }
private void initCdiConstructorInterceptors(Map<Class<? extends Annotation>, Annotation> classBindingAnnotations) { Set<Annotation> constructorBindings = getMemberBindingAnnotations(classBindingAnnotations, constructor.getAnnotations()); if (constructorBindings.isEmpty()) { return; } initLifeCycleInterceptor(InterceptionType.AROUND_CONSTRUCT, this.constructor, constructorBindings); }
private void initCdiBusinessMethodInterceptors(Multimap<Class<? extends Annotation>, Annotation> classBindingAnnotations) { for (EnhancedAnnotatedMethod<?, ?> method : businessMethods) { initCdiBusinessMethodInterceptor(method, getMemberBindingAnnotations(classBindingAnnotations, method.getMetaAnnotations(InterceptorBinding.class))); } }
public static <T> InterceptionModelInitializer<T> of(BeanManagerImpl manager, EnhancedAnnotatedType<T> annotatedType, Bean<?> bean) { return new InterceptionModelInitializer<T>(manager, annotatedType, Beans.getBeanConstructorStrict(annotatedType), bean); }
protected void buildInterceptionModel(EnhancedAnnotatedType<T> annotatedType, AbstractInstantiator<T> instantiator) { new InterceptionModelInitializer<T>(beanManager, annotatedType, instantiator.getConstructorInjectionPoint().getAnnotated(), getBean()).init(); }
this.cache = ComputingCacheBuilder.newBuilder().<Key, Optional<InterceptionFactoryData<?>>> build((key) -> { ClassTransformer classTransformer = beanManager.getServices().get(ClassTransformer.class); UnbackedAnnotatedType<?> slimAnnotatedType = classTransformer.getUnbackedAnnotatedType(key.annotatedType, beanManager.getId(), id); new InterceptionModelInitializer(beanManager, enhancedAnnotatedType, Beans.getBeanConstructor(enhancedAnnotatedType), null).init(); InterceptionModel interceptionModel = beanManager.getInterceptorModelRegistry().get(slimAnnotatedType); if (!interceptionModel.getInterceptors(InterceptionType.AROUND_INVOKE, method.getJavaMember()).isEmpty()) { interceptedMethodSignatures.add(MethodSignatureImpl.of(method)); InterceptedProxyFactory<?> proxyFactory = new InterceptedProxyFactory<>(beanManager.getContextId(), enhancedAnnotatedType.getJavaClass(), Collections.singleton(enhancedAnnotatedType.getJavaClass()), enhancedMethodSignatures, interceptedMethodSignatures, "" + idx);
public void registerCdiInterceptorsForMessageDrivenBeans() { EjbServices ejbServices = getManager().getServices().get(EjbServices.class); for (InternalEjbDescriptor<?> descriptor : getEnvironment().getEjbDescriptors()) { if (descriptor.isMessageDriven()) { EnhancedAnnotatedType<?> type = classTransformer.getEnhancedAnnotatedType(descriptor.getBeanClass(), getManager().getId()); if (!getManager().getInterceptorModelRegistry().containsKey(type.slim())) { InterceptionModelInitializer.of(getManager(), type, null).init(); } InterceptionModel model = getManager().getInterceptorModelRegistry().get(type.slim()); if (model != null) { ejbServices.registerInterceptors(descriptor.delegate(), new InterceptorBindingsAdapter(model)); } } } }
public void init() { initTargetClassInterceptors(); businessMethods = Beans.getInterceptableMethods(annotatedType); initEjbInterceptors(); initCdiInterceptors(); InterceptionModel interceptionModel = builder.build(); if (interceptionModel.getAllInterceptors().size() > 0 || hasSerializationOrInvocationInterceptorMethods) { if (annotatedType.isFinal()) { throw BeanLogger.LOG.finalBeanClassWithInterceptorsNotAllowed(annotatedType.getJavaClass()); } if (Reflections.isPrivate(constructor.getJavaMember())) { throw new DeploymentException(ValidatorLogger.LOG.notProxyablePrivateConstructor(annotatedType.getJavaClass().getName(), constructor, annotatedType.getJavaClass())); } manager.getInterceptorModelRegistry().put(annotatedType.slim(), interceptionModel); } }
private void initMethodDeclaredEjbInterceptors(AnnotatedMethod<?> method) { Method javaMethod = method.getJavaMember(); boolean excludeClassInterceptors = method.isAnnotationPresent(interceptorsApi.getExcludeClassInterceptorsAnnotationClass()); if (excludeClassInterceptors) { builder.addMethodIgnoringGlobalInterceptors(javaMethod); } Class<?>[] methodDeclaredInterceptors = interceptorsApi.extractInterceptorClasses(method); if (methodDeclaredInterceptors != null && methodDeclaredInterceptors.length > 0) { if (Reflections.isFinal(method.getJavaMember())) { throw new DeploymentException(BeanLogger.LOG.finalInterceptedBeanMethodNotAllowed(method, methodDeclaredInterceptors[0].getName())); } InterceptionType interceptionType = isTimeoutAnnotationPresentOn(method) ? InterceptionType.AROUND_TIMEOUT : InterceptionType.AROUND_INVOKE; builder.interceptMethod(interceptionType, javaMethod, getMethodDeclaredInterceptorMetadatas(methodDeclaredInterceptors), null); } }
private void initInterceptor(InterceptionType interceptionType, AnnotatedMethod<?> method, Set<Annotation> methodBindingAnnotations) { List<Interceptor<?>> methodBoundInterceptors = manager.resolveInterceptors(interceptionType, methodBindingAnnotations); if (methodBoundInterceptors != null && methodBoundInterceptors.size() > 0) { Method javaMethod = method.getJavaMember(); if (Reflections.isFinal(javaMethod)) { if (configuration.isFinalMethodIgnored(javaMethod.getDeclaringClass().getName())) { BeanLogger.LOG.finalMethodNotIntercepted(javaMethod, methodBoundInterceptors.get(0).getBeanClass().getName()); } else { throw BeanLogger.LOG.finalInterceptedBeanMethodNotAllowed(method, methodBoundInterceptors.get(0).getBeanClass().getName()); } } else { builder.interceptMethod(interceptionType, javaMethod, asInterceptorMetadata(methodBoundInterceptors), methodBindingAnnotations); } } }
private void initCdiInterceptors() { Multimap<Class<? extends Annotation>, Annotation> classBindingAnnotations = getClassInterceptorBindings(); // WELD-1742 Set class level interceptor bindings Set<Annotation> bindings = classBindingAnnotations.uniqueValues(); builder.setClassInterceptorBindings(bindings); initCdiLifecycleInterceptors(bindings); initCdiConstructorInterceptors(classBindingAnnotations); initCdiBusinessMethodInterceptors(classBindingAnnotations); }