Use instanceof to find the right top level GwtSpecificValidator.
This allows sub classes and Proxies like those generated by RequestFactory
to be validated
[JSR 303 TCK Result] 53 of 258 (20.54%) Pass with 28 Failures and 13 Errors.
Review at http://gwt-code-reviews.appspot.com/1239802
Review by: rchandia@google.com
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@9484 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/validation/client/GwtValidation.java b/user/src/com/google/gwt/validation/client/GwtValidation.java
index 024df08..70f82c8 100644
--- a/user/src/com/google/gwt/validation/client/GwtValidation.java
+++ b/user/src/com/google/gwt/validation/client/GwtValidation.java
@@ -26,23 +26,58 @@
* Annotates a {@code javax.validation.Validator} explicitly listing the classes
* that can be validated in GWT.
* <p>
- * Define the Validator you want explicitly listing the class you want to
+ * Define the Validator you want, explicitly listing the class you want to
* validate.
- *
+ *
* <pre>
* @GwtValidation(MyBean.class, MyOther.class)
* public interface MyValidator extends javax.validation.Validator {
* }
* </pre>
* Create and use the validator.
- *
+ *
* <pre>
* MyValidator validator = GWT.create(MyValidator.class);
* MyBean bean = new MyBean();
* ...
* Set<ConstraintViolation<MyBean>> violations = validator.validate(bean);
* </pre>
+ *
+ * <p>
+ * NOTE: Validation is done using only the Constraints found on the Classes
+ * listed in the annotation. If you have
+ *
+ * <pre>
+ * class MyBean {
+ * @Null
+ * String getName(){return name;}
+ * }
+ * class MySubBean extends MyBean {
+ * @Size(min = 5)
+ * String getName(){return super.getName();}
+ * }
+ * </pre>
+ *
+ * And then create your {@link javax.validation.ValidatorFactory
+ * ValidatorFactory} using
+ *
+ * <pre>
+ * @GwtValidation(MyBean.class, MyOther.class)}
+ * </pre>
+ *
+ * but call validator with the subclass like
+ *
+ * <pre>
+ * MySubBean bean = new MySubBean();
+ * Set<ConstraintViolation<MyBean>> violations = validator.validate(bean);
+ * </pre>
*
+ * The {@code Size} constraint will not be validated.
+ *
+ * Instead make sure you list the all BeanTypes that will be directly validated
+ * in the {@link GwtValidation} annotation.
+ *
+ *
*/
@Documented
@Target(TYPE)
@@ -50,14 +85,14 @@
public @interface GwtValidation {
/**
- * The list of Classes which can be validated by the annotated
- * {@code Validator}.
- */
- Class<?>[] value();
-
- /**
* The list of Groups which can be processed by the annotated
* {@code Validator}, empty means all groups.
*/
Class<?>[] groups() default {};
+
+ /**
+ * The list of Classes which can be validated by the annotated
+ * {@code Validator}.
+ */
+ Class<?>[] value();
}
diff --git a/user/src/com/google/gwt/validation/rebind/ValidatorCreator.java b/user/src/com/google/gwt/validation/rebind/ValidatorCreator.java
index 5bdd9f1..7d4772f 100644
--- a/user/src/com/google/gwt/validation/rebind/ValidatorCreator.java
+++ b/user/src/com/google/gwt/validation/rebind/ValidatorCreator.java
@@ -160,9 +160,11 @@
sw.println("}");
}
- private void writeIfEqualsBeanType(SourceWriter sourceWriter, BeanHelper bean) {
- sourceWriter.println("if (object.getClass().equals("
- + bean.getTypeCanonicalName() + ".class)) {");
+ private void writeIfInstanceofBeanType(SourceWriter sourceWriter, BeanHelper bean) {
+ // if (object instanceof MyBean) {
+ sourceWriter.print("if (object instanceof ");
+ sourceWriter.print(bean.getTypeCanonicalName());
+ sourceWriter.println(") {");
}
private void writeThrowIllegalArgumnet(SourceWriter sourceWriter,
@@ -213,7 +215,7 @@
}
private void writeValidate(SourceWriter sw, BeanHelper bean) {
- writeIfEqualsBeanType(sw, bean);
+ writeIfInstanceofBeanType(sw, bean);
sw.indent();
writeContext(sw, bean, "object");
@@ -249,7 +251,7 @@
}
private void writeValidateProperty(SourceWriter sw, BeanHelper bean) {
- writeIfEqualsBeanType(sw, bean);
+ writeIfInstanceofBeanType(sw, bean);
sw.indent();
writeContext(sw, bean, "object");
sw.print("return " + bean.getValidatorInstanceName()