Extract ProblemCollector interface
This commit is contained in:
parent
60414c9052
commit
a2bc381ade
|
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2002-2011 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.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.beans.factory.parsing;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO SPR-7420: document
|
||||||
|
*
|
||||||
|
* @author Chris Beams
|
||||||
|
* @since 3.1
|
||||||
|
*/
|
||||||
|
public interface ProblemCollector {
|
||||||
|
|
||||||
|
void error(String message);
|
||||||
|
|
||||||
|
void error(String message, Throwable cause);
|
||||||
|
|
||||||
|
void reportProblems(ProblemReporter reporter);
|
||||||
|
|
||||||
|
boolean hasErrors();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -27,7 +27,7 @@ import org.springframework.core.io.DescriptiveResource;
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
*/
|
*/
|
||||||
public class SimpleProblemCollector {
|
public class SimpleProblemCollector implements ProblemCollector {
|
||||||
|
|
||||||
private Location location = null;
|
private Location location = null;
|
||||||
private List<Problem> errors = new ArrayList<Problem>();
|
private List<Problem> errors = new ArrayList<Problem>();
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ import java.util.List;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.parsing.SimpleProblemCollector;
|
import org.springframework.beans.factory.parsing.ProblemCollector;
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionDefaults;
|
import org.springframework.beans.factory.support.BeanDefinitionDefaults;
|
||||||
import org.springframework.beans.factory.support.BeanNameGenerator;
|
import org.springframework.beans.factory.support.BeanNameGenerator;
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
|
|
@ -289,7 +289,7 @@ public final class ComponentScanSpec extends AbstractFeatureSpecification {
|
||||||
ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS));
|
ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doValidate(SimpleProblemCollector problems) {
|
public void doValidate(ProblemCollector problems) {
|
||||||
if(this.basePackages.isEmpty()) {
|
if(this.basePackages.isEmpty()) {
|
||||||
problems.error("At least one base package must be specified");
|
problems.error("At least one base package must be specified");
|
||||||
}
|
}
|
||||||
|
|
@ -336,7 +336,7 @@ public final class ComponentScanSpec extends AbstractFeatureSpecification {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Object instantiateUserDefinedType(String description, Class<?> targetType, Object className, ClassLoader classLoader, SimpleProblemCollector problems) {
|
private static Object instantiateUserDefinedType(String description, Class<?> targetType, Object className, ClassLoader classLoader, ProblemCollector problems) {
|
||||||
Assert.isInstanceOf(String.class, className, "userType must be of type String");
|
Assert.isInstanceOf(String.class, className, "userType must be of type String");
|
||||||
Assert.notNull(classLoader, "classLoader must not be null");
|
Assert.notNull(classLoader, "classLoader must not be null");
|
||||||
Assert.notNull(targetType, "targetType must not be null");
|
Assert.notNull(targetType, "targetType must not be null");
|
||||||
|
|
@ -406,7 +406,7 @@ public final class ComponentScanSpec extends AbstractFeatureSpecification {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
TypeFilter createTypeFilter(SimpleProblemCollector problems) {
|
TypeFilter createTypeFilter(ProblemCollector problems) {
|
||||||
try {
|
try {
|
||||||
if ("annotation".equalsIgnoreCase(this.filterType)) {
|
if ("annotation".equalsIgnoreCase(this.filterType)) {
|
||||||
return new AnnotationTypeFilter((Class<Annotation>) this.classLoader.loadClass(this.expression));
|
return new AnnotationTypeFilter((Class<Annotation>) this.classLoader.loadClass(this.expression));
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package org.springframework.context.config;
|
package org.springframework.context.config;
|
||||||
|
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.beans.factory.parsing.ProblemCollector;
|
||||||
import org.springframework.beans.factory.parsing.ProblemReporter;
|
import org.springframework.beans.factory.parsing.ProblemReporter;
|
||||||
import org.springframework.beans.factory.parsing.SimpleProblemCollector;
|
import org.springframework.beans.factory.parsing.SimpleProblemCollector;
|
||||||
|
|
||||||
|
|
@ -42,13 +43,13 @@ public abstract class AbstractFeatureSpecification implements SourceAwareSpecifi
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean validate(ProblemReporter problemReporter) {
|
public final boolean validate(ProblemReporter problemReporter) {
|
||||||
SimpleProblemCollector collector = new SimpleProblemCollector(this.source());
|
ProblemCollector collector = new SimpleProblemCollector(this.source());
|
||||||
this.doValidate(collector);
|
this.doValidate(collector);
|
||||||
collector.reportProblems(problemReporter);
|
collector.reportProblems(problemReporter);
|
||||||
return collector.hasErrors() ? false : true;
|
return collector.hasErrors() ? false : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void doValidate(SimpleProblemCollector reporter);
|
protected abstract void doValidate(ProblemCollector problems);
|
||||||
|
|
||||||
public AbstractFeatureSpecification source(Object source) {
|
public AbstractFeatureSpecification source(Object source) {
|
||||||
this.source = source;
|
this.source = source;
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
package org.springframework.context.annotation.configuration;
|
package org.springframework.context.annotation.configuration;
|
||||||
|
|
||||||
import org.springframework.beans.factory.parsing.SimpleProblemCollector;
|
import org.springframework.beans.factory.parsing.ProblemCollector;
|
||||||
import org.springframework.context.config.AbstractFeatureSpecification;
|
import org.springframework.context.config.AbstractFeatureSpecification;
|
||||||
import org.springframework.context.config.ExecutorContext;
|
import org.springframework.context.config.ExecutorContext;
|
||||||
import org.springframework.context.config.FeatureSpecification;
|
import org.springframework.context.config.FeatureSpecification;
|
||||||
|
|
@ -33,7 +33,7 @@ public class StubSpecification extends AbstractFeatureSpecification {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doValidate(SimpleProblemCollector reporter) {
|
protected void doValidate(ProblemCollector problems) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
package org.springframework.transaction.config;
|
package org.springframework.transaction.config;
|
||||||
|
|
||||||
import org.springframework.beans.factory.parsing.SimpleProblemCollector;
|
import org.springframework.beans.factory.parsing.ProblemCollector;
|
||||||
import org.springframework.context.config.AbstractFeatureSpecification;
|
import org.springframework.context.config.AbstractFeatureSpecification;
|
||||||
import org.springframework.context.config.AdviceMode;
|
import org.springframework.context.config.AdviceMode;
|
||||||
import org.springframework.context.config.FeatureSpecificationExecutor;
|
import org.springframework.context.config.FeatureSpecificationExecutor;
|
||||||
|
|
@ -187,7 +187,7 @@ public final class TxAnnotationDriven extends AbstractFeatureSpecification {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doValidate(SimpleProblemCollector problems) {
|
protected void doValidate(ProblemCollector problems) {
|
||||||
if (this.mode instanceof String) {
|
if (this.mode instanceof String) {
|
||||||
if (!ObjectUtils.containsConstant(AdviceMode.values(), (String)this.mode)) {
|
if (!ObjectUtils.containsConstant(AdviceMode.values(), (String)this.mode)) {
|
||||||
problems.error("no such mode name: " + this.mode);
|
problems.error("no such mode name: " + this.mode);
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package org.springframework.web.servlet.config;
|
package org.springframework.web.servlet.config;
|
||||||
|
|
||||||
import org.springframework.beans.factory.parsing.SimpleProblemCollector;
|
import org.springframework.beans.factory.parsing.ProblemCollector;
|
||||||
import org.springframework.beans.factory.support.ManagedList;
|
import org.springframework.beans.factory.support.ManagedList;
|
||||||
import org.springframework.context.config.AbstractFeatureSpecification;
|
import org.springframework.context.config.AbstractFeatureSpecification;
|
||||||
import org.springframework.context.config.FeatureSpecificationExecutor;
|
import org.springframework.context.config.FeatureSpecificationExecutor;
|
||||||
|
|
@ -243,7 +243,7 @@ public final class MvcAnnotationDriven extends AbstractFeatureSpecification {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doValidate(SimpleProblemCollector reporter) {
|
protected void doValidate(ProblemCollector problems) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package org.springframework.web.servlet.config;
|
package org.springframework.web.servlet.config;
|
||||||
|
|
||||||
import org.springframework.beans.factory.parsing.SimpleProblemCollector;
|
import org.springframework.beans.factory.parsing.ProblemCollector;
|
||||||
import org.springframework.context.config.AbstractFeatureSpecification;
|
import org.springframework.context.config.AbstractFeatureSpecification;
|
||||||
import org.springframework.context.config.FeatureSpecificationExecutor;
|
import org.springframework.context.config.FeatureSpecificationExecutor;
|
||||||
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
|
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
|
||||||
|
|
@ -78,7 +78,7 @@ public class MvcDefaultServletHandler extends AbstractFeatureSpecification {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doValidate(SimpleProblemCollector reporter) {
|
protected void doValidate(ProblemCollector problems) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
package org.springframework.web.servlet.config;
|
package org.springframework.web.servlet.config;
|
||||||
|
|
||||||
import org.springframework.beans.factory.parsing.SimpleProblemCollector;
|
import org.springframework.beans.factory.parsing.ProblemCollector;
|
||||||
import org.springframework.context.config.AbstractFeatureSpecification;
|
import org.springframework.context.config.AbstractFeatureSpecification;
|
||||||
import org.springframework.context.config.FeatureSpecificationExecutor;
|
import org.springframework.context.config.FeatureSpecificationExecutor;
|
||||||
import org.springframework.core.Ordered;
|
import org.springframework.core.Ordered;
|
||||||
|
|
@ -167,7 +167,7 @@ public final class MvcResources extends AbstractFeatureSpecification {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doValidate(SimpleProblemCollector problems) {
|
protected void doValidate(ProblemCollector problems) {
|
||||||
if (!StringUtils.hasText(mapping)) {
|
if (!StringUtils.hasText(mapping)) {
|
||||||
problems.error("Mapping is required");
|
problems.error("Mapping is required");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.springframework.beans.factory.parsing.SimpleProblemCollector;
|
import org.springframework.beans.factory.parsing.ProblemCollector;
|
||||||
import org.springframework.context.config.AbstractFeatureSpecification;
|
import org.springframework.context.config.AbstractFeatureSpecification;
|
||||||
import org.springframework.context.config.FeatureSpecificationExecutor;
|
import org.springframework.context.config.FeatureSpecificationExecutor;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
@ -72,7 +72,7 @@ public final class MvcViewControllers extends AbstractFeatureSpecification {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doValidate(SimpleProblemCollector problems) {
|
protected void doValidate(ProblemCollector problems) {
|
||||||
if (mappings.size() == 0) {
|
if (mappings.size() == 0) {
|
||||||
problems.error("At least one ViewController must be defined");
|
problems.error("At least one ViewController must be defined");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue