org.springframework.context.annotation.Condition Java Examples

The following examples show how to use org.springframework.context.annotation.Condition. 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: CompatibleOnEnabledEndpointCondition.java    From dubbo-spring-boot-project with Apache License 2.0 5 votes vote down vote up
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
    ClassLoader classLoader = context.getClassLoader();

    Condition condition = Stream.of(CONDITION_CLASS_NAMES)                         // Iterate class names
            .filter(className -> ClassUtils.isPresent(className, classLoader))     // Search class existing or not by name
            .findFirst()                                                           // Find the first candidate
            .map(className -> ClassUtils.resolveClassName(className, classLoader)) // Resolve class name to Class
            .filter(Condition.class::isAssignableFrom)                             // Accept the Condition implementation
            .map(BeanUtils::instantiateClass)                                      // Instantiate Class to be instance
            .map(Condition.class::cast)                                            // Cast the instance to be Condition one
            .orElse(NegativeCondition.INSTANCE);                                   // Or else get a negative condition

    return condition.matches(context, metadata);
}
 
Example #2
Source File: OAuth2ResourceServerConfiguration.java    From spring-security-oauth2-boot with Apache License 2.0 5 votes vote down vote up
public static boolean matches(ConditionContext context) {
	Class<AuthorizationServerEndpointsConfigurationBeanCondition> type = AuthorizationServerEndpointsConfigurationBeanCondition.class;
	Conditional conditional = AnnotationUtils.findAnnotation(type, Conditional.class);
	StandardAnnotationMetadata metadata = new StandardAnnotationMetadata(type);
	for (Class<? extends Condition> conditionType : conditional.value()) {
		Condition condition = BeanUtils.instantiateClass(conditionType);
		if (condition.matches(context, metadata)) {
			return true;
		}
	}
	return false;
}
 
Example #3
Source File: ConditionEvaluator.java    From spring-init with Apache License 2.0 4 votes vote down vote up
private Condition getCondition(String conditionClassName,
		@Nullable ClassLoader classloader) {
	Class<?> conditionClass = ClassUtils.resolveClassName(conditionClassName,
			classloader);
	return (Condition) BeanUtils.instantiateClass(conditionClass);
}