Hibernate SVN: r16991 - in beanvalidation/trunk/validation-api/src/main/java/javax/validation: constraints and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-07-02 08:39:38 -0400 (Thu, 02 Jul 2009)
New Revision: 16991
Modified:
beanvalidation/trunk/validation-api/src/main/java/javax/validation/Valid.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/AssertFalse.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/AssertTrue.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/DecimalMax.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/DecimalMin.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Digits.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Future.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Max.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Min.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/NotNull.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Null.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Past.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Pattern.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Size.java
Log:
BVAL-170 BVAL-170 support constructor and parameter target for built-in annotations and recommend custom annotations to do so Also make @Valid support these targets
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/Valid.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/Valid.java 2009-07-01 22:55:25 UTC (rev 16990)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/Valid.java 2009-07-02 12:39:38 UTC (rev 16991)
@@ -19,6 +19,8 @@
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.CONSTRUCTOR;
+import static java.lang.annotation.ElementType.PARAMETER;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
@@ -30,7 +32,7 @@
* @author Emmanuel Bernard
* @author Hardy Ferentschik
*/
-@Target({ METHOD, FIELD })
+@Target({ METHOD, FIELD, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
public @interface Valid {
}
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/AssertFalse.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/AssertFalse.java 2009-07-01 22:55:25 UTC (rev 16990)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/AssertFalse.java 2009-07-02 12:39:38 UTC (rev 16991)
@@ -21,6 +21,8 @@
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.CONSTRUCTOR;
+import static java.lang.annotation.ElementType.PARAMETER;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
@@ -35,7 +37,7 @@
*
* @author Emmanuel Bernard
*/
-@Target({ METHOD, FIELD, ANNOTATION_TYPE })
+@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
@Documented
@Constraint(validatedBy = {})
@@ -52,7 +54,7 @@
*
* @author Emmanuel Bernard
*/
- @Target({ METHOD, FIELD, ANNOTATION_TYPE })
+ @Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
@Documented
@interface List {
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/AssertTrue.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/AssertTrue.java 2009-07-01 22:55:25 UTC (rev 16990)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/AssertTrue.java 2009-07-02 12:39:38 UTC (rev 16991)
@@ -18,12 +18,11 @@
package javax.validation.constraints;
import java.lang.annotation.Documented;
-import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
+import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.ElementType.PARAMETER;
import javax.validation.Constraint;
import javax.validation.ConstraintPayload;
@@ -35,7 +34,7 @@
*
* @author Emmanuel Bernard
*/
-@Target({ METHOD, FIELD, ANNOTATION_TYPE })
+@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
@Documented
@Constraint(validatedBy = {})
@@ -52,7 +51,7 @@
*
* @author Emmanuel Bernard
*/
- @Target({ METHOD, FIELD, ANNOTATION_TYPE })
+ @Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
@Documented
@interface List {
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/DecimalMax.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/DecimalMax.java 2009-07-01 22:55:25 UTC (rev 16990)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/DecimalMax.java 2009-07-02 12:39:38 UTC (rev 16991)
@@ -18,12 +18,11 @@
package javax.validation.constraints;
import java.lang.annotation.Documented;
-import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
+import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.ElementType.PARAMETER;
import javax.validation.Constraint;
import javax.validation.ConstraintPayload;
@@ -46,7 +45,7 @@
*
* @author Emmanuel Bernard
*/
-@Target({ METHOD, FIELD, ANNOTATION_TYPE })
+@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
@Documented
@Constraint(validatedBy = { })
@@ -71,7 +70,7 @@
* @author Emmanuel Bernard
* @see DecimalMax
*/
- @Target({ METHOD, FIELD, ANNOTATION_TYPE })
+ @Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
@Documented
@interface List {
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/DecimalMin.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/DecimalMin.java 2009-07-01 22:55:25 UTC (rev 16990)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/DecimalMin.java 2009-07-02 12:39:38 UTC (rev 16991)
@@ -18,12 +18,11 @@
package javax.validation.constraints;
import java.lang.annotation.Documented;
-import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
+import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.ElementType.PARAMETER;
import javax.validation.Constraint;
import javax.validation.ConstraintPayload;
@@ -46,7 +45,7 @@
*
* @author Emmanuel Bernard
*/
-@Target({ METHOD, FIELD, ANNOTATION_TYPE })
+@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
@Documented
@Constraint(validatedBy = {})
@@ -70,7 +69,7 @@
*
* @author Emmanuel Bernard
*/
- @Target({ METHOD, FIELD, ANNOTATION_TYPE })
+ @Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
@Documented
@interface List {
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Digits.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Digits.java 2009-07-01 22:55:25 UTC (rev 16990)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Digits.java 2009-07-02 12:39:38 UTC (rev 16991)
@@ -18,12 +18,11 @@
package javax.validation.constraints;
import java.lang.annotation.Documented;
-import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
+import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.ElementType.PARAMETER;
import javax.validation.Constraint;
import javax.validation.ConstraintPayload;
@@ -42,7 +41,7 @@
*
* @author Emmanuel Bernard
*/
-@Target({ METHOD, FIELD, ANNOTATION_TYPE })
+@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
@Documented
@Constraint(validatedBy = {})
@@ -69,7 +68,7 @@
*
* @author Emmanuel Bernard
*/
- @Target({ METHOD, FIELD, ANNOTATION_TYPE })
+ @Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
@Documented
@interface List {
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Future.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Future.java 2009-07-01 22:55:25 UTC (rev 16990)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Future.java 2009-07-02 12:39:38 UTC (rev 16991)
@@ -18,12 +18,11 @@
package javax.validation.constraints;
import java.lang.annotation.Documented;
-import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
+import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.ElementType.PARAMETER;
import javax.validation.Constraint;
import javax.validation.ConstraintPayload;
@@ -43,7 +42,7 @@
*
* @author Emmanuel Bernard
*/
-@Target({ METHOD, FIELD, ANNOTATION_TYPE })
+@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
@Documented
@Constraint(validatedBy = {})
@@ -60,7 +59,7 @@
*
* @author Emmanuel Bernard
*/
- @Target({ METHOD, FIELD, ANNOTATION_TYPE })
+ @Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
@Documented
@interface List {
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Max.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Max.java 2009-07-01 22:55:25 UTC (rev 16990)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Max.java 2009-07-02 12:39:38 UTC (rev 16991)
@@ -18,12 +18,11 @@
package javax.validation.constraints;
import java.lang.annotation.Documented;
-import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
+import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.ElementType.PARAMETER;
import javax.validation.Constraint;
import javax.validation.ConstraintPayload;
@@ -45,7 +44,7 @@
*
* @author Emmanuel Bernard
*/
-@Target({ METHOD, FIELD, ANNOTATION_TYPE })
+@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
@Documented
@Constraint(validatedBy = {})
@@ -67,7 +66,7 @@
*
* @author Emmanuel Bernard
*/
- @Target({ METHOD, FIELD, ANNOTATION_TYPE })
+ @Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
@Documented
@interface List {
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Min.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Min.java 2009-07-01 22:55:25 UTC (rev 16990)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Min.java 2009-07-02 12:39:38 UTC (rev 16991)
@@ -18,12 +18,11 @@
package javax.validation.constraints;
import java.lang.annotation.Documented;
-import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
+import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.ElementType.PARAMETER;
import javax.validation.Constraint;
import javax.validation.ConstraintPayload;
@@ -45,7 +44,7 @@
*
* @author Emmanuel Bernard
*/
-@Target({ METHOD, FIELD, ANNOTATION_TYPE })
+@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
@Documented
@Constraint(validatedBy = {})
@@ -67,7 +66,7 @@
*
* @author Emmanuel Bernard
*/
- @Target({ METHOD, FIELD, ANNOTATION_TYPE })
+ @Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
@Documented
@interface List {
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/NotNull.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/NotNull.java 2009-07-01 22:55:25 UTC (rev 16990)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/NotNull.java 2009-07-02 12:39:38 UTC (rev 16991)
@@ -18,12 +18,11 @@
package javax.validation.constraints;
import java.lang.annotation.Documented;
-import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
+import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.ElementType.PARAMETER;
import javax.validation.Constraint;
import javax.validation.ConstraintPayload;
@@ -33,7 +32,7 @@
*
* @author Emmanuel Bernard
*/
-@Target({ METHOD, FIELD, ANNOTATION_TYPE })
+@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
@Documented
@Constraint(validatedBy = {})
@@ -50,7 +49,7 @@
*
* @author Emmanuel Bernard
*/
- @Target({ METHOD, FIELD, ANNOTATION_TYPE })
+ @Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
@Documented
@interface List {
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Null.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Null.java 2009-07-01 22:55:25 UTC (rev 16990)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Null.java 2009-07-02 12:39:38 UTC (rev 16991)
@@ -18,12 +18,11 @@
package javax.validation.constraints;
import java.lang.annotation.Documented;
-import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
+import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.ElementType.PARAMETER;
import javax.validation.Constraint;
import javax.validation.ConstraintPayload;
@@ -33,7 +32,7 @@
*
* @author Emmanuel Bernard
*/
-@Target({ METHOD, FIELD, ANNOTATION_TYPE })
+@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
@Documented
@Constraint(validatedBy = {})
@@ -50,7 +49,7 @@
*
* @author Emmanuel Bernard
*/
- @Target({ METHOD, FIELD, ANNOTATION_TYPE })
+ @Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
@Documented
@interface List {
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Past.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Past.java 2009-07-01 22:55:25 UTC (rev 16990)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Past.java 2009-07-02 12:39:38 UTC (rev 16991)
@@ -18,12 +18,11 @@
package javax.validation.constraints;
import java.lang.annotation.Documented;
-import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
+import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.ElementType.PARAMETER;
import javax.validation.Constraint;
import javax.validation.ConstraintPayload;
@@ -43,7 +42,7 @@
*
* @author Emmanuel Bernard
*/
-@Target({ METHOD, FIELD, ANNOTATION_TYPE })
+@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
@Documented
@Constraint(validatedBy = {})
@@ -60,7 +59,7 @@
*
* @author Emmanuel Bernard
*/
- @Target({ METHOD, FIELD, ANNOTATION_TYPE })
+ @Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
@Documented
@interface List {
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Pattern.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Pattern.java 2009-07-01 22:55:25 UTC (rev 16990)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Pattern.java 2009-07-02 12:39:38 UTC (rev 16991)
@@ -20,10 +20,9 @@
import java.lang.annotation.Target;
import java.lang.annotation.Retention;
import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import javax.validation.Constraint;
import javax.validation.ConstraintPayload;
@@ -36,7 +35,7 @@
*
* @author Emmanuel Bernard
*/
-@Target({ METHOD, FIELD, ANNOTATION_TYPE })
+@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
@Documented
@Constraint(validatedBy = {})
@@ -134,7 +133,7 @@
*
* @author Emmanuel Bernard
*/
- @Target({ METHOD, FIELD, ANNOTATION_TYPE })
+ @Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
@Documented
@interface List {
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Size.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Size.java 2009-07-01 22:55:25 UTC (rev 16990)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Size.java 2009-07-02 12:39:38 UTC (rev 16991)
@@ -20,10 +20,9 @@
import java.lang.annotation.Target;
import java.lang.annotation.Retention;
import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import javax.validation.Constraint;
import javax.validation.ConstraintPayload;
@@ -41,7 +40,7 @@
*
* @author Emmanuel Bernard
*/
-@Target({ METHOD, FIELD, ANNOTATION_TYPE })
+@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
@Documented
@Constraint(validatedBy = {})
@@ -68,7 +67,7 @@
*
* @author Emmanuel Bernard
*/
- @Target({ METHOD, FIELD, ANNOTATION_TYPE })
+ @Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
@Documented
@interface List {
15 years, 4 months
Hibernate SVN: r16990 - search/trunk/src/main/java/org/hibernate/search/util.
by hibernate-commits@lists.jboss.org
Author: sannegrinovero
Date: 2009-07-01 18:55:25 -0400 (Wed, 01 Jul 2009)
New Revision: 16990
Modified:
search/trunk/src/main/java/org/hibernate/search/util/PluginLoader.java
Log:
javadoc for HSEARCH-384 improve error messages for loading plugins and add consistency to the performed checks
Modified: search/trunk/src/main/java/org/hibernate/search/util/PluginLoader.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/util/PluginLoader.java 2009-07-01 22:38:30 UTC (rev 16989)
+++ search/trunk/src/main/java/org/hibernate/search/util/PluginLoader.java 2009-07-01 22:55:25 UTC (rev 16990)
@@ -4,13 +4,29 @@
import org.hibernate.util.ReflectHelper;
/**
+ * Utility class to load instances of other classes by using a fully qualified name,
+ * or from a class type.
+ * Uses reflection and throws SearchException(s) with proper descriptions of the error,
+ * like the target class is missing a proper constructor, is an interface, is not found...
*
* @author Sanne Grinovero
- *
- * @param <T>
*/
public class PluginLoader {
+ /**
+ * Creates an instance of a target class designed by fully qualified name
+ *
+ * @param <T> matches the type of targetSuperType: defines the return type
+ * @param targetSuperType the return type of the function, the classNameToLoad will be checked
+ * to be assignable to this type.
+ * @param classNameToLoad a fully qualified class name, whose type is assignable to targetSuperType
+ * @param caller the class of the caller, needed for classloading purposes
+ * @param componentDescription a meaningful description of the role the instance will have,
+ * used to enrich error messages to describe the context of the error
+ * @return a new instance of classNameToLoad
+ * @throws SearchException wrapping other error types with a proper error message for all kind of problems, like
+ * classNotFound, missing proper constructor, wrong type, security errors.
+ */
public static <T> T instanceFromName(Class<T> targetSuperType, String classNameToLoad,
Class<?> caller, String componentDescription) {
final Class<?> clazzDef;
@@ -23,6 +39,16 @@
return instanceFromClass( targetSuperType, clazzDef, componentDescription );
}
+ /**
+ * Creates an instance of target class
+ * @param <T> the type of targetSuperType: defines the return type
+ * @param targetSuperType the created instance will be checked to be assignable to this type
+ * @param classToLoad the class to be instantiated
+ * @param componentDescription a role name/description to contextualize error messages
+ * @return a new instance of classToLoad
+ * @throws SearchException wrapping other error types with a proper error message for all kind of problems, like
+ * missing proper constructor, wrong type, security errors.
+ */
@SuppressWarnings("unchecked")
public static <T> T instanceFromClass(Class<T> targetSuperType, Class<?> classToLoad, String componentDescription) {
checkClassType( classToLoad, componentDescription );
@@ -66,6 +92,13 @@
}
}
+ /**
+ * Verifies if target class has a no-args constructor, and that it is
+ * accessible in current security manager.
+ * @param classToLoad the class type to check
+ * @param componentDescription adds a meaningful description to the type to describe in the
+ * exception message
+ */
public static void checkHasValidconstructor(Class<?> classToLoad, String componentDescription) {
try {
classToLoad.getConstructor();
15 years, 4 months
Hibernate SVN: r16989 - in search/trunk/src: main/java/org/hibernate/search/backend/impl and 5 other directories.
by hibernate-commits@lists.jboss.org
Author: sannegrinovero
Date: 2009-07-01 18:38:30 -0400 (Wed, 01 Jul 2009)
New Revision: 16989
Added:
search/trunk/src/main/java/org/hibernate/search/util/PluginLoader.java
search/trunk/src/test/java/org/hibernate/search/test/util/PluginLoaderTest.java
Modified:
search/trunk/src/main/java/org/hibernate/search/backend/WorkerFactory.java
search/trunk/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java
search/trunk/src/main/java/org/hibernate/search/impl/InitContext.java
search/trunk/src/main/java/org/hibernate/search/impl/SearchFactoryImpl.java
search/trunk/src/main/java/org/hibernate/search/reader/ReaderProviderFactory.java
search/trunk/src/main/java/org/hibernate/search/store/DirectoryProviderFactory.java
Log:
HSEARCH-384 improve error messages for loading plugins and add consistency to the performed checks
Modified: search/trunk/src/main/java/org/hibernate/search/backend/WorkerFactory.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/backend/WorkerFactory.java 2009-07-01 13:30:20 UTC (rev 16988)
+++ search/trunk/src/main/java/org/hibernate/search/backend/WorkerFactory.java 2009-07-01 22:38:30 UTC (rev 16989)
@@ -5,11 +5,10 @@
import java.util.Properties;
import org.hibernate.search.Environment;
-import org.hibernate.search.SearchException;
import org.hibernate.search.backend.impl.TransactionalWorker;
import org.hibernate.search.cfg.SearchConfiguration;
import org.hibernate.search.engine.SearchFactoryImplementor;
-import org.hibernate.util.ReflectHelper;
+import org.hibernate.search.util.PluginLoader;
import org.hibernate.util.StringHelper;
/**
@@ -41,21 +40,11 @@
worker = new TransactionalWorker();
}
else {
- try {
- Class workerClass = ReflectHelper.classForName( impl, WorkerFactory.class );
- worker = (Worker) workerClass.newInstance();
- }
- catch (ClassNotFoundException e) {
- throw new SearchException( "Unable to find worker class: " + impl, e );
- }
- catch (IllegalAccessException e) {
- throw new SearchException( "Unable to instanciate worker class: " + impl, e );
- }
- catch (InstantiationException e) {
- throw new SearchException( "Unable to instanciate worker class: " + impl, e );
- }
+ worker = PluginLoader.instanceFromName( Worker.class,
+ impl, WorkerFactory.class, "worker" );
}
worker.initialize( props, searchFactoryImplementor );
return worker;
}
+
}
Modified: search/trunk/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java 2009-07-01 13:30:20 UTC (rev 16988)
+++ search/trunk/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java 2009-07-01 22:38:30 UTC (rev 16989)
@@ -12,10 +12,8 @@
import org.slf4j.Logger;
import org.hibernate.Hibernate;
-import org.hibernate.util.ReflectHelper;
import org.hibernate.util.StringHelper;
import org.hibernate.search.Environment;
-import org.hibernate.search.SearchException;
import org.hibernate.search.backend.BackendQueueProcessorFactory;
import org.hibernate.search.backend.LuceneWork;
import org.hibernate.search.backend.QueueingProcessor;
@@ -30,6 +28,7 @@
import org.hibernate.search.engine.SearchFactoryImplementor;
import org.hibernate.search.engine.DocumentBuilderContainedEntity;
import org.hibernate.search.util.LoggerFactory;
+import org.hibernate.search.util.PluginLoader;
/**
* Batch work until {@link #performWorks} is called.
@@ -88,19 +87,8 @@
backendQueueProcessorFactory = new BlackHoleBackendQueueProcessorFactory();
}
else {
- try {
- Class<?> processorFactoryClass = ReflectHelper.classForName( backend, BatchedQueueingProcessor.class );
- backendQueueProcessorFactory = ( BackendQueueProcessorFactory ) processorFactoryClass.newInstance();
- }
- catch ( ClassNotFoundException e ) {
- throw new SearchException( "Unable to find processor class: " + backend, e );
- }
- catch ( IllegalAccessException e ) {
- throw new SearchException( "Unable to instanciate processor class: " + backend, e );
- }
- catch ( InstantiationException e ) {
- throw new SearchException( "Unable to instanciate processor class: " + backend, e );
- }
+ backendQueueProcessorFactory = PluginLoader.instanceFromName( BackendQueueProcessorFactory.class,
+ backend, BatchedQueueingProcessor.class, "processor" );
}
backendQueueProcessorFactory.initialize( properties, searchFactoryImplementor );
searchFactoryImplementor.setBackendQueueProcessorFactory( backendQueueProcessorFactory );
Modified: search/trunk/src/main/java/org/hibernate/search/impl/InitContext.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/impl/InitContext.java 2009-07-01 13:30:20 UTC (rev 16988)
+++ search/trunk/src/main/java/org/hibernate/search/impl/InitContext.java 2009-07-01 22:38:30 UTC (rev 16989)
@@ -16,7 +16,11 @@
import org.hibernate.search.annotations.AnalyzerDef;
import org.hibernate.search.cfg.SearchConfiguration;
import org.hibernate.search.util.DelegateNamedAnalyzer;
+import org.hibernate.search.util.LoggerFactory;
+import org.hibernate.search.util.PluginLoader;
import org.hibernate.util.ReflectHelper;
+import org.hibernate.util.StringHelper;
+import org.slf4j.Logger;
/**
* Provides access to some default configuration settings (eg default <code>Analyzer</code> or default
@@ -27,6 +31,9 @@
* @author Hardy Ferentschik
*/
public class InitContext {
+
+ private static final Logger log = LoggerFactory.make();
+
private final Map<String, AnalyzerDef> analyzerDefs = new HashMap<String, AnalyzerDef>();
private final List<DelegateNamedAnalyzer> lazyAnalyzers = new ArrayList<DelegateNamedAnalyzer>();
private final Analyzer defaultAnalyzer;
@@ -69,26 +76,18 @@
*/
private Analyzer initAnalyzer(SearchConfiguration cfg) {
Class analyzerClass;
- String analyzerClassName = cfg.getProperty( Environment.ANALYZER_CLASS);
- if (analyzerClassName != null) {
+ String analyzerClassName = cfg.getProperty( Environment.ANALYZER_CLASS );
+ if ( analyzerClassName != null ) {
try {
- analyzerClass = ReflectHelper.classForName(analyzerClassName);
+ analyzerClass = ReflectHelper.classForName( analyzerClassName );
} catch (Exception e) {
return buildLazyAnalyzer( analyzerClassName );
}
} else {
analyzerClass = StandardAnalyzer.class;
}
- // Initialize analyzer
- Analyzer defaultAnalyzer;
- try {
- defaultAnalyzer = (Analyzer) analyzerClass.newInstance();
- } catch (ClassCastException e) {
- throw new SearchException("Lucene analyzer does not implement " + Analyzer.class.getName() + ": "
- + analyzerClassName, e);
- } catch (Exception e) {
- throw new SearchException("Failed to instantiate lucene analyzer with type " + analyzerClassName, e);
- }
+ Analyzer defaultAnalyzer = PluginLoader.instanceFromClass( Analyzer.class,
+ analyzerClass, "Lucene analyzer" );
return defaultAnalyzer;
}
@@ -99,36 +98,17 @@
* @return returns the default similarity class.
*/
private Similarity initSimilarity(SearchConfiguration cfg) {
- Class similarityClass;
String similarityClassName = cfg.getProperty(Environment.SIMILARITY_CLASS);
- if (similarityClassName != null) {
- try {
- similarityClass = ReflectHelper.classForName(similarityClassName);
- } catch (Exception e) {
- throw new SearchException("Lucene Similarity class '" + similarityClassName + "' defined in property '"
- + Environment.SIMILARITY_CLASS + "' could not be found.", e);
- }
+ Similarity defaultSimilarity;
+ if ( StringHelper.isEmpty( similarityClassName ) ) {
+ defaultSimilarity = Similarity.getDefault();
}
else {
- similarityClass = null;
+ defaultSimilarity = PluginLoader.instanceFromName(
+ Similarity.class, similarityClassName, InitContext.class, "default similarity" );
}
-
- // Initialize similarity
- if ( similarityClass == null ) {
- return Similarity.getDefault();
- }
- else {
- Similarity defaultSimilarity;
- try {
- defaultSimilarity = (Similarity) similarityClass.newInstance();
- } catch (ClassCastException e) {
- throw new SearchException("Lucene similarity does not extend " + Similarity.class.getName() + ": "
- + similarityClassName, e);
- } catch (Exception e) {
- throw new SearchException("Failed to instantiate lucene similarity with type " + similarityClassName, e);
- }
- return defaultSimilarity;
- }
+ log.debug( "Using default similarity implementation: {}", defaultSimilarity.getClass().getName() );
+ return defaultSimilarity;
}
public Analyzer getDefaultAnalyzer() {
@@ -176,7 +156,7 @@
// SolrAnalyzerBuilder references Solr classes.
// InitContext should not (directly or indirectly) load a Solr class to avoid hard dependency
// unless necessary
- // the curent mecanism (check sor class presence and call SolrAnalyzerBuilder if needed
+ // the current mechanism (check Solr class presence and call SolrAnalyzerBuilder if needed
// seems to be sufficient on Apple VM (derived from Sun's
// TODO check on other VMs and be ready for a more reflexive approach
return SolrAnalyzerBuilder.buildAnalyzer( analyzerDef );
Modified: search/trunk/src/main/java/org/hibernate/search/impl/SearchFactoryImpl.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/impl/SearchFactoryImpl.java 2009-07-01 13:30:20 UTC (rev 16988)
+++ search/trunk/src/main/java/org/hibernate/search/impl/SearchFactoryImpl.java 2009-07-01 22:38:30 UTC (rev 16989)
@@ -24,7 +24,6 @@
import org.hibernate.annotations.common.reflection.MetadataProvider;
import org.hibernate.annotations.common.reflection.MetadataProviderInjector;
import org.hibernate.annotations.common.reflection.java.JavaReflectionManager;
-import org.hibernate.util.ReflectHelper;
import org.hibernate.util.StringHelper;
import org.hibernate.search.Environment;
import org.hibernate.search.SearchException;
@@ -64,6 +63,7 @@
import org.hibernate.search.store.DirectoryProviderFactory;
import org.hibernate.search.store.optimization.OptimizerStrategy;
import org.hibernate.search.util.LoggerFactory;
+import org.hibernate.search.util.PluginLoader;
/**
* @author Emmanuel Bernard
@@ -489,20 +489,8 @@
filterCachingStrategy = new MRUFilterCachingStrategy();
}
else {
- try {
- Class filterCachingStrategyClass = ReflectHelper
- .classForName( impl, SearchFactoryImpl.class );
- filterCachingStrategy = ( FilterCachingStrategy ) filterCachingStrategyClass.newInstance();
- }
- catch ( ClassNotFoundException e ) {
- throw new SearchException( "Unable to find filterCachingStrategy class: " + impl, e );
- }
- catch ( IllegalAccessException e ) {
- throw new SearchException( "Unable to instantiate filterCachingStrategy class: " + impl, e );
- }
- catch ( InstantiationException e ) {
- throw new SearchException( "Unable to instantiate filterCachingStrategy class: " + impl, e );
- }
+ filterCachingStrategy = PluginLoader.instanceFromName( FilterCachingStrategy.class,
+ impl, SearchFactoryImpl.class, "filterCachingStrategy" );
}
filterCachingStrategy.initialize( properties );
return filterCachingStrategy;
@@ -556,20 +544,8 @@
batchBackend = new LuceneBatchBackend();
}
else {
- try {
- Class batchBackendClass = ReflectHelper
- .classForName( impl, SearchFactoryImpl.class );
- batchBackend = ( BatchBackend ) batchBackendClass.newInstance();
- }
- catch ( ClassNotFoundException e ) {
- throw new SearchException( "Unable to find batchbackend implementation class: " + impl, e );
- }
- catch ( IllegalAccessException e ) {
- throw new SearchException( "Unable to instantiate batchbackend class: " + impl, e );
- }
- catch ( InstantiationException e ) {
- throw new SearchException( "Unable to instantiate batchbackend class: " + impl, e );
- }
+ batchBackend = PluginLoader.instanceFromName( BatchBackend.class, impl, SearchFactoryImpl.class,
+ "batchbackend" );
}
Properties batchBackendConfiguration = new MaskedProperty(
this.configurationProperties, Environment.BATCH_BACKEND );
Modified: search/trunk/src/main/java/org/hibernate/search/reader/ReaderProviderFactory.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/reader/ReaderProviderFactory.java 2009-07-01 13:30:20 UTC (rev 16988)
+++ search/trunk/src/main/java/org/hibernate/search/reader/ReaderProviderFactory.java 2009-07-01 22:38:30 UTC (rev 16989)
@@ -5,10 +5,9 @@
import java.util.Properties;
import org.hibernate.search.Environment;
-import org.hibernate.search.SearchException;
import org.hibernate.search.cfg.SearchConfiguration;
import org.hibernate.search.engine.SearchFactoryImplementor;
-import org.hibernate.util.ReflectHelper;
+import org.hibernate.search.util.PluginLoader;
import org.hibernate.util.StringHelper;
/**
@@ -47,19 +46,8 @@
readerProvider = new SharingBufferReaderProvider();
}
else {
- try {
- Class readerProviderClass = ReflectHelper.classForName( impl, ReaderProviderFactory.class );
- readerProvider = (ReaderProvider) readerProviderClass.newInstance();
- }
- catch (ClassNotFoundException e) {
- throw new SearchException( "Unable to find readerProvider class: " + impl, e );
- }
- catch (IllegalAccessException e) {
- throw new SearchException( "Unable to instanciate readerProvider class: " + impl, e );
- }
- catch (InstantiationException e) {
- throw new SearchException( "Unable to instanciate readerProvider class: " + impl, e );
- }
+ readerProvider = PluginLoader.instanceFromName( ReaderProvider.class, impl,
+ ReaderProviderFactory.class, "readerProvider" );
}
readerProvider.initialize( props, searchFactoryImplementor );
return readerProvider;
Modified: search/trunk/src/main/java/org/hibernate/search/store/DirectoryProviderFactory.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/store/DirectoryProviderFactory.java 2009-07-01 13:30:20 UTC (rev 16988)
+++ search/trunk/src/main/java/org/hibernate/search/store/DirectoryProviderFactory.java 2009-07-01 22:38:30 UTC (rev 16989)
@@ -18,7 +18,7 @@
import org.hibernate.search.store.optimization.IncrementalOptimizerStrategy;
import org.hibernate.search.store.optimization.NoOpOptimizerStrategy;
import org.hibernate.search.store.optimization.OptimizerStrategy;
-import org.hibernate.util.ReflectHelper;
+import org.hibernate.search.util.PluginLoader;
import org.hibernate.util.StringHelper;
/**
@@ -41,7 +41,6 @@
public class DirectoryProviderFactory {
private final List<DirectoryProvider<?>> providers = new ArrayList<DirectoryProvider<?>>();
- private static final String DEFAULT_DIRECTORY_PROVIDER = FSDirectoryProvider.class.getName();
private static final String SHARDING_STRATEGY = "sharding_strategy";
private static final String NBR_OF_SHARDS = SHARDING_STRATEGY + ".nbr_of_shards";
@@ -77,25 +76,8 @@
}
}
else {
- try {
- Class shardigStrategyClass = ReflectHelper.classForName( shardingStrategyName, this.getClass() );
- shardingStrategy = (IndexShardingStrategy) shardigStrategyClass.newInstance();
- }
- catch (ClassNotFoundException e) {
- throw new SearchException( "Unable to find IndexShardingStrategy class " + shardingStrategyName + " for " + directoryProviderName, e );
- }
- catch (IllegalAccessException e) {
- throw new SearchException( "Unable to create instance of IndexShardingStrategy class " + shardingStrategyName
- + " Be sure to have a no-arg constructor", e );
- }
- catch (InstantiationException e) {
- throw new SearchException( "Unable to create instance of IndexShardingStrategy class " + shardingStrategyName
- + " Be sure to have a no-arg constructor", e );
- }
- catch (ClassCastException e) {
- throw new SearchException( "ShardingStrategy class does not implement IndexShardingStrategy: "
- + shardingStrategyName, e );
- }
+ shardingStrategy = PluginLoader.instanceFromName( IndexShardingStrategy.class,
+ shardingStrategyName, DirectoryProviderFactory.class, "IndexShardingStrategy" );
}
shardingStrategy.initialize(
new MaskedProperty( indexProps[0], SHARDING_STRATEGY ), providers );
@@ -111,20 +93,14 @@
private DirectoryProvider<?> createDirectoryProvider(String directoryProviderName, Properties indexProps,
Class entity, SearchFactoryImplementor searchFactoryImplementor) {
String className = indexProps.getProperty( "directory_provider" );
+ DirectoryProvider<?> provider;
if ( StringHelper.isEmpty( className ) ) {
- className = DEFAULT_DIRECTORY_PROVIDER;
+ provider = new FSDirectoryProvider();
}
- DirectoryProvider<?> provider;
- try {
- @SuppressWarnings( "unchecked" )
- Class<DirectoryProvider> directoryClass = ReflectHelper.classForName(
- className, DirectoryProviderFactory.class
- );
- provider = directoryClass.newInstance();
+ else {
+ provider = PluginLoader.instanceFromName( DirectoryProvider.class, className,
+ DirectoryProviderFactory.class, "directory provider" );
}
- catch (Exception e) {
- throw new SearchException( "Unable to instantiate directory provider: " + className, e );
- }
try {
provider.initialize( directoryProviderName, indexProps, searchFactoryImplementor );
}
Added: search/trunk/src/main/java/org/hibernate/search/util/PluginLoader.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/util/PluginLoader.java (rev 0)
+++ search/trunk/src/main/java/org/hibernate/search/util/PluginLoader.java 2009-07-01 22:38:30 UTC (rev 16989)
@@ -0,0 +1,81 @@
+package org.hibernate.search.util;
+
+import org.hibernate.search.SearchException;
+import org.hibernate.util.ReflectHelper;
+
+/**
+ *
+ * @author Sanne Grinovero
+ *
+ * @param <T>
+ */
+public class PluginLoader {
+
+ public static <T> T instanceFromName(Class<T> targetSuperType, String classNameToLoad,
+ Class<?> caller, String componentDescription) {
+ final Class<?> clazzDef;
+ try {
+ clazzDef = ReflectHelper.classForName( classNameToLoad, caller );
+ } catch (ClassNotFoundException e) {
+ throw new SearchException( "Unable to find " + componentDescription +
+ " implementation class: " + classNameToLoad, e );
+ }
+ return instanceFromClass( targetSuperType, clazzDef, componentDescription );
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T> T instanceFromClass(Class<T> targetSuperType, Class<?> classToLoad, String componentDescription) {
+ checkClassType( classToLoad, componentDescription );
+ checkHasValidconstructor( classToLoad, componentDescription );
+ Object instance;
+ try {
+ instance = classToLoad.newInstance();
+ }
+ catch ( IllegalAccessException e ) {
+ throw new SearchException(
+ "Unable to instantiate " + componentDescription + " class: " + classToLoad.getName() +
+ ". Class or constructor is not accessible.", e );
+ }
+ catch ( InstantiationException e ) {
+ throw new SearchException(
+ "Unable to instantiate " + componentDescription + " class: " + classToLoad.getName() +
+ ". Verify it has a no-args public constructor and is not abstract.", e );
+ }
+ if ( ! targetSuperType.isInstance( instance ) ) {
+ // have a proper error message according to interface implementation or subclassing
+ if ( targetSuperType.isInterface() ) {
+ throw new SearchException(
+ "Wrong configuration of " + componentDescription + ": class " + classToLoad.getName()
+ + " does not implement interface " + targetSuperType.getName() );
+ }
+ else {
+ throw new SearchException(
+ "Wrong configuration of " + componentDescription + ": class " + classToLoad.getName()
+ + " is not a subtype of " + targetSuperType.getName() );
+ }
+ }
+ else {
+ return (T) instance;
+ }
+ }
+
+ private static void checkClassType(Class<?> classToLoad, String componentDescription) {
+ if ( classToLoad.isInterface() ) {
+ throw new SearchException( classToLoad.getName() + " defined for component " + componentDescription
+ + " is an interface: implementation required." );
+ }
+ }
+
+ public static void checkHasValidconstructor(Class<?> classToLoad, String componentDescription) {
+ try {
+ classToLoad.getConstructor();
+ } catch (SecurityException e) {
+ throw new SearchException( classToLoad.getName() + " defined for component " + componentDescription
+ + " could not be instantiated because of a security manager error", e );
+ } catch (NoSuchMethodException e) {
+ throw new SearchException( classToLoad.getName() + " defined for component " + componentDescription
+ + " is missing a no-arguments constructor" );
+ }
+ }
+
+}
Property changes on: search/trunk/src/main/java/org/hibernate/search/util/PluginLoader.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: search/trunk/src/test/java/org/hibernate/search/test/util/PluginLoaderTest.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/util/PluginLoaderTest.java (rev 0)
+++ search/trunk/src/test/java/org/hibernate/search/test/util/PluginLoaderTest.java 2009-07-01 22:38:30 UTC (rev 16989)
@@ -0,0 +1,91 @@
+// $Id$
+package org.hibernate.search.test.util;
+
+import org.apache.lucene.search.DefaultSimilarity;
+import org.apache.lucene.search.Similarity;
+import org.hibernate.Session;
+import org.hibernate.search.FullTextSession;
+import org.hibernate.search.SearchException;
+import org.hibernate.search.backend.BackendQueueProcessorFactory;
+import org.hibernate.search.backend.impl.batchlucene.BatchBackend;
+import org.hibernate.search.backend.impl.batchlucene.LuceneBatchBackend;
+import org.hibernate.search.impl.FullTextSessionImpl;
+import org.hibernate.search.util.PluginLoader;
+
+import junit.framework.TestCase;
+
+/**
+ * Test for PluginLoader, also verifying it throws easy to understand exceptions
+ *
+ * @author Sanne Grinovero
+ */
+public class PluginLoaderTest extends TestCase {
+
+ public void testInstanceFromName() {
+ BatchBackend batchBackend = PluginLoader.instanceFromName(BatchBackend.class, LuceneBatchBackend.class.getName(), getClass(), "Lucene batch backend");
+ assertNotNull( batchBackend );
+ assertTrue( batchBackend.getClass().equals( LuceneBatchBackend.class ) );
+
+ try {
+ PluginLoader.instanceFromName( BackendQueueProcessorFactory.class, "HeyThisClassIsNotThere", getClass(), "backend" );
+ fail( "was expecting a SearchException" );
+ }
+ catch (Exception e) {
+ assertEquals( e.getClass(), SearchException.class );
+ assertEquals( "Unable to find backend implementation class: HeyThisClassIsNotThere", e.getMessage() );
+ }
+ }
+
+ public void testInstanceFromClass() {
+ //testing for interface implementation:
+ BatchBackend batchBackend = PluginLoader.instanceFromClass( BatchBackend.class, LuceneBatchBackend.class, "Lucene batch backend" );
+ assertNotNull( batchBackend );
+ assertTrue( batchBackend.getClass().equals( LuceneBatchBackend.class ) );
+
+ //testing for subclasses:
+ Similarity sim = PluginLoader.instanceFromClass( Similarity.class, DefaultSimilarity.class, "default similarity" );
+ assertNotNull( sim );
+ assertTrue( sim.getClass().equals( DefaultSimilarity.class ) );
+
+ //testing proper error messages:
+ wrappingTestFromClass(
+ "Wrong configuration of Lucene batch backend: class " +
+ "org.hibernate.search.test.util.PluginLoaderTest does not implement " +
+ "interface org.hibernate.search.backend.impl.batchlucene.BatchBackend",
+ BatchBackend.class, PluginLoaderTest.class, "Lucene batch backend"
+ );
+ wrappingTestFromClass(
+ "org.hibernate.search.impl.FullTextSessionImpl defined for component session " +
+ "is missing a no-arguments constructor",
+ FullTextSession.class, FullTextSessionImpl.class, "session"
+ );
+ wrappingTestFromClass(
+ "org.hibernate.Session defined for component session is an interface: implementation required.",
+ FullTextSession.class, Session.class, "session"
+ );
+ wrappingTestFromClass(
+ "Wrong configuration of default similarity: " +
+ "class org.hibernate.search.backend.impl.batchlucene.LuceneBatchBackend " +
+ "is not a subtype of org.apache.lucene.search.Similarity",
+ Similarity.class, LuceneBatchBackend.class, "default similarity"
+ );
+ wrappingTestFromClass(
+ "Unable to instantiate default similarity class: org.apache.lucene.search.Similarity. " +
+ "Verify it has a no-args public constructor and is not abstract.",
+ Similarity.class, Similarity.class, "default similarity"
+ );
+ }
+
+ private void wrappingTestFromClass(String expectedErrorMessage, Class<?> interf, Class<?> impl, String componentName) {
+ try {
+ PluginLoader.instanceFromClass( interf, impl, componentName );
+ fail( "was expecting a SearchException" );
+ }
+ catch (Exception e) {
+ assertEquals( e.getClass(), SearchException.class );
+ assertEquals( expectedErrorMessage, e.getMessage() );
+ }
+ }
+
+}
+
Property changes on: search/trunk/src/test/java/org/hibernate/search/test/util/PluginLoaderTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
15 years, 4 months
Hibernate SVN: r16988 - beanvalidation/trunk/validation-api/src/main/java/javax/validation.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-07-01 09:30:20 -0400 (Wed, 01 Jul 2009)
New Revision: 16988
Modified:
beanvalidation/trunk/validation-api/src/main/java/javax/validation/PathBuilder.java
Log:
BVAL-171 Prototype for a PathBuilder
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/PathBuilder.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/PathBuilder.java 2009-07-01 12:55:44 UTC (rev 16987)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/PathBuilder.java 2009-07-01 13:30:20 UTC (rev 16988)
@@ -22,7 +22,7 @@
* Once a Path object is returned ( by calling #build() ),
* instances of the fluent API should no longer be used
* and an IllegalStateException is raised upon any of the
- * method call
+ * method call.
*
* @author Emmanuel Bernard
*/
@@ -53,9 +53,10 @@
/**
* Return a Path object whose state is represented by
* the path builder.
- * Methods of the PathBuilder instance this object comes
- * from and the path builder nested
- * objects return IllegalStateException from now on.
+ * Once a Path object is returned ( by calling #build() ),
+ * instances of the fluent API should no longer be used
+ * and an IllegalStateException is raised upon any of the
+ * method call.
*/
Path build();
}
@@ -64,8 +65,6 @@
* Represent a subnode whose context is
* configurable (ie index, key and isInIterable)
*/
- //ContextualizableNodeBuilder
- //NodeBuilderWithCustomizableContext
interface NodeBuilderWithCustomizableContext {
/**
* Mark the node as being in an Iterable or a Map
@@ -84,15 +83,16 @@
/**
* Return a Path object whose state is represented by
* the path builder.
- * Methods of the PathBuilder instance this object comes
- * from and the path builder nested
- * objects return IllegalStateException from now on.
+ * Once a Path object is returned ( by calling #build() ),
+ * instances of the fluent API should no longer be used
+ * and an IllegalStateException is raised upon any of the
+ * method call.
*/
Path build();
}
/**
- * Represent choices for a node which is
+ * Represent refinement choices for a node which is
* in an Iterator or Map.
* If the iterator is an indexed collection or a map,
* the index or the key should be set.
@@ -125,9 +125,10 @@
/**
* Return a Path object whose state is represented by
* the path builder.
- * Methods of the PathBuilder instance this object comes
- * from and the path builder nested
- * objects return IllegalStateException from now on.
+ * Once a Path object is returned ( by calling #build() ),
+ * instances of the fluent API should no longer be used
+ * and an IllegalStateException is raised upon any of the
+ * method call.
*/
Path build();
}
15 years, 4 months
Hibernate SVN: r16987 - in beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests: constraints/builtinconstraints and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-07-01 08:55:44 -0400 (Wed, 01 Jul 2009)
New Revision: 16987
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/Author.java
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/BootstrapTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinValidatorOverrideTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/DefaultGroupRedefinitionTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/CustomConstraintValidatorTest.java
Log:
mapped more tests
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/BootstrapTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/BootstrapTest.java 2009-07-01 12:17:39 UTC (rev 16986)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/BootstrapTest.java 2009-07-01 12:55:44 UTC (rev 16987)
@@ -44,7 +44,6 @@
import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.testharness.impl.packaging.ArtifactType;
import org.jboss.testharness.impl.packaging.Classes;
-import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
@@ -52,15 +51,15 @@
import org.hibernate.jsr303.tck.util.TestUtil;
import static org.hibernate.jsr303.tck.util.TestUtil.assertConstraintViolation;
-import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectPropertyPaths;
import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectConstraintViolationMessages;
import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectNumberOfViolations;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectPropertyPaths;
/**
* @author Hardy Ferentschik
*/
@Artifact(artifactType = ArtifactType.JSR303)
-(a)Classes({TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class})
+@Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class })
public class BootstrapTest extends AbstractTest {
private static final String SERVICES_FILE = "META-INF/services/" + ValidationProvider.class.getName();
@@ -74,7 +73,7 @@
person.setPersonalNumber( 12345678900l );
Set<ConstraintViolation<Person>> constraintViolations = validator.validate( person );
- assertEquals( constraintViolations.size(), 3, "Wrong number of constraints" );
+ assertCorrectNumberOfViolations( constraintViolations, 3 );
assertCorrectPropertyPaths(
constraintViolations, "firstName", "lastName", "personalNumber"
);
@@ -83,14 +82,14 @@
person.setLastName( "Doe" );
constraintViolations = validator.validate( person );
- assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
assertConstraintViolation(
constraintViolations.iterator().next(), Person.class, 12345678900l, "personalNumber"
);
person.setPersonalNumber( 1234567890l );
constraintViolations = validator.validate( person );
- assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
}
@Test
@@ -154,11 +153,7 @@
private void assertCustomTrversableResolverUsed(Validator validator) {
Person person = new Person();
Set<ConstraintViolation<Person>> constraintViolations = validator.validate( person );
- assertEquals(
- constraintViolations.size(),
- 0,
- "There should be no failures since the custom traversable resolver makes all properties non traversable."
- );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
}
private List<ValidationProvider> readBeanValidationServiceFile() {
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinValidatorOverrideTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinValidatorOverrideTest.java 2009-07-01 12:17:39 UTC (rev 16986)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinValidatorOverrideTest.java 2009-07-01 12:55:44 UTC (rev 16987)
@@ -29,13 +29,13 @@
import org.jboss.testharness.AbstractTest;
import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.testharness.impl.packaging.ArtifactType;
-import org.jboss.testharness.impl.packaging.Resource;
import org.jboss.testharness.impl.packaging.Classes;
-import static org.testng.Assert.assertTrue;
+import org.jboss.testharness.impl.packaging.Resource;
import org.testng.annotations.Test;
-import static org.hibernate.jsr303.tck.util.TestUtil.getInputStreamForPath;
import org.hibernate.jsr303.tck.util.TestUtil;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectNumberOfViolations;
+import static org.hibernate.jsr303.tck.util.TestUtil.getInputStreamForPath;
/**
* @author Hardy Ferentschik
@@ -43,7 +43,7 @@
@Artifact(artifactType = ArtifactType.JSR303)
@Resource(source = "builtin-constraints-override.xml",
destination = "WEB-INF/classes/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/builtin-constraints-override.xml")
-(a)Classes({TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class})
+@Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class })
public class BuiltinValidatorOverrideTest extends AbstractTest {
@Test
@@ -56,18 +56,12 @@
config.addMapping( in );
Validator validator = config.buildValidatorFactory().getValidator();
DummyEntity dummy = new DummyEntity();
- Set<ConstraintViolation<DummyEntity>> violation = validator.validate( dummy );
- assertTrue(
- violation.isEmpty(),
- "There should be no violation even though dummyProperty is null, because the default validator got overriden in xml."
- );
+ Set<ConstraintViolation<DummyEntity>> violations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( violations, 0 );
dummy.dummyProperty = "foobar";
- violation = validator.validate( dummy );
- assertTrue(
- violation.size() == 1,
- "There should be one violation due to the InvertedNotNullValidator."
- );
+ violations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( violations, 1 );
}
class DummyEntity {
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/DefaultGroupRedefinitionTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/DefaultGroupRedefinitionTest.java 2009-07-01 12:17:39 UTC (rev 16986)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/DefaultGroupRedefinitionTest.java 2009-07-01 12:55:44 UTC (rev 16987)
@@ -62,11 +62,7 @@
Validator validator = TestUtil.getDefaultValidator();
Set<ConstraintViolation<Address>> constraintViolations = validator.validate( address );
- assertEquals(
- constraintViolations.size(),
- 1,
- "There should only be one violation for zipcode"
- );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
ConstraintViolation<Address> violation = constraintViolations.iterator().next();
assertConstraintViolation( violation, Address.class, null, "zipcode" );
@@ -76,11 +72,7 @@
// now the second group in the re-defined default group causes an error
constraintViolations = validator.validate( address );
- assertEquals(
- constraintViolations.size(),
- 1,
- "There should only be one violation for zipcode"
- );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
violation = constraintViolations.iterator().next();
assertConstraintViolation( violation, Address.class, address, "" );
Copied: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/Author.java (from rev 16948, beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Author.java)
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/Author.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/Author.java 2009-07-01 12:55:44 UTC (rev 16987)
@@ -0,0 +1,59 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.jsr303.tck.tests.validation.customconstraint;
+
+import javax.validation.constraints.Size;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Author {
+
+ @Size(min = 2)
+ private String firstName;
+
+ @Size(min = 3)
+ private String lastName;
+
+ @Size(min = 3, message = "The company name must be a minimum {min} characters")
+ private String company;
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ public String getCompany() {
+ return company;
+ }
+
+ public void setCompany(String company) {
+ this.company = company;
+ }
+}
\ No newline at end of file
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/CustomConstraintValidatorTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/CustomConstraintValidatorTest.java 2009-07-01 12:17:39 UTC (rev 16986)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/CustomConstraintValidatorTest.java 2009-07-01 12:55:44 UTC (rev 16987)
@@ -36,13 +36,14 @@
import org.testng.annotations.Test;
import org.hibernate.jsr303.tck.util.TestUtil;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectNumberOfViolations;
/**
* @author Emmanuel Bernard
* @author Hardy Ferentschik
*/
@Artifact(artifactType = ArtifactType.JSR303)
-(a)Classes({TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class})
+@Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class })
public class CustomConstraintValidatorTest extends AbstractTest {
@Test
@@ -134,6 +135,52 @@
validator.validate( new Freezer() );
}
+ @Test
+ @SpecAssertion(section = "2.4", id = "l")
+ public void testOneConstraintViolationPerFailingConstraint() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ Author author = new Author();
+ author.setLastName( "" );
+ author.setFirstName( "" );
+ author.setCompany( "" );
+
+
+ Set<ConstraintViolation<Author>> constraintViolations = validator.validate( author );
+ assertCorrectNumberOfViolations( constraintViolations, 3 );
+
+ author.setFirstName( "John" );
+ constraintViolations = validator.validate( author );
+ assertCorrectNumberOfViolations( constraintViolations, 2 );
+
+ author.setLastName( "Doe" );
+ constraintViolations = validator.validate( author );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+
+ author.setCompany( "JBoss" );
+ constraintViolations = validator.validate( author );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
+ }
+
+ @Test
+ @SpecAssertion(section = "2.4", id = "n")
+ public void testNonInterpolatedMessageParamterIsUsed() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ Author author = new Author();
+ author.setLastName( "John" );
+ author.setFirstName( "Doe" );
+ author.setCompany( "" );
+
+ Set<ConstraintViolation<Author>> constraintViolations = validator.validate( author );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+
+ ConstraintViolation<Author> constraintViolation = constraintViolations.iterator().next();
+ assertEquals( constraintViolation.getMessage(), "The company name must be a minimum 3 characters" );
+ assertEquals( constraintViolation.getMessageTemplate(), "The company name must be a minimum {min} characters" );
+ }
+
+
public static class Shoe {
@Positive
public int size;
15 years, 4 months
Hibernate SVN: r16986 - beanvalidation/trunk/validation-api/src/main/java/javax/validation.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-07-01 08:17:39 -0400 (Wed, 01 Jul 2009)
New Revision: 16986
Added:
beanvalidation/trunk/validation-api/src/main/java/javax/validation/PathBuilder.java
Log:
BVAL-171 Prototype for a PathBuilder
Added: beanvalidation/trunk/validation-api/src/main/java/javax/validation/PathBuilder.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/PathBuilder.java (rev 0)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/PathBuilder.java 2009-07-01 12:17:39 UTC (rev 16986)
@@ -0,0 +1,134 @@
+package javax.validation;
+
+/**
+ * Define a fluent API to build a Path object and define
+ * its sub nodes.
+ * A Path object accepted by a given Bean Validation provider
+ * must be built by a PathBuilder provided by this Bean
+ * Validation provider. In other words, Path implementations
+ * are not portable across implementations.
+ *
+ * <pre>PathBuilder builder = ...;
+ * // addresses["home"].inhabitants[].lastname
+ * Path path = builder.path("addresses")
+ * .addSubNode("inhabitants")
+ * .inIterable()
+ * .atKey("home")
+ * .addSubNode("lastname")
+ * .inIterable()
+ * .build();
+ * </pre>
+ *
+ * Once a Path object is returned ( by calling #build() ),
+ * instances of the fluent API should no longer be used
+ * and an IllegalStateException is raised upon any of the
+ * method call
+ *
+ * @author Emmanuel Bernard
+ */
+public interface PathBuilder {
+
+ /**
+ * Start the creation of a Path object whose root node is
+ * named rootNode.
+ *
+ * @param rootNode root node name
+ * @return a builder representing the root node
+ */
+ PathBuilder.NodeBuilderWithDefinedContext buildPath(String rootNode);
+
+ /**
+ * Represent a node whose context is known
+ * (ie index, key and isInIterable)
+ */
+ interface NodeBuilderWithDefinedContext {
+ /**
+ * Add a subNode to the path
+ *
+ * @param name property
+ * @return a builder representing this node
+ */
+ NodeBuilderWithCustomizableContext addSubNode(String name);
+
+ /**
+ * Return a Path object whose state is represented by
+ * the path builder.
+ * Methods of the PathBuilder instance this object comes
+ * from and the path builder nested
+ * objects return IllegalStateException from now on.
+ */
+ Path build();
+ }
+
+ /**
+ * Represent a subnode whose context is
+ * configurable (ie index, key and isInIterable)
+ */
+ //ContextualizableNodeBuilder
+ //NodeBuilderWithCustomizableContext
+ interface NodeBuilderWithCustomizableContext {
+ /**
+ * Mark the node as being in an Iterable or a Map
+ * @return a builder representing iterable details
+ */
+ NodeContextBuilder inIterable();
+
+ /**
+ * Add a subNode to the path
+ *
+ * @param name property
+ * @return a builder representing this node
+ */
+ NodeBuilderWithCustomizableContext addSubNode(String name);
+
+ /**
+ * Return a Path object whose state is represented by
+ * the path builder.
+ * Methods of the PathBuilder instance this object comes
+ * from and the path builder nested
+ * objects return IllegalStateException from now on.
+ */
+ Path build();
+ }
+
+ /**
+ * Represent choices for a node which is
+ * in an Iterator or Map.
+ * If the iterator is an indexed collection or a map,
+ * the index or the key should be set.
+ */
+ interface NodeContextBuilder {
+ /**
+ * Define the key the object is into the Map
+ *
+ * @param key map key
+ * @return a builder representing the current node
+ */
+ NodeBuilderWithDefinedContext atKey(Object key);
+
+ /**
+ * Define the index the object is into the List or array
+ *
+ * @param index index
+ * @return a builder representing the current node
+ */
+ NodeBuilderWithDefinedContext atIndex(Integer index);
+
+ /**
+ * Add a subNode to the path
+ *
+ * @param name property
+ * @return a builder representing this node
+ */
+ NodeBuilderWithCustomizableContext addSubNode(String name);
+
+ /**
+ * Return a Path object whose state is represented by
+ * the path builder.
+ * Methods of the PathBuilder instance this object comes
+ * from and the path builder nested
+ * objects return IllegalStateException from now on.
+ */
+ Path build();
+ }
+}
15 years, 4 months
Hibernate SVN: r16985 - beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-07-01 07:20:24 -0400 (Wed, 01 Jul 2009)
New Revision: 16985
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/Shoe.java
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionTest.java
Log:
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionTest.java 2009-06-30 16:51:13 UTC (rev 16984)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionTest.java 2009-07-01 11:20:24 UTC (rev 16985)
@@ -24,6 +24,7 @@
import javax.validation.ConstraintDefinitionException;
import javax.validation.ConstraintViolation;
import javax.validation.Validator;
+import javax.validation.UnexpectedTypeException;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
@@ -245,6 +246,19 @@
}
}
+ @Test
+ @SpecAssertion(section = "2.3", id = "f")
+ public void testAllComposingConstraintsMustBeApplicableToAnnotatedType() {
+ Validator validator = TestUtil.getDefaultValidator();
+ try {
+ validator.validate( new Shoe( 41 ) );
+ fail( "Shoe defines @NotEmpty on an int. Validation should have failed." );
+ }
+ catch ( UnexpectedTypeException e ) {
+ // success
+ }
+ }
+
private FrenchAddress getFrenchAddressWithoutZipCode() {
FrenchAddress address = new FrenchAddress();
address.setAddressline1( "10 rue des Treuils" );
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/Shoe.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/Shoe.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/Shoe.java 2009-07-01 11:20:24 UTC (rev 16985)
@@ -0,0 +1,30 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.jsr303.tck.tests.constraints.constraintcomposition;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Shoe {
+ @NotEmpty
+ int size;
+
+ public Shoe(int size) {
+ this.size = size;
+ }
+}
15 years, 4 months