tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1565557 - /tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/bval/BeanValidationAppendixInterceptor.java
Date Fri, 07 Feb 2014 07:09:37 GMT
Author: rmannibucau
Date: Fri Feb  7 07:09:37 2014
New Revision: 1565557

URL: http://svn.apache.org/r1565557
Log:
supporting mdb as well for bval interceptor + skipping this interceptor is bval 1.1 is on

Modified:
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/bval/BeanValidationAppendixInterceptor.java

Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/bval/BeanValidationAppendixInterceptor.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/bval/BeanValidationAppendixInterceptor.java?rev=1565557&r1=1565556&r2=1565557&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/bval/BeanValidationAppendixInterceptor.java
(original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/bval/BeanValidationAppendixInterceptor.java
Fri Feb  7 07:09:37 2014
@@ -16,11 +16,12 @@
  */
 package org.apache.openejb.bval;
 
+import org.apache.openejb.core.ThreadContext;
 import org.apache.openejb.core.ivm.naming.NamingException;
+import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
 
-import javax.ejb.SessionContext;
 import javax.interceptor.AroundInvoke;
 import javax.interceptor.InvocationContext;
 import javax.naming.InitialContext;
@@ -41,8 +42,27 @@ public class BeanValidationAppendixInter
     private static final Logger logger = Logger.getInstance(LogCategory.OPENEJB, BeanValidationAppendixInterceptor.class);
     private static final Class<?> APACHE_BVAL_METHOD_CLASS = initApache();
     private static final Class<?> HIBERNATE_METHOD_CLASS = initHibernate();
-
-    private SessionContext sessionContext;
+    public static final Class<?>[] BVAL_ARG_TYPES = new Class<?>[]{
+            Class.class, Method.class, Object[].class, Class[].class
+    };
+    public static final Class<?>[] HIBERNATE_ARG_TYPES = new Class<?>[]{
+            Object.class, Method.class, Object[].class, Class[].class
+    };
+
+    private static final boolean ON;
+    static {
+        boolean on = true;
+        try {
+            BeanValidationAppendixInterceptor.class.getClassLoader().loadClass("javax.validation.executable.ExecutableValidator");
+            on = "true".equalsIgnoreCase(SystemInstance.get().getProperty("openejb.bval.10.interceptor.force",
"false"));
+            if (!on) {
+                logger.debug(BeanValidationAppendixInterceptor.class.getName() + " deactivated
since BVal 1.1 is usable, use openejb.bval.10.interceptor.force=true to force it");
+            }
+        } catch (final Throwable e) {
+            // no-op
+        }
+        ON = on;
+    }
 
     @AroundInvoke
     public Object aroundInvoke(final InvocationContext ejbContext) throws Exception {
@@ -50,16 +70,16 @@ public class BeanValidationAppendixInter
         Validator validator = null;
         try {
             validator = (Validator) new InitialContext().lookup("java:comp/Validator");
-            sessionContext = (SessionContext) new InitialContext().lookup("java:comp/EJBContext");
// injection doesn't work
         } catch (NamingException ne) {
             // no-op
         }
 
-        // get bval annotation informations
+        final ThreadContext threadContext = ThreadContext.getThreadContext();
         Class<?> bvalClazzToValidate = ejbContext.getTarget().getClass();
-        if (sessionContext != null && ejbContext.getTarget().getClass().getInterfaces().length
> 0) {
-            bvalClazzToValidate = sessionContext.getInvokedBusinessInterface();
+        if (threadContext != null && ejbContext.getTarget().getClass().getInterfaces().length
> 0) {
+            bvalClazzToValidate = threadContext.getInvokedInterface();
         }
+
         Method method = ejbContext.getMethod();
         if (!bvalClazzToValidate.equals(ejbContext.getTarget().getClass())) {
             method = bvalClazzToValidate.getMethod(method.getName(), method.getParameterTypes());
@@ -72,18 +92,14 @@ public class BeanValidationAppendixInter
                     new Object[]{
                             bvalClazzToValidate, method, ejbContext.getParameters(), new
Class[0]
                     },
-                    new Class<?>[]{
-                            Class.class, Method.class, Object[].class, Class[].class
-                    });
+                    BVAL_ARG_TYPES);
         } else if (HIBERNATE_METHOD_CLASS != null && validator != null) {
             validatorObject = validator.unwrap(HIBERNATE_METHOD_CLASS);
             violations = call(Set.class, validatorObject, "validateAllParameters",
                     new Object[]{
                             ejbContext.getTarget(), ejbContext.getMethod(), ejbContext.getParameters(),
new Class[0]
                     },
-                    new Class<?>[]{
-                            Object.class, Method.class, Object[].class, Class[].class
-                    });
+                    HIBERNATE_ARG_TYPES);
         } else { // a warning message to inform Apache Bean Validation is not present
             if (validator == null) {
                 logger.error("can't find validator");
@@ -127,6 +143,7 @@ public class BeanValidationAppendixInter
         return returnedValue;
     }
 
+
     // just a simple EJBException for now
     private RuntimeException buildValidationException(Set<ConstraintViolation<?>>
violations) {
         return new ConstraintViolationException(violations);



Mime
View raw message