bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r992374 - in /incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303: ApacheValidatorFactory.java ClassValidator.java
Date Fri, 03 Sep 2010 16:58:45 GMT
Author: mbenson
Date: Fri Sep  3 16:58:45 2010
New Revision: 992374

URL: http://svn.apache.org/viewvc?rev=992374&view=rev
Log:
merge r992329,992349 from trunk

Modified:
    incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidatorFactory.java
    incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/ClassValidator.java

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidatorFactory.java?rev=992374&r1=992373&r2=992374&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidatorFactory.java
(original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidatorFactory.java
Fri Sep  3 16:58:45 2010
@@ -30,6 +30,7 @@ import javax.validation.*;
 import javax.validation.bootstrap.ProviderSpecificBootstrap;
 import javax.validation.spi.ConfigurationState;
 import java.lang.annotation.Annotation;
+import java.lang.reflect.Modifier;
 import java.util.*;
 
 /**
@@ -207,16 +208,22 @@ public class ApacheValidatorFactory impl
     @SuppressWarnings("unchecked")
     public <T> T unwrap(Class<T> type) {
         if (type.isInstance(this)) {
-            return (T) this;
-        } else if (!type.isInterface()) {
+            @SuppressWarnings("unchecked")
+            final T result = (T) this;
+            return result;
+        } else if (!(type.isInterface() || Modifier.isAbstract(type.getModifiers()))) {
             return SecureActions.newInstance(type);
         } else {
             try {
-                Class<T> cls = ClassUtils.getClass(type.getName() + "Impl");
-                return SecureActions.newInstance(cls);
+                Class<?> cls = ClassUtils.getClass(type.getName() + "Impl");
+                if (type.isAssignableFrom(cls)) {
+                    @SuppressWarnings("unchecked")
+                    final Class<? extends T> implClass = (Class<? extends T>)
cls;
+                    return SecureActions.newInstance(implClass);
+                }
             } catch (ClassNotFoundException e) {
-                throw new ValidationException("Type " + type + " not supported");
             }
+            throw new ValidationException("Type " + type + " not supported");
         }
     }
 

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/ClassValidator.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/ClassValidator.java?rev=992374&r1=992373&r2=992374&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/ClassValidator.java
(original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/ClassValidator.java
Fri Sep  3 16:58:45 2010
@@ -18,6 +18,7 @@
  */
 package org.apache.bval.jsr303;
 
+import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
@@ -365,20 +366,28 @@ public class ClassValidator implements V
     // @Override - not allowed in 1.5 for Interface methods
     public <T> T unwrap(Class<T> type) {
         if (type.isAssignableFrom(getClass())) {
-            return (T) this;
-        } else if (!type.isInterface()) {
+            @SuppressWarnings("unchecked")
+            final T result = (T) this;
+            return result;
+        } else if (!(type.isInterface() || Modifier.isAbstract(type
+            .getModifiers()))) {
             return SecureActions.newInstance(type,
                 new Class[] { ApacheFactoryContext.class },
                 new Object[] { factoryContext });
         } else {
             try {
-                Class<T> cls = ClassUtils.getClass(type.getName() + "Impl");
-                return SecureActions.newInstance(cls,
-                    new Class[] { ApacheFactoryContext.class },
-                    new Object[] { factoryContext });
+                Class<?> cls = ClassUtils.getClass(type.getName() + "Impl");
+                if (type.isAssignableFrom(cls)) {
+                    @SuppressWarnings("unchecked")
+                    final Class<? extends T> implClass =
+                        (Class<? extends T>) cls;
+                    return SecureActions.newInstance(implClass,
+                        new Class[] { ApacheFactoryContext.class },
+                        new Object[] { factoryContext });
+                }
             } catch (ClassNotFoundException e) {
-                throw new ValidationException("Type " + type + " not supported");
             }
+            throw new ValidationException("Type " + type + " not supported");
         }
     }
 
@@ -602,7 +611,7 @@ public class ClassValidator implements V
             return new IllegalArgumentException(ex.getMessage(), ex);
         } else if (ex instanceof ValidationException) {
             return ex; // do not wrap specific ValidationExceptions (or
-                       // instances from subclasses)
+            // instances from subclasses)
         } else {
             return new ValidationException("error during validation of "
                 + object, ex);



Mime
View raw message