Displaying and editing the complex value types for attributes.
[platform/upstream/iotivity.git] / service / simulator / java / sdk / src / org / oic / simulator / SimulatorResourceModel.java
index 04c2de5..c1e3b80 100644 (file)
@@ -180,8 +180,7 @@ public class SimulatorResourceModel {
      * @param attrName
      *            Name of the attribute.
      *
-     * @return Attribute value type information         {@AttributeValue.TypeInfo
-     * }.
+     * @return Attribute value type information {@AttributeValue.TypeInfo}.
      */
     public AttributeValue.TypeInfo getAttributeType(String attrName) {
         if (mValues.containsKey(attrName))
@@ -218,6 +217,32 @@ public class SimulatorResourceModel {
         return mValues.size();
     }
 
+    /**
+     * API to update the attribute values from given
+     * {@link SimulatorResourceModel}.
+     */
+    public void update(SimulatorResourceModel resourceModel) {
+        if (null == resourceModel || 0 == resourceModel.size())
+            return;
+
+        for (Map.Entry<String, SimulatorResourceAttribute> entry : resourceModel
+                .getAttributes().entrySet()) {
+            SimulatorResourceAttribute newAttribute = entry.getValue();
+            SimulatorResourceAttribute attribute = getAttribute(entry.getKey());
+            if (null != newAttribute && null != attribute) {
+                if (null != attribute.property()) {
+                    AttributeValueValidation validation = new AttributeValueValidation(
+                            attribute.property());
+                    if (!validation.validate(newAttribute.value())) {
+                        mValues.put(entry.getKey(), newAttribute.value());
+                    }
+                } else {
+                    mValues.put(entry.getKey(), newAttribute.value());
+                }
+            }
+        }
+    }
+
     // Methods used in native code
     private SimulatorResourceModel(Map<String, AttributeValue> values,
             Map<String, AttributeProperty> properties) {