Removed Validator interface and inlined its implementations
This commit is contained in:
@@ -33,7 +33,6 @@ public final class BeanMethod implements Validatable {
|
||||
private final List<Annotation> annotations = new ArrayList<Annotation>();
|
||||
private transient ConfigurationClass declaringClass;
|
||||
private transient int lineNumber;
|
||||
private transient final List<Validator> validators = new ArrayList<Validator>();
|
||||
|
||||
public BeanMethod(String name, int modifiers, ModelClass returnType, Annotation... annotations) {
|
||||
Assert.hasText(name);
|
||||
@@ -117,10 +116,6 @@ public final class BeanMethod implements Validatable {
|
||||
return lineNumber;
|
||||
}
|
||||
|
||||
public void registerValidator(Validator validator) {
|
||||
validators.add(validator);
|
||||
}
|
||||
|
||||
public void validate(List<UsageError> errors) {
|
||||
|
||||
if (Modifier.isPrivate(getModifiers()))
|
||||
@@ -129,33 +124,16 @@ public final class BeanMethod implements Validatable {
|
||||
if (Modifier.isFinal(getModifiers()))
|
||||
errors.add(new FinalMethodError());
|
||||
|
||||
new BeanValidator().validate(this, errors);
|
||||
if (this.getAnnotation(ScopedProxy.class) == null)
|
||||
return;
|
||||
|
||||
Bean bean =this.getRequiredAnnotation(Bean.class);
|
||||
|
||||
if (bean.scope().equals(StandardScopes.SINGLETON)
|
||||
|| bean.scope().equals(StandardScopes.PROTOTYPE))
|
||||
errors.add(new InvalidScopedProxyDeclarationError(this));
|
||||
}
|
||||
|
||||
// public BeanDefinitionRegistrar getRegistrar() {
|
||||
// return getInstance(factoryAnno.registrar());
|
||||
// }
|
||||
|
||||
// public Set<Validator> getValidators() {
|
||||
// HashSet<Validator> validators = new HashSet<Validator>();
|
||||
//
|
||||
//// for (Class<? extends Validator> validatorType : factoryAnno.validators())
|
||||
//// validator.add(getInstance(validatorType));
|
||||
//
|
||||
// validators.add(IllegalB)
|
||||
//
|
||||
// return validators;
|
||||
// }
|
||||
|
||||
// public Callback getCallback() {
|
||||
// Class<? extends Callback> callbackType = factoryAnno.interceptor();
|
||||
//
|
||||
// if (callbackType.equals(NoOpInterceptor.class))
|
||||
// return NoOpInterceptor.INSTANCE;
|
||||
//
|
||||
// return getInstance(callbackType);
|
||||
// }
|
||||
//
|
||||
@Override
|
||||
public String toString() {
|
||||
String returnTypeName = returnType == null ? "<unknown>" : returnType.getSimpleName();
|
||||
@@ -227,31 +205,4 @@ public final class BeanMethod implements Validatable {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects any user errors when declaring {@link Bean}-annotated methods.
|
||||
*
|
||||
* @author Chris Beams
|
||||
*/
|
||||
class BeanValidator implements Validator {
|
||||
|
||||
public boolean supports(Object object) {
|
||||
return object instanceof BeanMethod;
|
||||
}
|
||||
|
||||
public void validate(Object object, List<UsageError> errors) {
|
||||
BeanMethod method = (BeanMethod) object;
|
||||
|
||||
if (method.getAnnotation(ScopedProxy.class) == null)
|
||||
return;
|
||||
|
||||
Bean bean = method.getRequiredAnnotation(Bean.class);
|
||||
|
||||
if (bean.scope().equals(StandardScopes.SINGLETON)
|
||||
|| bean.scope().equals(StandardScopes.PROTOTYPE))
|
||||
errors.add(new InvalidScopedProxyDeclarationError(method));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -43,7 +43,6 @@ public final class ConfigurationModel implements Validatable {
|
||||
|
||||
/* list is used because order and collection equality matters. */
|
||||
private final ArrayList<ConfigurationClass> configurationClasses = new ArrayList<ConfigurationClass>();
|
||||
private final ArrayList<Validator> validators = new ArrayList<Validator>();
|
||||
|
||||
/**
|
||||
* Add a {@link Configuration @Configuration} class to the model. Classes may be added
|
||||
@@ -57,10 +56,6 @@ public final class ConfigurationModel implements Validatable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public void registerValidator(Validator validator) {
|
||||
validators.add(validator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return configuration classes that have been directly added to this model.
|
||||
*
|
||||
@@ -96,7 +91,6 @@ public final class ConfigurationModel implements Validatable {
|
||||
*
|
||||
* @see ConfigurationClass#validate(java.util.List)
|
||||
* @see BeanMethod#validate(java.util.List)
|
||||
* @see Validator
|
||||
* @see UsageError
|
||||
*/
|
||||
public void validate(List<UsageError> errors) {
|
||||
@@ -104,27 +98,20 @@ public final class ConfigurationModel implements Validatable {
|
||||
if (configurationClasses.isEmpty())
|
||||
errors.add(new EmptyModelError());
|
||||
|
||||
// cascade through model and allow handlers to register validators
|
||||
// depending on where they are registered (with the model, the class, or the method)
|
||||
// they will be called directly or indirectly below
|
||||
// for (ConfigurationClass configClass : getAllConfigurationClasses()) {
|
||||
// for (BeanMethod method : configClass.getMethods()) {
|
||||
// for (Validator validator : method.getValidators()) {
|
||||
// if (validator.supports(method))
|
||||
// method.registerValidator(validator);
|
||||
// // TODO: support class-level validation
|
||||
// // if(validator.supports(configClass))
|
||||
// // configClass.registerValidator(validator);
|
||||
// if (validator.supports(this))
|
||||
// this.registerValidator(validator);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// process any validators registered directly with this model object
|
||||
// for (Validator validator : validators)
|
||||
// validator.validate(this, errors);
|
||||
new IllegalBeanOverrideValidator().validate(this, errors);
|
||||
// check for any illegal @Bean overriding
|
||||
ConfigurationClass[] allClasses = getAllConfigurationClasses();
|
||||
for (int i = 0; i < allClasses.length; i++) {
|
||||
for (BeanMethod method : allClasses[i].getMethods()) {
|
||||
Bean bean = method.getAnnotation(Bean.class);
|
||||
|
||||
if (bean == null || bean.allowOverriding())
|
||||
continue;
|
||||
|
||||
for (int j = i + 1; j < allClasses.length; j++)
|
||||
if (allClasses[j].hasMethod(method.getName()))
|
||||
errors.add(allClasses[i].new IllegalBeanOverrideError(allClasses[j], method));
|
||||
}
|
||||
}
|
||||
|
||||
// each individual configuration class must be well-formed
|
||||
// note that each configClass detects usage errors on its imports recursively
|
||||
@@ -176,39 +163,4 @@ public final class ConfigurationModel implements Validatable {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects any illegally-overridden {@link Bean} definitions within a particular
|
||||
* {@link ConfigurationModel}
|
||||
*
|
||||
* @see Bean#allowOverriding()
|
||||
*
|
||||
* @author Chris Beams
|
||||
*/
|
||||
class IllegalBeanOverrideValidator implements Validator {
|
||||
|
||||
public boolean supports(Object object) {
|
||||
return object instanceof ConfigurationModel;
|
||||
}
|
||||
|
||||
public void validate(Object object, List<UsageError> errors) {
|
||||
ConfigurationModel model = (ConfigurationModel) object;
|
||||
|
||||
ConfigurationClass[] allClasses = model.getAllConfigurationClasses();
|
||||
|
||||
for (int i = 0; i < allClasses.length; i++) {
|
||||
for (BeanMethod method : allClasses[i].getMethods()) {
|
||||
Bean bean = method.getAnnotation(Bean.class);
|
||||
|
||||
if (bean == null || bean.allowOverriding())
|
||||
continue;
|
||||
|
||||
for (int j = i + 1; j < allClasses.length; j++)
|
||||
if (allClasses[j].hasMethod(method.getName()))
|
||||
errors.add(allClasses[i].new IllegalBeanOverrideError(allClasses[j], method));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,6 @@ import java.util.List;
|
||||
/**
|
||||
* Indicates a type is able to be validated for errors.
|
||||
*
|
||||
* @see Validator
|
||||
*
|
||||
* @author Chris Beams
|
||||
*/
|
||||
interface Validatable {
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
package org.springframework.config.java;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
interface Validator {
|
||||
boolean supports(Object object);
|
||||
|
||||
void validate(Object object, List<UsageError> errors);
|
||||
}
|
||||
Reference in New Issue
Block a user