[seam-commits] Seam SVN: r12078 - in modules/xml/trunk: src/main/java/org/jboss/seam/xml/parser/namespace and 2 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Fri Feb 26 00:01:06 EST 2010


Author: swd847
Date: 2010-02-26 00:01:05 -0500 (Fri, 26 Feb 2010)
New Revision: 12078

Added:
   modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/PrimitiveBean.java
   modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/PrimitiveMethodTest.java
   modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/PrimitiveValueProducer.java
   modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/method/primitive-method-beans.xml
Modified:
   modules/xml/trunk/docs/en-US/xml-general.xml
   modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/RootNamespaceElementResolver.java
Log:
added handling of primitive types in method resolution



Modified: modules/xml/trunk/docs/en-US/xml-general.xml
===================================================================
--- modules/xml/trunk/docs/en-US/xml-general.xml	2010-02-26 04:17:09 UTC (rev 12077)
+++ modules/xml/trunk/docs/en-US/xml-general.xml	2010-02-26 05:01:05 UTC (rev 12078)
@@ -126,10 +126,18 @@
             <listitem><para><literal>value</literal></para></listitem>
             <listitem><para><literal>key</literal></para></listitem>
             <listitem><para><literal>entry</literal></para></listitem>
-            <listitem><para><literal>array</literal></para></listitem>
             <listitem><para><literal>e</literal> (alias for entry)</para></listitem>
             <listitem><para><literal>v</literal> (alias for value)</para></listitem>
             <listitem><para><literal>k</literal> (alias for key)</para></listitem>
+            <listitem><para><literal>array</literal></para></listitem>
+            <listitem><para><literal>int</literal></para></listitem>
+            <listitem><para><literal>short</literal></para></listitem>
+            <listitem><para><literal>long</literal></para></listitem>
+            <listitem><para><literal>byte</literal></para></listitem>
+            <listitem><para><literal>char</literal></para></listitem>
+            <listitem><para><literal>double</literal></para></listitem>
+            <listitem><para><literal>float</literal></para></listitem>
+            <listitem><para><literal>boolean</literal></para></listitem>
          </itemizedlist>
          
          <para>as well as classes from the following packages:</para>    
@@ -236,6 +244,14 @@
                 <test:Qualifier2/>
             </test:MethodValueBean>
         </test:method>
+         <test:method>
+            <Produces/>
+            <test:Qualifier1/>
+            <array dimensions="2">
+                <test:Qualifier2/>
+                <test:MethodValueBean/>
+            </array>
+        </test:method>
     </test:MethodBean>
 </Beans>
 
@@ -257,10 +273,11 @@
             ]]>
         </programlisting>
 
-        <para>In this instance <literal>MethodBean</literal> has two methods, both of them rather imaginatively named <literal>method</literal>. 
+        <para>In this instance <literal>MethodBean</literal> has three methods, all of them rather imaginatively named <literal>method</literal>. 
         The first <literal>&lt;test:method&gt;</literal> entry in the XML file configures the method that takes no arguments. 
         The <literal>&lt;Produces&gt;</literal> element makes it into a producer method. The next entry in the file configures 
-        the method that takes a <literal>MethodValueBean</literal> as a parameter.When configuring methods non-annotation classes are 
+        the method that takes a <literal>MethodValueBean</literal> as a parameter. The final entry configures a method that takes a two
+        dimensional array of<literal>MethodValueBean</literal>'s as a parameter.  When configuring methods non-annotation classes are 
         considered to represent method paramters. If these parameters have annotation children they are taken to be annotations 
         on the parameter.</para> 
         

Modified: modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/RootNamespaceElementResolver.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/RootNamespaceElementResolver.java	2010-02-26 04:17:09 UTC (rev 12077)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/RootNamespaceElementResolver.java	2010-02-26 05:01:05 UTC (rev 12078)
@@ -5,11 +5,14 @@
 package org.jboss.seam.xml.parser.namespace;
 
 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.KeyXmlItem;
+import org.jboss.seam.xml.model.ParameterXmlItem;
 import org.jboss.seam.xml.model.ValueXmlItem;
 import org.jboss.seam.xml.model.VetoXmlItem;
 import org.jboss.seam.xml.model.XmlItem;
+import org.jboss.seam.xml.model.XmlItemType;
 import org.jboss.seam.xml.parser.SaxNode;
 
 public class RootNamespaceElementResolver implements NamespaceElementResolver
@@ -55,7 +58,53 @@
       {
          return new VetoXmlItem(parent, node.getDocument(), node.getLineNo());
       }
+      // now deal with primitive types
 
+      Class primType = null;
+      if (item.equals("int"))
+      {
+         primType = int.class;
+      }
+      else if (item.equals("short"))
+      {
+         primType = short.class;
+      }
+      else if (item.equals("long"))
+      {
+         primType = long.class;
+      }
+      else if (item.equals("byte"))
+      {
+         primType = byte.class;
+      }
+      else if (item.equals("char"))
+      {
+         primType = char.class;
+      }
+      else if (item.equals("double"))
+      {
+         primType = double.class;
+      }
+      else if (item.equals("float"))
+      {
+         primType = float.class;
+      }
+      else if (item.equals("boolean"))
+      {
+         primType = boolean.class;
+      }
+      if (primType != null)
+      {
+         if (parent != null && (parent.getType() == XmlItemType.METHOD || parent.getType() == XmlItemType.CLASS))
+         {
+            return new ParameterXmlItem(parent, primType, node.getDocument(), node.getLineNo());
+         }
+         else
+         {
+            return new ClassXmlItem(parent, primType, node.getDocument(), node.getLineNo());
+         }
+      }
+
       return null;
    }
 

Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/PrimitiveBean.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/PrimitiveBean.java	                        (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/PrimitiveBean.java	2010-02-26 05:01:05 UTC (rev 12078)
@@ -0,0 +1,18 @@
+package org.jboss.seam.xml.test.method;
+
+public class PrimitiveBean
+{
+   public int add(int val)
+   {
+      return val + 1;
+   }
+
+   public int[] add(int[] val)
+   {
+      for (int i = 0; i < val.length; ++i)
+      {
+         val[i] = val[i] + 1;
+      }
+      return val;
+   }
+}

Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/PrimitiveMethodTest.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/PrimitiveMethodTest.java	                        (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/PrimitiveMethodTest.java	2010-02-26 05:01:05 UTC (rev 12078)
@@ -0,0 +1,42 @@
+/*
+ * Distributed under the LGPL License
+ * 
+ */
+package org.jboss.seam.xml.test.method;
+
+import javax.enterprise.util.AnnotationLiteral;
+
+import org.jboss.seam.xml.test.AbstractXMLTest;
+import org.testng.annotations.Test;
+
+public class PrimitiveMethodTest extends AbstractXMLTest
+{
+
+   @Override
+   protected String getXmlFileName()
+   {
+      return "primitive-method-beans.xml";
+   }
+
+   @Test
+   public void methodTest()
+   {
+      int x = getReference(int.class, new Qual1Lit());
+      assert x == 1;
+      int[] y = getReference(int[].class, new Qual2Lit());
+      for (int i = 0; i < y.length; ++i)
+      {
+         assert y[i] == i + 2;
+      }
+
+   }
+
+   class Qual1Lit extends AnnotationLiteral<Qualifier1>
+   {
+   };
+
+   class Qual2Lit extends AnnotationLiteral<Qualifier2>
+   {
+   };
+
+}

Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/PrimitiveValueProducer.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/PrimitiveValueProducer.java	                        (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/PrimitiveValueProducer.java	2010-02-26 05:01:05 UTC (rev 12078)
@@ -0,0 +1,9 @@
+package org.jboss.seam.xml.test.method;
+
+public class PrimitiveValueProducer
+{
+   public int value = 0;
+
+   public int[] value2 = { 1, 2, 3 };
+
+}

Added: modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/method/primitive-method-beans.xml
===================================================================
--- modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/method/primitive-method-beans.xml	                        (rev 0)
+++ modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/method/primitive-method-beans.xml	2010-02-26 05:01:05 UTC (rev 12078)
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Beans xmlns="urn:seam:core"
+          xmlns:test="urn:java:org.jboss.seam.xml.test.method">
+   
+
+   <test:Qualifier1>
+    	<Qualifier/>
+   </test:Qualifier1>
+   
+    <test:Qualifier2>
+        <Qualifier/>
+   </test:Qualifier2>
+   
+    <test:PrimitiveBean>
+        <test:add>
+            <Produces/>
+            <test:Qualifier1/>
+            <int/>
+        </test:add>
+        <test:add>
+            <Produces/>
+                <test:Qualifier2/>
+            <array>
+                <int/>
+            </array>
+        </test:add>
+    </test:PrimitiveBean>
+    
+    <test:PrimitiveValueProducer>
+        <test:value>
+            <Produces/>
+        </test:value>
+        
+        <test:value2>
+            <Produces/>
+        </test:value2>
+    </test:PrimitiveValueProducer>
+ 
+</Beans>
\ No newline at end of file



More information about the seam-commits mailing list