Browse Source

Extract ProblemCollector interface

pull/7/head
Chris Beams 15 years ago
parent
commit
a2bc381ade
  1. 35
      org.springframework.beans/src/main/java/org/springframework/beans/factory/parsing/ProblemCollector.java
  2. 2
      org.springframework.beans/src/main/java/org/springframework/beans/factory/parsing/SimpleProblemCollector.java
  3. 8
      org.springframework.context/src/main/java/org/springframework/context/annotation/ComponentScanSpec.java
  4. 5
      org.springframework.context/src/main/java/org/springframework/context/config/AbstractFeatureSpecification.java
  5. 0
      org.springframework.context/src/main/java/org/springframework/context/config/SpecificationContext.java
  6. 4
      org.springframework.context/src/test/java/org/springframework/context/annotation/configuration/StubSpecification.java
  7. 4
      org.springframework.transaction/src/main/java/org/springframework/transaction/config/TxAnnotationDriven.java
  8. 4
      org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/MvcAnnotationDriven.java
  9. 4
      org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/MvcDefaultServletHandler.java
  10. 4
      org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/MvcResources.java
  11. 4
      org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/MvcViewControllers.java

35
org.springframework.beans/src/main/java/org/springframework/beans/factory/parsing/ProblemCollector.java

@ -0,0 +1,35 @@ @@ -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();
}

2
org.springframework.beans/src/main/java/org/springframework/beans/factory/parsing/SimpleProblemCollector.java

@ -27,7 +27,7 @@ import org.springframework.core.io.DescriptiveResource; @@ -27,7 +27,7 @@ import org.springframework.core.io.DescriptiveResource;
* @author Chris Beams
* @since 3.1
*/
public class SimpleProblemCollector {
public class SimpleProblemCollector implements ProblemCollector {
private Location location = null;
private List<Problem> errors = new ArrayList<Problem>();

8
org.springframework.context/src/main/java/org/springframework/context/annotation/ComponentScanSpec.java

@ -23,7 +23,7 @@ import java.util.List; @@ -23,7 +23,7 @@ import java.util.List;
import java.util.regex.Pattern;
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.BeanNameGenerator;
import org.springframework.context.ConfigurableApplicationContext;
@ -289,7 +289,7 @@ public final class ComponentScanSpec extends AbstractFeatureSpecification { @@ -289,7 +289,7 @@ public final class ComponentScanSpec extends AbstractFeatureSpecification {
ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS));
}
public void doValidate(SimpleProblemCollector problems) {
public void doValidate(ProblemCollector problems) {
if(this.basePackages.isEmpty()) {
problems.error("At least one base package must be specified");
}
@ -336,7 +336,7 @@ public final class ComponentScanSpec extends AbstractFeatureSpecification { @@ -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.notNull(classLoader, "classLoader must not be null");
Assert.notNull(targetType, "targetType must not be null");
@ -406,7 +406,7 @@ public final class ComponentScanSpec extends AbstractFeatureSpecification { @@ -406,7 +406,7 @@ public final class ComponentScanSpec extends AbstractFeatureSpecification {
}
@SuppressWarnings("unchecked")
TypeFilter createTypeFilter(SimpleProblemCollector problems) {
TypeFilter createTypeFilter(ProblemCollector problems) {
try {
if ("annotation".equalsIgnoreCase(this.filterType)) {
return new AnnotationTypeFilter((Class<Annotation>) this.classLoader.loadClass(this.expression));

5
org.springframework.context/src/main/java/org/springframework/context/config/AbstractFeatureSpecification.java

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
package org.springframework.context.config;
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.SimpleProblemCollector;
@ -42,13 +43,13 @@ public abstract class AbstractFeatureSpecification implements SourceAwareSpecifi @@ -42,13 +43,13 @@ public abstract class AbstractFeatureSpecification implements SourceAwareSpecifi
}
public final boolean validate(ProblemReporter problemReporter) {
SimpleProblemCollector collector = new SimpleProblemCollector(this.source());
ProblemCollector collector = new SimpleProblemCollector(this.source());
this.doValidate(collector);
collector.reportProblems(problemReporter);
return collector.hasErrors() ? false : true;
}
protected abstract void doValidate(SimpleProblemCollector reporter);
protected abstract void doValidate(ProblemCollector problems);
public AbstractFeatureSpecification source(Object source) {
this.source = source;

0
org.springframework.context/src/main/java/org/springframework/context/config/ExecutorContext.java → org.springframework.context/src/main/java/org/springframework/context/config/SpecificationContext.java

4
org.springframework.context/src/test/java/org/springframework/context/annotation/configuration/StubSpecification.java

@ -16,7 +16,7 @@ @@ -16,7 +16,7 @@
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.ExecutorContext;
import org.springframework.context.config.FeatureSpecification;
@ -33,7 +33,7 @@ public class StubSpecification extends AbstractFeatureSpecification { @@ -33,7 +33,7 @@ public class StubSpecification extends AbstractFeatureSpecification {
}
@Override
protected void doValidate(SimpleProblemCollector reporter) {
protected void doValidate(ProblemCollector problems) {
}
}

4
org.springframework.transaction/src/main/java/org/springframework/transaction/config/TxAnnotationDriven.java

@ -16,7 +16,7 @@ @@ -16,7 +16,7 @@
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.AdviceMode;
import org.springframework.context.config.FeatureSpecificationExecutor;
@ -187,7 +187,7 @@ public final class TxAnnotationDriven extends AbstractFeatureSpecification { @@ -187,7 +187,7 @@ public final class TxAnnotationDriven extends AbstractFeatureSpecification {
}
@Override
protected void doValidate(SimpleProblemCollector problems) {
protected void doValidate(ProblemCollector problems) {
if (this.mode instanceof String) {
if (!ObjectUtils.containsConstant(AdviceMode.values(), (String)this.mode)) {
problems.error("no such mode name: " + this.mode);

4
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/MvcAnnotationDriven.java

@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
*/
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.context.config.AbstractFeatureSpecification;
import org.springframework.context.config.FeatureSpecificationExecutor;
@ -243,7 +243,7 @@ public final class MvcAnnotationDriven extends AbstractFeatureSpecification { @@ -243,7 +243,7 @@ public final class MvcAnnotationDriven extends AbstractFeatureSpecification {
}
@Override
protected void doValidate(SimpleProblemCollector reporter) {
protected void doValidate(ProblemCollector problems) {
}
}

4
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/MvcDefaultServletHandler.java

@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
*/
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.FeatureSpecificationExecutor;
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
@ -78,7 +78,7 @@ public class MvcDefaultServletHandler extends AbstractFeatureSpecification { @@ -78,7 +78,7 @@ public class MvcDefaultServletHandler extends AbstractFeatureSpecification {
}
@Override
protected void doValidate(SimpleProblemCollector reporter) {
protected void doValidate(ProblemCollector problems) {
}
}

4
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/MvcResources.java

@ -16,7 +16,7 @@ @@ -16,7 +16,7 @@
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.FeatureSpecificationExecutor;
import org.springframework.core.Ordered;
@ -167,7 +167,7 @@ public final class MvcResources extends AbstractFeatureSpecification { @@ -167,7 +167,7 @@ public final class MvcResources extends AbstractFeatureSpecification {
}
@Override
protected void doValidate(SimpleProblemCollector problems) {
protected void doValidate(ProblemCollector problems) {
if (!StringUtils.hasText(mapping)) {
problems.error("Mapping is required");
}

4
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/MvcViewControllers.java

@ -19,7 +19,7 @@ import java.util.Collections; @@ -19,7 +19,7 @@ import java.util.Collections;
import java.util.HashMap;
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.FeatureSpecificationExecutor;
import org.springframework.util.StringUtils;
@ -72,7 +72,7 @@ public final class MvcViewControllers extends AbstractFeatureSpecification { @@ -72,7 +72,7 @@ public final class MvcViewControllers extends AbstractFeatureSpecification {
}
@Override
protected void doValidate(SimpleProblemCollector problems) {
protected void doValidate(ProblemCollector problems) {
if (mappings.size() == 0) {
problems.error("At least one ViewController must be defined");
}

Loading…
Cancel
Save