|
|
|
@ -20,6 +20,7 @@ import java.util.Arrays; |
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.logging.Log; |
|
|
|
import org.apache.commons.logging.Log; |
|
|
|
import org.apache.commons.logging.LogFactory; |
|
|
|
import org.apache.commons.logging.LogFactory; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.context.ApplicationContextInitializer; |
|
|
|
import org.springframework.context.ApplicationContextInitializer; |
|
|
|
import org.springframework.context.ConfigurableApplicationContext; |
|
|
|
import org.springframework.context.ConfigurableApplicationContext; |
|
|
|
import org.springframework.core.annotation.AnnotationAttributes; |
|
|
|
import org.springframework.core.annotation.AnnotationAttributes; |
|
|
|
@ -44,13 +45,11 @@ public class ContextConfigurationAttributes { |
|
|
|
|
|
|
|
|
|
|
|
private final Class<?> declaringClass; |
|
|
|
private final Class<?> declaringClass; |
|
|
|
|
|
|
|
|
|
|
|
private String[] locations; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Class<?>[] classes; |
|
|
|
private Class<?>[] classes; |
|
|
|
|
|
|
|
|
|
|
|
private final boolean inheritLocations; |
|
|
|
private String[] locations; |
|
|
|
|
|
|
|
|
|
|
|
private final Class<? extends ContextLoader> contextLoaderClass; |
|
|
|
private final boolean inheritLocations; |
|
|
|
|
|
|
|
|
|
|
|
private final Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>[] initializers; |
|
|
|
private final Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>[] initializers; |
|
|
|
|
|
|
|
|
|
|
|
@ -58,42 +57,8 @@ public class ContextConfigurationAttributes { |
|
|
|
|
|
|
|
|
|
|
|
private final String name; |
|
|
|
private final String name; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final Class<? extends ContextLoader> contextLoaderClass; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Resolve resource locations from the {@link ContextConfiguration#locations() locations} |
|
|
|
|
|
|
|
* and {@link ContextConfiguration#value() value} attributes of the supplied |
|
|
|
|
|
|
|
* {@link ContextConfiguration} annotation. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @throws IllegalStateException if both the locations and value attributes have been declared |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private static String[] resolveLocations(Class<?> declaringClass, ContextConfiguration contextConfiguration) { |
|
|
|
|
|
|
|
return resolveLocations(declaringClass, contextConfiguration.locations(), contextConfiguration.value()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Resolve resource locations from the supplied {@code locations} and |
|
|
|
|
|
|
|
* {@code value} arrays, which correspond to attributes of the same names in |
|
|
|
|
|
|
|
* the {@link ContextConfiguration} annotation. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @throws IllegalStateException if both the locations and value attributes have been declared |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private static String[] resolveLocations(Class<?> declaringClass, String[] locations, String[] value) { |
|
|
|
|
|
|
|
Assert.notNull(declaringClass, "declaringClass must not be null"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!ObjectUtils.isEmpty(value) && !ObjectUtils.isEmpty(locations)) { |
|
|
|
|
|
|
|
String msg = String.format("Test class [%s] has been configured with @ContextConfiguration's 'value' %s " |
|
|
|
|
|
|
|
+ "and 'locations' %s attributes. Only one declaration of resource " |
|
|
|
|
|
|
|
+ "locations is permitted per @ContextConfiguration annotation.", declaringClass.getName(), |
|
|
|
|
|
|
|
ObjectUtils.nullSafeToString(value), ObjectUtils.nullSafeToString(locations)); |
|
|
|
|
|
|
|
logger.error(msg); |
|
|
|
|
|
|
|
throw new IllegalStateException(msg); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (!ObjectUtils.isEmpty(value)) { |
|
|
|
|
|
|
|
locations = value; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return locations; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Construct a new {@link ContextConfigurationAttributes} instance for the |
|
|
|
* Construct a new {@link ContextConfigurationAttributes} instance for the |
|
|
|
@ -118,11 +83,9 @@ public class ContextConfigurationAttributes { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
public ContextConfigurationAttributes(Class<?> declaringClass, AnnotationAttributes annAttrs) { |
|
|
|
public ContextConfigurationAttributes(Class<?> declaringClass, AnnotationAttributes annAttrs) { |
|
|
|
this( |
|
|
|
this(declaringClass, |
|
|
|
declaringClass, |
|
|
|
|
|
|
|
resolveLocations(declaringClass, annAttrs.getStringArray("locations"), annAttrs.getStringArray("value")), |
|
|
|
resolveLocations(declaringClass, annAttrs.getStringArray("locations"), annAttrs.getStringArray("value")), |
|
|
|
annAttrs.getClassArray("classes"), |
|
|
|
annAttrs.getClassArray("classes"), annAttrs.getBoolean("inheritLocations"), |
|
|
|
annAttrs.getBoolean("inheritLocations"), |
|
|
|
|
|
|
|
(Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>[]) annAttrs.getClassArray("initializers"), |
|
|
|
(Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>[]) annAttrs.getClassArray("initializers"), |
|
|
|
annAttrs.getBoolean("inheritInitializers"), annAttrs.getString("name"), |
|
|
|
annAttrs.getBoolean("inheritInitializers"), annAttrs.getString("name"), |
|
|
|
(Class<? extends ContextLoader>) annAttrs.getClass("loader")); |
|
|
|
(Class<? extends ContextLoader>) annAttrs.getClass("loader")); |
|
|
|
@ -133,7 +96,6 @@ public class ContextConfigurationAttributes { |
|
|
|
* {@linkplain Class test class} that declared the |
|
|
|
* {@linkplain Class test class} that declared the |
|
|
|
* {@link ContextConfiguration @ContextConfiguration} annotation and its |
|
|
|
* {@link ContextConfiguration @ContextConfiguration} annotation and its |
|
|
|
* corresponding attributes. |
|
|
|
* corresponding attributes. |
|
|
|
* |
|
|
|
|
|
|
|
* @param declaringClass the test class that declared {@code @ContextConfiguration} |
|
|
|
* @param declaringClass the test class that declared {@code @ContextConfiguration} |
|
|
|
* @param locations the resource locations declared via {@code @ContextConfiguration} |
|
|
|
* @param locations the resource locations declared via {@code @ContextConfiguration} |
|
|
|
* @param classes the annotated classes declared via {@code @ContextConfiguration} |
|
|
|
* @param classes the annotated classes declared via {@code @ContextConfiguration} |
|
|
|
@ -148,6 +110,7 @@ public class ContextConfigurationAttributes { |
|
|
|
@Deprecated |
|
|
|
@Deprecated |
|
|
|
public ContextConfigurationAttributes(Class<?> declaringClass, String[] locations, Class<?>[] classes, |
|
|
|
public ContextConfigurationAttributes(Class<?> declaringClass, String[] locations, Class<?>[] classes, |
|
|
|
boolean inheritLocations, Class<? extends ContextLoader> contextLoaderClass) { |
|
|
|
boolean inheritLocations, Class<? extends ContextLoader> contextLoaderClass) { |
|
|
|
|
|
|
|
|
|
|
|
this(declaringClass, locations, classes, inheritLocations, null, true, null, contextLoaderClass); |
|
|
|
this(declaringClass, locations, classes, inheritLocations, null, true, null, contextLoaderClass); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -156,7 +119,6 @@ public class ContextConfigurationAttributes { |
|
|
|
* {@linkplain Class test class} that declared the |
|
|
|
* {@linkplain Class test class} that declared the |
|
|
|
* {@link ContextConfiguration @ContextConfiguration} annotation and its |
|
|
|
* {@link ContextConfiguration @ContextConfiguration} annotation and its |
|
|
|
* corresponding attributes. |
|
|
|
* corresponding attributes. |
|
|
|
* |
|
|
|
|
|
|
|
* @param declaringClass the test class that declared {@code @ContextConfiguration} |
|
|
|
* @param declaringClass the test class that declared {@code @ContextConfiguration} |
|
|
|
* @param locations the resource locations declared via {@code @ContextConfiguration} |
|
|
|
* @param locations the resource locations declared via {@code @ContextConfiguration} |
|
|
|
* @param classes the annotated classes declared via {@code @ContextConfiguration} |
|
|
|
* @param classes the annotated classes declared via {@code @ContextConfiguration} |
|
|
|
@ -167,10 +129,11 @@ public class ContextConfigurationAttributes { |
|
|
|
* @throws IllegalArgumentException if the {@code declaringClass} or {@code contextLoaderClass} is |
|
|
|
* @throws IllegalArgumentException if the {@code declaringClass} or {@code contextLoaderClass} is |
|
|
|
* {@code null} |
|
|
|
* {@code null} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public ContextConfigurationAttributes(Class<?> declaringClass, String[] locations, Class<?>[] classes, |
|
|
|
public ContextConfigurationAttributes( |
|
|
|
boolean inheritLocations, |
|
|
|
Class<?> declaringClass, String[] locations, Class<?>[] classes, boolean inheritLocations, |
|
|
|
Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>[] initializers, |
|
|
|
Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>[] initializers, |
|
|
|
boolean inheritInitializers, Class<? extends ContextLoader> contextLoaderClass) { |
|
|
|
boolean inheritInitializers, Class<? extends ContextLoader> contextLoaderClass) { |
|
|
|
|
|
|
|
|
|
|
|
this(declaringClass, locations, classes, inheritLocations, initializers, inheritInitializers, null, |
|
|
|
this(declaringClass, locations, classes, inheritLocations, initializers, inheritInitializers, null, |
|
|
|
contextLoaderClass); |
|
|
|
contextLoaderClass); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -180,7 +143,6 @@ public class ContextConfigurationAttributes { |
|
|
|
* {@linkplain Class test class} that declared the |
|
|
|
* {@linkplain Class test class} that declared the |
|
|
|
* {@link ContextConfiguration @ContextConfiguration} annotation and its |
|
|
|
* {@link ContextConfiguration @ContextConfiguration} annotation and its |
|
|
|
* corresponding attributes. |
|
|
|
* corresponding attributes. |
|
|
|
* |
|
|
|
|
|
|
|
* @param declaringClass the test class that declared {@code @ContextConfiguration} |
|
|
|
* @param declaringClass the test class that declared {@code @ContextConfiguration} |
|
|
|
* @param locations the resource locations declared via {@code @ContextConfiguration} |
|
|
|
* @param locations the resource locations declared via {@code @ContextConfiguration} |
|
|
|
* @param classes the annotated classes declared via {@code @ContextConfiguration} |
|
|
|
* @param classes the annotated classes declared via {@code @ContextConfiguration} |
|
|
|
@ -192,8 +154,8 @@ public class ContextConfigurationAttributes { |
|
|
|
* @throws IllegalArgumentException if the {@code declaringClass} or {@code contextLoaderClass} is |
|
|
|
* @throws IllegalArgumentException if the {@code declaringClass} or {@code contextLoaderClass} is |
|
|
|
* {@code null} |
|
|
|
* {@code null} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public ContextConfigurationAttributes(Class<?> declaringClass, String[] locations, Class<?>[] classes, |
|
|
|
public ContextConfigurationAttributes( |
|
|
|
boolean inheritLocations, |
|
|
|
Class<?> declaringClass, String[] locations, Class<?>[] classes, boolean inheritLocations, |
|
|
|
Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>[] initializers, |
|
|
|
Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>[] initializers, |
|
|
|
boolean inheritInitializers, String name, Class<? extends ContextLoader> contextLoaderClass) { |
|
|
|
boolean inheritInitializers, String name, Class<? extends ContextLoader> contextLoaderClass) { |
|
|
|
|
|
|
|
|
|
|
|
@ -202,9 +164,9 @@ public class ContextConfigurationAttributes { |
|
|
|
|
|
|
|
|
|
|
|
if (!ObjectUtils.isEmpty(locations) && !ObjectUtils.isEmpty(classes) && logger.isDebugEnabled()) { |
|
|
|
if (!ObjectUtils.isEmpty(locations) && !ObjectUtils.isEmpty(classes) && logger.isDebugEnabled()) { |
|
|
|
logger.debug(String.format( |
|
|
|
logger.debug(String.format( |
|
|
|
"Test class [%s] has been configured with @ContextConfiguration's 'locations' (or 'value') %s " |
|
|
|
"Test class [%s] has been configured with @ContextConfiguration's 'locations' (or 'value') %s " + |
|
|
|
+ "and 'classes' %s attributes. Most SmartContextLoader implementations support " |
|
|
|
"and 'classes' %s attributes. Most SmartContextLoader implementations support " + |
|
|
|
+ "only one declaration of resources per @ContextConfiguration annotation.", |
|
|
|
"only one declaration of resources per @ContextConfiguration annotation.", |
|
|
|
declaringClass.getName(), ObjectUtils.nullSafeToString(locations), |
|
|
|
declaringClass.getName(), ObjectUtils.nullSafeToString(locations), |
|
|
|
ObjectUtils.nullSafeToString(classes))); |
|
|
|
ObjectUtils.nullSafeToString(classes))); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -215,77 +177,112 @@ public class ContextConfigurationAttributes { |
|
|
|
this.inheritLocations = inheritLocations; |
|
|
|
this.inheritLocations = inheritLocations; |
|
|
|
this.initializers = initializers; |
|
|
|
this.initializers = initializers; |
|
|
|
this.inheritInitializers = inheritInitializers; |
|
|
|
this.inheritInitializers = inheritInitializers; |
|
|
|
this.name = StringUtils.hasText(name) ? name : null; |
|
|
|
this.name = (StringUtils.hasText(name) ? name : null); |
|
|
|
this.contextLoaderClass = contextLoaderClass; |
|
|
|
this.contextLoaderClass = contextLoaderClass; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Get the {@linkplain Class class} that declared the |
|
|
|
* Resolve resource locations from the {@link ContextConfiguration#locations() locations} |
|
|
|
* {@link ContextConfiguration @ContextConfiguration} annotation. |
|
|
|
* and {@link ContextConfiguration#value() value} attributes of the supplied |
|
|
|
* |
|
|
|
* {@link ContextConfiguration} annotation. |
|
|
|
* @return the declaring class; never {@code null} |
|
|
|
* @throws IllegalStateException if both the locations and value attributes have been declared |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Class<?> getDeclaringClass() { |
|
|
|
private static String[] resolveLocations(Class<?> declaringClass, ContextConfiguration contextConfiguration) { |
|
|
|
return declaringClass; |
|
|
|
return resolveLocations(declaringClass, contextConfiguration.locations(), contextConfiguration.value()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Get the resource locations that were declared via |
|
|
|
* Resolve resource locations from the supplied {@code locations} and |
|
|
|
* {@link ContextConfiguration @ContextConfiguration}. |
|
|
|
* {@code value} arrays, which correspond to attributes of the same names in |
|
|
|
* |
|
|
|
* the {@link ContextConfiguration} annotation. |
|
|
|
* <p>Note: this is a mutable property. The returned value may therefore |
|
|
|
* @throws IllegalStateException if both the locations and value attributes have been declared |
|
|
|
* represent a <em>processed</em> value that does not match the original value |
|
|
|
|
|
|
|
* declared via {@link ContextConfiguration @ContextConfiguration}. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return the resource locations; potentially {@code null} or <em>empty</em> |
|
|
|
|
|
|
|
* @see ContextConfiguration#value |
|
|
|
|
|
|
|
* @see ContextConfiguration#locations |
|
|
|
|
|
|
|
* @see #setLocations(String[]) |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public String[] getLocations() { |
|
|
|
private static String[] resolveLocations(Class<?> declaringClass, String[] locations, String[] value) { |
|
|
|
|
|
|
|
Assert.notNull(declaringClass, "declaringClass must not be null"); |
|
|
|
|
|
|
|
if (!ObjectUtils.isEmpty(value) && !ObjectUtils.isEmpty(locations)) { |
|
|
|
|
|
|
|
throw new IllegalStateException(String.format("Test class [%s] has been configured with " + |
|
|
|
|
|
|
|
"@ContextConfiguration's 'value' %s and 'locations' %s attributes. Only one declaration " + |
|
|
|
|
|
|
|
"of resource locations is permitted per @ContextConfiguration annotation.", |
|
|
|
|
|
|
|
declaringClass.getName(), ObjectUtils.nullSafeToString(value), ObjectUtils.nullSafeToString(locations))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (!ObjectUtils.isEmpty(value)) { |
|
|
|
|
|
|
|
locations = value; |
|
|
|
|
|
|
|
} |
|
|
|
return locations; |
|
|
|
return locations; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set the <em>processed</em> resource locations, effectively overriding the |
|
|
|
* Get the {@linkplain Class class} that declared the |
|
|
|
|
|
|
|
* {@link ContextConfiguration @ContextConfiguration} annotation. |
|
|
|
|
|
|
|
* @return the declaring class (never {@code null}) |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public Class<?> getDeclaringClass() { |
|
|
|
|
|
|
|
return this.declaringClass; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Set the <em>processed</em> annotated classes, effectively overriding the |
|
|
|
* original value declared via {@link ContextConfiguration @ContextConfiguration}. |
|
|
|
* original value declared via {@link ContextConfiguration @ContextConfiguration}. |
|
|
|
* |
|
|
|
* @see #getClasses() |
|
|
|
* @see #getLocations() |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setLocations(String[] locations) { |
|
|
|
public void setClasses(Class<?>... classes) { |
|
|
|
this.locations = locations; |
|
|
|
this.classes = classes; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Get the annotated classes that were declared via |
|
|
|
* Get the annotated classes that were declared via |
|
|
|
* {@link ContextConfiguration @ContextConfiguration}. |
|
|
|
* {@link ContextConfiguration @ContextConfiguration}. |
|
|
|
* |
|
|
|
|
|
|
|
* <p>Note: this is a mutable property. The returned value may therefore |
|
|
|
* <p>Note: this is a mutable property. The returned value may therefore |
|
|
|
* represent a <em>processed</em> value that does not match the original value |
|
|
|
* represent a <em>processed</em> value that does not match the original value |
|
|
|
* declared via {@link ContextConfiguration @ContextConfiguration}. |
|
|
|
* declared via {@link ContextConfiguration @ContextConfiguration}. |
|
|
|
* |
|
|
|
|
|
|
|
* @return the annotated classes; potentially {@code null} or <em>empty</em> |
|
|
|
* @return the annotated classes; potentially {@code null} or <em>empty</em> |
|
|
|
* @see ContextConfiguration#classes |
|
|
|
* @see ContextConfiguration#classes |
|
|
|
* @see #setClasses(Class[]) |
|
|
|
* @see #setClasses(Class[]) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Class<?>[] getClasses() { |
|
|
|
public Class<?>[] getClasses() { |
|
|
|
return classes; |
|
|
|
return this.classes; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set the <em>processed</em> annotated classes, effectively overriding the |
|
|
|
* Determine if this {@code ContextConfigurationAttributes} instance has |
|
|
|
|
|
|
|
* class-based resources. |
|
|
|
|
|
|
|
* @return {@code true} if the {@link #getClasses() classes} array is not empty |
|
|
|
|
|
|
|
* @see #hasResources() |
|
|
|
|
|
|
|
* @see #hasLocations() |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public boolean hasClasses() { |
|
|
|
|
|
|
|
return !ObjectUtils.isEmpty(getClasses()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Set the <em>processed</em> resource locations, effectively overriding the |
|
|
|
* original value declared via {@link ContextConfiguration @ContextConfiguration}. |
|
|
|
* original value declared via {@link ContextConfiguration @ContextConfiguration}. |
|
|
|
* |
|
|
|
* @see #getLocations() |
|
|
|
* @see #getClasses() |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setClasses(Class<?>[] classes) { |
|
|
|
public void setLocations(String... locations) { |
|
|
|
this.classes = classes; |
|
|
|
this.locations = locations; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Get the resource locations that were declared via |
|
|
|
|
|
|
|
* {@link ContextConfiguration @ContextConfiguration}. |
|
|
|
|
|
|
|
* <p>Note: this is a mutable property. The returned value may therefore |
|
|
|
|
|
|
|
* represent a <em>processed</em> value that does not match the original value |
|
|
|
|
|
|
|
* declared via {@link ContextConfiguration @ContextConfiguration}. |
|
|
|
|
|
|
|
* @return the resource locations; potentially {@code null} or <em>empty</em> |
|
|
|
|
|
|
|
* @see ContextConfiguration#value |
|
|
|
|
|
|
|
* @see ContextConfiguration#locations |
|
|
|
|
|
|
|
* @see #setLocations(String[]) |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public String[] getLocations() { |
|
|
|
|
|
|
|
return this.locations; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Determine if this {@code ContextConfigurationAttributes} instance has |
|
|
|
* Determine if this {@code ContextConfigurationAttributes} instance has |
|
|
|
* path-based resource locations. |
|
|
|
* path-based resource locations. |
|
|
|
* |
|
|
|
|
|
|
|
* @return {@code true} if the {@link #getLocations() locations} array is not empty |
|
|
|
* @return {@code true} if the {@link #getLocations() locations} array is not empty |
|
|
|
* @see #hasResources() |
|
|
|
* @see #hasResources() |
|
|
|
* @see #hasClasses() |
|
|
|
* @see #hasClasses() |
|
|
|
@ -294,79 +291,51 @@ public class ContextConfigurationAttributes { |
|
|
|
return !ObjectUtils.isEmpty(getLocations()); |
|
|
|
return !ObjectUtils.isEmpty(getLocations()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Determine if this {@code ContextConfigurationAttributes} instance has |
|
|
|
|
|
|
|
* class-based resources. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return {@code true} if the {@link #getClasses() classes} array is not empty |
|
|
|
|
|
|
|
* @see #hasResources() |
|
|
|
|
|
|
|
* @see #hasLocations() |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public boolean hasClasses() { |
|
|
|
|
|
|
|
return !ObjectUtils.isEmpty(getClasses()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Determine if this {@code ContextConfigurationAttributes} instance has |
|
|
|
* Determine if this {@code ContextConfigurationAttributes} instance has |
|
|
|
* either path-based resource locations or class-based resources. |
|
|
|
* either path-based resource locations or class-based resources. |
|
|
|
* |
|
|
|
|
|
|
|
* @return {@code true} if either the {@link #getLocations() locations} |
|
|
|
* @return {@code true} if either the {@link #getLocations() locations} |
|
|
|
* or the {@link #getClasses() classes} array is not empty |
|
|
|
* or the {@link #getClasses() classes} array is not empty |
|
|
|
* @see #hasLocations() |
|
|
|
* @see #hasLocations() |
|
|
|
* @see #hasClasses() |
|
|
|
* @see #hasClasses() |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean hasResources() { |
|
|
|
public boolean hasResources() { |
|
|
|
return hasLocations() || hasClasses(); |
|
|
|
return (hasLocations() || hasClasses()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Get the {@code inheritLocations} flag that was declared via |
|
|
|
* Get the {@code inheritLocations} flag that was declared via |
|
|
|
* {@link ContextConfiguration @ContextConfiguration}. |
|
|
|
* {@link ContextConfiguration @ContextConfiguration}. |
|
|
|
* |
|
|
|
|
|
|
|
* @return the {@code inheritLocations} flag |
|
|
|
* @return the {@code inheritLocations} flag |
|
|
|
* @see ContextConfiguration#inheritLocations |
|
|
|
* @see ContextConfiguration#inheritLocations |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean isInheritLocations() { |
|
|
|
public boolean isInheritLocations() { |
|
|
|
return inheritLocations; |
|
|
|
return this.inheritLocations; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Get the {@code ApplicationContextInitializer} classes that were declared via |
|
|
|
* Get the {@code ApplicationContextInitializer} classes that were declared via |
|
|
|
* {@link ContextConfiguration @ContextConfiguration}. |
|
|
|
* {@link ContextConfiguration @ContextConfiguration}. |
|
|
|
* |
|
|
|
|
|
|
|
* @return the {@code ApplicationContextInitializer} classes |
|
|
|
* @return the {@code ApplicationContextInitializer} classes |
|
|
|
* @since 3.2 |
|
|
|
* @since 3.2 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>[] getInitializers() { |
|
|
|
public Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>[] getInitializers() { |
|
|
|
return initializers; |
|
|
|
return this.initializers; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Get the {@code inheritInitializers} flag that was declared via |
|
|
|
* Get the {@code inheritInitializers} flag that was declared via |
|
|
|
* {@link ContextConfiguration @ContextConfiguration}. |
|
|
|
* {@link ContextConfiguration @ContextConfiguration}. |
|
|
|
* |
|
|
|
|
|
|
|
* @return the {@code inheritInitializers} flag |
|
|
|
* @return the {@code inheritInitializers} flag |
|
|
|
* @since 3.2 |
|
|
|
* @since 3.2 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean isInheritInitializers() { |
|
|
|
public boolean isInheritInitializers() { |
|
|
|
return inheritInitializers; |
|
|
|
return this.inheritInitializers; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Get the {@code ContextLoader} class that was declared via |
|
|
|
|
|
|
|
* {@link ContextConfiguration @ContextConfiguration}. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return the {@code ContextLoader} class
|
|
|
|
|
|
|
|
* @see ContextConfiguration#loader |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public Class<? extends ContextLoader> getContextLoaderClass() { |
|
|
|
|
|
|
|
return contextLoaderClass; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Get the name of the context hierarchy level that was declared via |
|
|
|
* Get the name of the context hierarchy level that was declared via |
|
|
|
* {@link ContextConfiguration @ContextConfiguration}. |
|
|
|
* {@link ContextConfiguration @ContextConfiguration}. |
|
|
|
* |
|
|
|
|
|
|
|
* @return the name of the context hierarchy level or {@code null} if not applicable |
|
|
|
* @return the name of the context hierarchy level or {@code null} if not applicable |
|
|
|
* @see ContextConfiguration#name() |
|
|
|
* @see ContextConfiguration#name() |
|
|
|
* @since 3.2.2 |
|
|
|
* @since 3.2.2 |
|
|
|
@ -376,24 +345,16 @@ public class ContextConfigurationAttributes { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Generate a unique hash code for all properties of this |
|
|
|
* Get the {@code ContextLoader} class that was declared via |
|
|
|
* {@code ContextConfigurationAttributes} instance excluding the |
|
|
|
* {@link ContextConfiguration @ContextConfiguration}. |
|
|
|
* {@linkplain #getName() name}. |
|
|
|
* @return the {@code ContextLoader} class
|
|
|
|
|
|
|
|
* @see ContextConfiguration#loader |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public Class<? extends ContextLoader> getContextLoaderClass() { |
|
|
|
public int hashCode() { |
|
|
|
return this.contextLoaderClass; |
|
|
|
final int prime = 31; |
|
|
|
|
|
|
|
int result = 1; |
|
|
|
|
|
|
|
result = prime * result + declaringClass.hashCode(); |
|
|
|
|
|
|
|
result = prime * result + Arrays.hashCode(locations); |
|
|
|
|
|
|
|
result = prime * result + Arrays.hashCode(classes); |
|
|
|
|
|
|
|
result = prime * result + (inheritLocations ? 1231 : 1237); |
|
|
|
|
|
|
|
result = prime * result + Arrays.hashCode(initializers); |
|
|
|
|
|
|
|
result = prime * result + (inheritInitializers ? 1231 : 1237); |
|
|
|
|
|
|
|
result = prime * result + contextLoaderClass.hashCode(); |
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Determine if the supplied object is equal to this |
|
|
|
* Determine if the supplied object is equal to this |
|
|
|
* {@code ContextConfigurationAttributes} instance by comparing both object's |
|
|
|
* {@code ContextConfigurationAttributes} instance by comparing both object's |
|
|
|
@ -406,56 +367,36 @@ public class ContextConfigurationAttributes { |
|
|
|
* {@link #getContextLoaderClass() ContextLoader class}. |
|
|
|
* {@link #getContextLoaderClass() ContextLoader class}. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean equals(Object obj) { |
|
|
|
public boolean equals(Object other) { |
|
|
|
|
|
|
|
if (this == other) { |
|
|
|
if (this == obj) { |
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
if (!(obj instanceof ContextConfigurationAttributes)) { |
|
|
|
if (!(other instanceof ContextConfigurationAttributes)) { |
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final ContextConfigurationAttributes that = (ContextConfigurationAttributes) obj; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.declaringClass == null) { |
|
|
|
|
|
|
|
if (that.declaringClass != null) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (!this.declaringClass.equals(that.declaringClass)) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!Arrays.equals(this.locations, that.locations)) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!Arrays.equals(this.classes, that.classes)) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.inheritLocations != that.inheritLocations) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!Arrays.equals(this.initializers, that.initializers)) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.inheritInitializers != that.inheritInitializers) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.contextLoaderClass == null) { |
|
|
|
|
|
|
|
if (that.contextLoaderClass != null) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (!this.contextLoaderClass.equals(that.contextLoaderClass)) { |
|
|
|
|
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
ContextConfigurationAttributes otherAttr = (ContextConfigurationAttributes) other; |
|
|
|
|
|
|
|
return (ObjectUtils.nullSafeEquals(this.declaringClass, otherAttr.declaringClass) && |
|
|
|
|
|
|
|
Arrays.equals(this.classes, otherAttr.classes)) && |
|
|
|
|
|
|
|
Arrays.equals(this.locations, otherAttr.locations) && |
|
|
|
|
|
|
|
this.inheritLocations == otherAttr.inheritLocations && |
|
|
|
|
|
|
|
Arrays.equals(this.initializers, otherAttr.initializers) && |
|
|
|
|
|
|
|
this.inheritInitializers == otherAttr.inheritInitializers && |
|
|
|
|
|
|
|
ObjectUtils.nullSafeEquals(this.name, otherAttr.name) && |
|
|
|
|
|
|
|
ObjectUtils.nullSafeEquals(this.contextLoaderClass, otherAttr.contextLoaderClass); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
/** |
|
|
|
|
|
|
|
* Generate a unique hash code for all properties of this |
|
|
|
|
|
|
|
* {@code ContextConfigurationAttributes} instance excluding the |
|
|
|
|
|
|
|
* {@linkplain #getName() name}. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public int hashCode() { |
|
|
|
|
|
|
|
int result = this.declaringClass.hashCode(); |
|
|
|
|
|
|
|
result = 31 * result + Arrays.hashCode(this.classes); |
|
|
|
|
|
|
|
result = 31 * result + Arrays.hashCode(this.locations); |
|
|
|
|
|
|
|
result = 31 * result + Arrays.hashCode(this.initializers); |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -464,16 +405,16 @@ public class ContextConfigurationAttributes { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public String toString() { |
|
|
|
public String toString() { |
|
|
|
return new ToStringCreator(this)//
|
|
|
|
return new ToStringCreator(this) |
|
|
|
.append("declaringClass", declaringClass.getName())//
|
|
|
|
.append("declaringClass", this.declaringClass.getName()) |
|
|
|
.append("locations", ObjectUtils.nullSafeToString(locations))//
|
|
|
|
.append("classes", ObjectUtils.nullSafeToString(this.classes)) |
|
|
|
.append("classes", ObjectUtils.nullSafeToString(classes))//
|
|
|
|
.append("locations", ObjectUtils.nullSafeToString(this.locations)) |
|
|
|
.append("inheritLocations", inheritLocations)//
|
|
|
|
.append("inheritLocations", this.inheritLocations) |
|
|
|
.append("initializers", ObjectUtils.nullSafeToString(initializers))//
|
|
|
|
.append("initializers", ObjectUtils.nullSafeToString(this.initializers)) |
|
|
|
.append("inheritInitializers", inheritInitializers)//
|
|
|
|
.append("inheritInitializers", this.inheritInitializers) |
|
|
|
.append("name", name)//
|
|
|
|
.append("name", this.name) |
|
|
|
.append("contextLoaderClass", contextLoaderClass.getName())//
|
|
|
|
.append("contextLoaderClass", this.contextLoaderClass.getName()) |
|
|
|
.toString(); |
|
|
|
.toString(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|