Skip to content

Commit a2bc381

Browse files
committed
Extract ProblemCollector interface
1 parent 60414c9 commit a2bc381

File tree

11 files changed

+55
-19
lines changed

11 files changed

+55
-19
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2002-2011 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.beans.factory.parsing;
18+
19+
/**
20+
* TODO SPR-7420: document
21+
*
22+
* @author Chris Beams
23+
* @since 3.1
24+
*/
25+
public interface ProblemCollector {
26+
27+
void error(String message);
28+
29+
void error(String message, Throwable cause);
30+
31+
void reportProblems(ProblemReporter reporter);
32+
33+
boolean hasErrors();
34+
35+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* @author Chris Beams
2828
* @since 3.1
2929
*/
30-
public class SimpleProblemCollector {
30+
public class SimpleProblemCollector implements ProblemCollector {
3131

3232
private Location location = null;
3333
private List<Problem> errors = new ArrayList<Problem>();

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import java.util.regex.Pattern;
2424

2525
import org.springframework.beans.BeanUtils;
26-
import org.springframework.beans.factory.parsing.SimpleProblemCollector;
26+
import org.springframework.beans.factory.parsing.ProblemCollector;
2727
import org.springframework.beans.factory.support.BeanDefinitionDefaults;
2828
import org.springframework.beans.factory.support.BeanNameGenerator;
2929
import org.springframework.context.ConfigurableApplicationContext;
@@ -289,7 +289,7 @@ static ComponentScanSpec forDelimitedPackages(String basePackages) {
289289
ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS));
290290
}
291291

292-
public void doValidate(SimpleProblemCollector problems) {
292+
public void doValidate(ProblemCollector problems) {
293293
if(this.basePackages.isEmpty()) {
294294
problems.error("At least one base package must be specified");
295295
}
@@ -336,7 +336,7 @@ else if ("no".equalsIgnoreCase((String)this.scopedProxyMode)) {
336336
}
337337
}
338338

339-
private static Object instantiateUserDefinedType(String description, Class<?> targetType, Object className, ClassLoader classLoader, SimpleProblemCollector problems) {
339+
private static Object instantiateUserDefinedType(String description, Class<?> targetType, Object className, ClassLoader classLoader, ProblemCollector problems) {
340340
Assert.isInstanceOf(String.class, className, "userType must be of type String");
341341
Assert.notNull(classLoader, "classLoader must not be null");
342342
Assert.notNull(targetType, "targetType must not be null");
@@ -406,7 +406,7 @@ private static class FilterTypeDescriptor {
406406
}
407407

408408
@SuppressWarnings("unchecked")
409-
TypeFilter createTypeFilter(SimpleProblemCollector problems) {
409+
TypeFilter createTypeFilter(ProblemCollector problems) {
410410
try {
411411
if ("annotation".equalsIgnoreCase(this.filterType)) {
412412
return new AnnotationTypeFilter((Class<Annotation>) this.classLoader.loadClass(this.expression));

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.context.config;
1818

1919
import org.springframework.beans.BeanUtils;
20+
import org.springframework.beans.factory.parsing.ProblemCollector;
2021
import org.springframework.beans.factory.parsing.ProblemReporter;
2122
import org.springframework.beans.factory.parsing.SimpleProblemCollector;
2223

@@ -42,13 +43,13 @@ protected AbstractFeatureSpecification(Class<? extends FeatureSpecificationExecu
4243
}
4344

4445
public final boolean validate(ProblemReporter problemReporter) {
45-
SimpleProblemCollector collector = new SimpleProblemCollector(this.source());
46+
ProblemCollector collector = new SimpleProblemCollector(this.source());
4647
this.doValidate(collector);
4748
collector.reportProblems(problemReporter);
4849
return collector.hasErrors() ? false : true;
4950
}
5051

51-
protected abstract void doValidate(SimpleProblemCollector reporter);
52+
protected abstract void doValidate(ProblemCollector problems);
5253

5354
public AbstractFeatureSpecification source(Object source) {
5455
this.source = source;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.context.annotation.configuration;
1818

19-
import org.springframework.beans.factory.parsing.SimpleProblemCollector;
19+
import org.springframework.beans.factory.parsing.ProblemCollector;
2020
import org.springframework.context.config.AbstractFeatureSpecification;
2121
import org.springframework.context.config.ExecutorContext;
2222
import org.springframework.context.config.FeatureSpecification;
@@ -33,7 +33,7 @@ public StubSpecification(Class<? extends FeatureSpecificationExecutor> excecutor
3333
}
3434

3535
@Override
36-
protected void doValidate(SimpleProblemCollector reporter) {
36+
protected void doValidate(ProblemCollector problems) {
3737
}
3838

3939
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.transaction.config;
1818

19-
import org.springframework.beans.factory.parsing.SimpleProblemCollector;
19+
import org.springframework.beans.factory.parsing.ProblemCollector;
2020
import org.springframework.context.config.AbstractFeatureSpecification;
2121
import org.springframework.context.config.AdviceMode;
2222
import org.springframework.context.config.FeatureSpecificationExecutor;
@@ -187,7 +187,7 @@ Object order() {
187187
}
188188

189189
@Override
190-
protected void doValidate(SimpleProblemCollector problems) {
190+
protected void doValidate(ProblemCollector problems) {
191191
if (this.mode instanceof String) {
192192
if (!ObjectUtils.containsConstant(AdviceMode.values(), (String)this.mode)) {
193193
problems.error("no such mode name: " + this.mode);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package org.springframework.web.servlet.config;
1717

18-
import org.springframework.beans.factory.parsing.SimpleProblemCollector;
18+
import org.springframework.beans.factory.parsing.ProblemCollector;
1919
import org.springframework.beans.factory.support.ManagedList;
2020
import org.springframework.context.config.AbstractFeatureSpecification;
2121
import org.springframework.context.config.FeatureSpecificationExecutor;
@@ -243,7 +243,7 @@ Object messageCodesResolver() {
243243
}
244244

245245
@Override
246-
protected void doValidate(SimpleProblemCollector reporter) {
246+
protected void doValidate(ProblemCollector problems) {
247247
}
248248

249249
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package org.springframework.web.servlet.config;
1717

18-
import org.springframework.beans.factory.parsing.SimpleProblemCollector;
18+
import org.springframework.beans.factory.parsing.ProblemCollector;
1919
import org.springframework.context.config.AbstractFeatureSpecification;
2020
import org.springframework.context.config.FeatureSpecificationExecutor;
2121
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
@@ -78,7 +78,7 @@ String defaultServletName() {
7878
}
7979

8080
@Override
81-
protected void doValidate(SimpleProblemCollector reporter) {
81+
protected void doValidate(ProblemCollector problems) {
8282
}
8383

8484
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.web.servlet.config;
1818

19-
import org.springframework.beans.factory.parsing.SimpleProblemCollector;
19+
import org.springframework.beans.factory.parsing.ProblemCollector;
2020
import org.springframework.context.config.AbstractFeatureSpecification;
2121
import org.springframework.context.config.FeatureSpecificationExecutor;
2222
import org.springframework.core.Ordered;
@@ -167,7 +167,7 @@ Object order() {
167167
}
168168

169169
@Override
170-
protected void doValidate(SimpleProblemCollector problems) {
170+
protected void doValidate(ProblemCollector problems) {
171171
if (!StringUtils.hasText(mapping)) {
172172
problems.error("Mapping is required");
173173
}

0 commit comments

Comments
 (0)