Package javax.interceptor

Examples of javax.interceptor.Interceptors


    }

    protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo,
            EjbContext[] ejbContexts) throws AnnotationProcessorException {

        Interceptors interceptors = (Interceptors) ainfo.getAnnotation();

       
        EjbBundleDescriptor ejbBundle =
            ((EjbDescriptor)ejbContexts[0].getDescriptor()).
                getEjbBundleDescriptor();
       
        // Process each of the interceptor classes.
        for(Class interceptor : interceptors.value()) {
            processInterceptorClass(interceptor, ejbBundle, ainfo);
        }

        for(EjbContext next : ejbContexts) {

            EjbDescriptor ejbDescriptor = (EjbDescriptor) next.getDescriptor();

            // Create binding information. 
            InterceptorBindingDescriptor binding =
                new InterceptorBindingDescriptor();

            binding.setEjbName(ejbDescriptor.getName());

            for(Class interceptor : interceptors.value()) {
                binding.appendInterceptorClass(interceptor.getName());
            }
           
            if(ElementType.METHOD.equals(ainfo.getElementType())) {
                Method m = (Method) ainfo.getAnnotatedElement();
View Full Code Here


        }
    }

    private <T> void collectEjbInterceptors(List<Interceptor<?>> ejbInterceptors, Annotated annotated, boolean unproxyable, Set<Type> types)
    {
        Interceptors interceptorsAnnot = annotated.getAnnotation(Interceptors.class);
        if (interceptorsAnnot != null)
        {
            if (unproxyable)
            {
                throw new WebBeansConfigurationException(annotated + " is not proxyable, but an Interceptor got defined on it!");
            }

            if (types == null)
            {
                types = Collections.emptySet();
            }

            for (Class interceptorClass : interceptorsAnnot.value())
            {
                if (types.contains(interceptorClass)) // don't create another bean for it
                {
                    continue;
                }
View Full Code Here

              beanEJBAnnotation.setClassInject(new ClassInjectAnnotationWrapper(annotation));
              isKeep = true;
            }
            if (annotation instanceof Interceptors) {
              InterceptorsAnnotationWrapper interceptorsAnnotationWrapper = new InterceptorsAnnotationWrapper();
              Interceptors interceptorsAnnotation = (Interceptors) annotation;
              Class<?>[] interceptorClasses = interceptorsAnnotation.value();
              InterceptorsAnnotationEntry[] interceptors = new InterceptorsAnnotationEntry[interceptorClasses.length];
              for (int i = 0; i < interceptors.length; i++) {
                interceptors[i] = new InterceptorsAnnotationEntry(ObjectUtils.createObject(interceptorClasses[i]),
                    findInterceptorMethod(interceptorClasses[i]));
              }
              interceptorsAnnotationWrapper.setInterceptors(interceptors);
              if (clazz.isAnnotationPresent(ExcludeDefaultInterceptors.class)) {
                // 排除默认拦截
                interceptorsAnnotationWrapper.setExcludeDefaultInterceptors(true);
              }
              beanEJBAnnotation.setClassInterceptors(interceptorsAnnotationWrapper);
            }
          }
          // 字段注解
          Field[] fields = ObjectUtils.getAllField(clazz);
          for (Field field : fields) {
            for (Annotation annotation : field.getAnnotations()) {
              if (annotation instanceof Resource) {
                beanEJBAnnotation.addFieldInject(field.getName(), new FieldInjectAnnotationWrapper(field, annotation));
                break;
              }
              if (annotation instanceof EJB) {
                beanEJBAnnotation.addFieldInject(field.getName(), new FieldInjectAnnotationWrapper(field, annotation));
                break;
              }
              if (annotation.getClass().isAnnotationPresent(ResourceComponent.class)) {
                beanEJBAnnotation.addFieldInject(field.getName(), new FieldInjectAnnotationWrapper(field, annotation));
                break;
              }
              if (annotation.getClass().isAnnotationPresent(EJBComponent.class)) {
                beanEJBAnnotation.addFieldInject(field.getName(), new FieldInjectAnnotationWrapper(field, annotation));
                break;
              }
            }
          }
          // 方法注解
          Method[] methods = clazz.getMethods();
          for (Method method : methods) {
            String methodName = method.getName();
            isKeep = false;
            for (Annotation annotation : method.getAnnotations()) {
              if (!isKeep && annotation instanceof Resource) {
                beanEJBAnnotation.addMethodInject(methodName, new MethodInjectAnnotationWrapper(method, annotation));
                isKeep = true;
              }
              if (!isKeep && annotation instanceof EJB) {
                beanEJBAnnotation.addMethodInject(methodName, new MethodInjectAnnotationWrapper(method, annotation));
                isKeep = true;
              }
              if (!isKeep && annotation.getClass().isAnnotationPresent(ResourceComponent.class)) {
                beanEJBAnnotation.addMethodInject(methodName, new MethodInjectAnnotationWrapper(method, annotation));
                isKeep = true;
              }
              if (!isKeep && annotation.getClass().isAnnotationPresent(EJBComponent.class)) {
                beanEJBAnnotation.addMethodInject(methodName, new MethodInjectAnnotationWrapper(method, annotation));
                isKeep = true;
              }
              if (annotation instanceof Interceptors) {
                InterceptorsAnnotationWrapper interceptorsAnnotationWrapper = new InterceptorsAnnotationWrapper();
                Interceptors interceptorsAnnotation = (Interceptors) annotation;
                Class<?>[] interceptorClasses = interceptorsAnnotation.value();
                InterceptorsAnnotationEntry[] interceptors = new InterceptorsAnnotationEntry[interceptorClasses.length];
                for (int i = 0; i < interceptors.length; i++) {
                  interceptors[i] = new InterceptorsAnnotationEntry(ObjectUtils.createObject(interceptorClasses[i]),
                      findInterceptorMethod(interceptorClasses[i]));
                }
View Full Code Here

      _isExcludeDefaultInterceptors = true;

    if (implMethod.isAnnotationPresent(ExcludeDefaultInterceptors.class))
      _isExcludeDefaultInterceptors = true;

    Interceptors iAnn;

    if (! _isExcludeClassInterceptors) {
      iAnn = apiClass.getAnnotation(Interceptors.class);

      if (iAnn != null) {
        for (Class<?> iClass : iAnn.value()) {
          if (! _classInterceptors.contains(iClass))
            _classInterceptors.add(iClass);
        }
      }

      if (implClass != null) {
        iAnn = implClass.getAnnotation(Interceptors.class);

        if (apiMethod != implMethod && iAnn != null) {
          for (Class<?> iClass : iAnn.value()) {
            if (! _classInterceptors.contains(iClass))
              _classInterceptors.add(iClass);
          }
        }
      }
    }

    iAnn = apiMethod.getAnnotation(Interceptors.class);

    if (iAnn != null) {
      for (Class<?> iClass : iAnn.value()) {
        if (! _methodInterceptors.contains(iClass))
          _methodInterceptors.add(iClass);
      }
    }

    iAnn = implMethod.getAnnotation(Interceptors.class);

    if (apiMethod != implMethod && iAnn != null) {
      for (Class<?> iClass : iAnn.value()) {
        if (! _methodInterceptors.contains(iClass))
          _methodInterceptors.add(iClass);
      }
    }
View Full Code Here

        
         log.debug("Found class interceptors " + defaultInterceptors);
         // Default Interceptors
         instanceAdvisor.getMetaData().addMetaData(InterceptorsFactory.class, "defaultInterceptors", defaultInterceptors);
        
         Interceptors interceptorsAnnotation = (Interceptors) advisor.resolveAnnotation(Interceptors.class);
         List<BusinessMethodInterceptorMethodInterceptor> classInterceptors = new ArrayList<BusinessMethodInterceptorMethodInterceptor>();
         if(interceptorsAnnotation != null)
            createInterceptors(advisor, interceptorFactory, interceptorsAnnotation.value(), classInterceptors, interceptors, lifeCycleInterceptors);
        
         log.debug("Found class interceptors " + classInterceptors);
         // Class Interceptors
         instanceAdvisor.getMetaData().addMetaData(InterceptorsFactory.class, "classInterceptors", classInterceptors);
        
         Class<?> beanClass = advisor.getClazz();
         List<Interceptor> beanInterceptors = new ArrayList<Interceptor>();
         for(Method beanMethod : ClassHelper.getAllMethods(beanClass))
         {
            interceptorsAnnotation = (Interceptors) advisor.resolveAnnotation(beanMethod, Interceptors.class);
            if(interceptorsAnnotation != null)
            {
               List<Interceptor> businessMethodInterceptors = new ArrayList<Interceptor>();
               // TODO: use visitors?
               for(Class<?> interceptorClass : interceptorsAnnotation.value())
               {
                  Object interceptor = interceptors.get(interceptorClass);
                  if(interceptor == null)
                  {
                     interceptor = interceptorFactory.create(advisor, interceptorClass);
View Full Code Here

      log.debug("Found default interceptors " + defaultInterceptorClasses);
//      interceptorClasses.addAll(defaultInterceptorClasses);
      List<Class<?>> lifecycleInterceptorClasses = new ArrayList<Class<?>>();
      lifecycleInterceptorClasses.addAll(defaultInterceptorClasses);
     
      Interceptors interceptorsAnnotation = (Interceptors) advisor.resolveAnnotation(Interceptors.class);
      List<Class<?>> classInterceptorClasses = new ArrayList<Class<?>>();
      if(interceptorsAnnotation != null)
      {
         for(Class<?> classInterceptorClass : interceptorsAnnotation.value())
         {
            classInterceptorClasses.add(classInterceptorClass);
//            if(!interceptorClasses.contains(classInterceptorClass))
//               interceptorClasses.add(classInterceptorClass);
            if(!lifecycleInterceptorClasses.contains(classInterceptorClass))
               lifecycleInterceptorClasses.add(classInterceptorClass);
         }
      }
      log.debug("Found class interceptors " + classInterceptorClasses);
     
      {
         // Ordering of lifecycle interceptors
         InterceptorOrder order = (InterceptorOrder) advisor.resolveAnnotation(InterceptorOrder.class);
         if(order != null)
         {
            List<Class<?>> orderedInterceptorClasses = Arrays.asList(order.value());
            if(!orderedInterceptorClasses.containsAll(lifecycleInterceptorClasses))
               throw new IllegalStateException("EJB3 12.8.2 footnote 59: all applicable lifecycle interceptors must be listed in the interceptor order");
            lifecycleInterceptorClasses = orderedInterceptorClasses;
         }
      }
      this.lifecycleInterceptorClasses.addAll(lifecycleInterceptorClasses);
      for(Class<?> interceptorClass : lifecycleInterceptorClasses)
      {
         if(!interceptorClasses.contains(interceptorClass))
            interceptorClasses.add(interceptorClass);
      }
     
      Class<?> beanClass = advisor.getClazz();
      for(Method beanMethod : ClassHelper.getAllMethods(beanClass))
      {
         interceptorsAnnotation = (Interceptors) advisor.resolveAnnotation(beanMethod, Interceptors.class);
         List<Class<?>> methodInterceptorClasses = new ArrayList<Class<?>>();
         if(interceptorsAnnotation != null)
         {
            for(Class<?> interceptorClass : interceptorsAnnotation.value())
               methodInterceptorClasses.add(interceptorClass);
         }
        
         // Interceptors applicable for this bean method
         List<Class<?>> methodApplicableInterceptorClasses = new ArrayList<Class<?>>();
View Full Code Here

                /*
                 * @Interceptors
                 */
                final List<Annotated<Class<?>>> annotatedClasses = sortClasses(annotationFinder.findMetaAnnotatedClasses(Interceptors.class));
                for (Annotated<Class<?>> interceptorsAnnotatedClass : annotatedClasses) {
                    Interceptors interceptors = interceptorsAnnotatedClass.getAnnotation(Interceptors.class);
                    EjbJar ejbJar = ejbModule.getEjbJar();
                    for (Class interceptor : interceptors.value()) {
                        if (ejbJar.getInterceptor(interceptor.getName()) == null) {
                            ejbJar.addInterceptor(new Interceptor(interceptor.getName()));
                        }
                    }

                    InterceptorBinding binding = new InterceptorBinding(bean);
                    assemblyDescriptor.getInterceptorBinding().add(0, binding);

                    for (Class interceptor : interceptors.value()) {
                        binding.getInterceptorClass().add(interceptor.getName());
                    }
                }

                final List<Annotated<Method>> annotatedMethods = sortMethods(annotationFinder.findMetaAnnotatedMethods(Interceptors.class));
                for (Annotated<Method> method : annotatedMethods) {
                    Interceptors interceptors = method.getAnnotation(Interceptors.class);
                    if (interceptors != null) {
                        EjbJar ejbJar = ejbModule.getEjbJar();
                        for (Class interceptor : interceptors.value()) {
                            if (ejbJar.getInterceptor(interceptor.getName()) == null) {
                                ejbJar.addInterceptor(new Interceptor(interceptor.getName()));
                            }
                        }

                        InterceptorBinding binding = new InterceptorBinding(bean);
                        assemblyDescriptor.getInterceptorBinding().add(0, binding);

                        for (Class interceptor : interceptors.value()) {
                            binding.getInterceptorClass().add(interceptor.getName());
                        }

                        binding.setMethod(new NamedMethod(method.get()));
                    }
View Full Code Here

        
         log.debug("Found class interceptors " + defaultInterceptors);
         // Default Interceptors
         instanceAdvisor.getMetaData().addMetaData(InterceptorsFactory.class, "defaultInterceptors", defaultInterceptors);
        
         Interceptors interceptorsAnnotation = (Interceptors) advisor.resolveAnnotation(Interceptors.class);
         List<BusinessMethodInterceptorMethodInterceptor> classInterceptors = new ArrayList<BusinessMethodInterceptorMethodInterceptor>();
         if(interceptorsAnnotation != null)
            createInterceptors(advisor, interceptorFactory, interceptorsAnnotation.value(), classInterceptors, interceptors, lifeCycleInterceptors);
        
         log.debug("Found class interceptors " + classInterceptors);
         // Class Interceptors
         instanceAdvisor.getMetaData().addMetaData(InterceptorsFactory.class, "classInterceptors", classInterceptors);
        
         Class<?> beanClass = advisor.getClazz();
         List<Interceptor> beanInterceptors = new ArrayList<Interceptor>();
         for(Method beanMethod : ClassHelper.getAllMethods(beanClass))
         {
            interceptorsAnnotation = (Interceptors) advisor.resolveAnnotation(beanMethod, Interceptors.class);
            if(interceptorsAnnotation != null)
            {
               List<Interceptor> businessMethodInterceptors = new ArrayList<Interceptor>();
               // TODO: use visitors?
               for(Class<?> interceptorClass : interceptorsAnnotation.value())
               {
                  Object interceptor = interceptors.get(interceptorClass);
                  if(interceptor == null)
                  {
                     interceptor = interceptorFactory.create(advisor, interceptorClass);
View Full Code Here

      if (!isExcludedDefaultInterceptors(advisor))
      {
         lifecycleInterceptorClasses.addAll(defaultInterceptorClasses);
      }

      Interceptors interceptorsAnnotation = (Interceptors) advisor.resolveAnnotation(Interceptors.class);
      List<Class<?>> classInterceptorClasses = new ArrayList<Class<?>>();
      if(interceptorsAnnotation != null)
      {
         for(Class<?> classInterceptorClass : interceptorsAnnotation.value())
         {
            classInterceptorClasses.add(classInterceptorClass);
//            if(!interceptorClasses.contains(classInterceptorClass))
//               interceptorClasses.add(classInterceptorClass);
            if(!lifecycleInterceptorClasses.contains(classInterceptorClass))
               lifecycleInterceptorClasses.add(classInterceptorClass);
         }
      }
      log.debug("Found class interceptors " + classInterceptorClasses);

      {
         // Ordering of lifecycle interceptors
         InterceptorOrder order = (InterceptorOrder) advisor.resolveAnnotation(InterceptorOrder.class);
         if(order != null)
         {
            List<Class<?>> orderedInterceptorClasses = Arrays.asList(order.value());
            if(!orderedInterceptorClasses.containsAll(lifecycleInterceptorClasses))
               throw new IllegalStateException("EJB3 12.8.2 footnote 59: all applicable lifecycle interceptors must be listed in the interceptor order");
            lifecycleInterceptorClasses = orderedInterceptorClasses;
         }
      }
      this.lifecycleInterceptorClasses.addAll(lifecycleInterceptorClasses);
      for(Class<?> interceptorClass : lifecycleInterceptorClasses)
      {
         if(!interceptorClasses.contains(interceptorClass))
            interceptorClasses.add(interceptorClass);
      }

      Class<?> beanClass = advisor.getClazz();
      // EJB3 spec says in section 12.7
      // "A business method interceptor method may be defined to apply to a specific *business method*
      // invocation, rather than to all of the business methods of the bean class."
      // So all we need are "public" methods.
      for(Method beanMethod : beanClass.getMethods())
      {
         interceptorsAnnotation = (Interceptors) advisor.resolveAnnotation(beanMethod, Interceptors.class);
         List<Class<?>> methodInterceptorClasses = new ArrayList<Class<?>>();
         if(interceptorsAnnotation != null)
         {
            for(Class<?> interceptorClass : interceptorsAnnotation.value())
               methodInterceptorClasses.add(interceptorClass);
         }

         // Interceptors applicable for this bean method
         List<Class<?>> methodApplicableInterceptorClasses = new ArrayList<Class<?>>();
View Full Code Here

      methodInterceptors = addInterceptors(methodInterceptors,
                                           typeInterceptors.getClassInterceptors(),
                                           annType);
    }
   
    Interceptors interceptorsAnn = method.getAnnotation(Interceptors.class);

    boolean isMethodInterceptor = false;
   
    if (interceptorsAnn != null) {
      for (Class<?> iClass : interceptorsAnn.value()) {
        if (! hasAroundInvoke(iClass)) {
          continue;
        }
       
        isMethodInterceptor = true;
View Full Code Here

TOP

Related Classes of javax.interceptor.Interceptors

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.