FilteringSpringBootCondition Class — spring-boot Architecture
Architecture documentation for the FilteringSpringBootCondition class in FilteringSpringBootCondition.java from the spring-boot codebase.
Entity Profile
Relationship Graph
Source Code
core/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/FilteringSpringBootCondition.java lines 42–160
abstract class FilteringSpringBootCondition extends SpringBootCondition
implements AutoConfigurationImportFilter, BeanFactoryAware, BeanClassLoaderAware {
@SuppressWarnings("NullAway.Init")
private BeanFactory beanFactory;
@SuppressWarnings("NullAway.Init")
private ClassLoader beanClassLoader;
@Override
public boolean[] match(@Nullable String[] autoConfigurationClasses,
AutoConfigurationMetadata autoConfigurationMetadata) {
ConditionEvaluationReport report = ConditionEvaluationReport.find(this.beanFactory);
@Nullable ConditionOutcome[] outcomes = getOutcomes(autoConfigurationClasses, autoConfigurationMetadata);
boolean[] match = new boolean[outcomes.length];
for (int i = 0; i < outcomes.length; i++) {
ConditionOutcome outcome = outcomes[i];
match[i] = (outcome == null || outcome.isMatch());
if (!match[i] && outcome != null) {
String autoConfigurationClass = autoConfigurationClasses[i];
Assert.state(autoConfigurationClass != null, "'autoConfigurationClass' must not be null");
logOutcome(autoConfigurationClass, outcome);
if (report != null) {
report.recordConditionEvaluation(autoConfigurationClass, this, outcome);
}
}
}
return match;
}
protected abstract @Nullable ConditionOutcome[] getOutcomes(@Nullable String[] autoConfigurationClasses,
AutoConfigurationMetadata autoConfigurationMetadata);
@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
this.beanFactory = beanFactory;
}
protected final BeanFactory getBeanFactory() {
return this.beanFactory;
}
protected final ClassLoader getBeanClassLoader() {
return this.beanClassLoader;
}
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
this.beanClassLoader = classLoader;
}
protected final List<String> filter(@Nullable Collection<String> classNames, ClassNameFilter classNameFilter,
@Nullable ClassLoader classLoader) {
if (CollectionUtils.isEmpty(classNames)) {
return Collections.emptyList();
}
List<String> matches = new ArrayList<>(classNames.size());
for (String candidate : classNames) {
if (classNameFilter.matches(candidate, classLoader)) {
matches.add(candidate);
}
}
return matches;
}
/**
* Slightly faster variant of {@link ClassUtils#forName(String, ClassLoader)} that
* doesn't deal with primitives, arrays or inner types.
* @param className the class name to resolve
* @param classLoader the class loader to use
* @return a resolved class
* @throws ClassNotFoundException if the class cannot be found
*/
protected static Class<?> resolve(String className, @Nullable ClassLoader classLoader)
throws ClassNotFoundException {
if (classLoader != null) {
return Class.forName(className, false, classLoader);
}
return Class.forName(className);
}
protected enum ClassNameFilter {
PRESENT {
@Override
public boolean matches(String className, @Nullable ClassLoader classLoader) {
return isPresent(className, classLoader);
}
},
MISSING {
@Override
public boolean matches(String className, @Nullable ClassLoader classLoader) {
return !isPresent(className, classLoader);
}
};
abstract boolean matches(String className, @Nullable ClassLoader classLoader);
private static boolean isPresent(String className, @Nullable ClassLoader classLoader) {
if (classLoader == null) {
classLoader = ClassUtils.getDefaultClassLoader();
}
try {
resolve(className, classLoader);
return true;
}
catch (Throwable ex) {
return false;
}
}
}
}
Domain
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free