public int compareTo(ClassAnnotationsLoader o) {
    Order order1 = AnnotationUtils.findAnnotation(getClass(), Order.class);
    Order order2 = AnnotationUtils.findAnnotation(o.getClass(), Order.class);
    int order1Value = order1 != null ? order1.value() : Ordered.LOWEST_PRECEDENCE;
    int order2Value = order2 != null ? order2.value() : Ordered.LOWEST_PRECEDENCE;

    return order1Value - order2Value;
  }
 /**
  * Determine the order for this factory's target aspect, either an instance-specific order
  * expressed through implementing the {@link org.springframework.core.Ordered} interface (only
  * checked for singleton beans), or an order expressed through the {@link
  * org.springframework.core.annotation.Order} annotation at the class level.
  *
  * @see org.springframework.core.Ordered
  * @see org.springframework.core.annotation.Order
  */
 public int getOrder() {
   Class<?> type = this.beanFactory.getType(this.name);
   if (type != null) {
     if (Ordered.class.isAssignableFrom(type) && this.beanFactory.isSingleton(this.name)) {
       return ((Ordered) this.beanFactory.getBean(this.name)).getOrder();
     }
     Order order = type.getAnnotation(Order.class);
     if (order != null) {
       return order.value();
     }
   }
   return Ordered.LOWEST_PRECEDENCE;
 }
 @Override
 public Object postProcess(Object bean, String beanName, Method method, T annotation) {
   MessageHandler handler = this.createHandler(bean, method, annotation);
   this.setAdviceChainIfPresent(beanName, annotation, handler);
   if (handler instanceof Orderable) {
     Order orderAnnotation = AnnotationUtils.findAnnotation(method, Order.class);
     if (orderAnnotation != null) {
       ((Orderable) handler).setOrder(orderAnnotation.value());
     }
   }
   if (beanFactory instanceof ConfigurableListableBeanFactory) {
     String handlerBeanName =
         this.generateHandlerBeanName(beanName, method, annotation.annotationType());
     ConfigurableListableBeanFactory listableBeanFactory =
         (ConfigurableListableBeanFactory) beanFactory;
     listableBeanFactory.registerSingleton(handlerBeanName, handler);
     handler = (MessageHandler) listableBeanFactory.initializeBean(handler, handlerBeanName);
   }
   AbstractEndpoint endpoint = this.createEndpoint(handler, annotation);
   if (endpoint != null) {
     return endpoint;
   }
   return handler;
 }
  @Override
  public Object postProcess(
      Object bean, String beanName, Method method, List<Annotation> annotations) {
    if (this.beanAnnotationAware()
        && AnnotatedElementUtils.isAnnotated(method, Bean.class.getName())) {
      try {
        resolveTargetBeanFromMethodWithBeanAnnotation(method);
      } catch (NoSuchBeanDefinitionException e) {
        if (this.logger.isDebugEnabled()) {
          this.logger.debug(
              "Skipping endpoint creation; "
                  + e.getMessage()
                  + "; perhaps due to some '@Conditional' annotation.");
        }
        return null;
      }
    }

    List<Advice> adviceChain = extractAdviceChain(beanName, annotations);

    MessageHandler handler = createHandler(bean, method, annotations);

    if (!CollectionUtils.isEmpty(adviceChain)
        && handler instanceof AbstractReplyProducingMessageHandler) {
      ((AbstractReplyProducingMessageHandler) handler).setAdviceChain(adviceChain);
    }

    if (handler instanceof Orderable) {
      Order orderAnnotation = AnnotationUtils.findAnnotation(method, Order.class);
      if (orderAnnotation != null) {
        ((Orderable) handler).setOrder(orderAnnotation.value());
      }
    }
    if (handler instanceof AbstractMessageProducingHandler
        || handler instanceof AbstractMessageRouter) {
      String sendTimeout =
          MessagingAnnotationUtils.resolveAttribute(annotations, "sendTimeout", String.class);
      if (sendTimeout != null) {
        Long value = Long.valueOf(this.beanFactory.resolveEmbeddedValue(sendTimeout));
        if (handler instanceof AbstractMessageProducingHandler) {
          ((AbstractMessageProducingHandler) handler).setSendTimeout(value);
        } else {
          ((AbstractMessageRouter) handler).setSendTimeout(value);
        }
      }
    }

    boolean handlerExists = false;
    if (this.beanAnnotationAware()
        && AnnotatedElementUtils.isAnnotated(method, Bean.class.getName())) {
      Object handlerBean = this.resolveTargetBeanFromMethodWithBeanAnnotation(method);
      handlerExists = handlerBean != null && handler == handlerBean;
    }

    if (!handlerExists) {
      String handlerBeanName = generateHandlerBeanName(beanName, method);
      this.beanFactory.registerSingleton(handlerBeanName, handler);
      handler = (MessageHandler) this.beanFactory.initializeBean(handler, handlerBeanName);
    }

    if (AnnotatedElementUtils.isAnnotated(method, IdempotentReceiver.class.getName())
        && !AnnotatedElementUtils.isAnnotated(method, Bean.class.getName())) {
      String[] interceptors =
          AnnotationUtils.getAnnotation(method, IdempotentReceiver.class).value();
      for (String interceptor : interceptors) {
        DefaultBeanFactoryPointcutAdvisor advisor = new DefaultBeanFactoryPointcutAdvisor();
        advisor.setAdviceBeanName(interceptor);
        NameMatchMethodPointcut pointcut = new NameMatchMethodPointcut();
        pointcut.setMappedName("handleMessage");
        advisor.setPointcut(pointcut);
        advisor.setBeanFactory(this.beanFactory);

        if (handler instanceof Advised) {
          ((Advised) handler).addAdvisor(advisor);
        } else {
          ProxyFactory proxyFactory = new ProxyFactory(handler);
          proxyFactory.addAdvisor(advisor);
          handler = (MessageHandler) proxyFactory.getProxy(this.beanFactory.getBeanClassLoader());
        }
      }
    }

    if (!CollectionUtils.isEmpty(adviceChain)) {
      for (Advice advice : adviceChain) {
        if (advice instanceof HandleMessageAdvice) {
          NameMatchMethodPointcutAdvisor handlerAdvice = new NameMatchMethodPointcutAdvisor(advice);
          handlerAdvice.addMethodName("handleMessage");
          if (handler instanceof Advised) {
            ((Advised) handler).addAdvisor(handlerAdvice);
          } else {
            ProxyFactory proxyFactory = new ProxyFactory(handler);
            proxyFactory.addAdvisor(handlerAdvice);
            handler = (MessageHandler) proxyFactory.getProxy(this.beanFactory.getBeanClassLoader());
          }
        }
      }
    }

    AbstractEndpoint endpoint = createEndpoint(handler, method, annotations);
    if (endpoint != null) {
      return endpoint;
    }
    return handler;
  }
 private static int getOrder(@NotNull Object object) { // NOSONAR
   Order order = object.getClass().getDeclaredAnnotation(Order.class);
   return order != null ? order.value() : 10;
 }
 @Override
 public int getOrder() {
   Order order = getMethodAnnotation(Order.class);
   return (order != null ? order.value() : 0);
 }