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

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Tue Apr 13 05:33:28 EDT 2010


Author: swd847
Date: 2010-04-13 05:33:27 -0400 (Tue, 13 Apr 2010)
New Revision: 12448

Added:
   modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/GenericBeanResult.java
   modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/GenericBeanXmlItem.java
Modified:
   modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/XmlResult.java
   modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java
   modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/XmlItemType.java
   modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/parser/namespace/RootNamespaceElementResolver.java
Log:
Added parser support for generic beans



Added: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/GenericBeanResult.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/GenericBeanResult.java	                        (rev 0)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/GenericBeanResult.java	2010-04-13 09:33:27 UTC (rev 12448)
@@ -0,0 +1,28 @@
+package org.jboss.seam.xml.core;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class GenericBeanResult
+{
+   final Class genericBean;
+
+   final Set<Class> secondaryBeans;
+
+   public GenericBeanResult(Class genericBean, Set<Class> secondaryBeans)
+   {
+      this.genericBean = genericBean;
+      this.secondaryBeans = new HashSet<Class>(secondaryBeans);
+   }
+
+   public Class getGenericBean()
+   {
+      return genericBean;
+   }
+
+   public Set<Class> getSecondaryBeans()
+   {
+      return secondaryBeans;
+   }
+
+}

Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/XmlResult.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/XmlResult.java	2010-04-13 09:31:41 UTC (rev 12447)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/XmlResult.java	2010-04-13 09:33:27 UTC (rev 12448)
@@ -21,39 +21,61 @@
 public class XmlResult
 {
 
-   Map<Class<? extends Annotation>, Annotation[]> stereotypes = new HashMap<Class<? extends Annotation>, Annotation[]>();
+   private Map<Class<? extends Annotation>, Annotation[]> stereotypes = new HashMap<Class<? extends Annotation>, Annotation[]>();
 
-   List<Class<? extends Annotation>> qualifiers = new ArrayList<Class<? extends Annotation>>();
+   private List<Class<? extends Annotation>> qualifiers = new ArrayList<Class<? extends Annotation>>();
 
-   List<Class<? extends Annotation>> interceptorBindings = new ArrayList<Class<? extends Annotation>>();
+   private List<Class<? extends Annotation>> interceptorBindings = new ArrayList<Class<? extends Annotation>>();
 
-   List<Class<?>> veto = new ArrayList<Class<?>>();
+   private List<Class<?>> veto = new ArrayList<Class<?>>();
 
-   List<String> problems = new ArrayList<String>();
+   private List<String> problems = new ArrayList<String>();
 
-   List<BeanResult<?>> beans = new ArrayList<BeanResult<?>>();
+   private List<BeanResult<?>> beans = new ArrayList<BeanResult<?>>();
 
-   List<BeanResult<?>> interfaces = new ArrayList<BeanResult<?>>();
+   private List<BeanResult<?>> interfaces = new ArrayList<BeanResult<?>>();
 
-   Map<BeanResult<?>, List<FieldValueObject>> fieldValues = new HashMap<BeanResult<?>, List<FieldValueObject>>();
+   private List<GenericBeanResult> genericBeans = new ArrayList<GenericBeanResult>();
 
-   Map<Class<?>, List<FieldValueObject>> interfaceFieldValues = new HashMap<Class<?>, List<FieldValueObject>>();
+   private Map<BeanResult<?>, List<FieldValueObject>> fieldValues = new HashMap<BeanResult<?>, List<FieldValueObject>>();
 
+   private Map<Class<?>, List<FieldValueObject>> interfaceFieldValues = new HashMap<Class<?>, List<FieldValueObject>>();
+
+   public void addStereotype(Class<? extends Annotation> an, Annotation[] values)
+   {
+      stereotypes.put(an, values);
+   }
+
    public Map<Class<? extends Annotation>, Annotation[]> getStereotypes()
    {
       return stereotypes;
    }
 
+   public void addQualifier(Class<? extends Annotation> qualifier)
+   {
+      qualifiers.add(qualifier);
+   }
+
    public List<Class<? extends Annotation>> getQualifiers()
    {
       return qualifiers;
    }
 
+   public void addInterceptorBinding(Class<? extends Annotation> binding)
+   {
+      interceptorBindings.add(binding);
+   }
+
    public List<Class<? extends Annotation>> getInterceptorBindings()
    {
       return interceptorBindings;
    }
 
+   public void addBean(BeanResult<?> bean)
+   {
+      beans.add(bean);
+   }
+
    public List<BeanResult<?>> getBeans()
    {
       return beans;
@@ -69,6 +91,11 @@
       problems.add(p);
    }
 
+   public void addFieldValue(BeanResult<?> res, List<FieldValueObject> list)
+   {
+      fieldValues.put(res, list);
+   }
+
    public Map<BeanResult<?>, List<FieldValueObject>> getFieldValues()
    {
       return fieldValues;
@@ -84,14 +111,34 @@
       return veto;
    }
 
+   public void addInterface(BeanResult<?> bean)
+   {
+      interfaces.add(bean);
+   }
+
    public List<BeanResult<?>> getInterfaces()
    {
       return interfaces;
    }
 
+   public void addInterfaceFieldValues(Class<?> clazz, List<FieldValueObject> values)
+   {
+      interfaceFieldValues.put(clazz, values);
+   }
+
    public Map<Class<?>, List<FieldValueObject>> getInterfaceFieldValues()
    {
       return interfaceFieldValues;
    }
 
+   public void addGenericBean(GenericBeanResult result)
+   {
+      genericBeans.add(result);
+   }
+
+   public List<GenericBeanResult> getGenericBeans()
+   {
+      return genericBeans;
+   }
+
 }

Added: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/GenericBeanXmlItem.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/GenericBeanXmlItem.java	                        (rev 0)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/GenericBeanXmlItem.java	2010-04-13 09:33:27 UTC (rev 12448)
@@ -0,0 +1,65 @@
+/*
+ * Distributed under the LGPL License
+ * 
+ */
+package org.jboss.seam.xml.model;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.seam.xml.util.XmlConfigurationException;
+
+public class GenericBeanXmlItem extends AbstractXmlItem
+{
+
+   Class<?> javaClass;
+
+   public GenericBeanXmlItem(XmlItem parent, Map<String, String> attributes, String document, int lineno)
+   {
+      super(XmlItemType.GENERIC_BEAN, parent, null, null, attributes, document, lineno);
+      if (attributes.containsKey("class"))
+      {
+         javaClass = getClass(attributes.get("class"), document, lineno);
+      }
+      else
+      {
+         throw new XmlConfigurationException("<genericBean> element must have a class attribute", document, lineno);
+      }
+   }
+
+   public Set<XmlItemType> getAllowedItem()
+   {
+      return Collections.singleton(XmlItemType.CLASS);
+   }
+
+   public Class<?> getClass(String className, String document, int lineno)
+   {
+      try
+      {
+         if (Thread.currentThread().getContextClassLoader() != null)
+         {
+            return Thread.currentThread().getContextClassLoader().loadClass(className);
+         }
+      }
+      catch (ClassNotFoundException e)
+      {
+
+      }
+      try
+      {
+         return getClass().getClassLoader().loadClass(className);
+      }
+      catch (ClassNotFoundException e1)
+      {
+         throw new XmlConfigurationException("could not find class <genericBean>", document, lineno);
+      }
+   }
+
+   @Override
+   public Class<?> getJavaClass()
+   {
+      return javaClass;
+   }
+
+}

Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java	2010-04-13 09:31:41 UTC (rev 12447)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java	2010-04-13 09:33:27 UTC (rev 12448)
@@ -9,6 +9,7 @@
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -21,6 +22,7 @@
 import javax.interceptor.InterceptorBinding;
 
 import org.jboss.seam.xml.core.BeanResult;
+import org.jboss.seam.xml.core.GenericBeanResult;
 import org.jboss.seam.xml.core.XmlResult;
 import org.jboss.seam.xml.fieldset.FieldValueObject;
 import org.jboss.seam.xml.parser.SaxNode;
@@ -107,11 +109,11 @@
             BeanResult<?> tp = buildAnnotatedType((ClassXmlItem) rb);
             if (rb.getJavaClass().isInterface())
             {
-               ret.getInterfaces().add(tp);
+               ret.addInterface(tp);
             }
             else
             {
-               ret.getBeans().add(tp);
+               ret.addBean(tp);
             }
             if (tp.isOverride() || tp.isExtend())
             {
@@ -138,21 +140,21 @@
             {
                if (rb.getJavaClass().isInterface())
                {
-                  ret.getInterfaceFieldValues().put(tp.getType(), fields);
+                  ret.addInterfaceFieldValues(tp.getType(), fields);
                }
                else
                {
-                  ret.getFieldValues().put(tp, fields);
+                  ret.addFieldValue(tp, fields);
                }
             }
          }
          else if (type == ResultType.QUALIFIER)
          {
-            ret.getQualifiers().add((Class) rb.getJavaClass());
+            ret.addQualifier((Class) rb.getJavaClass());
          }
          else if (type == ResultType.INTERCEPTOR_BINDING)
          {
-            ret.getInterceptorBindings().add((Class) rb.getJavaClass());
+            ret.addInterceptorBinding((Class) rb.getJavaClass());
          }
          else if (type == ResultType.STEREOTYPE)
          {
@@ -166,6 +168,16 @@
             ret.addVeto(it.getJavaClass());
          }
       }
+      else if (rb.getType() == XmlItemType.GENERIC_BEAN)
+      {
+         GenericBeanXmlItem item = (GenericBeanXmlItem) rb;
+         Set<Class> classes = new HashSet<Class>();
+         for (ClassXmlItem c : rb.getChildrenOfType(ClassXmlItem.class))
+         {
+            classes.add(c.getJavaClass());
+         }
+         ret.addGenericBean(new GenericBeanResult(item.getJavaClass(), classes));
+      }
    }
 
    protected XmlItem resolveNode(SaxNode node, XmlItem parent)
@@ -429,7 +441,7 @@
          }
          count++;
       }
-      ret.getStereotypes().put((Class) rb.getJavaClass(), values);
+      ret.addStereotype((Class) rb.getJavaClass(), values);
 
    }
 

Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/XmlItemType.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/XmlItemType.java	2010-04-13 09:31:41 UTC (rev 12447)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/XmlItemType.java	2010-04-13 09:33:27 UTC (rev 12448)
@@ -6,5 +6,5 @@
 
 public enum XmlItemType
 {
-   CLASS, METHOD, FIELD, ANNOTATION, VALUE, VETO, ENTRY, KEY, DEPENDENCY, PARAMETERS, PARAMETER, ARRAY, OVERRIDE, SPECIALIZES, TYPE;
+   CLASS, METHOD, FIELD, ANNOTATION, VALUE, VETO, ENTRY, KEY, DEPENDENCY, PARAMETERS, PARAMETER, ARRAY, OVERRIDE, SPECIALIZES, TYPE, GENERIC_BEAN;
 }

Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/parser/namespace/RootNamespaceElementResolver.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/parser/namespace/RootNamespaceElementResolver.java	2010-04-13 09:31:41 UTC (rev 12447)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/parser/namespace/RootNamespaceElementResolver.java	2010-04-13 09:33:27 UTC (rev 12448)
@@ -7,6 +7,7 @@
 import org.jboss.seam.xml.model.ArrayXmlItem;
 import org.jboss.seam.xml.model.ClassXmlItem;
 import org.jboss.seam.xml.model.EntryXmlItem;
+import org.jboss.seam.xml.model.GenericBeanXmlItem;
 import org.jboss.seam.xml.model.KeyXmlItem;
 import org.jboss.seam.xml.model.OverrideXmlItem;
 import org.jboss.seam.xml.model.ParameterXmlItem;
@@ -73,7 +74,10 @@
       {
          return new TypeXmlItem(parent, node.getDocument(), node.getLineNo());
       }
-
+      else if (item.equals("genericBean"))
+      {
+         return new GenericBeanXmlItem(parent, node.getAttributes(), node.getDocument(), node.getLineNo());
+      }
       // now deal with primitive types
 
       Class<?> primType = null;



More information about the seam-commits mailing list