Integrated resource model related changes with eclipse plug-ins.
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ClientControllerPlugin / src / oic / simulator / clientcontroller / remoteresource / ResourceRepresentation.java
index ef8cef7..f2c3f18 100644 (file)
@@ -19,6 +19,7 @@ package oic.simulator.clientcontroller.remoteresource;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.oic.simulator.AttributeValue;
 import org.oic.simulator.InvalidArgsException;
 import org.oic.simulator.SimulatorResourceAttribute;
 import org.oic.simulator.SimulatorResourceModel;
@@ -28,10 +29,12 @@ public class ResourceRepresentation {
 
     public ResourceRepresentation(SimulatorResourceModel resourceModel) {
         if (resourceModel != null && resourceModel.size() > 0) {
-            for (Map.Entry<String, SimulatorResourceAttribute> entry : resourceModel
-                    .getAttributes().entrySet())
-                mAttributes.put(entry.getKey(), new AttributeElement(this,
-                        entry.getValue()));
+            for (Map.Entry<String, AttributeValue> entry : resourceModel.get()
+                    .entrySet())
+                mAttributes.put(entry.getKey(),
+                        new AttributeElement(this,
+                                new SimulatorResourceAttribute(entry.getKey(),
+                                        entry.getValue())));
         }
     }
 
@@ -41,18 +44,18 @@ public class ResourceRepresentation {
 
     public void update(SimulatorResourceModel resourceModel,
             boolean ramlUploaded) {
-        for (Map.Entry<String, SimulatorResourceAttribute> entry : resourceModel
-                .getAttributes().entrySet()) {
+        for (Map.Entry<String, AttributeValue> entry : resourceModel.get()
+                .entrySet()) {
             AttributeElement attributeElement = mAttributes.get(entry.getKey());
             if (attributeElement != null) {
-                if (ramlUploaded)
-                    attributeElement.updateForRAMLUpload(entry.getValue());
-                else
-                    attributeElement.update(entry.getValue());
-            } else // Display new attribute in UI
-            {
+                attributeElement.update(
+                        new SimulatorResourceAttribute(entry.getKey(), entry
+                                .getValue()), ramlUploaded);
+            } else {
+                // Display new attribute in UI
                 AttributeElement newAttribute = new AttributeElement(this,
-                        entry.getValue());
+                        new SimulatorResourceAttribute(entry.getKey(),
+                                entry.getValue()));
                 mAttributes.put(entry.getKey(), newAttribute);
             }
         }
@@ -67,8 +70,8 @@ public class ResourceRepresentation {
             AttributeElement attributeElement = mAttributes.get(entry.getKey());
             if (attributeElement != null) {
                 try {
-                    model.addAttribute(attributeElement
-                            .getSimulatorResourceAttribute());
+                    model.set(entry.getKey(), attributeElement
+                            .getSimulatorResourceAttribute().value());
                 } catch (InvalidArgsException e) {
                     e.printStackTrace();
                 }
@@ -86,8 +89,8 @@ public class ResourceRepresentation {
             AttributeElement attributeElement = mAttributes.get(entry.getKey());
             if (attributeElement != null && attributeElement.getPostState()) {
                 try {
-                    model.addAttribute(attributeElement
-                            .getSimulatorResourceAttribute());
+                    model.set(entry.getKey(), attributeElement
+                            .getSimulatorResourceAttribute().value());
                 } catch (InvalidArgsException e) {
                     e.printStackTrace();
                 }