[seam-commits] Seam SVN: r13821 - in modules/xml/trunk/impl/src: test/java/org/jboss/seam/xml/test/simple and 1 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Sat Oct 9 20:28:38 EDT 2010


Author: swd847
Date: 2010-10-09 20:28:38 -0400 (Sat, 09 Oct 2010)
New Revision: 13821

Added:
   modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/simple/ScopeOverrideBean.java
   modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/simple/ScopeOverrideTest.java
Modified:
   modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/BeanResult.java
   modules/xml/trunk/impl/src/test/resources/org/jboss/seam/xml/test/simple/simple-beans.xml
Log:
SEAMXML-17 add ability to override the scope of a bean


Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/BeanResult.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/BeanResult.java	2010-10-10 00:27:40 UTC (rev 13820)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/BeanResult.java	2010-10-10 00:28:38 UTC (rev 13821)
@@ -27,9 +27,7 @@
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 import javax.enterprise.context.NormalScope;
 import javax.enterprise.inject.spi.AnnotatedType;
@@ -50,10 +48,6 @@
 
    private final BeanManager beanManager;
 
-   private final Map<Method, Annotation> methodScopeOverrides;
-   private final Map<Field, Annotation> fieldScopeOverrides;
-   private Annotation beanScopeOverride = null;
-
    public BeanResult(Class<X> type, boolean readAnnotations, BeanResultType beanType, List<FieldValueObject> fieldValues, List<BeanResult<?>> inlineBeans, BeanManager beanManager)
    {
       this.beanManager = beanManager;
@@ -69,8 +63,6 @@
       this.beanType = beanType;
       this.fieldValues = new ArrayList<FieldValueObject>(fieldValues);
       this.inlineBeans = new ArrayList<BeanResult<?>>(inlineBeans);
-      methodScopeOverrides = new HashMap<Method, Annotation>();
-      fieldScopeOverrides = new HashMap<Field, Annotation>();
    }
 
    public List<BeanResult<?>> getInlineBeans()
@@ -98,7 +90,15 @@
       // TODO: this should be done with the BeanManager one WELD-721 is resolved
       if (annotation.annotationType().isAnnotationPresent(Scope.class) || annotation.annotationType().isAnnotationPresent(NormalScope.class))
       {
-         beanScopeOverride = annotation;
+         // if the user is adding a new scope we need to remove any existing
+         // ones
+         for (Annotation typeAnnotation : type.getAnnotations())
+         {
+            if (typeAnnotation.annotationType().isAnnotationPresent(Scope.class) || typeAnnotation.annotationType().isAnnotationPresent(NormalScope.class))
+            {
+               builder.removeFromClass(typeAnnotation.annotationType());
+            }
+         }
       }
       builder.addToClass(annotation);
    }
@@ -107,7 +107,13 @@
    {
       if (annotation.annotationType().isAnnotationPresent(Scope.class) || annotation.annotationType().isAnnotationPresent(NormalScope.class))
       {
-         fieldScopeOverrides.put(field, annotation);
+         for (Annotation typeAnnotation : field.getAnnotations())
+         {
+            if (typeAnnotation.annotationType().isAnnotationPresent(Scope.class) || typeAnnotation.annotationType().isAnnotationPresent(NormalScope.class))
+            {
+               builder.removeFromField(field, typeAnnotation.annotationType());
+            }
+         }
       }
       builder.addToField(field, annotation);
    }
@@ -116,7 +122,13 @@
    {
       if (annotation.annotationType().isAnnotationPresent(Scope.class) || annotation.annotationType().isAnnotationPresent(NormalScope.class))
       {
-         methodScopeOverrides.put(method, annotation);
+         for (Annotation typeAnnotation : method.getAnnotations())
+         {
+            if (typeAnnotation.annotationType().isAnnotationPresent(Scope.class) || typeAnnotation.annotationType().isAnnotationPresent(NormalScope.class))
+            {
+               builder.removeFromMethod(method, typeAnnotation.annotationType());
+            }
+         }
       }
       builder.addToMethod(method, annotation);
    }

Added: modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/simple/ScopeOverrideBean.java
===================================================================
--- modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/simple/ScopeOverrideBean.java	                        (rev 0)
+++ modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/simple/ScopeOverrideBean.java	2010-10-10 00:28:38 UTC (rev 13821)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.xml.test.simple;
+
+import javax.enterprise.context.Dependent;
+
+ at Dependent
+public class ScopeOverrideBean
+{
+   public ScopeOverrideBean()
+   {
+      value = 1;
+   }
+
+   private int value;
+
+   public int getValue()
+   {
+      return value;
+   }
+
+   public void setValue(int value)
+   {
+      this.value = value;
+   }
+
+}

Added: modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/simple/ScopeOverrideTest.java
===================================================================
--- modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/simple/ScopeOverrideTest.java	                        (rev 0)
+++ modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/simple/ScopeOverrideTest.java	2010-10-10 00:28:38 UTC (rev 13821)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.xml.test.simple;
+
+import junit.framework.Assert;
+
+import org.jboss.seam.xml.test.AbstractXMLTest;
+import org.junit.Test;
+
+public class ScopeOverrideTest extends AbstractXMLTest
+{
+
+   @Override
+   protected String getXmlFileName()
+   {
+      return "simple-beans.xml";
+   }
+
+   @Test
+   public void scopeOverrideTest()
+   {
+      ScopeOverrideBean x = getReference(ScopeOverrideBean.class);
+      x.setValue(10);
+      x = getReference(ScopeOverrideBean.class);
+      Assert.assertEquals(10, x.getValue());
+   }
+
+}

Modified: modules/xml/trunk/impl/src/test/resources/org/jboss/seam/xml/test/simple/simple-beans.xml
===================================================================
--- modules/xml/trunk/impl/src/test/resources/org/jboss/seam/xml/test/simple/simple-beans.xml	2010-10-10 00:27:40 UTC (rev 13820)
+++ modules/xml/trunk/impl/src/test/resources/org/jboss/seam/xml/test/simple/simple-beans.xml	2010-10-10 00:28:38 UTC (rev 13821)
@@ -33,4 +33,8 @@
          <test:ExtendedQualifier2/>
     </test:ExtendedBean>
           
+    <test:ScopeOverrideBean>
+      <modifies/>
+      <ApplicationScoped/>
+    </test:ScopeOverrideBean>      
 </beans>
\ No newline at end of file



More information about the seam-commits mailing list