Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2012, Red Hat, Inc., and individual contributors
   * by the @authors tag. See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
  * http://www.apache.org/licenses/LICENSE-2.0
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.jboss.weld.injection.producer;
 
 import static org.jboss.weld.util.Interceptors.filterInterceptorBindings;
 import static org.jboss.weld.util.Interceptors.flattenInterceptorBindings;
 import static org.jboss.weld.util.Interceptors.mergeBeanInterceptorBindings;
 
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 
 
Initializes org.jboss.weld.interceptor.spi.model.InterceptionModel for a javax.enterprise.inject.spi.Bean or a non-contextual component.

Parameters:
<T>
Author(s):
Marko Luksa
Jozef Hartinger
 
 public class InterceptionModelInitializer<T> {
 
     public static <T> InterceptionModelInitializer<T> of(BeanManagerImpl managerEnhancedAnnotatedType<T> annotatedTypeBean<?> bean) {
         return new InterceptionModelInitializer<T>(managerannotatedType, Beans.getBeanConstructorStrict(annotatedType), bean);
     }
 
     private final BeanManagerImpl manager;
     private final InterceptorMetadataReader reader;
     private final EnhancedAnnotatedType<T> annotatedType;
     private final Set<Class<? extends Annotation>> stereotypes;
     private final AnnotatedConstructor<T> constructor;
 
     private final InterceptorsApiAbstraction interceptorsApi;
     private final EJBApiAbstraction ejbApi;
 
     private List<AnnotatedMethod<?>> businessMethods;
     private final InterceptionModelBuilder builder;
 
     public InterceptionModelInitializer(BeanManagerImpl managerEnhancedAnnotatedType<T> annotatedTypeAnnotatedConstructor<T> constructorBean<?> bean) {
         this. = constructor;
         this. = manager;
         this. = manager.getInterceptorMetadataReader();
         this. = annotatedType;
         this. = new InterceptionModelBuilder();
         if (bean == null) {
              = Collections.emptySet();
         } else {
              = bean.getStereotypes();
         }
         this. = manager.getServices().get(InterceptorsApiAbstraction.class);
         this. = manager.getServices().get(EJBApiAbstraction.class);
     }
 
     public void init() {
        initEjbInterceptors();
        initCdiInterceptors();
        InterceptionModel interceptionModel = .build();
        if (interceptionModel.getAllInterceptors().size() > 0 || ) {
            if (.isFinal()) {
            }
            if (Reflections.isPrivate(.getJavaMember())) {
            }
            .getInterceptorModelRegistry().put(.slim(), interceptionModel);
        }
    }
    private void initTargetClassInterceptors() {
        if (!Beans.isInterceptor()) {
            TargetClassInterceptorMetadata interceptorClassMetadata = .getTargetClassInterceptorMetadata();
            .setTargetClassInterceptorMetadata(interceptorClassMetadata);
                    || interceptorClassMetadata.isEligible(.......)
                    || interceptorClassMetadata.isEligible(.......)
                    || interceptorClassMetadata.isEligible(.......);
        } else {
            // an interceptor does not have lifecycle methods of its own, but it intercepts the methods of the
            // target class
             = false;
        }
    }
    private void initCdiInterceptors() {
        Map<Class<? extends Annotation>, AnnotationclassBindingAnnotations = getClassInterceptorBindings();
        initCdiLifecycleInterceptors(classBindingAnnotations);
        initCdiConstructorInterceptors(classBindingAnnotations);
        initCdiBusinessMethodInterceptors(classBindingAnnotations);
    }
    private Map<Class<? extends Annotation>, AnnotationgetClassInterceptorBindings() {
    }
    /*
     * CDI lifecycle interceptors
     */
    private void initCdiLifecycleInterceptors(Map<Class<? extends Annotation>, AnnotationclassBindingAnnotations) {
        if (classBindingAnnotations.size() == 0) {
            return;
        }
        final Collection<Annotationqualifiers = classBindingAnnotations.values();
    }
    private void initLifeCycleInterceptor(InterceptionType interceptionTypeCollection<Annotationannotations) {
        List<Interceptor<?>> resolvedInterceptors = .resolveInterceptors(interceptionTypeannotations);
        if (!resolvedInterceptors.isEmpty()) {
            .intercept(interceptionTypeasInterceptorMetadata(resolvedInterceptors));
        }
    }
    /*
     * CDI business method interceptors
     */
    private void initCdiBusinessMethodInterceptors(Map<Class<? extends Annotation>, AnnotationclassBindingAnnotations) {
        for (AnnotatedMethod<?> method : ) {
            initCdiBusinessMethodInterceptor(methodgetMemberBindingAnnotations(classBindingAnnotationsmethod.getAnnotations()));
        }
    }
    private void initCdiBusinessMethodInterceptor(AnnotatedMethod<?> methodCollection<AnnotationmethodBindingAnnotations) {
        if (methodBindingAnnotations.size() == 0) {
            return;
        }
        initInterceptor(.methodmethodBindingAnnotations);
        initInterceptor(.methodmethodBindingAnnotations);
    }
    private void initInterceptor(InterceptionType interceptionTypeAnnotatedMethod<?> methodCollection<AnnotationmethodBindingAnnotations) {
        List<Interceptor<?>> methodBoundInterceptors = .resolveInterceptors(interceptionTypemethodBindingAnnotations);
        if (methodBoundInterceptors != null && methodBoundInterceptors.size() > 0) {
            if (Reflections.isFinal(method.getJavaMember())) {
                throw ..finalInterceptedBeanMethodNotAllowed(methodmethodBoundInterceptors.get(0).getBeanClass().getName());
            }
            Method javaMethod = method.getJavaMember();
            .intercept(interceptionTypejavaMethodasInterceptorMetadata(methodBoundInterceptors));
        }
    }
    /*
     * CDI @AroundConstruct interceptors
     */
    private void initCdiConstructorInterceptors(Map<Class<? extends Annotation>, AnnotationclassBindingAnnotations) {
        Collection<AnnotationconstructorBindings = getMemberBindingAnnotations(classBindingAnnotations.getAnnotations());
        if (constructorBindings.isEmpty()) {
            return;
        }
        initLifeCycleInterceptor(.constructorBindings);
    }
    private Collection<AnnotationgetMemberBindingAnnotations(Map<Class<? extends Annotation>, AnnotationclassBindingAnnotationsSet<AnnotationmemberAnnotations) {
        Set<AnnotationmethodBindingAnnotations = flattenInterceptorBindings(filterInterceptorBindings(memberAnnotations), truetrue);
        return mergeMethodInterceptorBindings(classBindingAnnotationsmethodBindingAnnotations).values();
    }
    /*
     * EJB-style interceptors
     */
    private void initEjbInterceptors() {
        for (AnnotatedMethod<?> method : ) {
            initMethodDeclaredEjbInterceptors(method);
        }
    }
    /*
     * Class-level EJB-style interceptors
     */
    private void initClassDeclaredEjbInterceptors() {
        Class<?>[] classDeclaredInterceptors = .extractInterceptorClasses();
        boolean excludeClassLevelAroundConstructInterceptors = .isAnnotationPresent(ExcludeClassInterceptors.class);
        if (classDeclaredInterceptors != null) {
            for (Class<?> clazz : classDeclaredInterceptors) {
                InterceptorClassMetadata<?> interceptor = .getPlainInterceptorMetadata(clazz);
                for (InterceptionType interceptionType : InterceptionType.values()) {
                    if (excludeClassLevelAroundConstructInterceptors && interceptionType.equals(.)) {
                        /*
                         * @ExcludeClassInterceptors suppresses @AroundConstruct interceptors defined on class level
                         */
                        continue;
                    }
                    if (interceptor.isEligible(org.jboss.weld.interceptor.spi.model.InterceptionType.valueOf(interceptionType))) {
                        .intercept(interceptionType, Collections.<InterceptorClassMetadata<?>>singleton(interceptor));
                    }
                }
            }
        }
    }
    /*
     * Constructor-level EJB-style interceptors
     */
        Class<?>[] constructorDeclaredInterceptors = .extractInterceptorClasses();
        if (constructorDeclaredInterceptors != null) {
            for (Class<?> clazz : constructorDeclaredInterceptors) {
            }
        }
    }
    private void initMethodDeclaredEjbInterceptors(AnnotatedMethod<?> method) {
        Method javaMethod = method.getJavaMember();
        boolean excludeClassInterceptors = method.isAnnotationPresent(.getExcludeClassInterceptorsAnnotationClass());
        if (excludeClassInterceptors) {
            .addMethodIgnoringGlobalInterceptors(javaMethod);
        }
        Class<?>[] methodDeclaredInterceptors = .extractInterceptorClasses(method);
        if (methodDeclaredInterceptors != null && methodDeclaredInterceptors.length > 0) {
            if (Reflections.isFinal(method.getJavaMember())) {
                throw new DeploymentException(..finalInterceptedBeanMethodNotAllowed(methodmethodDeclaredInterceptors[0].getName()));
            }
            InterceptionType interceptionType = isTimeoutAnnotationPresentOn(method)
                    ? .
                    : .;
            .intercept(interceptionTypejavaMethodgetMethodDeclaredInterceptorMetadatas(methodDeclaredInterceptors));
        }
    }
    private List<InterceptorClassMetadata<?>> getMethodDeclaredInterceptorMetadatas(Class<?>[] methodDeclaredInterceptors) {
        List<InterceptorClassMetadata<?>> list = Lists.newLinkedList();
        for (Class<?> clazz : methodDeclaredInterceptors) {
            list.add(.getPlainInterceptorMetadata(clazz));
        }
        return list;
    }
    private boolean isTimeoutAnnotationPresentOn(AnnotatedMethod<?> method) {
        return method.isAnnotationPresent(.);
    }

    
Merges bean interceptor bindings (including inherited ones) with method interceptor bindings. Method interceptor bindings override bean interceptor bindings. The bean binding map is not modified - a copy is used.
    protected Map<Class<? extends Annotation>, AnnotationmergeMethodInterceptorBindings(Map<Class<? extends Annotation>, AnnotationbeanBindings,
            Collection<AnnotationmethodBindingAnnotations) {
        Map<Class<? extends Annotation>, AnnotationmergedBeanBindings = new HashMap<Class<? extends Annotation>, Annotation>(beanBindings);
        // conflict detection
        Set<Class<? extends Annotation>> processedBindingTypes = new HashSet<Class<? extends Annotation>>();
        for (Annotation methodBinding : methodBindingAnnotations) {
            Class<? extends AnnotationmethodBindingType = methodBinding.annotationType();
            if (processedBindingTypes.contains(methodBindingType)) {
            }
            processedBindingTypes.add(methodBindingType);
            // override bean interceptor binding
            mergedBeanBindings.put(methodBindingTypemethodBinding);
        }
        return mergedBeanBindings;
    }
    private List<InterceptorClassMetadata<?>> asInterceptorMetadata(List<Interceptor<?>> interceptors) {
        return Lists.transform(interceptors.getInterceptorToInterceptorMetadataFunction());
    }
New to GrepCode? Check out our FAQ X