Author: nickarls
Date: 2008-10-28 03:15:16 -0400 (Tue, 28 Oct 2008)
New Revision: 189
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/AbstractContext.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/DependentContext.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/NormalContext.java
Log:
context hierarchy changes
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/AbstractContext.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/AbstractContext.java 2008-10-28
00:54:40 UTC (rev 188)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/AbstractContext.java 2008-10-28
07:15:16 UTC (rev 189)
@@ -3,7 +3,6 @@
import java.lang.annotation.Annotation;
import java.util.HashMap;
-import javax.webbeans.ContextNotActiveException;
import javax.webbeans.manager.Bean;
import javax.webbeans.manager.Context;
import javax.webbeans.manager.Manager;
@@ -21,7 +20,7 @@
public abstract class AbstractContext implements Context
{
- private class BeanMap extends MapWrapper<Bean<? extends Object>, Object>
+ protected class BeanMap extends MapWrapper<Bean<? extends Object>,
Object>
{
public BeanMap()
@@ -37,50 +36,18 @@
}
- private BeanMap beans;
+ protected BeanMap beans;
private Class<? extends Annotation> scopeType;
- private boolean active;
+ protected boolean active;
public AbstractContext(Class<? extends Annotation> scopeType)
{
this.scopeType = scopeType;
beans = new BeanMap();
- active = true;
}
- public <T> T get(Bean<T> bean, boolean create)
- {
- if (!active)
- {
- throw new ContextNotActiveException();
- }
-
- if (beans == null)
- {
- // Context has been destroyed
- return null;
- }
-
- T instance = beans.get(bean);
-
- if (instance != null)
- {
- return instance;
- }
+ public abstract <T> T get(Bean<T> bean, boolean create);
- if (!create)
- {
- return null;
- }
-
- // TODO should bean creation be synchronized?
-
- instance = bean.create();
-
- beans.put(bean, instance);
- return instance;
- }
-
public Class<? extends Annotation> getScopeType()
{
return scopeType;
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/DependentContext.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/DependentContext.java 2008-10-28
00:54:40 UTC (rev 188)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/DependentContext.java 2008-10-28
07:15:16 UTC (rev 189)
@@ -2,7 +2,9 @@
import java.lang.annotation.Annotation;
+import javax.webbeans.ContextNotActiveException;
import javax.webbeans.Dependent;
+import javax.webbeans.manager.Bean;
public class DependentContext extends PseudoContext
{
@@ -10,12 +12,23 @@
public DependentContext(Class<? extends Annotation> scopeType)
{
super(Dependent.class);
+ active = false;
}
@Override
+ public <T> T get(Bean<T> bean, boolean create)
+ {
+ if (!active)
+ {
+ throw new ContextNotActiveException();
+ }
+
+ return create == false ? null : bean.create();
+ }
+
+ @Override
public String toString()
{
return "Dependent context";
}
-
}
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/NormalContext.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/NormalContext.java 2008-10-28
00:54:40 UTC (rev 188)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/NormalContext.java 2008-10-28
07:15:16 UTC (rev 189)
@@ -2,12 +2,49 @@
import java.lang.annotation.Annotation;
+import javax.webbeans.ContextNotActiveException;
+import javax.webbeans.manager.Bean;
+
public abstract class NormalContext extends AbstractContext
{
public NormalContext(Class<? extends Annotation> scopeType)
{
super(scopeType);
+ active = true;
}
+
+ public <T> T get(Bean<T> bean, boolean create)
+ {
+ if (!active)
+ {
+ throw new ContextNotActiveException();
+ }
+
+ if (beans == null)
+ {
+ // Context has been destroyed
+ return null;
+ }
+
+ T instance = beans.get(bean);
+
+ if (instance != null)
+ {
+ return instance;
+ }
+ if (!create)
+ {
+ return null;
+ }
+
+ // TODO should bean creation be synchronized?
+
+ instance = bean.create();
+
+ beans.put(bean, instance);
+ return instance;
+ }
+
}
Show replies by date