Author: alessio.soldano(a)jboss.com
Date: 2013-10-14 10:58:56 -0400 (Mon, 14 Oct 2013)
New Revision: 594
Modified:
core/trunk/core/src/main/java/org/jboss/wise/tree/impl/ElementBuilderImpl.java
core/trunk/core/src/main/java/org/jboss/wise/tree/impl/ElementImpl.java
Log:
- [WISE-210] Properly deal with enums in tree view
- Improve exception handling in ElementImpl
Modified: core/trunk/core/src/main/java/org/jboss/wise/tree/impl/ElementBuilderImpl.java
===================================================================
---
core/trunk/core/src/main/java/org/jboss/wise/tree/impl/ElementBuilderImpl.java 2013-10-14
14:53:05 UTC (rev 593)
+++
core/trunk/core/src/main/java/org/jboss/wise/tree/impl/ElementBuilderImpl.java 2013-10-14
14:58:56 UTC (rev 594)
@@ -20,10 +20,12 @@
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -261,11 +263,25 @@
return "0";
} else if ("javax.xml.datatype.XMLGregorianCalendar".equals(cn)) {
return "1970-01-01T00:00:00.000Z";
+ } else if (cl.isEnum()) {
+ return getValidEnumValues(cl).iterator().next();
} else {
return "";
}
}
+ public static List<String> getValidEnumValues(Class<?> classType) {
+ List<String> list = new ArrayList<String>();
+ for (Object obj : classType.getEnumConstants()) {
+ try {
+ list.add((String) obj.getClass().getMethod("value").invoke(obj));
+ } catch (Exception e) {
+ throw new WiseRuntimeException("Could not get enum values for " + classType,
e);
+ }
+ }
+ return list;
+ }
+
protected String generateNewID() {
return IDGenerator.nextVal();
}
Modified: core/trunk/core/src/main/java/org/jboss/wise/tree/impl/ElementImpl.java
===================================================================
--- core/trunk/core/src/main/java/org/jboss/wise/tree/impl/ElementImpl.java 2013-10-14
14:53:05 UTC (rev 593)
+++ core/trunk/core/src/main/java/org/jboss/wise/tree/impl/ElementImpl.java 2013-10-14
14:58:56 UTC (rev 594)
@@ -382,6 +382,12 @@
}
if (cl.isPrimitive()) {
cl = JavaUtils.getWrapperType(cl);
+ } else if (cl.isEnum()) {
+ try {
+ return cl.getMethod("fromValue", String.class).invoke(null, value);
+ } catch (Exception e) {
+ throw new WiseRuntimeException("Could not get enum from value '" +
value + "'", e);
+ }
}
final String n = cl.getName();
if ("java.lang.String".equals(n)) {
@@ -479,6 +485,8 @@
}
}
return obj;
+ } catch (WiseRuntimeException wre) {
+ throw wre;
} catch (Exception e) {
throw new WiseRuntimeException("Error converting element to object", e);
}
Show replies by date