X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=service%2Fsimulator%2Fjava%2Feclipse-plugin%2FClientControllerPlugin%2Fsrc%2Foic%2Fsimulator%2Fclientcontroller%2Futils%2FUtility.java;h=9c13390344ff9c72921b8bde4ddad15c29bcffdf;hb=b76f9709482b03334b468ab47a295761b3fd6a78;hp=254f1f876c44070446e1f47fc032fb23a44a5b09;hpb=d0686ee241a3102399a7135dbe3eb2930219aab9;p=platform%2Fupstream%2Fiotivity.git diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/Utility.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/Utility.java index 254f1f8..9c13390 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/Utility.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/Utility.java @@ -22,7 +22,10 @@ import java.util.Iterator; import java.util.List; import java.util.Set; +import org.oic.simulator.AttributeValue; import org.oic.simulator.SimulatorException; +import org.oic.simulator.AttributeValue.TypeInfo; +import org.oic.simulator.AttributeValue.ValueType; /** * This class has common utility methods. @@ -93,4 +96,69 @@ public class Utility { } return detail; } + + // This method only works for attributes whose values are of type int, + // double, bool, string and 1-D array of primitive types + public static String getAttributeValueAsString(AttributeValue val) { + if (null == val) { + return null; + } + Object value = val.get(); + if (null == value) { + return null; + } + TypeInfo type = val.typeInfo(); + if (type.mType == ValueType.RESOURCEMODEL + || (type.mType == ValueType.ARRAY && type.mBaseType == ValueType.RESOURCEMODEL) + || (type.mType == ValueType.ARRAY && type.mDepth > 1)) { + return null; + } + if (type.mType == ValueType.ARRAY) { + if (type.mBaseType == ValueType.INTEGER) { + Integer[] values = (Integer[]) value; + if (null == values || values.length < 1) { + return null; + } + List list = new ArrayList(); + for (Integer i : values) { + list.add(i); + } + return list.toString(); + } else if (type.mBaseType == ValueType.DOUBLE) { + Double[] values = (Double[]) value; + if (null == values || values.length < 1) { + return null; + } + List list = new ArrayList(); + for (Double i : values) { + list.add(i); + } + return list.toString(); + } else if (type.mBaseType == ValueType.BOOLEAN) { + Boolean[] values = (Boolean[]) value; + if (null == values || values.length < 1) { + return null; + } + List list = new ArrayList(); + for (Boolean i : values) { + list.add(i); + } + return list.toString(); + } else if (type.mBaseType == ValueType.STRING) { + String[] values = (String[]) value; + if (null == values || values.length < 1) { + return null; + } + List list = new ArrayList(); + for (String i : values) { + list.add(i); + } + return list.toString(); + } else { + return null; + } + } else { + return String.valueOf(value); + } + } } \ No newline at end of file