You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by st...@apache.org on 2009/11/29 23:46:06 UTC

svn commit: r885284 - /incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java

Author: struberg
Date: Sun Nov 29 22:46:05 2009
New Revision: 885284

URL: http://svn.apache.org/viewvc?rev=885284&view=rev
Log:
OWB-181 allow interceptor creation even if they have only package scoped visability

Modified:
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java?rev=885284&r1=885283&r2=885284&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java Sun Nov 29 22:46:05 2009
@@ -18,6 +18,7 @@
 import java.lang.annotation.Target;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Member;
 import java.lang.reflect.Method;
 import java.lang.reflect.ParameterizedType;
@@ -94,7 +95,6 @@
 import org.apache.webbeans.config.DefinitionUtil;
 import org.apache.webbeans.config.EJBWebBeansConfigurator;
 import org.apache.webbeans.config.ManagedBeanConfigurator;
-import org.apache.webbeans.config.OpenWebBeansConfiguration;
 import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.conversation.ConversationImpl;
 import org.apache.webbeans.decorator.DecoratorUtil;
@@ -965,12 +965,7 @@
                 {
                     if (!isDefinedWithWebBeans)
                     {
-                        if (ClassUtil.isContaintNoArgConstructor(clazz) == null)
-                        {
-                            throw new WebBeansConfigurationException("Interceptor class : " + clazz.getName() + " must have no-arg constructor");
-                        }
-
-                        intData.setInterceptorInstance(clazz.newInstance());
+                        intData.setInterceptorInstance(newInstanceForced(clazz));
                     }
                 }
                 catch (WebBeansConfigurationException e1)
@@ -990,6 +985,52 @@
     }
 
     /**
+     * Create a new instance of the given class using it's default constructor
+     * regardless if the constructor is visible or not.
+     * This is needed to construct some package scope classes in the TCK.
+     * 
+     * @param <T>
+     * @param clazz
+     * @return
+     * @throws WebBeansConfigurationException
+     */
+    public static <T> T newInstanceForced(Class<T> clazz) 
+    throws WebBeansConfigurationException 
+    {
+        Constructor<T> ct = ClassUtil.isContaintNoArgConstructor(clazz);
+        if (ct == null)
+        {
+            throw new WebBeansConfigurationException("class : " + clazz.getName() + " must have no-arg constructor");
+        }
+
+        if (!ct.isAccessible())
+        {
+            ct.setAccessible(true);
+        }
+        
+        try 
+        {
+            return ct.newInstance();
+        } 
+        catch( IllegalArgumentException e )
+        {
+            throw new WebBeansConfigurationException("class : " + clazz.getName() + " is not constructable", e);
+        } 
+        catch( IllegalAccessException e ) 
+        {
+            throw new WebBeansConfigurationException("class : " + clazz.getName() + " is not constructable", e);
+        } 
+        catch( InvocationTargetException e ) 
+        {
+            throw new WebBeansConfigurationException("class : " + clazz.getName() + " is not constructable", e);
+        } 
+        catch( InstantiationException e ) 
+        {
+            throw new WebBeansConfigurationException("class : " + clazz.getName() + " is not constructable", e);
+        }
+    }
+
+    /**
      * Returns true if interceptor stack contains interceptor with given type.
      * 
      * @param stack interceptor stack