openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r906455 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/component/ main/java/org/apache/webbeans/container/ test/java/org/apache/webbeans/test/
Date Thu, 04 Feb 2010 11:29:22 GMT
Author: struberg
Date: Thu Feb  4 11:29:21 2010
New Revision: 906455

URL: http://svn.apache.org/viewvc?rev=906455&view=rev
Log:
OWB-261 Implement BeanManager#getPassivationCapableBean(String id)
OWB-262 Beans defined via TextContext XML only add once.
OWB-6 scope passivation

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/BaseBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractBean.java?rev=906455&r1=906454&r2=906455&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractBean.java
Thu Feb  4 11:29:21 2010
@@ -110,7 +110,7 @@
      * Constructor definiton. Each subclass redefines its own constructor with
      * calling this.
      * 
-     * @param name name of the bean
+     * @param returnType of the bean
      * @param webBeansType web beans type
      */
     protected AbstractBean(WebBeansType webBeansType, Class<T> returnType)
@@ -228,6 +228,29 @@
     }
 
     /**
+     * This is needed for serialization
+     * @return the id uniquely identifying the bean.
+     * @see javax.enterprise.inject.spi.PassivationCapable#getId() 
+     */
+    public String getId()
+    {
+        if (!isEnabled()) {
+            return null;
+        }
+        
+        StringBuilder sb = new StringBuilder(webBeansType.toString()).append('#');
+        sb.append(returnType).append('#');
+        for (Annotation qualifier : implQualifiers)
+        {
+            sb.append(qualifier.toString()).append(',');
+        }
+
+        //X TODO there are most probably other infos which must get added to make the id
unique! 
+
+        return sb.toString();
+    }
+
+    /**
      * Get bean type.
      * 
      * @return bean type

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/BaseBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/BaseBean.java?rev=906455&r1=906454&r2=906455&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/BaseBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/BaseBean.java
Thu Feb  4 11:29:21 2010
@@ -13,15 +13,13 @@
  */
 package org.apache.webbeans.component;
 
+import java.io.Serializable;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Member;
 import java.util.List;
 import java.util.Set;
 
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.enterprise.inject.spi.Decorator;
-import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.*;
 
 import org.apache.webbeans.config.inheritance.IBeanInheritedMetaData;
 import org.apache.webbeans.intercept.InterceptorData;
@@ -34,9 +32,9 @@
  * @version $Rev$ $Date$
  * <T> bean class
  */
-public abstract class BaseBean<T> implements Bean<T>
+public abstract class BaseBean<T> implements Bean<T>, PassivationCapable, Serializable
 {
-	/**Bean Manager*/
+    /**Bean Manager*/
     private final BeanManager manager;
 
     /**

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java?rev=906455&r1=906454&r2=906455&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
Thu Feb  4 11:29:21 2010
@@ -40,17 +40,7 @@
 import javax.enterprise.inject.AmbiguousResolutionException;
 import javax.enterprise.inject.Default;
 import javax.enterprise.inject.Stereotype;
-import javax.enterprise.inject.spi.Annotated;
-import javax.enterprise.inject.spi.AnnotatedType;
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.enterprise.inject.spi.BeforeBeanDiscovery;
-import javax.enterprise.inject.spi.Decorator;
-import javax.enterprise.inject.spi.InjectionPoint;
-import javax.enterprise.inject.spi.InjectionTarget;
-import javax.enterprise.inject.spi.InterceptionType;
-import javax.enterprise.inject.spi.Interceptor;
-import javax.enterprise.inject.spi.ObserverMethod;
+import javax.enterprise.inject.spi.*;
 import javax.enterprise.util.TypeLiteral;
 import javax.inject.Scope;
 import javax.naming.NamingException;
@@ -75,6 +65,7 @@
 import org.apache.webbeans.el.WebBeansELResolver;
 import org.apache.webbeans.event.NotificationManager;
 import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.exception.inject.DefinitionException;
 import org.apache.webbeans.intercept.InterceptorComparator;
 import org.apache.webbeans.intercept.WebBeansInterceptorConfig;
 import org.apache.webbeans.intercept.webbeans.WebBeansInterceptor;
@@ -144,7 +135,13 @@
     private ErrorStack errorStack = new ErrorStack();
     
     private List<AnnotatedType<?>> additionalAnnotatedTypes = new CopyOnWriteArrayList<AnnotatedType<?>>();
-    
+
+    /**
+     * This map stores all {@link PassivationCapable} beans along with their unique id.
+     * This is used for serialization.
+     */
+    private Map<String, Bean<?>> passivationCapableBeans = new ConcurrentHashMap<String,
Bean<?>>(); 
+
     /**
      * The parent Manager this child is depending from.
      */
@@ -289,18 +286,43 @@
     {
         if(component instanceof AbstractBean)
         {
-            this.components.add(component);    
+            this.components.add(component);
+            addPassivationCapableBean(component);
         }
         else
         {
             ThirdpartyBeanImpl<?> bean = new ThirdpartyBeanImpl(component);
             this.components.add(bean);
+            addPassivationCapableBean(bean);
         }
         
 
         return this;
     }
 
+    /**
+     * Check if the bean is PassivationCapable and add it to the id store.
+     *
+     * @param bean
+     * @throws DefinitionException if the id is not unique.
+     */
+    protected void addPassivationCapableBean(Bean<?> bean) throws DefinitionException
+    {
+        if (bean instanceof PassivationCapable)
+        {
+            PassivationCapable pc = (PassivationCapable) bean;
+            String id = pc.getId();
+            if (id != null)
+            {
+                Bean<?> oldBean = passivationCapableBeans.put(id, bean);
+                if (oldBean != null)
+                {
+                    throw new DefinitionException("PassivationCapable bean id is not unique:
" + id);
+                }
+            }
+        }
+    }
+
     
     public BeanManager addContext(Context context)
     {
@@ -674,7 +696,7 @@
     @Override
     public Bean<?> getPassivationCapableBean(String id)
     {
-        throw new UnsupportedOperationException();
+        return passivationCapableBeans.get(id);
     }
 
     /**

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java?rev=906455&r1=906454&r2=906455&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java
Thu Feb  4 11:29:21 2010
@@ -339,12 +339,6 @@
         XMLManagedBean<T> bean = null;
         bean = this.xmlConfigurator.configureSimpleWebBean(simpleClass, webBeanDecleration);
 
-        if (bean != null)
-        {
-            getComponents().add(bean);
-            manager.addBean(bean);
-        }
-
         return bean;
     }
 
@@ -382,7 +376,7 @@
      * @return XMLComponentImpl<?> with the WebBean definition
      */
     @SuppressWarnings("unchecked")
-    protected AbstractBean<?> getWebBeanFromXml(String xmlResourcePath, Class<?>
desiredClazz)
+    protected AbstractBean<?> getWebBeanFromXml(String xmlResourcePath, Class<?>
desiredClazz, Annotation... bindings)
     {
         InputStream stream = XMLTest.class.getClassLoader().getResourceAsStream(xmlResourcePath);
         Assert.assertNotNull(stream);
@@ -396,14 +390,11 @@
             defineXMLSimpleWebBeans(clazz, beanElement);
         }
 
-        for (AbstractBean<?> def : getComponents())
+        Set<Bean<?>> beans = getManager().getBeans(desiredClazz, bindings);
+        if (beans != null && beans.size() == 1)
         {
-            if (def.getReturnType().equals(desiredClazz))
-            {
-                return def;
-            }
+            return (AbstractBean<?>) beans.iterator().next();
         }
-
         return null;
     }
 



Mime
View raw message