提交 8f90eacd 编写于 作者: J Juergen Hoeller

Polishing

上级 aecf60d2
......@@ -42,9 +42,6 @@ import org.springframework.util.MultiValueMap;
*/
class ConditionEvaluator {
private static final String CONDITIONAL_ANNOTATION = Conditional.class.getName();
private final ConditionContextImpl context;
......@@ -52,10 +49,9 @@ class ConditionEvaluator {
* Create a new {@link ConditionEvaluator} instance.
*/
public ConditionEvaluator(BeanDefinitionRegistry registry, Environment environment,
ApplicationContext applicationContext, ClassLoader classLoader,
ResourceLoader resourceLoader) {
this.context = new ConditionContextImpl(registry, environment,
applicationContext, classLoader, resourceLoader);
ApplicationContext applicationContext, ClassLoader classLoader, ResourceLoader resourceLoader) {
this.context = new ConditionContextImpl(registry, environment, applicationContext, classLoader, resourceLoader);
}
......@@ -77,7 +73,7 @@ class ConditionEvaluator {
* @return if the item should be skipped
*/
public boolean shouldSkip(AnnotatedTypeMetadata metadata, ConfigurationPhase phase) {
if (metadata == null || !metadata.isAnnotated(CONDITIONAL_ANNOTATION)) {
if (metadata == null || !metadata.isAnnotated(Conditional.class.getName())) {
return false;
}
......@@ -108,16 +104,13 @@ class ConditionEvaluator {
@SuppressWarnings("unchecked")
private List<String[]> getConditionClasses(AnnotatedTypeMetadata metadata) {
MultiValueMap<String, Object> attributes = metadata.getAllAnnotationAttributes(
CONDITIONAL_ANNOTATION, true);
Object values = attributes == null ? null : attributes.get("value");
return (List<String[]>) (values == null ? Collections.emptyList() : values);
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());
}
private Condition getCondition(String conditionClassName,
ClassLoader classloader) {
Class<?> conditionClass = ClassUtils.resolveClassName(conditionClassName,
classloader);
private Condition getCondition(String conditionClassName, ClassLoader classloader) {
Class<?> conditionClass = ClassUtils.resolveClassName(conditionClassName, classloader);
return (Condition) BeanUtils.instantiateClass(conditionClass);
}
......@@ -139,7 +132,6 @@ class ConditionEvaluator {
private ResourceLoader resourceLoader;
public ConditionContextImpl(BeanDefinitionRegistry registry,
Environment environment, ApplicationContext applicationContext,
ClassLoader classLoader, ResourceLoader resourceLoader) {
......@@ -169,7 +161,7 @@ class ConditionEvaluator {
if (this.registry != null) {
return this.registry;
}
if(getBeanFactory() != null && getBeanFactory() instanceof BeanDefinitionRegistry) {
if (getBeanFactory() instanceof BeanDefinitionRegistry) {
return (BeanDefinitionRegistry) getBeanFactory();
}
return null;
......@@ -180,7 +172,7 @@ class ConditionEvaluator {
if (this.environment != null) {
return this.environment;
}
if (getRegistry() != null && getRegistry() instanceof EnvironmentCapable) {
if (getRegistry() instanceof EnvironmentCapable) {
return ((EnvironmentCapable) getRegistry()).getEnvironment();
}
return null;
......@@ -197,7 +189,7 @@ class ConditionEvaluator {
if (this.resourceLoader != null) {
return this.resourceLoader;
}
if (registry instanceof ResourceLoader) {
if (this.registry instanceof ResourceLoader) {
return (ResourceLoader) registry;
}
return null;
......@@ -219,7 +211,7 @@ class ConditionEvaluator {
if (this.applicationContext != null) {
return this.applicationContext;
}
if (getRegistry() != null && getRegistry() instanceof ApplicationContext) {
if (getRegistry() instanceof ApplicationContext) {
return (ApplicationContext) getRegistry();
}
return null;
......
......@@ -45,11 +45,11 @@ import org.springframework.core.env.ConfigurableEnvironment;
*
* <p>If a {@code @Configuration} class is marked with {@code @Profile}, all of the
* {@code @Bean} methods and {@link Import @Import} annotations associated with that class
* will be bypassed unless one or more the specified profiles are active. This is very
* will be bypassed unless one or more of the specified profiles are active. This is very
* similar to the behavior in Spring XML: if the {@code profile} attribute of the
* {@code beans} element is supplied e.g., {@code <beans profile="p1,p2">}, the
* {@code beans} element will not be parsed unless profiles 'p1' and/or 'p2' have been
* activated. Likewise, if a {@code @Component} or {@code @Configuration} class is marked
* activated. Likewise, if a {@code @Component} or {@code @Configuration} class is marked
* with {@code @Profile({"p1", "p2"})}, that class will not be registered/processed unless
* profiles 'p1' and/or 'p2' have been activated.
*
......@@ -74,7 +74,7 @@ import org.springframework.core.env.ConfigurableEnvironment;
* @see AbstractEnvironment#DEFAULT_PROFILES_PROPERTY_NAME
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.METHOD })
@Target({ElementType.TYPE, ElementType.METHOD})
@Conditional(ProfileCondition.class)
public @interface Profile {
......
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -746,7 +746,7 @@ public abstract class ClassUtils {
/**
* Return a public static method of a class.
* @param methodName the static method name
* @param clazz the class which defines the method
* @param clazz the class which defines the method
* @param args the parameter types to the method
* @return the static method, or {@code null} if no static method was found
* @throws IllegalArgumentException if the method name is blank or the clazz is null
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册