Java Code Examples for org.springframework.core.type.AnnotatedTypeMetadata#getAllAnnotationAttributes()

The following examples show how to use org.springframework.core.type.AnnotatedTypeMetadata#getAllAnnotationAttributes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OnBuildSystemCondition.java    From initializr with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean matches(ProjectDescription description, ConditionContext context,
		AnnotatedTypeMetadata metadata) {
	MultiValueMap<String, Object> attributes = metadata
			.getAllAnnotationAttributes(ConditionalOnBuildSystem.class.getName());
	String buildSystemId = (String) attributes.getFirst("value");
	String dialect = (String) attributes.getFirst("dialect");
	BuildSystem buildSystem = description.getBuildSystem();
	if (buildSystem.id().equals(buildSystemId)) {
		if (StringUtils.hasText(dialect)) {
			return dialect.equals(buildSystem.dialect());
		}
		return true;
	}
	return false;
}
 
Example 2
Source File: OnProfileCondition.java    From frostmourne with MIT License 6 votes vote down vote up
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;
}
 
Example 3
Source File: OnSystemPropertyCondition.java    From thinking-in-spring-boot-samples with Apache License 2.0 6 votes vote down vote up
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
    // 获取 ConditionalOnSystemProperty 所有的属性方法值
    MultiValueMap<String, Object> attributes = metadata.getAllAnnotationAttributes(ConditionalOnSystemProperty.class.getName());
    // 获取 ConditionalOnSystemProperty#name() 方法值(单值)
    String propertyName = (String) attributes.getFirst("name");
    // 获取 ConditionalOnSystemProperty#value() 方法值(单值)
    String propertyValue = (String) attributes.getFirst("value");
    // 获取 系统属性值
    String systemPropertyValue = System.getProperty(propertyName);
    // 比较 系统属性值 与 ConditionalOnSystemProperty#value() 方法值 是否相等
    if (Objects.equals(systemPropertyValue, propertyValue)) {
        System.out.printf("系统属性[名称 : %s] 找到匹配值 : %s\n",propertyName,propertyValue);
        return true;
    }
    return false;
}
 
Example 4
Source File: ImporterExporterComponentConditional.java    From sofa-lookout with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 5
Source File: MonitorComponentConditional.java    From sofa-lookout with Apache License 2.0 6 votes vote down vote up
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
    Environment env = context.getEnvironment();
    MultiValueMap<String, Object> map = metadata
        .getAllAnnotationAttributes(ConditionalOnMonitorComponent.class.getName());
    List<Object> value = map.get("value");
    if (CollectionUtils.isEmpty(value)) {
        return false;
    }
    String componentName = (String) value.get(0);
    List<String> activeComponents = getComponents(context);
    boolean active = activeComponents.contains(componentName);

    active = active ? isActiveByZoneInfo(env, componentName) : false;

    LOGGER.info("monitor component:{}, active:{}", componentName, active);
    return active;
}
 
Example 6
Source File: AliasPrototypeBeanFactory.java    From super-cloudops with Apache License 2.0 6 votes vote down vote up
/**
 * Get annotation delegate alias value.
 * 
 * @param metadata
 * @return
 */
@SuppressWarnings("rawtypes")
private String[] getAnnotationDelegateAliasValue(AnnotatedTypeMetadata metadata) {
	MultiValueMap<String, Object> annotationPropertyValues = metadata
			.getAllAnnotationAttributes(PrototypeAlias.class.getName());
	if (!CollectionUtils.isEmpty(annotationPropertyValues)) {
		/**
		 * See:{@link DelegateAlias}
		 */
		Object values = annotationPropertyValues.get("value");
		if (nonNull(values) && values instanceof List) {
			List _values = ((List) values);
			if (!isEmpty(_values)) {
				return (String[]) _values.get(0);
			}
		}
	}
	return null;
}
 
Example 7
Source File: ConditionEvaluator.java    From spring-init with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private List<String[]> getConditionClasses(AnnotatedTypeMetadata metadata) {
	MultiValueMap<String, Object> attributes = metadata
			.getAllAnnotationAttributes(Conditional.class.getName(), true);
	Object values = (attributes != null ? attributes.get("value") : null);
	return (List<String[]>) (values != null ? values : Collections.emptyList());
}
 
Example 8
Source File: OnMissingAmazonClientCondition.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
	MultiValueMap<String, Object> attributes = metadata.getAllAnnotationAttributes(
			ConditionalOnMissingAmazonClient.class.getName(), true);

	for (Object amazonClientClass : attributes.get("value")) {
		if (isAmazonClientMissing(context, (String) amazonClientClass)) {
			return true;
		}
	}

	return false;
}
 
Example 9
Source File: OnClassCondition.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
	MultiValueMap<String, Object> attributes = metadata
			.getAllAnnotationAttributes(ConditionalOnClass.class.getName(), true);
	String className = String.valueOf(attributes.get(AnnotationUtils.VALUE).get(0));
	return ClassUtils.isPresent(className, context.getClassLoader());
}
 
Example 10
Source File: PropertyExistsCondition.java    From logging-log4j-audit with Apache License 2.0 5 votes vote down vote up
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
    Environment env = context.getEnvironment();
    MultiValueMap<String, Object> attrs = metadata.getAllAnnotationAttributes(ConditionOnPropertyExists.class.getName());
    if (attrs != null) {
        Object value = attrs.get("value");
        return value != null && null != env && env.getProperty(value.toString()) != null;
    }
    return false;
}
 
Example 11
Source File: ProfileCondition.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
	if (context.getEnvironment() != null) {
		MultiValueMap<String, Object> attrs = metadata.getAllAnnotationAttributes(Profile.class.getName());
		if (attrs != null) {
			for (Object value : attrs.get("value")) {
				if (context.getEnvironment().acceptsProfiles(((String[]) value))) {
					return true;
				}
			}
			return false;
		}
	}
	return true;
}
 
Example 12
Source File: OnProfileCondition.java    From apollo with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 13
Source File: ProfileCondition.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
	if (context.getEnvironment() != null) {
		MultiValueMap<String, Object> attrs = metadata.getAllAnnotationAttributes(Profile.class.getName());
		if (attrs != null) {
			for (Object value : attrs.get("value")) {
				if (context.getEnvironment().acceptsProfiles(((String[]) value))) {
					return true;
				}
			}
			return false;
		}
	}
	return true;
}
 
Example 14
Source File: ProfileCondition.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
	MultiValueMap<String, Object> attrs = metadata.getAllAnnotationAttributes(Profile.class.getName());
	if (attrs != null) {
		for (Object value : attrs.get("value")) {
			if (context.getEnvironment().acceptsProfiles(Profiles.of((String[]) value))) {
				return true;
			}
		}
		return false;
	}
	return true;
}
 
Example 15
Source File: ProfileCondition.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
	MultiValueMap<String, Object> attrs = metadata.getAllAnnotationAttributes(Profile.class.getName());
	if (attrs != null) {
		for (Object value : attrs.get("value")) {
			if (context.getEnvironment().acceptsProfiles(Profiles.of((String[]) value))) {
				return true;
			}
		}
		return false;
	}
	return true;
}
 
Example 16
Source File: ConditionEvaluator.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private List<String[]> getConditionClasses(AnnotatedTypeMetadata metadata) {
	MultiValueMap<String, Object> attributes = metadata.getAllAnnotationAttributes(Conditional.class.getName(), true);
	Object values = (attributes != null ? attributes.get("value") : null);
	return (List<String[]>) (values != null ? values : Collections.emptyList());
}
 
Example 17
Source File: ConditionEvaluator.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private List<String[]> getConditionClasses(AnnotatedTypeMetadata metadata) {
	MultiValueMap<String, Object> attributes = metadata.getAllAnnotationAttributes(Conditional.class.getName(), true);
	Object values = (attributes != null ? attributes.get("value") : null);
	return (List<String[]>) (values != null ? values : Collections.emptyList());
}
 
Example 18
Source File: ConditionEvaluator.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@SuppressWarnings("unchecked")
private List<String[]> getConditionClasses(AnnotatedTypeMetadata metadata) {
	MultiValueMap<String, Object> attributes = metadata.getAllAnnotationAttributes(Conditional.class.getName(), true);
	Object values = (attributes != null ? attributes.get("value") : null);
	return (List<String[]>) (values != null ? values : Collections.emptyList());
}
 
Example 19
Source File: ConditionEvaluator.java    From java-technology-stack with MIT License 4 votes vote down vote up
@SuppressWarnings("unchecked")
private List<String[]> getConditionClasses(AnnotatedTypeMetadata metadata) {
	MultiValueMap<String, Object> attributes = metadata.getAllAnnotationAttributes(Conditional.class.getName(), true);
	Object values = (attributes != null ? attributes.get("value") : null);
	return (List<String[]>) (values != null ? values : Collections.emptyList());
}