You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by ge...@apache.org on 2009/04/22 23:42:08 UTC
svn commit: r767680 - in
/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans:
component/ config/ container/ container/activity/ util/
Author: gerdogdu
Date: Wed Apr 22 21:42:07 2009
New Revision: 767680
URL: http://svn.apache.org/viewvc?rev=767680&view=rev
Log:
Updating the 11.6 Activitiy Managers Manager#setCurrent.
Modified:
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ComponentImpl.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContainerDeployer.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ManagerImpl.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/activity/ActivityManager.java (contents, props changed)
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/component/ComponentImpl.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ComponentImpl.java?rev=767680&r1=767679&r2=767680&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ComponentImpl.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ComponentImpl.java Wed Apr 22 21:42:07 2009
@@ -73,6 +73,7 @@
@Override
+ @SuppressWarnings("unchecked")
protected void destroyComponentInstance(T instance)
{
if (WebBeansUtil.isContainsInterceptorMethod(getInterceptorStack(), InterceptorType.PRE_DESTROY))
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContainerDeployer.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContainerDeployer.java?rev=767680&r1=767679&r2=767680&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContainerDeployer.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContainerDeployer.java Wed Apr 22 21:42:07 2009
@@ -42,7 +42,6 @@
import org.apache.webbeans.component.WebBeansType;
import org.apache.webbeans.container.InjectionResolver;
import org.apache.webbeans.container.ManagerImpl;
-import org.apache.webbeans.container.activity.ActivityManager;
import org.apache.webbeans.decorator.DecoratorUtil;
import org.apache.webbeans.deployment.StereoTypeManager;
import org.apache.webbeans.deployment.StereoTypeModel;
@@ -495,7 +494,7 @@
component = SimpleWebBeansConfigurator.define(clazz, WebBeansType.SIMPLE);
if (component != null)
{
- ActivityManager.addBean(WebBeansUtil.createNewSimpleBeanComponent(component));
+ ManagerImpl.getManager().addBean(WebBeansUtil.createNewSimpleBeanComponent(component));
DecoratorUtil.checkSimpleWebBeanDecoratorConditions(component);
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ManagerImpl.java?rev=767680&r1=767679&r2=767680&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ManagerImpl.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ManagerImpl.java Wed Apr 22 21:42:07 2009
@@ -74,29 +74,46 @@
@SuppressWarnings("unchecked")
public class ManagerImpl implements Manager, Referenceable
{
+ /**Holds the context with key scope*/
private Map<Class<? extends Annotation>, List<Context>> contextMap = new ConcurrentHashMap<Class<? extends Annotation>, List<Context>>();
+ /**Activity webbeans components*/
private Set<Bean<?>> components = new CopyOnWriteArraySet<Bean<?>>();
+ /**Activity interceptors*/
private Set<Interceptor> webBeansInterceptors = new CopyOnWriteArraySet<Interceptor>();
+ /**Activity decorators*/
private Set<Decorator> webBeansDecorators = new CopyOnWriteArraySet<Decorator>();
+ /**Event notification manager instance*/
private NotificationManager notificationManager = null;
+ /**Injection resolver instance*/
private InjectionResolver injectionResolver = null;
+ /**Proxy map for the webbeans components*/
private Map<Bean<?>, Object> proxyMap = Collections.synchronizedMap(new IdentityHashMap<Bean<?>, Object>());
+ /**XML configurator instance*/
private WebBeansXMLConfigurator xmlConfigurator = null;
-
+ /**
+ * Creates a new {@link Manager} instance.
+ * Called by the system. Do not use outside of the
+ * system.
+ */
public ManagerImpl()
{
injectionResolver = InjectionResolver.getInstance();
notificationManager = NotificationManager.getInstance();
}
+ /**
+ * Gets current activity.
+ *
+ * @return the current activity
+ */
public static ManagerImpl getManager()
{
ActivityManager activityManager = ActivityManager.getInstance();
@@ -106,25 +123,39 @@
return currentManager;
}
- public void setXMLConfigurator(WebBeansXMLConfigurator xmlConfigurator)
+
+ /**
+ * Sets the xml configurator instance.
+ *
+ * @param xmlConfigurator set xml configurator instance.
+ * @see WebBeansXMLConfigurator
+ */
+ public synchronized void setXMLConfigurator(WebBeansXMLConfigurator xmlConfigurator)
{
if(this.xmlConfigurator != null)
{
- throw new IllegalStateException("There is a WebBeansXMLConfigurator defined already");
+ throw new IllegalStateException("WebBeansXMLConfigurator is already defined!");
}
this.xmlConfigurator = xmlConfigurator;
}
- public Context getContext(Class<? extends Annotation> scopType)
+ /**
+ * Gets the active context for the given scope type.
+ *
+ * @param scopeType scope type of the context
+ * @throws ContextNotActiveException if no active context
+ * @throws IllegalStateException if more than one active context
+ */
+ public Context getContext(Class<? extends Annotation> scopeType)
{
- Asserts.assertNotNull(scopType, "scopeType paramter can not be null");
+ Asserts.assertNotNull(scopeType, "scopeType paramter can not be null");
List<Context> contexts = new ArrayList<Context>();
Context standardContext = null;
- standardContext = ContextFactory.getStandardContext(scopType);
+ standardContext = ContextFactory.getStandardContext(scopeType);
if(standardContext != null)
{
@@ -134,7 +165,7 @@
}
}
- List<Context> others = this.contextMap.get(scopType);
+ List<Context> others = this.contextMap.get(scopeType);
if(others != null)
{
for(Context otherContext : others)
@@ -150,17 +181,23 @@
// Still null
if (contexts.isEmpty())
{
- throw new ContextNotActiveException("WebBeans context with scope type annotation @" + scopType.getSimpleName() + " does not exist within current thread");
+ throw new ContextNotActiveException("WebBeans context with scope type annotation @" + scopeType.getSimpleName() + " does not exist within current thread");
}
else if(contexts.size() > 1)
{
- throw new IllegalStateException("More than one active context exists with scope type annotation @" + scopType.getSimpleName());
+ throw new IllegalStateException("More than one active context exists with scope type annotation @" + scopeType.getSimpleName());
}
return contexts.get(0);
}
+ /**
+ * Add new webbeans component to the activity.
+ *
+ * @param component new webbeans component
+ * @return the this activity
+ */
public Manager addBean(Bean<?> component)
{
if(component instanceof AbstractComponent)
@@ -184,7 +221,8 @@
return this;
}
-
+
+
public void fireEvent(Object event, Annotation... bindings)
{
if (ClassUtil.isParametrized(event.getClass()))
@@ -500,9 +538,23 @@
return new ChildActivityManager(this);
}
+ /**
+ * Set the activity for the given scope type.
+ *
+ * @param scopeType scope type for the context
+ */
public Manager setCurrent(Class<? extends Annotation> scopeType)
{
- // TODO Auto-generated method stub
- return null;
+ if(!WebBeansUtil.isScopeTypeNormal(scopeType))
+ {
+ throw new IllegalArgumentException("Scope type : " + scopeType.getSimpleName() + " must be normal scope type");
+
+ }
+
+ Context context = getContext(scopeType);
+
+ ActivityManager.getInstance().addCurrentActivity(context, this);
+
+ return this;
}
}
\ No newline at end of file
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/activity/ActivityManager.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/activity/ActivityManager.java?rev=767680&r1=767679&r2=767680&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/activity/ActivityManager.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/activity/ActivityManager.java Wed Apr 22 21:42:07 2009
@@ -17,22 +17,49 @@
package org.apache.webbeans.container.activity;
-import javax.inject.manager.Bean;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.context.Context;
import org.apache.webbeans.config.WebBeansFinder;
import org.apache.webbeans.container.ManagerImpl;
+import org.apache.webbeans.exception.WebBeansException;
+/**
+ * Class is responsible for managing the activities.
+ *
+ * <p>
+ * There is always one root activity.
+ * </p>
+ *
+ * @version $Rev$ $Date$
+ */
public class ActivityManager
{
+ /**Root activity*/
private ManagerImpl rootActivity = null;
- private ManagerImpl currentActivity = null;
+ /**Setted current activities*/
+ private Map<Context, ManagerImpl> currentActivityMap = new ConcurrentHashMap<Context, ManagerImpl>();
+ /**
+ * Used by the system. Do not
+ * instantiate this from outside.
+ */
public ActivityManager()
{
}
+ /**
+ * Gets the activity manager.
+ *
+ * @return the singleton acitivity manager
+ */
public static ActivityManager getInstance()
{
ActivityManager currentActivityManager = (ActivityManager)WebBeansFinder.getSingletonInstance(ActivityManager.class.getName());
@@ -40,28 +67,77 @@
return currentActivityManager;
}
- public void setRootActivity(ManagerImpl rootActivity)
+
+ /**
+ * Sets the root activity
+ *
+ * @param rootActivity root activity
+ */
+ public synchronized void setRootActivity(ManagerImpl rootActivity)
{
this.rootActivity = rootActivity;
}
+ /**
+ * Gets root activity
+ *
+ * @return the root activity
+ */
public ManagerImpl getRootActivity()
{
return this.rootActivity;
}
- public static void addBean(Bean<?> bean)
- {
- getInstance().getRootActivity().addBean(bean);
- }
-
- public void setCurrentActivity(ManagerImpl currentManager)
- {
- currentActivity = currentManager;
- }
+ /**
+ * Add new current activity for the context.
+ *
+ * @param context
+ * @param currentManager
+ */
+ public void addCurrentActivity(Context context, ManagerImpl currentManager)
+ {
+ this.currentActivityMap.put(context, currentManager);
+ }
+
+ /**
+ * Looks for the registered current activities.
+ * <ul>
+ * <li>If there are more than one activity, throws exception.</li>
+ * <li>If no registered current activity, return the root activity.
+ * </ul>
+ *
+ *
+ * @return the current activity
+ * @throws WebBeansException if more than one current activity exist
+ */
public ManagerImpl getCurrentActivity()
{
+ ManagerImpl currentActivity = null;
+
+ Set<Context> contexts = this.currentActivityMap.keySet();
+ List<ManagerImpl> managers = new ArrayList<ManagerImpl>();
+ for(Context context : contexts)
+ {
+ if(context.isActive())
+ {
+ managers.add(this.currentActivityMap.get(context));
+ }
+ }
+
+ if(managers.size() > 1)
+ {
+ throw new WebBeansException("There are more than one current activity");
+ }
+ else
+ {
+ if(!managers.isEmpty())
+ {
+ currentActivity = managers.get(0);
+ }
+ }
+
+
if(currentActivity == null)
{
return getRootActivity();
Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/activity/ActivityManager.java
------------------------------------------------------------------------------
svn:keywords = Date Rev
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=767680&r1=767679&r2=767680&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 Wed Apr 22 21:42:07 2009
@@ -93,7 +93,6 @@
import org.apache.webbeans.config.EJBWebBeansConfigurator;
import org.apache.webbeans.config.SimpleWebBeansConfigurator;
import org.apache.webbeans.container.ManagerImpl;
-import org.apache.webbeans.container.activity.ActivityManager;
import org.apache.webbeans.conversation.ConversationImpl;
import org.apache.webbeans.decorator.DecoratorUtil;
import org.apache.webbeans.decorator.DecoratorsManager;
@@ -1759,7 +1758,7 @@
bindings = injectionPoint.getBindings().toArray(bindings);
Bean<?> bean = createObservableImplicitComponent(EventImpl.class, clazz, bindings);
- ActivityManager.addBean(bean);
+ ManagerImpl.getManager().addBean(bean);
}
}
@@ -1774,7 +1773,7 @@
bindings = injectionPoint.getBindings().toArray(bindings);
Bean<Instance<T>> bean = createInstanceComponent(genericType,clazz, genericType.getActualTypeArguments()[0], bindings);
- ActivityManager.addBean(bean);
+ ManagerImpl.getManager().addBean(bean);
}