当前位置: 首页>>代码示例>>Java>>正文


Java ConditionContext类代码示例

本文整理汇总了Java中org.springframework.context.annotation.ConditionContext的典型用法代码示例。如果您正苦于以下问题:Java ConditionContext类的具体用法?Java ConditionContext怎么用?Java ConditionContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ConditionContext类属于org.springframework.context.annotation包,在下文中一共展示了ConditionContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getMatchOutcome

import org.springframework.context.annotation.ConditionContext; //导入依赖的package包/类
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
		AnnotatedTypeMetadata metadata) {
	ConfigurableEnvironment environment = (ConfigurableEnvironment) context
			.getEnvironment();
	ResourceProperties properties = new ResourceProperties();
	RelaxedDataBinder binder = new RelaxedDataBinder(properties, "spring.resources");
	binder.bind(new PropertySourcesPropertyValues(environment.getPropertySources()));
	Boolean match = properties.getChain().getEnabled();
	if (match == null) {
		boolean webJarsLocatorPresent = ClassUtils.isPresent(WEBJAR_ASSERT_LOCATOR,
				getClass().getClassLoader());
		return new ConditionOutcome(webJarsLocatorPresent,
				"Webjars locator (" + WEBJAR_ASSERT_LOCATOR + ") is "
						+ (webJarsLocatorPresent ? "present" : "absent"));
	}
	return new ConditionOutcome(match,
			"Resource chain is " + (match ? "enabled" : "disabled"));
}
 
开发者ID:philwebb,项目名称:spring-boot-concourse,代码行数:20,代码来源:OnEnabledResourceChainCondition.java

示例2: getMatchOutcome

import org.springframework.context.annotation.ConditionContext; //导入依赖的package包/类
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
		AnnotatedTypeMetadata metadata) {
	ConditionMessage.Builder message = ConditionMessage
			.forCondition("OAuth JWT Condition");
	Environment environment = context.getEnvironment();
	String keyValue = environment
			.getProperty("security.oauth2.resource.jwt.key-value");
	String keyUri = environment
			.getProperty("security.oauth2.resource.jwt.key-uri");
	if (StringUtils.hasText(keyValue) || StringUtils.hasText(keyUri)) {
		return ConditionOutcome
				.match(message.foundExactly("provided public key"));
	}
	return ConditionOutcome
			.noMatch(message.didNotFind("provided public key").atAll());
}
 
开发者ID:spring-projects,项目名称:spring-security-oauth2-boot,代码行数:18,代码来源:ResourceServerTokenServicesConfiguration.java

示例3: getMatchOutcome

import org.springframework.context.annotation.ConditionContext; //导入依赖的package包/类
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
		AnnotatedTypeMetadata metadata) {
	String[] enablers = context.getBeanFactory()
			.getBeanNamesForAnnotation(EnableOAuth2Sso.class);
	ConditionMessage.Builder message = ConditionMessage
			.forCondition("@EnableOAuth2Sso Condition");
	for (String name : enablers) {
		if (context.getBeanFactory().isTypeMatch(name,
				WebSecurityConfigurerAdapter.class)) {
			return ConditionOutcome.match(message
					.found("@EnableOAuth2Sso annotation on WebSecurityConfigurerAdapter")
					.items(name));
		}
	}
	return ConditionOutcome.noMatch(message.didNotFind(
			"@EnableOAuth2Sso annotation " + "on any WebSecurityConfigurerAdapter")
			.atAll());
}
 
开发者ID:spring-projects,项目名称:spring-security-oauth2-boot,代码行数:20,代码来源:EnableOAuth2SsoCondition.java

示例4: getMatchOutcome

import org.springframework.context.annotation.ConditionContext; //导入依赖的package包/类
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
		AnnotatedTypeMetadata metadata) {

	CloudFactory cloudFactory = new CloudFactory();
	try {
		Cloud cloud = cloudFactory.getCloud();
		List<ServiceInfo> serviceInfos = cloud.getServiceInfos();

		for (ServiceInfo serviceInfo : serviceInfos) {
			if (serviceInfo instanceof VaultServiceInfo) {
				return ConditionOutcome.match(String.format(
						"Found Vault service %s", serviceInfo.getId()));
			}
		}

		return ConditionOutcome.noMatch("No Vault service found");
	}
	catch (CloudException e) {
		return ConditionOutcome.noMatch("Not running in a Cloud");
	}
}
 
开发者ID:pivotal-cf,项目名称:spring-cloud-vault-connector,代码行数:23,代码来源:VaultConnectorBootstrapConfiguration.java

示例5: BeanSearchSpec

import org.springframework.context.annotation.ConditionContext; //导入依赖的package包/类
BeanSearchSpec(ConditionContext context, AnnotatedTypeMetadata metadata, Class<?> annotationType) {
    this.annotationType = annotationType;
    MultiValueMap<String, Object> attributes = metadata.getAllAnnotationAttributes(annotationType.getName(), true);
    collect(attributes, "name", this.names);
    collect(attributes, "value", this.types);
    collect(attributes, "type", this.types);
    collect(attributes, "annotation", this.annotations);
    collect(attributes, "ignored", this.ignoredTypes);
    collect(attributes, "ignoredType", this.ignoredTypes);
    this.strategy = (SearchStrategy) metadata.getAnnotationAttributes(annotationType.getName()).get("search");
    BeanTypeDeductionException deductionException = null;
    try {
        if (this.types.isEmpty() && this.names.isEmpty()) {
            addDeducedBeanType(context, metadata, this.types);
        }
    } catch (BeanTypeDeductionException ex) {
        deductionException = ex;
    }
    validate(deductionException);
}
 
开发者ID:drtrang,项目名称:spring-boot-autoconfigure,代码行数:21,代码来源:OnBeansCondition.java

示例6: getMatchOutcome

import org.springframework.context.annotation.ConditionContext; //导入依赖的package包/类
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
	final RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(context.getEnvironment(),
			"holon.swagger.");

	if (!resolver.getProperty("holon.swagger.enabled", boolean.class, true)) {
		return ConditionOutcome.noMatch(ConditionMessage.forCondition("SwaggerApiAutoDetectCondition")
				.because("holon.swagger.enabled is false"));
	}

	if (resolver.containsProperty("resourcePackage")) {
		return ConditionOutcome.noMatch(
				ConditionMessage.forCondition("SwaggerApiAutoDetectCondition").available("resourcePackage"));
	}
	Map<String, Object> ag = resolver.getSubProperties("apiGroups");
	if (ag != null && ag.size() > 0) {
		return ConditionOutcome
				.noMatch(ConditionMessage.forCondition("SwaggerApiAutoDetectCondition").available("apiGroups"));
	}
	return ConditionOutcome.match();
}
 
开发者ID:holon-platform,项目名称:holon-jaxrs,代码行数:22,代码来源:SwaggerApiAutoDetectCondition.java

示例7: getMatchOutcome

import org.springframework.context.annotation.ConditionContext; //导入依赖的package包/类
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
		AnnotatedTypeMetadata metadata) {
	ConditionMessage.Builder message = ConditionMessage
			.forCondition("EmbeddedDataSource");
	if (anyMatches(context, metadata, this.pooledCondition)) {
		return ConditionOutcome
				.noMatch(message.foundExactly("supported pooled data source"));
	}
	EmbeddedDatabaseType type = EmbeddedDatabaseConnection
			.get(context.getClassLoader()).getType();
	if (type == null) {
		return ConditionOutcome
				.noMatch(message.didNotFind("embedded database").atAll());
	}
	return ConditionOutcome.match(message.found("embedded database").items(type));
}
 
开发者ID:muxiangqiu,项目名称:spring-boot-multidatasource,代码行数:18,代码来源:DataSourceAutoConfiguration.java

示例8: getMatchOutcome

import org.springframework.context.annotation.ConditionContext; //导入依赖的package包/类
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
	Map<String, Object> attributes = metadata.getAnnotationAttributes(ConditionalOnPropertyPrefix.class.getName());
	if (attributes.containsKey("value")) {
		String prefix = (String) attributes.get("value");
		if (prefix != null && !prefix.trim().equals("")) {
			final String propertyPrefix = !prefix.endsWith(".") ? prefix + "." : prefix;
			ConfigPropertyProvider configPropertyProvider = EnvironmentConfigPropertyProvider
					.create(context.getEnvironment());
			Set<String> names = configPropertyProvider.getPropertyNames()
					.filter((n) -> n.startsWith(propertyPrefix)).collect(Collectors.toSet());
			if (!names.isEmpty()) {
				return ConditionOutcome.match();
			}
			return ConditionOutcome.noMatch(
					ConditionMessage.forCondition(ConditionalOnPropertyPrefix.class).notAvailable(propertyPrefix));
		}
	}
	return ConditionOutcome.match();
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:21,代码来源:OnPropertyPrefixCondition.java

示例9: getMatchOutcome

import org.springframework.context.annotation.ConditionContext; //导入依赖的package包/类
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
    AnnotatedTypeMetadata metadata) {
  String prefix = (String) attribute(metadata, "prefix");
  Class<?> value = (Class<?>) attribute(metadata, "value");
  ConfigurableEnvironment environment = (ConfigurableEnvironment) context.getEnvironment();
  try {
    new Binder(ConfigurationPropertySources.from(environment.getPropertySources()))
        .bind(prefix, Bindable.of(value))
        .orElseThrow(
            () -> new FatalBeanException("Could not bind DataSourceSettings properties"));
    return new ConditionOutcome(true, String.format("Map property [%s] is not empty", prefix));
  } catch (Exception e) {
    //ignore
  }
  return new ConditionOutcome(false, String.format("Map property [%s] is empty", prefix));
}
 
开发者ID:lord-of-code,项目名称:loc-framework,代码行数:18,代码来源:PrefixPropertyCondition.java

示例10: isSpringSecurityEnabled

import org.springframework.context.annotation.ConditionContext; //导入依赖的package包/类
private boolean isSpringSecurityEnabled(ConditionContext ctx) {

        boolean enabled = true;

        Environment env = ctx.getEnvironment();

        for (String propName : props) {
            if (env.containsProperty(propName)) {
                if (!Boolean.parseBoolean(env.getProperty(propName))) {
                    enabled = false;
                    break;
                }
            }
        }

        if (enabled) {
            enabled = ClassUtils.isPresent(SPRING_SEC_CLASS_NAME, ctx.getClassLoader());
        }

        return enabled;
    }
 
开发者ID:juiser,项目名称:juiser,代码行数:22,代码来源:JuiserSpringSecurityCondition.java

示例11: isWebApplication

import org.springframework.context.annotation.ConditionContext; //导入依赖的package包/类
private ConditionOutcome isWebApplication(ConditionContext context,
		AnnotatedTypeMetadata metadata) {

	if (!ClassUtils.isPresent(WEB_CONTEXT_CLASS, context.getClassLoader())) {
		return ConditionOutcome.noMatch("web application classes not found");
	}

	if (context.getBeanFactory() != null) {
		String[] scopes = context.getBeanFactory().getRegisteredScopeNames();
		if (ObjectUtils.containsElement(scopes, "session")) {
			return ConditionOutcome.match("found web application 'session' scope");
		}
	}

	if (context.getEnvironment() instanceof StandardServletEnvironment) {
		return ConditionOutcome
				.match("found web application StandardServletEnvironment");
	}

	if (context.getResourceLoader() instanceof WebApplicationContext) {
		return ConditionOutcome.match("found web application WebApplicationContext");
	}

	return ConditionOutcome.noMatch("not a web application");
}
 
开发者ID:philwebb,项目名称:spring-boot-concourse,代码行数:26,代码来源:OnWebApplicationCondition.java

示例12: getMatchOutcome

import org.springframework.context.annotation.ConditionContext; //导入依赖的package包/类
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
		AnnotatedTypeMetadata metadata) {
	boolean webApplicationRequired = metadata
			.isAnnotated(ConditionalOnWebApplication.class.getName());
	ConditionOutcome webApplication = isWebApplication(context, metadata);

	if (webApplicationRequired && !webApplication.isMatch()) {
		return ConditionOutcome.noMatch(webApplication.getMessage());
	}

	if (!webApplicationRequired && webApplication.isMatch()) {
		return ConditionOutcome.noMatch(webApplication.getMessage());
	}

	return ConditionOutcome.match(webApplication.getMessage());
}
 
开发者ID:philwebb,项目名称:spring-boot-concourse,代码行数:18,代码来源:OnWebApplicationCondition.java

示例13: getMatchOutcome

import org.springframework.context.annotation.ConditionContext; //导入依赖的package包/类
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    if (!metadata.isAnnotated(ConditionalOnDevelopment.class.getName())) {
        return ConditionOutcome.match(StringUtils.EMPTY);
    }

    Boolean isDevMode = Env.getBoolean("application.devMode", null);
    if (null == isDevMode) {
        isDevMode = Env.getBoolean("application.dev-mode", null);
    }

    isDevMode = null == isDevMode ? false : isDevMode;

    if (!isDevMode) {
        return ConditionOutcome.noMatch("this is not dev-mode!");
    }

    return ConditionOutcome.match("this is dev-mode!");
}
 
开发者ID:lodsve,项目名称:lodsve-framework,代码行数:20,代码来源:OnDevelopmentConditional.java

示例14: BeanSearchSpec

import org.springframework.context.annotation.ConditionContext; //导入依赖的package包/类
BeanSearchSpec(ConditionContext context, AnnotatedTypeMetadata metadata,
		Class<?> annotationType) {
	this.annotationType = annotationType;
	MultiValueMap<String, Object> attributes = metadata
			.getAllAnnotationAttributes(annotationType.getName(), true);
	collect(attributes, "name", this.names);
	collect(attributes, "value", this.types);
	collect(attributes, "type", this.types);
	collect(attributes, "annotation", this.annotations);
	collect(attributes, "ignored", this.ignoredTypes);
	collect(attributes, "ignoredType", this.ignoredTypes);
	this.strategy = (SearchStrategy) metadata
			.getAnnotationAttributes(annotationType.getName()).get("search");
	BeanTypeDeductionException deductionException = null;
	try {
		if (this.types.isEmpty() && this.names.isEmpty()) {
			addDeducedBeanType(context, metadata, this.types);
		}
	}
	catch (BeanTypeDeductionException ex) {
		deductionException = ex;
	}
	validate(deductionException);
}
 
开发者ID:philwebb,项目名称:spring-boot-concourse,代码行数:25,代码来源:OnBeanCondition.java

示例15: getMatchOutcome

import org.springframework.context.annotation.ConditionContext; //导入依赖的package包/类
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
		AnnotatedTypeMetadata metadata) {
	RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(
			context.getEnvironment(), "spring.cache.");
	if (!resolver.containsProperty("type")) {
		return ConditionOutcome.match("Automatic cache type");
	}
	CacheType cacheType = CacheConfigurations
			.getType(((AnnotationMetadata) metadata).getClassName());
	String value = resolver.getProperty("type").replace("-", "_").toUpperCase();
	if (value.equals(cacheType.name())) {
		return ConditionOutcome.match("Cache type " + cacheType);
	}
	return ConditionOutcome.noMatch("Cache type " + value);
}
 
开发者ID:philwebb,项目名称:spring-boot-concourse,代码行数:17,代码来源:CacheCondition.java


注:本文中的org.springframework.context.annotation.ConditionContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。