Revision: 9484
Author: ncha...@google.com
Date: Fri Dec 24 18:46:16 2010
Log: 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: rchan...@google.com
http://code.google.com/p/google-web-toolkit/source/detail?r=9484

Modified:
 /trunk/user/src/com/google/gwt/validation/client/GwtValidation.java
 /trunk/user/src/com/google/gwt/validation/rebind/ValidatorCreator.java

=======================================
--- /trunk/user/src/com/google/gwt/validation/client/GwtValidation.java Tue Oct 5 11:03:13 2010 +++ /trunk/user/src/com/google/gwt/validation/client/GwtValidation.java Fri Dec 24 18:46:16 2010
@@ -26,38 +26,73 @@
* 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>
  * &#064;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&lt;ConstraintViolation&lt;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 {
+ *  &#064;Null
+ *  String getName(){return name;}
+ * }
+ * class MySubBean extends MyBean {
+ *   &#064;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&lt;ConstraintViolation&lt;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)
 @Retention(RUNTIME)
 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();
+}
=======================================
--- /trunk/user/src/com/google/gwt/validation/rebind/ValidatorCreator.java Tue Dec 21 06:50:31 2010 +++ /trunk/user/src/com/google/gwt/validation/rebind/ValidatorCreator.java Fri Dec 24 18:46:16 2010
@@ -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()

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to