Displaying and editing the complex value types for attributes.
authorG S Senthil Kumar <senthil.gs@samsung.com>
Wed, 18 Nov 2015 19:14:46 +0000 (00:44 +0530)
committerMadan Lanka <lanka.madan@samsung.com>
Thu, 19 Nov 2015 01:59:05 +0000 (01:59 +0000)
1. Tested model and array of model type attribute values.
2. Inclues bug fixing for single resource creation without RAML.

Change-Id: I3f0791dde17e4e0d7f6c2165eb59443465f4163d
Signed-off-by: G S Senthil Kumar <senthil.gs@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/4267
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: RadhaBhavani <radha.p@samsung.com>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
37 files changed:
service/simulator/examples/client/simulator_client.cpp
service/simulator/inc/simulator_manager.h
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/manager/ResourceManager.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/AttributeElement.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/PutPostAttributeModel.java [deleted file]
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/RemoteResource.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/RemoteResourceAttribute.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/ResourceRepresentation.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/AttributeValueStringConverter.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/Utility.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/AttributeEditingSupport.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/AttributeView.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/PostRequestDialog.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/PutRequestDialog.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/AttributeElement.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/AutomationSettingHelper.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/DataChangeListener.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/Resource.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/ResourceRepresentation.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/AttributeValueStringConverter.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Utility.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeEditingSupport.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeView.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CreateResourceWizard.java
service/simulator/java/jni/simulator_manager_jni.cpp
service/simulator/java/jni/simulator_resource_model_jni.cpp
service/simulator/java/sdk/src/org/oic/simulator/AttributeProperty.java
service/simulator/java/sdk/src/org/oic/simulator/AttributeValueValidation.java
service/simulator/java/sdk/src/org/oic/simulator/AttributeValueVisitor.java
service/simulator/java/sdk/src/org/oic/simulator/SimulatorManager.java
service/simulator/java/sdk/src/org/oic/simulator/SimulatorResourceAttribute.java
service/simulator/java/sdk/src/org/oic/simulator/SimulatorResourceModel.java
service/simulator/src/server/simulator_collection_resource_impl.cpp
service/simulator/src/simulator_manager.cpp
service/simulator/unittests/SimulatorTest/src/org/oic/simulator/test/AttributeValueValidationTest.java
service/simulator/unittests/SimulatorTest/src/org/oic/simulator/test/SimulatorManagerTest.java

index db7fca2..ea039cb 100644 (file)
@@ -71,7 +71,7 @@ class ClientController
                 int choice = -1;
                 std::cout << "Enter your choice: ";
                 std::cin >> choice;
-                if (choice < 0 || choice > 12)
+                if (choice < 0 || choice > 14)
                 {
                     std::cout << "Invaild choice !" << std::endl; continue;
                 }
@@ -89,7 +89,9 @@ class ClientController
                     case 9: sendAllPUTRequests(); break;
                     case 10: sendAllPOSTRequests(); break;
                     case 11: configure(); break;
-                    case 12: printMenu(); break;
+                    case 12: getDeviceInfo(); break;
+                    case 13: getPlatformInfo(); break;
+                    case 14: printMenu(); break;
                     case 0: cont = false;
                 }
             }
@@ -110,7 +112,9 @@ class ClientController
             std::cout << "9. Send All PUT requests" << std::endl;
             std::cout << "10. Send All POST requests" << std::endl;
             std::cout << "11. Configure (using RAML file)" << std::endl;
-            std::cout << "12: Help" << std::endl;
+            std::cout << "12. Get Device Information" << std::endl;
+            std::cout << "13. Get Platform Information" << std::endl;
+            std::cout << "14: Help" << std::endl;
             std::cout << "0. Exit" << std::endl;
             std::cout << "###################################################" << std::endl;
         }
@@ -539,6 +543,77 @@ class ClientController
             }
         }
 
+        void getDeviceInfo()
+        {
+            SimulatorRemoteResourceSP resource = selectResource();
+            if (!resource)
+                return;
+
+            try
+            {
+                SimulatorManager::getInstance()->getDeviceInfo(resource->getHost(), std::bind([](DeviceInfo & deviceInfo)
+                {
+                    std::cout << "###Device Information received...." << std::endl;
+                    std::ostringstream out;
+                    out << "Device name: " << deviceInfo.getName() << std::endl;
+                    out << "Device ID: " << deviceInfo.getID() << std::endl;
+                    out << "Device Spec version: " << deviceInfo.getSpecVersion() << std::endl;
+                    out << "Device dat model version: " << deviceInfo.getDataModelVersion() << std::endl;
+
+                    std::cout << out.str() << std::endl;
+                }, std::placeholders::_1));
+            }
+            catch (InvalidArgsException &e)
+            {
+                std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: " << e.what() << "]"
+                          << std::endl;
+            }
+            catch (SimulatorException &e)
+            {
+                std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " << e.what() << "]" <<
+                          std::endl;
+            }
+        }
+
+        void getPlatformInfo()
+        {
+            SimulatorRemoteResourceSP resource = selectResource();
+            if (!resource)
+                return;
+
+            try
+            {
+                SimulatorManager::getInstance()->getPlatformInfo(resource->getHost(), std::bind([](PlatformInfo & platformInfo)
+                {
+                    std::cout << "###Platform Information received...." << std::endl;
+                    std::ostringstream out;
+                    out << "Platform ID: " << platformInfo.getPlatformID() << std::endl;
+                    out << "Platform version: " << platformInfo.getPlatformVersion() << std::endl;
+                    out << "Manufacturer name: " << platformInfo.getManufacturerName() << std::endl;
+                    out << "Manufacturer url: " << platformInfo.getManufacturerUrl() << std::endl;
+                    out << "Modle number: " << platformInfo.getModelNumber() << std::endl;
+                    out << "Date of manufacture: " << platformInfo.getDateOfManfacture() << std::endl;
+                    out << "Operatio system version: " << platformInfo.getOSVersion() << std::endl;
+                    out << "Hardware version: " << platformInfo.getHardwareVersion() << std::endl;
+                    out << "Firmware version: " << platformInfo.getFirmwareVersion() << std::endl;
+                    out << "Support url: " << platformInfo.getSupportUrl() << std::endl;
+                    out << "System time: " << platformInfo.getSystemTime() << std::endl;
+
+                    std::cout << out.str() << std::endl;
+                }, std::placeholders::_1));
+            }
+            catch (InvalidArgsException &e)
+            {
+                std::cout << "InvalidArgsException occured [code : " << e.code()
+                        << " Detail: " << e.what() << "]" << std::endl;
+            }
+            catch (SimulatorException &e)
+            {
+                std::cout << "SimulatorException occured [code : " << e.code()
+                        << " Detail: " << e.what() << "]" << std::endl;
+            }
+        }
+
     private:
         std::recursive_mutex m_mutex;
         std::map<std::string, SimulatorRemoteResourceSP> m_resList;
@@ -548,10 +623,8 @@ void printMainMenu()
 {
     std::cout << "############### MAIN MENU###############" << std::endl;
     std::cout << "1. Client Controller Test" << std::endl;
-    std::cout << "2. Get device information" << std::endl;
-    std::cout << "3. Get platform information" << std::endl;
-    std::cout << "4. Set Logger" << std::endl;
-    std::cout << "5. Help" << std::endl;
+    std::cout << "2. Set Logger" << std::endl;
+    std::cout << "3. Help" << std::endl;
     std::cout << "0. Exit" << std::endl;
     std::cout << "######################################" << std::endl;
 }
@@ -615,74 +688,9 @@ int main(void)
                 std::cout << "Welcome back to main menu !" << std::endl;
                 break;
 
-            case 2:
-                {
-                    try
-                    {
-                        SimulatorManager::getInstance()->getDeviceInfo(std::bind([](DeviceInfo & deviceInfo)
-                        {
-                            std::cout << "###Device Information received...." << std::endl;
-                            std::ostringstream out;
-                            out << "Device name: " << deviceInfo.getName() << std::endl;
-                            out << "Device ID: " << deviceInfo.getID() << std::endl;
-                            out << "Device Spec version: " << deviceInfo.getSpecVersion() << std::endl;
-                            out << "Device dat model version: " << deviceInfo.getDataModelVersion() << std::endl;
-
-                            std::cout << out.str() << std::endl;
-                        }, std::placeholders::_1));
-                    }
-                    catch (InvalidArgsException &e)
-                    {
-                        std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: " << e.what() << "]"
-                                  << std::endl;
-                    }
-                    catch (SimulatorException &e)
-                    {
-                        std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " << e.what() << "]" <<
-                                  std::endl;
-                    }
-                }
-                break;
-
-            case 3:
-                {
-                    try
-                    {
-                        SimulatorManager::getInstance()->getPlatformInfo(std::bind([](PlatformInfo & platformInfo)
-                        {
-                            std::cout << "###Platform Information received...." << std::endl;
-                            std::ostringstream out;
-                            out << "Platform ID: " << platformInfo.getPlatformID() << std::endl;
-                            out << "Platform version: " << platformInfo.getPlatformVersion() << std::endl;
-                            out << "Manufacturer name: " << platformInfo.getManufacturerName() << std::endl;
-                            out << "Manufacturer url: " << platformInfo.getManufacturerUrl() << std::endl;
-                            out << "Modle number: " << platformInfo.getModelNumber() << std::endl;
-                            out << "Date of manufacture: " << platformInfo.getDateOfManfacture() << std::endl;
-                            out << "Operatio system version: " << platformInfo.getOSVersion() << std::endl;
-                            out << "Hardware version: " << platformInfo.getHardwareVersion() << std::endl;
-                            out << "Firmware version: " << platformInfo.getFirmwareVersion() << std::endl;
-                            out << "Support url: " << platformInfo.getSupportUrl() << std::endl;
-                            out << "System time: " << platformInfo.getSystemTime() << std::endl;
-
-                            std::cout << out.str() << std::endl;
-                        }, std::placeholders::_1));
-                    }
-                    catch (InvalidArgsException &e)
-                    {
-                        std::cout << "InvalidArgsException occured [code : " << e.code()
-                                << " Detail: " << e.what() << "]" << std::endl;
-                    }
-                    catch (SimulatorException &e)
-                    {
-                        std::cout << "SimulatorException occured [code : " << e.code()
-                                << " Detail: " << e.what() << "]" << std::endl;
-                    }
-                }
-                break;
-
-            case 4: setLogger(); break;
+            case 2: setLogger(); break;
 
-            case 5: printMainMenu(); break;
+            case 3: printMainMenu(); break;
 
             case 0: cont = false;
         }
index 5b3d76e..6ba4572 100644 (file)
@@ -124,7 +124,7 @@ class SimulatorManager
          *
          * NOTE: API throws @InvalidArgsException and @SimulatorException on error.
          */
-        void getDeviceInfo(DeviceInfoCallback callback);
+        void getDeviceInfo(const std::string &host, DeviceInfoCallback callback);
 
         /**
          * API for registering device information with stack.
@@ -145,7 +145,7 @@ class SimulatorManager
          *
          * NOTE: API throws @InvalidArgsException and @SimulatorException on error.
          */
-        void getPlatformInfo(PlatformInfoCallback callback);
+        void getPlatformInfo(const std::string &host, PlatformInfoCallback callback);
 
         /**
          * API for registering platform information with stack.
index bcadd4a..3de0d3e 100644 (file)
@@ -39,10 +39,7 @@ import oic.simulator.clientcontroller.listener.IPutUIListener;
 import oic.simulator.clientcontroller.listener.IResourceSelectionChangedUIListener;
 import oic.simulator.clientcontroller.listener.IVerificationUIListener;
 import oic.simulator.clientcontroller.remoteresource.MetaProperty;
-import oic.simulator.clientcontroller.remoteresource.PutPostAttributeModel;
 import oic.simulator.clientcontroller.remoteresource.RemoteResource;
-import oic.simulator.clientcontroller.remoteresource.RemoteResourceAttribute;
-import oic.simulator.clientcontroller.utils.AttributeValueBuilder;
 import oic.simulator.clientcontroller.utils.Constants;
 import oic.simulator.clientcontroller.utils.Utility;
 
@@ -215,9 +212,12 @@ public class ResourceManager {
 
                         // Get the device and platform information
                         try {
-                            SimulatorManager.findDevices(deviceListener);
-                            SimulatorManager
-                                    .getPlatformInformation(platformListener);
+                            SimulatorManager.findDevices(resource
+                                    .getRemoteResourceRef().getHost(),
+                                    deviceListener);
+                            SimulatorManager.getPlatformInformation(resource
+                                    .getRemoteResourceRef().getHost(),
+                                    platformListener);
                         } catch (SimulatorException e) {
                             Activator
                                     .getDefault()
@@ -473,57 +473,18 @@ public class ResourceManager {
             return null;
         }
 
-        resource.setResourceModelRef(resourceModelN);
-        Map<String, RemoteResourceAttribute> attributeMap = fetchResourceAttributesFromModel(resourceModelN);
-        if (resource.isConfigUploaded()) {
-            updateResourceAttributesFromResponse(resource, attributeMap);
+        // if(!resource.isConfigUploaded() || null ==
+        // resource.getResourceModelRef())
+        SimulatorResourceModel resourceModel = resource.getResourceModelRef();
+        if (null == resourceModel) {
+            resource.setResourceModelRef(resourceModelN);
         } else {
-            resource.setResourceAttributesMap(attributeMap);
+            resourceModel.update(resourceModelN);
         }
-        // TODO: Printing the values for debugging
-        if (null != attributeMap) {
-            RemoteResourceAttribute.printAttributes(attributeMap);
-        }
-        return resource;
-    }
 
-    private void updateResourceAttributesFromResponse(RemoteResource res,
-            Map<String, RemoteResourceAttribute> newAttributeMap) {
-        if (null == res || null == newAttributeMap) {
-            return;
-        }
-        Map<String, RemoteResourceAttribute> oldAttributeMap = res
-                .getResourceAttributesMap();
-        if (null == oldAttributeMap) {
-            return;
-        }
-        Iterator<String> itr = oldAttributeMap.keySet().iterator();
-        String attName;
-        RemoteResourceAttribute newAtt;
-        RemoteResourceAttribute oldAtt;
-        while (itr.hasNext()) {
-            attName = itr.next();
-            newAtt = newAttributeMap.get(attName);
-            if (null == newAtt) {
-                // Attribute does not exist in the received model. Hence
-                // removing it from local model.
-                itr.remove();
-            } else {
-                oldAtt = oldAttributeMap.get(attName);
-                if (null != oldAtt) {
-                    oldAtt.setAttributeValue(newAtt.getAttributeValue());
-                } else {
-                    itr.remove();
-                }
-                newAttributeMap.remove(attName);
-            }
-        }
-        // Adding new attributes in the received model.
-        itr = newAttributeMap.keySet().iterator();
-        while (itr.hasNext()) {
-            attName = itr.next();
-            oldAttributeMap.put(attName, newAttributeMap.get(attName));
-        }
+        resource.setResourceRepresentation(resourceModelN, false);
+
+        return resource;
     }
 
     public synchronized DeviceInfo getDeviceInfo() {
@@ -729,7 +690,8 @@ public class ResourceManager {
 
     public void addObservedResourceURI(String resourceURI) {
         synchronized (observedResourceURIList) {
-            observedResourceURIList.add(resourceURI);
+            if (!observedResourceURIList.contains(resourceURI))
+                observedResourceURIList.add(resourceURI);
         }
     }
 
@@ -802,75 +764,6 @@ public class ResourceManager {
         return resource;
     }
 
-    private Map<String, RemoteResourceAttribute> fetchResourceAttributesFromModel(
-            SimulatorResourceModel resourceModelN) {
-        Map<String, RemoteResourceAttribute> resourceAttributeMap = null;
-        if (null != resourceModelN) {
-            Map<String, SimulatorResourceAttribute> attributeMapN;
-            attributeMapN = resourceModelN.getAttributes();
-            if (null != attributeMapN) {
-                resourceAttributeMap = new HashMap<String, RemoteResourceAttribute>();
-
-                Set<String> attNameSet = attributeMapN.keySet();
-                String attName;
-                Object attValueObj;
-                AttributeValue attValueN;
-                AttributeProperty attPropN;
-                TypeInfo typeInfo;
-                Type valuesType;
-                SimulatorResourceAttribute attributeN;
-                RemoteResourceAttribute attribute;
-                Iterator<String> attNameItr = attNameSet.iterator();
-                while (attNameItr.hasNext()) {
-                    attName = attNameItr.next();
-                    attributeN = attributeMapN.get(attName);
-                    if (null != attributeN) {
-                        attribute = new RemoteResourceAttribute();
-                        attribute.setResourceAttributeRef(attributeN);
-                        attribute.setAttributeName(attName);
-
-                        attValueN = attributeN.value();
-                        if (null != attValueN) {
-                            attValueObj = attValueN.get();
-                            if (null != attValueObj) {
-                                attribute.setAttributeValue(attValueObj);
-                            }
-
-                            // Set the attribute type
-                            typeInfo = attValueN.typeInfo();
-                            if (null != typeInfo) {
-                                attribute.setAttValBaseType(typeInfo.mBaseType);
-                                attribute.setAttValType(typeInfo.mType);
-                                attribute.setDepth(typeInfo.mDepth);
-                            }
-
-                        }
-
-                        // Set the range and allowed values
-                        attPropN = attributeN.property();
-                        valuesType = attPropN.type();
-                        attribute.setValuesType(valuesType);
-                        if (valuesType == Type.RANGE) {
-                            attribute.setMinValue(attPropN.min());
-                            attribute.setMaxValue(attPropN.max());
-                        } else if (valuesType == Type.VALUESET) {
-                            Object[] values = attPropN.valueSet();
-                            if (null != values && values.length > 0) {
-                                List<Object> valueList = new ArrayList<Object>();
-                                for (Object obj : values) {
-                                    valueList.add(((AttributeValue) obj).get());
-                                }
-                                attribute.setAllowedValues(valueList);
-                            }
-                        }
-                        resourceAttributeMap.put(attName, attribute);
-                    }
-                }
-            }
-        }
-        return resourceAttributeMap;
-    }
-
     private void newResourceFoundNotification(RemoteResource resource) {
         synchronized (findResourceUIListeners) {
             if (findResourceUIListeners.size() > 0) {
@@ -1401,13 +1294,135 @@ public class ResourceManager {
         return resourceList;
     }
 
-    public String getAttributeValue(RemoteResource res, String attName) {
-        if (null == res || null == attName) {
+    public List<String> getAllValuesOfAttribute(SimulatorResourceAttribute att) {
+        if (null == att) {
+            return null;
+        }
+
+        AttributeValue val = att.value();
+        if (null == val) {
             return null;
         }
-        return res.getAttributeValue(attName);
+
+        List<String> values = new ArrayList<String>();
+
+        TypeInfo type = val.typeInfo();
+
+        AttributeProperty prop = att.property();
+        if (null == prop || prop.type().ordinal() == Type.UNKNOWN.ordinal()) {
+            values.add(Utility.getAttributeValueAsString(val));
+            return values;
+        }
+
+        Type valuesType = prop.type();
+
+        if (type.mType != ValueType.RESOURCEMODEL) {
+            if (type.mType == ValueType.ARRAY) {
+                if (type.mDepth == 1) {
+                    AttributeProperty childProp = prop.getChildProperty();
+                    if (null != childProp) {
+                        valuesType = childProp.type();
+                        if (valuesType.ordinal() == Type.RANGE.ordinal()) {
+                            List<String> list = getRangeForPrimitiveNonArrayAttributes(
+                                    childProp, type.mBaseType);
+                            if (null != list) {
+                                values.addAll(list);
+                            }
+                        } else if (valuesType.ordinal() == Type.VALUESET
+                                .ordinal()) {
+                            List<String> list = getAllowedValuesForPrimitiveNonArrayAttributes(
+                                    childProp.valueSet(), type.mBaseType);
+                            if (null != list) {
+                                values.addAll(list);
+                            }
+                        }
+                    }
+                }
+            } else {
+                if (valuesType.ordinal() == Type.RANGE.ordinal()) {
+                    List<String> list = getRangeForPrimitiveNonArrayAttributes(
+                            prop, type.mType);
+                    if (null != list) {
+                        values.addAll(list);
+                    }
+                } else if (valuesType.ordinal() == Type.VALUESET.ordinal()) {
+                    List<String> list = getAllowedValuesForPrimitiveNonArrayAttributes(
+                            prop.valueSet(), type.mType);
+                    if (null != list) {
+                        values.addAll(list);
+                    }
+                }
+            }
+        }
+
+        if (values.isEmpty()) {
+            values.add(Utility.getAttributeValueAsString(val));
+        }
+
+        return values;
+    }
+
+    public List<String> getRangeForPrimitiveNonArrayAttributes(
+            AttributeProperty prop, ValueType type) {
+        if (null == prop) {
+            return null;
+        }
+
+        if (type == ValueType.ARRAY || type == ValueType.RESOURCEMODEL) {
+            return null;
+        }
+
+        List<String> values = new ArrayList<String>();
+        switch (type) {
+            case INTEGER:
+                int min = (int) prop.min();
+                int max = (int) prop.max();
+                for (int iVal = min; iVal <= max; iVal++) {
+                    values.add(String.valueOf(iVal));
+                }
+                break;
+            case DOUBLE:
+                double minD = (double) prop.min();
+                double maxD = (double) prop.max();
+                for (double iVal = minD; iVal <= maxD; iVal = iVal + 1.0) {
+                    values.add(String.valueOf(iVal));
+                }
+                break;
+            default:
+        }
+        return values;
+    }
+
+    public List<String> getAllowedValuesForPrimitiveNonArrayAttributes(
+            AttributeValue[] attValues, ValueType type) {
+        if (null == attValues || attValues.length < 1) {
+            return null;
+        }
+
+        if (type == ValueType.ARRAY || type == ValueType.RESOURCEMODEL) {
+            return null;
+        }
+
+        Object obj;
+        List<String> values = new ArrayList<String>();
+        for (AttributeValue val : attValues) {
+            if (null == val) {
+                continue;
+            }
+            obj = val.get();
+            if (null == obj) {
+                continue;
+            }
+            values.add(String.valueOf(obj));
+        }
+        return values;
     }
 
+    /*
+     * public String getAttributeValue(RemoteResource res, String attName) { if
+     * (null == res || null == attName) { return null; } return
+     * res.getAttributeValue(attName); }
+     */
     public void sendGetRequest(RemoteResource resource) {
         if (null == resource) {
             return;
@@ -1428,23 +1443,16 @@ public class ResourceManager {
     }
 
     public void sendPutRequest(RemoteResource resource,
-            List<PutPostAttributeModel> putPostModelList) {
-        if (null == resource) {
+            SimulatorResourceModel model) {
+        if (null == resource || null == model) {
             return;
         }
         SimulatorRemoteResource resourceN = resource.getRemoteResourceRef();
         if (null == resourceN) {
             return;
         }
-        Map<String, RemoteResourceAttribute> attMap = resource
-                .getResourceAttributesMap();
-        if (null == attMap || attMap.size() < 1) {
-            return;
-        }
         try {
-            SimulatorResourceModel resourceModel = getUpdatedResourceModel(
-                    attMap, putPostModelList);
-            resourceN.put(null, resourceModel, putListener);
+            resourceN.put(null, model, putListener);
         } catch (Exception e) {
             String addlInfo;
             addlInfo = "Invalid Attribute Value. Cannot send PUT request.";
@@ -1457,32 +1465,16 @@ public class ResourceManager {
     }
 
     public void sendPostRequest(RemoteResource resource,
-            List<PutPostAttributeModel> putPostModelList) {
-        if (null == resource) {
+            SimulatorResourceModel model) {
+        if (null == resource || null == model) {
             return;
         }
         SimulatorRemoteResource resourceN = resource.getRemoteResourceRef();
         if (null == resourceN) {
             return;
         }
-        Map<String, RemoteResourceAttribute> attMap = resource
-                .getResourceAttributesMap();
-        if (null == attMap || attMap.size() < 1) {
-            return;
-        }
-        // Filter out the attributes whose modification status is true.
-        Iterator<PutPostAttributeModel> itr = putPostModelList.iterator();
-        PutPostAttributeModel model;
-        while (itr.hasNext()) {
-            model = itr.next();
-            if (!model.isModified()) {
-                itr.remove();
-            }
-        }
         try {
-            SimulatorResourceModel resourceModel = getUpdatedResourceModel(
-                    attMap, putPostModelList);
-            resourceN.post(null, resourceModel, postListener);
+            resourceN.post(null, model, postListener);
         } catch (Exception e) {
             String addlInfo;
             addlInfo = "Invalid Attribute Value. Cannot send POST request.";
@@ -1494,22 +1486,6 @@ public class ResourceManager {
         }
     }
 
-    private SimulatorResourceModel getUpdatedResourceModel(
-            Map<String, RemoteResourceAttribute> attMap,
-            List<PutPostAttributeModel> putPostModelList) throws Exception {
-        SimulatorResourceModel resourceModel = new SimulatorResourceModel();
-        for (PutPostAttributeModel putPostAttribute : putPostModelList)
-        {
-            String attributeName = putPostAttribute.getAttName();
-            RemoteResourceAttribute resourceAttribute = attMap.get(attributeName);
-            AttributeValue attributeValue = AttributeValueBuilder.build(
-                    putPostAttribute.getAttValue(), resourceAttribute.getAttValBaseType());
-            resourceModel.addAttribute(attributeName, attributeValue);
-        }
-
-        return resourceModel;
-    }
-
     public boolean sendObserveRequest(RemoteResource resource) {
         if (null == resource) {
             return false;
@@ -1640,21 +1616,19 @@ public class ResourceManager {
             return false;
         }
         try {
-            SimulatorResourceModel resourceModel;
-            resourceModel = resourceN.setConfigInfo(configFilePath);
-            if (null == resourceModel) {
+            SimulatorResourceModel configuredResourceModel;
+            configuredResourceModel = resourceN.setConfigInfo(configFilePath);
+            if (null == configuredResourceModel) {
                 return false;
             }
+
             // Store the resource model in the local cache
-            resource.setResourceModelRef(resourceModel);
-
-            // Fetching the allowed values and range for all the attributes
-            Map<String, RemoteResourceAttribute> attributeMap = fetchResourceAttributesFromModel(resourceModel);
-            resource.setResourceAttributesMap(attributeMap);
-            // TODO: Printing the values for debugging
-            if (null != attributeMap) {
-                RemoteResourceAttribute.printAttributes(attributeMap);
+            SimulatorResourceModel resourceModel = resource
+                    .getResourceModelRef();
+            if (null != resourceModel) {
+                configuredResourceModel.update(resourceModel);
             }
+            resource.setResourceModelRef(configuredResourceModel);
         } catch (SimulatorException e) {
             Activator
                     .getDefault()
diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/AttributeElement.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/AttributeElement.java
new file mode 100644 (file)
index 0000000..670d2a7
--- /dev/null
@@ -0,0 +1,300 @@
+package oic.simulator.clientcontroller.remoteresource;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import oic.simulator.clientcontroller.utils.AttributeValueStringConverter;
+
+import org.oic.simulator.AttributeValue;
+import org.oic.simulator.InvalidArgsException;
+import org.oic.simulator.SimulatorResourceAttribute;
+import org.oic.simulator.SimulatorResourceModel;
+
+public class AttributeElement {
+    private Object                        mParent          = null;
+    private SimulatorResourceAttribute    mAttribute       = null;
+    private Map<String, AttributeElement> mChildAttributes = new HashMap<String, AttributeElement>();
+    private boolean                       mPostState       = false;
+
+    public AttributeElement(Object parent, SimulatorResourceAttribute attribute) {
+        mParent = parent;
+        mAttribute = attribute;
+        AttributeValue.TypeInfo typeInfo = attribute.value().typeInfo();
+        if (typeInfo.mType == AttributeValue.ValueType.RESOURCEMODEL) {
+            SimulatorResourceModel resModel = (SimulatorResourceModel) attribute
+                    .value().get();
+            for (Map.Entry<String, SimulatorResourceAttribute> entrySet : resModel
+                    .getAttributes().entrySet())
+                mChildAttributes.put(entrySet.getKey(), new AttributeElement(
+                        this, entrySet.getValue()));
+        } else if (typeInfo.mType == AttributeValue.ValueType.ARRAY
+                && typeInfo.mBaseType == AttributeValue.ValueType.RESOURCEMODEL) {
+            if (typeInfo.mDepth == 1) {
+                SimulatorResourceModel[] resModelArray = (SimulatorResourceModel[]) attribute
+                        .value().get();
+                for (int i = 0; i < resModelArray.length; i++) {
+                    SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
+                            "[" + Integer.toString(i) + "]",
+                            new AttributeValue(resModelArray[i]), null);
+                    mChildAttributes.put("[" + Integer.toString(i) + "]",
+                            new AttributeElement(this, indexAttribute));
+                }
+            } else if (typeInfo.mDepth == 2) {
+                SimulatorResourceModel[][] resModelArray = (SimulatorResourceModel[][]) attribute
+                        .value().get();
+                for (int i = 0; i < resModelArray.length; i++) {
+                    SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
+                            "[" + Integer.toString(i) + "]",
+                            new AttributeValue(resModelArray[i]), null);
+                    mChildAttributes.put("[" + Integer.toString(i) + "]",
+                            new AttributeElement(this, indexAttribute));
+                }
+            } else if (typeInfo.mDepth == 3) {
+                SimulatorResourceModel[][][] resModelArray = (SimulatorResourceModel[][][]) attribute
+                        .value().get();
+                for (int i = 0; i < resModelArray.length; i++) {
+                    SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
+                            "[" + Integer.toString(i) + "]",
+                            new AttributeValue(resModelArray[i]), null);
+                    mChildAttributes.put("[" + Integer.toString(i) + "]",
+                            new AttributeElement(this, indexAttribute));
+                }
+            }
+        }
+    }
+
+    public Object getParent() {
+        return mParent;
+    }
+
+    public boolean hasChildren() {
+        if (mChildAttributes != null && mChildAttributes.size() > 0)
+            return true;
+        return false;
+    }
+
+    public Map<String, AttributeElement> getChildren() {
+        if (hasChildren() == true)
+            return mChildAttributes;
+        return null;
+    }
+
+    public SimulatorResourceAttribute getSimulatorResourceAttribute() {
+        return mAttribute;
+    }
+
+    public boolean isPostSupported() {
+        /* Auto update is disabled for ARRAY and RESOURCEMODEL type values */
+        AttributeValue.TypeInfo typeInfo = mAttribute.value().typeInfo();
+        return (!(typeInfo.mType == AttributeValue.ValueType.ARRAY && typeInfo.mBaseType == AttributeValue.ValueType.RESOURCEMODEL) && typeInfo.mType != AttributeValue.ValueType.RESOURCEMODEL);
+    }
+
+    public void update(SimulatorResourceAttribute attribute) {
+        if (attribute == null)
+            return;
+
+        AttributeValue.TypeInfo typeInfo = attribute.value().typeInfo();
+        if (typeInfo.mType == AttributeValue.ValueType.RESOURCEMODEL) {
+            SimulatorResourceModel resModel = (SimulatorResourceModel) attribute
+                    .value().get();
+            for (Map.Entry<String, SimulatorResourceAttribute> entry : resModel
+                    .getAttributes().entrySet()) {
+                AttributeElement attributeElement = mChildAttributes.get(entry
+                        .getKey());
+                if (attributeElement != null) {
+                    attributeElement.update(entry.getValue());
+                } else // Display new attribute in UI
+                {
+                    AttributeElement newAttribute = new AttributeElement(this,
+                            entry.getValue());
+                    mChildAttributes.put(entry.getKey(), newAttribute);
+                }
+            }
+        } else if (typeInfo.mType == AttributeValue.ValueType.ARRAY
+                && typeInfo.mBaseType == AttributeValue.ValueType.RESOURCEMODEL) {
+            if (typeInfo.mDepth == 1) {
+                SimulatorResourceModel[] resModelArray = (SimulatorResourceModel[]) attribute
+                        .value().get();
+                for (int i = 0; i < resModelArray.length; i++) {
+                    SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
+                            "[" + Integer.toString(i) + "]",
+                            new AttributeValue(resModelArray[i]), null);
+                    AttributeElement attributeElement = mChildAttributes
+                            .get("[" + Integer.toString(i) + "]");
+                    if (attributeElement != null) {
+                        attributeElement.update(indexAttribute);
+                    } else // Display new attribute in UI
+                    {
+                        AttributeElement newAttribute = new AttributeElement(
+                                this, indexAttribute);
+                        mChildAttributes.put("[" + Integer.toString(i) + "]",
+                                newAttribute);
+                    }
+                }
+            }
+            if (typeInfo.mDepth == 2) {
+                SimulatorResourceModel[][] resModelArray = (SimulatorResourceModel[][]) attribute
+                        .value().get();
+                for (int i = 0; i < resModelArray.length; i++) {
+                    SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
+                            "[" + Integer.toString(i) + "]",
+                            new AttributeValue(resModelArray[i]), null);
+                    AttributeElement attributeElement = mChildAttributes
+                            .get("[" + Integer.toString(i) + "]");
+                    if (attributeElement != null) {
+                        attributeElement.update(indexAttribute);
+                    } else // Display new attribute in UI
+                    {
+                        AttributeElement newAttribute = new AttributeElement(
+                                this, indexAttribute);
+                        mChildAttributes.put("[" + Integer.toString(i) + "]",
+                                newAttribute);
+                    }
+                }
+            }
+            if (typeInfo.mDepth == 3) {
+                SimulatorResourceModel[][][] resModelArray = (SimulatorResourceModel[][][]) attribute
+                        .value().get();
+                for (int i = 0; i < resModelArray.length; i++) {
+                    SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
+                            "[" + Integer.toString(i) + "]",
+                            new AttributeValue(resModelArray[i]), null);
+                    AttributeElement attributeElement = mChildAttributes
+                            .get("[" + Integer.toString(i) + "]");
+                    if (attributeElement != null) {
+                        attributeElement.update(indexAttribute);
+                    } else // Display new attribute in UI
+                    {
+                        AttributeElement newAttribute = new AttributeElement(
+                                this, indexAttribute);
+                        mChildAttributes.put("[" + Integer.toString(i) + "]",
+                                newAttribute);
+                    }
+                }
+            }
+        } else {
+            String currentValue = new AttributeValueStringConverter(
+                    mAttribute.value()).toString();
+            String newValue = new AttributeValueStringConverter(
+                    attribute.value()).toString();
+            if (currentValue != newValue) {
+                mAttribute.setValue(attribute.value());
+            }
+        }
+    }
+
+    public void updateForRAMLUpload(SimulatorResourceAttribute attribute) {
+        if (attribute == null)
+            return;
+
+        AttributeValue.TypeInfo typeInfo = attribute.value().typeInfo();
+        if (typeInfo.mType == AttributeValue.ValueType.RESOURCEMODEL) {
+            SimulatorResourceModel resModel = (SimulatorResourceModel) attribute
+                    .value().get();
+            for (Map.Entry<String, SimulatorResourceAttribute> entry : resModel
+                    .getAttributes().entrySet()) {
+                AttributeElement attributeElement = mChildAttributes.get(entry
+                        .getKey());
+                if (attributeElement != null) {
+                    attributeElement.update(entry.getValue());
+                } else // Display new attribute in UI
+                {
+                    AttributeElement newAttribute = new AttributeElement(this,
+                            entry.getValue());
+                    mChildAttributes.put(entry.getKey(), newAttribute);
+                }
+            }
+        } else if (typeInfo.mType == AttributeValue.ValueType.ARRAY
+                && typeInfo.mBaseType == AttributeValue.ValueType.RESOURCEMODEL) {
+            if (typeInfo.mDepth == 1) {
+                SimulatorResourceModel[] resModelArray = (SimulatorResourceModel[]) attribute
+                        .value().get();
+                for (int i = 0; i < resModelArray.length; i++) {
+                    SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
+                            "[" + Integer.toString(i) + "]",
+                            new AttributeValue(resModelArray[i]), null);
+                    AttributeElement attributeElement = mChildAttributes
+                            .get("[" + Integer.toString(i) + "]");
+                    if (attributeElement != null) {
+                        attributeElement.update(indexAttribute);
+                    } else // Display new attribute in UI
+                    {
+                        AttributeElement newAttribute = new AttributeElement(
+                                this, indexAttribute);
+                        mChildAttributes.put("[" + Integer.toString(i) + "]",
+                                newAttribute);
+                    }
+                }
+            }
+            if (typeInfo.mDepth == 2) {
+                SimulatorResourceModel[][] resModelArray = (SimulatorResourceModel[][]) attribute
+                        .value().get();
+                for (int i = 0; i < resModelArray.length; i++) {
+                    SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
+                            "[" + Integer.toString(i) + "]",
+                            new AttributeValue(resModelArray[i]), null);
+                    AttributeElement attributeElement = mChildAttributes
+                            .get("[" + Integer.toString(i) + "]");
+                    if (attributeElement != null) {
+                        attributeElement.update(indexAttribute);
+                    } else // Display new attribute in UI
+                    {
+                        AttributeElement newAttribute = new AttributeElement(
+                                this, indexAttribute);
+                        mChildAttributes.put("[" + Integer.toString(i) + "]",
+                                newAttribute);
+                    }
+                }
+            }
+            if (typeInfo.mDepth == 3) {
+                SimulatorResourceModel[][][] resModelArray = (SimulatorResourceModel[][][]) attribute
+                        .value().get();
+                for (int i = 0; i < resModelArray.length; i++) {
+                    SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
+                            "[" + Integer.toString(i) + "]",
+                            new AttributeValue(resModelArray[i]), null);
+                    AttributeElement attributeElement = mChildAttributes
+                            .get("[" + Integer.toString(i) + "]");
+                    if (attributeElement != null) {
+                        attributeElement.update(indexAttribute);
+                    } else // Display new attribute in UI
+                    {
+                        AttributeElement newAttribute = new AttributeElement(
+                                this, indexAttribute);
+                        mChildAttributes.put("[" + Integer.toString(i) + "]",
+                                newAttribute);
+                    }
+                }
+            }
+        } else {
+            mAttribute.setProperty(attribute.property());
+        }
+    }
+
+    public boolean getPostState() {
+        return mPostState;
+    }
+
+    public void setPostState(boolean mPostState) {
+        this.mPostState = mPostState;
+    }
+
+    public void deepSetChildValue(SimulatorResourceAttribute attribute)
+            throws InvalidArgsException {
+        if (null == attribute || null == attribute.name())
+            return;
+
+        AttributeValue.TypeInfo myValuetypeInfo = mAttribute.value().typeInfo();
+        if (myValuetypeInfo.mType == AttributeValue.ValueType.RESOURCEMODEL) {
+            SimulatorResourceModel resModel = (SimulatorResourceModel) mAttribute
+                    .value().get();
+            if (resModel.containsAttribute(attribute.name()))
+                resModel.setAttributeValue(attribute.name(), attribute.value());
+            else
+                return;
+        }
+
+        if (mParent instanceof AttributeElement)
+            ((AttributeElement) mParent).deepSetChildValue(mAttribute);
+    }
+}
diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/PutPostAttributeModel.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/PutPostAttributeModel.java
deleted file mode 100644 (file)
index de3f384..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package oic.simulator.clientcontroller.remoteresource;
-
-import java.util.List;
-
-/**
- * This is a helper class for showing the resource attributes in PUT and POST
- * dialogs.
- */
-public class PutPostAttributeModel {
-
-    private String       attName;
-    private String       attValue;
-    private List<String> values;
-    boolean              modified;
-
-    public String getAttName() {
-        return attName;
-    }
-
-    public void setAttName(String attName) {
-        this.attName = attName;
-    }
-
-    public String getAttValue() {
-        return attValue;
-    }
-
-    public void setAttValue(String attValue) {
-        this.attValue = attValue;
-    }
-
-    public List<String> getValues() {
-        return values;
-    }
-
-    public void setValues(List<String> values) {
-        this.values = values;
-    }
-
-    public void prependNewValue(String customValue) {
-        if (values.contains(customValue)) {
-            values.remove(customValue);
-        }
-        values.add(0, customValue);
-    }
-
-    public boolean isModified() {
-        return modified;
-    }
-
-    public void setModified(boolean modified) {
-        this.modified = modified;
-    }
-
-    public static PutPostAttributeModel getModel(
-            RemoteResourceAttribute attribute) {
-        PutPostAttributeModel putPostModel = null;
-        if (null != attribute) {
-            putPostModel = new PutPostAttributeModel();
-            putPostModel.setAttName(attribute.getAttributeName());
-            putPostModel.setAttValue(String.valueOf(attribute
-                    .getAttributeValue()));
-            putPostModel.setValues(attribute.getAllValues());
-            putPostModel.setModified(false);
-        }
-        return putPostModel;
-    }
-
-    @Override
-    public String toString() {
-        return attName + "," + attValue + "\n";
-    }
-}
index 04c39d1..977e0b2 100644 (file)
 
 package oic.simulator.clientcontroller.remoteresource;
 
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
 import oic.simulator.clientcontroller.utils.Constants;
 
 import org.oic.simulator.SimulatorResourceModel;
@@ -32,24 +27,25 @@ import org.oic.simulator.client.SimulatorRemoteResource;
  */
 public class RemoteResource {
 
-    private boolean                              observed;
+    private boolean                 observed;
 
     // Native object references
-    private SimulatorRemoteResource              remoteResourceRef;
-    private SimulatorResourceModel               resourceModelRef;
-    private Map<String, RemoteResourceAttribute> resourceAttributesMap;
+    private SimulatorRemoteResource remoteResourceRef;
+    private SimulatorResourceModel  resourceModelRef;
+    private ResourceRepresentation  mResourceRepresentation;
+    // private Map<String, RemoteResourceAttribute> resourceAttributesMap;
 
-    private boolean                              configUploaded;
+    private boolean                 configUploaded;
 
-    private boolean                              getAutomtnInProgress;
-    private boolean                              putAutomtnInProgress;
-    private boolean                              postAutomtnInProgress;
+    private boolean                 getAutomtnInProgress;
+    private boolean                 putAutomtnInProgress;
+    private boolean                 postAutomtnInProgress;
 
-    private int                                  getAutomtnId;
-    private int                                  putAutomtnId;
-    private int                                  postAutomtnId;
+    private int                     getAutomtnId;
+    private int                     putAutomtnId;
+    private int                     postAutomtnId;
 
-    private boolean                              isFavorite;
+    private boolean                 isFavorite;
 
     public SimulatorResourceModel getResourceModelRef() {
         return resourceModelRef;
@@ -59,15 +55,14 @@ public class RemoteResource {
         this.resourceModelRef = resourceModel;
     }
 
-    public Map<String, RemoteResourceAttribute> getResourceAttributesMap() {
-        return resourceAttributesMap;
-    }
-
-    public void setResourceAttributesMap(
-            Map<String, RemoteResourceAttribute> resourceAttributesMap) {
-        this.resourceAttributesMap = resourceAttributesMap;
-    }
-
+    /*
+     * public Map<String, RemoteResourceAttribute> getResourceAttributesMap() {
+     * return resourceAttributesMap; }
+     * 
+     * public void setResourceAttributesMap( Map<String,
+     * RemoteResourceAttribute> resourceAttributesMap) {
+     * this.resourceAttributesMap = resourceAttributesMap; }
+     */
     public int getGetAutomtnId() {
         return getAutomtnId;
     }
@@ -140,35 +135,22 @@ public class RemoteResource {
         this.observed = observed;
     }
 
-    public List<PutPostAttributeModel> getPutPostModel() {
-        Map<String, RemoteResourceAttribute> attMap = getResourceAttributesMap();
-        if (null == attMap || attMap.size() < 1) {
-            return null;
-        }
-        List<PutPostAttributeModel> putPostModelList = new ArrayList<PutPostAttributeModel>();
-        String attName;
-        RemoteResourceAttribute attribute;
-        PutPostAttributeModel putPostModel;
-        Iterator<String> attItr = attMap.keySet().iterator();
-        while (attItr.hasNext()) {
-            attName = attItr.next();
-            attribute = attMap.get(attName);
-            putPostModel = PutPostAttributeModel.getModel(attribute);
-            if (null != putPostModel) {
-                putPostModelList.add(putPostModel);
-            }
-        }
-        return putPostModelList;
-    }
-
-    public String getAttributeValue(String attName) {
-        RemoteResourceAttribute attribute = resourceAttributesMap.get(attName);
-        if (null == attribute) {
-            return null;
-        }
-        return String.valueOf(attribute.getAttributeValue());
-    }
-
+    /*
+     * public List<PutPostAttributeModel> getPutPostModel() { Map<String,
+     * RemoteResourceAttribute> attMap = getResourceAttributesMap(); if (null ==
+     * attMap || attMap.size() < 1) { return null; } List<PutPostAttributeModel>
+     * putPostModelList = new ArrayList<PutPostAttributeModel>(); String
+     * attName; RemoteResourceAttribute attribute; PutPostAttributeModel
+     * putPostModel; Iterator<String> attItr = attMap.keySet().iterator(); while
+     * (attItr.hasNext()) { attName = attItr.next(); attribute =
+     * attMap.get(attName); putPostModel =
+     * PutPostAttributeModel.getModel(attribute); if (null != putPostModel) {
+     * putPostModelList.add(putPostModel); } } return putPostModelList; }
+     * 
+     * public String getAttributeValue(String attName) { RemoteResourceAttribute
+     * attribute = resourceAttributesMap.get(attName); if (null == attribute) {
+     * return null; } return String.valueOf(attribute.getAttributeValue()); }
+     */
     public int getAutomationtype(int autoId) {
         if (getAutomtnId == autoId) {
             return Constants.GET_AUTOMATION_INDEX;
@@ -196,4 +178,16 @@ public class RemoteResource {
     public void setFavorite(boolean isFavorite) {
         this.isFavorite = isFavorite;
     }
+
+    public void setResourceRepresentation(SimulatorResourceModel resModel,
+            boolean ramlUploaded) {
+        if (mResourceRepresentation == null)
+            mResourceRepresentation = new ResourceRepresentation(resModel);
+        else
+            mResourceRepresentation.update(resModel, ramlUploaded);
+    }
+
+    public ResourceRepresentation getResourceRepresentation() {
+        return mResourceRepresentation;
+    }
 }
diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/ResourceRepresentation.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/ResourceRepresentation.java
new file mode 100644 (file)
index 0000000..724edbb
--- /dev/null
@@ -0,0 +1,82 @@
+package oic.simulator.clientcontroller.remoteresource;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.oic.simulator.InvalidArgsException;
+import org.oic.simulator.SimulatorResourceAttribute;
+import org.oic.simulator.SimulatorResourceModel;
+
+public class ResourceRepresentation {
+    private Map<String, AttributeElement> mAttributes = new HashMap<String, AttributeElement>();
+
+    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()));
+        }
+    }
+
+    public Map<String, AttributeElement> getAttributes() {
+        return mAttributes;
+    }
+
+    public void update(SimulatorResourceModel resourceModel,
+            boolean ramlUploaded) {
+        for (Map.Entry<String, SimulatorResourceAttribute> entry : resourceModel
+                .getAttributes().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 newAttribute = new AttributeElement(this,
+                        entry.getValue());
+                mAttributes.put(entry.getKey(), newAttribute);
+            }
+        }
+    }
+
+    public SimulatorResourceModel getModel() {
+        if (null == mAttributes || mAttributes.isEmpty()) {
+            return null;
+        }
+        SimulatorResourceModel model = new SimulatorResourceModel();
+        for (Map.Entry<String, AttributeElement> entry : mAttributes.entrySet()) {
+            AttributeElement attributeElement = mAttributes.get(entry.getKey());
+            if (attributeElement != null) {
+                try {
+                    model.addAttribute(attributeElement
+                            .getSimulatorResourceAttribute());
+                } catch (InvalidArgsException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        return model;
+    }
+
+    public SimulatorResourceModel getSelectedModel() {
+        if (null == mAttributes || mAttributes.isEmpty()) {
+            return null;
+        }
+        SimulatorResourceModel model = new SimulatorResourceModel();
+        for (Map.Entry<String, AttributeElement> entry : mAttributes.entrySet()) {
+            AttributeElement attributeElement = mAttributes.get(entry.getKey());
+            if (attributeElement != null && attributeElement.getPostState()) {
+                try {
+                    model.addAttribute(attributeElement
+                            .getSimulatorResourceAttribute());
+                } catch (InvalidArgsException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        return model;
+    }
+}
\ No newline at end of file
diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/AttributeValueStringConverter.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/AttributeValueStringConverter.java
new file mode 100644 (file)
index 0000000..e15c5d2
--- /dev/null
@@ -0,0 +1,327 @@
+package oic.simulator.clientcontroller.utils;
+
+import java.util.Map;
+
+import org.oic.simulator.AttributeValue;
+import org.oic.simulator.AttributeValueVisitor;
+import org.oic.simulator.SimulatorResourceAttribute;
+import org.oic.simulator.SimulatorResourceModel;
+
+public class AttributeValueStringConverter implements
+        AttributeValueVisitor.VisitingMethods<String> {
+
+    private AttributeValue mValue;
+
+    public AttributeValueStringConverter(AttributeValue value) {
+        mValue = value;
+    }
+
+    @Override
+    public String toString() {
+        AttributeValueVisitor visitor = new AttributeValueVisitor(mValue, this);
+        return (String) visitor.visit();
+    }
+
+    @Override
+    public String visitingValue(Integer value) {
+        return value.toString();
+    }
+
+    @Override
+    public String visitingValue(Double value) {
+        return value.toString();
+    }
+
+    @Override
+    public String visitingValue(Boolean value) {
+        return value.toString();
+    }
+
+    @Override
+    public String visitingValue(String value) {
+        return new String(value);
+    }
+
+    @Override
+    public String visitingValue(SimulatorResourceModel value) {
+        StringBuilder result = new StringBuilder();
+        result.append("{");
+        boolean first = true;
+        for (Map.Entry<String, SimulatorResourceAttribute> entry : value
+                .getAttributes().entrySet()) {
+            if (!first)
+                result.append(", ");
+            first = false;
+            result.append("\"" + entry.getKey() + "\":");
+            AttributeValue attributeValue = entry.getValue().value();
+            result.append(new AttributeValueStringConverter(attributeValue)
+                    .toString());
+        }
+
+        result.append("}");
+        return result.toString();
+    }
+
+    @Override
+    public String visitingValue(Integer[] values) {
+        StringBuilder result = new StringBuilder();
+        result.append("[");
+        boolean first = true;
+        for (Integer value : values) {
+            if (!first)
+                result.append(", ");
+            first = false;
+            result.append(value.toString());
+        }
+
+        result.append("]");
+        return result.toString();
+    }
+
+    @Override
+    public String visitingValue(Double[] values) {
+        StringBuilder result = new StringBuilder();
+        result.append("[");
+        boolean first = true;
+        for (Double value : values) {
+            if (!first)
+                result.append(", ");
+            first = false;
+            result.append(value.toString());
+        }
+
+        result.append("]");
+        return result.toString();
+    }
+
+    @Override
+    public String visitingValue(Boolean[] values) {
+        StringBuilder result = new StringBuilder();
+        result.append("[");
+        boolean first = true;
+        for (Boolean value : values) {
+            if (!first)
+                result.append(", ");
+            first = false;
+            result.append(value.toString());
+        }
+
+        result.append("]");
+        return result.toString();
+    }
+
+    @Override
+    public String visitingValue(String[] values) {
+        StringBuilder result = new StringBuilder();
+        result.append("[");
+        boolean first = true;
+        for (String value : values) {
+            if (!first)
+                result.append(", ");
+            first = false;
+            result.append(value);
+        }
+
+        result.append("]");
+        return result.toString();
+    }
+
+    @Override
+    public String visitingValue(SimulatorResourceModel[] values) {
+        StringBuilder result = new StringBuilder();
+        result.append("[");
+        boolean first = true;
+        for (SimulatorResourceModel value : values) {
+            if (!first)
+                result.append(", ");
+            first = false;
+            AttributeValue attributeValue = new AttributeValue(value);
+            result.append(new AttributeValueStringConverter(attributeValue)
+                    .toString());
+        }
+
+        result.append("]");
+        return result.toString();
+    }
+
+    @Override
+    public String visitingValue(Integer[][] values) {
+        StringBuilder result = new StringBuilder();
+        result.append("[");
+        boolean first = true;
+        for (Integer[] value : values) {
+            if (!first)
+                result.append(", ");
+            first = false;
+            AttributeValue attributeValue = new AttributeValue(value);
+            result.append(new AttributeValueStringConverter(attributeValue)
+                    .toString());
+        }
+
+        result.append("]");
+        return result.toString();
+    }
+
+    @Override
+    public String visitingValue(Double[][] values) {
+        StringBuilder result = new StringBuilder();
+        result.append("[");
+        boolean first = true;
+        for (Double[] value : values) {
+            if (!first)
+                result.append(", ");
+            first = false;
+            AttributeValue attributeValue = new AttributeValue(value);
+            result.append(new AttributeValueStringConverter(attributeValue)
+                    .toString());
+        }
+
+        result.append("]");
+        return result.toString();
+    }
+
+    @Override
+    public String visitingValue(Boolean[][] values) {
+        StringBuilder result = new StringBuilder();
+        result.append("[");
+        boolean first = true;
+        for (Boolean[] value : values) {
+            if (!first)
+                result.append(", ");
+            first = false;
+            AttributeValue attributeValue = new AttributeValue(value);
+            result.append(new AttributeValueStringConverter(attributeValue)
+                    .toString());
+        }
+
+        result.append("]");
+        return result.toString();
+    }
+
+    @Override
+    public String visitingValue(String[][] values) {
+        StringBuilder result = new StringBuilder();
+        result.append("[");
+        boolean first = true;
+        for (String[] value : values) {
+            if (!first)
+                result.append(", ");
+            first = false;
+            AttributeValue attributeValue = new AttributeValue(value);
+            result.append(new AttributeValueStringConverter(attributeValue)
+                    .toString());
+        }
+
+        result.append("]");
+        return result.toString();
+    }
+
+    @Override
+    public String visitingValue(SimulatorResourceModel[][] values) {
+        StringBuilder result = new StringBuilder();
+        result.append("[");
+        boolean first = true;
+        for (SimulatorResourceModel[] value : values) {
+            if (!first)
+                result.append(", ");
+            first = false;
+            AttributeValue attributeValue = new AttributeValue(value);
+            result.append(new AttributeValueStringConverter(attributeValue)
+                    .toString());
+        }
+
+        result.append("]");
+        return result.toString();
+    }
+
+    @Override
+    public String visitingValue(Integer[][][] values) {
+        StringBuilder result = new StringBuilder();
+        result.append("[");
+        boolean first = true;
+        for (Integer[][] value : values) {
+            if (!first)
+                result.append(", ");
+            first = false;
+            AttributeValue attributeValue = new AttributeValue(value);
+            result.append(new AttributeValueStringConverter(attributeValue)
+                    .toString());
+        }
+
+        result.append("]");
+        return result.toString();
+    }
+
+    @Override
+    public String visitingValue(Double[][][] values) {
+        StringBuilder result = new StringBuilder();
+        result.append("[");
+        boolean first = true;
+        for (Double[][] value : values) {
+            if (!first)
+                result.append(", ");
+            first = false;
+            AttributeValue attributeValue = new AttributeValue(value);
+            result.append(new AttributeValueStringConverter(attributeValue)
+                    .toString());
+        }
+
+        result.append("]");
+        return result.toString();
+    }
+
+    @Override
+    public String visitingValue(Boolean[][][] values) {
+        StringBuilder result = new StringBuilder();
+        result.append("[");
+        boolean first = true;
+        for (Boolean[][] value : values) {
+            if (!first)
+                result.append(", ");
+            first = false;
+            AttributeValue attributeValue = new AttributeValue(value);
+            result.append(new AttributeValueStringConverter(attributeValue)
+                    .toString());
+        }
+
+        result.append("]");
+        return result.toString();
+    }
+
+    @Override
+    public String visitingValue(String[][][] values) {
+        StringBuilder result = new StringBuilder();
+        result.append("[");
+        boolean first = true;
+        for (String[][] value : values) {
+            if (!first)
+                result.append(", ");
+            first = false;
+            AttributeValue attributeValue = new AttributeValue(value);
+            result.append(new AttributeValueStringConverter(attributeValue)
+                    .toString());
+        }
+
+        result.append("]");
+        return result.toString();
+    }
+
+    @Override
+    public String visitingValue(SimulatorResourceModel[][][] values) {
+        StringBuilder result = new StringBuilder();
+        result.append("[");
+        boolean first = true;
+        for (SimulatorResourceModel[][] value : values) {
+            if (!first)
+                result.append(", ");
+            first = false;
+            AttributeValue attributeValue = new AttributeValue(value);
+            result.append(new AttributeValueStringConverter(attributeValue)
+                    .toString());
+        }
+
+        result.append("]");
+        return result.toString();
+    }
+
+}
index 254f1f8..9c13390 100644 (file)
@@ -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<Integer> list = new ArrayList<Integer>();
+                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<Double> list = new ArrayList<Double>();
+                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<Boolean> list = new ArrayList<Boolean>();
+                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<String> list = new ArrayList<String>();
+                for (String i : values) {
+                    list.add(i);
+                }
+                return list.toString();
+            } else {
+                return null;
+            }
+        } else {
+            return String.valueOf(value);
+        }
+    }
 }
\ No newline at end of file
diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/AttributeEditingSupport.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/AttributeEditingSupport.java
new file mode 100644 (file)
index 0000000..0120f9d
--- /dev/null
@@ -0,0 +1,414 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package oic.simulator.clientcontroller.view;
+
+import java.util.List;
+
+import oic.simulator.clientcontroller.Activator;
+import oic.simulator.clientcontroller.manager.ResourceManager;
+import oic.simulator.clientcontroller.remoteresource.AttributeElement;
+import oic.simulator.clientcontroller.remoteresource.RemoteResource;
+import oic.simulator.clientcontroller.utils.AttributeValueBuilder;
+import oic.simulator.clientcontroller.utils.Utility;
+import oic.simulator.clientcontroller.view.dialogs.PostRequestDialog;
+
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.CheckboxCellEditor;
+import org.eclipse.jface.viewers.ComboBoxCellEditor;
+import org.eclipse.jface.viewers.EditingSupport;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CCombo;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+import org.oic.simulator.AttributeValue;
+import org.oic.simulator.AttributeValue.TypeInfo;
+import org.oic.simulator.AttributeValue.ValueType;
+import org.oic.simulator.InvalidArgsException;
+import org.oic.simulator.SimulatorResourceAttribute;
+
+/**
+ * This class provides editing support to the resources attributes table in the
+ * attributes view.
+ */
+public class AttributeEditingSupport {
+
+    private AttributeValueEditor attValueEditor;
+    private PostRequestEditor    postReqEditor;
+
+    public AttributeValueEditor createAttributeValueEditor(TreeViewer viewer,
+            TitleAreaDialog dialog) {
+        attValueEditor = new AttributeValueEditor(viewer, dialog);
+        return attValueEditor;
+    }
+
+    public PostRequestEditor createAutomationEditor(TreeViewer viewer) {
+        postReqEditor = new PostRequestEditor(viewer);
+        return postReqEditor;
+    }
+
+    class AttributeValueEditor extends EditingSupport {
+
+        private final TreeViewer viewer;
+        private CCombo           comboBox;
+        private TitleAreaDialog  dialog;
+
+        public AttributeValueEditor(TreeViewer viewer, TitleAreaDialog dialog) {
+            super(viewer);
+            this.viewer = viewer;
+            this.dialog = dialog;
+        }
+
+        @Override
+        protected boolean canEdit(Object arg0) {
+            return true;
+        }
+
+        @Override
+        protected CellEditor getCellEditor(final Object element) {
+            ResourceManager resourceManager = Activator.getDefault()
+                    .getResourceManager();
+
+            RemoteResource res = resourceManager
+                    .getCurrentResourceInSelection();
+            if (null == res) {
+                return null;
+            }
+
+            final SimulatorResourceAttribute attribute;
+            if (!(element instanceof AttributeElement)) {
+                return null;
+            }
+
+            final AttributeElement attributeElement = ((AttributeElement) element);
+            attribute = attributeElement.getSimulatorResourceAttribute();
+            if (null == attribute) {
+                return null;
+            }
+
+            final AttributeValue val = attribute.value();
+            if (null == val) {
+                return null;
+            }
+
+            final TypeInfo type = val.typeInfo();
+            if (type.mBaseType == ValueType.RESOURCEMODEL) {
+                return null;
+            }
+
+            String values[] = null;
+            List<String> valueSet = resourceManager
+                    .getAllValuesOfAttribute(attribute);
+            values = convertListToStringArray(valueSet);
+
+            ComboBoxCellEditor comboEditor;
+            comboEditor = new ComboBoxCellEditor(viewer.getTree(), values);
+            comboBox = (CCombo) comboEditor.getControl();
+            comboBox.addModifyListener(new ModifyListener() {
+
+                @Override
+                public void modifyText(ModifyEvent event) {
+
+                    String newValue = comboBox.getText();
+
+                    if (null != newValue && !newValue.isEmpty()) {
+                        attributeElement.setPostState(true);
+                    } else {
+                        attributeElement.setPostState(false);
+                    }
+
+                    /*
+                     * if (type.mType == ValueType.ARRAY) { return; }
+                     */
+                    /*
+                     * String oldValue = String.valueOf(Utility
+                     * .getAttributeValueAsString(val)); String newValue =
+                     * comboBox.getText();
+                     * 
+                     * if (null != newValue && !newValue.isEmpty()) {
+                     * attributeElement.setPostState(true); } else {
+                     * attributeElement.setPostState(false); }
+                     * 
+                     * if (!oldValue.equals(newValue)) { // Get the
+                     * AttriuteValue from the string AttributeValue value =
+                     * AttributeValueBuilder.build( newValue, type.mBaseType);
+                     * TypeInfo resTypeInfo = value.typeInfo(); if (null ==
+                     * value || type.mDepth != resTypeInfo.mDepth || type.mType
+                     * != resTypeInfo.mType || type.mBaseType !=
+                     * resTypeInfo.mBaseType) { MessageBox dialog = new
+                     * MessageBox(viewer.getTree() .getShell(), SWT.ICON_ERROR |
+                     * SWT.OK); dialog.setText("Invalid Value");
+                     * dialog.setMessage("Given value is invalid");
+                     * dialog.open(); } else { updateAttributeValue(attribute,
+                     * value); } }
+                     */
+                    if (dialog instanceof PostRequestDialog) {
+                        viewer.update(attributeElement, null);
+                        // comboBox.setVisible(false);
+                    }
+                }
+            });
+            return comboEditor;
+        }
+
+        @Override
+        protected Object getValue(Object element) {
+            int indexOfItem = 0;
+            SimulatorResourceAttribute att = null;
+
+            if (element instanceof AttributeElement) {
+                att = ((AttributeElement) element)
+                        .getSimulatorResourceAttribute();
+            }
+
+            if (att == null) {
+                return 0;
+            }
+
+            String valueString = Utility.getAttributeValueAsString(att.value());
+            List<String> valueSet = Activator.getDefault().getResourceManager()
+                    .getAllValuesOfAttribute(att);
+            if (null != valueSet) {
+                indexOfItem = valueSet.indexOf(valueString);
+            }
+            if (indexOfItem == -1) {
+                indexOfItem = 0;
+            }
+            return indexOfItem;
+        }
+
+        @Override
+        protected void setValue(Object element, Object value) {
+            SimulatorResourceAttribute att = null;
+            if (element instanceof AttributeElement) {
+                att = ((AttributeElement) element)
+                        .getSimulatorResourceAttribute();
+            }
+
+            if (att == null) {
+                return;
+            }
+
+            AttributeValue val = att.value();
+            if (null == val) {
+                return;
+            }
+
+            TypeInfo type = val.typeInfo();
+            /*
+             * if (type.mType == ValueType.ARRAY) { int index; try { index =
+             * Integer.parseInt(String.valueOf(value)); } catch
+             * (NumberFormatException nfe) { index = -1; } if (index == -1) {
+             * String oldValue = String.valueOf(Utility
+             * .getAttributeValueAsString(val)); String newValue =
+             * comboBox.getText(); if (!oldValue.equals(newValue)) { // Get the
+             * AttriuteValue from the string AttributeValue attValue =
+             * AttributeValueBuilder.build( newValue, type.mBaseType); TypeInfo
+             * resTypeInfo = attValue.typeInfo(); if (null == attValue ||
+             * type.mDepth != resTypeInfo.mDepth || type.mType !=
+             * resTypeInfo.mType || type.mBaseType != resTypeInfo.mBaseType) {
+             * MessageBox dialog = new MessageBox(viewer.getTree() .getShell(),
+             * SWT.ICON_ERROR | SWT.OK); dialog.setText("Invalid Value");
+             * dialog.setMessage("Given value is invalid"); dialog.open(); }
+             * else { updateAttributeValue(att, attValue); } } } }
+             */
+
+            String oldValue = String.valueOf(Utility
+                    .getAttributeValueAsString(val));
+            String newValue = comboBox.getText();
+            if (!oldValue.equals(newValue)) {
+                // Get the AttriuteValue from the string
+                AttributeValue attValue = AttributeValueBuilder.build(newValue,
+                        type.mBaseType);
+                TypeInfo resTypeInfo = attValue.typeInfo();
+                if (null == attValue || type.mDepth != resTypeInfo.mDepth
+                        || type.mType != resTypeInfo.mType
+                        || type.mBaseType != resTypeInfo.mBaseType) {
+                    MessageBox dialog = new MessageBox(viewer.getTree()
+                            .getShell(), SWT.ICON_ERROR | SWT.OK);
+                    dialog.setText("Invalid Value");
+                    dialog.setMessage("Given value is invalid");
+                    dialog.open();
+                } else {
+                    updateAttributeValue(att, attValue);
+                }
+            }
+
+            viewer.update(element, null);
+        }
+
+        public String[] convertListToStringArray(List<String> values) {
+            String[] strArr;
+            if (null != values && values.size() > 0) {
+                strArr = values.toArray(new String[1]);
+            } else {
+                strArr = new String[1];
+            }
+            return strArr;
+        }
+
+        public void updateAttributeValue(SimulatorResourceAttribute att,
+                AttributeValue value) {
+            att.setValue(value);
+
+            IStructuredSelection selection = (IStructuredSelection) viewer
+                    .getSelection();
+            if (null == selection) {
+                return;
+            }
+
+            Object obj = selection.getFirstElement();
+            if (null == obj) {
+                return;
+            }
+
+            Tree t = viewer.getTree();
+            TreeItem item = t.getSelection()[0];
+            if (null == item) {
+                return;
+            }
+
+            TreeItem parent = item.getParentItem();
+            if (null != parent) {
+                while (parent.getParentItem() != null) {
+                    parent = parent.getParentItem();
+                }
+                Object data = parent.getData();
+                ((AttributeElement) data).setPostState(true);
+            }
+
+            if (item.getData() instanceof AttributeElement) {
+                AttributeElement attributeElement = (AttributeElement) item
+                        .getData();
+                attributeElement.getSimulatorResourceAttribute()
+                        .setValue(value);
+
+                parent = item.getParentItem();
+                if (null != parent) {
+                    Object data = parent.getData();
+                    try {
+                        ((AttributeElement) data).deepSetChildValue(att);
+                    } catch (InvalidArgsException e) {
+                        e.printStackTrace();
+                    }
+                }
+            }
+        }
+
+        public AttributeValue getResultantValue(AttributeValue newValue) {
+            AttributeValue val = null;
+            IStructuredSelection selection = (IStructuredSelection) viewer
+                    .getSelection();
+            if (null == selection) {
+                return null;
+            }
+
+            Object obj = selection.getFirstElement();
+            if (null == obj) {
+                return null;
+            }
+
+            Tree t = viewer.getTree();
+            TreeItem item = t.getSelection()[0];
+            if (null == item) {
+                return null;
+            }
+
+            TreeItem parent = item.getParentItem();
+            if (null == parent) {
+                val = newValue;
+            } else {
+                while (parent.getParentItem() != null) {
+                    parent = parent.getParentItem();
+                }
+                // Parent will point to the top-level attribute of type
+                // LocalResourceAttribute
+                Object data = parent.getData();
+                val = ((AttributeElement) data).getSimulatorResourceAttribute()
+                        .value();
+            }
+
+            return val;
+        }
+    }
+
+    class PostRequestEditor extends EditingSupport {
+
+        private final TreeViewer viewer;
+
+        public PostRequestEditor(TreeViewer viewer) {
+            super(viewer);
+            this.viewer = viewer;
+        }
+
+        @Override
+        protected boolean canEdit(Object arg0) {
+            return true;
+        }
+
+        @Override
+        protected CellEditor getCellEditor(Object element) {
+            SimulatorResourceAttribute att = null;
+            if (element instanceof AttributeElement) {
+                att = ((AttributeElement) element)
+                        .getSimulatorResourceAttribute();
+            }
+
+            if (null == att) {
+                return null;
+            }
+
+            AttributeValue val = att.value();
+            if (null == val) {
+                return null;
+            }
+
+            TypeInfo type = val.typeInfo();
+
+            if (type.mType == ValueType.RESOURCEMODEL
+                    || type.mBaseType == ValueType.RESOURCEMODEL) {
+                return null;
+            }
+
+            return new CheckboxCellEditor(null, SWT.CHECK | SWT.READ_ONLY);
+        }
+
+        @Override
+        protected Object getValue(Object element) {
+            if (element instanceof AttributeElement) {
+                return ((AttributeElement) element).getPostState();
+            }
+
+            return false;
+        }
+
+        @Override
+        protected void setValue(Object element, Object value) {
+            if (!(element instanceof AttributeElement)) {
+                return;
+            }
+            boolean status = (Boolean) value;
+            ((AttributeElement) element).setPostState(status);
+            viewer.update(element, null);
+        }
+    }
+}
index e61d484..953e8f0 100644 (file)
@@ -16,7 +16,6 @@
 
 package oic.simulator.clientcontroller.view;
 
-import java.util.List;
 import java.util.Map;
 
 import oic.simulator.clientcontroller.Activator;
@@ -28,35 +27,39 @@ import oic.simulator.clientcontroller.listener.IPutUIListener;
 import oic.simulator.clientcontroller.listener.IResourceSelectionChangedUIListener;
 import oic.simulator.clientcontroller.listener.IVerificationUIListener;
 import oic.simulator.clientcontroller.manager.ResourceManager;
-import oic.simulator.clientcontroller.remoteresource.PutPostAttributeModel;
+import oic.simulator.clientcontroller.remoteresource.AttributeElement;
 import oic.simulator.clientcontroller.remoteresource.RemoteResource;
-import oic.simulator.clientcontroller.remoteresource.RemoteResourceAttribute;
+import oic.simulator.clientcontroller.remoteresource.ResourceRepresentation;
 import oic.simulator.clientcontroller.utils.Constants;
+import oic.simulator.clientcontroller.utils.Utility;
 import oic.simulator.clientcontroller.view.dialogs.PostRequestDialog;
 import oic.simulator.clientcontroller.view.dialogs.PutRequestDialog;
 import oic.simulator.clientcontroller.view.dialogs.VerificationDialog;
 
 import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.StyledCellLabelProvider;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TreeViewer;
 import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerCell;
 import org.eclipse.jface.window.Window;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeColumn;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.part.ViewPart;
+import org.oic.simulator.AttributeValue.ValueType;
+import org.oic.simulator.SimulatorResourceAttribute;
 import org.oic.simulator.client.SimulatorRemoteResource.VerificationType;
 
 /**
@@ -66,7 +69,7 @@ public class AttributeView extends ViewPart {
 
     public static final String                  VIEW_ID        = "oic.simulator.clientcontroller.view.attribute";
 
-    private TableViewer                         attTblViewer;
+    private TreeViewer                          attViewer;
 
     private Button                              getButton;
     private Button                              putButton;
@@ -107,9 +110,9 @@ public class AttributeView extends ViewPart {
                         setVisibility((resource == null) ? false : true);
 
                         // Update the attribute table
-                        if (null != attTblViewer
-                                && !attTblViewer.getControl().isDisposed()) {
-                            updateViewer(getData(resource));
+                        if (null != attViewer
+                                && !attViewer.getControl().isDisposed()) {
+                            updateViewer(resource);
                         }
 
                         // Update the observe status
@@ -134,7 +137,7 @@ public class AttributeView extends ViewPart {
                         if (resourceInSelection != resource) {
                             return;
                         }
-                        updateViewer(getData(resource));
+                        updateViewer(resource);
 
                         // Update the observe status
                         updateObserve(resource);
@@ -158,7 +161,7 @@ public class AttributeView extends ViewPart {
                         if (resourceInSelection != resource) {
                             return;
                         }
-                        updateViewer(getData(resource));
+                        updateViewer(resource);
 
                         // Update the observe status
                         updateObserve(resource);
@@ -182,7 +185,7 @@ public class AttributeView extends ViewPart {
                         if (resourceInSelection != resource) {
                             return;
                         }
-                        updateViewer(getData(resource));
+                        updateViewer(resource);
 
                         // Update the observe status
                         updateObserve(resource);
@@ -206,7 +209,7 @@ public class AttributeView extends ViewPart {
                         if (resourceInSelection != resource) {
                             return;
                         }
-                        updateViewer(getData(resource));
+                        updateViewer(resource);
 
                         // Update the observe status
                         updateObserve(resource);
@@ -293,28 +296,20 @@ public class AttributeView extends ViewPart {
         }
     }
 
-    private Map<String, RemoteResourceAttribute> getData(RemoteResource resource) {
-        if (null == resource) {
-            return null;
+    private void updateViewer(RemoteResource resource) {
+        if (null == attViewer) {
+            return;
         }
-        Map<String, RemoteResourceAttribute> attMap = resource
-                .getResourceAttributesMap();
-        return attMap;
-    }
-
-    private void updateViewer(Map<String, RemoteResourceAttribute> attMap) {
-        if (null != attTblViewer) {
-            Table tbl = attTblViewer.getTable();
-            if (null != attMap) {
-                attTblViewer.setInput(attMap.entrySet().toArray());
-                if (!tbl.isDisposed()) {
-                    tbl.setLinesVisible(true);
-                }
-            } else {
-                if (!tbl.isDisposed()) {
-                    tbl.removeAll();
-                    tbl.setLinesVisible(false);
-                }
+        Tree tree = attViewer.getTree();
+        if (null != resource) {
+            attViewer.setInput(resource.getResourceRepresentation());
+            if (!tree.isDisposed()) {
+                tree.setLinesVisible(true);
+            }
+        } else {
+            if (!tree.isDisposed()) {
+                tree.removeAll();
+                tree.setLinesVisible(false);
             }
         }
     }
@@ -363,9 +358,8 @@ public class AttributeView extends ViewPart {
         setVisibility(false);
 
         // Updating the data in the UI as per the resource in selection.
-        if (null != attTblViewer && !attTblViewer.getControl().isDisposed()) {
-            updateViewer(getData(resourceManager
-                    .getCurrentResourceInSelection()));
+        if (null != attViewer && !attViewer.getControl().isDisposed()) {
+            updateViewer(resourceManager.getCurrentResourceInSelection());
         }
     }
 
@@ -421,57 +415,34 @@ public class AttributeView extends ViewPart {
     }
 
     private void setupAttributeTable(Group attGroup) {
-        attTblViewer = new TableViewer(attGroup, SWT.SINGLE | SWT.H_SCROLL
-                | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
+        Tree addressTree = new Tree(attGroup, SWT.SINGLE | SWT.BORDER
+                | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
+        addressTree.setHeaderVisible(true);
 
-        createAttributeColumns(attTblViewer);
+        attViewer = new TreeViewer(addressTree);
+
+        createAttributeColumns(attViewer);
 
         // make lines and header visible
-        Table table = attTblViewer.getTable();
-        table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-        table.setHeaderVisible(true);
-        table.setLinesVisible(true);
+        Tree tree = attViewer.getTree();
+        tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+        tree.setHeaderVisible(true);
+        tree.setLinesVisible(true);
 
-        attTblViewer.setContentProvider(new AttributeContentProvider());
+        attViewer.setContentProvider(new AttributeContentProvider());
+        attViewer.setLabelProvider(new AttributeLabelProvider());
     }
 
-    public void createAttributeColumns(TableViewer tableViewer) {
+    public void createAttributeColumns(TreeViewer viewer) {
+        Tree tree = viewer.getTree();
 
-        TableViewerColumn attName = new TableViewerColumn(tableViewer, SWT.NONE);
-        attName.getColumn().setWidth(attTblColWidth[0]);
-        attName.getColumn().setText(attTblHeaders[0]);
-        attName.setLabelProvider(new StyledCellLabelProvider() {
-            @Override
-            public void update(ViewerCell cell) {
-                Object element = cell.getElement();
-                if (element instanceof Map.Entry) {
-                    @SuppressWarnings("unchecked")
-                    Map.Entry<String, RemoteResourceAttribute> entry = (Map.Entry<String, RemoteResourceAttribute>) element;
-                    cell.setText(entry.getKey());
-                }
-            }
-        });
+        TreeColumn attName = new TreeColumn(tree, SWT.NONE);
+        attName.setWidth(attTblColWidth[0]);
+        attName.setText(attTblHeaders[0]);
 
-        TableViewerColumn attValue = new TableViewerColumn(tableViewer,
-                SWT.NONE);
-        attValue.getColumn().setWidth(attTblColWidth[1]);
-        attValue.getColumn().setText(attTblHeaders[1]);
-        attValue.setLabelProvider(new StyledCellLabelProvider() {
-            @Override
-            public void update(ViewerCell cell) {
-                Object element = cell.getElement();
-                if (element instanceof Map.Entry) {
-                    @SuppressWarnings("unchecked")
-                    Map.Entry<String, RemoteResourceAttribute> entry = (Map.Entry<String, RemoteResourceAttribute>) element;
-                    Object value = entry.getValue().getAttributeValue();
-                    if (null == value) {
-                        cell.setText("");
-                    } else {
-                        cell.setText(String.valueOf(value));
-                    }
-                }
-            }
-        });
+        TreeColumn attValue = new TreeColumn(tree, SWT.NONE);
+        attValue.setWidth(attTblColWidth[1]);
+        attValue.setText(attTblHeaders[1]);
     }
 
     private void setUIListeners() {
@@ -503,10 +474,8 @@ public class AttributeView extends ViewPart {
                                             "PUT Automation is in progress. Please wait or stop the automation.");
                             return;
                         }
-                        List<PutPostAttributeModel> putPostModelList;
-                        putPostModelList = resourceInSelection
-                                .getPutPostModel();
-                        if (null == putPostModelList) {
+                        if (resourceInSelection.getResourceRepresentation()
+                                .getAttributes().size() < 1) {
                             MessageDialog
                                     .openInformation(Display.getDefault()
                                             .getActiveShell(), "PUT Request",
@@ -514,12 +483,12 @@ public class AttributeView extends ViewPart {
                             return;
                         }
                         PutRequestDialog putDialog = new PutRequestDialog(
-                                Display.getDefault().getActiveShell(),
-                                putPostModelList);
+                                Display.getDefault().getActiveShell());
                         if (putDialog.open() == Window.OK) {
                             // Call the native PUT method
                             resourceManager.sendPutRequest(resourceInSelection,
-                                    putPostModelList);
+                                    putDialog.getUpdatedRepresentation()
+                                            .getModel());
                         }
                     }
                 });
@@ -539,24 +508,24 @@ public class AttributeView extends ViewPart {
                                             "POST Automation is in progress. Please wait or stop the automation.");
                             return;
                         }
-                        List<PutPostAttributeModel> putPostModelList;
-                        putPostModelList = resourceInSelection
-                                .getPutPostModel();
-                        if (null == putPostModelList) {
+                        if (resourceInSelection.getResourceRepresentation()
+                                .getAttributes().size() < 1) {
                             MessageDialog
                                     .openInformation(Display.getDefault()
-                                            .getActiveShell(), "PUT Request",
+                                            .getActiveShell(), "POST Request",
                                             "No attributes exist in the resource model.");
                             return;
                         }
 
                         PostRequestDialog postDialog = new PostRequestDialog(
-                                Display.getDefault().getActiveShell(),
-                                putPostModelList);
+                                Display.getDefault().getActiveShell());
                         if (postDialog.open() == Window.OK) {
                             // Call the native POST method
+                            ResourceRepresentation representation = postDialog
+                                    .getUpdatedRepresentation();
                             resourceManager.sendPostRequest(
-                                    resourceInSelection, putPostModelList);
+                                    resourceInSelection,
+                                    representation.getSelectedModel());
                         }
                     }
                 });
@@ -756,21 +725,103 @@ public class AttributeView extends ViewPart {
             observeResButton.setEnabled(visibility);
     }
 
-    class AttributeContentProvider implements IStructuredContentProvider {
+    class AttributeContentProvider implements ITreeContentProvider {
 
         @Override
         public void dispose() {
         }
 
         @Override
-        public void inputChanged(Viewer viewer, Object arg1, Object arg2) {
+        public void inputChanged(Viewer viewer, Object oldAttribute,
+                Object newAttribute) {
+        }
+
+        @Override
+        public Object[] getChildren(Object attribute) {
+            if (attribute instanceof AttributeElement) {
+                return ((AttributeElement) attribute).getChildren().values()
+                        .toArray();
+            }
+
+            return new Object[0];
+        }
+
+        @Override
+        public Object getParent(Object attribute) {
+            if (attribute instanceof AttributeElement)
+                return ((AttributeElement) attribute).getParent();
+            return null;
         }
 
         @Override
-        public Object[] getElements(Object element) {
-            return (Object[]) element;
+        public boolean hasChildren(Object attribute) {
+            if (attribute instanceof AttributeElement)
+                return ((AttributeElement) attribute).hasChildren();
+            return false;
         }
 
+        @Override
+        public Object[] getElements(Object resourceModel) {
+            if (resourceModel instanceof ResourceRepresentation) {
+                return ((ResourceRepresentation) resourceModel).getAttributes()
+                        .values().toArray();
+            }
+
+            return new Object[0];
+        }
+    }
+
+    class AttributeLabelProvider implements ITableLabelProvider {
+
+        @Override
+        public void addListener(ILabelProviderListener arg0) {
+        }
+
+        @Override
+        public void dispose() {
+        }
+
+        @Override
+        public boolean isLabelProperty(Object arg0, String arg1) {
+            return false;
+        }
+
+        @Override
+        public void removeListener(ILabelProviderListener arg0) {
+
+        }
+
+        @Override
+        public Image getColumnImage(Object element, int col) {
+            return null;
+        }
+
+        @Override
+        public String getColumnText(Object element, int column) {
+            if (element instanceof AttributeElement) {
+                AttributeElement attrElement = (AttributeElement) element;
+                switch (column) {
+                    case 0: // Attribute name column
+                    {
+                        SimulatorResourceAttribute attribute = attrElement
+                                .getSimulatorResourceAttribute();
+                        return attribute.name();
+                    }
+
+                    case 1: // Attribute value column
+                    {
+                        SimulatorResourceAttribute attribute = attrElement
+                                .getSimulatorResourceAttribute();
+
+                        if (attribute.value().typeInfo().mBaseType != ValueType.RESOURCEMODEL)
+                            return Utility.getAttributeValueAsString(attribute
+                                    .value());
+                        return null;
+                    }
+                }
+            }
+            return null;
+        }
     }
 
     @Override
index 2e9bc3c..2dec196 100644 (file)
 
 package oic.simulator.clientcontroller.view.dialogs;
 
-import java.util.Iterator;
-import java.util.List;
-
 import oic.simulator.clientcontroller.Activator;
-import oic.simulator.clientcontroller.manager.ResourceManager;
-import oic.simulator.clientcontroller.remoteresource.PutPostAttributeModel;
+import oic.simulator.clientcontroller.remoteresource.AttributeElement;
+import oic.simulator.clientcontroller.remoteresource.RemoteResource;
+import oic.simulator.clientcontroller.remoteresource.ResourceRepresentation;
 import oic.simulator.clientcontroller.utils.Constants;
+import oic.simulator.clientcontroller.utils.Utility;
+import oic.simulator.clientcontroller.view.AttributeEditingSupport;
 
 import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.dialogs.TitleAreaDialog;
-import org.eclipse.jface.viewers.CellEditor;
-import org.eclipse.jface.viewers.CheckboxCellEditor;
-import org.eclipse.jface.viewers.ColumnLabelProvider;
-import org.eclipse.jface.viewers.ComboBoxCellEditor;
-import org.eclipse.jface.viewers.EditingSupport;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.StyledCellLabelProvider;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.TreeViewerColumn;
 import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerCell;
 import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.CCombo;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeColumn;
+import org.oic.simulator.AttributeValue.ValueType;
+import org.oic.simulator.SimulatorResourceAttribute;
 
 /**
  * This dialog is used for generating a POST request.
  */
 public class PostRequestDialog extends TitleAreaDialog {
 
-    private TableViewer                 attTblViewer;
+    private TreeViewer              attViewer;
+
+    private AttributeEditingSupport attributeEditor;
 
-    private final String[]              attTblHeaders  = { "Name", "Value",
-            "Select"                                  };
-    private final Integer[]             attTblColWidth = { 200, 200, 50 };
+    private ResourceRepresentation  updatedRepresentation;
 
-    private List<PutPostAttributeModel> modelList      = null;
+    private final String[]          attTblHeaders  = { "Name", "Value",
+            "Select"                              };
+    private final Integer[]         attTblColWidth = { 200, 200, 50 };
 
-    public PostRequestDialog(Shell parentShell,
-            List<PutPostAttributeModel> modelList) {
+    public PostRequestDialog(Shell parentShell) {
         super(parentShell);
-        this.modelList = modelList;
     }
 
     @Override
@@ -89,270 +81,203 @@ public class PostRequestDialog extends TitleAreaDialog {
         layout.marginTop = 10;
         container.setLayout(layout);
 
-        createTableViewer(container);
-
-        attTblViewer.setInput(modelList.toArray());
+        createTreeViewer(container);
 
-        return compLayout;
-    }
+        RemoteResource resource = Activator.getDefault().getResourceManager()
+                .getCurrentResourceInSelection();
 
-    private void createTableViewer(Composite parent) {
-        attTblViewer = new TableViewer(parent, SWT.SINGLE | SWT.H_SCROLL
-                | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
+        updatedRepresentation = new ResourceRepresentation(
+                resource.getResourceModelRef());
 
-        createAttributeColumns(attTblViewer);
+        attViewer.setInput(updatedRepresentation);
 
-        // make lines and header visible
-        Table table = attTblViewer.getTable();
-        table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-        table.setHeaderVisible(true);
-        table.setLinesVisible(true);
-
-        attTblViewer.setContentProvider(new AttributeContentProvider());
+        return compLayout;
     }
 
-    public void createAttributeColumns(TableViewer tableViewer) {
-
-        // attributeEditor = new AttributeEditingSupport();
+    private void createTreeViewer(Composite parent) {
+        Tree addressTree = new Tree(parent, SWT.SINGLE | SWT.BORDER
+                | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
+        addressTree.setHeaderVisible(true);
 
-        TableViewerColumn attName = new TableViewerColumn(tableViewer, SWT.NONE);
-        attName.getColumn().setWidth(attTblColWidth[0]);
-        attName.getColumn().setText(attTblHeaders[0]);
-        attName.setLabelProvider(new StyledCellLabelProvider() {
-            @Override
-            public void update(ViewerCell cell) {
-                Object element = cell.getElement();
-                if (element instanceof PutPostAttributeModel) {
-                    PutPostAttributeModel entry = (PutPostAttributeModel) element;
-                    cell.setText(entry.getAttName());
-                }
-            }
-        });
-
-        TableViewerColumn attValue = new TableViewerColumn(tableViewer,
-                SWT.NONE);
-        attValue.getColumn().setWidth(attTblColWidth[1]);
-        attValue.getColumn().setText(attTblHeaders[1]);
-        attValue.setLabelProvider(new StyledCellLabelProvider() {
-            @Override
-            public void update(ViewerCell cell) {
-                Object element = cell.getElement();
-                if (element instanceof PutPostAttributeModel) {
-                    PutPostAttributeModel entry = (PutPostAttributeModel) element;
-                    cell.setText(entry.getAttValue());
-                }
-            }
-        });
-
-        attValue.setEditingSupport(new AttributeValueEditor(attTblViewer));
-
-        TableViewerColumn updateColumn = new TableViewerColumn(tableViewer,
-                SWT.NONE);
-        updateColumn.getColumn().setWidth(attTblColWidth[2]);
-        updateColumn.getColumn().setText(attTblHeaders[2]);
-        updateColumn.setLabelProvider(new ColumnLabelProvider() {
-            @Override
-            public String getText(Object element) {
-                return "";
-            }
+        attViewer = new TreeViewer(addressTree);
 
-            @Override
-            public Image getImage(Object element) {
-                PutPostAttributeModel model = (PutPostAttributeModel) element;
-                if (model.isModified()) {
-                    return Activator.getDefault().getImageRegistry()
-                            .get(Constants.CHECKED);
-                }
-                return Activator.getDefault().getImageRegistry()
-                        .get(Constants.UNCHECKED);
-            }
-        });
-        updateColumn.setEditingSupport(new UpdateEditor(attTblViewer));
-    }
+        createAttributeColumns(attViewer);
 
-    @Override
-    protected boolean isResizable() {
-        return true;
-    }
+        // make lines and header visible
+        Tree tree = attViewer.getTree();
+        tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+        tree.setHeaderVisible(true);
+        tree.setLinesVisible(true);
 
-    @Override
-    public boolean isHelpAvailable() {
-        return false;
+        attViewer.setContentProvider(new AttributeContentProvider());
+        attViewer.setLabelProvider(new AttributeLabelProvider());
     }
 
-    @Override
-    protected Button createButton(Composite parent, int id, String label,
-            boolean defaultButton) {
-        if (id == IDialogConstants.OK_ID) {
-            label = "POST";
-        }
-        return super.createButton(parent, id, label, defaultButton);
+    public void createAttributeColumns(TreeViewer viewer) {
+        Tree tree = viewer.getTree();
+
+        attributeEditor = new AttributeEditingSupport();
+
+        TreeColumn attName = new TreeColumn(tree, SWT.NONE);
+        attName.setWidth(attTblColWidth[0]);
+        attName.setText(attTblHeaders[0]);
+
+        TreeColumn attValue = new TreeColumn(tree, SWT.NONE);
+        attValue.setWidth(attTblColWidth[1]);
+        attValue.setText(attTblHeaders[1]);
+        TreeViewerColumn attValueVwrCol = new TreeViewerColumn(attViewer,
+                attValue);
+        attValueVwrCol.setEditingSupport(attributeEditor
+                .createAttributeValueEditor(attViewer, this));
+
+        TreeColumn updateColumn = new TreeColumn(tree, SWT.NONE);
+        updateColumn.setWidth(attTblColWidth[2]);
+        updateColumn.setText(attTblHeaders[2]);
+        TreeViewerColumn updateVwrCol = new TreeViewerColumn(attViewer,
+                updateColumn);
+        updateVwrCol.setEditingSupport(attributeEditor
+                .createAutomationEditor(attViewer));
     }
 
-    class AttributeContentProvider implements IStructuredContentProvider {
+    class AttributeContentProvider implements ITreeContentProvider {
 
         @Override
         public void dispose() {
         }
 
         @Override
-        public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
+        public void inputChanged(Viewer viewer, Object oldAttribute,
+                Object newAttribute) {
         }
 
         @Override
-        public Object[] getElements(Object element) {
-            return (Object[]) element;
-        }
-
-    }
-
-    class AttributeValueEditor extends EditingSupport {
-        private final TableViewer viewer;
-        private CCombo            comboBox;
+        public Object[] getChildren(Object attribute) {
+            if (attribute instanceof AttributeElement) {
+                return ((AttributeElement) attribute).getChildren().values()
+                        .toArray();
+            }
 
-        public AttributeValueEditor(TableViewer viewer) {
-            super(viewer);
-            this.viewer = viewer;
+            return new Object[0];
         }
 
         @Override
-        protected boolean canEdit(Object arg0) {
-            return true;
-        }
-
-        @Override
-        protected CellEditor getCellEditor(Object element) {
-            PutPostAttributeModel attributeInSelection = (PutPostAttributeModel) element;
-
-            String values[] = null;
-            List<String> valueSet = attributeInSelection.getValues();
-            values = convertListToStringArray(valueSet);
-
-            ComboBoxCellEditor comboEditor = new ComboBoxCellEditor(
-                    viewer.getTable(), values);
-            comboBox = (CCombo) comboEditor.getControl();
-            if (null != comboBox) {
-                comboBox.addModifyListener(new ModifyListener() {
-                    @Override
-                    public void modifyText(ModifyEvent e) {
-                        IStructuredSelection selection = (IStructuredSelection) AttributeValueEditor.this.viewer
-                                .getSelection();
-                        PutPostAttributeModel att = (PutPostAttributeModel) selection
-                                .getFirstElement();
-                        if (null == att) {
-                            return;
-                        }
-                        String newValue = comboBox.getText();
-                        if (null != newValue && !newValue.isEmpty()) {
-                            att.setModified(true);
-                        } else {
-                            att.setModified(false);
-                        }
-                        AttributeValueEditor.this.viewer.update(att, null);
-                    }
-                });
-            }
-            return comboEditor;
+        public Object getParent(Object attribute) {
+            if (attribute instanceof AttributeElement)
+                return ((AttributeElement) attribute).getParent();
+            return null;
         }
 
         @Override
-        protected Object getValue(Object element) {
-            int indexOfItem = 0;
-            PutPostAttributeModel att = (PutPostAttributeModel) element;
-            String valueString = att.getAttValue();
-            List<String> valueSet = att.getValues();
-            if (null != valueSet) {
-                indexOfItem = valueSet.indexOf(valueString);
-            }
-            if (indexOfItem == -1) {
-                indexOfItem = 0;
-            }
-            return indexOfItem;
+        public boolean hasChildren(Object attribute) {
+            if (attribute instanceof AttributeElement)
+                return ((AttributeElement) attribute).hasChildren();
+            return false;
         }
 
         @Override
-        protected void setValue(Object element, Object value) {
-            PutPostAttributeModel att = (PutPostAttributeModel) element;
-            int index;
-            try {
-                index = Integer.parseInt(String.valueOf(value));
-            } catch (NumberFormatException nfe) {
-                index = -1;
+        public Object[] getElements(Object resourceModel) {
+            if (resourceModel instanceof ResourceRepresentation) {
+                return ((ResourceRepresentation) resourceModel).getAttributes()
+                        .values().toArray();
             }
-            String newValue;
-            if (index == -1) {
-                newValue = comboBox.getText();
-                att.prependNewValue(newValue);
-            } else {
-                newValue = att.getValues().get(index);
-            }
-            att.setAttValue(newValue);
-            viewer.update(element, null);
-        }
 
-        public String[] convertListToStringArray(List<String> valueList) {
-            String[] strArr;
-            if (null != valueList && valueList.size() > 0) {
-                strArr = valueList.toArray(new String[1]);
-            } else {
-                strArr = new String[1];
-            }
-            return strArr;
+            return new Object[0];
         }
     }
 
-    class UpdateEditor extends EditingSupport {
+    class AttributeLabelProvider implements ITableLabelProvider {
 
-        private final TableViewer viewer;
+        @Override
+        public void addListener(ILabelProviderListener arg0) {
+        }
 
-        public UpdateEditor(TableViewer viewer) {
-            super(viewer);
-            this.viewer = viewer;
+        @Override
+        public void dispose() {
         }
 
         @Override
-        protected boolean canEdit(Object arg0) {
-            return true;
+        public boolean isLabelProperty(Object arg0, String arg1) {
+            return false;
         }
 
         @Override
-        protected CellEditor getCellEditor(Object element) {
-            return new CheckboxCellEditor(null, SWT.CHECK | SWT.READ_ONLY);
+        public void removeListener(ILabelProviderListener arg0) {
+
         }
 
         @Override
-        protected Object getValue(Object element) {
-            PutPostAttributeModel model = (PutPostAttributeModel) element;
-            return model.isModified();
+        public Image getColumnImage(Object element, int col) {
+            if (col == 2) {
+                if (element instanceof AttributeElement) {
+
+                    AttributeElement attrElement = (AttributeElement) element;
+                    if (attrElement.isPostSupported()) {
+                        if (attrElement.getPostState()) {
+                            return Activator.getDefault().getImageRegistry()
+                                    .get(Constants.CHECKED);
+                        } else {
+                            return Activator.getDefault().getImageRegistry()
+                                    .get(Constants.UNCHECKED);
+                        }
+                    }
+                }
+            }
+
+            return null;
         }
 
         @Override
-        protected void setValue(Object element, Object value) {
-            PutPostAttributeModel model = (PutPostAttributeModel) element;
-            boolean status = (Boolean) value;
-            model.setModified(status);
-            viewer.update(element, null);
+        public String getColumnText(Object element, int column) {
+            if (element instanceof AttributeElement) {
+                AttributeElement attrElement = (AttributeElement) element;
+                switch (column) {
+                    case 0: // Attribute name column
+                    {
+                        SimulatorResourceAttribute attribute = attrElement
+                                .getSimulatorResourceAttribute();
+                        return attribute.name();
+                    }
+
+                    case 1: // Attribute value column
+                    {
+                        SimulatorResourceAttribute attribute = attrElement
+                                .getSimulatorResourceAttribute();
+
+                        if (attribute.value().typeInfo().mBaseType != ValueType.RESOURCEMODEL)
+                            return Utility.getAttributeValueAsString(attribute
+                                    .value());
+                        return null;
+                    }
+
+                    case 2: {
+                        return "";
+                    }
+                }
+            }
+            return null;
         }
     }
 
     @Override
-    protected void okPressed() {
-        String value;
-        PutPostAttributeModel attModel;
-        Iterator<PutPostAttributeModel> itr;
-        itr = modelList.iterator();
-        while (itr.hasNext()) {
-            attModel = itr.next();
-            if (null == attModel) {
-                return;
-            }
-            value = attModel.getAttValue();
-            if (null == value || value.isEmpty()) {
-                MessageDialog.openError(Display.getDefault().getActiveShell(),
-                        "Empty value", "Attribute value should not be empty.");
-                return;
-            }
+    protected boolean isResizable() {
+        return true;
+    }
+
+    @Override
+    public boolean isHelpAvailable() {
+        return false;
+    }
+
+    @Override
+    protected Button createButton(Composite parent, int id, String label,
+            boolean defaultButton) {
+        if (id == IDialogConstants.OK_ID) {
+            label = "POST";
         }
-        close();
+        return super.createButton(parent, id, label, defaultButton);
+    }
+
+    public ResourceRepresentation getUpdatedRepresentation() {
+        return updatedRepresentation;
     }
 }
index 69dbeeb..12981f6 100644 (file)
 
 package oic.simulator.clientcontroller.view.dialogs;
 
-import java.util.Iterator;
-import java.util.List;
-
-import oic.simulator.clientcontroller.remoteresource.PutPostAttributeModel;
+import oic.simulator.clientcontroller.Activator;
+import oic.simulator.clientcontroller.remoteresource.AttributeElement;
+import oic.simulator.clientcontroller.remoteresource.RemoteResource;
+import oic.simulator.clientcontroller.remoteresource.ResourceRepresentation;
+import oic.simulator.clientcontroller.utils.Utility;
+import oic.simulator.clientcontroller.view.AttributeEditingSupport;
 
 import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.dialogs.TitleAreaDialog;
-import org.eclipse.jface.viewers.CellEditor;
-import org.eclipse.jface.viewers.ComboBoxCellEditor;
-import org.eclipse.jface.viewers.EditingSupport;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.StyledCellLabelProvider;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.TreeViewerColumn;
 import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerCell;
 import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.CCombo;
+import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeColumn;
+import org.oic.simulator.AttributeValue.ValueType;
+import org.oic.simulator.SimulatorResourceAttribute;
 
 /**
  * This dialog is used for generating a PUT request.
  */
 public class PutRequestDialog extends TitleAreaDialog {
 
-    private TableViewer                 attTblViewer;
+    private TreeViewer              attViewer;
+
+    private AttributeEditingSupport attributeEditor;
 
-    private final String[]              attTblHeaders  = { "Name", "Value" };
-    private final Integer[]             attTblColWidth = { 200, 200 };
+    private ResourceRepresentation  updatedRepresentation;
 
-    private List<PutPostAttributeModel> modelList      = null;
+    private final String[]          attTblHeaders  = { "Name", "Value" };
+    private final Integer[]         attTblColWidth = { 200, 200 };
 
-    public PutRequestDialog(Shell parentShell,
-            List<PutPostAttributeModel> modelList) {
+    public PutRequestDialog(Shell parentShell) {
         super(parentShell);
-        this.modelList = modelList;
     }
 
     @Override
@@ -79,155 +79,155 @@ public class PutRequestDialog extends TitleAreaDialog {
         layout.marginTop = 10;
         container.setLayout(layout);
 
-        createTableViewer(container);
+        createTreeViewer(container);
+
+        RemoteResource resource = Activator.getDefault().getResourceManager()
+                .getCurrentResourceInSelection();
 
-        attTblViewer.setInput(modelList.toArray());
+        updatedRepresentation = new ResourceRepresentation(
+                resource.getResourceModelRef());
+
+        attViewer.setInput(updatedRepresentation);
 
         return compLayout;
     }
 
-    private void createTableViewer(Composite parent) {
-        attTblViewer = new TableViewer(parent, SWT.SINGLE | SWT.H_SCROLL
-                | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
+    private void createTreeViewer(Composite parent) {
+        Tree addressTree = new Tree(parent, SWT.SINGLE | SWT.BORDER
+                | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
+        addressTree.setHeaderVisible(true);
+
+        attViewer = new TreeViewer(addressTree);
 
-        createAttributeColumns(attTblViewer);
+        createAttributeColumns(attViewer);
 
         // make lines and header visible
-        Table table = attTblViewer.getTable();
-        table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-        table.setHeaderVisible(true);
-        table.setLinesVisible(true);
+        Tree tree = attViewer.getTree();
+        tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+        tree.setHeaderVisible(true);
+        tree.setLinesVisible(true);
 
-        attTblViewer.setContentProvider(new AttributeContentProvider());
+        attViewer.setContentProvider(new AttributeContentProvider());
+        attViewer.setLabelProvider(new AttributeLabelProvider());
     }
 
-    public void createAttributeColumns(TableViewer tableViewer) {
-
-        TableViewerColumn attName = new TableViewerColumn(tableViewer, SWT.NONE);
-        attName.getColumn().setWidth(attTblColWidth[0]);
-        attName.getColumn().setText(attTblHeaders[0]);
-        attName.setLabelProvider(new StyledCellLabelProvider() {
-            @Override
-            public void update(ViewerCell cell) {
-                Object element = cell.getElement();
-                if (element instanceof PutPostAttributeModel) {
-                    PutPostAttributeModel entry = (PutPostAttributeModel) element;
-                    cell.setText(entry.getAttName());
-                }
-            }
-        });
-
-        TableViewerColumn attValue = new TableViewerColumn(tableViewer,
-                SWT.NONE);
-        attValue.getColumn().setWidth(attTblColWidth[1]);
-        attValue.getColumn().setText(attTblHeaders[1]);
-        attValue.setLabelProvider(new StyledCellLabelProvider() {
-            @Override
-            public void update(ViewerCell cell) {
-                Object element = cell.getElement();
-                if (element instanceof PutPostAttributeModel) {
-                    PutPostAttributeModel entry = (PutPostAttributeModel) element;
-                    cell.setText(entry.getAttValue());
-                }
-            }
-        });
-        attValue.setEditingSupport(new AttributeValueEditor(attTblViewer));
+    public void createAttributeColumns(TreeViewer viewer) {
+        Tree tree = viewer.getTree();
+
+        attributeEditor = new AttributeEditingSupport();
+
+        TreeColumn attName = new TreeColumn(tree, SWT.NONE);
+        attName.setWidth(attTblColWidth[0]);
+        attName.setText(attTblHeaders[0]);
+
+        TreeColumn attValue = new TreeColumn(tree, SWT.NONE);
+        attValue.setWidth(attTblColWidth[1]);
+        attValue.setText(attTblHeaders[1]);
+        TreeViewerColumn attValueVwrCol = new TreeViewerColumn(attViewer,
+                attValue);
+        attValueVwrCol.setEditingSupport(attributeEditor
+                .createAttributeValueEditor(attViewer, this));
     }
 
-    class AttributeContentProvider implements IStructuredContentProvider {
+    class AttributeContentProvider implements ITreeContentProvider {
 
         @Override
         public void dispose() {
         }
 
         @Override
-        public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
+        public void inputChanged(Viewer viewer, Object oldAttribute,
+                Object newAttribute) {
         }
 
         @Override
-        public Object[] getElements(Object element) {
-            return (Object[]) element;
+        public Object[] getChildren(Object attribute) {
+            if (attribute instanceof AttributeElement) {
+                return ((AttributeElement) attribute).getChildren().values()
+                        .toArray();
+            }
+
+            return new Object[0];
         }
-    }
 
-    class AttributeValueEditor extends EditingSupport {
-        private final TableViewer viewer;
-        private CCombo            comboBox;
+        @Override
+        public Object getParent(Object attribute) {
+            if (attribute instanceof AttributeElement)
+                return ((AttributeElement) attribute).getParent();
+            return null;
+        }
 
-        public AttributeValueEditor(TableViewer viewer) {
-            super(viewer);
-            this.viewer = viewer;
+        @Override
+        public boolean hasChildren(Object attribute) {
+            if (attribute instanceof AttributeElement)
+                return ((AttributeElement) attribute).hasChildren();
+            return false;
         }
 
         @Override
-        protected boolean canEdit(Object arg0) {
-            return true;
+        public Object[] getElements(Object resourceModel) {
+            if (resourceModel instanceof ResourceRepresentation) {
+                return ((ResourceRepresentation) resourceModel).getAttributes()
+                        .values().toArray();
+            }
+
+            return new Object[0];
         }
+    }
+
+    class AttributeLabelProvider implements ITableLabelProvider {
 
         @Override
-        protected CellEditor getCellEditor(Object element) {
-            PutPostAttributeModel attributeInSelection = (PutPostAttributeModel) element;
+        public void addListener(ILabelProviderListener arg0) {
+        }
 
-            String values[] = null;
-            List<String> valueSet = attributeInSelection.getValues();
-            values = convertListToStringArray(valueSet);
+        @Override
+        public void dispose() {
+        }
 
-            ComboBoxCellEditor comboEditor = new ComboBoxCellEditor(
-                    viewer.getTable(), values);
-            comboBox = (CCombo) comboEditor.getControl();
-            return comboEditor;
+        @Override
+        public boolean isLabelProperty(Object arg0, String arg1) {
+            return false;
         }
 
         @Override
-        protected Object getValue(Object element) {
-            int indexOfItem = 0;
-            PutPostAttributeModel att = (PutPostAttributeModel) element;
-            String valueString = att.getAttValue();
-            List<String> valueSet = att.getValues();
-            if (null != valueSet) {
-                indexOfItem = valueSet.indexOf(valueString);
-            }
-            if (indexOfItem == -1) {
-                indexOfItem = 0;
-            }
-            return indexOfItem;
+        public void removeListener(ILabelProviderListener arg0) {
+
         }
 
         @Override
-        protected void setValue(Object element, Object value) {
-            PutPostAttributeModel att = (PutPostAttributeModel) element;
-            int index;
-            try {
-                index = Integer.parseInt(String.valueOf(value));
-            } catch (NumberFormatException nfe) {
-                index = -1;
-            }
-            if (index == -1) {
-                String customValue = comboBox.getText();
-                att.prependNewValue(customValue);
-                att.setAttValue(customValue);
-            } else {
-                String attValue = att.getValues().get(index);
-                att.setAttValue(attValue);
-            }
-            viewer.update(element, null);
+        public Image getColumnImage(Object element, int col) {
+            return null;
         }
 
-        public String[] convertListToStringArray(List<String> valueList) {
-            String[] strArr;
-            if (null != valueList && valueList.size() > 0) {
-                strArr = valueList.toArray(new String[1]);
-            } else {
-                strArr = new String[1];
+        @Override
+        public String getColumnText(Object element, int column) {
+            if (element instanceof AttributeElement) {
+                AttributeElement attrElement = (AttributeElement) element;
+                switch (column) {
+                    case 0: // Attribute name column
+                    {
+                        SimulatorResourceAttribute attribute = attrElement
+                                .getSimulatorResourceAttribute();
+                        return attribute.name();
+                    }
+
+                    case 1: // Attribute value column
+                    {
+                        SimulatorResourceAttribute attribute = attrElement
+                                .getSimulatorResourceAttribute();
+
+                        if (attribute.value().typeInfo().mBaseType != ValueType.RESOURCEMODEL)
+                            return Utility.getAttributeValueAsString(attribute
+                                    .value());
+                        return null;
+                    }
+                }
             }
-            return strArr;
+            return null;
         }
     }
 
-    public List<PutPostAttributeModel> getUpdatedModel() {
-        return modelList;
-    }
-
     @Override
     protected boolean isResizable() {
         return true;
@@ -247,24 +247,8 @@ public class PutRequestDialog extends TitleAreaDialog {
         return super.createButton(parent, id, label, defaultButton);
     }
 
-    @Override
-    protected void okPressed() {
-        String value;
-        PutPostAttributeModel attModel;
-        Iterator<PutPostAttributeModel> itr;
-        itr = modelList.iterator();
-        while (itr.hasNext()) {
-            attModel = itr.next();
-            if (null == attModel) {
-                return;
-            }
-            value = attModel.getAttValue();
-            if (null == value || value.isEmpty()) {
-                MessageDialog.openError(Display.getDefault().getActiveShell(),
-                        "Empty value", "Attribute value should not be empty.");
-                return;
-            }
-        }
-        close();
+    public ResourceRepresentation getUpdatedRepresentation() {
+        return updatedRepresentation;
     }
+
 }
index 3e80941..d7a8e20 100644 (file)
@@ -27,18 +27,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.Vector;
 
-import oic.simulator.serviceprovider.Activator;
-import oic.simulator.serviceprovider.model.CollectionResource;
-import oic.simulator.serviceprovider.model.Device;
-import oic.simulator.serviceprovider.model.LocalResourceAttribute;
-import oic.simulator.serviceprovider.model.MetaProperty;
-import oic.simulator.serviceprovider.model.Resource;
-import oic.simulator.serviceprovider.model.ResourceType;
-import oic.simulator.serviceprovider.model.SRMItem;
-import oic.simulator.serviceprovider.model.SingleResource;
-import oic.simulator.serviceprovider.utils.Constants;
-import oic.simulator.serviceprovider.utils.Utility;
-
+import org.eclipse.swt.widgets.Display;
 import org.oic.simulator.AttributeProperty;
 import org.oic.simulator.AttributeProperty.Type;
 import org.oic.simulator.AttributeValue;
@@ -59,6 +48,19 @@ import org.oic.simulator.server.SimulatorResource.ObserverListener;
 import org.oic.simulator.server.SimulatorResource.ResourceModelChangeListener;
 import org.oic.simulator.server.SimulatorSingleResource;
 
+import oic.simulator.serviceprovider.Activator;
+import oic.simulator.serviceprovider.model.AttributeElement;
+import oic.simulator.serviceprovider.model.CollectionResource;
+import oic.simulator.serviceprovider.model.Device;
+import oic.simulator.serviceprovider.model.LocalResourceAttribute;
+import oic.simulator.serviceprovider.model.MetaProperty;
+import oic.simulator.serviceprovider.model.Resource;
+import oic.simulator.serviceprovider.model.ResourceType;
+import oic.simulator.serviceprovider.model.SRMItem;
+import oic.simulator.serviceprovider.model.SingleResource;
+import oic.simulator.serviceprovider.utils.Constants;
+import oic.simulator.serviceprovider.utils.Utility;
+
 /**
  * This class acts as an interface between the simulator java SDK and the
  * various UI modules. It maintains all the details of resources and provides
@@ -141,27 +143,16 @@ public class ResourceManager {
                             return;
                         }
 
-                        Resource resource = data.getResourceByURI(resourceURI);
-                        if (null == resource) {
-                            return;
-                        }
-
-                        resource.setResourceModel(resourceModelN);
-
-                        // 7. Fetch the resource attributes.
-                        Map<String, LocalResourceAttribute> resourceAttributeMap;
-                        try {
-                            resourceAttributeMap = fetchResourceAttributesFromModel(resourceModelN);
-                            if (null != resourceAttributeMap) {
-                                resource.setResourceAttributes(resourceAttributeMap);
+                        Display.getDefault().asyncExec(new Runnable() {
+                            @Override
+                            public void run() {
+                                Resource resource = data
+                                        .getResourceByURI(resourceURI);
+                                if (null != resource) {
+                                    resource.setResourceRepresentation(resourceModelN);
+                                }
                             }
-                        } catch (SimulatorException e) {
-                            // TODO Auto-generated catch block
-                            e.printStackTrace();
-                        }
-
-                        UiListenerHandler.getInstance()
-                                .resourceModelChangedUINotification(resource);
+                        });
                     }
                 });
             }
@@ -191,20 +182,24 @@ public class ResourceManager {
                                             null);
                         } else if (resource.isAttributeAutomationInProgress()) {
                             // Find the attribute with the given automation id
-                            LocalResourceAttribute attribute;
-                            attribute = getAttributeWithGivenAutomationId(
+                            final AttributeElement attribute = getAttributeWithGivenAutomationId(
                                     resource, automationId);
                             if (null != attribute) {
-                                attribute.setAutomationInProgress(false);
+                                // Display.getDefault().asyncExec(new Runnable()
+                                // {
+                                // @Override
+                                // public void run() {
+                                attribute.setAutoUpdateState(false);
+                                // }
+                                // });
                                 resource.setAttributeAutomationInProgress(isAnyAttributeInAutomation(resource));
                                 // Notify the UI listeners
-                                UiListenerHandler
-                                        .getInstance()
-                                        .automationCompleteUINotification(
-                                                resource,
-                                                attribute
-                                                        .getResourceAttributeRef()
-                                                        .name());
+                                /*
+                                 * UiListenerHandler .getInstance()
+                                 * .automationCompleteUINotification( resource,
+                                 * attribute
+                                 * .getSimulatorResourceAttribute().name());
+                                 */
                             } else {
                                 // TODO: Temporarily reset the attribute
                                 // automation status to false for making
@@ -484,6 +479,8 @@ public class ResourceManager {
                 // 6. Get the resource model java object reference.
                 resource.setResourceModel(jSimulatorSingleResource
                         .getResourceModel());
+
+                resource.setResourceRepresentation(resource.getResourceModel());
             }
 
             // 7. Register the resource with the platform.
@@ -541,6 +538,10 @@ public class ResourceManager {
             jSimulatorCollectionResource
                     .setResourceModelChangeListener(resourceModelChangeListener);
 
+            // set resource model
+            resource.setResourceRepresentation(jSimulatorCollectionResource
+                    .getResourceModel());;
+
             // 5. Register the resource with the platform.
             jSimulatorCollectionResource.start();
             resource.setStarted(true);
@@ -673,6 +674,8 @@ public class ResourceManager {
             jSimulatorSingleResource.start();
             singleRes.setStarted(true);
 
+            singleRes.setResourceRepresentation(jResModel);
+
             // 7. Fetch the resource attributes.
             Map<String, LocalResourceAttribute> resourceAttributeMap;
             resourceAttributeMap = fetchResourceAttributesFromModel(jResModel);
@@ -761,6 +764,8 @@ public class ResourceManager {
             jSimulatorCollectionResource.start();
             collectionRes.setStarted(true);
 
+            collectionRes.setResourceRepresentation(jResModel);
+
             // 7. Fetch the resource attributes.
             Map<String, LocalResourceAttribute> resourceAttributeMap;
             resourceAttributeMap = fetchResourceAttributesFromModel(jResModel);
@@ -1475,107 +1480,6 @@ public class ResourceManager {
         return Utility.getCollectionResourceListFromSet(childs);
     }
 
-    /*
-     * public void deleteResourceByURI(String resourceURI) { if (null !=
-     * resourceURI) { Resource resource =
-     * getSimulatorResourceByURI(resourceURI); if (null != resource) { //
-     * Unregister the resource from the platform deleteResource(resource);
-     * 
-     * // Delete from the local data structure deleteLocalResourceDetails(null,
-     * resourceURI);
-     * 
-     * // Notify the UI listener for removing this resource // from UI //
-     * resourceDeletedUINotification(); if (resource ==
-     * getCurrentResourceInSelection()) { // Listeners might query the resource
-     * being deleted // if exists. So set the currently selection to // null.
-     * setCurrentResourceInSelection(null);
-     * 
-     * // Notify all observers for resource selection // change event //
-     * resourceSelectionChangedUINotification(); } } } }
-     * 
-     * private SingleResource getSimulatorResourceByURI(String resourceURI) {
-     * SingleResource resource = null; if (null != resourceURI) { synchronized
-     * (resourceMap) { resource = resourceMap.get(resourceURI); } } return
-     * resource; }
-     * 
-     * private void deleteResource(SingleResource resource) { if (null !=
-     * resource) { SimulatorResourceServer resourceServerN = resource
-     * .getResourceServer(); if (null != resourceServerN) { try {
-     * SimulatorManager.deleteResource(resourceServerN); } catch
-     * (SimulatorException e) { Activator .getDefault() .getLogManager()
-     * .log(Level.ERROR.ordinal(), new Date(),
-     * Utility.getSimulatorErrorString(e, null)); } } } }
-     * 
-     * public void deleteResourceByType(final String resourceType) {
-     * System.out.println(resourceType + "to be deleted."); if (null !=
-     * resourceType) { new Thread() {
-     * 
-     * @Override public void run() { // Unregister the resources from the
-     * platform deleteResource(resourceType);
-     * 
-     * // Delete from the local data structure
-     * deleteLocalResourceDetails(resourceType, null);
-     * 
-     * // Notify the UI listener for removing this resource from UI
-     * resourceDeletedUINotification();
-     * 
-     * if (null != currentResourceInSelection &&
-     * currentResourceInSelection.getResourceTypes() .contains(resourceType)) {
-     * // Listeners might query the resource being deleted if // exists. So set
-     * the currently selection to null. setCurrentResourceInSelection(null);
-     * 
-     * // Notify all observers for resource selection change // event
-     * resourceSelectionChangedUINotification(null); } } }.start(); } }
-     * 
-     * private void deleteResource(String resourceType) { if (null !=
-     * resourceType) { try { SimulatorManager.deleteResources(resourceType); }
-     * catch (SimulatorException e) { Activator .getDefault() .getLogManager()
-     * .log(Level.ERROR.ordinal(), new Date(),
-     * Utility.getSimulatorErrorString(e, null)); } } }
-     * 
-     * public void deleteAllResources() { new Thread() {
-     * 
-     * @Override public void run() { // Unregister the resources from the
-     * platform deleteResource();
-     * 
-     * // Delete from the local data structure deleteLocalResourceDetails(null,
-     * null);
-     * 
-     * // Notify the UI listener for removing this resource from UI
-     * resourceDeletedUINotification();
-     * 
-     * // Listeners might query the resource being deleted if exists. // So set
-     * the currently selection to null. setCurrentResourceInSelection(null);
-     * 
-     * // Notify all observers for resource selection change event
-     * resourceSelectionChangedUINotification(null); } }.start(); }
-     * 
-     * private void deleteResource() { try {
-     * SimulatorManager.deleteResources(null); } catch (SimulatorException e) {
-     * Activator .getDefault() .getLogManager() .log(Level.ERROR.ordinal(), new
-     * Date(), Utility.getSimulatorErrorString(e, null)); } }
-     * 
-     * private void deleteLocalResourceDetails(String resourceType, String
-     * resourceURI) { synchronized (resourceMap) { if (null == resourceType &&
-     * null == resourceURI) { resourceMap.clear(); } else if (null !=
-     * resourceType) { Set<String> uriSet = resourceMap.keySet(); if (null ==
-     * uriSet) { return; } String uri; SingleResource simpleRes;
-     * Iterator<String> uriItr = uriSet.iterator(); while (uriItr.hasNext()) {
-     * uri = uriItr.next(); simpleRes = resourceMap.get(uri); if
-     * (simpleRes.getResourceTypes().contains(resourceType)) { uriItr.remove();
-     * } } } else { removeResourceFromMap(resourceURI); } } }
-     * 
-     * 
-     * 
-     * public Set<String> getResourceTypeList() { Set<String> types = null;
-     * synchronized (resourceMap) { if (resourceMap.size() > 0) { types = new
-     * TreeSet<String>(); Set<String> typeSet = resourceMap.keySet();
-     * Iterator<String> typeItr = typeSet.iterator(); SingleResource resource;
-     * while (typeItr.hasNext()) { resource = resourceMap.get(typeItr.next());
-     * Set<String> subTypes = resource.getResourceTypes();
-     * types.addAll(subTypes); } } } return types; }
-     */
-
     public void resourceSelectionChanged(final Resource selectedResource) {
         new Thread() {
             @Override
@@ -1932,51 +1836,6 @@ public class ResourceManager {
         }
     }
 
-    /*
-     * private ModelChangeNotificationType compareAndUpdateLocalAttributes(
-     * Map<String, LocalResourceAttribute> resourceAttributeMapOld, Map<String,
-     * LocalResourceAttribute> resourceAttributeMapNew,
-     * Set<LocalResourceAttribute> valueChangeSet) { ModelChangeNotificationType
-     * notificationType = ModelChangeNotificationType.NONE; if (null !=
-     * resourceAttributeMapOld && null != resourceAttributeMapNew) { Set<String>
-     * oldMapKeySet = resourceAttributeMapOld.keySet(); Iterator<String>
-     * attributeMapOldItr = oldMapKeySet.iterator(); String attName;
-     * LocalResourceAttribute attributeOld; LocalResourceAttribute attributeNew;
-     * Object attValueOld; Object attValueNew; String oldValueStr; String
-     * newValueStr; while (attributeMapOldItr.hasNext()) { attName =
-     * attributeMapOldItr.next(); if
-     * (resourceAttributeMapNew.containsKey(attName)) { attributeOld =
-     * resourceAttributeMapOld.get(attName); attributeNew =
-     * resourceAttributeMapNew.get(attName); // Copy the attribute value from
-     * new to old if the value // has been changed // Comparing only the
-     * attribute's value considering the // fact that only the value can be
-     * changed if (null != attributeOld && null != attributeNew) { attValueOld =
-     * attributeOld.getAttributeValue(); attValueNew =
-     * attributeNew.getAttributeValue();
-     * 
-     * oldValueStr = String.valueOf(attValueOld); newValueStr =
-     * String.valueOf(attValueNew);
-     * 
-     * if (null != oldValueStr && null != newValueStr) { if
-     * (!oldValueStr.equals(newValueStr)) {
-     * attributeOld.setAttributeValue(attValueNew); notificationType =
-     * ModelChangeNotificationType.ATTRIBUTE_VALUE_CHANGED;
-     * valueChangeSet.add(attributeOld); } } }
-     * resourceAttributeMapNew.remove(attName); } else { // Attribute doesn't
-     * exist in the new model. Hence // removing it from the model.
-     * resourceAttributeMapOld.remove(attName); notificationType =
-     * ModelChangeNotificationType.ATTRIBUTE_REMOVED; } } // Check for new
-     * attributes in the new model if (resourceAttributeMapNew.size() > 0) {
-     * Set<String> remainingAttSet = resourceAttributeMapNew.keySet();
-     * Iterator<String> remainingAttItr = remainingAttSet.iterator();
-     * LocalResourceAttribute attribute; while (remainingAttItr.hasNext()) {
-     * attName = remainingAttItr.next(); if (null != attName) { attribute =
-     * resourceAttributeMapNew.get(attName); if (null != attribute) {
-     * resourceAttributeMapOld.put(attName, attribute); } } } notificationType =
-     * ModelChangeNotificationType.ATTRIBUTE_ADDED; } } return notificationType;
-     * }
-     */
-
     // TODO: This method should get the status from the native layer.
     public boolean isResourceStarted(Resource resource) {
         if (null == resource) {
@@ -2170,14 +2029,15 @@ public class ResourceManager {
     }
 
     public int startAutomation(SingleResource resource,
-            LocalResourceAttribute attribute, AutoUpdateType autoType,
+            AttributeElement attribute, AutoUpdateType autoType,
             int autoUpdateInterval) {
         int autoId = -1;
         if (null != resource && null != attribute) {
             SimulatorSingleResource server = (SimulatorSingleResource) resource
                     .getSimulatorResource();
             if (null != server) {
-                String attrName = attribute.getResourceAttributeRef().name();
+                String attrName = attribute.getSimulatorResourceAttribute()
+                        .name();
                 try {
                     autoId = server.startAttributeUpdation(attrName, autoType,
                             autoUpdateInterval, automationListener);
@@ -2193,21 +2053,19 @@ public class ResourceManager {
                     return -1;
                 }
                 if (-1 != autoId) {
-                    attribute.setAutomationId(autoId);
-                    attribute.setAutomationType(autoType);
-                    attribute.setAutomationUpdateInterval(autoUpdateInterval);
-                    attribute.setAutomationInProgress(true);
+                    attribute.setAutoUpdateId(autoId);
+                    attribute.setAutoUpdateType(autoType);
+                    attribute.setAutoUpdateInterval(autoUpdateInterval);
+                    attribute.setAutoUpdateState(true);
                     resource.setAttributeAutomationInProgress(true);
-                } else {
-                    attribute.setAutomationInProgress(false);
                 }
             }
         }
         return autoId;
     }
 
-    public void stopAutomation(SingleResource resource,
-            LocalResourceAttribute att, int autoId) {
+    public void stopAutomation(SingleResource resource, AttributeElement att,
+            int autoId) {
         if (null != resource) {
             SimulatorSingleResource server = (SimulatorSingleResource) resource
                     .getSimulatorResource();
@@ -2226,7 +2084,7 @@ public class ResourceManager {
                     return;
                 }
                 // Change the automation status
-                att.setAutomationInProgress(false);
+                att.setAutoUpdateState(false);
                 resource.setAttributeAutomationInProgress(isAnyAttributeInAutomation(resource));
             }
         }
@@ -2317,76 +2175,60 @@ public class ResourceManager {
     }
 
     private boolean isAnyAttributeInAutomation(SingleResource resource) {
-        if (null == resource) {
+        if (null == resource || null == resource.getResourceRepresentation()) {
             return false;
         }
-        Map<String, LocalResourceAttribute> attMap = resource
-                .getResourceAttributes();
-        if (null == attMap) {
+
+        Map<String, AttributeElement> attributes = resource
+                .getResourceRepresentation().getAttributes();
+        if (null == attributes || 0 == attributes.size())
             return false;
+
+        for (Map.Entry<String, AttributeElement> entry : attributes.entrySet()) {
+            if (entry.getValue().isAutoUpdateInProgress())
+                return true;
         }
-        boolean status = false;
-        Set<String> keySet = attMap.keySet();
-        Iterator<String> attItr = keySet.iterator();
-        while (attItr.hasNext()) {
-            LocalResourceAttribute attribute = attMap.get(attItr.next());
-            if (attribute.isAutomationInProgress()) {
-                status = true;
-                break;
-            }
-        }
-        return status;
+
+        return false;
     }
 
     // Changes the automation state of the resource and its attributes
     private void changeResourceLevelAutomationStatus(SingleResource resource,
             boolean status) {
 
-        Map<String, LocalResourceAttribute> attributeMap = resource
-                .getResourceAttributes();
-        if (null != attributeMap) {
-            Set<String> attrNameSet = attributeMap.keySet();
-            Iterator<String> attrNameItr = attrNameSet.iterator();
-            String attrName;
-            LocalResourceAttribute attribute;
-            while (attrNameItr.hasNext()) {
-                attrName = attrNameItr.next();
-                attribute = attributeMap.get(attrName);
-                if (null != attribute) {
-                    attribute.setAutomationInProgress(status);
-                }
-            }
+        if (null == resource || null == resource.getResourceRepresentation()) {
+            return;
+        }
+
+        Map<String, AttributeElement> attributes = resource
+                .getResourceRepresentation().getAttributes();
+        if (null == attributes || 0 == attributes.size())
+            return;
+
+        for (Map.Entry<String, AttributeElement> entry : attributes.entrySet()) {
+            entry.getValue().setAutoUpdateState(status);
         }
+
         resource.setResourceAutomationInProgress(status);
     }
 
-    private LocalResourceAttribute getAttributeWithGivenAutomationId(
+    private AttributeElement getAttributeWithGivenAutomationId(
             SingleResource resource, int automationId) {
-        LocalResourceAttribute targetAttribute = null;
-        if (null != resource) {
-            Map<String, LocalResourceAttribute> attributeMap = resource
-                    .getResourceAttributes();
-            if (null != attributeMap) {
-                Set<String> attNameSet = attributeMap.keySet();
-                Iterator<String> attNameItr = attNameSet.iterator();
-                String attName;
-                LocalResourceAttribute attribute;
-                while (attNameItr.hasNext()) {
-                    attName = attNameItr.next();
-                    if (null != attName) {
-                        attribute = attributeMap.get(attName);
-                        if (null != attribute) {
-                            if (attribute.isAutomationInProgress()
-                                    && (attribute.getAutomationId() == automationId)) {
-                                targetAttribute = attribute;
-                                break;
-                            }
-                        }
-                    }
-                }
-            }
+        if (null == resource || null == resource.getResourceRepresentation()) {
+            return null;
+        }
+
+        Map<String, AttributeElement> attributes = resource
+                .getResourceRepresentation().getAttributes();
+        if (null == attributes || 0 == attributes.size())
+            return null;
+
+        for (Map.Entry<String, AttributeElement> entry : attributes.entrySet()) {
+            if (automationId == entry.getValue().getAutoUpdateId())
+                return entry.getValue();
         }
-        return targetAttribute;
+
+        return null;
     }
 
     public boolean isResourceAutomationStarted(SingleResource resource) {
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/AttributeElement.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/AttributeElement.java
new file mode 100644 (file)
index 0000000..4c493a2
--- /dev/null
@@ -0,0 +1,278 @@
+package oic.simulator.serviceprovider.model;
+
+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;
+import org.oic.simulator.server.SimulatorResource.AutoUpdateType;
+
+import oic.simulator.serviceprovider.utils.AttributeValueStringConverter;
+import oic.simulator.serviceprovider.utils.Constants;
+
+public class AttributeElement {
+    private Object                        mParent             = null;
+    private SimulatorResourceAttribute    mAttribute          = null;
+    private Map<String, AttributeElement> mChildAttributes    = new HashMap<String, AttributeElement>();
+    private DataChangeListener            mListener           = null;
+    private boolean                       mAutoUpdateSupport  = false;
+    private int                           mAutoUpdateId       = -1;
+    private boolean                       mAutoUpdateState    = false;
+    private int                           mAutoUpdateInterval = Constants.DEFAULT_AUTOMATION_INTERVAL;
+    private AutoUpdateType                mAutoUpdateType     = Constants.DEFAULT_AUTOMATION_TYPE;
+
+    public AttributeElement(Object parent,
+            SimulatorResourceAttribute attribute, boolean autoUpdateSupport) {
+        mParent = parent;
+        mAttribute = attribute;
+        mAutoUpdateSupport = autoUpdateSupport;
+        AttributeValue.TypeInfo typeInfo = attribute.value().typeInfo();
+        if (typeInfo.mType == AttributeValue.ValueType.RESOURCEMODEL) {
+            mAutoUpdateSupport = false;
+            SimulatorResourceModel resModel = (SimulatorResourceModel) attribute
+                    .value().get();
+            for (Map.Entry<String, SimulatorResourceAttribute> entrySet : resModel
+                    .getAttributes().entrySet())
+                mChildAttributes.put(entrySet.getKey(), new AttributeElement(
+                        this, entrySet.getValue(), false));
+        } else if (typeInfo.mType == AttributeValue.ValueType.ARRAY) {
+            mAutoUpdateSupport = false;
+            if (typeInfo.mBaseType == AttributeValue.ValueType.RESOURCEMODEL) {
+                if (typeInfo.mDepth == 1) {
+                    SimulatorResourceModel[] resModelArray = (SimulatorResourceModel[]) attribute
+                            .value().get();
+                    for (int i = 0; i < resModelArray.length; i++) {
+                        SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
+                                "[" + Integer.toString(i) + "]",
+                                new AttributeValue(resModelArray[i]), null);
+                        mChildAttributes.put("[" + Integer.toString(i) + "]",
+                                new AttributeElement(this, indexAttribute,
+                                        false));
+                    }
+                } else if (typeInfo.mDepth == 2) {
+                    SimulatorResourceModel[][] resModelArray = (SimulatorResourceModel[][]) attribute
+                            .value().get();
+                    for (int i = 0; i < resModelArray.length; i++) {
+                        SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
+                                "[" + Integer.toString(i) + "]",
+                                new AttributeValue(resModelArray[i]), null);
+                        mChildAttributes.put("[" + Integer.toString(i) + "]",
+                                new AttributeElement(this, indexAttribute,
+                                        false));
+                    }
+                } else if (typeInfo.mDepth == 3) {
+                    SimulatorResourceModel[][][] resModelArray = (SimulatorResourceModel[][][]) attribute
+                            .value().get();
+                    for (int i = 0; i < resModelArray.length; i++) {
+                        SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
+                                "[" + Integer.toString(i) + "]",
+                                new AttributeValue(resModelArray[i]), null);
+                        mChildAttributes.put("[" + Integer.toString(i) + "]",
+                                new AttributeElement(this, indexAttribute,
+                                        false));
+                    }
+                }
+            }
+        }
+    }
+
+    public Object getParent() {
+        return mParent;
+    }
+
+    public boolean hasChildren() {
+        if (mChildAttributes != null && mChildAttributes.size() > 0)
+            return true;
+        return false;
+    }
+
+    public Map<String, AttributeElement> getChildren() {
+        if (hasChildren() == true)
+            return mChildAttributes;
+        return null;
+    }
+
+    public SimulatorResourceAttribute getSimulatorResourceAttribute() {
+        return mAttribute;
+    }
+
+    public int getAutoUpdateId() {
+        return mAutoUpdateId;
+    }
+
+    public void setAutoUpdateId(int id) {
+        mAutoUpdateId = id;
+    }
+
+    public boolean isAutoUpdateInProgress() {
+        return mAutoUpdateState;
+    }
+
+    public void setAutoUpdateState(boolean state) {
+        if (mAutoUpdateState != state) {
+            mAutoUpdateState = state;
+            if (mListener != null)
+                mListener.update(this);
+        }
+    }
+
+    public int getAutoUpdateInterval() {
+        return mAutoUpdateInterval;
+    }
+
+    public void setAutoUpdateInterval(int interval) {
+        mAutoUpdateInterval = interval;
+    }
+
+    public AutoUpdateType getAutoUpdateType() {
+        return mAutoUpdateType;
+    }
+
+    public void setAutoUpdateType(AutoUpdateType type) {
+        mAutoUpdateType = type;
+    }
+
+    public boolean isAutoUpdateSupport() {
+        return mAutoUpdateSupport;
+    }
+
+    public boolean isReadOnly() {
+        return (null == mAttribute.property());
+    }
+
+    public void setListener(DataChangeListener listener) {
+        mListener = listener;
+        for (Map.Entry<String, AttributeElement> entry : mChildAttributes
+                .entrySet())
+            entry.getValue().setListener(listener);
+    }
+
+    public DataChangeListener getListener() {
+        return mListener;
+    }
+
+    public void update(SimulatorResourceAttribute attribute) {
+        if (attribute == null)
+            return;
+
+        AttributeValue.TypeInfo typeInfo = attribute.value().typeInfo();
+        if (typeInfo.mType == AttributeValue.ValueType.RESOURCEMODEL) {
+            SimulatorResourceModel resModel = (SimulatorResourceModel) attribute
+                    .value().get();
+            for (Map.Entry<String, SimulatorResourceAttribute> entry : resModel
+                    .getAttributes().entrySet()) {
+                AttributeElement attributeElement = mChildAttributes.get(entry
+                        .getKey());
+                if (attributeElement != null) {
+                    attributeElement.update(entry.getValue());
+                } else // Display new attribute in UI
+                {
+                    AttributeElement newAttribute = new AttributeElement(this,
+                            entry.getValue(), false);
+                    mChildAttributes.put(entry.getKey(), newAttribute);
+                    if (mListener != null)
+                        mListener.add(newAttribute);
+                }
+            }
+        } else if (typeInfo.mType == AttributeValue.ValueType.ARRAY
+                && typeInfo.mBaseType == AttributeValue.ValueType.RESOURCEMODEL) {
+            if (typeInfo.mDepth == 1) {
+                SimulatorResourceModel[] resModelArray = (SimulatorResourceModel[]) attribute
+                        .value().get();
+                for (int i = 0; i < resModelArray.length; i++) {
+                    SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
+                            "[" + Integer.toString(i) + "]",
+                            new AttributeValue(resModelArray[i]), null);
+                    AttributeElement attributeElement = mChildAttributes
+                            .get("[" + Integer.toString(i) + "]");
+                    if (attributeElement != null) {
+                        attributeElement.update(indexAttribute);
+                    } else // Display new attribute in UI
+                    {
+                        AttributeElement newAttribute = new AttributeElement(
+                                this, indexAttribute, false);
+                        mChildAttributes.put("[" + Integer.toString(i) + "]",
+                                newAttribute);
+                        if (mListener != null)
+                            mListener.add(newAttribute);
+                    }
+                }
+            }
+            if (typeInfo.mDepth == 2) {
+                SimulatorResourceModel[][] resModelArray = (SimulatorResourceModel[][]) attribute
+                        .value().get();
+                for (int i = 0; i < resModelArray.length; i++) {
+                    SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
+                            "[" + Integer.toString(i) + "]",
+                            new AttributeValue(resModelArray[i]), null);
+                    AttributeElement attributeElement = mChildAttributes
+                            .get("[" + Integer.toString(i) + "]");
+                    if (attributeElement != null) {
+                        attributeElement.update(indexAttribute);
+                    } else // Display new attribute in UI
+                    {
+                        AttributeElement newAttribute = new AttributeElement(
+                                this, indexAttribute, false);
+                        mChildAttributes.put("[" + Integer.toString(i) + "]",
+                                newAttribute);
+                        if (mListener != null)
+                            mListener.add(newAttribute);
+                    }
+                }
+            }
+            if (typeInfo.mDepth == 3) {
+                SimulatorResourceModel[][][] resModelArray = (SimulatorResourceModel[][][]) attribute
+                        .value().get();
+                for (int i = 0; i < resModelArray.length; i++) {
+                    SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
+                            "[" + Integer.toString(i) + "]",
+                            new AttributeValue(resModelArray[i]), null);
+                    AttributeElement attributeElement = mChildAttributes
+                            .get("[" + Integer.toString(i) + "]");
+                    if (attributeElement != null) {
+                        attributeElement.update(indexAttribute);
+                    } else // Display new attribute in UI
+                    {
+                        AttributeElement newAttribute = new AttributeElement(
+                                this, indexAttribute, false);
+                        mChildAttributes.put("[" + Integer.toString(i) + "]",
+                                newAttribute);
+                        if (mListener != null)
+                            mListener.add(newAttribute);
+                    }
+                }
+            }
+        } else {
+            String currentValue = new AttributeValueStringConverter(
+                    mAttribute.value()).toString();
+            String newValue = new AttributeValueStringConverter(
+                    attribute.value()).toString();
+            if (!currentValue.equals(newValue)) {
+                mAttribute = attribute;
+                if (mListener != null)
+                    mListener.update(this);
+            }
+        }
+    }
+
+    public void deepSetChildValue(SimulatorResourceAttribute attribute)
+            throws InvalidArgsException {
+        if (null == attribute || null == attribute.name())
+            return;
+
+        AttributeValue.TypeInfo myValuetypeInfo = mAttribute.value().typeInfo();
+        if (myValuetypeInfo.mType == AttributeValue.ValueType.RESOURCEMODEL) {
+            SimulatorResourceModel resModel = (SimulatorResourceModel) mAttribute
+                    .value().get();
+            if (resModel.containsAttribute(attribute.name()))
+                resModel.setAttributeValue(attribute.name(), attribute.value());
+            else
+                return;
+        }
+
+        if (mParent instanceof AttributeElement)
+            ((AttributeElement) mParent).deepSetChildValue(mAttribute);
+    }
+}
index 9a456b9..efb7726 100644 (file)
@@ -20,10 +20,10 @@ import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
-import oic.simulator.serviceprovider.utils.Constants;
-
 import org.oic.simulator.server.SimulatorResource.AutoUpdateType;
 
+import oic.simulator.serviceprovider.utils.Constants;
+
 /**
  * This is a helper class for providing the automation settings information to
  * UI.
@@ -64,7 +64,7 @@ public class AutomationSettingHelper {
     }
 
     public static List<AutomationSettingHelper> getAutomationSettings(
-            LocalResourceAttribute attribute) {
+            AttributeElement attribute) {
         List<AutomationSettingHelper> settingList = null;
         boolean invalidSetting;
 
@@ -76,7 +76,7 @@ public class AutomationSettingHelper {
                     .equals(Constants.AUTOMATION_TYPE)) {
                 setting.setSettingID(Constants.AUTOMATION_TYPE);
                 if (null != attribute) {
-                    setting.setSettingValue(attribute.getAutomationType()
+                    setting.setSettingValue(attribute.getAutoUpdateType()
                             .toString());
                 } else {
                     setting.setSettingValue(AutoUpdateType.ONE_TIME.toString());
@@ -90,7 +90,7 @@ public class AutomationSettingHelper {
                 setting.setSettingID(Constants.UPDATE_INTERVAL_IN_MS);
                 if (null != attribute) {
                     setting.setSettingValue(String.valueOf(attribute
-                            .getAutomationUpdateInterval()));
+                            .getAutoUpdateInterval()));
                 } else {
                     setting.setSettingValue(String
                             .valueOf(Constants.DEFAULT_AUTOMATION_INTERVAL));
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/DataChangeListener.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/DataChangeListener.java
new file mode 100644 (file)
index 0000000..745332b
--- /dev/null
@@ -0,0 +1,9 @@
+package oic.simulator.serviceprovider.model;
+
+public interface DataChangeListener {
+    public void add(AttributeElement attribute);
+
+    public void remove(AttributeElement attribute);
+
+    public void update(AttributeElement attribute);
+}
index 5772cc2..abf0c31 100644 (file)
@@ -30,6 +30,7 @@ public abstract class Resource {
     // Java SDK object reference
     SimulatorResource                           simulatorResource;
     private SimulatorResourceModel              resourceModel;
+    private ResourceRepresentation              mResourceRepresentation;
 
     private String                              resourceURI;
     private String                              resourceName;
@@ -243,18 +244,14 @@ public abstract class Resource {
         this.attributes = attributes;
     }
 
-    // Added for debugging purpose
-    public void printResourceInfo() {
-        System.out.println("Resource URI: " + getResourceURI());
-        System.out.println("Resource Name: " + getResourceName());
-        System.out.println("Resource types: " + getResourceTypes());
-        System.out.println("Resource Interfaces: " + getResourceInterfaces());
-        System.out.println("Resource Attributes:-");
-        /*
-         * if (null != resourceAttributesMap) { Iterator<String> attItr =
-         * resourceAttributesMap.keySet().iterator(); while (attItr.hasNext()) {
-         * resourceAttributesMap.get(attItr.next()) .printAttributeDetails();; }
-         * }
-         */
+    public void setResourceRepresentation(SimulatorResourceModel resModel) {
+        if (mResourceRepresentation == null)
+            mResourceRepresentation = new ResourceRepresentation(resModel);
+        else
+            mResourceRepresentation.update(resModel);
+    }
+
+    public ResourceRepresentation getResourceRepresentation() {
+        return mResourceRepresentation;
     }
 }
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/ResourceRepresentation.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/ResourceRepresentation.java
new file mode 100644 (file)
index 0000000..799c7bd
--- /dev/null
@@ -0,0 +1,55 @@
+package oic.simulator.serviceprovider.model;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.oic.simulator.SimulatorResourceAttribute;
+import org.oic.simulator.SimulatorResourceModel;
+
+public class ResourceRepresentation {
+    private DataChangeListener            mListener   = null;
+    private Map<String, AttributeElement> mAttributes = new HashMap<String, AttributeElement>();
+
+    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(), true));
+        }
+    }
+
+    public Map<String, AttributeElement> getAttributes() {
+        return mAttributes;
+    }
+
+    public void setListener(DataChangeListener listener) {
+        mListener = listener;
+        for (Map.Entry<String, AttributeElement> entry : mAttributes.entrySet())
+            entry.getValue().setListener(listener);
+    }
+
+    public DataChangeListener getListener() {
+        return mListener;
+    }
+
+    public void update(SimulatorResourceModel resourceModel) {
+        if (null == resourceModel)
+            return;
+
+        for (Map.Entry<String, SimulatorResourceAttribute> entry : resourceModel
+                .getAttributes().entrySet()) {
+            AttributeElement attributeElement = mAttributes.get(entry.getKey());
+            if (attributeElement != null) {
+                attributeElement.update(entry.getValue());
+            } else // Display new attribute in UI
+            {
+                AttributeElement newAttribute = new AttributeElement(this,
+                        entry.getValue(), true);
+                mAttributes.put(entry.getKey(), newAttribute);
+                if (mListener != null)
+                    mListener.add(newAttribute);
+            }
+        }
+    }
+}
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/AttributeValueStringConverter.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/AttributeValueStringConverter.java
new file mode 100644 (file)
index 0000000..fab87b9
--- /dev/null
@@ -0,0 +1,327 @@
+package oic.simulator.serviceprovider.utils;
+
+import java.util.Map;
+
+import org.oic.simulator.AttributeValue;
+import org.oic.simulator.AttributeValueVisitor;
+import org.oic.simulator.SimulatorResourceAttribute;
+import org.oic.simulator.SimulatorResourceModel;
+
+public class AttributeValueStringConverter implements
+        AttributeValueVisitor.VisitingMethods<String> {
+
+    private AttributeValue mValue;
+
+    public AttributeValueStringConverter(AttributeValue value) {
+        mValue = value;
+    }
+
+    @Override
+    public String toString() {
+        AttributeValueVisitor visitor = new AttributeValueVisitor(mValue, this);
+        return (String) visitor.visit();
+    }
+
+    @Override
+    public String visitingValue(Integer value) {
+        return value.toString();
+    }
+
+    @Override
+    public String visitingValue(Double value) {
+        return value.toString();
+    }
+
+    @Override
+    public String visitingValue(Boolean value) {
+        return value.toString();
+    }
+
+    @Override
+    public String visitingValue(String value) {
+        return new String(value);
+    }
+
+    @Override
+    public String visitingValue(SimulatorResourceModel value) {
+        StringBuilder result = new StringBuilder();
+        result.append("{");
+        boolean first = true;
+        for (Map.Entry<String, SimulatorResourceAttribute> entry : value
+                .getAttributes().entrySet()) {
+            if (!first)
+                result.append(", ");
+            first = false;
+            result.append("\"" + entry.getKey() + "\":");
+            AttributeValue attributeValue = entry.getValue().value();
+            result.append(new AttributeValueStringConverter(attributeValue)
+                    .toString());
+        }
+
+        result.append("}");
+        return result.toString();
+    }
+
+    @Override
+    public String visitingValue(Integer[] values) {
+        StringBuilder result = new StringBuilder();
+        result.append("[");
+        boolean first = true;
+        for (Integer value : values) {
+            if (!first)
+                result.append(", ");
+            first = false;
+            result.append(value.toString());
+        }
+
+        result.append("]");
+        return result.toString();
+    }
+
+    @Override
+    public String visitingValue(Double[] values) {
+        StringBuilder result = new StringBuilder();
+        result.append("[");
+        boolean first = true;
+        for (Double value : values) {
+            if (!first)
+                result.append(", ");
+            first = false;
+            result.append(value.toString());
+        }
+
+        result.append("]");
+        return result.toString();
+    }
+
+    @Override
+    public String visitingValue(Boolean[] values) {
+        StringBuilder result = new StringBuilder();
+        result.append("[");
+        boolean first = true;
+        for (Boolean value : values) {
+            if (!first)
+                result.append(", ");
+            first = false;
+            result.append(value.toString());
+        }
+
+        result.append("]");
+        return result.toString();
+    }
+
+    @Override
+    public String visitingValue(String[] values) {
+        StringBuilder result = new StringBuilder();
+        result.append("[");
+        boolean first = true;
+        for (String value : values) {
+            if (!first)
+                result.append(", ");
+            first = false;
+            result.append(value);
+        }
+
+        result.append("]");
+        return result.toString();
+    }
+
+    @Override
+    public String visitingValue(SimulatorResourceModel[] values) {
+        StringBuilder result = new StringBuilder();
+        result.append("[");
+        boolean first = true;
+        for (SimulatorResourceModel value : values) {
+            if (!first)
+                result.append(", ");
+            first = false;
+            AttributeValue attributeValue = new AttributeValue(value);
+            result.append(new AttributeValueStringConverter(attributeValue)
+                    .toString());
+        }
+
+        result.append("]");
+        return result.toString();
+    }
+
+    @Override
+    public String visitingValue(Integer[][] values) {
+        StringBuilder result = new StringBuilder();
+        result.append("[");
+        boolean first = true;
+        for (Integer[] value : values) {
+            if (!first)
+                result.append(", ");
+            first = false;
+            AttributeValue attributeValue = new AttributeValue(value);
+            result.append(new AttributeValueStringConverter(attributeValue)
+                    .toString());
+        }
+
+        result.append("]");
+        return result.toString();
+    }
+
+    @Override
+    public String visitingValue(Double[][] values) {
+        StringBuilder result = new StringBuilder();
+        result.append("[");
+        boolean first = true;
+        for (Double[] value : values) {
+            if (!first)
+                result.append(", ");
+            first = false;
+            AttributeValue attributeValue = new AttributeValue(value);
+            result.append(new AttributeValueStringConverter(attributeValue)
+                    .toString());
+        }
+
+        result.append("]");
+        return result.toString();
+    }
+
+    @Override
+    public String visitingValue(Boolean[][] values) {
+        StringBuilder result = new StringBuilder();
+        result.append("[");
+        boolean first = true;
+        for (Boolean[] value : values) {
+            if (!first)
+                result.append(", ");
+            first = false;
+            AttributeValue attributeValue = new AttributeValue(value);
+            result.append(new AttributeValueStringConverter(attributeValue)
+                    .toString());
+        }
+
+        result.append("]");
+        return result.toString();
+    }
+
+    @Override
+    public String visitingValue(String[][] values) {
+        StringBuilder result = new StringBuilder();
+        result.append("[");
+        boolean first = true;
+        for (String[] value : values) {
+            if (!first)
+                result.append(", ");
+            first = false;
+            AttributeValue attributeValue = new AttributeValue(value);
+            result.append(new AttributeValueStringConverter(attributeValue)
+                    .toString());
+        }
+
+        result.append("]");
+        return result.toString();
+    }
+
+    @Override
+    public String visitingValue(SimulatorResourceModel[][] values) {
+        StringBuilder result = new StringBuilder();
+        result.append("[");
+        boolean first = true;
+        for (SimulatorResourceModel[] value : values) {
+            if (!first)
+                result.append(", ");
+            first = false;
+            AttributeValue attributeValue = new AttributeValue(value);
+            result.append(new AttributeValueStringConverter(attributeValue)
+                    .toString());
+        }
+
+        result.append("]");
+        return result.toString();
+    }
+
+    @Override
+    public String visitingValue(Integer[][][] values) {
+        StringBuilder result = new StringBuilder();
+        result.append("[");
+        boolean first = true;
+        for (Integer[][] value : values) {
+            if (!first)
+                result.append(", ");
+            first = false;
+            AttributeValue attributeValue = new AttributeValue(value);
+            result.append(new AttributeValueStringConverter(attributeValue)
+                    .toString());
+        }
+
+        result.append("]");
+        return result.toString();
+    }
+
+    @Override
+    public String visitingValue(Double[][][] values) {
+        StringBuilder result = new StringBuilder();
+        result.append("[");
+        boolean first = true;
+        for (Double[][] value : values) {
+            if (!first)
+                result.append(", ");
+            first = false;
+            AttributeValue attributeValue = new AttributeValue(value);
+            result.append(new AttributeValueStringConverter(attributeValue)
+                    .toString());
+        }
+
+        result.append("]");
+        return result.toString();
+    }
+
+    @Override
+    public String visitingValue(Boolean[][][] values) {
+        StringBuilder result = new StringBuilder();
+        result.append("[");
+        boolean first = true;
+        for (Boolean[][] value : values) {
+            if (!first)
+                result.append(", ");
+            first = false;
+            AttributeValue attributeValue = new AttributeValue(value);
+            result.append(new AttributeValueStringConverter(attributeValue)
+                    .toString());
+        }
+
+        result.append("]");
+        return result.toString();
+    }
+
+    @Override
+    public String visitingValue(String[][][] values) {
+        StringBuilder result = new StringBuilder();
+        result.append("[");
+        boolean first = true;
+        for (String[][] value : values) {
+            if (!first)
+                result.append(", ");
+            first = false;
+            AttributeValue attributeValue = new AttributeValue(value);
+            result.append(new AttributeValueStringConverter(attributeValue)
+                    .toString());
+        }
+
+        result.append("]");
+        return result.toString();
+    }
+
+    @Override
+    public String visitingValue(SimulatorResourceModel[][][] values) {
+        StringBuilder result = new StringBuilder();
+        result.append("[");
+        boolean first = true;
+        for (SimulatorResourceModel[][] value : values) {
+            if (!first)
+                result.append(", ");
+            first = false;
+            AttributeValue attributeValue = new AttributeValue(value);
+            result.append(new AttributeValueStringConverter(attributeValue)
+                    .toString());
+        }
+
+        result.append("]");
+        return result.toString();
+    }
+
+}
index 73d559c..8b3f2f5 100644 (file)
@@ -362,7 +362,7 @@ public class Utility {
             return null;
         }
         Set<Object> resultSet = new HashSet<Object>();
-        if (type.equals(Constants.INT)) {
+        if (AttributeValue.ValueType.INTEGER == type) {
             int val;
             Iterator<String> itr = values.iterator();
             while (itr.hasNext()) {
@@ -373,7 +373,7 @@ public class Utility {
                     // Added for safety. Nothing to do.
                 }
             }
-        } else if (type.equals(Constants.DOUBLE)) {
+        } else if (AttributeValue.ValueType.DOUBLE == type) {
             double val;
             Iterator<String> itr = values.iterator();
             while (itr.hasNext()) {
@@ -384,10 +384,10 @@ public class Utility {
                     // Added for safety. Nothing to do.
                 }
             }
-        } else if (type.equals(Constants.BOOL)) {
+        } else if (AttributeValue.ValueType.BOOLEAN == type) {
             resultSet.add(true);
             resultSet.add(false);
-        } else {
+        } else if (AttributeValue.ValueType.STRING == type) {
             Iterator<String> itr = values.iterator();
             while (itr.hasNext()) {
                 resultSet.add(itr.next());
index 1544fb6..b9de9d2 100644 (file)
@@ -20,11 +20,11 @@ import java.util.List;
 
 import oic.simulator.serviceprovider.Activator;
 import oic.simulator.serviceprovider.manager.ResourceManager;
+import oic.simulator.serviceprovider.model.AttributeElement;
 import oic.simulator.serviceprovider.model.AutomationSettingHelper;
 import oic.simulator.serviceprovider.model.CollectionResource;
-import oic.simulator.serviceprovider.model.LocalResourceAttribute;
 import oic.simulator.serviceprovider.model.Resource;
-import oic.simulator.serviceprovider.model.SRMItem;
+import oic.simulator.serviceprovider.model.ResourceRepresentation;
 import oic.simulator.serviceprovider.model.SingleResource;
 import oic.simulator.serviceprovider.utils.AttributeValueBuilder;
 import oic.simulator.serviceprovider.utils.Utility;
@@ -52,7 +52,6 @@ import org.oic.simulator.AttributeValue.TypeInfo;
 import org.oic.simulator.AttributeValue.ValueType;
 import org.oic.simulator.InvalidArgsException;
 import org.oic.simulator.SimulatorResourceAttribute;
-import org.oic.simulator.SimulatorResourceModel;
 import org.oic.simulator.server.SimulatorResource.AutoUpdateType;
 
 /**
@@ -105,53 +104,44 @@ public class AttributeEditingSupport {
                 return null;
             }
 
-            final SimulatorResourceAttribute att;
-            if (element instanceof SimulatorResourceAttribute
-                    || element instanceof LocalResourceAttribute) {
-                if (element instanceof LocalResourceAttribute) {
-                    LocalResourceAttribute localAtt = (LocalResourceAttribute) element;
-                    att = localAtt.getResourceAttributeRef();
-                } else {
-                    att = (SimulatorResourceAttribute) element;
-                }
-            } else {
+            final SimulatorResourceAttribute attribute;
+            if (!(element instanceof AttributeElement)) {
                 return null;
             }
 
-            if (null == att) {
+            AttributeElement attributeElement = ((AttributeElement) element);
+            attribute = attributeElement.getSimulatorResourceAttribute();
+            if (null == attribute) {
                 return null;
             }
 
-            final AttributeValue val = att.value();
-            if (null == val) {
+            // CellEditor is not required as the automation is in progress.
+            if (attributeElement.isAutoUpdateInProgress()) {
                 return null;
             }
 
-            final TypeInfo type = val.typeInfo();
-            if (type.mType == ValueType.RESOURCEMODEL
-                    || (type.mType == ValueType.ARRAY && type.mBaseType == ValueType.RESOURCEMODEL)) {
+            final AttributeValue val = attribute.value();
+            if (null == val) {
                 return null;
             }
 
-            AttributeProperty prop = att.property();
-            if (null == prop) {
+            final TypeInfo type = val.typeInfo();
+            if (type.mBaseType == ValueType.RESOURCEMODEL) {
                 return null;
             }
 
-            if (!resourceManager.isAttHasRangeOrAllowedValues(att)) {
+            AttributeProperty prop = attribute.property();
+            if (null == prop) {
                 return null;
             }
 
-            // CellEditor is not required as the automation is in progress.
-            if (element instanceof LocalResourceAttribute
-                    && ((LocalResourceAttribute) element)
-                            .isAutomationInProgress()) {
+            if (!resourceManager.isAttHasRangeOrAllowedValues(attribute)) {
                 return null;
             }
 
             String values[] = null;
             List<String> valueSet = resourceManager
-                    .getAllValuesOfAttribute(att);
+                    .getAllValuesOfAttribute(attribute);
             values = convertListToStringArray(valueSet);
 
             ComboBoxCellEditor comboEditor;
@@ -186,7 +176,7 @@ public class AttributeEditingSupport {
                             dialog.setMessage("Given value is invalid");
                             dialog.open();
                         } else {
-                            updateAttributeValue(att, value);
+                            updateAttributeValue(attribute, value);
                             MessageBox dialog = new MessageBox(viewer.getTree()
                                     .getShell(), SWT.ICON_QUESTION | SWT.OK
                                     | SWT.CANCEL);
@@ -196,7 +186,7 @@ public class AttributeEditingSupport {
                             if (retval != SWT.OK) {
                                 value = AttributeValueBuilder.build(oldValue,
                                         type.mBaseType);
-                                updateAttributeValue(att, value);
+                                updateAttributeValue(attribute, value);
                             } else {
                                 ResourceManager resourceManager;
                                 resourceManager = Activator.getDefault()
@@ -205,11 +195,11 @@ public class AttributeEditingSupport {
                                 Resource resource = resourceManager
                                         .getCurrentResourceInSelection();
 
-                                AttributeValue resultValue = getResultantValue(value);
+                                SimulatorResourceAttribute result = getResultantValue(value);
 
                                 resourceManager.attributeValueUpdated(
-                                        (SingleResource) resource, att.name(),
-                                        resultValue);
+                                        (SingleResource) resource,
+                                        result.name(), result.value());
 
                             }
                         }
@@ -224,17 +214,14 @@ public class AttributeEditingSupport {
         @Override
         protected Object getValue(Object element) {
             int indexOfItem = 0;
-            SimulatorResourceAttribute att;
+            SimulatorResourceAttribute att = null;
 
-            if (element instanceof LocalResourceAttribute) {
-                LocalResourceAttribute localAtt = (LocalResourceAttribute) element;
-                att = localAtt.getResourceAttributeRef();
-                if (null == att) {
-                    return 0;
-                }
-            } else if (element instanceof SimulatorResourceAttribute) {
-                att = (SimulatorResourceAttribute) element;
-            } else {
+            if (element instanceof AttributeElement) {
+                att = ((AttributeElement) element)
+                        .getSimulatorResourceAttribute();
+            }
+
+            if (att == null) {
                 return 0;
             }
 
@@ -252,17 +239,14 @@ public class AttributeEditingSupport {
 
         @Override
         protected void setValue(Object element, Object value) {
-            SimulatorResourceAttribute att;
+            SimulatorResourceAttribute att = null;
 
-            if (element instanceof LocalResourceAttribute) {
-                LocalResourceAttribute localAtt = (LocalResourceAttribute) element;
-                att = localAtt.getResourceAttributeRef();
-                if (null == att) {
-                    return;
-                }
-            } else if (element instanceof SimulatorResourceAttribute) {
-                att = (SimulatorResourceAttribute) element;
-            } else {
+            if (element instanceof AttributeElement) {
+                att = ((AttributeElement) element)
+                        .getSimulatorResourceAttribute();
+            }
+
+            if (att == null) {
                 return;
             }
 
@@ -316,11 +300,11 @@ public class AttributeEditingSupport {
                                 Resource resource = resourceManager
                                         .getCurrentResourceInSelection();
 
-                                AttributeValue resultValue = getResultantValue(attValue);
+                                SimulatorResourceAttribute result = getResultantValue(attValue);
 
                                 resourceManager.attributeValueUpdated(
-                                        (SingleResource) resource, att.name(),
-                                        resultValue);
+                                        (SingleResource) resource,
+                                        result.name(), result.value());
                             }
                         }
                     }
@@ -360,54 +344,27 @@ public class AttributeEditingSupport {
             if (null == item) {
                 return;
             }
-            TreeItem parent = item.getParentItem();
 
-            // Get the parent model
-            if (null == parent) {
-                // Top-level attribute
-                Resource res = Activator.getDefault().getResourceManager()
-                        .getCurrentResourceInSelection();
-                if (null == res) {
-                    return;
-                }
-                SimulatorResourceModel model = res.getResourceModel();
-                if (null == model) {
-                    return;
-                }
-                try {
-                    model.setAttributeValue(att.name(), value);
-                } catch (InvalidArgsException e) {
-                    // TODO Auto-generated catch block
-                    e.printStackTrace();
-                }
-            } else {
-                SimulatorResourceModel model;
-                Object data = parent.getData();
-                if (null == data) {
-                    return;
-                }
-                if (data instanceof SRMItem) {
-                    model = ((SRMItem) data).getModel();
-                } else {
-                    SimulatorResourceAttribute parentAtt;
-                    if (data instanceof LocalResourceAttribute) {
-                        parentAtt = ((LocalResourceAttribute) data)
-                                .getResourceAttributeRef();
-                    } else {
-                        parentAtt = (SimulatorResourceAttribute) data;
+            if (item.getData() instanceof AttributeElement) {
+                AttributeElement attributeElement = (AttributeElement) item
+                        .getData();
+                attributeElement.getSimulatorResourceAttribute()
+                        .setValue(value);
+
+                TreeItem parent = item.getParentItem();
+                if (null != parent) {
+                    Object data = parent.getData();
+                    try {
+                        ((AttributeElement) data).deepSetChildValue(att);
+                    } catch (InvalidArgsException e) {
+                        e.printStackTrace();
                     }
-                    model = (SimulatorResourceModel) parentAtt.value().get();
-                }
-                try {
-                    model.setAttributeValue(att.name(), value);
-                } catch (InvalidArgsException e) {
-                    // TODO Auto-generated catch block
-                    e.printStackTrace();
                 }
             }
         }
 
-        public AttributeValue getResultantValue(AttributeValue newValue) {
+        public SimulatorResourceAttribute getResultantValue(
+                AttributeValue newValue) {
             AttributeValue val = null;
             IStructuredSelection selection = (IStructuredSelection) viewer
                     .getSelection();
@@ -426,24 +383,24 @@ public class AttributeEditingSupport {
                 return null;
             }
 
+            SimulatorResourceAttribute result = null;
             TreeItem parent = item.getParentItem();
             if (null == parent) {
                 Object data = item.getData();
-                // SimulatorResourceAttribute att =
-                // ((LocalResourceAttribute)data).getResourceAttributeRef();
-                val = newValue;
+                result = ((AttributeElement) data)
+                        .getSimulatorResourceAttribute();
             } else {
                 while (parent.getParentItem() != null) {
                     parent = parent.getParentItem();
                 }
+
                 // Parent will point to the top-level attribute of type
-                // LocalResourceAttribute
                 Object data = parent.getData();
-                val = ((LocalResourceAttribute) data).getResourceAttributeRef()
-                        .value();
+                result = ((AttributeElement) data)
+                        .getSimulatorResourceAttribute();
             }
 
-            return val;
+            return result;
         }
     }
 
@@ -480,9 +437,9 @@ public class AttributeEditingSupport {
             }
 
             SimulatorResourceAttribute att = null;
-            if (element instanceof LocalResourceAttribute) {
-                LocalResourceAttribute localAtt = (LocalResourceAttribute) element;
-                att = localAtt.getResourceAttributeRef();
+            if (element instanceof AttributeElement) {
+                att = ((AttributeElement) element)
+                        .getSimulatorResourceAttribute();
             }
 
             if (null == att) {
@@ -501,17 +458,29 @@ public class AttributeEditingSupport {
                 return null;
             }
 
+            Object parent = ((AttributeElement) element).getParent();
+            if (null != parent && !(parent instanceof ResourceRepresentation)) {
+                return null;
+            }
+
             return new CheckboxCellEditor(null, SWT.CHECK | SWT.READ_ONLY);
         }
 
         @Override
         protected Object getValue(Object element) {
-            LocalResourceAttribute att = (LocalResourceAttribute) element;
-            return att.isAutomationInProgress();
+            if (element instanceof AttributeElement) {
+                return ((AttributeElement) element).isAutoUpdateInProgress();
+            }
+
+            return false;
         }
 
         @Override
         protected void setValue(Object element, Object value) {
+            if (!(element instanceof AttributeElement)) {
+                return;
+            }
+
             ResourceManager resourceManager = Activator.getDefault()
                     .getResourceManager();
             // As automation depends on the current resource in selection, its
@@ -521,7 +490,7 @@ public class AttributeEditingSupport {
                 return;
             }
 
-            LocalResourceAttribute att = (LocalResourceAttribute) element;
+            AttributeElement att = (AttributeElement) element;
             boolean checked = (Boolean) value;
             if (checked) {
                 // Start the automation
@@ -549,17 +518,17 @@ public class AttributeEditingSupport {
                                 .getActiveShell(), "Automation Status",
                                 "Automation start failed!!");
                     } else {
-                        viewer.update(element, null);
+                        // viewer.update(element, null);
                     }
                 }
             } else {
                 // Stop the automation
                 resourceManager.stopAutomation((SingleResource) resource, att,
-                        att.getAutomationId());
+                        att.getAutoUpdateId());
                 MessageDialog.openInformation(Display.getDefault()
                         .getActiveShell(), "Automation Status",
                         "Automation stopped.");
-                viewer.update(element, null);
+                // viewer.update(element, null);
             }
         }
     }
index f81bda6..5806cec 100644 (file)
@@ -17,7 +17,6 @@
 package oic.simulator.serviceprovider.view;
 
 import java.util.List;
-import java.util.Map;
 
 import oic.simulator.serviceprovider.Activator;
 import oic.simulator.serviceprovider.listener.IAutomationUIListener;
@@ -25,11 +24,12 @@ import oic.simulator.serviceprovider.listener.IResourceModelChangedUIListener;
 import oic.simulator.serviceprovider.listener.ISelectionChangedUIListener;
 import oic.simulator.serviceprovider.manager.ResourceManager;
 import oic.simulator.serviceprovider.manager.UiListenerHandler;
-import oic.simulator.serviceprovider.model.CollectionResource;
+import oic.simulator.serviceprovider.model.AttributeElement;
+import oic.simulator.serviceprovider.model.DataChangeListener;
 import oic.simulator.serviceprovider.model.Device;
 import oic.simulator.serviceprovider.model.LocalResourceAttribute;
 import oic.simulator.serviceprovider.model.Resource;
-import oic.simulator.serviceprovider.model.SRMItem;
+import oic.simulator.serviceprovider.model.ResourceRepresentation;
 import oic.simulator.serviceprovider.model.SingleResource;
 import oic.simulator.serviceprovider.utils.Constants;
 import oic.simulator.serviceprovider.utils.Utility;
@@ -55,7 +55,6 @@ import org.oic.simulator.AttributeValue;
 import org.oic.simulator.AttributeValue.TypeInfo;
 import org.oic.simulator.AttributeValue.ValueType;
 import org.oic.simulator.SimulatorResourceAttribute;
-import org.oic.simulator.SimulatorResourceModel;
 
 /**
  * This class manages and shows the attribute view in the perspective.
@@ -90,17 +89,20 @@ public class AttributeView extends ViewPart {
                     @Override
                     public void run() {
                         if (null != attViewer) {
-                            updateViewer(getData(resource));
-                            Tree tree = attViewer.getTree();
-                            if (!tree.isDisposed()) {
-                                if (null != resource
-                                        && (resource instanceof SingleResource && ((SingleResource) resource)
-                                                .isResourceAutomationInProgress())) {
-                                    tree.setEnabled(false);
-                                } else {
-                                    tree.setEnabled(true);
-                                }
-                            }
+                            if (null != resource
+                                    && null != resource
+                                            .getResourceRepresentation())
+                                attViewer.setInput(resource
+                                        .getResourceRepresentation());
+                            /*
+                             * updateViewer(getData(resource)); Tree tree =
+                             * attViewer.getTree(); if (!tree.isDisposed()) { if
+                             * (null != resource && (resource instanceof
+                             * SingleResource && ((SingleResource) resource)
+                             * .isResourceAutomationInProgress())) {
+                             * tree.setEnabled(false); } else {
+                             * tree.setEnabled(true); } }
+                             */
                         }
                     }
                 });
@@ -131,22 +133,17 @@ public class AttributeView extends ViewPart {
                         if (null == resourceInSelection) {
                             return;
                         }
-                        if (resource != resourceInSelection) {
-                            // This notification is for a different resource
-                            // whose attributes are not
-                            // currently not being shown in UI. So ignoring this
-                            // notification.
-                            return;
-                        }
-                        // Refresh the table viewers which will display
-                        // the updated values
-                        if (null != attViewer) {
-                            if (resource instanceof CollectionResource) {
-                                updateViewer(getData(resource));
-                            } else {
-                                updateViewer(getData(resource));
-                            }
-                        }
+                        /*
+                         * if (resource != resourceInSelection) { // This
+                         * notification is for a different resource // whose
+                         * attributes are not // currently not being shown in
+                         * UI. So ignoring this // notification. return; } //
+                         * Refresh the table viewers which will display // the
+                         * updated values if (null != attViewer) { if (resource
+                         * instanceof CollectionResource) {
+                         * updateViewer(getData(resource)); } else {
+                         * updateViewer(getData(resource)); } }
+                         */
                     }
                 });
             }
@@ -272,10 +269,9 @@ public class AttributeView extends ViewPart {
         addManagerListeners();
 
         // Check whether there is any resource selected already
-        List<LocalResourceAttribute> propertyList = getData(resourceManager
-                .getCurrentResourceInSelection());
-        if (null != propertyList) {
-            updateViewer(propertyList);
+        Resource resource = resourceManager.getCurrentResourceInSelection();
+        if (resource != null) {
+            attViewer.setInput(resource.getResourceRepresentation());
         }
     }
 
@@ -345,128 +341,84 @@ public class AttributeView extends ViewPart {
         }
     }
 
-    class AttributeContentProvider implements ITreeContentProvider {
+    class AttributeContentProvider implements ITreeContentProvider,
+            DataChangeListener {
+
+        private TreeViewer mTreeViewer;
 
         @Override
         public void dispose() {
         }
 
         @Override
-        public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
+        public void inputChanged(Viewer viewer, Object oldAttribute,
+                Object newAttribute) {
+            mTreeViewer = (TreeViewer) viewer;
         }
 
         @Override
-        public Object[] getChildren(Object element) {
-            if (element instanceof SimulatorResourceAttribute
-                    || element instanceof LocalResourceAttribute) {
-                SimulatorResourceAttribute att;
-                if (element instanceof LocalResourceAttribute) {
-                    LocalResourceAttribute localAtt = (LocalResourceAttribute) element;
-                    att = localAtt.getResourceAttributeRef();
-                    if (null == att) {
-                        return new Object[1];
-                    }
-                } else {
-                    att = (SimulatorResourceAttribute) element;
-                }
-                AttributeValue val = att.value();
-                if (null == val) {
-                    return new Object[1];
-                }
-                TypeInfo type = val.typeInfo();
-                if (type.mType == ValueType.RESOURCEMODEL) {
-                    SimulatorResourceModel model = (SimulatorResourceModel) val
-                            .get();
-                    if (null == model) {
-                        return new Object[1];
-                    }
-                    return resourceManager.getAttributes(model).toArray();
-                } else if (type.mType == ValueType.ARRAY
-                        && type.mBaseType == ValueType.RESOURCEMODEL
-                        && type.mDepth == 1) {
-                    SimulatorResourceModel[] model = (SimulatorResourceModel[]) val
-                            .get();
-                    if (null == model || model.length < 1) {
-                        return new Object[1];
-                    }
-                    return resourceManager.getIndexedAttributes(model)
-                            .toArray();
-                }
-            } else if (element instanceof SRMItem) {
-                SRMItem item = (SRMItem) element;
-                SimulatorResourceModel model = (SimulatorResourceModel) item
-                        .getModel();
-                if (null == model) {
-                    return new Object[1];
-                }
-                return resourceManager.getAttributes(model).toArray();
+        public Object[] getChildren(Object attribute) {
+            if (attribute instanceof AttributeElement) {
+                return ((AttributeElement) attribute).getChildren().values()
+                        .toArray();
             }
-            return new Object[1];
+
+            return new Object[0];
         }
 
         @Override
-        public Object[] getElements(Object element) {
-            Object[] elements = (Object[]) element;
-            return elements;
+        public Object getParent(Object attribute) {
+            if (attribute instanceof AttributeElement)
+                return ((AttributeElement) attribute).getParent();
+            return null;
         }
 
         @Override
-        public Object getParent(Object element) {
-            return null;
+        public boolean hasChildren(Object attribute) {
+            if (attribute instanceof AttributeElement)
+                return ((AttributeElement) attribute).hasChildren();
+            return false;
         }
 
         @Override
-        public boolean hasChildren(Object element) {
-            if (element instanceof SimulatorResourceAttribute
-                    || element instanceof LocalResourceAttribute) {
-                SimulatorResourceAttribute att;
-                if (element instanceof LocalResourceAttribute) {
-                    LocalResourceAttribute localAtt = (LocalResourceAttribute) element;
-                    att = localAtt.getResourceAttributeRef();
-                    if (null == att) {
-                        return false;
-                    }
-                } else {
-                    att = (SimulatorResourceAttribute) element;
-                }
-                AttributeValue val = att.value();
-                if (null == val) {
-                    return false;
-                }
-                TypeInfo type = val.typeInfo();
-                if (type.mType == ValueType.RESOURCEMODEL) {
-                    SimulatorResourceModel model = (SimulatorResourceModel) val
-                            .get();
-                    if (null == model) {
-                        return false;
-                    }
-                    Map<String, SimulatorResourceAttribute> attributes = model
-                            .getAttributes();
-                    if (null != attributes && attributes.size() > 0) {
-                        return true;
-                    }
-                } else if (type.mType == ValueType.ARRAY
-                        && type.mBaseType == ValueType.RESOURCEMODEL
-                        && type.mDepth == 1) {
-                    SimulatorResourceModel[] model = (SimulatorResourceModel[]) val
-                            .get();
-                    if (null != model && model.length > 0) {
-                        return true;
-                    }
+        public Object[] getElements(Object resourceModel) {
+            if (resourceModel instanceof ResourceRepresentation) {
+                ((ResourceRepresentation) resourceModel).setListener(this);
+                return ((ResourceRepresentation) resourceModel).getAttributes()
+                        .values().toArray();
+            }
+
+            return new Object[0];
+        }
+
+        @Override
+        public void add(final AttributeElement attribute) {
+            Display.getDefault().asyncExec(new Runnable() {
+                @Override
+                public void run() {
+                    mTreeViewer.refresh(attribute.getParent());
                 }
-            } else if (element instanceof SRMItem) {
-                SRMItem srmItem = (SRMItem) element;
-                SimulatorResourceModel model = srmItem.getModel();
-                if (null == model) {
-                    return false;
+            });
+        }
+
+        @Override
+        public void remove(final AttributeElement attribute) {
+            Display.getDefault().asyncExec(new Runnable() {
+                @Override
+                public void run() {
+                    mTreeViewer.refresh(attribute.getParent());
                 }
-                Map<String, SimulatorResourceAttribute> attributes = model
-                        .getAttributes();
-                if (null != attributes && attributes.size() > 0) {
-                    return true;
+            });
+        }
+
+        @Override
+        public void update(final AttributeElement attribute) {
+            Display.getDefault().asyncExec(new Runnable() {
+                @Override
+                public void run() {
+                    mTreeViewer.update(attribute, null);
                 }
-            }
-            return false;
+            });
         }
     }
 
@@ -493,110 +445,89 @@ public class AttributeView extends ViewPart {
         @Override
         public Image getColumnImage(Object element, int col) {
             if (col == 2) {
-                if (element instanceof SimulatorResourceAttribute
-                        || element instanceof LocalResourceAttribute) {
-                    SimulatorResourceAttribute att;
-                    if (element instanceof LocalResourceAttribute) {
-                        LocalResourceAttribute localAtt = (LocalResourceAttribute) element;
-                        att = localAtt.getResourceAttributeRef();
-                    } else {
-                        att = (SimulatorResourceAttribute) element;
-                    }
-                    AttributeValue val = att.value();
-                    if (null == val) {
-                        return null;
-                    }
-                    TypeInfo type = val.typeInfo();
-                    if (type.mType == ValueType.RESOURCEMODEL
-                            || type.mType == ValueType.ARRAY) {
-                        return null;
-                    }
-                    if (element instanceof LocalResourceAttribute) {
-                        if (!resourceManager.isAttHasRangeOrAllowedValues(att)) {
-                            System.out.println("No range or allowed values");
-                            return null;
-                        }
-                        if (((LocalResourceAttribute) element)
-                                .isAutomationInProgress()) {
-                            return Activator.getDefault().getImageRegistry()
-                                    .get(Constants.CHECKED);
+                if (element instanceof AttributeElement) {
+                    // Ignore for collection resource
+                    Resource res = resourceManager
+                            .getCurrentResourceInSelection();
+                    if (res instanceof SingleResource) {
+                        AttributeElement attrElement = (AttributeElement) element;
+                        SimulatorResourceAttribute attribute = attrElement
+                                .getSimulatorResourceAttribute();
+                        TypeInfo type = attribute.value().typeInfo();
+                        if (attrElement.isAutoUpdateSupport()
+                                && !attrElement.isReadOnly()) {
+                            if (attrElement.isAutoUpdateInProgress()) {
+                                return Activator.getDefault()
+                                        .getImageRegistry()
+                                        .get(Constants.CHECKED);
+                            } else {
+                                return Activator.getDefault()
+                                        .getImageRegistry()
+                                        .get(Constants.UNCHECKED);
+                            }
                         }
-                        return Activator.getDefault().getImageRegistry()
-                                .get(Constants.UNCHECKED);
                     }
-                    return null;
                 }
             }
             return null;
         }
 
         @Override
-        public String getColumnText(Object element, int col) {
-            if (element instanceof SimulatorResourceAttribute
-                    || element instanceof LocalResourceAttribute) {
-                SimulatorResourceAttribute att;
-                if (element instanceof LocalResourceAttribute) {
-                    LocalResourceAttribute localAtt = (LocalResourceAttribute) element;
-                    att = localAtt.getResourceAttributeRef();
-                } else {
-                    att = (SimulatorResourceAttribute) element;
-                }
-                AttributeValue val = att.value();
-                if (null == val) {
-                    return "";
-                }
-                TypeInfo type = val.typeInfo();
-                switch (col) {
-                    case 0:
-                        return att.name();
-                    case 1:
-                        if (!(type.mType == ValueType.RESOURCEMODEL || (type.mType == ValueType.ARRAY && type.mBaseType == ValueType.RESOURCEMODEL))) {
-                            String value = Utility
-                                    .getAttributeValueAsString(val);
-                            if (null == value) {
-                                value = "";
-                            }
-                            return value;
-                        } else {
-                            return "";
-                        }
-                    case 2:
+        public String getColumnText(Object element, int column) {
+            if (element instanceof AttributeElement) {
+                AttributeElement attrElement = (AttributeElement) element;
+                switch (column) {
+                    case 0: // Attribute name column
+                    {
+                        SimulatorResourceAttribute attribute = attrElement
+                                .getSimulatorResourceAttribute();
+                        return attribute.name();
+                    }
+
+                    case 1: // Attribute value column
+                    {
+                        SimulatorResourceAttribute attribute = attrElement
+                                .getSimulatorResourceAttribute();
+
+                        if (attribute.value().typeInfo().mBaseType != ValueType.RESOURCEMODEL)
+                            return Utility.getAttributeValueAsString(attribute
+                                    .value());
+                        return null;
+                    }
+
+                    case 2: {
+                        // Ignore for collection resource
                         Resource res = resourceManager
                                 .getCurrentResourceInSelection();
-                        if (null != res && res instanceof CollectionResource) {
-                            return "-";
-                        }
-
-                        if (type.mType == ValueType.RESOURCEMODEL
-                                || type.mType == ValueType.ARRAY) {
-                            return "";
-                        }
-                        if (element instanceof LocalResourceAttribute) {
-                            if (!resourceManager
-                                    .isAttHasRangeOrAllowedValues(att)) {
-                                System.out
-                                        .println("No range or allowed values");
-                                return "Read Only";
-                            }
-                            if (((LocalResourceAttribute) element)
-                                    .isAutomationInProgress()) {
-                                return Constants.ENABLED;
+                        if (res instanceof SingleResource) {
+                            SimulatorResourceAttribute attribute = attrElement
+                                    .getSimulatorResourceAttribute();
+                            TypeInfo type = attribute.value().typeInfo();
+                            if (type.mType == AttributeValue.ValueType.ARRAY) {
+                                if (type.mBaseType != AttributeValue.ValueType.RESOURCEMODEL) {
+                                    return "NA";
+                                }
+                            } else if (type.mType != AttributeValue.ValueType.RESOURCEMODEL) {
+                                Object parent = attrElement.getParent();
+                                if (null != parent
+                                        && !(parent instanceof ResourceRepresentation)) {
+                                    return "NA";
+                                } else if (attrElement.isReadOnly()) {
+                                    return "Read-only";
+                                } else if (attrElement.isAutoUpdateSupport()) {
+                                    if (attrElement.isAutoUpdateInProgress())
+                                        return Constants.ENABLED;
+                                    else
+                                        return Constants.DISABLED;
+                                }
                             }
-                            return Constants.DISABLED;
                         }
-                        return "NA";
-                }
-            } else if (element instanceof SRMItem) {
-                SRMItem item = (SRMItem) element;
-                switch (col) {
-                    case 0:
-                        return "[" + item.getIndex() + "]";
-                    case 1:
-                        return "";
-                    case 2:
+
                         return "";
+                    }
                 }
             }
+
             return null;
         }
 
index 9098bcf..20fac74 100644 (file)
@@ -500,7 +500,6 @@ public class CreateResourceWizard extends Wizard {
                     .createSingleResource(resource);
             if (result) {
                 status = "Resource created.";
-                resource.printResourceInfo();
             } else {
                 status = "Failed to create resource.";
             }
@@ -532,7 +531,6 @@ public class CreateResourceWizard extends Wizard {
 
             if (result) {
                 status = "Resource created.";
-                loadRamlPage.getResource().printResourceInfo();
             } else {
                 status = "Failed to create resource.";
             }
index 3391685..ab1a338 100644 (file)
@@ -270,7 +270,7 @@ Java_org_oic_simulator_SimulatorManager_setDeviceInfo
 
 JNIEXPORT void JNICALL
 Java_org_oic_simulator_SimulatorManager_findDevices
-(JNIEnv *env, jobject object, jobject listener)
+(JNIEnv *env, jobject object, jstring hostUri, jobject listener)
 {
     VALIDATE_CALLBACK(env, listener)
 
@@ -282,7 +282,8 @@ Java_org_oic_simulator_SimulatorManager_findDevices
 
     try
     {
-        SimulatorManager::getInstance()->getDeviceInfo(callback);
+        JniString jniHostUri(env, hostUri);
+        SimulatorManager::getInstance()->getDeviceInfo(jniHostUri.get(), callback);
     }
     catch (InvalidArgsException &e)
     {
@@ -314,7 +315,7 @@ Java_org_oic_simulator_SimulatorManager_setPlatformInfo
 
 JNIEXPORT void JNICALL
 Java_org_oic_simulator_SimulatorManager_getPlatformInformation
-(JNIEnv *env, jobject object, jobject listener)
+(JNIEnv *env, jobject object, jstring hostUri, jobject listener)
 {
     VALIDATE_CALLBACK(env, listener)
 
@@ -326,7 +327,8 @@ Java_org_oic_simulator_SimulatorManager_getPlatformInformation
 
     try
     {
-        SimulatorManager::getInstance()->getPlatformInfo(callback);
+        JniString jniHostUri(env, hostUri);
+        SimulatorManager::getInstance()->getPlatformInfo(jniHostUri.get(), callback);
     }
     catch (InvalidArgsException &e)
     {
index d363d0b..63babf1 100644 (file)
@@ -492,18 +492,58 @@ class ValueConverterCpp
 
         void getValue(jobject &jValue, SimulatorResourceModel &value)
         {
+            simulatorResourceModelToCpp(m_env, jValue, value);
         }
 
         void getValue(jobject &jValue, std::vector<SimulatorResourceModel> &value)
         {
+            jobjectArray array = (jobjectArray) jValue;
+            size_t length = m_env->GetArrayLength(array);
+            std::vector<SimulatorResourceModel> result(length);
+            for (size_t i = 0; i < length; i++)
+            {
+                jobject jElement = m_env->GetObjectArrayElement(array, i);
+
+                SimulatorResourceModel element;
+                getValue(jElement, element);
+                result[i] = element;
+            }
+
+            value = result;
         }
 
         void getValue(jobject &jValue, std::vector<std::vector<SimulatorResourceModel>> &value)
         {
+            jobjectArray array = (jobjectArray) jValue;
+            size_t length = m_env->GetArrayLength(array);
+            std::vector<std::vector<SimulatorResourceModel>> result(length);
+            for (size_t i = 0; i < length; i++)
+            {
+                jobject jElement = m_env->GetObjectArrayElement(array, i);
+
+                std::vector<SimulatorResourceModel> childArray;
+                getValue(jElement, childArray);
+                value[i] = childArray;
+            }
+
+            value = result;
         }
 
         void getValue(jobject &jValue, std::vector<std::vector<std::vector<SimulatorResourceModel>>> &value)
         {
+            jobjectArray array = (jobjectArray) jValue;
+            size_t length = m_env->GetArrayLength(array);
+            std::vector<std::vector<std::vector<SimulatorResourceModel>>> result(length);
+            for (size_t i = 0; i < length; i++)
+            {
+                jobject jElement = m_env->GetObjectArrayElement(array, i);
+
+                std::vector<std::vector<SimulatorResourceModel>> childArray;
+                getValue(jElement, childArray);
+                value[i] = childArray;
+            }
+
+            value = result;
         }
 
         JNIEnv *m_env;
@@ -561,7 +601,7 @@ class JniAttributeProperty
                 jAttributeProperty = env->NewObject(gSimulatorClassRefs.attributePropertyCls, propertyCtor,
                                                     property.min(), property.max());
             }
-            else
+            else if (SimulatorResourceModel::AttributeProperty::Type::VALUE_SET == property.type())
             {
                 static jmethodID propertyCtor = env->GetMethodID(
                                                     gSimulatorClassRefs.attributePropertyCls, "<init>", "([Lorg/oic/simulator/AttributeValue;)V");
@@ -578,6 +618,10 @@ class JniAttributeProperty
                 jAttributeProperty = env->NewObject(gSimulatorClassRefs.attributePropertyCls, propertyCtor,
                                                     jValueSet);
             }
+            else
+            {
+                return jAttributeProperty;
+            }
 
             // Add child property
             if (jAttributeProperty && property.getChildProperty())
@@ -684,7 +728,8 @@ jobject simulatorResourceModelToJava(JNIEnv *env, SimulatorResourceModel &resMod
         addEntryToHashMap(env, attributesMap, jAttrName, jAttributeValue);
 
         jobject jAttributeProperty = JniAttributeProperty::toJava(env, attributeEntry.second.getProperty());
-        addEntryToHashMap(env, propertiesMap, jAttrName, jAttributeProperty);
+        if (jAttributeProperty)
+            addEntryToHashMap(env, propertiesMap, jAttrName, jAttributeProperty);
     }
 
     static jmethodID simulatorResourceModelCtor = env->GetMethodID(
index b555f0e..32bfafb 100644 (file)
@@ -21,10 +21,10 @@ package org.oic.simulator;
  */
 public class AttributeProperty {
 
-    private Type             mType     = Type.UNKNOWN;
-    private double           mMin      = -1;
-    private double           mMax      = -1;
-    private AttributeValue[] mValueSet = null;
+    private Type              mType          = Type.UNKNOWN;
+    private double            mMin           = -1;
+    private double            mMax           = -1;
+    private AttributeValue[]  mValueSet      = null;
     private AttributeProperty mChildProperty = null;
 
     /**
@@ -146,8 +146,8 @@ public class AttributeProperty {
      * API to set child attribute propety.
      *
      * @param childProperty
-     *            Child element property this property used if the
-     *            Attribute value is of array type.
+     *            Child element property this property used if the Attribute
+     *            value is of array type.
      */
     public void setChildProperty(AttributeProperty childProperty) {
         mChildProperty = childProperty;
index 935588f..30ace70 100644 (file)
@@ -1,6 +1,7 @@
 package org.oic.simulator;
 
-public class AttributeValueValidation implements AttributeValueVisitor.VisitingMethods<Boolean> {
+public class AttributeValueValidation implements
+        AttributeValueVisitor.VisitingMethods<Boolean> {
     private AttributeProperty mProperty = null;
 
     public AttributeValueValidation(AttributeProperty property) {
@@ -67,7 +68,8 @@ public class AttributeValueValidation implements AttributeValueVisitor.VisitingM
             return false;
 
         if (mProperty.getChildProperty() != null) {
-            AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty());
+            AttributeValueValidation rangeValidation = new AttributeValueValidation(
+                    mProperty.getChildProperty());
             for (Integer value : values) {
                 if (rangeValidation.visitingValue(value) == false)
                     return false;
@@ -86,7 +88,8 @@ public class AttributeValueValidation implements AttributeValueVisitor.VisitingM
             return false;
 
         if (mProperty.getChildProperty() != null) {
-            AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty());
+            AttributeValueValidation rangeValidation = new AttributeValueValidation(
+                    mProperty.getChildProperty());
             for (Double value : values) {
                 if (rangeValidation.visitingValue(value) == false)
                     return false;
@@ -105,7 +108,8 @@ public class AttributeValueValidation implements AttributeValueVisitor.VisitingM
             return false;
 
         if (mProperty.getChildProperty() != null) {
-            AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty());
+            AttributeValueValidation rangeValidation = new AttributeValueValidation(
+                    mProperty.getChildProperty());
             for (Boolean value : values) {
                 if (rangeValidation.visitingValue(value) == false)
                     return false;
@@ -124,7 +128,8 @@ public class AttributeValueValidation implements AttributeValueVisitor.VisitingM
             return false;
 
         if (mProperty.getChildProperty() != null) {
-            AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty());
+            AttributeValueValidation rangeValidation = new AttributeValueValidation(
+                    mProperty.getChildProperty());
             for (String value : values) {
                 if (rangeValidation.visitingValue(value) == false)
                     return false;
@@ -148,7 +153,8 @@ public class AttributeValueValidation implements AttributeValueVisitor.VisitingM
             return false;
 
         if (mProperty.getChildProperty() != null) {
-            AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty());
+            AttributeValueValidation rangeValidation = new AttributeValueValidation(
+                    mProperty.getChildProperty());
             for (Integer[] value : values) {
                 if (rangeValidation.visitingValue(value) == false)
                     return false;
@@ -167,7 +173,8 @@ public class AttributeValueValidation implements AttributeValueVisitor.VisitingM
             return false;
 
         if (mProperty.getChildProperty() != null) {
-            AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty());
+            AttributeValueValidation rangeValidation = new AttributeValueValidation(
+                    mProperty.getChildProperty());
             for (Double[] value : values) {
                 if (rangeValidation.visitingValue(value) == false)
                     return false;
@@ -186,7 +193,8 @@ public class AttributeValueValidation implements AttributeValueVisitor.VisitingM
             return false;
 
         if (mProperty.getChildProperty() != null) {
-            AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty());
+            AttributeValueValidation rangeValidation = new AttributeValueValidation(
+                    mProperty.getChildProperty());
             for (Boolean[] value : values) {
                 if (rangeValidation.visitingValue(value) == false)
                     return false;
@@ -205,7 +213,8 @@ public class AttributeValueValidation implements AttributeValueVisitor.VisitingM
             return false;
 
         if (mProperty.getChildProperty() != null) {
-            AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty());
+            AttributeValueValidation rangeValidation = new AttributeValueValidation(
+                    mProperty.getChildProperty());
             for (String[] value : values) {
                 if (rangeValidation.visitingValue(value) == false)
                     return false;
@@ -229,7 +238,8 @@ public class AttributeValueValidation implements AttributeValueVisitor.VisitingM
             return false;
 
         if (mProperty.getChildProperty() != null) {
-            AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty());
+            AttributeValueValidation rangeValidation = new AttributeValueValidation(
+                    mProperty.getChildProperty());
             for (Integer[][] value : values) {
                 if (rangeValidation.visitingValue(value) == false)
                     return false;
@@ -248,7 +258,8 @@ public class AttributeValueValidation implements AttributeValueVisitor.VisitingM
             return false;
 
         if (mProperty.getChildProperty() != null) {
-            AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty());
+            AttributeValueValidation rangeValidation = new AttributeValueValidation(
+                    mProperty.getChildProperty());
             for (Double[][] value : values) {
                 if (rangeValidation.visitingValue(value) == false)
                     return false;
@@ -267,7 +278,8 @@ public class AttributeValueValidation implements AttributeValueVisitor.VisitingM
             return false;
 
         if (mProperty.getChildProperty() != null) {
-            AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty());
+            AttributeValueValidation rangeValidation = new AttributeValueValidation(
+                    mProperty.getChildProperty());
             for (Boolean[][] value : values) {
                 if (rangeValidation.visitingValue(value) == false)
                     return false;
@@ -286,7 +298,8 @@ public class AttributeValueValidation implements AttributeValueVisitor.VisitingM
             return false;
 
         if (mProperty.getChildProperty() != null) {
-            AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty());
+            AttributeValueValidation rangeValidation = new AttributeValueValidation(
+                    mProperty.getChildProperty());
             for (String[][] value : values) {
                 if (rangeValidation.visitingValue(value) == false)
                     return false;
@@ -311,7 +324,8 @@ public class AttributeValueValidation implements AttributeValueVisitor.VisitingM
     }
 
     private <T> boolean checkValueSet(T value) {
-        if (AttributeProperty.Type.VALUESET == mProperty.type() && null != mProperty.valueSet()) {
+        if (AttributeProperty.Type.VALUESET == mProperty.type()
+                && null != mProperty.valueSet()) {
             for (AttributeValue allowedValue : mProperty.valueSet()) {
                 if (allowedValue.get().equals(value))
                     return true;
index 28fc0fb..0d2cea5 100644 (file)
@@ -1,7 +1,7 @@
 package org.oic.simulator;
 
 public class AttributeValueVisitor {
-    private AttributeValue mValue;
+    private AttributeValue  mValue;
     private VisitingMethods mListener;
 
     public interface VisitingMethods<T extends Object> {
@@ -65,7 +65,8 @@ public class AttributeValueVisitor {
                 if (2 == typeInfo.mDepth)
                     return mListener.visitingValue((Integer[][]) mValue.get());
                 if (3 == typeInfo.mDepth)
-                    return mListener.visitingValue((Integer[][][]) mValue.get());
+                    return mListener
+                            .visitingValue((Integer[][][]) mValue.get());
             }
         } else if (AttributeValue.ValueType.DOUBLE == typeInfo.mBaseType) {
             if (AttributeValue.ValueType.DOUBLE == typeInfo.mType)
@@ -87,7 +88,8 @@ public class AttributeValueVisitor {
                 if (2 == typeInfo.mDepth)
                     return mListener.visitingValue((Boolean[][]) mValue.get());
                 if (3 == typeInfo.mDepth)
-                    return mListener.visitingValue((Boolean[][][]) mValue.get());
+                    return mListener
+                            .visitingValue((Boolean[][][]) mValue.get());
             }
         } else if (AttributeValue.ValueType.STRING == typeInfo.mBaseType) {
             if (AttributeValue.ValueType.STRING == typeInfo.mType)
@@ -102,14 +104,21 @@ public class AttributeValueVisitor {
             }
         } else if (AttributeValue.ValueType.RESOURCEMODEL == typeInfo.mBaseType) {
             if (AttributeValue.ValueType.RESOURCEMODEL == typeInfo.mType)
-                return mListener.visitingValue((SimulatorResourceModel) mValue.get());
+                return mListener.visitingValue((SimulatorResourceModel) mValue
+                        .get());
             else if (AttributeValue.ValueType.ARRAY == typeInfo.mType) {
                 if (1 == typeInfo.mDepth)
-                    return mListener.visitingValue((SimulatorResourceModel[]) mValue.get());
+                    return mListener
+                            .visitingValue((SimulatorResourceModel[]) mValue
+                                    .get());
                 if (2 == typeInfo.mDepth)
-                    return mListener.visitingValue((SimulatorResourceModel[][]) mValue.get());
+                    return mListener
+                            .visitingValue((SimulatorResourceModel[][]) mValue
+                                    .get());
                 if (3 == typeInfo.mDepth)
-                    return mListener.visitingValue((SimulatorResourceModel[][][]) mValue.get());
+                    return mListener
+                            .visitingValue((SimulatorResourceModel[][][]) mValue
+                                    .get());
             }
         }
 
index 4f4fb5e..e4d3772 100644 (file)
@@ -148,11 +148,14 @@ public class SimulatorManager {
     /**
      * API to search for devices in the network.
      *
+     * @param hostUri
+     *            URI of the host device.
      * @param listener
      *            Listener for receiving the device information.
      */
-    public static native void findDevices(DeviceListener listener)
-            throws InvalidArgsException, SimulatorException;
+    public static native void findDevices(String hostUri,
+            DeviceListener listener) throws InvalidArgsException,
+            SimulatorException;
 
     /**
      * API to set the platform information.
@@ -166,11 +169,14 @@ public class SimulatorManager {
     /**
      * API to find all devices' platform information in the network.
      *
+     * @param hostUri
+     *            URI of the host device.
      * @param listener
      *            Listener for receiving the platform information.
      */
-    public static native void getPlatformInformation(PlatformListener listener)
-            throws InvalidArgsException, SimulatorException;
+    public static native void getPlatformInformation(String hostUri,
+            PlatformListener listener) throws InvalidArgsException,
+            SimulatorException;
 
     /**
      * API to set the listener for receiving log messages.
index e2db0f4..e8bbb39 100644 (file)
@@ -78,10 +78,9 @@ public class SimulatorResourceAttribute {
     }
 
     /**
-     * API to get propety of attribute's value.
+     * API to get property of attribute's value.
      *
-     * @return Attribute's value property        {@AttributeProperty
-     * }.
+     * @return Attribute's value property {@AttributeProperty}.
      */
     public AttributeProperty property() {
         return mProperty;
@@ -89,11 +88,21 @@ public class SimulatorResourceAttribute {
 
     /**
      * API to set the value of attribute.
-     * 
+     *
      * @param value
      *            Value of the attribute.
      */
     public void setValue(AttributeValue value) {
         this.mValue = value;
     }
+
+    /**
+     * API to set the property of attribute.
+     *
+     * @param value
+     *            Property of the attribute.
+     */
+    public void setProperty(AttributeProperty property) {
+        this.mProperty = property;
+    }
 }
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) {
index b519c07..b9fcb62 100755 (executable)
@@ -31,6 +31,9 @@ SimulatorCollectionResourceImpl::SimulatorCollectionResourceImpl()
         m_resourceHandle(NULL)
 {
     m_property = static_cast<OCResourceProperty>(OC_DISCOVERABLE | OC_OBSERVABLE);
+
+    std::vector<SimulatorResourceModel> links;
+    m_resModel.add("links", links);
 }
 
 std::string SimulatorCollectionResourceImpl::getName() const
@@ -234,6 +237,11 @@ void SimulatorCollectionResourceImpl::setActionType(std::map<RAML::ActionType, R
     m_actionTypes = actionType;
 }
 
+void SimulatorCollectionResourceImpl::setActionType(std::map<RAML::ActionType, RAML::ActionPtr> &actionType)
+{
+    m_actionTypes = actionType;
+}
+
 std::vector<ObserverInfo> SimulatorCollectionResourceImpl::getObserversList()
 {
     return m_observersList;
@@ -601,4 +609,4 @@ RAML::ActionType SimulatorCollectionResourceImpl::getActionType(std::string requ
         return RAML::ActionType::DELETE;
 
     return RAML::ActionType::NONE;
-}
\ No newline at end of file
+}
index 001cbb3..4b10c14 100644 (file)
@@ -49,7 +49,7 @@ std::shared_ptr<SimulatorResource> SimulatorManager::createResource(
     VALIDATE_INPUT(configPath.empty(), "Empty path!")
 
     std::shared_ptr<SimulatorResource> resource =
-            SimulatorResourceFactory::getInstance()->createResource(configPath);
+        SimulatorResourceFactory::getInstance()->createResource(configPath);
     if (!resource)
         throw SimulatorException(SIMULATOR_ERROR, "Failed to create resource!");
     return resource;
@@ -62,7 +62,7 @@ std::vector<std::shared_ptr<SimulatorResource>> SimulatorManager::createResource
     VALIDATE_INPUT(!count, "Count is zero!")
 
     std::vector<std::shared_ptr<SimulatorResource>> resources =
-            SimulatorResourceFactory::getInstance()->createResource(configPath, count);
+                SimulatorResourceFactory::getInstance()->createResource(configPath, count);
     if (!resources.size())
         throw SimulatorException(SIMULATOR_ERROR, "Failed to create resource!");
     return resources;
@@ -133,7 +133,7 @@ void SimulatorManager::findResource(const std::string &resourceType,
                      CT_DEFAULT, findCallback);
 }
 
-void SimulatorManager::getDeviceInfo(DeviceInfoCallback callback)
+void SimulatorManager::getDeviceInfo(const std::string &host, DeviceInfoCallback callback)
 {
     VALIDATE_CALLBACK(callback)
 
@@ -149,14 +149,11 @@ void SimulatorManager::getDeviceInfo(DeviceInfoCallback callback)
         callback(deviceInfo);
     }, std::placeholders::_1, callback);
 
-    std::ostringstream uri;
-    uri << OC_MULTICAST_PREFIX << OC_RSRVD_DEVICE_URI;
-
     typedef OCStackResult (*GetDeviceInfo)(const std::string &, const std::string &,
                                            OCConnectivityType, OC::FindDeviceCallback);
 
-    invokeocplatform(static_cast<GetDeviceInfo>(OC::OCPlatform::getDeviceInfo), "",
-                     uri.str(), CT_DEFAULT, deviceCallback);
+    invokeocplatform(static_cast<GetDeviceInfo>(OC::OCPlatform::getDeviceInfo), host.c_str(),
+                     "/oic/d", CT_DEFAULT, deviceCallback);
 }
 
 void SimulatorManager::setDeviceInfo(const std::string &deviceName)
@@ -171,7 +168,7 @@ void SimulatorManager::setDeviceInfo(const std::string &deviceName)
                      ocDeviceInfo);
 }
 
-void SimulatorManager::getPlatformInfo(PlatformInfoCallback callback)
+void SimulatorManager::getPlatformInfo(const std::string &host, PlatformInfoCallback callback)
 {
     VALIDATE_CALLBACK(callback)
 
@@ -194,14 +191,11 @@ void SimulatorManager::getPlatformInfo(PlatformInfoCallback callback)
         callback(platformInfo);
     }, std::placeholders::_1, callback);
 
-    std::ostringstream uri;
-    uri << OC_MULTICAST_PREFIX << OC_RSRVD_PLATFORM_URI;
-
     typedef OCStackResult (*GetPlatformInfo)(const std::string &, const std::string &,
             OCConnectivityType, OC::FindPlatformCallback);
 
-    invokeocplatform(static_cast<GetPlatformInfo>(OC::OCPlatform::getPlatformInfo), "",
-                     uri.str(), CT_DEFAULT, platformCallback);
+    invokeocplatform(static_cast<GetPlatformInfo>(OC::OCPlatform::getPlatformInfo), host.c_str(),
+                     "/oic/p", CT_DEFAULT, platformCallback);
 }
 
 void SimulatorManager::setPlatformInfo(PlatformInfo &platformInfo)
index 96618f4..8ba72fa 100644 (file)
@@ -46,8 +46,7 @@ public class AttributeValueValidationTest extends TestCase {
     }
 
     public void testValidateInt_N03() {
-        AttributeValueValidation validation = new AttributeValueValidation(
-                null);
+        AttributeValueValidation validation = new AttributeValueValidation(null);
         assertFalse(validation.validate(new AttributeValue(6)));
     }
 
@@ -164,8 +163,7 @@ public class AttributeValueValidationTest extends TestCase {
     }
 
     public void testValidateDouble_N03() {
-        AttributeValueValidation validation = new AttributeValueValidation(
-                null);
+        AttributeValueValidation validation = new AttributeValueValidation(null);
         assertFalse(validation.validate(new AttributeValue(6.0)));
     }
 
index c63170a..4d195a1 100644 (file)
@@ -611,7 +611,7 @@ public class SimulatorManagerTest extends TestCase {
 
         try {
             SimulatorManager.setDeviceInfo("Samsung");
-            SimulatorManager.findDevices(listener);
+            SimulatorManager.findDevices(null, listener);
             syncResult = true;
         } catch (InvalidArgsException e) {
             e.printStackTrace();
@@ -634,7 +634,7 @@ public class SimulatorManagerTest extends TestCase {
         ExceptionType exType = ExceptionType.UNKNOWN;
 
         try {
-            SimulatorManager.findDevices(null);
+            SimulatorManager.findDevices(null, null);
         } catch (InvalidArgsException e) {
             exType = ExceptionType.INVALID_ARGS;
         } catch (SimulatorException e) {
@@ -652,7 +652,7 @@ public class SimulatorManagerTest extends TestCase {
                 infoHolder);
 
         try {
-            SimulatorManager.getPlatformInformation(listener);
+            SimulatorManager.getPlatformInformation(null, listener);
             syncResult = true;
         } catch (InvalidArgsException e) {
             e.printStackTrace();
@@ -675,7 +675,7 @@ public class SimulatorManagerTest extends TestCase {
         ExceptionType exType = ExceptionType.UNKNOWN;
 
         try {
-            SimulatorManager.getPlatformInformation(null);
+            SimulatorManager.getPlatformInformation(null, null);
         } catch (InvalidArgsException e) {
             exType = ExceptionType.INVALID_ARGS;
         } catch (SimulatorException e) {