You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by st...@apache.org on 2012/08/06 02:47:25 UTC
[2/2] git commit: DELTASPIKE-258 fix Weld container.
DELTASPIKE-258 fix Weld container.
Txs to Stuart Douglas for helping
Project: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/commit/c947ae1c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/tree/c947ae1c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/diff/c947ae1c
Branch: refs/heads/master
Commit: c947ae1c70eecec631574cc75a43569ec050d60c
Parents: 3c73175
Author: Mark Struberg <st...@apache.org>
Authored: Mon Aug 6 02:45:28 2012 +0200
Committer: Mark Struberg <st...@apache.org>
Committed: Mon Aug 6 02:46:45 2012 +0200
----------------------------------------------------------------------
.../deltaspike/cdise/weld/ContextController.java | 109 +--------------
1 files changed, 4 insertions(+), 105 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/c947ae1c/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/ContextController.java
----------------------------------------------------------------------
diff --git a/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/ContextController.java b/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/ContextController.java
index dec1d0c..85f05c6 100644
--- a/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/ContextController.java
+++ b/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/ContextController.java
@@ -18,23 +18,19 @@
*/
package org.apache.deltaspike.cdise.weld;
+import org.jboss.weld.context.AbstractSharedContext;
import org.jboss.weld.context.ApplicationContext;
-import org.jboss.weld.context.api.ContextualInstance;
-import org.jboss.weld.context.beanstore.BeanStore;
import org.jboss.weld.context.bound.BoundConversationContext;
import org.jboss.weld.context.bound.BoundRequestContext;
import org.jboss.weld.context.bound.BoundSessionContext;
import org.jboss.weld.context.bound.MutableBoundRequest;
-import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.context.SessionScoped;
import javax.enterprise.inject.Typed;
import javax.inject.Inject;
import javax.inject.Singleton;
-import java.lang.reflect.Field;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
/**
@@ -63,116 +59,19 @@ public class ContextController
private boolean singletonScopeStarted;
- private Boolean resetSuccessful;
-
- //X TODO check if we can remove it
void startApplicationScope()
{
- if (applicationScopeStarted)
- {
- throw new IllegalStateException(ApplicationScoped.class.getName() + " started already");
- }
- applicationScopeStarted = true;
+ // Welds ApplicationContext is always active
}
void stopApplicationScope()
{
- if (Boolean.FALSE.equals(resetSuccessful) /*|| TODO detect weld 2.x+*/)
- {
- if (applicationContext.isActive())
- {
- applicationContext.invalidate();
- applicationScopeStarted = false;
- }
- return;
- }
-
if (applicationContext.isActive())
{
- //workaround for weld 1.x (see WELD-1072)
- org.jboss.weld.bootstrap.api.Singleton<BeanStore> beanStoreHolder = null;
- BeanStore originalBeanStore = null;
- try
+ if (applicationContext instanceof AbstractSharedContext)
{
- Field field = applicationContext.getClass().getSuperclass().getDeclaredField("beanStore");
- field.setAccessible(true);
- beanStoreHolder = (org.jboss.weld.bootstrap.api.Singleton)field.get(applicationContext);
- final BeanStore beanStore = beanStoreHolder.get();
- originalBeanStore = beanStore;
-
- beanStoreHolder.set(new BeanStore()
- {
- @Override
- public <T> ContextualInstance<T> get(String id)
- {
- return beanStore.get(id);
- }
-
- @Override
- public boolean contains(String id)
- {
- return beanStore.contains(id);
- }
-
- @Override
- public void clear()
- {
- //do nothing
- }
-
- @Override
- public Iterator<String> iterator()
- {
- return beanStore.iterator();
- }
-
- @Override
- public <T> void put(String id, ContextualInstance<T> contextualInstance)
- {
- beanStore.put(id, contextualInstance);
- }
- });
+ ((AbstractSharedContext) applicationContext).getBeanStore().clear();
}
- catch (Exception e)
- {
- //do nothing
- resetSuccessful = false;
- }
- catch (LinkageError e)
- {
- //do nothing - a new version of weld is used which introduced other required dependencies.
- //WELD-1072 should be fixed in this version already
- resetSuccessful = false;
- }
-
- applicationContext.invalidate();
-
- if (beanStoreHolder != null)
- {
- Iterator<String> idIterator = originalBeanStore.iterator();
-
- String currentId;
- ContextualInstance<Object> currentContextualInstance;
- while (idIterator.hasNext())
- {
- currentId = idIterator.next();
- currentContextualInstance = originalBeanStore.get(currentId);
-
- //keep (weld) internal application scoped beans - TODO check possible side-effects
- if (currentContextualInstance.getInstance().getClass().getName().startsWith("org.jboss."))
- {
- //internalBeanList.add(currentContextualInstance);
- continue;
- }
- idIterator.remove();
- }
-
- beanStoreHolder.set(originalBeanStore);
- }
-
- applicationScopeStarted = false;
-
- resetSuccessful = true;
}
}