Author: epbernard
Date: 2008-10-07 23:06:23 -0400 (Tue, 07 Oct 2008)
New Revision: 15265
Added:
validator/trunk/validation-api/src/main/java/javax/validation/ReportAsSingleInvalidConstraint.java
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ConstraintDescriptorImpl.java
validator/trunk/validation-api/src/main/java/javax/validation/ConstraintDescriptor.java
validator/trunk/validation-api/src/main/java/javax/validation/OverridesParameter.java
Log:
BVAL-31 add isReportAsSingleInvalidConstraint
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ConstraintDescriptorImpl.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ConstraintDescriptorImpl.java 2008-10-07
21:23:27 UTC (rev 15264)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ConstraintDescriptorImpl.java 2008-10-08
03:06:23 UTC (rev 15265)
@@ -29,6 +29,7 @@
import javax.validation.Constraint;
import javax.validation.ConstraintDescriptor;
import javax.validation.ValidationException;
+import javax.validation.ReportAsSingleInvalidConstraint;
/**
* Describe a single constraint.
@@ -36,10 +37,11 @@
* @author Emmanuel Bernard
*/
public class ConstraintDescriptorImpl implements ConstraintDescriptor {
- private Annotation annotation;
- private Constraint constraintImplementation;
- private Set<String> contexts;
- private Map<String, Object> parameters;
+ private final Annotation annotation;
+ private final Constraint constraintImplementation;
+ private final Set<String> contexts;
+ private final Map<String, Object> parameters;
+ private final boolean isReportAsSingleInvalidConstraint;
public ConstraintDescriptorImpl(Annotation annotation, String[] contexts, Constraint
validator) {
@@ -51,6 +53,9 @@
this.contexts.addAll( Arrays.asList( contexts ) );
this.constraintImplementation = validator;
this.parameters = getAnnotationParameters( annotation );
+ this.isReportAsSingleInvalidConstraint =
annotation.annotationType().isAnnotationPresent(
+ ReportAsSingleInvalidConstraint.class
+ );
}
/**
@@ -87,6 +92,10 @@
return Collections.emptySet();
}
+ public boolean isReportAsSingleInvalidConstraint() {
+ return isReportAsSingleInvalidConstraint;
+ }
+
private Map<String, Object> getAnnotationParameters(Annotation annotation) {
Method[] declaredMethods = annotation.annotationType().getDeclaredMethods();
Map<String, Object> parameters = new HashMap<String, Object>(
declaredMethods.length );
Modified:
validator/trunk/validation-api/src/main/java/javax/validation/ConstraintDescriptor.java
===================================================================
---
validator/trunk/validation-api/src/main/java/javax/validation/ConstraintDescriptor.java 2008-10-07
21:23:27 UTC (rev 15264)
+++
validator/trunk/validation-api/src/main/java/javax/validation/ConstraintDescriptor.java 2008-10-08
03:06:23 UTC (rev 15265)
@@ -31,7 +31,7 @@
/**
* Returns the annotation describing the constraint declaration.
* If a composing constraint, parameter values are reflecting
- * the overridden parameters form the main constraint
+ * the overridden parameters from the main constraint
*
* @return The annotation for this constraint.
*/
@@ -66,4 +66,9 @@
* @return a set of ConstraintDescriptor object or an empty set
*/
Set<ConstraintDescriptor> getComposingConstraints();
+
+ /**
+ * @return true if the constraint is annotated with @ReportAsSingleInvalidConstraint
+ */
+ boolean isReportAsSingleInvalidConstraint();
}
Modified:
validator/trunk/validation-api/src/main/java/javax/validation/OverridesParameter.java
===================================================================
---
validator/trunk/validation-api/src/main/java/javax/validation/OverridesParameter.java 2008-10-07
21:23:27 UTC (rev 15264)
+++
validator/trunk/validation-api/src/main/java/javax/validation/OverridesParameter.java 2008-10-08
03:06:23 UTC (rev 15265)
@@ -1,6 +1,11 @@
package javax.validation;
import java.lang.annotation.Annotation;
+import java.lang.annotation.Target;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.FIELD;
/**
* Mark a parameter as overriding the parameter of a composing constraint.
@@ -8,6 +13,7 @@
*
* @author Emmanuel Bernard
*/
+@Retention(RUNTIME)
public @interface OverridesParameter {
/**
* constraint type the parameter is overriding
@@ -15,7 +21,8 @@
Class<? extends Annotation> constraint();
/**
- * name of constraint parameter overridden
+ * name of constraint parameter overridden
+ * Defaults to the name of the parameter hosting the annotation
*/
String parameter();
Added:
validator/trunk/validation-api/src/main/java/javax/validation/ReportAsSingleInvalidConstraint.java
===================================================================
---
validator/trunk/validation-api/src/main/java/javax/validation/ReportAsSingleInvalidConstraint.java
(rev 0)
+++
validator/trunk/validation-api/src/main/java/javax/validation/ReportAsSingleInvalidConstraint.java 2008-10-08
03:06:23 UTC (rev 15265)
@@ -0,0 +1,18 @@
+package javax.validation;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+
+/**
+ * A constraint annotation annotated with ReportAsSingleInvalidConstraint
+ * will return the composed annotation error report if any of the composing annotations
+ * fail. The error reports of each individual composing constraint is ignored.
+ *
+ * @author Emmanuel Bernard
+ */
+@Target({ ANNOTATION_TYPE })
+@Retention(RUNTIME)
+public @interface ReportAsSingleInvalidConstraint {
+}
Show replies by date