[seam-commits] Seam SVN: r12702 - in modules/xml/trunk/impl/src: main/java/org/jboss/seam/xml/util and 1 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Mon May 10 06:50:27 EDT 2010
Author: swd847
Date: 2010-05-10 06:50:26 -0400 (Mon, 10 May 2010)
New Revision: 12702
Added:
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/util/TypeReader.java
Modified:
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/CollectionFieldSet.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/MapFieldSet.java
modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/CollectionFieldValue.java
Log:
SEAMXML-4
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/CollectionFieldSet.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/CollectionFieldSet.java 2010-05-10 09:15:20 UTC (rev 12701)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/CollectionFieldSet.java 2010-05-10 10:50:26 UTC (rev 12702)
@@ -17,6 +17,7 @@
import java.util.TreeSet;
import org.jboss.seam.xml.model.XmlItem;
+import org.jboss.seam.xml.util.TypeReader;
import org.jboss.seam.xml.util.XmlObjectConverter;
/**
@@ -68,54 +69,45 @@
if (parameterizedType.getRawType() == Collection.class)
{
- elementType = (Class<?>) parameterizedType.getActualTypeArguments()[0];
collectionType = LinkedHashSet.class;
}
else if (parameterizedType.getRawType() == List.class)
{
- elementType = (Class<?>) parameterizedType.getActualTypeArguments()[0];
collectionType = ArrayList.class;
}
else if (parameterizedType.getRawType() == Set.class)
{
- elementType = (Class<?>) parameterizedType.getActualTypeArguments()[0];
collectionType = LinkedHashSet.class;
}
else if (parameterizedType.getRawType() == SortedSet.class)
{
- elementType = (Class<?>) parameterizedType.getActualTypeArguments()[0];
collectionType = TreeSet.class;
}
else if (parameterizedType.getRawType() == HashSet.class)
{
- elementType = (Class<?>) parameterizedType.getActualTypeArguments()[0];
collectionType = HashSet.class;
}
else if (parameterizedType.getRawType() == ArrayList.class)
{
- elementType = (Class<?>) parameterizedType.getActualTypeArguments()[0];
collectionType = ArrayList.class;
}
else if (parameterizedType.getRawType() == LinkedList.class)
{
- elementType = (Class<?>) parameterizedType.getActualTypeArguments()[0];
collectionType = LinkedList.class;
}
else if (parameterizedType.getRawType() == LinkedHashSet.class)
{
- elementType = (Class<?>) parameterizedType.getActualTypeArguments()[0];
collectionType = LinkedHashSet.class;
}
else if (parameterizedType.getRawType() == TreeSet.class)
{
- elementType = (Class<?>) parameterizedType.getActualTypeArguments()[0];
collectionType = TreeSet.class;
}
else
{
throw new RuntimeException("Could not determine element type for " + field.getDeclaringClass().getName() + "." + field.getName());
}
-
+ elementType = TypeReader.readClassFromType(parameterizedType.getActualTypeArguments()[0]);
}
else
{
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/MapFieldSet.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/MapFieldSet.java 2010-05-10 09:15:20 UTC (rev 12701)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/MapFieldSet.java 2010-05-10 10:50:26 UTC (rev 12702)
@@ -15,6 +15,7 @@
import java.util.TreeMap;
import org.jboss.seam.xml.model.EntryXmlItem;
+import org.jboss.seam.xml.util.TypeReader;
import org.jboss.seam.xml.util.XmlObjectConverter;
/**
@@ -66,20 +67,14 @@
if (parameterizedType.getRawType() == Map.class)
{
- keyType = (Class<?>) parameterizedType.getActualTypeArguments()[0];
- valueType = (Class<?>) parameterizedType.getActualTypeArguments()[1];
collectionType = LinkedHashMap.class;
}
else if (parameterizedType.getRawType() == LinkedHashMap.class)
{
- keyType = (Class<?>) parameterizedType.getActualTypeArguments()[0];
- valueType = (Class<?>) parameterizedType.getActualTypeArguments()[1];
collectionType = LinkedHashMap.class;
}
else if (parameterizedType.getRawType() == HashMap.class)
{
- keyType = (Class<?>) parameterizedType.getActualTypeArguments()[0];
- valueType = (Class<?>) parameterizedType.getActualTypeArguments()[1];
collectionType = HashMap.class;
}
else if (parameterizedType.getRawType() == SortedMap.class)
@@ -90,8 +85,6 @@
}
else if (parameterizedType.getRawType() == TreeMap.class)
{
- keyType = (Class<?>) parameterizedType.getActualTypeArguments()[0];
- valueType = (Class<?>) parameterizedType.getActualTypeArguments()[1];
collectionType = TreeMap.class;
}
else
@@ -99,6 +92,8 @@
throw new RuntimeException("Could not determine element type for map " + field.getDeclaringClass().getName() + "." + field.getName());
}
+ keyType = TypeReader.readClassFromType(parameterizedType.getActualTypeArguments()[0]);
+ valueType = TypeReader.readClassFromType(parameterizedType.getActualTypeArguments()[1]);
}
else
{
Added: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/util/TypeReader.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/util/TypeReader.java (rev 0)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/util/TypeReader.java 2010-05-10 10:50:26 UTC (rev 12702)
@@ -0,0 +1,24 @@
+package org.jboss.seam.xml.util;
+
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+
+public class TypeReader
+{
+ public static Class<?> readClassFromType(Type type)
+ {
+ if (type instanceof Class)
+ {
+ return (Class) type;
+ }
+ else if (type instanceof ParameterizedType)
+ {
+ ParameterizedType p = (ParameterizedType) type;
+ return TypeReader.readClassFromType(p.getRawType());
+ }
+ else
+ {
+ throw new RuntimeException("Cannot convert " + type + " into a java.lang.Class");
+ }
+ }
+}
Modified: modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/CollectionFieldValue.java
===================================================================
--- modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/CollectionFieldValue.java 2010-05-10 09:15:20 UTC (rev 12701)
+++ modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/CollectionFieldValue.java 2010-05-10 10:50:26 UTC (rev 12702)
@@ -12,5 +12,5 @@
{
public Set<Integer> iset;
public SortedSet<String> sset;
- public List<Class> clist;
+ public List<Class<?>> clist;
}
More information about the seam-commits
mailing list