Author: rmannibucau
Date: Thu Sep 13 13:38:24 2012
New Revision: 1384322

URL: http://svn.apache.org/viewvc?rev=1384322&view=rev
Log:
switching off logging directly on the right class

Modified:
    
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ValidatorBuilder.java

Modified: 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ValidatorBuilder.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ValidatorBuilder.java?rev=1384322&r1=1384321&r2=1384322&view=diff
==============================================================================
--- 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ValidatorBuilder.java
 (original)
+++ 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ValidatorBuilder.java
 Thu Sep 13 13:38:24 2012
@@ -16,6 +16,7 @@
  */
 package org.apache.openejb.assembler.classic;
 
+import java.lang.reflect.Field;
 import java.util.logging.Level;
 import org.apache.openejb.jee.bval.PropertyType;
 import org.apache.openejb.jee.bval.ValidationConfigType;
@@ -101,21 +102,6 @@ public final class ValidatorBuilder {
             providerClassName = 
SystemInstance.get().getOptions().get(VALIDATION_PROVIDER_KEY, (String) null);
         }
 
-        // the only message logged by bval is "ignoreXmlConfiguration == true"
-        // which is false since we parse it ourself so hidding it
-        if (providerClassName == null || 
"org.apache.bval.jsr303.ApacheValidationProvider".equals(providerClassName)) {
-            bvalOffLogging(); // do it with original classloader
-
-            // it is important to switch of classloader because tomee uses a 
hierarchic logmanager
-            final ClassLoader original = 
Thread.currentThread().getContextClassLoader();
-            
Thread.currentThread().setContextClassLoader(ValidatorBuilder.class.getClassLoader());
-            try {
-                bvalOffLogging();
-            } finally {
-                Thread.currentThread().setContextClassLoader(original);
-            }
-        }
-
         if (providerClassName != null) {
             try {
                 @SuppressWarnings({"unchecked","rawtypes"})
@@ -138,6 +124,11 @@ public final class ValidatorBuilder {
         }
 
         // config is manage here so ignore provider parsing so ignore it from 
the impl
+        // the only message logged by bval is "ignoreXmlConfiguration == true"
+        // which is false since we parse it ourself so hidding it
+        if (providerClassName == null || 
"org.apache.bval.jsr303.ApacheValidationProvider".equals(providerClassName)) {
+            bvalOffLogging(target);
+        }
         target.ignoreXmlConfiguration();
 
         String messageInterpolatorClass = info.messageInterpolatorClass;
@@ -198,11 +189,22 @@ public final class ValidatorBuilder {
         return target;
     }
 
-    private static void bvalOffLogging() {
-        final java.util.logging.Logger offLogger = 
java.util.logging.Logger.getLogger("org.apache.bval.jsr303.ConfigurationImpl");
-        if (!Level.SEVERE.equals(offLogger.getLevel())) {
-            offLogger.setLevel(Level.SEVERE);
-            offLogger.setUseParentHandlers(false);
+    private static void bvalOffLogging(final Configuration<?> target) {
+        try {
+            final Field field = target.getClass().getDeclaredField("log");
+            final boolean acc = field.isAccessible();
+            field.setAccessible(true);
+            try {
+                final java.util.logging.Logger offLogger = 
(java.util.logging.Logger) field.get(null);
+                if (!Level.SEVERE.equals(offLogger.getLevel())) { // do it 
this way since it is faster
+                    offLogger.setLevel(Level.SEVERE);
+                    offLogger.setUseParentHandlers(false);
+                }
+            } finally {
+                field.setAccessible(acc);
+            }
+        } catch (Exception e) {
+            // no-op
         }
     }
 }


Reply via email to