You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by db...@apache.org on 2011/01/26 02:20:33 UTC

svn commit: r1063550 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: component/ config/ context/creational/ conversation/ corespi/ el/ inject/instance/

Author: dblevins
Date: Wed Jan 26 01:20:32 2011
New Revision: 1063550

URL: http://svn.apache.org/viewvc?rev=1063550&view=rev
Log:
Destatic InstanceImpl and the Context code.  Some destatic of WebBeansELResolver
OWB-503 status: 524 code uses
Total of 7756 static synchronized accesses and 8941 hashed calls in 898 tests
Average of 8 static synchronized accesses and 9 hashed calls per test

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ConversationBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InstanceBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextFactory.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/WrappedCreationalContext.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/DefaultSingletonService.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/el/WebBeansELResolver.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceFactory.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ConversationBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ConversationBean.java?rev=1063550&r1=1063549&r2=1063550&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ConversationBean.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ConversationBean.java Wed Jan 26 01:20:32 2011
@@ -67,12 +67,13 @@ public class ConversationBean extends Ab
         {
             if(sessionId != null)
             {
-                conversation = new ConversationImpl(conversationService.getConversationSessionId());    
+                conversation = new ConversationImpl(conversationService.getConversationSessionId(),
+                                                    getWebBeansContext());
             }
             else
             {
                 //Used in Tests
-                conversation = new ConversationImpl();
+                conversation = new ConversationImpl(getWebBeansContext());
             }
             
         }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InstanceBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InstanceBean.java?rev=1063550&r1=1063549&r2=1063550&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InstanceBean.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InstanceBean.java Wed Jan 26 01:20:32 2011
@@ -51,7 +51,8 @@ public class InstanceBean<T> extends Abs
             ParameterizedType injectedType = (ParameterizedType)local.get().getType();
             Set<Annotation> qualifiers = local.get().getQualifiers();
             Instance<T> instance = InstanceFactory.getInstance(injectedType.getActualTypeArguments()[0], 
-                    (local.get().getBean() == null) ? null : local.get().getBean().getBeanClass(), 
+                    (local.get().getBean() == null) ? null : local.get().getBean().getBeanClass(),
+                    getWebBeansContext(), 
                             qualifiers.toArray(new Annotation[qualifiers.size()]));
             
             return instance;

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=1063550&r1=1063549&r2=1063550&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 Jan 26 01:20:32 2011
@@ -67,7 +67,7 @@ public class WebBeansContext
     private AnnotatedElementFactory annotatedElementFactory = new AnnotatedElementFactory();
     private BeanManagerImpl beanManagerImpl = new BeanManagerImpl(this);
     private ConversationManager conversationManager = new ConversationManager(this);
-    private CreationalContextFactory creationalContextFactory = new CreationalContextFactory();
+    private CreationalContextFactory creationalContextFactory = new CreationalContextFactory(this);
     private DecoratorsManager decoratorsManager = new DecoratorsManager(this);
     private ExtensionLoader extensionLoader = new ExtensionLoader(this);
     private InterceptorsManager interceptorsManager = new InterceptorsManager(this);
@@ -329,7 +329,7 @@ public class WebBeansContext
 
     public <T> T get(Class<T> clazz)
     {
-        //util.Track.get(clazz);
+        util.Track.get(clazz);
         T object = clazz.cast(managerMap.get(clazz));
 
         /* No singleton for this application, create one */

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextFactory.java?rev=1063550&r1=1063549&r2=1063550&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextFactory.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextFactory.java Wed Jan 26 01:20:32 2011
@@ -32,11 +32,15 @@ import org.apache.webbeans.config.WebBea
  */
 public final class CreationalContextFactory<T>
 {
+    private WebBeansContext webBeansContext;
+
     /**
      * Creates a new <code>CreationalContextFactory</code> instance.
+     * @param webBeansContext
      */
-    public CreationalContextFactory()
+    public CreationalContextFactory(WebBeansContext webBeansContext)
     {
+        this.webBeansContext = webBeansContext;
     }
 
     /**
@@ -59,12 +63,12 @@ public final class CreationalContextFact
      */
     public CreationalContext<T> getCreationalContext(Contextual<T> contextual)
     {        
-        return new CreationalContextImpl<T>(contextual);   
+        return new CreationalContextImpl<T>(contextual, webBeansContext);
     }        
     
     public CreationalContext<T> wrappedCreationalContext(CreationalContext<T> creationalContext, Contextual<T> contextual)
     {
-        return new WrappedCreationalContext<T>(contextual, creationalContext);
+        return new WrappedCreationalContext<T>(contextual, creationalContext, webBeansContext);
     }
     
 }
\ No newline at end of file

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.java?rev=1063550&r1=1063549&r2=1063550&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.java Wed Jan 26 01:20:32 2011
@@ -53,13 +53,16 @@ public class CreationalContextImpl<T> im
 
     /**When bean object is destroyed it is set*/
     public static ThreadLocal<Object> currentRemoveObject = new ThreadLocal<Object>();
-    
+
+    private WebBeansContext webBeansContext;
+
     /**
      * Package private
      */
-    CreationalContextImpl(Contextual<T> contextual)
+    CreationalContextImpl(Contextual<T> contextual, WebBeansContext webBeansContext)
     {
         this.contextual = contextual;
+        this.webBeansContext = webBeansContext;
     }
     
     /**
@@ -288,7 +291,7 @@ public class CreationalContextImpl<T> im
         List<DependentCreationalContext<?>> values = this.dependentObjects.get(ownerInstance);
         if(values != null)
         {
-            final CreationalContextFactory contextFactory = WebBeansContext.getInstance().getCreationalContextFactory();
+            final CreationalContextFactory contextFactory = webBeansContext.getCreationalContextFactory();
             Iterator<?> iterator = values.iterator();        
             while(iterator.hasNext())
             {
@@ -317,7 +320,7 @@ public class CreationalContextImpl<T> im
     @SuppressWarnings("unchecked")
     public void removeAllDependents()
     {
-        WebBeansContext webBeansContext = WebBeansContext.getInstance();
+        WebBeansContext webBeansContext = this.webBeansContext;
         Collection<List<DependentCreationalContext<?>>> values = this.dependentObjects.values();
         if(values != null)
         {
@@ -418,13 +421,14 @@ public class CreationalContextImpl<T> im
     private synchronized void readObject(ObjectInputStream s)
     throws IOException, ClassNotFoundException
     {
+        this.webBeansContext = WebBeansContext.currentInstance();
         HashMap<Object, List<DependentCreationalContext<?>>> depo = (HashMap<Object, List<DependentCreationalContext<?>>>)s.readObject();
         dependentObjects = new WeakHashMap<Object, List<DependentCreationalContext<?>>>(depo);
 
         String id = (String) s.readObject();
         if (id != null)
         {
-            contextual = (Contextual<T>) WebBeansContext.getInstance().getBeanManagerImpl().getPassivationCapableBean(id);
+            contextual = (Contextual<T>) webBeansContext.getBeanManagerImpl().getPassivationCapableBean(id);
         }
                 
         ejbInterceptors = (ConcurrentMap<Object, List<EjbInterceptorContext>>) s.readObject();

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/WrappedCreationalContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/WrappedCreationalContext.java?rev=1063550&r1=1063549&r2=1063550&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/WrappedCreationalContext.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/WrappedCreationalContext.java Wed Jan 26 01:20:32 2011
@@ -21,15 +21,18 @@ package org.apache.webbeans.context.crea
 import javax.enterprise.context.spi.Contextual;
 import javax.enterprise.context.spi.CreationalContext;
 
+import org.apache.webbeans.config.WebBeansContext;
+
 class WrappedCreationalContext<T> extends CreationalContextImpl<T> implements CreationalContext<T>
 {
     private static final long serialVersionUID = 3580925478881669439L;
     
     private CreationalContext<T> wrapped = null;    
 
-    WrappedCreationalContext(Contextual<T> contextual, CreationalContext<T> creationalContext)
+    WrappedCreationalContext(Contextual<T> contextual, CreationalContext<T> creationalContext,
+                             WebBeansContext webBeansContext)
     {
-        super(contextual);
+        super(contextual, webBeansContext);
         this.wrapped = creationalContext;
     }
 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationImpl.java?rev=1063550&r1=1063549&r2=1063550&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationImpl.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationImpl.java Wed Jan 26 01:20:32 2011
@@ -68,14 +68,22 @@ public class ConversationImpl implements
     /**This instance is under used*/
     private AtomicBoolean inUsed = new AtomicBoolean(false);
 
+    private WebBeansContext webBeansContext;
+
     /**
      * Default constructor. Used in tests.
      */
     public ConversationImpl()
     {
+        this(WebBeansContext.getInstance());
+    }
+    
+    public ConversationImpl(WebBeansContext webBeansContext)
+    {
+        this.webBeansContext = webBeansContext;
         try
         {
-            this.timeout = Long.parseLong(WebBeansContext.getInstance().getOpenWebBeansConfiguration().
+            this.timeout = Long.parseLong(this.webBeansContext.getOpenWebBeansConfiguration().
                     getProperty(OpenWebBeansConfiguration.CONVERSATION_TIMEOUT_INTERVAL, "1800000"));   
         }
         catch(NumberFormatException e)
@@ -88,14 +96,17 @@ public class ConversationImpl implements
      * Creates a new conversation instance. Id is not
      * set until conversation is begin.
      * @param sessionId
+     * @param webBeansContext
      */
-    public ConversationImpl(String sessionId)
+    public ConversationImpl(String sessionId, WebBeansContext webBeansContext)
     {
         Asserts.assertNotNull(sessionId);
-        
+
+        this.webBeansContext = webBeansContext;
+
         try
         {
-            this.timeout = Long.parseLong(WebBeansContext.getInstance().getOpenWebBeansConfiguration().
+            this.timeout = Long.parseLong(this.webBeansContext.getOpenWebBeansConfiguration().
                     getProperty(OpenWebBeansConfiguration.CONVERSATION_TIMEOUT_INTERVAL, "1800000"));   
         }
         catch(NumberFormatException e)
@@ -104,6 +115,7 @@ public class ConversationImpl implements
         }
         
         this.sessionId = sessionId;
+        this.webBeansContext = WebBeansContext.getInstance();
     }
     
     /**
@@ -119,7 +131,7 @@ public class ConversationImpl implements
             this.id = Integer.toString(conversationIdGenerator.incrementAndGet());
             
             //Conversation manager
-            WebBeansContext webBeansContext = WebBeansContext.getInstance();
+            WebBeansContext webBeansContext = this.webBeansContext;
             ConversationManager manager = webBeansContext.getConversationManager();
             try
             {
@@ -150,7 +162,7 @@ public class ConversationImpl implements
     public void begin(String id)
     {   
         //Look at other conversation, that may collate with this is
-        final WebBeansContext webBeansContext = WebBeansContext.getInstance();
+        final WebBeansContext webBeansContext = this.webBeansContext;
         final ConversationManager conversationManager = webBeansContext.getConversationManager();
         if(conversationManager.isConversationExistWithGivenId(id))
         {
@@ -177,7 +189,7 @@ public class ConversationImpl implements
         {
             this.isTransient = true;
 
-            WebBeansContext.getInstance().getConversationManager().removeConversation(this);
+            webBeansContext.getConversationManager().removeConversation(this);
         }
         else
         {

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/DefaultSingletonService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/DefaultSingletonService.java?rev=1063550&r1=1063549&r2=1063550&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/DefaultSingletonService.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/DefaultSingletonService.java Wed Jan 26 01:20:32 2011
@@ -48,10 +48,10 @@ public class DefaultSingletonService imp
         ClassLoader classLoader = (ClassLoader) key;
         synchronized (singletonMap)
         {
-            //util.Track.sync(key);
+            util.Track.sync(key);
             
             WebBeansContext webBeansContext = singletonMap.get(classLoader);
-            //util.Track.get(key);
+            util.Track.get(key);
 
             if (webBeansContext == null)
             {

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/el/WebBeansELResolver.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/el/WebBeansELResolver.java?rev=1063550&r1=1063549&r2=1063550&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/el/WebBeansELResolver.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/el/WebBeansELResolver.java Wed Jan 26 01:20:32 2011
@@ -53,11 +53,13 @@ import org.apache.webbeans.spi.plugins.A
  *
  */
 public class WebBeansELResolver extends ELResolver
-{    
+{
+    private WebBeansContext webBeansContext;
 
     public WebBeansELResolver()
     {
 
+        webBeansContext = WebBeansContext.getInstance();
     }
     
     /**
@@ -97,7 +99,7 @@ public class WebBeansELResolver extends 
         //Check that application is OWB enabled
         //For JSF applications that are not
         //OWB enabled, no need to go with this resolver....
-        WebBeansContext webBeansContext = WebBeansContext.getInstance();
+        WebBeansContext webBeansContext = this.webBeansContext;
         
         AbstractOwbJsfPlugin jsfPlugin = webBeansContext.getPluginLoader().getJsfPlugin();
         

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceFactory.java?rev=1063550&r1=1063549&r2=1063550&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceFactory.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceFactory.java Wed Jan 26 01:20:32 2011
@@ -23,6 +23,8 @@ import java.lang.reflect.Type;
 
 import javax.enterprise.inject.Instance;
 
+import org.apache.webbeans.config.WebBeansContext;
+
 public final class InstanceFactory
 {
     private InstanceFactory()
@@ -34,12 +36,14 @@ public final class InstanceFactory
      * 
      * @param injectedType injection class type
      * @param injectionPointClass null or the class of the injection point
+     * @param webBeansContext
      * @param annotations qualifier annotations
      * @return
      */
-    public static <T> Instance<T> getInstance(Type injectedType, Class<?> injectionPointClass,Annotation...annotations)
+    public static <T> Instance<T> getInstance(Type injectedType, Class<?> injectionPointClass,
+                                              WebBeansContext webBeansContext, Annotation... annotations)
     {
-        InstanceImpl<T> instance = new InstanceImpl<T>(injectedType,injectionPointClass, annotations);   
+        InstanceImpl<T> instance = new InstanceImpl<T>(injectedType,injectionPointClass, webBeansContext, annotations);
         
         return instance;
     }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java?rev=1063550&r1=1063549&r2=1063550&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java Wed Jan 26 01:20:32 2011
@@ -58,14 +58,17 @@ class InstanceImpl<T> implements Instanc
     /** Qualifier annotations appeared on the injection point */
     private Set<Annotation> qualifierAnnotations = new HashSet<Annotation>();
 
+    private WebBeansContext webBeansContext;
+
     /**
      * Creates new instance.
      * 
      * @param injectionClazz injection class type
      * @param injectionPointClazz null or class of injection point
+     * @param webBeansContext
      * @param annotations qualifier annotations
      */
-    InstanceImpl(Type injectionClazz, Class<?> injectionPointClazz,Annotation... annotations)
+    InstanceImpl(Type injectionClazz, Class<?> injectionPointClazz, WebBeansContext webBeansContext, Annotation... annotations)
     {
         this.injectionClazz = injectionClazz;
         this.injectionPointClazz=injectionPointClazz;
@@ -74,6 +77,7 @@ class InstanceImpl<T> implements Instanc
         {
             qualifierAnnotations.add(ann);
         }
+        this.webBeansContext = webBeansContext;
     }
 
     /**
@@ -92,7 +96,7 @@ class InstanceImpl<T> implements Instanc
         
         Set<Bean<?>> beans = resolveBeans();
 
-        WebBeansContext webBeansContext = WebBeansContext.getInstance();
+        WebBeansContext webBeansContext = this.webBeansContext;
         webBeansContext.getResolutionUtil().checkResolvedBeans(beans, ClassUtil.getClazz(this.injectionClazz), anns);
 
         Bean<?> bean = beans.iterator().next();
@@ -111,7 +115,7 @@ class InstanceImpl<T> implements Instanc
         Annotation[] anns = new Annotation[this.qualifierAnnotations.size()];
         anns = this.qualifierAnnotations.toArray(anns);
 
-        InjectionResolver injectionResolver = WebBeansContext.getInstance().getBeanManagerImpl().getInjectionResolver();
+        InjectionResolver injectionResolver = webBeansContext.getBeanManagerImpl().getInjectionResolver();
 
         InjectionResolver resolver = injectionResolver;
         Set<Bean<?>> beans = resolver.implResolveByType(
@@ -148,7 +152,8 @@ class InstanceImpl<T> implements Instanc
     public Instance<T> select(Annotation... qualifiers)
     {
         Annotation[] newQualifiersArray = getAdditionalQualifiers(qualifiers);
-        InstanceImpl<T> newInstance = new InstanceImpl<T>(this.injectionClazz, this.injectionPointClazz,newQualifiersArray);
+        InstanceImpl<T> newInstance = new InstanceImpl<T>(this.injectionClazz, this.injectionPointClazz,
+                                                          webBeansContext, newQualifiersArray);
 
         return newInstance;
     }
@@ -161,7 +166,7 @@ class InstanceImpl<T> implements Instanc
      */
     private Annotation[] getAdditionalQualifiers(Annotation[] qualifiers)
     {
-        WebBeansContext.getInstance().getAnnotationManager().checkQualifierConditions(qualifiers);
+        webBeansContext.getAnnotationManager().checkQualifierConditions(qualifiers);
         Set<Annotation> newQualifiers = new HashSet<Annotation>(this.qualifierAnnotations);
 
         if (qualifiers != null && qualifiers.length > 0)
@@ -189,7 +194,7 @@ class InstanceImpl<T> implements Instanc
     @Override
     public <U extends T> Instance<U> select(Class<U> subtype, Annotation... qualifiers)
     {
-        WebBeansContext.getInstance().getAnnotationManager().checkQualifierConditions(qualifiers);
+        webBeansContext.getAnnotationManager().checkQualifierConditions(qualifiers);
 
         Type sub = subtype;
         
@@ -200,7 +205,7 @@ class InstanceImpl<T> implements Instanc
         
         Annotation[] newQualifiers = getAdditionalQualifiers(qualifiers);
         
-        InstanceImpl<U> newInstance = new InstanceImpl<U>(sub, this.injectionPointClazz,newQualifiers);
+        InstanceImpl<U> newInstance = new InstanceImpl<U>(sub, this.injectionPointClazz, webBeansContext, newQualifiers);
                     
         return newInstance;
     }
@@ -225,7 +230,7 @@ class InstanceImpl<T> implements Instanc
         Set<T> instances = new HashSet<T>();
         for(Bean<?> bean : beans)
         {
-            T instance = (T) WebBeansContext.getInstance().getBeanManagerImpl().getInstance(bean,null);
+            T instance = (T) webBeansContext.getBeanManagerImpl().getInstance(bean,null);
             instances.add(instance);
         }
         
@@ -244,6 +249,7 @@ class InstanceImpl<T> implements Instanc
     
     private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException
     {
+        this.webBeansContext = WebBeansContext.currentInstance();
         final ObjectInputStream inputStream = new OwbCustomObjectInputStream(in, WebBeansUtil.getCurrentClassLoader());
         this.injectionClazz = (Type)inputStream.readObject();
         this.qualifierAnnotations = (Set<Annotation>)inputStream.readObject();