openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject svn commit: r1073856 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: config/ proxy/ util/
Date Wed, 23 Feb 2011 18:03:49 GMT
Author: gpetracek
Date: Wed Feb 23 18:03:49 2011
New Revision: 1073856

URL: http://svn.apache.org/viewvc?rev=1073856&view=rev
Log:
OWB-496 fixed fallback approach for JavassistProxyFactory#getProxyClass

Added:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/OpenWebBeansClassLoaderProvider.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/JavassistProxyFactory.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java?rev=1073856&r1=1073855&r2=1073856&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java
Wed Feb 23 18:03:49 2011
@@ -110,8 +110,6 @@ public class OpenWebBeansConfiguration
     
     public static final String PROPERTY_OWB_APPLICATION = "org.apache.webbeans.application.isOwbApplication";
     
-    public static final String USE_JAVASSIST_CLASSLOADERPROVIDER = "org.apache.webbeans.javassist.useClassLoaderProvider";
-
     /**
      * Use BDABeansXmlScanner to determine if interceptors, decorators, and
      * alternatives are enabled in the beans.xml of a given BDA. For an
@@ -314,17 +312,4 @@ public class OpenWebBeansConfiguration
         
         return Boolean.valueOf(value);
     }
-    
-    /**
-     * Gets flag for updating Javasisst ProxyFactory.classLoaderProvider
-     * @return true if use javassist ProxyFactory.classLoaderProvider
-     * update if exception occurn on ProxyFactory.createClass
-     */
-    public boolean isUpdateJavassistClassLoaderProvider()
-    {
-        String value = getProperty(USE_JAVASSIST_CLASSLOADERPROVIDER);
-        
-        return Boolean.valueOf(value);
-    }
-    
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java?rev=1073856&r1=1073855&r2=1073856&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
Wed Feb 23 18:03:49 2011
@@ -92,6 +92,8 @@ public class WebBeansContext
 
     public WebBeansContext()
     {
+        WebBeansUtil.initProxyFactoryClassLoaderProvider();
+
         // Allow the WebBeansContext itself to be looked up
         managerMap.put(this.getClass(), this);
 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/JavassistProxyFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/JavassistProxyFactory.java?rev=1073856&r1=1073855&r2=1073856&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/JavassistProxyFactory.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/JavassistProxyFactory.java
Wed Feb 23 18:03:49 2011
@@ -50,6 +50,7 @@ import org.apache.webbeans.intercept.Int
 import org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler;
 import org.apache.webbeans.intercept.webbeans.WebBeansInterceptor;
 import org.apache.webbeans.util.ClassUtil;
+import org.apache.webbeans.util.OpenWebBeansClassLoaderProvider;
 import org.apache.webbeans.util.SecurityUtil;
 import org.apache.webbeans.util.WebBeansUtil;
 
@@ -333,7 +334,7 @@ public final class JavassistProxyFactory
 
     public  Class<?> getProxyClass(ProxyFactory factory)
     {
-        ClassLoaderProvider oldProvider = ProxyFactory.classLoaderProvider;
+        ClassLoaderProvider classLoaderProvider = ProxyFactory.classLoaderProvider;
         Class<?> clazz = null;
         try
         {
@@ -341,32 +342,20 @@ public final class JavassistProxyFactory
         }
         catch(RuntimeException e)
         {
-            //Default is false
-            if(WebBeansContext.getInstance().getOpenWebBeansConfiguration().isUpdateJavassistClassLoaderProvider())
-            {                   
-                //Try thread class loader
-                ProxyFactory.classLoaderProvider = new ProxyFactory.ClassLoaderProvider()
-                {                            
-                    @Override
-                    public ClassLoader get(ProxyFactory pf)
-                    {
-                        return WebBeansUtil.getCurrentClassLoader();
-                    }
-                };
-                
-                //try again with updated class loader
-                clazz = SecurityUtil.doPrivilegedCreateClass(factory);  
-            }
-            else
+            if(classLoaderProvider instanceof OpenWebBeansClassLoaderProvider)
             {
-                //Default, throw exception
-                throw e;
+                ((OpenWebBeansClassLoaderProvider)classLoaderProvider).useCurrentClassLoader();
             }
+
+            //try again with updated class loader
+            clazz = SecurityUtil.doPrivilegedCreateClass(factory);
         }
         finally
         {
-            //Switch to old
-            ProxyFactory.classLoaderProvider = oldProvider;            
+            if(classLoaderProvider instanceof OpenWebBeansClassLoaderProvider)
+            {
+                ((OpenWebBeansClassLoaderProvider)classLoaderProvider).reset();
+            }
         }
         
         return clazz; 

Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/OpenWebBeansClassLoaderProvider.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/OpenWebBeansClassLoaderProvider.java?rev=1073856&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/OpenWebBeansClassLoaderProvider.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/OpenWebBeansClassLoaderProvider.java
Wed Feb 23 18:03:49 2011
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.webbeans.util;
+
+import javassist.util.proxy.ProxyFactory;
+
+/**
+ * Allows to switch to the {@link ClassLoader} of the current thread
+ */
+public class OpenWebBeansClassLoaderProvider implements ProxyFactory.ClassLoaderProvider
+{
+    private ProxyFactory.ClassLoaderProvider wrapped;
+
+    private static ThreadLocal<Boolean> useCurrentClassLoader = new ThreadLocal<Boolean>();
+
+    OpenWebBeansClassLoaderProvider()
+    {
+        this.wrapped = ProxyFactory.classLoaderProvider;
+    }
+
+    public void useCurrentClassLoader()
+    {
+        useCurrentClassLoader.set(true);
+    }
+
+    public void reset()
+    {
+        useCurrentClassLoader.set(null);
+        useCurrentClassLoader.remove();
+    }
+
+    @Override
+    public ClassLoader get(ProxyFactory proxyFactory)
+    {
+        if(!Boolean.TRUE.equals(useCurrentClassLoader.get()))
+        {
+            return wrapped.get(proxyFactory);
+        }
+        return Thread.currentThread().getContextClassLoader();
+    }
+}

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java?rev=1073856&r1=1073855&r2=1073856&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
Wed Feb 23 18:03:49 2011
@@ -3023,15 +3023,7 @@ public final class WebBeansUtil
 
     public static void initProxyFactoryClassLoaderProvider()
     {
-        ProxyFactory.classLoaderProvider = new ProxyFactory.ClassLoaderProvider()
-        {
-            @Override
-            public ClassLoader get(ProxyFactory pf)
-            {
-                return WebBeansUtil.getCurrentClassLoader();
-            }
-
-        };
+        ProxyFactory.classLoaderProvider = new OpenWebBeansClassLoaderProvider();
     }
 
     /**



Mime
View raw message