[seam-commits] Seam SVN: r13818 - in modules/xml/trunk: impl/src/main/java/org/jboss/seam/xml and 3 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Sat Oct 9 18:47:06 EDT 2010


Author: swd847
Date: 2010-10-09 18:47:06 -0400 (Sat, 09 Oct 2010)
New Revision: 13818

Removed:
   modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/annotations/
Modified:
   modules/xml/trunk/docs/src/main/docbook/en-US/xml-general.xml
   modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/bootstrap/XmlExtension.java
   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/model/ClassXmlItem.java
   modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/PropertyXmlItem.java
Log:
minor refactoring


Modified: modules/xml/trunk/docs/src/main/docbook/en-US/xml-general.xml
===================================================================
--- modules/xml/trunk/docs/src/main/docbook/en-US/xml-general.xml	2010-10-09 12:33:10 UTC (rev 13817)
+++ modules/xml/trunk/docs/src/main/docbook/en-US/xml-general.xml	2010-10-09 22:47:06 UTC (rev 13818)
@@ -429,8 +429,7 @@
     <s:array>
       <test:MethodValueBean/>
     </s:array>
-</test:method>
-        ]]>
+</test:method>]]>
         </programlisting>
     </section>
    <section>

Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/bootstrap/XmlExtension.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/bootstrap/XmlExtension.java	2010-10-09 12:33:10 UTC (rev 13817)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/bootstrap/XmlExtension.java	2010-10-09 22:47:06 UTC (rev 13818)
@@ -30,8 +30,8 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.Map.Entry;
 import java.util.Set;
+import java.util.Map.Entry;
 
 import javax.enterprise.event.Observes;
 import javax.enterprise.inject.spi.AfterBeanDiscovery;
@@ -42,7 +42,6 @@
 import javax.enterprise.inject.spi.Extension;
 import javax.enterprise.inject.spi.ProcessAnnotatedType;
 import javax.enterprise.inject.spi.ProcessInjectionTarget;
-import javax.enterprise.util.AnnotationLiteral;
 import javax.inject.Named;
 
 import org.jboss.seam.xml.core.BeanResult;
@@ -62,24 +61,24 @@
 public class XmlExtension implements Extension
 {
 
-   AnnotationInstanceProvider ac = new AnnotationInstanceProvider();
+   private AnnotationInstanceProvider annotationInstanceProvider = new AnnotationInstanceProvider();
 
    static final String PROVIDERS_FILE = "META-INF/services/org.jboss.seam.xml.XmlExtension";
 
-   List<XmlResult> results = new ArrayList<XmlResult>();
+   private List<XmlResult> results = new ArrayList<XmlResult>();
 
-   Set<Class<?>> veto = new HashSet<Class<?>>();
+   private Set<Class<?>> veto = new HashSet<Class<?>>();
 
-   int count = 0;
+   private int count = 0;
 
    private static final Logger log = LoggerFactory.getLogger(XmlExtension.class);
 
    /**
     * map of syntetic bean id to a list of field value objects
     */
-   Map<Integer, List<FieldValueObject>> fieldValues = new HashMap<Integer, List<FieldValueObject>>();
+   private Map<Integer, List<FieldValueObject>> fieldValues = new HashMap<Integer, List<FieldValueObject>>();
 
-   List<Exception> errors = new ArrayList<Exception>();
+   private List<Exception> errors = new ArrayList<Exception>();
 
    /**
     * This is the entry point for the extension
@@ -114,13 +113,22 @@
       // build the generic bean data
       for (XmlResult r : results)
       {
-         // add the qualifiers as we need them before we process the generic
-         // bean info
+         // add the qualifiers etc first
          for (Class<? extends Annotation> b : r.getQualifiers())
          {
             log.info("Adding XML Defined Qualifier: " + b.getName());
             event.addQualifier(b);
          }
+         for (Class<? extends Annotation> b : r.getInterceptorBindings())
+         {
+            log.info("Adding XML Defined Interceptor Binding: " + b.getName());
+            event.addInterceptorBinding(b);
+         }
+         for (Entry<Class<? extends Annotation>, Annotation[]> b : r.getStereotypes().entrySet())
+         {
+            log.info("Adding XML Defined Stereotype: " + b.getKey().getName());
+            event.addStereotype(b.getKey(), b.getValue());
+         }
       }
 
       for (XmlResult r : results)
@@ -140,27 +148,14 @@
                fieldValues.put(val, b.getFieldValues());
                Map<String, Object> am = new HashMap<String, Object>();
                am.put("value", val);
-               Annotation a = ac.get(XmlId.class, am);
-               b.getBuilder().addToClass(a);
+               Annotation a = annotationInstanceProvider.get(XmlId.class, am);
+               b.addToClass(a);
             }
          }
 
-         for (Class<? extends Annotation> b : r.getInterceptorBindings())
-         {
-            log.info("Adding XML Defined Interceptor Binding: " + b.getName());
-            event.addInterceptorBinding(b);
-         }
-         for (Entry<Class<? extends Annotation>, Annotation[]> b : r.getStereotypes().entrySet())
-         {
-            log.info("Adding XML Defined Stereotype: " + b.getKey().getName());
-            event.addStereotype(b.getKey(), b.getValue());
-         }
          for (BeanResult<?> bb : r.getFlattenedBeans())
          {
-            bb.getBuilder().addToClass(new AnnotationLiteral<XmlConfiguredBean>()
-            {
-            });
-            AnnotatedType<?> tp = bb.getBuilder().create();
+            AnnotatedType<?> tp = bb.getAnnotatedType();
             log.info("Adding XML Defined Bean: " + tp.getJavaClass().getName());
             event.addAnnotatedType(tp);
          }

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-09 12:33:10 UTC (rev 13817)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/BeanResult.java	2010-10-09 22:47:06 UTC (rev 13818)
@@ -21,10 +21,21 @@
  */
 package org.jboss.seam.xml.core;
 
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+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;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Scope;
+
 import org.jboss.seam.xml.fieldset.FieldValueObject;
 import org.jboss.weld.extensions.core.Veto;
 import org.jboss.weld.extensions.reflection.annotated.AnnotatedTypeBuilder;
@@ -37,10 +48,18 @@
    private final List<FieldValueObject> fieldValues;
    private final List<BeanResult<?>> inlineBeans;
 
-   public BeanResult(Class<X> type, boolean readAnnotations, BeanResultType beanType, List<FieldValueObject> fieldValues, List<BeanResult<?>> inlineBeans)
+   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;
       this.type = type;
-      builder = new AnnotatedTypeBuilder().setJavaClass(type);
+      builder = new AnnotatedTypeBuilder<X>().setJavaClass(type);
+      builder.addToClass(XmlConfiguredBeanLiteral.INSTANCE);
       if (readAnnotations)
       {
          builder.readFromType(type);
@@ -50,6 +69,8 @@
       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()
@@ -57,11 +78,6 @@
       return inlineBeans;
    }
 
-   public AnnotatedTypeBuilder<X> getBuilder()
-   {
-      return builder;
-   }
-
    public Class<X> getType()
    {
       return type;
@@ -77,4 +93,57 @@
       return Collections.unmodifiableList(fieldValues);
    }
 
+   public void addToClass(Annotation annotation)
+   {
+      // 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;
+      }
+      builder.addToClass(annotation);
+   }
+
+   public void addToField(Field field, Annotation annotation)
+   {
+      if (annotation.annotationType().isAnnotationPresent(Scope.class) || annotation.annotationType().isAnnotationPresent(NormalScope.class))
+      {
+         fieldScopeOverrides.put(field, annotation);
+      }
+      builder.addToField(field, annotation);
+   }
+
+   public void addToMethod(Method method, Annotation annotation)
+   {
+      if (annotation.annotationType().isAnnotationPresent(Scope.class) || annotation.annotationType().isAnnotationPresent(NormalScope.class))
+      {
+         methodScopeOverrides.put(method, annotation);
+      }
+      builder.addToMethod(method, annotation);
+   }
+
+   public void addToMethodParameter(Method method, int param, Annotation annotation)
+   {
+      builder.addToMethodParameter(method, param, annotation);
+   }
+
+   public void addToConstructor(Constructor<?> constructor, Annotation annotation)
+   {
+      builder.addToConstructor((Constructor) constructor, annotation);
+   }
+
+   public void addToConstructorParameter(Constructor<?> constructor, int param, Annotation annotation)
+   {
+      builder.addToConstructorParameter((Constructor) constructor, param, annotation);
+   }
+
+   public void overrideFieldType(Field field, Class<?> javaClass)
+   {
+      builder.overrideFieldType(field, javaClass);
+   }
+
+   public AnnotatedType<?> getAnnotatedType()
+   {
+      return builder.create();
+   }
+
 }

Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ClassXmlItem.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ClassXmlItem.java	2010-10-09 12:33:10 UTC (rev 13817)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ClassXmlItem.java	2010-10-09 22:47:06 UTC (rev 13818)
@@ -29,12 +29,10 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.Map.Entry;
 import java.util.Set;
+import java.util.Map.Entry;
 
 import javax.enterprise.inject.spi.BeanManager;
-import javax.enterprise.util.AnnotationLiteral;
-import javax.inject.Inject;
 
 import org.jboss.seam.xml.core.BeanResult;
 import org.jboss.seam.xml.core.BeanResultType;
@@ -42,18 +40,18 @@
 import org.jboss.seam.xml.fieldset.FieldValueObject;
 import org.jboss.seam.xml.util.TypeOccuranceInformation;
 import org.jboss.seam.xml.util.XmlConfigurationException;
+import org.jboss.weld.extensions.literal.InjectLiteral;
 import org.jboss.weld.extensions.properties.Properties;
 import org.jboss.weld.extensions.properties.Property;
 import org.jboss.weld.extensions.properties.query.NamedPropertyCriteria;
 import org.jboss.weld.extensions.properties.query.PropertyQueries;
 import org.jboss.weld.extensions.properties.query.PropertyQuery;
 import org.jboss.weld.extensions.reflection.Reflections;
-import org.jboss.weld.extensions.reflection.annotated.AnnotatedTypeBuilder;
 
 public class ClassXmlItem extends AbstractXmlItem
 {
 
-   HashSet<TypeOccuranceInformation> allowed = new HashSet<TypeOccuranceInformation>();
+   private HashSet<TypeOccuranceInformation> allowed = new HashSet<TypeOccuranceInformation>();
 
    public ClassXmlItem(XmlItem parent, Class<?> c, Map<String, String> attributes, String document, int lineno)
    {
@@ -97,20 +95,12 @@
    {
       boolean override = !getChildrenOfType(ReplacesXmlItem.class).isEmpty();
       boolean extend = !getChildrenOfType(ModifiesXmlItem.class).isEmpty();
-      BeanResultType beanType = BeanResultType.ADD;
       if (override && extend)
       {
          throw new XmlConfigurationException("A bean may not both <override> and <extend> an existing bean", getDocument(), getLineno());
       }
-      if (override)
-      {
-         beanType = BeanResultType.REPLACES;
-      }
-      else if (extend)
-      {
-         beanType = BeanResultType.MODIFIES;
-      }
-      List<BeanResult> inlineBeans = new ArrayList<BeanResult>();
+      BeanResultType beanType = override ? BeanResultType.REPLACES : (extend ? BeanResultType.MODIFIES : BeanResultType.ADD);
+      List<BeanResult<?>> inlineBeans = new ArrayList<BeanResult<?>>();
       // get all the field values from the bean
       Set<String> configuredFields = new HashSet<String>();
       List<FieldValueObject> fields = new ArrayList<FieldValueObject>();
@@ -136,16 +126,16 @@
 
       // if it is an extend we want to read the annotations from the underlying
       // class
-      BeanResult<?> result = new BeanResult(getJavaClass(), extend, beanType, fields, inlineBeans);
-      AnnotatedTypeBuilder<?> type = result.getBuilder();
-      // list of constructor arguments
+      BeanResult<?> result = new BeanResult(getJavaClass(), extend, beanType, fields, inlineBeans, manager);
+
       List<ParameterXmlItem> constList = new ArrayList<ParameterXmlItem>();
 
       for (AnnotationXmlItem item : getChildrenOfType(AnnotationXmlItem.class))
       {
          Annotation a = AnnotationUtils.createAnnotation(item);
-         type.addToClass(a);
+         result.addToClass(a);
       }
+      // list of constructor arguments
       List<ParametersXmlItem> constructorParameters = getChildrenOfType(ParametersXmlItem.class);
       if (constructorParameters.size() > 1)
       {
@@ -165,7 +155,7 @@
             for (AnnotationXmlItem fi : item.getChildrenOfType(AnnotationXmlItem.class))
             {
                Annotation a = AnnotationUtils.createAnnotation(fi);
-               type.addToField(item.getField(), a);
+               result.addToField(item.getField(), a);
             }
          }
          else if (!item.getChildrenOfType(AnnotationXmlItem.class).isEmpty())
@@ -180,7 +170,7 @@
          for (AnnotationXmlItem fi : item.getChildrenOfType(AnnotationXmlItem.class))
          {
             Annotation a = AnnotationUtils.createAnnotation(fi);
-            type.addToMethod(item.getMethod(), a);
+            result.addToMethod(item.getMethod(), a);
          }
          List<ParametersXmlItem> parameters = item.getChildrenOfType(ParametersXmlItem.class);
          if (parameters.size() > 1)
@@ -195,7 +185,7 @@
                for (AnnotationXmlItem pan : fi.getChildrenOfType(AnnotationXmlItem.class))
                {
                   Annotation a = AnnotationUtils.createAnnotation(pan);
-                  type.addToMethodParameter(item.getMethod(), param, a);
+                  result.addToMethodParameter(item.getMethod(), param, a);
                }
             }
          }
@@ -205,18 +195,16 @@
       if (!constList.isEmpty())
       {
          int paramCount = 0;
-         Constructor<?> c = resolveConstructor(constList);
+         Constructor<?> constructor = resolveConstructor(constList);
          // we automatically add inject to the constructor
-         type.addToConstructor((Constructor) c, new AnnotationLiteral<Inject>()
-         {
-         });
+         result.addToConstructor(constructor, InjectLiteral.INSTANCE);
          for (ParameterXmlItem fi : constList)
          {
             int param = paramCount++;
             for (AnnotationXmlItem pan : fi.getChildrenOfType(AnnotationXmlItem.class))
             {
                Annotation a = AnnotationUtils.createAnnotation(pan);
-               type.addToConstructorParameter((Constructor) c, param, a);
+               result.addToConstructorParameter(constructor, param, a);
             }
          }
       }
@@ -238,7 +226,7 @@
          throw new XmlConfigurationException("A virtual producer field may not containe <override> or <extend> tags", getDocument(), getLineno());
       }
       Field member = org.jboss.seam.xml.util.Reflections.getField(VirtualProducerField.class, "field");
-      ClassXmlItem vclass = new ClassXmlItem(null, VirtualProducerField.class, Collections.EMPTY_MAP, document, lineno);
+      ClassXmlItem vclass = new ClassXmlItem(null, VirtualProducerField.class, Collections.<String, String> emptyMap(), document, lineno);
       PropertyXmlItem field = new PropertyXmlItem(vclass, Properties.createProperty(member), null, getJavaClass(), document, lineno);
       vclass.addChild(field);
       for (XmlItem i : this.getChildren())
@@ -247,8 +235,7 @@
       }
       field.resolveChildren(manager);
       BeanResult<?> result = vclass.createBeanResult(manager);
-      AnnotatedTypeBuilder<?> builder = result.getBuilder();
-      builder.overrideFieldType(member, this.getJavaClass());
+      result.overrideFieldType(member, this.getJavaClass());
       return result;
    }
 

Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/PropertyXmlItem.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/PropertyXmlItem.java	2010-10-09 12:33:10 UTC (rev 13817)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/PropertyXmlItem.java	2010-10-09 22:47:06 UTC (rev 13818)
@@ -202,7 +202,7 @@
       return allowed;
    }
 
-   public Collection<? extends BeanResult> getInlineBeans()
+   public Collection<? extends BeanResult<?>> getInlineBeans()
    {
       return inlineBeans;
    }



More information about the seam-commits mailing list