You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fm...@apache.org on 2012/04/26 16:22:22 UTC
svn commit: r1330866 -
/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/JSONConverter.java
Author: fmui
Date: Thu Apr 26 14:22:22 2012
New Revision: 1330866
URL: http://svn.apache.org/viewvc?rev=1330866&view=rev
Log:
Browser Binding: fixed bug with int enum
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/JSONConverter.java
Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/JSONConverter.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/JSONConverter.java?rev=1330866&r1=1330865&r2=1330866&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/JSONConverter.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/JSONConverter.java Thu Apr 26 14:22:22 2012
@@ -579,7 +579,7 @@ public class JSONConverter {
result = new PropertyDecimalDefinitionImpl();
((PropertyDecimalDefinitionImpl) result).setMinValue(getDecimal(json, JSON_PROPERTY_TYPE_MIN_VALUE));
((PropertyDecimalDefinitionImpl) result).setMaxValue(getDecimal(json, JSON_PROPERTY_TYPE_MAX_VALUE));
- ((PropertyDecimalDefinitionImpl) result).setPrecision(getEnum(json, JSON_PROPERTY_TYPE_PRECISION,
+ ((PropertyDecimalDefinitionImpl) result).setPrecision(getIntEnum(json, JSON_PROPERTY_TYPE_PRECISION,
DecimalPrecision.class));
((PropertyDecimalDefinitionImpl) result).setChoices(convertChoicesDecimal(json
.get(JSON_PROPERTY_TYPE_CHOICE)));
@@ -2402,4 +2402,23 @@ public class JSONConverter {
}
}
}
+
+ @SuppressWarnings("unchecked")
+ public static <T extends Enum<T>> T getIntEnum(Map<String, Object> json, String key, Class<T> clazz) {
+ BigInteger value = getInteger(json, key);
+ if (value == null) {
+ return null;
+ }
+
+ try {
+ Method m = clazz.getMethod("fromValue", BigInteger.class);
+ return (T) m.invoke(null, value);
+ } catch (Exception e) {
+ if (e instanceof IllegalArgumentException) {
+ return null;
+ } else {
+ throw new CmisRuntimeException("Could not parse enum value!", e);
+ }
+ }
+ }
}