org.springframework.core.type.AnnotatedTypeMetadata#isAnnotated ( )源码实例Demo

下面列出了org.springframework.core.type.AnnotatedTypeMetadata#isAnnotated ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: frostmourne   文件: OnProfileCondition.java
private Set<String> retrieveAnnotatedProfiles(AnnotatedTypeMetadata metadata, String annotationType) {
    if (!metadata.isAnnotated(annotationType)) {
        return Collections.emptySet();
    }

    MultiValueMap<String, Object> attributes = metadata.getAllAnnotationAttributes(annotationType);

    if (attributes == null) {
        return Collections.emptySet();
    }

    Set<String> profiles = Sets.newHashSet();
    List<?> values = attributes.get("value");

    if (values != null) {
        for (Object value : values) {
            if (value instanceof String[]) {
                Collections.addAll(profiles, (String[]) value);
            } else {
                profiles.add((String) value);
            }
        }
    }

    return profiles;
}
 
private boolean isComponentEnable(ConditionContext context, AnnotatedTypeMetadata metadata) {
    boolean isImporter = metadata.isAnnotated(ConditionalOnImporterComponent.class.getName());

    MultiValueMap<String, Object> map = null;
    if (isImporter) {
        map = metadata.getAllAnnotationAttributes(ConditionalOnImporterComponent.class
            .getName());
    } else {
        map = metadata.getAllAnnotationAttributes(ConditionalOnExporterComponent.class
            .getName());
    }

    String importerExporterName = getFirstAnnotationValueFromMetadata(map, "value");
    MonitorComponent monitorComponent = getFirstAnnotationValueFromMetadata(map, "type");
    List<String> activeComponents = getActivatedComponentsFromConfiguration(context,
        isImporter, monitorComponent);
    boolean active = activeComponents.contains(importerExporterName);
    LOGGER.info("gateway {} {}:{} active:{}", monitorComponent.name().toLowerCase(),
        (isImporter ? "importer" : "exporter"), importerExporterName, active);
    return active;
}
 
源代码3 项目: lams   文件: AnnotationConfigUtils.java
static void processCommonDefinitionAnnotations(AnnotatedBeanDefinition abd, AnnotatedTypeMetadata metadata) {
	if (metadata.isAnnotated(Lazy.class.getName())) {
		abd.setLazyInit(attributesFor(metadata, Lazy.class).getBoolean("value"));
	}
	else if (abd.getMetadata() != metadata && abd.getMetadata().isAnnotated(Lazy.class.getName())) {
		abd.setLazyInit(attributesFor(abd.getMetadata(), Lazy.class).getBoolean("value"));
	}

	if (metadata.isAnnotated(Primary.class.getName())) {
		abd.setPrimary(true);
	}
	if (metadata.isAnnotated(DependsOn.class.getName())) {
		abd.setDependsOn(attributesFor(metadata, DependsOn.class).getStringArray("value"));
	}

	if (abd instanceof AbstractBeanDefinition) {
		AbstractBeanDefinition absBd = (AbstractBeanDefinition) abd;
		if (metadata.isAnnotated(Role.class.getName())) {
			absBd.setRole(attributesFor(metadata, Role.class).getNumber("value").intValue());
		}
		if (metadata.isAnnotated(Description.class.getName())) {
			absBd.setDescription(attributesFor(metadata, Description.class).getString("value"));
		}
	}
}
 
static void processCommonDefinitionAnnotations(AnnotatedBeanDefinition abd, AnnotatedTypeMetadata metadata) {
	if (metadata.isAnnotated(Lazy.class.getName())) {
		abd.setLazyInit(attributesFor(metadata, Lazy.class).getBoolean("value"));
	}
	else if (abd.getMetadata() != metadata && abd.getMetadata().isAnnotated(Lazy.class.getName())) {
		abd.setLazyInit(attributesFor(abd.getMetadata(), Lazy.class).getBoolean("value"));
	}

	if (metadata.isAnnotated(Primary.class.getName())) {
		abd.setPrimary(true);
	}
	if (metadata.isAnnotated(DependsOn.class.getName())) {
		abd.setDependsOn(attributesFor(metadata, DependsOn.class).getStringArray("value"));
	}

	if (abd instanceof AbstractBeanDefinition) {
		AbstractBeanDefinition absBd = (AbstractBeanDefinition) abd;
		if (metadata.isAnnotated(Role.class.getName())) {
			absBd.setRole(attributesFor(metadata, Role.class).getNumber("value").intValue());
		}
		if (metadata.isAnnotated(Description.class.getName())) {
			absBd.setDescription(attributesFor(metadata, Description.class).getString("value"));
		}
	}
}
 
源代码5 项目: micro-service   文件: MicroServiceCondition.java
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
	
	if (metadata.isAnnotated(Bean.class.getName())) {
		
		Map<String, Object> map = metadata.getAnnotationAttributes(Bean.class.getName());
		if(!CollectionUtils.isEmpty(map)) {
			
			String[] names = (String[]) map.get("name");
			if(ArrayUtils.isNotEmpty(names)) {
				
				for(String name : names) {
					
					if(StringUtils.isNotBlank(name) && name.endsWith("ConfigBean")) {
						return true;
					}
				}
			}
		}
	}
	
	return false;
}
 
static void processCommonDefinitionAnnotations(AnnotatedBeanDefinition abd, AnnotatedTypeMetadata metadata) {
	AnnotationAttributes lazy = attributesFor(metadata, Lazy.class);
	if (lazy != null) {
		abd.setLazyInit(lazy.getBoolean("value"));
	}
	else if (abd.getMetadata() != metadata) {
		lazy = attributesFor(abd.getMetadata(), Lazy.class);
		if (lazy != null) {
			abd.setLazyInit(lazy.getBoolean("value"));
		}
	}

	if (metadata.isAnnotated(Primary.class.getName())) {
		abd.setPrimary(true);
	}
	AnnotationAttributes dependsOn = attributesFor(metadata, DependsOn.class);
	if (dependsOn != null) {
		abd.setDependsOn(dependsOn.getStringArray("value"));
	}

	AnnotationAttributes role = attributesFor(metadata, Role.class);
	if (role != null) {
		abd.setRole(role.getNumber("value").intValue());
	}
	AnnotationAttributes description = attributesFor(metadata, Description.class);
	if (description != null) {
		abd.setDescription(description.getString("value"));
	}
}
 
static void processCommonDefinitionAnnotations(AnnotatedBeanDefinition abd, AnnotatedTypeMetadata metadata) {
	AnnotationAttributes lazy = attributesFor(metadata, Lazy.class);
	if (lazy != null) {
		abd.setLazyInit(lazy.getBoolean("value"));
	}
	else if (abd.getMetadata() != metadata) {
		lazy = attributesFor(abd.getMetadata(), Lazy.class);
		if (lazy != null) {
			abd.setLazyInit(lazy.getBoolean("value"));
		}
	}

	if (metadata.isAnnotated(Primary.class.getName())) {
		abd.setPrimary(true);
	}
	AnnotationAttributes dependsOn = attributesFor(metadata, DependsOn.class);
	if (dependsOn != null) {
		abd.setDependsOn(dependsOn.getStringArray("value"));
	}

	AnnotationAttributes role = attributesFor(metadata, Role.class);
	if (role != null) {
		abd.setRole(role.getNumber("value").intValue());
	}
	AnnotationAttributes description = attributesFor(metadata, Description.class);
	if (description != null) {
		abd.setDescription(description.getString("value"));
	}
}
 
源代码8 项目: juiser   文件: JuiserSpringSecurityCondition.java
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {

    ConditionMessage matchMessage = ConditionMessage.empty();

    boolean enabled = isSpringSecurityEnabled(context);

    if (metadata.isAnnotated(ConditionalOnJuiserSpringSecurityEnabled.class.getName())) {
        if (!enabled) {
            return ConditionOutcome.noMatch(
                ConditionMessage.forCondition(ConditionalOnJuiserSpringSecurityEnabled.class)
                    .didNotFind("spring security enabled").atAll());
        }
        matchMessage = matchMessage.andCondition(ConditionalOnJuiserSpringSecurityEnabled.class)
            .foundExactly("spring security enabled");
    }

    if (metadata.isAnnotated(ConditionalOnJuiserSpringSecurityDisabled.class.getName())) {
        if (enabled) {
            return ConditionOutcome.noMatch(
                ConditionMessage.forCondition(ConditionalOnJuiserSpringSecurityDisabled.class)
                    .didNotFind("spring security disabled").atAll());
        }
        matchMessage = matchMessage.andCondition(ConditionalOnJuiserSpringSecurityDisabled.class)
            .didNotFind("spring security disabled").atAll();
    }

    return ConditionOutcome.match(matchMessage);
}
 
源代码9 项目: apollo   文件: OnProfileCondition.java
private Set<String> retrieveAnnotatedProfiles(AnnotatedTypeMetadata metadata, String annotationType) {
  if (!metadata.isAnnotated(annotationType)) {
    return Collections.emptySet();
  }

  MultiValueMap<String, Object> attributes = metadata.getAllAnnotationAttributes(annotationType);

  if (attributes == null) {
    return Collections.emptySet();
  }

  Set<String> profiles = Sets.newHashSet();
  List<?> values = attributes.get("value");

  if (values != null) {
    for (Object value : values) {
      if (value instanceof String[]) {
        Collections.addAll(profiles, (String[]) value);
      }
      else {
        profiles.add((String) value);
      }
    }
  }

  return profiles;
}
 
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
		AnnotatedTypeMetadata metadata) {
	ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
	List<String> types = CompositeUtils
			.getCompositeTypeList(context.getEnvironment());

	// get EnvironmentRepository types from registered factories
	List<Class<? extends EnvironmentRepository>> repositoryTypes = new ArrayList<>();
	for (String type : types) {
		String factoryName = CompositeUtils.getFactoryName(type, beanFactory);
		Type[] actualTypeArguments = CompositeUtils
				.getEnvironmentRepositoryFactoryTypeParams(beanFactory, factoryName);
		Class<? extends EnvironmentRepository> repositoryType;
		repositoryType = (Class<? extends EnvironmentRepository>) actualTypeArguments[0];
		repositoryTypes.add(repositoryType);
	}

	boolean required = metadata
			.isAnnotated(ConditionalOnSearchPathLocator.class.getName());
	boolean foundSearchPathLocator = repositoryTypes.stream()
			.anyMatch(SearchPathLocator.class::isAssignableFrom);
	if (required && !foundSearchPathLocator) {
		return ConditionOutcome.noMatch(
				ConditionMessage.forCondition(ConditionalOnSearchPathLocator.class)
						.notAvailable(SearchPathLocator.class.getTypeName()));
	}
	if (!required && foundSearchPathLocator) {
		return ConditionOutcome.noMatch(ConditionMessage
				.forCondition(ConditionalOnMissingSearchPathLocator.class)
				.available(SearchPathLocator.class.getTypeName()));
	}
	return ConditionOutcome.match();
}