Author: mbenson
Date: Sun Oct 5 20:21:44 2014
New Revision: 1629535
URL: http://svn.apache.org/r1629535
Log:
tweaks and formatting
Modified:
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/AnyLiteral.java
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValAnnotatedType.java
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValBinding.java
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValInterceptor.java
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValInterceptorBean.java
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/DefaultLiteral.java
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/AnnotationConstraintBuilder.java
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/AnnotationProcessor.java
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheFactoryContext.java
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidationProvider.java
Modified:
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/AnyLiteral.java
URL:
http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/AnyLiteral.java?rev=1629535&r1=1629534&r2=1629535&view=diff
==============================================================================
---
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/AnyLiteral.java
(original)
+++
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/AnyLiteral.java
Sun Oct 5 20:21:44 2014
@@ -22,6 +22,11 @@ import javax.enterprise.inject.Any;
import javax.enterprise.util.AnnotationLiteral;
public class AnyLiteral extends AnnotationLiteral<Any> implements Any {
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Statically available instance.
+ */
public static final AnyLiteral INSTANCE = new AnyLiteral();
@Override
Modified:
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValAnnotatedType.java
URL:
http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValAnnotatedType.java?rev=1629535&r1=1629534&r2=1629535&view=diff
==============================================================================
---
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValAnnotatedType.java
(original)
+++
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValAnnotatedType.java
Sun Oct 5 20:21:44 2014
@@ -23,6 +23,7 @@ import javax.enterprise.inject.spi.Annot
import javax.enterprise.inject.spi.AnnotatedMethod;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.util.AnnotationLiteral;
+
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.HashSet;
@@ -37,7 +38,7 @@ public class BValAnnotatedType<A> implem
annotations = new
HashSet<Annotation>(annotatedType.getAnnotations().size());
annotations.addAll(annotatedType.getAnnotations());
- annotations.add(BValBindingLitteral.INSTANCE);
+ annotations.add(BValBindingLiteral.INSTANCE);
}
public Class<A> getJavaClass() {
@@ -67,7 +68,9 @@ public class BValAnnotatedType<A> implem
public <T extends Annotation> T getAnnotation(final Class<T>
annotationType) {
for (final Annotation ann : annotations) {
if (ann.annotationType().equals(annotationType)) {
- return (T) ann;
+ @SuppressWarnings("unchecked")
+ final T result = (T) ann;
+ return result;
}
}
return null;
@@ -86,8 +89,10 @@ public class BValAnnotatedType<A> implem
return false;
}
- public static class BValBindingLitteral extends
AnnotationLiteral<BValBinding> implements BValBinding {
- public static final Annotation INSTANCE = new BValBindingLitteral();
+ public static class BValBindingLiteral extends
AnnotationLiteral<BValBinding> implements BValBinding {
+ private static final long serialVersionUID = 1L;
+
+ public static final Annotation INSTANCE = new BValBindingLiteral();
public Class<? extends Annotation> annotationType() {
return BValBinding.class;
Modified:
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValBinding.java
URL:
http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValBinding.java?rev=1629535&r1=1629534&r2=1629535&view=diff
==============================================================================
---
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValBinding.java
(original)
+++
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValBinding.java
Sun Oct 5 20:21:44 2014
@@ -24,6 +24,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+//TODO javadoc
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@InterceptorBinding
Modified:
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValInterceptor.java
URL:
http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValInterceptor.java?rev=1629535&r1=1629534&r2=1629535&view=diff
==============================================================================
---
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValInterceptor.java
(original)
+++
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValInterceptor.java
Sun Oct 5 20:21:44 2014
@@ -35,6 +35,7 @@ import javax.validation.executable.Execu
import javax.validation.executable.ValidateOnExecution;
import javax.validation.metadata.ConstructorDescriptor;
import javax.validation.metadata.MethodDescriptor;
+
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayList;
@@ -52,9 +53,9 @@ import java.util.concurrent.CopyOnWriteA
@BValBinding
@Priority(4800) // TODO: maybe add it through ASM to be compliant with CDI 1.0
containers using simply this class as a template to generate another one for
CDI 1.1 impl
public class BValInterceptor {
- private Collection<ExecutableType> classConfiguration = null;
private final Map<Method, Boolean> methodConfiguration = new
ConcurrentHashMap<Method, Boolean>();
- private Boolean constructorValidated = null;
+ private Collection<ExecutableType> classConfiguration;
+ private Boolean constructorValidated;
@Inject
private Validator validator;
@@ -62,17 +63,19 @@ public class BValInterceptor {
@Inject
private BValExtension globalConfiguration;
- private ExecutableValidator executableValidator = null;
+ private ExecutableValidator executableValidator;
@AroundConstruct // TODO: see previous one
public Object construct(final InvocationContext context) throws Exception {
+ @SuppressWarnings("rawtypes")
final Constructor constructor = context.getConstructor();
final Class<?> targetClass = constructor.getDeclaringClass();
if (!isConstructorValidated(targetClass, constructor)) {
return context.proceed();
}
- final ConstructorDescriptor constraints =
validator.getConstraintsForClass(targetClass).getConstraintsForConstructor(constructor.getParameterTypes());
+ final ConstructorDescriptor constraints =
+
validator.getConstraintsForClass(targetClass).getConstraintsForConstructor(constructor.getParameterTypes());
if (constraints == null) { // surely implicit constructor
return context.proceed();
}
@@ -80,6 +83,7 @@ public class BValInterceptor {
initExecutableValidator();
{
+ @SuppressWarnings("unchecked")
final Set<ConstraintViolation<?>> violations =
executableValidator.validateConstructorParameters(constructor,
context.getParameters());
if (!violations.isEmpty()) {
throw new ConstraintViolationException(violations);
@@ -89,6 +93,7 @@ public class BValInterceptor {
final Object result = context.proceed();
{
+ @SuppressWarnings("unchecked")
final Set<ConstraintViolation<?>> violations =
executableValidator.validateConstructorReturnValue(constructor,
context.getTarget());
if (!violations.isEmpty()) {
throw new ConstraintViolationException(violations);
@@ -106,7 +111,9 @@ public class BValInterceptor {
return context.proceed();
}
- final MethodDescriptor constraintsForMethod =
validator.getConstraintsForClass(targetClass).getConstraintsForMethod(method.getName(),
method.getParameterTypes());
+ final MethodDescriptor constraintsForMethod =
+
validator.getConstraintsForClass(targetClass).getConstraintsForMethod(method.getName(),
+ method.getParameterTypes());
if (constraintsForMethod == null) {
return context.proceed();
}
@@ -114,7 +121,8 @@ public class BValInterceptor {
initExecutableValidator();
{
- final Set<ConstraintViolation<Object>> violations =
executableValidator.validateParameters(context.getTarget(), method,
context.getParameters());
+ final Set<ConstraintViolation<Object>> violations =
+ executableValidator.validateParameters(context.getTarget(),
method, context.getParameters());
if (!violations.isEmpty()) {
throw new ConstraintViolationException(violations);
}
@@ -123,7 +131,8 @@ public class BValInterceptor {
final Object result = context.proceed();
{
- final Set<ConstraintViolation<Object>> violations =
executableValidator.validateReturnValue(context.getTarget(), method, result);
+ final Set<ConstraintViolation<Object>> violations =
+ executableValidator.validateReturnValue(context.getTarget(),
method, result);
if (!violations.isEmpty()) {
throw new ConstraintViolationException(violations);
}
@@ -138,18 +147,22 @@ public class BValInterceptor {
if (constructorValidated == null) {
synchronized (this) {
if (constructorValidated == null) {
- final ValidateOnExecution annotation =
targetClass.getConstructor(constructor.getParameterTypes()).getAnnotation(ValidateOnExecution.class);
+ final ValidateOnExecution annotation =
+
targetClass.getConstructor(constructor.getParameterTypes()).getAnnotation(
+ ValidateOnExecution.class);
if (annotation == null) {
constructorValidated =
classConfiguration.contains(ExecutableType.CONSTRUCTORS);
} else {
final Collection<ExecutableType> types =
Arrays.asList(annotation.type());
- constructorValidated =
types.contains(ExecutableType.CONSTRUCTORS) ||
types.contains(ExecutableType.IMPLICIT) || types.contains(ExecutableType.ALL);
+ constructorValidated =
+ types.contains(ExecutableType.CONSTRUCTORS) ||
types.contains(ExecutableType.IMPLICIT)
+ || types.contains(ExecutableType.ALL);
}
}
}
}
- return constructorValidated;
+ return constructorValidated.booleanValue();
}
private boolean isMethodValidated(final Class<?> targetClass, final Method
method) throws NoSuchMethodException {
@@ -160,7 +173,8 @@ public class BValInterceptor {
synchronized (this) {
methodConfig = methodConfiguration.get(method);
if (methodConfig == null) {
- final List<Class<?>> classHierarchy =
ClassHelper.fillFullClassHierarchyAsList(new ArrayList<Class<?>>(),
targetClass);
+ final List<Class<?>> classHierarchy =
+ ClassHelper.fillFullClassHierarchyAsList(new
ArrayList<Class<?>>(), targetClass);
Class<?> lastClassWithTheMethod = null;
@@ -169,7 +183,9 @@ public class BValInterceptor {
ValidateOnExecution validateOnExecution = null;
for (final Class<?> c : classHierarchy) {
try {
- validateOnExecution =
c.getDeclaredMethod(method.getName(),
method.getParameterTypes()).getAnnotation(ValidateOnExecution.class);
+ validateOnExecution =
+ c.getDeclaredMethod(method.getName(),
method.getParameterTypes()).getAnnotation(
+ ValidateOnExecution.class);
if (lastClassWithTheMethod == null) {
lastClassWithTheMethod = c;
}
@@ -192,16 +208,16 @@ public class BValInterceptor {
} else {
final Collection<ExecutableType> config = new
HashSet<ExecutableType>();
for (final ExecutableType type :
validateOnExecution.type()) {
- if (ExecutableType.IMPLICIT.equals(type)) { // on
method it just means validate, even on getters
+ if (ExecutableType.IMPLICIT == type) { // on
method it just means validate, even on getters
config.add(ExecutableType.NON_GETTER_METHODS);
if (lastClassWithTheMethod == null) {
config.add(ExecutableType.GETTER_METHODS);
} // else the annotation was not on the method
so implicit doesn't mean getters
- } else if (ExecutableType.ALL.equals(type)) {
+ } else if (ExecutableType.ALL == type) {
config.add(ExecutableType.NON_GETTER_METHODS);
config.add(ExecutableType.GETTER_METHODS);
break;
- } else if (!ExecutableType.NONE.equals(type)) {
+ } else if (ExecutableType.NONE != type) {
config.add(type);
}
}
@@ -226,15 +242,15 @@ public class BValInterceptor {
classConfiguration.addAll(globalConfiguration.getGlobalExecutableTypes());
} else {
for (final ExecutableType type : annotation.type()) {
- if (ExecutableType.IMPLICIT.equals(type)) {
+ if (ExecutableType.IMPLICIT ==type) {
classConfiguration.add(ExecutableType.CONSTRUCTORS);
classConfiguration.add(ExecutableType.NON_GETTER_METHODS);
- } else if (ExecutableType.ALL.equals(type)) {
+ } else if (ExecutableType.ALL == type) {
classConfiguration.add(ExecutableType.CONSTRUCTORS);
classConfiguration.add(ExecutableType.NON_GETTER_METHODS);
classConfiguration.add(ExecutableType.GETTER_METHODS);
break;
- } else if (!ExecutableType.NONE.equals(type)) {
+ } else if (ExecutableType.NONE != type) {
classConfiguration.add(type);
}
}
@@ -256,11 +272,13 @@ public class BValInterceptor {
private static boolean doValidMethod(final Method method, final
Collection<ExecutableType> config) {
final boolean getter = isGetter(method);
- return (!getter && config.contains(ExecutableType.NON_GETTER_METHODS))
|| (getter && config.contains(ExecutableType.GETTER_METHODS));
+ return (!getter && config.contains(ExecutableType.NON_GETTER_METHODS))
+ || (getter && config.contains(ExecutableType.GETTER_METHODS));
}
private static boolean isGetter(final Method method) {
final String name = method.getName();
- return (name.startsWith("get") || name.startsWith("is")) &&
method.getReturnType() != Void.TYPE && method.getParameterTypes().length == 0;
+ return (name.startsWith("get") || name.startsWith("is")) &&
Void.TYPE.equals(method.getReturnType())
+ && method.getParameterTypes().length == 0;
}
}
Modified:
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValInterceptorBean.java
URL:
http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValInterceptorBean.java?rev=1629535&r1=1629534&r2=1629535&view=diff
==============================================================================
---
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValInterceptorBean.java
(original)
+++
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValInterceptorBean.java
Sun Oct 5 20:21:44 2014
@@ -49,7 +49,9 @@ public class BValInterceptorBean impleme
qualifiers.add(AnyLiteral.INSTANCE);
injectionTarget =
bm.createInjectionTarget(bm.createAnnotatedType(BValInterceptor.class));
- injectionPoints = Collections.singleton(InjectionPoint.class.cast(new
BValInterceptorInjectionPoint(this,
injectionTarget.getInjectionPoints().iterator().next())));
+ injectionPoints =
+ Collections.singleton(InjectionPoint.class.cast(new
BValInterceptorInjectionPoint(this, injectionTarget
+ .getInjectionPoints().iterator().next())));
}
public Set<Type> getTypes() {
Modified:
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/DefaultLiteral.java
URL:
http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/DefaultLiteral.java?rev=1629535&r1=1629534&r2=1629535&view=diff
==============================================================================
---
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/DefaultLiteral.java
(original)
+++
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/DefaultLiteral.java
Sun Oct 5 20:21:44 2014
@@ -22,6 +22,8 @@ import javax.enterprise.inject.Default;
import javax.enterprise.util.AnnotationLiteral;
public class DefaultLiteral extends AnnotationLiteral<Default> implements
Default {
+ private static final long serialVersionUID = 1L;
+
public static final DefaultLiteral INSTANCE = new DefaultLiteral();
@Override
Modified:
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/AnnotationConstraintBuilder.java
URL:
http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/AnnotationConstraintBuilder.java?rev=1629535&r1=1629534&r2=1629535&view=diff
==============================================================================
---
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/AnnotationConstraintBuilder.java
(original)
+++
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/AnnotationConstraintBuilder.java
Sun Oct 5 20:21:44 2014
@@ -47,6 +47,7 @@ import javax.validation.constraintvalida
import org.apache.bval.jsr.groups.GroupsComputer;
import org.apache.bval.jsr.xml.AnnotationProxyBuilder;
import org.apache.bval.util.AccessStrategy;
+import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.reflect.TypeUtils;
import org.apache.commons.weaver.privilizer.Privileged;
@@ -69,11 +70,14 @@ final class AnnotationConstraintBuilder<
* @param owner
* @param access
*/
- public AnnotationConstraintBuilder(ConstraintValidatorFactory factory,
Class<? extends ConstraintValidator<A, ?>>[] validatorClasses,
- A annotation, Class<?> owner,
AccessStrategy access, ConstraintTarget target) {
- boolean reportFromComposite =
+ public AnnotationConstraintBuilder(ConstraintValidatorFactory factory,
+ Class<? extends ConstraintValidator<A, ?>>[] validatorClasses, A
annotation, Class<?> owner,
+ AccessStrategy access, ConstraintTarget target) {
+ final boolean reportFromComposite =
annotation != null &&
annotation.annotationType().isAnnotationPresent(ReportAsSingleViolation.class);
- constraintValidation = new ConstraintValidation<A>(factory,
validatorClasses, annotation, owner, access, reportFromComposite, target);
+ constraintValidation =
+ new ConstraintValidation<A>(factory, validatorClasses, annotation,
owner, access, reportFromComposite,
+ target);
buildFromAnnotation();
}
@@ -182,12 +186,12 @@ final class AnnotationConstraintBuilder<
if (annotatedElt == 0 && param >= 1 &&
constraintValidation.getValidationAppliesTo() != null) { // pure cross param
throw new ConstraintDefinitionException("pure cross parameter
constraints shouldn't get validationAppliesTo attribute");
- } else {
- if (param >= 1 && annotatedElt >= 1 &&
constraintValidation.getValidationAppliesTo() == null) { // generic and cross
param
- throw new ConstraintDefinitionException("cross parameter AND
generic constraints should get validationAppliesTo attribute");
- } else if (param == 0 &&
constraintValidation.getValidationAppliesTo() != null) { // pure generic
- throw new ConstraintDefinitionException("pure generic
constraints shouldn't get validationAppliesTo attribute");
- }
+ }
+ if (param >= 1 && annotatedElt >= 1 &&
constraintValidation.getValidationAppliesTo() == null) { // generic and cross
param
+ throw new ConstraintDefinitionException("cross parameter AND
generic constraints should get validationAppliesTo attribute");
+ }
+ if (param == 0 && constraintValidation.getValidationAppliesTo() !=
null) { // pure generic
+ throw new ConstraintDefinitionException("pure generic constraints
shouldn't get validationAppliesTo attribute");
}
return new Pair(annotatedElt, param);
@@ -195,19 +199,20 @@ final class AnnotationConstraintBuilder<
private void buildValidationAppliesTo(final Method method) throws
InvocationTargetException, IllegalAccessException {
if (!TypeUtils.isAssignable(method.getReturnType(),
ConstraintAnnotationAttributes.VALIDATION_APPLIES_TO.getType())) {
- throw new ConstraintDefinitionException("Return type for
validationAppliesTo() must be of type " +
ConstraintAnnotationAttributes.VALIDATION_APPLIES_TO.getType());
+ throw new ConstraintDefinitionException("Return type for
validationAppliesTo() must be of type "
+ +
ConstraintAnnotationAttributes.VALIDATION_APPLIES_TO.getType());
}
final Object validationAppliesTo =
method.invoke(constraintValidation.getAnnotation());
- if (ConstraintTarget.class.isInstance(validationAppliesTo)) {
-
constraintValidation.setValidationAppliesTo(ConstraintTarget.class.cast(validationAppliesTo));
- } else {
+ if (!ConstraintTarget.class.isInstance(validationAppliesTo)) {
throw new ConstraintDefinitionException("validationAppliesTo type
is " + ConstraintTarget.class.getName());
}
+
constraintValidation.setValidationAppliesTo(ConstraintTarget.class.cast(validationAppliesTo));
}
private void buildGroups(final Method method) throws
IllegalAccessException, InvocationTargetException {
if (!TypeUtils.isAssignable(method.getReturnType(),
ConstraintAnnotationAttributes.GROUPS.getType())) {
- throw new ConstraintDefinitionException("Return type for groups()
must be of type " + ConstraintAnnotationAttributes.GROUPS.getType());
+ throw new ConstraintDefinitionException("Return type for groups()
must be of type "
+ + ConstraintAnnotationAttributes.GROUPS.getType());
}
final Object raw = method.invoke(constraintValidation.getAnnotation());
@@ -223,7 +228,7 @@ final class AnnotationConstraintBuilder<
garr = null;
}
- if (garr == null || garr.length == 0) {
+ if (ArrayUtils.isEmpty(garr)) {
garr = GroupsComputer.DEFAULT_GROUP;
}
constraintValidation.setGroups(garr);
@@ -232,15 +237,17 @@ final class AnnotationConstraintBuilder<
@SuppressWarnings("unchecked")
private void buildPayload(final Method method) throws
IllegalAccessException, InvocationTargetException {
if (!TypeUtils.isAssignable(method.getReturnType(),
ConstraintAnnotationAttributes.PAYLOAD.getType())) {
- throw new ConstraintDefinitionException("Return type for payload()
must be of type " + ConstraintAnnotationAttributes.PAYLOAD.getType());
+ throw new ConstraintDefinitionException("Return type for payload()
must be of type "
+ + ConstraintAnnotationAttributes.PAYLOAD.getType());
}
if (Object[].class.cast(method.getDefaultValue()).length > 0) {
throw new ConstraintDefinitionException("Default value for
payload() must be an empty array");
}
- Class<? extends Payload>[] payload_raw =
+ final Class<? extends Payload>[] payload_raw =
(Class<? extends Payload>[])
method.invoke(constraintValidation.getAnnotation());
- Set<Class<? extends Payload>> payloadSet;
+
+ final Set<Class<? extends Payload>> payloadSet;
if (payload_raw == null) {
payloadSet = Collections.<Class<? extends Payload>> emptySet();
} else {
@@ -278,10 +285,10 @@ final class AnnotationConstraintBuilder<
buildOverridesAttributes();
}
if (!overrides.isEmpty()) {
- int index = computeIndex(composite);
+ final int index = computeIndex(composite);
// Search for the overrides to apply
- ConstraintOverrides generalOverride =
findOverride(composite.getAnnotation().annotationType(), -1);
+ final ConstraintOverrides generalOverride =
findOverride(composite.getAnnotation().annotationType(), -1);
if (generalOverride != null) {
if (index > 0) {
throw new ConstraintDeclarationException("Wrong
OverridesAttribute declaration for "
@@ -291,11 +298,10 @@ final class AnnotationConstraintBuilder<
generalOverride.applyOn(composite);
}
- ConstraintOverrides override =
findOverride(composite.getAnnotation().annotationType(), index);
+ final ConstraintOverrides override =
findOverride(composite.getAnnotation().annotationType(), index);
if (override != null) {
override.applyOn(composite);
}
-
}
}
@@ -322,15 +328,15 @@ final class AnnotationConstraintBuilder<
private void buildOverridesAttributes() {
overrides = new LinkedList<ConstraintOverrides>();
for (Method method :
constraintValidation.getAnnotation().annotationType().getDeclaredMethods()) {
- OverridesAttribute.List annoOAL =
method.getAnnotation(OverridesAttribute.List.class);
- if (annoOAL != null) {
- for (OverridesAttribute annoOA : annoOAL.value()) {
- parseConstraintOverride(method.getName(), annoOA);
+ final OverridesAttribute.List overridesAttributeList =
method.getAnnotation(OverridesAttribute.List.class);
+ if (overridesAttributeList != null) {
+ for (OverridesAttribute overridesAttribute :
overridesAttributeList.value()) {
+ parseConstraintOverride(method.getName(),
overridesAttribute);
}
}
- OverridesAttribute annoOA =
method.getAnnotation(OverridesAttribute.class);
- if (annoOA != null) {
- parseConstraintOverride(method.getName(), annoOA);
+ final OverridesAttribute overridesAttribute =
method.getAnnotation(OverridesAttribute.class);
+ if (overridesAttribute != null) {
+ parseConstraintOverride(method.getName(), overridesAttribute);
}
}
}
@@ -376,12 +382,12 @@ final class AnnotationConstraintBuilder<
composite.getAttributes().putAll(values);
// And the annotation
- Annotation originalAnnot = composite.getAnnotation();
- AnnotationProxyBuilder<Annotation> apb = new
AnnotationProxyBuilder<Annotation>(originalAnnot);
+ final Annotation originalAnnot = composite.getAnnotation();
+ final AnnotationProxyBuilder<Annotation> apb = new
AnnotationProxyBuilder<Annotation>(originalAnnot);
for (String key : values.keySet()) {
apb.putValue(key, values.get(key));
}
- Annotation newAnnot = apb.createAnnotation();
+ final Annotation newAnnot = apb.createAnnotation();
((ConstraintValidation<Annotation>)
composite).setAnnotation(newAnnot);
}
}
Modified:
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/AnnotationProcessor.java
URL:
http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/AnnotationProcessor.java?rev=1629535&r1=1629534&r2=1629535&view=diff
==============================================================================
---
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/AnnotationProcessor.java
(original)
+++
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/AnnotationProcessor.java
Sun Oct 5 20:21:44 2014
@@ -78,8 +78,8 @@ public final class AnnotationProcessor {
* @throws IllegalAccessException
* @throws InvocationTargetException
*/
- public boolean processAnnotations(Meta prop, Class<?> owner,
AnnotatedElement element,
- AccessStrategy access, AppendValidation appender) throws
IllegalAccessException, InvocationTargetException {
+ public boolean processAnnotations(Meta prop, Class<?> owner,
AnnotatedElement element, AccessStrategy access,
+ AppendValidation appender) throws IllegalAccessException,
InvocationTargetException {
boolean changed = false;
for (final Annotation annotation : element.getDeclaredAnnotations()) {
@@ -112,7 +112,8 @@ public final class AnnotationProcessor {
* @throws InvocationTargetException
*/
public <A extends Annotation> boolean processAnnotation(A annotation, Meta
prop, Class<?> owner,
- AccessStrategy access, AppendValidation appender, boolean reflection)
throws IllegalAccessException, InvocationTargetException {
+ AccessStrategy access, AppendValidation appender, boolean reflection)
throws IllegalAccessException,
+ InvocationTargetException {
if (annotation instanceof Valid) {
return addAccessStrategy(prop, access);
}
@@ -134,7 +135,7 @@ public final class AnnotationProcessor {
* policy contains RUNTIME and if the annotation itself is annotated
* with javax.validation.Constraint.
*/
- Constraint vcAnno =
annotation.annotationType().getAnnotation(Constraint.class);
+ final Constraint vcAnno =
annotation.annotationType().getAnnotation(Constraint.class);
if (vcAnno != null) {
Class<? extends ConstraintValidator<A, ?>>[] validatorClasses;
validatorClasses = findConstraintValidatorClasses(annotation,
vcAnno);
@@ -177,13 +178,12 @@ public final class AnnotationProcessor {
AccessStrategy[] strategies =
prop.getFeature(Features.Property.REF_CASCADE);
if (strategies == null) {
strategies = new AccessStrategy[] { access };
- prop.putFeature(Features.Property.REF_CASCADE, strategies);
- } else if (!ArrayUtils.contains(strategies, access)) {
- AccessStrategy[] newStrategies = new
AccessStrategy[strategies.length + 1];
- System.arraycopy(strategies, 0, newStrategies, 0,
strategies.length);
- newStrategies[strategies.length] = access;
- prop.putFeature(Features.Property.REF_CASCADE, newStrategies);
+ } else if (ArrayUtils.contains(strategies, access)) {
+ return false;
+ } else {
+ strategies = ArrayUtils.add(strategies, access);
}
+ prop.putFeature(Features.Property.REF_CASCADE, strategies);
return true;
}
@@ -201,9 +201,9 @@ public final class AnnotationProcessor {
if (vcAnno == null) {
vcAnno =
annotation.annotationType().getAnnotation(Constraint.class);
}
- Class<? extends ConstraintValidator<A, ?>>[] validatorClasses;
- Class<A> annotationType = (Class<A>) annotation.annotationType();
- validatorClasses =
factoryContext.getFactory().getConstraintsCache().getConstraintValidators(annotationType);
+ final Class<A> annotationType = (Class<A>) annotation.annotationType();
+ Class<? extends ConstraintValidator<A, ?>>[] validatorClasses =
+
factoryContext.getFactory().getConstraintsCache().getConstraintValidators(annotationType);
if (validatorClasses == null) {
validatorClasses = (Class<? extends ConstraintValidator<A, ?>>[])
vcAnno.validatedBy();
if (validatorClasses.length == 0) {
@@ -237,17 +237,18 @@ public final class AnnotationProcessor {
Class<? extends ConstraintValidator<A, ?>>[] rawConstraintClasses,
Meta prop, Class<?> owner,
AccessStrategy access, AppendValidation appender) throws
IllegalAccessException, InvocationTargetException {
- Class<? extends ConstraintValidator<A, ?>>[] constraintClasses =
select(rawConstraintClasses, access);
+ final Class<? extends ConstraintValidator<A, ?>>[] constraintClasses =
select(rawConstraintClasses, access);
if (constraintClasses != null && constraintClasses.length == 0 &&
rawConstraintClasses.length > 0) {
return false;
}
final AnnotationConstraintBuilder<A> builder =
- new
AnnotationConstraintBuilder<A>(factoryContext.getConstraintValidatorFactory(),
constraintClasses, annotation, owner, access, null);
+ new
AnnotationConstraintBuilder<A>(factoryContext.getConstraintValidatorFactory(),
constraintClasses,
+ annotation, owner, access, null);
// JSR-303 3.4.4: Add implicit groups
if (prop != null && prop.getParentMetaBean() != null) {
- MetaBean parentMetaBean = prop.getParentMetaBean();
+ final MetaBean parentMetaBean = prop.getParentMetaBean();
// If:
// - the owner is an interface
// - the class of the metabean being build is different than the
@@ -284,26 +285,29 @@ public final class AnnotationProcessor {
}
private static <A extends Annotation> Class<? extends
ConstraintValidator<A, ?>>[] select(
- final Class<? extends ConstraintValidator<A, ?>>[]
rawConstraintClasses, final AccessStrategy access) {
+ final Class<? extends ConstraintValidator<A, ?>>[]
rawConstraintClasses, final AccessStrategy access) {
final boolean isReturn = ReturnAccess.class.isInstance(access);
final boolean isParam = ParametersAccess.class.isInstance(access);
if (rawConstraintClasses != null && (isReturn || isParam)) {
- final Collection<Class<? extends ConstraintValidator<A, ?>>>
selected = new ArrayList<Class<? extends ConstraintValidator<A, ?>>>();
+ final Collection<Class<? extends ConstraintValidator<A, ?>>>
selected =
+ new ArrayList<Class<? extends ConstraintValidator<A, ?>>>();
for (final Class<? extends ConstraintValidator<A, ?>> constraint :
rawConstraintClasses) {
final SupportedValidationTarget target =
constraint.getAnnotation(SupportedValidationTarget.class);
if (target == null && isReturn) {
selected.add(constraint);
} else if (target != null) {
for (final ValidationTarget validationTarget :
target.value()) {
- if (isReturn &&
ValidationTarget.ANNOTATED_ELEMENT.equals(validationTarget)) {
+ if (isReturn && ValidationTarget.ANNOTATED_ELEMENT ==
validationTarget) {
selected.add(constraint);
- } else if (isParam &&
ValidationTarget.PARAMETERS.equals(validationTarget)) {
+ } else if (isParam && ValidationTarget.PARAMETERS ==
validationTarget) {
selected.add(constraint);
}
}
+ }
}
- }
- return selected.toArray(new Class[selected.size()]);
+ @SuppressWarnings("unchecked")
+ final Class<? extends ConstraintValidator<A, ?>>[] result =
selected.toArray(new Class[selected.size()]);
+ return result;
}
return rawConstraintClasses;
}
Modified:
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheFactoryContext.java
URL:
http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheFactoryContext.java?rev=1629535&r1=1629534&r2=1629535&view=diff
==============================================================================
---
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheFactoryContext.java
(original)
+++
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheFactoryContext.java
Sun Oct 5 20:21:44 2014
@@ -192,19 +192,19 @@ public class ApacheFactoryContext implem
* @return a new instance of MetaBeanManager with adequate
MetaBeanFactories
*/
protected MetaBeanFinder buildMetaBeanFinder() {
- List<MetaBeanFactory> builders = new ArrayList<MetaBeanFactory>();
+ final List<MetaBeanFactory> builders = new
ArrayList<MetaBeanFactory>();
if (Boolean.parseBoolean(factory.getProperties().get(
ApacheValidatorConfiguration.Properties.ENABLE_INTROSPECTOR))) {
builders.add(new IntrospectorMetaBeanFactory());
}
- String[] factoryClassNames =
- StringUtils.split(
-
factory.getProperties().get(ApacheValidatorConfiguration.Properties.METABEAN_FACTORY_CLASSNAMES));
+ final String[] factoryClassNames =
+ StringUtils.split(factory.getProperties().get(
+
ApacheValidatorConfiguration.Properties.METABEAN_FACTORY_CLASSNAMES));
if (factoryClassNames != null) {
for (String clsName : factoryClassNames) {
// cast, relying on #createMetaBeanFactory to throw the
exception if incompatible:
@SuppressWarnings("unchecked")
- Class<? extends MetaBeanFactory> factoryClass = (Class<?
extends MetaBeanFactory>) loadClass(clsName);
+ final Class<? extends MetaBeanFactory> factoryClass = (Class<?
extends MetaBeanFactory>) loadClass(clsName);
builders.add(createMetaBeanFactory(factoryClass));
}
}
@@ -216,8 +216,9 @@ public class ApacheFactoryContext implem
builders.add(new JsrMetaBeanFactory(this));
}
@SuppressWarnings("deprecation")
- boolean enableMetaBeansXml =
Boolean.parseBoolean(factory.getProperties().get(
- ApacheValidatorConfiguration.Properties.ENABLE_METABEANS_XML));
+ final boolean enableMetaBeansXml =
+ Boolean.parseBoolean(factory.getProperties().get(
+ ApacheValidatorConfiguration.Properties.ENABLE_METABEANS_XML));
if (enableMetaBeansXml) {
XMLMetaBeanManagerCreator.addFactory(builders);
}
Modified:
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidationProvider.java
URL:
http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidationProvider.java?rev=1629535&r1=1629534&r2=1629535&view=diff
==============================================================================
---
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidationProvider.java
(original)
+++
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidationProvider.java
Sun Oct 5 20:21:44 2014
@@ -73,7 +73,7 @@ public class ApacheValidationProvider im
public ValidatorFactory buildValidatorFactory(final ConfigurationState
configuration) {
final Class<? extends ValidatorFactory> validatorFactoryClass;
try {
- String validatorFactoryClassname =
+ final String validatorFactoryClassname =
configuration.getProperties().get(ApacheValidatorConfiguration.Properties.VALIDATOR_FACTORY_CLASSNAME);
if (validatorFactoryClassname == null) {