[seam-commits] Seam SVN: r12077 - 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
Thu Feb 25 23:17:10 EST 2010
Author: swd847
Date: 2010-02-25 23:17:09 -0500 (Thu, 25 Feb 2010)
New Revision: 12077
Added:
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/MethodValueArrayProducer.java
Modified:
modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/AnnotationXmlItem.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ArrayXmlItem.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ClassXmlItem.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ParameterXmlItem.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/XmlItemType.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/RootNamespaceElementResolver.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/MethodBean.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/MethodTarget.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/MethodTest.java
modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/method/method-beans.xml
Log:
added proper array parameter handling, including multi-dimensional arrays
Modified: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/AnnotationXmlItem.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/AnnotationXmlItem.java 2010-02-26 03:11:50 UTC (rev 12076)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/AnnotationXmlItem.java 2010-02-26 04:17:09 UTC (rev 12077)
@@ -4,23 +4,14 @@
*/
package org.jboss.seam.xml.model;
-import java.util.Collections;
+import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class AnnotationXmlItem extends AbstractXmlItem
{
+ HashSet<XmlItemType> allowed = new HashSet<XmlItemType>();
- /**
- * create a class note. If the class is an annotation in can have inner text
- * to represent the 'value' of the annotation, if can also have atrributes to
- * represent other properties
- *
- * @param parent
- * @param c
- * @param innerText
- * @param attributes
- */
public AnnotationXmlItem(XmlItem parent, Class<?> c, String innerText, Map<String, String> attributes, String document, int lineno)
{
super(XmlItemType.ANNOTATION, parent, c, innerText, attributes, document, lineno);
@@ -31,11 +22,12 @@
attributes.put("value", innerText);
}
}
+ allowed.add(XmlItemType.ANNOTATION);
}
public Set<XmlItemType> getAllowedItem()
{
- return Collections.emptySet();
+ return allowed;
}
}
Modified: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ArrayXmlItem.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ArrayXmlItem.java 2010-02-26 03:11:50 UTC (rev 12076)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ArrayXmlItem.java 2010-02-26 04:17:09 UTC (rev 12077)
@@ -4,144 +4,61 @@
*/
package org.jboss.seam.xml.model;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
+import java.lang.reflect.Array;
import java.util.List;
import java.util.Map;
-import java.util.Set;
-import org.jboss.seam.xml.fieldset.FieldValueObject;
import org.jboss.seam.xml.util.XmlConfigurationException;
-public class ArrayXmlItem implements XmlItem
+public class ArrayXmlItem extends ParameterXmlItem
{
- XmlItem child = null, parent;
+ Class javaClass = null;
- Class<?> javaClass;
+ int dimensions = 1;
- final String document;
-
- final int lineno;
-
- public ArrayXmlItem(XmlItem parent, String document, int lineno)
+ public ArrayXmlItem(XmlItem parent, Map<String, String> attributes, String document, int lineno)
{
- allowed.add(XmlItemType.CLASS);
- this.parent = parent;
- this.document = document;
- this.lineno = lineno;
- }
-
- public String getDocument()
- {
- return document;
- }
-
- public int getLineno()
- {
- return lineno;
- }
-
- Set<XmlItemType> allowed = new HashSet<XmlItemType>();
-
- public Set<XmlItemType> getAllowedItem()
- {
- return allowed;
- }
-
- public void addChild(XmlItem xmlItem)
- {
- if (child != null)
+ super(parent, null, document, lineno);
+ if (attributes.containsKey("dimensions"))
{
- throw new XmlConfigurationException("Array elements can only have one child", getDocument(), getLineno());
+ try
+ {
+ dimensions = Integer.parseInt(attributes.get("dimensions"));
+ }
+ catch (NumberFormatException e)
+ {
+ throw new XmlConfigurationException("dimensions attribute on <array> must be an integer", document, lineno);
+ }
}
- child = xmlItem;
}
- @SuppressWarnings("unchecked")
- public Map<String, String> getAttributes()
- {
- return Collections.EMPTY_MAP;
- }
-
- public List<XmlItem> getChildren()
- {
- return Collections.singletonList(child);
- }
-
- public Field getField()
- {
- return null;
- }
-
- public FieldValueObject getFieldValue()
- {
- return null;
- }
-
- public String getInnerText()
- {
- return null;
- }
-
- public Class getJavaClass()
- {
- return javaClass;
- }
-
- public Method getMethod()
- {
- return null;
- }
-
- public XmlItem getParent()
- {
- return parent;
- }
-
- public XmlItemType getType()
- {
- return XmlItemType.CLASS;
- }
-
public boolean resolveChildren()
{
- if (child == null)
+ List<ClassXmlItem> classXmlItems = getChildrenOfType(ClassXmlItem.class);
+ if (classXmlItems.isEmpty())
{
throw new XmlConfigurationException("<array> element must have a child specifying the array type", getDocument(), getLineno());
}
- Class<?> l = child.getJavaClass();
- try
+ else if (classXmlItems.size() != 1)
{
- javaClass = getClass().getClassLoader().loadClass("[L" + l.getName() + ";");
+ throw new XmlConfigurationException("<array> element must have a single child specifying the array type", getDocument(), getLineno());
}
- catch (ClassNotFoundException e)
+ int[] dims = new int[dimensions];
+ for (int i = 0; i < dimensions; ++i)
{
- try
- {
- javaClass = Thread.currentThread().getContextClassLoader().loadClass("[L" + l.getName() + ";");
- }
- catch (ClassNotFoundException e2)
- {
- throw new XmlConfigurationException("Cannot create array class from " + l.getName(), getDocument(), getLineno());
- }
+ dims[i] = 0;
}
+ Class<?> l = classXmlItems.get(0).getJavaClass();
+ javaClass = Array.newInstance(l, dims).getClass();
+
return true;
}
- public <T> List<T> getChildrenOfType(Class<T> type)
+
+ @Override
+ public Class<?> getJavaClass()
{
- List<T> ret = new ArrayList<T>();
- for(XmlItem i : getChildren())
- {
- if(type.isAssignableFrom(i.getClass()))
- {
- ret.add((T)i);
- }
- }
- return ret;
+ return javaClass;
}
-
+
}
Modified: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ClassXmlItem.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ClassXmlItem.java 2010-02-26 03:11:50 UTC (rev 12076)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ClassXmlItem.java 2010-02-26 04:17:09 UTC (rev 12077)
@@ -12,16 +12,6 @@
HashSet<XmlItemType> allowed = new HashSet<XmlItemType>();
- /**
- * create a class note. If the class is an annotation in can have inner text
- * to represent the 'value' of the annotation, if can also have atrributes to
- * represent other properties
- *
- * @param parent
- * @param c
- * @param innerText
- * @param attributes
- */
public ClassXmlItem(XmlItem parent, Class<?> c, String document, int lineno)
{
super(XmlItemType.CLASS, parent, c, null, null, document, lineno);
Modified: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java 2010-02-26 03:11:50 UTC (rev 12076)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java 2010-02-26 04:17:09 UTC (rev 12077)
@@ -30,7 +30,7 @@
import org.jboss.weld.extensions.util.annotated.NewAnnotatedTypeBuilder;
/**
- * Parser for xml configration
+ * Builds an XML result from sax nodes
*
* @author stuart
*
@@ -71,6 +71,7 @@
if (node.getNamespaceUri() != null)
{
XmlItem rb = resolveNode(node, null);
+ // validateXmlItem(rb);
addNodeToResult(ret, rb);
}
}
@@ -174,57 +175,53 @@
{
ResultType ret = null;
- for (XmlItem it : item.getChildren())
+ for (AnnotationXmlItem it : item.getChildrenOfType(AnnotationXmlItem.class))
{
- if (it.getType() == XmlItemType.ANNOTATION)
+ if (it.getJavaClass() == InterceptorBinding.class)
{
- if (it.getJavaClass() == InterceptorBinding.class)
+ if (ret != null)
{
- if (ret != null)
- {
- throw new XmlConfigurationException("Element cannot be both an INTERCEPTOR_BINDING and a " + ret.toString(), item.getDocument(), item.getLineno());
- }
- else
- {
- ret = ResultType.INTERCEPTOR_BINDING;
- }
+ throw new XmlConfigurationException("Element cannot be both an INTERCEPTOR_BINDING and a " + ret.toString(), item.getDocument(), item.getLineno());
}
- else if (it.getJavaClass() == Qualifier.class)
+ else
{
- if (ret != null)
- {
- throw new XmlConfigurationException("Element cannot be both an QUALIFIER and a " + ret.toString(), item.getDocument(), item.getLineno());
- }
- else
- {
- ret = ResultType.QUALIFIER;
- }
+ ret = ResultType.INTERCEPTOR_BINDING;
}
- else if (it.getJavaClass() == Stereotype.class)
+ }
+ else if (it.getJavaClass() == Qualifier.class)
+ {
+ if (ret != null)
{
- if (ret != null)
- {
- throw new XmlConfigurationException("Element cannot be both an STEREOTYPE and a " + ret.toString(), item.getDocument(), item.getLineno());
- }
- else
- {
- ret = ResultType.STEREOTYPE;
- }
+ throw new XmlConfigurationException("Element cannot be both an QUALIFIER and a " + ret.toString(), item.getDocument(), item.getLineno());
}
+ else
+ {
+ ret = ResultType.QUALIFIER;
+ }
}
- else if (it.getType() == XmlItemType.VETO)
+ else if (it.getJavaClass() == Stereotype.class)
{
if (ret != null)
{
- throw new XmlConfigurationException("Element cannot be both an VETO and a " + ret.toString(), item.getDocument(), item.getLineno());
+ throw new XmlConfigurationException("Element cannot be both an STEREOTYPE and a " + ret.toString(), item.getDocument(), item.getLineno());
}
else
{
- ret = ResultType.VETO;
+ ret = ResultType.STEREOTYPE;
}
}
-
}
+ for (VetoXmlItem it : item.getChildrenOfType(VetoXmlItem.class))
+ {
+ if (ret != null)
+ {
+ throw new XmlConfigurationException("Element cannot be both an VETO and a " + ret.toString(), item.getDocument(), item.getLineno());
+ }
+ else
+ {
+ ret = ResultType.VETO;
+ }
+ }
if (ret == null)
{
ret = ResultType.BEAN;
Modified: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ParameterXmlItem.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ParameterXmlItem.java 2010-02-26 03:11:50 UTC (rev 12076)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ParameterXmlItem.java 2010-02-26 04:17:09 UTC (rev 12077)
@@ -7,26 +7,20 @@
import java.util.HashSet;
import java.util.Set;
+/**
+ * represents a parameter of a constructor or method
+ *
+ * @author Stuart Douglas <stuart at baileyroberts.com.au>
+ *
+ */
public class ParameterXmlItem extends AbstractXmlItem
{
-
HashSet<XmlItemType> allowed = new HashSet<XmlItemType>();
- /**
- * create a class note. If the class is an annotation in can have inner text
- * to represent the 'value' of the annotation, if can also have atrributes to
- * represent other properties
- *
- * @param parent
- * @param c
- * @param innerText
- * @param attributes
- */
public ParameterXmlItem(XmlItem parent, Class<?> c, String document, int lineno)
{
super(XmlItemType.PARAMETER, parent, c, null, null, document, lineno);
allowed.add(XmlItemType.ANNOTATION);
-
}
public Set<XmlItemType> getAllowedItem()
Modified: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/XmlItemType.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/XmlItemType.java 2010-02-26 03:11:50 UTC (rev 12076)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/XmlItemType.java 2010-02-26 04:17:09 UTC (rev 12077)
@@ -6,5 +6,5 @@
public enum XmlItemType
{
- CLASS, METHOD, FIELD, ANNOTATION, VALUE, VETO, ENTRY, KEY, DEPENDENCY,PARAMETER;
+ CLASS, METHOD, FIELD, ANNOTATION, VALUE, VETO, ENTRY, KEY, DEPENDENCY, PARAMETER, ARRAY;
}
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 03:11:50 UTC (rev 12076)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/RootNamespaceElementResolver.java 2010-02-26 04:17:09 UTC (rev 12077)
@@ -49,13 +49,13 @@
}
else if (item.equals("array"))
{
- return new ArrayXmlItem(parent, node.getDocument(), node.getLineNo());
+ return new ArrayXmlItem(parent, node.getAttributes(), node.getDocument(), node.getLineNo());
}
else if (item.equals("veto"))
{
return new VetoXmlItem(parent, node.getDocument(), node.getLineNo());
}
-
+
return null;
}
Modified: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/MethodBean.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/MethodBean.java 2010-02-26 03:11:50 UTC (rev 12076)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/MethodBean.java 2010-02-26 04:17:09 UTC (rev 12077)
@@ -17,4 +17,9 @@
return bean.value + 1;
}
+ public long method(MethodValueBean[][] beans)
+ {
+ return beans.length;
+ }
+
}
Modified: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/MethodTarget.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/MethodTarget.java 2010-02-26 03:11:50 UTC (rev 12076)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/MethodTarget.java 2010-02-26 04:17:09 UTC (rev 12077)
@@ -8,4 +8,6 @@
{
public int value1, value2;
+
+ public long longValue;
}
Modified: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/MethodTest.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/MethodTest.java 2010-02-26 03:11:50 UTC (rev 12076)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/MethodTest.java 2010-02-26 04:17:09 UTC (rev 12077)
@@ -23,6 +23,7 @@
assert x != null;
assert x.value1 == 1;
assert x.value2 == 11;
+ assert x.longValue == 10;
}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/MethodValueArrayProducer.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/MethodValueArrayProducer.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/MethodValueArrayProducer.java 2010-02-26 04:17:09 UTC (rev 12077)
@@ -0,0 +1,13 @@
+package org.jboss.seam.xml.test.method;
+
+import javax.enterprise.inject.Produces;
+
+public class MethodValueArrayProducer
+{
+ @Produces
+ @Qualifier2
+ public MethodValueBean[][] createMethodValueBeans()
+ {
+ return new MethodValueBean[10][10];
+ }
+}
Modified: modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/method/method-beans.xml
===================================================================
--- modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/method/method-beans.xml 2010-02-26 03:11:50 UTC (rev 12076)
+++ modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/method/method-beans.xml 2010-02-26 04:17:09 UTC (rev 12077)
@@ -26,11 +26,22 @@
<test:Qualifier2/>
</test:MethodValueBean>
</test:method>
+
+ <test:method>
+ <Produces/>
+ <test:Qualifier1/>
+ <array dimensions="2">
+ <test:Qualifier2/>
+ <test:MethodValueBean/>
+ </array>
+ </test:method>
+
</test:MethodBean>
<test:MethodTarget>
<test:value1><Inject/></test:value1>
<test:value2><Inject/><test:Qualifier1/></test:value2>
+ <test:longValue><Inject/><test:Qualifier1/></test:longValue>
</test:MethodTarget>
<test:MethodValueBean>
More information about the seam-commits
mailing list