@Override
  public String[] selectImports(AnnotationMetadata metadata) {
    try {
      AnnotationAttributes attributes =
          AnnotationAttributes.fromMap(
              metadata.getAnnotationAttributes(EnableAutoConfiguration.class.getName(), true));

      Assert.notNull(
          attributes,
          "No auto-configuration attributes found. Is "
              + metadata.getClassName()
              + " annotated with @EnableAutoConfiguration?");

      // Find all possible auto configuration classes, filtering duplicates
      List<String> factories =
          new ArrayList<String>(
              new LinkedHashSet<String>(
                  SpringFactoriesLoader.loadFactoryNames(
                      EnableAutoConfiguration.class, this.beanClassLoader)));

      // Remove those specifically excluded
      Set<String> excluded = new LinkedHashSet<String>();
      excluded.addAll(Arrays.asList(attributes.getStringArray("exclude")));
      excluded.addAll(Arrays.asList(attributes.getStringArray("excludeName")));
      factories.removeAll(excluded);
      ConditionEvaluationReport.get(this.beanFactory).recordExclusions(excluded);

      // Sort
      factories = new AutoConfigurationSorter(this.resourceLoader).getInPriorityOrder(factories);

      return factories.toArray(new String[factories.size()]);
    } catch (IOException ex) {
      throw new IllegalStateException(ex);
    }
  }
示例#2
0
  @Override
  protected BeanDefinition buildBeanDefinition(
      AnnotationMetadata importingClassMetadata, Class<? extends Annotation> namedAnnotation)
      throws Exception {

    String enableStateMachineEnclosingClassName = importingClassMetadata.getClassName();
    // for below classloader, see gh122
    Class<?> enableStateMachineEnclosingClass =
        ClassUtils.forName(
            enableStateMachineEnclosingClassName, ClassUtils.getDefaultClassLoader());
    // return null if it looks like @EnableStateMachine was annotated with class
    // not extending StateMachineConfigurer.
    if (!ClassUtils.isAssignable(StateMachineConfigurer.class, enableStateMachineEnclosingClass)) {
      return null;
    }

    BeanDefinitionBuilder beanDefinitionBuilder =
        BeanDefinitionBuilder.rootBeanDefinition(StateMachineDelegatingFactoryBean.class);
    AnnotationAttributes esmAttributes =
        AnnotationAttributes.fromMap(
            importingClassMetadata.getAnnotationAttributes(
                EnableStateMachine.class.getName(), false));
    Boolean contextEvents = esmAttributes.getBoolean("contextEvents");

    // check if Scope annotation is defined and set scope from it
    AnnotationAttributes scopeAttributes =
        AnnotationAttributes.fromMap(
            importingClassMetadata.getAnnotationAttributes(Scope.class.getName(), false));
    if (scopeAttributes != null) {
      String scope =
          scopeAttributes.getAliasedString("value", Scope.class, enableStateMachineEnclosingClass);
      if (StringUtils.hasText(scope)) {
        beanDefinitionBuilder.setScope(scope);
      }
    }

    beanDefinitionBuilder.addConstructorArgValue(builder);
    beanDefinitionBuilder.addConstructorArgValue(StateMachine.class);
    beanDefinitionBuilder.addConstructorArgValue(importingClassMetadata.getClassName());
    beanDefinitionBuilder.addConstructorArgValue(contextEvents);
    return beanDefinitionBuilder.getBeanDefinition();
  }
 @Override
 public void setImportMetadata(AnnotationMetadata importMetadata) {
   AnnotationAttributes annotationAttributes =
       AnnotationAttributes.fromMap(
           importMetadata.getAnnotationAttributes(EnableRoleChecking.class.getName()));
   Assert.notNull(
       annotationAttributes,
       "No "
           + EnableRoleChecking.class.getSimpleName()
           + " annotation found on  '"
           + importMetadata.getClassName()
           + "'.");
 }
  public void setImportMetadata(AnnotationMetadata importMetadata) {
    Map<String, Object> enableAttrMap =
        importMetadata.getAnnotationAttributes(EnableHazelcastHttpSession.class.getName());
    AnnotationAttributes enableAttrs = AnnotationAttributes.fromMap(enableAttrMap);
    if (enableAttrs == null) {
      // search parent classes
      Class<?> currentClass =
          ClassUtils.resolveClassName(importMetadata.getClassName(), beanClassLoader);
      for (Class<?> classToInspect = currentClass;
          classToInspect != null;
          classToInspect = classToInspect.getSuperclass()) {
        EnableHazelcastHttpSession enableHazelcastHttpSessionAnnotation =
            AnnotationUtils.findAnnotation(classToInspect, EnableHazelcastHttpSession.class);
        if (enableHazelcastHttpSessionAnnotation == null) {
          continue;
        }
        enableAttrMap =
            AnnotationUtils.getAnnotationAttributes(enableHazelcastHttpSessionAnnotation);
        enableAttrs = AnnotationAttributes.fromMap(enableAttrMap);
      }
    }

    transferAnnotationAttributes(enableAttrs);
  }
 private Set<String> getPackagesToScan(AnnotationMetadata metadata) {
   AnnotationAttributes attributes =
       AnnotationAttributes.fromMap(
           metadata.getAnnotationAttributes(EntityScan.class.getName()));
   String[] basePackages =
       attributes.getAliasedStringArray(
           "basePackages", EntityScan.class, metadata.getClassName());
   Class<?>[] basePackageClasses = attributes.getClassArray("basePackageClasses");
   Set<String> packagesToScan = new LinkedHashSet<String>();
   packagesToScan.addAll(Arrays.asList(basePackages));
   for (Class<?> basePackageClass : basePackageClasses) {
     packagesToScan.add(ClassUtils.getPackageName(basePackageClass));
   }
   if (packagesToScan.isEmpty()) {
     String packageName = ClassUtils.getPackageName(metadata.getClassName());
     Assert.state(
         !StringUtils.isEmpty(packageName),
         "@EntityScan cannot be used with the default package");
     return Collections.singleton(packageName);
   }
   return packagesToScan;
 }
 public static AnnotationAttributes attributesFor(
     AnnotationMetadata metadata, String annoClassName) {
   return AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(annoClassName, false));
 }