Simulator Plug-ins: Bug fixing and enhancements.
authorG S Senthil Kumar <senthil.gs@samsung.com>
Mon, 23 Nov 2015 16:25:24 +0000 (21:55 +0530)
committerMadan Lanka <lanka.madan@samsung.com>
Tue, 24 Nov 2015 05:31:04 +0000 (05:31 +0000)
1. Resolved minor issues in resource creation, invalid URIs and editing attribute values.
2. Updated the APIs to get the device and platform information by address.
3. Showing all properties of device in service provider plug-in.

Change-Id: I810f3110c0587a34042361c4d0be109ba9f7f646
Signed-off-by: G S Senthil Kumar <senthil.gs@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/4313
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: RadhaBhavani <radha.p@samsung.com>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
42 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/DeviceAndPlatformInfo.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/AttributeValueBuilder.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/AttributeEditingSupport.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/AttributeView.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/MetaPropertiesView.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/listener/IDeviceInfoUIListener.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/UiListenerHandler.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/AttributeHelper.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/AttributeValueBuilder.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Constants.java
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/DevicePlatformInfoView.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/MetaPropertiesView.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/ResourceManagerView.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddAttributeDialog.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CollectionResourceBasicDetailsPage.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CreateResourceWizard.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteResourceWizard.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/LoadRamlPage.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/MainPage.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/ResourceWizardDialog.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourceAddAttributePage.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourceBasicDetailsPage.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourcePage.java [deleted file]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/UpdatePropertiesPage.java
service/simulator/java/jni/simulator_device_info_jni.cpp
service/simulator/java/jni/simulator_device_info_jni.h
service/simulator/java/jni/simulator_manager_jni.cpp
service/simulator/java/jni/simulator_platform_info_jni.cpp
service/simulator/java/jni/simulator_platform_info_jni.h
service/simulator/java/sdk/src/org/oic/simulator/DeviceListener.java
service/simulator/java/sdk/src/org/oic/simulator/PlatformListener.java
service/simulator/src/server/simulator_single_resource_impl.cpp
service/simulator/src/simulator_manager.cpp

index ea039cb..d381d32 100644 (file)
@@ -551,17 +551,19 @@ class ClientController
 
             try
             {
-                SimulatorManager::getInstance()->getDeviceInfo(resource->getHost(), std::bind([](DeviceInfo & deviceInfo)
+                SimulatorManager::getInstance()->getDeviceInfo(resource->getHost(),
+                    std::bind([](const std::string & host, DeviceInfo & deviceInfo)
                 {
                     std::cout << "###Device Information received...." << std::endl;
                     std::ostringstream out;
+                    out << "Host URI: " << host << std::endl;
                     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));
+                }, std::placeholders::_1, std::placeholders::_2));
             }
             catch (InvalidArgsException &e)
             {
@@ -583,10 +585,12 @@ class ClientController
 
             try
             {
-                SimulatorManager::getInstance()->getPlatformInfo(resource->getHost(), std::bind([](PlatformInfo & platformInfo)
+                SimulatorManager::getInstance()->getPlatformInfo(resource->getHost(),
+                    std::bind([](const std::string & host, PlatformInfo & platformInfo)
                 {
                     std::cout << "###Platform Information received...." << std::endl;
                     std::ostringstream out;
+                    out << "Host URI: " << host << std::endl;
                     out << "Platform ID: " << platformInfo.getPlatformID() << std::endl;
                     out << "Platform version: " << platformInfo.getPlatformVersion() << std::endl;
                     out << "Manufacturer name: " << platformInfo.getManufacturerName() << std::endl;
@@ -600,7 +604,7 @@ class ClientController
                     out << "System time: " << platformInfo.getSystemTime() << std::endl;
 
                     std::cout << out.str() << std::endl;
-                }, std::placeholders::_1));
+                }, std::placeholders::_1, std::placeholders::_2));
             }
             catch (InvalidArgsException &e)
             {
index 6ba4572..0b92092 100644 (file)
@@ -38,8 +38,8 @@
 #include "simulator_exceptions.h"
 #include "simulator_logger.h"
 
-typedef std::function<void(DeviceInfo &deviceInfo)> DeviceInfoCallback;
-typedef std::function<void(PlatformInfo &platformInfo)> PlatformInfoCallback;
+typedef std::function<void(const std::string &hostUri, DeviceInfo &deviceInfo)> DeviceInfoCallback;
+typedef std::function<void(const std::string &hostUri, PlatformInfo &platformInfo)> PlatformInfoCallback;
 
 /**
  * @class   SimulatorManager
index 3de0d3e..63b22c6 100644 (file)
@@ -38,6 +38,7 @@ import oic.simulator.clientcontroller.listener.IPostUIListener;
 import oic.simulator.clientcontroller.listener.IPutUIListener;
 import oic.simulator.clientcontroller.listener.IResourceSelectionChangedUIListener;
 import oic.simulator.clientcontroller.listener.IVerificationUIListener;
+import oic.simulator.clientcontroller.remoteresource.DeviceAndPlatformInfo;
 import oic.simulator.clientcontroller.remoteresource.MetaProperty;
 import oic.simulator.clientcontroller.remoteresource.RemoteResource;
 import oic.simulator.clientcontroller.utils.Constants;
@@ -112,14 +113,15 @@ public class ResourceManager {
     // Maintaining a list of observed resource URIs.
     private List<String>                              observedResourceURIList;
 
-    private DeviceInfo                                devInfo;
-    private PlatformInfo                              platInfo;
+    private Map<String, DeviceAndPlatformInfo>        hostDeviceAndPlatformMap;
 
     public ResourceManager() {
         resourceMap = new HashMap<String, RemoteResource>();
         favoriteResources = new ArrayList<RemoteResource>();
         favoriteURIList = new ArrayList<String>();
         observedResourceURIList = new ArrayList<String>();
+        hostDeviceAndPlatformMap = new HashMap<String, DeviceAndPlatformInfo>();
+
         findResourceUIListeners = new ArrayList<IFindResourceUIListener>();
         resourceSelectionChangedUIListeners = new ArrayList<IResourceSelectionChangedUIListener>();
         getUIListeners = new ArrayList<IGetUIListener>();
@@ -210,22 +212,38 @@ public class ResourceManager {
                                                     null));
                         }
 
-                        // Get the device and platform information
-                        try {
-                            SimulatorManager.findDevices(resource
-                                    .getRemoteResourceRef().getHost(),
-                                    deviceListener);
-                            SimulatorManager.getPlatformInformation(resource
-                                    .getRemoteResourceRef().getHost(),
-                                    platformListener);
-                        } catch (SimulatorException e) {
-                            Activator
-                                    .getDefault()
-                                    .getLogManager()
-                                    .log(Level.ERROR.ordinal(),
-                                            new Date(),
-                                            Utility.getSimulatorErrorString(e,
-                                                    null));
+                        // Get the device information
+                        if (!isDeviceInfoExist(resourceN.getHost())) {
+                            try {
+                                SimulatorManager.findDevices(resource
+                                        .getRemoteResourceRef().getHost(),
+                                        deviceListener);
+                            } catch (SimulatorException e) {
+                                Activator
+                                        .getDefault()
+                                        .getLogManager()
+                                        .log(Level.ERROR.ordinal(),
+                                                new Date(),
+                                                Utility.getSimulatorErrorString(
+                                                        e, null));
+                            }
+                        }
+
+                        // Get the platform information
+                        if (!isPlatformInfoExist(resourceN.getHost())) {
+                            try {
+                                SimulatorManager.getPlatformInformation(
+                                        resource.getRemoteResourceRef()
+                                                .getHost(), platformListener);
+                            } catch (SimulatorException e) {
+                                Activator
+                                        .getDefault()
+                                        .getLogManager()
+                                        .log(Level.ERROR.ordinal(),
+                                                new Date(),
+                                                Utility.getSimulatorErrorString(
+                                                        e, null));
+                            }
                         }
                     }
                 });
@@ -236,14 +254,24 @@ public class ResourceManager {
         deviceListener = new DeviceListener() {
 
             @Override
-            public void onDeviceFound(final DeviceInfo deviceInfo) {
-                if (null == deviceInfo) {
+            public void onDeviceFound(final String host,
+                    final DeviceInfo deviceInfo) {
+                if (null == deviceInfo || null == host) {
                     return;
                 }
                 synchronizerThread.addToQueue(new Runnable() {
                     @Override
                     public void run() {
-                        setDeviceInfo(deviceInfo);
+                        synchronized (hostDeviceAndPlatformMap) {
+                            DeviceAndPlatformInfo info = hostDeviceAndPlatformMap
+                                    .get(host);
+                            if (null == info) {
+                                info = new DeviceAndPlatformInfo();
+                                info.setHost(host);
+                                hostDeviceAndPlatformMap.put(host, info);
+                            }
+                            info.setDeviceInfo(deviceInfo);
+                        }
 
                         // Notify UI listeners
                         deviceInfoReceivedNotification();
@@ -255,14 +283,24 @@ public class ResourceManager {
         platformListener = new PlatformListener() {
 
             @Override
-            public void onPlatformFound(final PlatformInfo platformInfo) {
-                if (null == platformInfo) {
+            public void onPlatformFound(final String host,
+                    final PlatformInfo platformInfo) {
+                if (null == platformInfo || null == host) {
                     return;
                 }
                 synchronizerThread.addToQueue(new Runnable() {
                     @Override
                     public void run() {
-                        setPlatformInfo(platformInfo);
+                        synchronized (hostDeviceAndPlatformMap) {
+                            DeviceAndPlatformInfo info = hostDeviceAndPlatformMap
+                                    .get(host);
+                            if (null == info) {
+                                info = new DeviceAndPlatformInfo();
+                                info.setHost(host);
+                                hostDeviceAndPlatformMap.put(host, info);
+                            }
+                            info.setPlatformInfo(platformInfo);
+                        }
 
                         // Notify UI listeners
                         platformInfoReceivedNotification();
@@ -487,20 +525,26 @@ public class ResourceManager {
         return resource;
     }
 
-    public synchronized DeviceInfo getDeviceInfo() {
-        return devInfo;
-    }
-
-    public synchronized void setDeviceInfo(DeviceInfo devInfo) {
-        this.devInfo = devInfo;
-    }
-
-    public synchronized PlatformInfo getPlatformInfo() {
-        return platInfo;
+    public synchronized boolean isDeviceInfoExist(String host) {
+        DeviceAndPlatformInfo info = hostDeviceAndPlatformMap.get(host);
+        if (null == info) {
+            return false;
+        }
+        if (null == info.getDeviceInfo()) {
+            return false;
+        }
+        return true;
     }
 
-    public synchronized void setPlatformInfo(PlatformInfo platInfo) {
-        this.platInfo = platInfo;
+    public synchronized boolean isPlatformInfoExist(String host) {
+        DeviceAndPlatformInfo info = hostDeviceAndPlatformMap.get(host);
+        if (null == info) {
+            return false;
+        }
+        if (null == info.getPlatformInfo()) {
+            return false;
+        }
+        return true;
     }
 
     private static class ResponseSynchronizerThread implements Runnable {
@@ -1020,6 +1064,9 @@ public class ResourceManager {
                         // Delete all cached details of resources
                         resourceMap.clear();
                         favoriteResources.clear();
+
+                        // Clearing the device and platform information
+                        hostDeviceAndPlatformMap.clear();
                     }
                     // Change the current resource in selection
                     setCurrentResourceInSelection(null);
@@ -1094,6 +1141,11 @@ public class ResourceManager {
                         removeResourceFromFavorites(resource);
                         // Remove the resource
                         keyItr.remove();
+                        // Remove the device and platform information
+                        synchronized (hostDeviceAndPlatformMap) {
+                            hostDeviceAndPlatformMap.remove(resource
+                                    .getRemoteResourceRef().getHost());
+                        }
                     }
                 }
             }
@@ -1160,20 +1212,48 @@ public class ResourceManager {
     }
 
     public List<MetaProperty> getDeviceProperties() {
-        if (null == devInfo) {
+        if (null == currentResourceInSelection) {
             return null;
         }
 
-        List<MetaProperty> metaProperties = new ArrayList<MetaProperty>();
+        SimulatorRemoteResource remoteResource = currentResourceInSelection
+                .getRemoteResourceRef();
+        if (null == remoteResource) {
+            return null;
+        }
+
+        String host = remoteResource.getHost();
+        if (null == host) {
+            return null;
+        }
+
+        if (!isDeviceInfoExist(host)) {
+            // Device Information
+            try {
+                SimulatorManager.findDevices(host, deviceListener);
+            } catch (SimulatorException e) {
+                Activator
+                        .getDefault()
+                        .getLogManager()
+                        .log(Level.ERROR.ordinal(), new Date(),
+                                Utility.getSimulatorErrorString(e, null));
+            }
+            return null;
+        }
 
-        metaProperties.add(new MetaProperty(Constants.DEVICE_ID, devInfo
-                .getID()));
-        metaProperties.add(new MetaProperty(Constants.DEVICE_NAME, devInfo
-                .getName()));
-        metaProperties.add(new MetaProperty(Constants.DEVICE_SPEC_VERSION,
-                devInfo.getSpecVersion()));
-        metaProperties.add(new MetaProperty(Constants.DEVICE_DMV_VERSION,
-                devInfo.getDataModelVersion()));
+        List<MetaProperty> metaProperties = new ArrayList<MetaProperty>();
+        synchronized (hostDeviceAndPlatformMap) {
+            DeviceInfo devInfo = hostDeviceAndPlatformMap.get(host)
+                    .getDeviceInfo();
+            metaProperties.add(new MetaProperty(Constants.DEVICE_ID, devInfo
+                    .getID()));
+            metaProperties.add(new MetaProperty(Constants.DEVICE_NAME, devInfo
+                    .getName()));
+            metaProperties.add(new MetaProperty(Constants.DEVICE_SPEC_VERSION,
+                    devInfo.getSpecVersion()));
+            metaProperties.add(new MetaProperty(Constants.DEVICE_DMV_VERSION,
+                    devInfo.getDataModelVersion()));
+        }
 
         /*
          * metaProperties.add(new MetaProperty(Constants.DEVICE_ID, ""));
@@ -1186,37 +1266,66 @@ public class ResourceManager {
     }
 
     public List<MetaProperty> getPlatformProperties() {
-        if (null == platInfo) {
+        if (null == currentResourceInSelection) {
             return null;
         }
 
-        List<MetaProperty> metaProperties = new ArrayList<MetaProperty>();
+        SimulatorRemoteResource remoteResource = currentResourceInSelection
+                .getRemoteResourceRef();
+        if (null == remoteResource) {
+            return null;
+        }
 
-        metaProperties.add(new MetaProperty(Constants.PLATFORM_ID, platInfo
-                .getPlatformID()));
-        metaProperties.add(new MetaProperty(Constants.PLATFORM_MANUFAC_NAME,
-                platInfo.getManufacturerName()));
-        metaProperties.add(new MetaProperty(Constants.PLATFORM_MANUFAC_URL,
-                platInfo.getManufacturerUrl()));
-        metaProperties.add(new MetaProperty(Constants.PLATFORM_MODEL_NO,
-                platInfo.getModelNumber()));
-        metaProperties.add(new MetaProperty(Constants.PLATFORM_DATE_OF_MANUFAC,
-                platInfo.getDateOfManufacture()));
-        metaProperties.add(new MetaProperty(Constants.PLATFORM_VERSION,
-                platInfo.getPlatformVersion()));
-        metaProperties.add(new MetaProperty(Constants.PLATFORM_OS_VERSION,
-                platInfo.getOperationSystemVersion()));
-        metaProperties.add(new MetaProperty(
-                Constants.PLATFORM_HARDWARE_VERSION, platInfo
-                        .getHardwareVersion()));
-        metaProperties.add(new MetaProperty(
-                Constants.PLATFORM_FIRMWARE_VERSION, platInfo
-                        .getFirmwareVersion()));
-        metaProperties.add(new MetaProperty(Constants.PLATFORM_SUPPORT_URL,
-                platInfo.getSupportUrl()));
-        metaProperties.add(new MetaProperty(Constants.PLATFORM_SYSTEM_TIME,
-                platInfo.getSystemTime()));
+        String host = remoteResource.getHost();
+        if (null == host) {
+            return null;
+        }
 
+        if (!isPlatformInfoExist(host)) {
+            // Platform Information
+            try {
+                SimulatorManager.getPlatformInformation(host, platformListener);
+            } catch (SimulatorException e) {
+                Activator
+                        .getDefault()
+                        .getLogManager()
+                        .log(Level.ERROR.ordinal(), new Date(),
+                                Utility.getSimulatorErrorString(e, null));
+            }
+            return null;
+        }
+
+        List<MetaProperty> metaProperties = new ArrayList<MetaProperty>();
+        synchronized (hostDeviceAndPlatformMap) {
+            PlatformInfo platInfo = hostDeviceAndPlatformMap.get(host)
+                    .getPlatformInfo();
+            metaProperties.add(new MetaProperty(Constants.PLATFORM_ID, platInfo
+                    .getPlatformID()));
+            metaProperties.add(new MetaProperty(
+                    Constants.PLATFORM_MANUFAC_NAME, platInfo
+                            .getManufacturerName()));
+            metaProperties.add(new MetaProperty(Constants.PLATFORM_MANUFAC_URL,
+                    platInfo.getManufacturerUrl()));
+            metaProperties.add(new MetaProperty(Constants.PLATFORM_MODEL_NO,
+                    platInfo.getModelNumber()));
+            metaProperties.add(new MetaProperty(
+                    Constants.PLATFORM_DATE_OF_MANUFAC, platInfo
+                            .getDateOfManufacture()));
+            metaProperties.add(new MetaProperty(Constants.PLATFORM_VERSION,
+                    platInfo.getPlatformVersion()));
+            metaProperties.add(new MetaProperty(Constants.PLATFORM_OS_VERSION,
+                    platInfo.getOperationSystemVersion()));
+            metaProperties.add(new MetaProperty(
+                    Constants.PLATFORM_HARDWARE_VERSION, platInfo
+                            .getHardwareVersion()));
+            metaProperties.add(new MetaProperty(
+                    Constants.PLATFORM_FIRMWARE_VERSION, platInfo
+                            .getFirmwareVersion()));
+            metaProperties.add(new MetaProperty(Constants.PLATFORM_SUPPORT_URL,
+                    platInfo.getSupportUrl()));
+            metaProperties.add(new MetaProperty(Constants.PLATFORM_SYSTEM_TIME,
+                    platInfo.getSystemTime()));
+        }
         /*
          * metaProperties.add(new MetaProperty(Constants.PLATFORM_ID, ""));
          * metaProperties .add(new MetaProperty(Constants.PLATFORM_MANUFAC_NAME,
diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/DeviceAndPlatformInfo.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/DeviceAndPlatformInfo.java
new file mode 100644 (file)
index 0000000..73ca5ff
--- /dev/null
@@ -0,0 +1,34 @@
+package oic.simulator.clientcontroller.remoteresource;
+
+import org.oic.simulator.DeviceInfo;
+import org.oic.simulator.PlatformInfo;
+
+public class DeviceAndPlatformInfo {
+    private String       host;
+    private DeviceInfo   deviceInfo;
+    private PlatformInfo platformInfo;
+
+    public String getHost() {
+        return host;
+    }
+
+    public void setHost(String host) {
+        this.host = host;
+    }
+
+    public DeviceInfo getDeviceInfo() {
+        return deviceInfo;
+    }
+
+    public void setDeviceInfo(DeviceInfo deviceInfo) {
+        this.deviceInfo = deviceInfo;
+    }
+
+    public PlatformInfo getPlatformInfo() {
+        return platformInfo;
+    }
+
+    public void setPlatformInfo(PlatformInfo platformInfo) {
+        this.platformInfo = platformInfo;
+    }
+}
index 1716846..7a3cca1 100644 (file)
@@ -70,14 +70,23 @@ public class AttributeValueBuilder {
         if (0 != findDepth(valueString))
             return null;
 
-        if (valueType == AttributeValue.ValueType.INTEGER)
-            return new AttributeValue(Integer.parseInt(valueString));
-        else if (valueType == AttributeValue.ValueType.DOUBLE)
-            return new AttributeValue(Double.parseDouble(valueString));
-        else if (valueType == AttributeValue.ValueType.BOOLEAN)
-            return new AttributeValue(Boolean.parseBoolean(valueString));
-        else if (valueType == AttributeValue.ValueType.STRING)
-            return new AttributeValue(valueString);
+        try {
+            if (valueType == AttributeValue.ValueType.INTEGER)
+                return new AttributeValue(Integer.parseInt(valueString));
+            else if (valueType == AttributeValue.ValueType.DOUBLE) {
+                Double value = Double.parseDouble(valueString);
+                if (!value.isInfinite()) {
+                    return new AttributeValue(value);
+                }
+            } else if (valueType == AttributeValue.ValueType.BOOLEAN) {
+                if (valueString.equalsIgnoreCase("true")
+                        || valueString.equalsIgnoreCase("false"))
+                    return new AttributeValue(Boolean.parseBoolean(valueString));
+            } else if (valueType == AttributeValue.ValueType.STRING)
+                return new AttributeValue(valueString);
+        } catch (Exception e) {
+            return null;
+        }
         return null;
     }
 
index 0120f9d..a58b42c 100644 (file)
@@ -127,7 +127,6 @@ public class AttributeEditingSupport {
 
                 @Override
                 public void modifyText(ModifyEvent event) {
-
                     String newValue = comboBox.getText();
 
                     if (null != newValue && !newValue.isEmpty()) {
@@ -136,31 +135,6 @@ public class AttributeEditingSupport {
                         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);
@@ -214,23 +188,6 @@ public class AttributeEditingSupport {
             }
 
             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));
@@ -239,10 +196,18 @@ public class AttributeEditingSupport {
                 // 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) {
+                boolean invalid = false;
+                if (null == attValue) {
+                    invalid = true;
+                } else {
+                    TypeInfo resTypeInfo = attValue.typeInfo();
+                    if (type.mDepth != resTypeInfo.mDepth
+                            || type.mType != resTypeInfo.mType
+                            || type.mBaseType != resTypeInfo.mBaseType) {
+                        invalid = true;
+                    }
+                }
+                if (invalid) {
                     MessageBox dialog = new MessageBox(viewer.getTree()
                             .getShell(), SWT.ICON_ERROR | SWT.OK);
                     dialog.setText("Invalid Value");
index 953e8f0..ec1ded7 100644 (file)
@@ -303,6 +303,7 @@ public class AttributeView extends ViewPart {
         Tree tree = attViewer.getTree();
         if (null != resource) {
             attViewer.setInput(resource.getResourceRepresentation());
+            attViewer.expandAll();
             if (!tree.isDisposed()) {
                 tree.setLinesVisible(true);
             }
@@ -467,15 +468,17 @@ public class AttributeView extends ViewPart {
                 PlatformUI.getWorkbench().getDisplay().syncExec(new Thread() {
                     @Override
                     public void run() {
-                        if (resourceInSelection.isPutAutomtnInProgress()) {
-                            MessageDialog
-                                    .openInformation(Display.getDefault()
-                                            .getActiveShell(), "PUT Request",
-                                            "PUT Automation is in progress. Please wait or stop the automation.");
-                            return;
+                        boolean attributesExist = false;
+                        ResourceRepresentation rep = resourceInSelection
+                                .getResourceRepresentation();
+                        if (null != rep) {
+                            Map<String, AttributeElement> attributes = rep
+                                    .getAttributes();
+                            if (null != attributes && !attributes.isEmpty()) {
+                                attributesExist = true;
+                            }
                         }
-                        if (resourceInSelection.getResourceRepresentation()
-                                .getAttributes().size() < 1) {
+                        if (!attributesExist) {
                             MessageDialog
                                     .openInformation(Display.getDefault()
                                             .getActiveShell(), "PUT Request",
@@ -501,15 +504,17 @@ public class AttributeView extends ViewPart {
                 PlatformUI.getWorkbench().getDisplay().syncExec(new Thread() {
                     @Override
                     public void run() {
-                        if (resourceInSelection.isPostAutomtnInProgress()) {
-                            MessageDialog
-                                    .openInformation(Display.getDefault()
-                                            .getActiveShell(), "POST Request",
-                                            "POST Automation is in progress. Please wait or stop the automation.");
-                            return;
+                        boolean attributesExist = false;
+                        ResourceRepresentation rep = resourceInSelection
+                                .getResourceRepresentation();
+                        if (null != rep) {
+                            Map<String, AttributeElement> attributes = rep
+                                    .getAttributes();
+                            if (null != attributes && !attributes.isEmpty()) {
+                                attributesExist = true;
+                            }
                         }
-                        if (resourceInSelection.getResourceRepresentation()
-                                .getAttributes().size() < 1) {
+                        if (!attributesExist) {
                             MessageDialog
                                     .openInformation(Display.getDefault()
                                             .getActiveShell(), "POST Request",
index acf8933..cbc51a8 100644 (file)
@@ -94,8 +94,9 @@ public class MetaPropertiesView extends ViewPart {
 
                     @Override
                     public void run() {
-                        if (null != deviceTblViewer) {
-                            updateViewer(deviceTblViewer, getDevicePropData());
+                        if (null != platformTblViewer) {
+                            updateViewer(platformTblViewer,
+                                    getPlatformPropData());
                         }
                     }
                 });
@@ -108,9 +109,8 @@ public class MetaPropertiesView extends ViewPart {
 
                     @Override
                     public void run() {
-                        if (null != platformTblViewer) {
-                            updateViewer(platformTblViewer,
-                                    getPlatformPropData());
+                        if (null != deviceTblViewer) {
+                            updateViewer(deviceTblViewer, getDevicePropData());
                         }
                     }
                 });
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IDeviceInfoUIListener.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IDeviceInfoUIListener.java
new file mode 100644 (file)
index 0000000..509f717
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * 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.serviceprovider.listener;
+
+public interface IDeviceInfoUIListener {
+    public void onDeviceInfoFound();
+}
index d7a8e20..49fdb46 100644 (file)
@@ -27,12 +27,27 @@ import java.util.Map;
 import java.util.Set;
 import java.util.Vector;
 
+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;
+
 import org.eclipse.swt.widgets.Display;
 import org.oic.simulator.AttributeProperty;
 import org.oic.simulator.AttributeProperty.Type;
 import org.oic.simulator.AttributeValue;
 import org.oic.simulator.AttributeValue.TypeInfo;
 import org.oic.simulator.AttributeValue.ValueType;
+import org.oic.simulator.DeviceInfo;
+import org.oic.simulator.DeviceListener;
 import org.oic.simulator.ILogger.Level;
 import org.oic.simulator.PlatformInfo;
 import org.oic.simulator.SimulatorException;
@@ -48,19 +63,6 @@ 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
@@ -82,13 +84,17 @@ public class ResourceManager {
 
     private ObserverListener               observer;
 
+    private DeviceListener                 deviceListener;
+
     private NotificationSynchronizerThread synchronizerThread;
 
     private Thread                         threadHandle;
 
-    private String                         deviceName;
+    private DeviceInfo                     deviceInfo;
     private PlatformInfo                   platformInfo;
 
+    private String                         deviceName;
+
     public ResourceManager() {
         data = new Data();
 
@@ -130,6 +136,47 @@ public class ResourceManager {
                                     + Utility.getSimulatorErrorString(e, null));
         }
 
+        deviceListener = new DeviceListener() {
+
+            @Override
+            public void onDeviceFound(final String host,
+                    final DeviceInfo deviceInfo) {
+                if (null != ResourceManager.this.deviceInfo
+                        || null == deviceInfo || null == host) {
+                    return;
+                }
+                synchronizerThread.addToQueue(new Runnable() {
+                    @Override
+                    public void run() {
+                        String rcvdDeviceName = deviceInfo.getName();
+                        if (null == rcvdDeviceName) {
+                            return;
+                        }
+                        if (deviceName.equalsIgnoreCase(rcvdDeviceName)) {
+                            ResourceManager.this.deviceInfo = deviceInfo;
+
+                            // Notify the UI Listeners
+                            UiListenerHandler.getInstance()
+                                    .deviceInfoReceivedNotification();
+                        }
+                    }
+                });
+            }
+        };
+
+        // Get the device information to show other details of the device in UI.
+        try {
+            SimulatorManager.findDevices("", deviceListener);
+        } catch (SimulatorException e) {
+            Activator
+                    .getDefault()
+                    .getLogManager()
+                    .log(Level.ERROR.ordinal(),
+                            new Date(),
+                            "Failed to get the local device information.\n"
+                                    + Utility.getSimulatorErrorString(e, null));
+        }
+
         resourceModelChangeListener = new ResourceModelChangeListener() {
 
             @Override
@@ -298,12 +345,30 @@ public class ResourceManager {
         }
     }
 
-    public String getDeviceName() {
-        return deviceName;
-    }
+    public void setDeviceInfo(List<MetaProperty> metaProperties) {
+        if (null == metaProperties || metaProperties.size() < 1) {
+            return;
+        }
+        Iterator<MetaProperty> itr = metaProperties.iterator();
+        MetaProperty prop;
+        String propName;
+        String propValue;
+        boolean found = false;
+        while (itr.hasNext()) {
+            prop = itr.next();
+            propName = prop.getPropName();
+            propValue = prop.getPropValue();
+            if (propName.equals(Constants.DEVICE_NAME)) {
+                this.deviceName = propValue;
+                found = true;
+                break;
+            }
+        }
+
+        if (!found) {
+            return;
+        }
 
-    public void setDeviceName(String deviceName) {
-        this.deviceName = deviceName;
         try {
             SimulatorManager.setDeviceInfo(deviceName);
         } catch (SimulatorException e) {
@@ -317,6 +382,43 @@ public class ResourceManager {
         }
     }
 
+    public boolean isDeviceInfoValid(List<MetaProperty> metaProperties) {
+        if (null == metaProperties || metaProperties.size() < 1) {
+            return false;
+        }
+
+        Iterator<MetaProperty> itr = metaProperties.iterator();
+        MetaProperty prop;
+        String propName;
+        String propValue;
+        while (itr.hasNext()) {
+            prop = itr.next();
+            propName = prop.getPropName();
+            propValue = prop.getPropValue();
+            if (propName.equals(Constants.DEVICE_NAME)) {
+                if (null == propValue || propValue.length() < 1) {
+                    return false;
+                }
+                break;
+            }
+        }
+        return true;
+    }
+
+    public List<MetaProperty> getDeviceInfo() {
+        List<MetaProperty> metaProperties = new ArrayList<MetaProperty>();
+        metaProperties.add(new MetaProperty(Constants.DEVICE_NAME, deviceName));
+        if (null != deviceInfo) {
+            metaProperties.add(new MetaProperty(Constants.DEVICE_ID, deviceInfo
+                    .getID()));
+            metaProperties.add(new MetaProperty(Constants.DEVICE_SPEC_VERSION,
+                    deviceInfo.getSpecVersion()));
+            metaProperties.add(new MetaProperty(Constants.DEVICE_DMV,
+                    deviceInfo.getDataModelVersion()));
+        }
+        return metaProperties;
+    }
+
     public List<MetaProperty> getPlatformInfo() {
         List<MetaProperty> metaProperties = new ArrayList<MetaProperty>();
         metaProperties.add(new MetaProperty(Constants.PLATFORM_ID, platformInfo
@@ -395,6 +497,23 @@ public class ResourceManager {
         }
     }
 
+    public boolean isPlatformInfoValid(List<MetaProperty> metaProperties) {
+        if (null == metaProperties || metaProperties.size() < 1) {
+            return false;
+        }
+        Iterator<MetaProperty> itr = metaProperties.iterator();
+        MetaProperty prop;
+        String propValue;
+        while (itr.hasNext()) {
+            prop = itr.next();
+            propValue = prop.getPropValue();
+            if (null == propValue || propValue.length() < 1) {
+                return false;
+            }
+        }
+        return true;
+    }
+
     public synchronized Resource getCurrentResourceInSelection() {
         return currentResourceInSelection;
     }
@@ -837,7 +956,7 @@ public class ResourceManager {
         return createCount;
     }
 
-    public void createDevice(String deviceName, Set<Resource> childs) {
+    public Device createDevice(String deviceName, Set<Resource> childs) {
         // 1. Create device
         Device dev = new Device();
         dev.setDeviceName(deviceName);
@@ -850,6 +969,7 @@ public class ResourceManager {
         // 3. Update ui listeners
         UiListenerHandler.getInstance().resourceListUpdateUINotification(
                 ResourceType.DEVICE);
+        return dev;
     }
 
     private Map<String, LocalResourceAttribute> fetchResourceAttributesFromModel(
@@ -892,39 +1012,6 @@ public class ResourceManager {
 
     }
 
-    // This method gives all known possible values of the attribute in string
-    // format. It takes allowed values or range of values whichever is available
-    private List<String> getValueList(SimulatorResourceAttribute attributeN) {
-        AttributeProperty attProp = attributeN.property();
-        if (null == attProp) {
-            return null;
-        }
-        List<String> valueList = new ArrayList<String>();
-        Type valuesType = attProp.type();
-        if (valuesType == Type.VALUESET) {
-            Object[] allowedValues = attProp.valueSet();
-            if (null != allowedValues && allowedValues.length > 0) {
-                for (Object value : allowedValues) {
-                    if (null != value) {
-                        valueList.add(String.valueOf(((AttributeValue) value)
-                                .get()));
-                    }
-                }
-            }
-        } else if (valuesType == Type.RANGE) {
-            double minD = attProp.min();
-            double maxD = attProp.max();
-            for (double value = minD; value <= maxD; value++) {
-                valueList.add(String.valueOf(value));
-            }
-        }
-        Object attValue = attributeN.value().get();
-        if (valueList.size() < 1 && null != attValue) {
-            valueList.add(String.valueOf(attValue));
-        }
-        return valueList;
-    }
-
     public List<Resource> getResourceList() {
         List<Resource> resourceList = data.getResources();
         if (null == resourceList) {
@@ -1655,6 +1742,22 @@ public class ResourceManager {
         }
 
         String curURI = resource.getResourceURI();
+        setResourceURI(resource, newURI);
+
+        try {
+            if (!startResource(resource)) {
+                return false;
+            }
+        } catch (SimulatorException e) {
+            setResourceURI(resource, curURI);
+        }
+
+        return true;
+    }
+
+    public void setResourceURI(Resource resource, String newURI)
+            throws SimulatorException {
+        String curURI = resource.getResourceURI();
         SimulatorResource server = resource.getSimulatorResource();
         try {
             server.setURI(newURI);
@@ -1669,11 +1772,6 @@ public class ResourceManager {
                                     + Utility.getSimulatorErrorString(e, null));
             throw e;
         }
-
-        if (!startResource(resource)) {
-            return false;
-        }
-        return true;
     }
 
     public boolean updateResourceProperties(Resource resource,
@@ -1856,8 +1954,14 @@ public class ResourceManager {
             prop = itr.next();
             if (prop.getPropName().equals(propName)) {
                 String value = prop.getPropValue();
-                if (null == value || value.trim().isEmpty()) {
-                    invalid = true;
+                if (propName.equals(Constants.RESOURCE_URI)) {
+                    if (!Utility.isUriValid(value)) {
+                        invalid = true;
+                    }
+                } else {
+                    if (null == value || value.trim().isEmpty()) {
+                        invalid = true;
+                    }
                 }
             }
         }
index 8d1535f..2e98c09 100644 (file)
@@ -21,6 +21,7 @@ import java.util.Iterator;
 import java.util.List;
 
 import oic.simulator.serviceprovider.listener.IAutomationUIListener;
+import oic.simulator.serviceprovider.listener.IDeviceInfoUIListener;
 import oic.simulator.serviceprovider.listener.IObserverListChangedUIListener;
 import oic.simulator.serviceprovider.listener.IPropertiesChangedUIListener;
 import oic.simulator.serviceprovider.listener.IResourceListChangedUIListener;
@@ -47,6 +48,8 @@ public class UiListenerHandler {
 
     private List<IPropertiesChangedUIListener>    propertiesChangedUIListeners;
 
+    private List<IDeviceInfoUIListener>           deviceInfoUIListeners;
+
     private UiListenerHandler() {
         resourceListChangedUIListeners = new ArrayList<IResourceListChangedUIListener>();
         selectionChangedUIListeners = new ArrayList<ISelectionChangedUIListener>();
@@ -54,6 +57,7 @@ public class UiListenerHandler {
         automationUIListeners = new ArrayList<IAutomationUIListener>();
         observerUIListeners = new ArrayList<IObserverListChangedUIListener>();
         propertiesChangedUIListeners = new ArrayList<IPropertiesChangedUIListener>();
+        deviceInfoUIListeners = new ArrayList<IDeviceInfoUIListener>();
     }
 
     public static UiListenerHandler getInstance() {
@@ -158,6 +162,19 @@ public class UiListenerHandler {
         }
     }
 
+    public void addDeviceInfoUIListener(IDeviceInfoUIListener deviceUIListener) {
+        synchronized (deviceInfoUIListeners) {
+            deviceInfoUIListeners.add(deviceUIListener);
+        }
+    }
+
+    public void removeDeviceInfoUIListener(
+            IDeviceInfoUIListener platformUIListener) {
+        synchronized (deviceInfoUIListeners) {
+            deviceInfoUIListeners.remove(platformUIListener);
+        }
+    }
+
     public void resourceCreatedUINotification(ResourceType type) {
         synchronized (resourceListChangedUIListeners) {
             if (resourceListChangedUIListeners.size() > 0) {
@@ -303,7 +320,7 @@ public class UiListenerHandler {
         }
     }
 
-    public void propertiesChangedUINotification(Class targetClass) {
+    public void propertiesChangedUINotification(Class<?> targetClass) {
         synchronized (propertiesChangedUIListeners) {
             if (propertiesChangedUIListeners.size() > 0) {
                 IPropertiesChangedUIListener listener;
@@ -322,4 +339,20 @@ public class UiListenerHandler {
             }
         }
     }
+
+    public void deviceInfoReceivedNotification() {
+        synchronized (deviceInfoUIListeners) {
+            if (deviceInfoUIListeners.size() > 0) {
+                IDeviceInfoUIListener listener;
+                Iterator<IDeviceInfoUIListener> listenerItr = deviceInfoUIListeners
+                        .iterator();
+                while (listenerItr.hasNext()) {
+                    listener = listenerItr.next();
+                    if (null != listener) {
+                        listener.onDeviceInfoFound();
+                    }
+                }
+            }
+        }
+    }
 }
index 50d6a49..d0549c5 100644 (file)
@@ -17,6 +17,7 @@
 package oic.simulator.serviceprovider.model;
 
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.Set;
 
 import oic.simulator.serviceprovider.utils.Constants;
@@ -252,7 +253,14 @@ public class AttributeHelper {
                         min = Double.parseDouble(this.min);
                         max = Double.parseDouble(this.max);
                         dflValue = Double.parseDouble(value);
-                        if (dflValue < min || dflValue > max) {
+                        boolean found = false;
+                        for (double val = min; val <= max; val += 1.0) {
+                            if (dflValue == val) {
+                                found = true;
+                                break;
+                            }
+                        }
+                        if (!found) {
                             result = false;
                         }
                     } catch (Exception e) {
@@ -261,7 +269,33 @@ public class AttributeHelper {
                 }
             } else if (validValuesType == Type.VALUESET
                     && null != allowedValues && !allowedValues.isEmpty()) {
-                result = allowedValues.contains(value);
+                boolean found = false;
+                if (attributeType.equals(Constants.INT)) {
+                    Iterator<String> itr = allowedValues.iterator();
+                    while (itr.hasNext()) {
+                        String val = itr.next();
+                        int v1 = Integer.parseInt(val);
+                        int v2 = Integer.parseInt(value);
+                        if (v1 == v2) {
+                            found = true;
+                            break;
+                        }
+                    }
+                } else {
+                    Iterator<String> itr = allowedValues.iterator();
+                    while (itr.hasNext()) {
+                        String val = itr.next();
+                        double v1 = Double.parseDouble(val);
+                        double v2 = Double.parseDouble(value);
+                        if (v1 == v2) {
+                            found = true;
+                            break;
+                        }
+                    }
+                }
+                if (!found) {
+                    result = false;
+                }
             }
         }
         return result;
@@ -321,6 +355,7 @@ public class AttributeHelper {
                 } else {
                     attProperty = null;
                 }
+                break;
             case DOUBLE:
                 attValue = new AttributeValue(
                         Double.parseDouble(attributeDflValue));
index fdebf0e..7c05136 100644 (file)
@@ -70,14 +70,23 @@ public class AttributeValueBuilder {
         if (0 != findDepth(valueString))
             return null;
 
-        if (valueType == AttributeValue.ValueType.INTEGER)
-            return new AttributeValue(Integer.parseInt(valueString));
-        else if (valueType == AttributeValue.ValueType.DOUBLE)
-            return new AttributeValue(Double.parseDouble(valueString));
-        else if (valueType == AttributeValue.ValueType.BOOLEAN)
-            return new AttributeValue(Boolean.parseBoolean(valueString));
-        else if (valueType == AttributeValue.ValueType.STRING)
-            return new AttributeValue(valueString);
+        try {
+            if (valueType == AttributeValue.ValueType.INTEGER)
+                return new AttributeValue(Integer.parseInt(valueString));
+            else if (valueType == AttributeValue.ValueType.DOUBLE) {
+                Double value = Double.parseDouble(valueString);
+                if (!value.isInfinite()) {
+                    return new AttributeValue(value);
+                }
+            } else if (valueType == AttributeValue.ValueType.BOOLEAN) {
+                if (valueString.equalsIgnoreCase("true")
+                        || valueString.equalsIgnoreCase("false"))
+                    return new AttributeValue(Boolean.parseBoolean(valueString));
+            } else if (valueType == AttributeValue.ValueType.STRING)
+                return new AttributeValue(valueString);
+        } catch (Exception e) {
+            return null;
+        }
         return null;
     }
 
index ef56513..aaf574e 100644 (file)
@@ -26,7 +26,7 @@ public class Constants {
 
     public static final String         INT                                                  = "Int";
     public static final String         DOUBLE                                               = "Double";
-    public static final String         BOOL                                                 = "Bool";
+    public static final String         BOOL                                                 = "Boolean";
     public static final String         STRING                                               = "String";
     public static final String         UNKNOWN                                              = "Unknown";
 
@@ -42,7 +42,6 @@ public class Constants {
     public static final String         RESOURCE_TYPE                                        = "Resource Type";
     public static final String         RESOURCE_TYPES                                       = "Resource Types";
     public static final String         RESOURCE_NAME                                        = "Resource Name";
-    public static final String         DEVICE_NAME                                          = "Device Name";
     public static final String         RESOURCE_UID                                         = "Resource ID";
     public static final String         CONNECTIVITY_TYPE                                    = "Connectivity Type";
 
@@ -124,6 +123,12 @@ public class Constants {
     public static final String         PLATFORM_SUPPORT_URL                                 = "Support URL";
     public static final String         PLATFORM_SYSTEM_TIME                                 = "System Time";
 
+    // Device information
+    public static final String         DEVICE_NAME                                          = "Device Name";
+    public static final String         DEVICE_ID                                            = "Device ID";
+    public static final String         DEVICE_SPEC_VERSION                                  = "Spec Version";
+    public static final String         DEVICE_DMV                                           = "Data Model Version";
+
     public static final String         SAMPLE_LIGHT                                         = "sample.light";
 
     public static final String         UPDATE_PROP_PAGE_TITLE                               = "Update Properties";
@@ -152,11 +157,10 @@ public class Constants {
     public static final String         SIMPLE_RESOURCE_OTHER_DETAILS_PAGE_TITLE             = "Create Simple Resource(Step 3 of 3)";
     public static final String         SIMPLE_RESOURCE_OTHER_DETAILS_PAGE_MESSAGE           = "Fill other details of the resource";
 
-    public static final String         COLLECTION_RESOURCE_BASIC_DETAILS_PAGE_TITLE1        = "Create Collection Resource";
-    public static final String         COLLECTION_RESOURCE_BASIC_DETAILS_PAGE_TITLE2        = "Create Collection Resource(Step 1 of 2)";
+    public static final String         COLLECTION_RESOURCE_BASIC_DETAILS_PAGE_TITLE         = "Create Collection Resource";
     public static final String         COLLECTION_RESOURCE_BASIC_DETAILS_PAGE_MESSAGE       = "Fill basic details of the resource";
 
-    public static final String         COLLECTION_RESOURCE_ADD_OTHER_RESOURCES_PAGE_TITLE   = "Create Collection Resource(Step 2 of 2)";
+    public static final String         COLLECTION_RESOURCE_ADD_OTHER_RESOURCES_PAGE_TITLE   = "Create Collection Resource";
     public static final String         COLLECTION_RESOURCE_ADD_OTHER_RESOURCES_PAGE_MESSAGE = "Add other resources to this collection resource";
 
     public static final String         CREATE_DEVICE_PAGE_TITLE                             = "Create Device";
@@ -165,5 +169,7 @@ public class Constants {
     public static final String         DEVICE                                               = "Create Device";
     public static final String         SINGLE_RESOURCE                                      = "Single Resource";
     public static final String         COLLECTION_RESOURCE                                  = "Collection Resource";
+    public static final String         INVALID_URI_MESSAGE                                  = "Resource URI should start with a '/' followed by atleast one character and it should not contain either # or ? or % or consecutive '/'.";
+    public static final int            TREE_EXPANSION_LEVEL                                 = 10;
 
 }
\ No newline at end of file
index 8b3f2f5..317d51d 100644 (file)
@@ -802,4 +802,13 @@ public class Utility {
         return localAtt;
     }
 
+    public static boolean isUriValid(String resURI) {
+        if (null == resURI || resURI.length() < 2 || !resURI.startsWith("/")
+                || resURI.contains("//") || resURI.contains("?")
+                || resURI.contains("#") || resURI.contains("%")) {
+            return false;
+        }
+        return true;
+    }
+
 }
\ No newline at end of file
index b9de9d2..ebd6439 100644 (file)
@@ -166,10 +166,18 @@ public class AttributeEditingSupport {
                         // 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) {
+                        boolean invalid = false;
+                        if (null == value) {
+                            invalid = true;
+                        } else {
+                            TypeInfo resTypeInfo = value.typeInfo();
+                            if (type.mDepth != resTypeInfo.mDepth
+                                    || type.mType != resTypeInfo.mType
+                                    || type.mBaseType != resTypeInfo.mBaseType) {
+                                invalid = true;
+                            }
+                        }
+                        if (invalid) {
                             MessageBox dialog = new MessageBox(viewer.getTree()
                                     .getShell(), SWT.ICON_ERROR | SWT.OK);
                             dialog.setText("Invalid Value");
@@ -270,11 +278,18 @@ public class AttributeEditingSupport {
                         // 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) {
+                        boolean invalid = false;
+                        if (null == attValue) {
+                            invalid = true;
+                        } else {
+                            TypeInfo resTypeInfo = attValue.typeInfo();
+                            if (type.mDepth != resTypeInfo.mDepth
+                                    || type.mType != resTypeInfo.mType
+                                    || type.mBaseType != resTypeInfo.mBaseType) {
+                                invalid = true;
+                            }
+                        }
+                        if (invalid) {
                             MessageBox dialog = new MessageBox(viewer.getTree()
                                     .getShell(), SWT.ICON_ERROR | SWT.OK);
                             dialog.setText("Invalid Value");
@@ -365,7 +380,6 @@ public class AttributeEditingSupport {
 
         public SimulatorResourceAttribute getResultantValue(
                 AttributeValue newValue) {
-            AttributeValue val = null;
             IStructuredSelection selection = (IStructuredSelection) viewer
                     .getSelection();
             if (null == selection) {
@@ -463,6 +477,10 @@ public class AttributeEditingSupport {
                 return null;
             }
 
+            if (((AttributeElement) element).isReadOnly()) {
+                return null;
+            }
+
             return new CheckboxCellEditor(null, SWT.CHECK | SWT.READ_ONLY);
         }
 
index 5806cec..1068b70 100644 (file)
@@ -89,20 +89,25 @@ public class AttributeView extends ViewPart {
                     @Override
                     public void run() {
                         if (null != attViewer) {
+                            Tree tree = attViewer.getTree();
+                            if (null == tree || tree.isDisposed()) {
+                                return;
+                            }
                             if (null != resource
                                     && null != resource
-                                            .getResourceRepresentation())
+                                            .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); } }
-                             */
+                                attViewer.expandAll();
+                                if (null != tree) {
+                                    tree.setLinesVisible(true);
+                                }
+                            } else {
+                                attViewer.setInput(null);
+                                if (null != tree) {
+                                    tree.setLinesVisible(false);
+                                }
+                            }
                         }
                     }
                 });
@@ -113,7 +118,14 @@ public class AttributeView extends ViewPart {
                 Display.getDefault().asyncExec(new Runnable() {
                     @Override
                     public void run() {
-                        updateViewer(null);
+                        if (null != attViewer) {
+                            Tree tree = attViewer.getTree();
+                            if (null != tree && !tree.isDisposed()) {
+                                // tbl.deselectAll();
+                                tree.removeAll();
+                                tree.setLinesVisible(false);
+                            }
+                        }
                     }
                 });
             }
@@ -133,17 +145,6 @@ 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)); } }
-                         */
                     }
                 });
             }
@@ -310,37 +311,6 @@ public class AttributeView extends ViewPart {
                 automationUIListener);
     }
 
-    private List<LocalResourceAttribute> getData(Resource resource) {
-        if (null != resource) {
-            List<LocalResourceAttribute> attList = resourceManager
-                    .getAttributes((Resource) resource);
-            // List<LocalResourceAttribute> attList =
-            // Utility.getDummyAttributes();
-            return attList;
-        } else {
-            return null;
-        }
-    }
-
-    private void updateViewer(List<LocalResourceAttribute> attList) {
-        Tree tree = attViewer.getTree();;
-        if (null != attList) {
-            if (null != tree && !tree.isDisposed()) {
-                tree.setLinesVisible(true);
-                attViewer.setInput(attList.toArray());
-            }
-        } else {
-            // Clear the attributes table viewer
-            if (null != attViewer) {
-                if (null != tree && !tree.isDisposed()) {
-                    // tbl.deselectAll();
-                    tree.removeAll();
-                    tree.setLinesVisible(false);
-                }
-            }
-        }
-    }
-
     class AttributeContentProvider implements ITreeContentProvider,
             DataChangeListener {
 
@@ -397,6 +367,7 @@ public class AttributeView extends ViewPart {
                 @Override
                 public void run() {
                     mTreeViewer.refresh(attribute.getParent());
+                    mTreeViewer.expandAll();
                 }
             });
         }
@@ -407,6 +378,7 @@ public class AttributeView extends ViewPart {
                 @Override
                 public void run() {
                     mTreeViewer.refresh(attribute.getParent());
+                    mTreeViewer.expandAll();
                 }
             });
         }
@@ -417,6 +389,7 @@ public class AttributeView extends ViewPart {
                 @Override
                 public void run() {
                     mTreeViewer.update(attribute, null);
+                    mTreeViewer.expandAll();
                 }
             });
         }
index b8ebf77..a89dcc6 100644 (file)
@@ -19,7 +19,10 @@ package oic.simulator.serviceprovider.view;
 import java.util.List;
 
 import oic.simulator.serviceprovider.Activator;
+import oic.simulator.serviceprovider.listener.IDeviceInfoUIListener;
+import oic.simulator.serviceprovider.manager.UiListenerHandler;
 import oic.simulator.serviceprovider.model.MetaProperty;
+import oic.simulator.serviceprovider.utils.Constants;
 
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.viewers.CellEditor;
@@ -44,9 +47,7 @@ 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.Label;
 import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.part.ViewPart;
 
 /**
@@ -62,21 +63,49 @@ public class DevicePlatformInfoView extends ViewPart {
 
     private final Integer[]    columnWidth   = { 150, 150 };
 
-    private List<MetaProperty> metaProperties;
+    enum PropertiesType {
+        DEVICE, PLATFORM
+    }
+
+    private List<MetaProperty>    deviceProperties;
+    private List<MetaProperty>    platformProperties;
+
+    private boolean               enableDeviceEdit;
+    private boolean               enablePlatformEdit;
 
-    private boolean            enable_edit;
+    private Button                devEditBtn;
+    private Button                devCancelBtn;
+    private Button                platEditBtn;
+    private Button                platCancelBtn;
 
-    private Text               deviceNameTxt;
-    private Button             devEditBtn;
-    private Button             devCancelBtn;
-    private Button             platEditBtn;
-    private Button             platCancelBtn;
+    private TableViewer           platformTblViewer;
+    private TableViewer           deviceTblViewer;
 
-    private TableViewer        platformTblViewer;
+    private CTabFolder            folder;
+    private CTabItem              devicePropTab;
+    private CTabItem              platformPropTab;
 
-    private CTabFolder         folder;
-    private CTabItem           devicePropTab;
-    private CTabItem           platformPropTab;
+    private IDeviceInfoUIListener deviceInfoUIListener;
+
+    public DevicePlatformInfoView() {
+        deviceInfoUIListener = new IDeviceInfoUIListener() {
+
+            @Override
+            public void onDeviceInfoFound() {
+                Display.getDefault().asyncExec(new Runnable() {
+
+                    @Override
+                    public void run() {
+                        if (null != deviceTblViewer) {
+                            updateViewer(deviceTblViewer, getDevicePropData());
+                        }
+                    }
+                });
+            }
+        };
+
+        addManagerListeners();
+    }
 
     @Override
     public void createPartControl(Composite parent) {
@@ -98,9 +127,18 @@ public class DevicePlatformInfoView extends ViewPart {
 
         folder.setSelection(devicePropTab);
 
-        metaProperties = getPlatformPropData();
+        platformProperties = getPlatformPropData();
+
+        updateViewer(platformTblViewer, platformProperties);
 
-        updateViewer(metaProperties);
+        deviceProperties = getDevicePropData();
+
+        updateViewer(deviceTblViewer, deviceProperties);
+    }
+
+    private void addManagerListeners() {
+        UiListenerHandler.getInstance().addDeviceInfoUIListener(
+                deviceInfoUIListener);
     }
 
     private void createDevicePropertiesTab() {
@@ -115,27 +153,23 @@ public class DevicePlatformInfoView extends ViewPart {
 
         propGroup.setLayout(new GridLayout(2, false));
         GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
-        gd.horizontalIndent = 5;
-        gd.verticalIndent = 5;
         propGroup.setLayoutData(gd);
 
-        Label devNameLbl = new Label(propGroup, SWT.NULL);
-        devNameLbl.setText("Device Name");
-        gd = new GridData();
-        gd.horizontalAlignment = SWT.FILL;
-        gd.grabExcessHorizontalSpace = true;
-        gd.horizontalSpan = 2;
-        devNameLbl.setLayoutData(gd);
+        deviceTblViewer = new TableViewer(propGroup, SWT.SINGLE | SWT.H_SCROLL
+                | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
 
-        deviceNameTxt = new Text(propGroup, SWT.BORDER);
-        deviceNameTxt.setText(Activator.getDefault().getResourceManager()
-                .getDeviceName());
-        gd = new GridData();
-        gd.horizontalAlignment = SWT.FILL;
-        gd.grabExcessHorizontalSpace = true;
+        createColumns(deviceTblViewer, PropertiesType.DEVICE);
+
+        // Make lines and header visible
+        final Table table = deviceTblViewer.getTable();
+        table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+        table.setHeaderVisible(true);
+        table.setLinesVisible(true);
+        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
         gd.horizontalSpan = 2;
-        deviceNameTxt.setLayoutData(gd);
-        deviceNameTxt.setEnabled(false);
+        table.setLayoutData(gd);
+
+        deviceTblViewer.setContentProvider(new PropertycontentProvider());
 
         devEditBtn = new Button(propGroup, SWT.PUSH);
         devEditBtn.setText("Edit");
@@ -146,26 +180,22 @@ public class DevicePlatformInfoView extends ViewPart {
             @Override
             public void widgetSelected(SelectionEvent e) {
                 if (devEditBtn.getText().equals("Edit")) {
-                    deviceNameTxt.setEnabled(true);
                     devCancelBtn.setEnabled(true);
-
-                    deviceNameTxt.selectAll();
-                    deviceNameTxt.setFocus();
                     devEditBtn.setText("Save");
+                    enableDeviceEdit = true;
                 } else {
-                    String devName = deviceNameTxt.getText();
-                    if (null == devName || devName.trim().length() < 1) {
+                    if (Activator.getDefault().getResourceManager()
+                            .isDeviceInfoValid(deviceProperties)) {
+                        Activator.getDefault().getResourceManager()
+                                .setDeviceInfo(deviceProperties);
+                        devCancelBtn.setEnabled(false);
+                        devEditBtn.setText("Edit");
+                        enableDeviceEdit = false;
+                    } else {
                         MessageDialog.openError(Display.getDefault()
-                                .getActiveShell(), "Invalid Device Name",
-                                "Device name is Invalid!!");
-                        deviceNameTxt.setFocus();
-                        return;
+                                .getActiveShell(), "Invalid value",
+                                "Property value cannot be empty.");
                     }
-                    Activator.getDefault().getResourceManager()
-                            .setDeviceName(devName);
-                    deviceNameTxt.setEnabled(false);
-                    devCancelBtn.setEnabled(false);
-                    devEditBtn.setText("Edit");
                 }
             }
         });
@@ -179,11 +209,12 @@ public class DevicePlatformInfoView extends ViewPart {
         devCancelBtn.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
-                deviceNameTxt.setText(Activator.getDefault()
-                        .getResourceManager().getDeviceName());
-                deviceNameTxt.setEnabled(false);
+                deviceProperties = getDevicePropData();
+                updateViewer(deviceTblViewer, deviceProperties);
+
                 devCancelBtn.setEnabled(false);
                 devEditBtn.setText("Edit");
+                enableDeviceEdit = false;
             }
         });
 
@@ -207,7 +238,7 @@ public class DevicePlatformInfoView extends ViewPart {
         platformTblViewer = new TableViewer(propGroup, SWT.SINGLE
                 | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
 
-        createColumns(platformTblViewer);
+        createColumns(platformTblViewer, PropertiesType.PLATFORM);
 
         // Make lines and header visible
         final Table table = platformTblViewer.getTable();
@@ -231,13 +262,20 @@ public class DevicePlatformInfoView extends ViewPart {
                 if (platEditBtn.getText().equals("Edit")) {
                     platCancelBtn.setEnabled(true);
                     platEditBtn.setText("Save");
-                    enable_edit = true;
+                    enablePlatformEdit = true;
                 } else {
-                    Activator.getDefault().getResourceManager()
-                            .setPlatformInfo(metaProperties);
-                    platCancelBtn.setEnabled(false);
-                    platEditBtn.setText("Edit");
-                    enable_edit = false;
+                    if (Activator.getDefault().getResourceManager()
+                            .isPlatformInfoValid(platformProperties)) {
+                        Activator.getDefault().getResourceManager()
+                                .setPlatformInfo(platformProperties);
+                        platCancelBtn.setEnabled(false);
+                        platEditBtn.setText("Edit");
+                        enablePlatformEdit = false;
+                    } else {
+                        MessageDialog.openError(Display.getDefault()
+                                .getActiveShell(), "Invalid value",
+                                "Property value cannot be empty.");
+                    }
                 }
             }
         });
@@ -251,19 +289,19 @@ public class DevicePlatformInfoView extends ViewPart {
         platCancelBtn.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
-                metaProperties = getPlatformPropData();
-                updateViewer(metaProperties);
+                platformProperties = getPlatformPropData();
+                updateViewer(platformTblViewer, platformProperties);
 
                 platCancelBtn.setEnabled(false);
                 platEditBtn.setText("Edit");
-                enable_edit = false;
+                enablePlatformEdit = false;
             }
         });
 
         platformPropTab.setControl(propGroup);
     }
 
-    public void createColumns(TableViewer tableViewer) {
+    public void createColumns(TableViewer tableViewer, PropertiesType propType) {
         TableViewerColumn propName = new TableViewerColumn(tableViewer,
                 SWT.NONE);
         propName.getColumn().setWidth(columnWidth[0]);
@@ -292,7 +330,13 @@ public class DevicePlatformInfoView extends ViewPart {
                 }
             }
         });
-        propValue.setEditingSupport(new PropValueEditor(platformTblViewer));
+        if (propType == PropertiesType.DEVICE) {
+            propValue.setEditingSupport(new PropValueEditor(deviceTblViewer,
+                    propType));
+        } else {
+            propValue.setEditingSupport(new PropValueEditor(platformTblViewer,
+                    propType));
+        }
     }
 
     class PropertycontentProvider implements IStructuredContentProvider {
@@ -317,11 +361,18 @@ public class DevicePlatformInfoView extends ViewPart {
         return metaPropertyList;
     }
 
-    private void updateViewer(List<MetaProperty> metaPropertyList) {
-        if (null != platformTblViewer) {
-            Table tbl = platformTblViewer.getTable();
+    private List<MetaProperty> getDevicePropData() {
+        List<MetaProperty> metaPropertyList = Activator.getDefault()
+                .getResourceManager().getDeviceInfo();
+        return metaPropertyList;
+    }
+
+    private void updateViewer(TableViewer tableViewer,
+            List<MetaProperty> metaPropertyList) {
+        if (null != tableViewer) {
+            Table tbl = tableViewer.getTable();
             if (null != metaPropertyList) {
-                platformTblViewer.setInput(metaPropertyList.toArray());
+                tableViewer.setInput(metaPropertyList.toArray());
                 if (!tbl.isDisposed()) {
                     tbl.setLinesVisible(true);
                 }
@@ -336,11 +387,14 @@ public class DevicePlatformInfoView extends ViewPart {
 
     class PropValueEditor extends EditingSupport {
 
-        private final TableViewer viewer;
+        private final TableViewer    viewer;
 
-        public PropValueEditor(TableViewer viewer) {
+        private final PropertiesType propType;
+
+        public PropValueEditor(TableViewer viewer, PropertiesType propType) {
             super(viewer);
             this.viewer = viewer;
+            this.propType = propType;
         }
 
         @Override
@@ -350,9 +404,24 @@ public class DevicePlatformInfoView extends ViewPart {
 
         @Override
         protected CellEditor getCellEditor(Object element) {
-            if (!enable_edit) {
+            String propName = ((MetaProperty) element).getPropName();
+            if (null == propName) {
                 return null;
             }
+
+            if (propType == PropertiesType.DEVICE) {
+                if (!enableDeviceEdit)
+                    return null;
+                // Only device name property is editable
+                if (!propName.equals(Constants.DEVICE_NAME)) {
+                    return null;
+                }
+            } else {
+                if (!enablePlatformEdit) {
+                    return null;
+                }
+            }
+
             CellEditor editor = new TextCellEditor(viewer.getTable());
             return editor;
         }
index c8f6668..25b4e12 100644 (file)
@@ -154,7 +154,8 @@ public class MetaPropertiesView extends ViewPart {
                                 Constants.RESOURCE_URI);
                         if (result) {
                             MessageDialog.openError(parent.getShell(),
-                                    "Invalid Input", "Resource URI is invalid.");
+                                    "Invalid Resource URI.",
+                                    Constants.INVALID_URI_MESSAGE);
                             return;
                         }
 
index c102e66..2f5c345 100644 (file)
@@ -39,6 +39,7 @@ import oic.simulator.serviceprovider.view.dialogs.AddResources;
 import oic.simulator.serviceprovider.view.dialogs.AutomationSettingDialog;
 import oic.simulator.serviceprovider.view.dialogs.CreateResourceWizard;
 import oic.simulator.serviceprovider.view.dialogs.DeleteResourceWizard;
+import oic.simulator.serviceprovider.view.dialogs.MainPage.Option;
 import oic.simulator.serviceprovider.view.dialogs.RemoveResourceFromCollections;
 import oic.simulator.serviceprovider.view.dialogs.RemoveResourceFromDevices;
 import oic.simulator.serviceprovider.view.dialogs.RemoveResources;
@@ -50,6 +51,7 @@ import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.ITreeContentProvider;
 import org.eclipse.jface.viewers.LabelProvider;
 import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.jface.viewers.TreeViewer;
 import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.jface.window.Window;
@@ -607,6 +609,10 @@ public class ResourceManagerView extends ViewPart {
                                             collectionResTreeViewer.refresh();
                                             // if(refreshDeviceTree)
                                             deviceTreeViewer.refresh();
+
+                                            resourceManager
+                                                    .resourceSelectionChanged(null);
+
                                             MessageDialog.openInformation(
                                                     Display.getDefault()
                                                             .getActiveShell(),
@@ -738,6 +744,9 @@ public class ResourceManagerView extends ViewPart {
                                                         .refresh();
                                                 deviceTreeViewer.refresh();
 
+                                                resourceManager
+                                                        .resourceSelectionChanged(null);
+
                                                 status = "Resource removed from its parent";
                                             } catch (SimulatorException e1) {
                                                 status = "Failed to remove the resource from its parent";
@@ -1058,6 +1067,9 @@ public class ResourceManagerView extends ViewPart {
                     collectionResTreeViewer.refresh();
                     // if(refreshDeviceTree)
                     deviceTreeViewer.refresh();
+
+                    resourceManager.resourceSelectionChanged(null);
+
                     MessageDialog.openInformation(Display.getDefault()
                             .getActiveShell(), "Deleted", "Resource deleted.");
                 } catch (SimulatorException e1) {
@@ -1486,6 +1498,45 @@ public class ResourceManagerView extends ViewPart {
                         int open = wizardDialog.open();
                         if (open == WizardDialog.OK
                                 || createWizard.isDlgForceClosed()) {
+
+                            Option option = createWizard.getMainPage()
+                                    .getOption();
+                            if (option == Option.DEVICE) {
+                                Device dev = createWizard.getCreatedDevice();
+                                folder.setSelection(deviceTab);
+                                deviceTreeViewer.setSelection(
+                                        new StructuredSelection(dev), true);
+                                resourceManager.deviceSelectionChanged(dev);
+                                deviceTreeViewer.expandToLevel(dev,
+                                        Constants.TREE_EXPANSION_LEVEL);
+                            } else if (option == Option.SIMPLE_FROM_RAML
+                                    || option == Option.SIMPLE) {
+                                SingleResource res = (SingleResource) createWizard
+                                        .getCreatedResource();
+                                folder.setSelection(singleResTab);
+                                boolean canSelect = true;
+                                if (option == Option.SIMPLE_FROM_RAML
+                                        && createWizard.getResourceCount() > 1) {
+                                    canSelect = false;
+                                }
+                                if (canSelect) {
+                                    singleResTreeViewer.setSelection(
+                                            new StructuredSelection(res), true);
+                                    resourceManager
+                                            .resourceSelectionChanged(res);
+                                }
+                            } else if (option == Option.COLLECTION_FROM_RAML
+                                    || option == Option.COLLECTION) {
+                                CollectionResource res = (CollectionResource) createWizard
+                                        .getCreatedResource();
+                                folder.setSelection(collectionResTab);
+                                collectionResTreeViewer.setSelection(
+                                        new StructuredSelection(res), true);
+                                resourceManager.resourceSelectionChanged(res);
+                                collectionResTreeViewer.expandToLevel(res,
+                                        Constants.TREE_EXPANSION_LEVEL);
+                            }
+
                             MessageDialog.openInformation(Display.getDefault()
                                     .getActiveShell(),
                                     "Resource Creation Status", createWizard
index 6fc69fa..9280790 100644 (file)
@@ -299,20 +299,6 @@ public class AddAttributeDialog extends TitleAreaDialog {
     }
 
     private void setUiListeners() {
-
-        /*
-         * attNameTxt.addModifyListener(new ModifyListener() {
-         * 
-         * @Override public void modifyText(ModifyEvent e) { String value =
-         * attNameTxt.getText(); if(null != value) { value = value.trim(); }
-         * attHelper.setAttributeName(value); } });
-         * 
-         * dflValueTxt.addModifyListener(new ModifyListener() {
-         * 
-         * @Override public void modifyText(ModifyEvent arg0) { String value =
-         * dflValueTxt.getText(); if(null != value) { value = value.trim(); }
-         * attHelper.setAttributeDflValue(value); } });
-         */
         rangeBtn.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
@@ -354,7 +340,8 @@ public class AddAttributeDialog extends TitleAreaDialog {
                 char[] chars = new char[string.length()];
                 string.getChars(0, chars.length, chars, 0);
                 for (int i = 0; i < chars.length; i++) {
-                    if (!('0' <= chars[i] && chars[i] <= '9')) {
+                    if (!(('0' <= chars[i] && chars[i] <= '9')
+                            || chars[i] == '-' || chars[i] == '+')) {
                         if (attTypeCmb.getText().equals(Constants.INT)) {
                             e.doit = false;
                             return;
@@ -378,7 +365,8 @@ public class AddAttributeDialog extends TitleAreaDialog {
                 char[] chars = new char[string.length()];
                 string.getChars(0, chars.length, chars, 0);
                 for (int i = 0; i < chars.length; i++) {
-                    if (!('0' <= chars[i] && chars[i] <= '9')) {
+                    if (!(('0' <= chars[i] && chars[i] <= '9')
+                            || chars[i] == '-' || chars[i] == '+')) {
                         if (attTypeCmb.getText().equals(Constants.INT)) {
                             e.doit = false;
                             return;
index 5024c6d..5f79415 100644 (file)
@@ -5,6 +5,7 @@ import java.util.Set;
 
 import oic.simulator.serviceprovider.Activator;
 import oic.simulator.serviceprovider.utils.Constants;
+import oic.simulator.serviceprovider.utils.Utility;
 
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.window.Window;
@@ -52,10 +53,7 @@ public class CollectionResourceBasicDetailsPage extends WizardPage {
     @Override
     public void createControl(Composite parent) {
         setPageComplete(false);
-        if (anyResourceExist)
-            setTitle(Constants.COLLECTION_RESOURCE_BASIC_DETAILS_PAGE_TITLE2);
-        else
-            setTitle(Constants.COLLECTION_RESOURCE_BASIC_DETAILS_PAGE_TITLE1);
+        setTitle(Constants.COLLECTION_RESOURCE_BASIC_DETAILS_PAGE_TITLE);
         setMessage(Constants.COLLECTION_RESOURCE_BASIC_DETAILS_PAGE_MESSAGE);
 
         Composite container = new Composite(parent, SWT.NONE);
@@ -175,6 +173,7 @@ public class CollectionResourceBasicDetailsPage extends WizardPage {
                 if (null == resURI) {
                     return;
                 }
+
                 if (anyResourceExist)
                     getWizard().getContainer().updateButtons();
                 else
@@ -304,6 +303,13 @@ public class CollectionResourceBasicDetailsPage extends WizardPage {
             // itself.
             return null;
         }
+
+        if (!Utility.isUriValid(resURI)) {
+            MessageDialog.openError(Display.getDefault().getActiveShell(),
+                    "Invalid Resource URI.", Constants.INVALID_URI_MESSAGE);
+            return null;
+        }
+
         if (anyResourceExist) {
             return ((CreateResourceWizard) getWizard())
                     .getAddResourcesToCollectionPage();
index 20fac74..64fded9 100644 (file)
@@ -28,12 +28,14 @@ import oic.simulator.serviceprovider.Activator;
 import oic.simulator.serviceprovider.manager.UiListenerHandler;
 import oic.simulator.serviceprovider.model.AttributeHelper;
 import oic.simulator.serviceprovider.model.CollectionResource;
+import oic.simulator.serviceprovider.model.Device;
 import oic.simulator.serviceprovider.model.LocalResourceAttribute;
 import oic.simulator.serviceprovider.model.Resource;
 import oic.simulator.serviceprovider.model.ResourceType;
 import oic.simulator.serviceprovider.model.SingleResource;
+import oic.simulator.serviceprovider.utils.Constants;
 import oic.simulator.serviceprovider.utils.Utility;
-import oic.simulator.serviceprovider.view.dialogs.MainPage.ResourceOption;
+import oic.simulator.serviceprovider.view.dialogs.MainPage.Option;
 
 import org.eclipse.core.runtime.FileLocator;
 import org.eclipse.core.runtime.IPath;
@@ -45,6 +47,7 @@ import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.jface.wizard.IWizardPage;
 import org.eclipse.jface.wizard.Wizard;
 import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.swt.widgets.Display;
 import org.oic.simulator.ILogger.Level;
 import org.oic.simulator.SimulatorException;
 
@@ -70,6 +73,9 @@ public class CreateResourceWizard extends Wizard {
     private WizardDialog                       wizDialog;
     private boolean                            dlgForceClosed;
 
+    private Resource                           createdResource;
+    private Device                             createdDevice;
+
     public CreateResourceWizard() {
         setWindowTitle("Create resources");
         IPath path = new Path("/icons/oic_logo_64x64.png");
@@ -136,12 +142,20 @@ public class CreateResourceWizard extends Wizard {
         return loadRamlPage.getResourceCount();
     }
 
+    public Resource getCreatedResource() {
+        return createdResource;
+    }
+
+    public Device getCreatedDevice() {
+        return createdDevice;
+    }
+
     @Override
     public boolean canFinish() {
         System.out.println("canFinish()");
         IWizardPage curPage = this.getContainer().getCurrentPage();
         System.out.println(curPage.getName());
-        if ((curPage == updatePropPage && ((mainPage.getResourceOption() == ResourceOption.SIMPLE_FROM_RAML) || !Activator
+        if ((curPage == updatePropPage && ((mainPage.getOption() == Option.SIMPLE_FROM_RAML) || !Activator
                 .getDefault().getResourceManager().isAnyResourceExist()))
                 || (curPage == collectionResourceBasicDetailsPage
                         && !Activator.getDefault().getResourceManager()
@@ -175,8 +189,7 @@ public class CreateResourceWizard extends Wizard {
                             monitor.beginTask(
                                     "Single Resource Creation Without RAML", 2);
                             monitor.worked(1);
-                            createSingleResourceWithoutRAML();
-                            monitor.worked(1);
+                            createdResource = createSingleResourceWithoutRAML();
                         } finally {
                             monitor.done();
                         }
@@ -223,6 +236,18 @@ public class CreateResourceWizard extends Wizard {
                 e.printStackTrace();
             }
         } else if (curPage == updatePropPage) { // Handling the single instance
+            String resName = updatePropPage.getResName();
+            String resURI = updatePropPage.getResURI();
+            if (null == resName || resName.trim().length() < 1) {
+                MessageDialog.openError(Display.getDefault().getActiveShell(),
+                        "Invalid Resource Name.", "Resource name is invalid");
+                return false;
+            }
+            if (!Utility.isUriValid(resURI)) {
+                MessageDialog.openError(Display.getDefault().getActiveShell(),
+                        "Invalid Resource URI.", Constants.INVALID_URI_MESSAGE);
+                return false;
+            }
             // creation of simple resource
             // with RAML
             // String resURI = updatePropPage.getResURI();
@@ -265,93 +290,118 @@ public class CreateResourceWizard extends Wizard {
                 e.printStackTrace();
             }
         } else if (curPage == collectionResourceBasicDetailsPage
-                || curPage == addResourcesToCollectionPage) { // Handling
-            // Collection
-            // Resource
-            // Creation
-            // without RAML
-            if (mainPage.getResourceOption() == ResourceOption.COLLECTION_FROM_RAML) {
-                Resource res = loadRamlPage.getResource();
-                if (null != res && res instanceof CollectionResource) {
-                    Set<Resource> selectedResources = addResourcesToCollectionPage
-                            .getSelectedResourceList();
-                    if (!selectedResources.isEmpty()) {
-                        int addedCount = Activator
-                                .getDefault()
-                                .getResourceManager()
-                                .addResourceToCollection(
-                                        (CollectionResource) res,
-                                        selectedResources);
-                        if (addedCount > 0) {
-
-                            status = "[" + addedCount + "/"
-                                    + selectedResources.size()
-                                    + "] resources added to the collection";
+                || (curPage == addResourcesToCollectionPage && mainPage
+                        .getOption() == Option.COLLECTION)) {
+            // Checking whether the uri is used by any other resource.
+            if (Activator
+                    .getDefault()
+                    .getResourceManager()
+                    .isResourceExist(
+                            collectionResourceBasicDetailsPage.getResURI())) {
+                MessageDialog
+                        .openError(getShell(), "Resource URI in use",
+                                "Entered resource URI is in use. Please try a different one.");
+                // TODO: Instead of MessageDialog, errors may be shown on
+                // wizard
+                // itself.
+                return false;
+            }
+            try {
+                getContainer().run(true, true, new IRunnableWithProgress() {
 
-                            UiListenerHandler.getInstance()
-                                    .resourceListUpdateUINotification(
-                                            ResourceType.COLLECTION);
-                        } else {
-                            status = "Failed to add resources to the collection";
+                    @Override
+                    public void run(IProgressMonitor monitor)
+                            throws InvocationTargetException,
+                            InterruptedException {
+                        try {
+                            monitor.beginTask(
+                                    "Collection Resource Creation Without RAML",
+                                    3);
+                            monitor.worked(1);
+                            createCollectionResourceWithoutRAML((curPage == addResourcesToCollectionPage) ? true
+                                    : false);
+                            monitor.worked(1);
+                            if (curPage == addResourcesToCollectionPage) {
+                                UiListenerHandler.getInstance()
+                                        .resourceListUpdateUINotification(
+                                                ResourceType.COLLECTION);
+                            }
+                            monitor.worked(1);
+                        } finally {
+                            monitor.done();
                         }
                     }
-                }
-            } else {
-                // Checking whether the uri is used by any other resource.
-                if (Activator
-                        .getDefault()
-                        .getResourceManager()
-                        .isResourceExist(
-                                collectionResourceBasicDetailsPage.getResURI())) {
-                    MessageDialog
-                            .openError(getShell(), "Resource URI in use",
-                                    "Entered resource URI is in use. Please try a different one.");
-                    // TODO: Instead of MessageDialog, errors may be shown on
-                    // wizard
-                    // itself.
-                    return false;
-                }
-                try {
-                    getContainer().run(true, true, new IRunnableWithProgress() {
-
-                        @Override
-                        public void run(IProgressMonitor monitor)
-                                throws InvocationTargetException,
-                                InterruptedException {
-                            try {
-                                monitor.beginTask(
-                                        "Collection Resource Creation Without RAML",
-                                        3);
-                                monitor.worked(1);
-                                createCollectionResourceWithoutRAML((curPage == addResourcesToCollectionPage) ? true
-                                        : false);
-                                monitor.worked(1);
-                                if (curPage == addResourcesToCollectionPage) {
-                                    UiListenerHandler.getInstance()
-                                            .resourceListUpdateUINotification(
-                                                    ResourceType.COLLECTION);
+                });
+            } catch (InvocationTargetException e) {
+                Activator.getDefault().getLogManager()
+                        .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
+                e.printStackTrace();
+            } catch (InterruptedException e) {
+                Activator.getDefault().getLogManager()
+                        .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
+                e.printStackTrace();
+            }
+        } else if (curPage == addResourcesToCollectionPage) {
+            try {
+                getContainer().run(true, true, new IRunnableWithProgress() {
+
+                    @Override
+                    public void run(IProgressMonitor monitor)
+                            throws InvocationTargetException,
+                            InterruptedException {
+                        try {
+                            monitor.beginTask(
+                                    "Completing Collection Resource Creation With RAML",
+                                    3);
+                            monitor.worked(1);
+                            completeResourceCreationWithRAML();
+                            monitor.worked(1);
+
+                            if (mainPage.getOption() == Option.COLLECTION_FROM_RAML) {
+                                Resource res = loadRamlPage.getResource();
+                                if (null != res
+                                        && res instanceof CollectionResource) {
+                                    Set<Resource> selectedResources = addResourcesToCollectionPage
+                                            .getSelectedResourceList();
+                                    if (!selectedResources.isEmpty()) {
+                                        int addedCount = Activator
+                                                .getDefault()
+                                                .getResourceManager()
+                                                .addResourceToCollection(
+                                                        (CollectionResource) res,
+                                                        selectedResources);
+                                        if (addedCount > 0) {
+
+                                            status += " and ["
+                                                    + addedCount
+                                                    + "/"
+                                                    + selectedResources.size()
+                                                    + "] resources added to the collection";
+
+                                            UiListenerHandler
+                                                    .getInstance()
+                                                    .resourceListUpdateUINotification(
+                                                            ResourceType.COLLECTION);
+                                        } else {
+                                            status += " but failed to add resources to the collection";
+                                        }
+                                    }
                                 }
-                                monitor.worked(1);
-                            } finally {
-                                monitor.done();
                             }
+                            monitor.worked(1);
+                        } finally {
+                            monitor.done();
                         }
-                    });
-                } catch (InvocationTargetException e) {
-                    Activator
-                            .getDefault()
-                            .getLogManager()
-                            .log(Level.ERROR.ordinal(), new Date(),
-                                    e.getMessage());
-                    e.printStackTrace();
-                } catch (InterruptedException e) {
-                    Activator
-                            .getDefault()
-                            .getLogManager()
-                            .log(Level.ERROR.ordinal(), new Date(),
-                                    e.getMessage());
-                    e.printStackTrace();
-                }
+                    }
+                });
+            } catch (InvocationTargetException e) {
+                Activator.getDefault().getLogManager()
+                        .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
+                e.printStackTrace();
+            } catch (InterruptedException e) {
+                Activator.getDefault().getLogManager()
+                        .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
+                e.printStackTrace();
             }
         } else if (curPage == devicePage) {
             final String devName = devicePage.getDeviceName();
@@ -367,7 +417,7 @@ public class CreateResourceWizard extends Wizard {
                         try {
                             monitor.beginTask("Device Creation", 3);
                             monitor.worked(1);
-                            createDevice(devName, resourceList);
+                            createdDevice = createDevice(devName, resourceList);
                             monitor.worked(1);
                             UiListenerHandler.getInstance()
                                     .resourceListUpdateUINotification(
@@ -451,7 +501,7 @@ public class CreateResourceWizard extends Wizard {
      * public SingleResource getCreatedResource() { return simResource; }
      */
 
-    private void createSingleResourceWithoutRAML() {
+    private SingleResource createSingleResourceWithoutRAML() {
         SingleResource resource = new SingleResource();
         // Basic resource details
         resource.setResourceURI(simpleResourceBasicDetailsPage.getResURI());
@@ -502,11 +552,14 @@ public class CreateResourceWizard extends Wizard {
                 status = "Resource created.";
             } else {
                 status = "Failed to create resource.";
+                resource = null;
             }
         } catch (SimulatorException e) {
             status = "Failed to create resource.\n"
                     + Utility.getSimulatorErrorString(e, null);
+            resource = null;
         }
+        return resource;
     }
 
     private void completeResourceCreationWithRAML() {
@@ -531,12 +584,15 @@ public class CreateResourceWizard extends Wizard {
 
             if (result) {
                 status = "Resource created.";
+                createdResource = res;
             } else {
                 status = "Failed to create resource.";
+                createdResource = null;
             }
         } catch (SimulatorException e) {
             status = "Failed to create resource.\n"
                     + Utility.getSimulatorErrorString(e, null);
+            createdResource = null;
         }
     }
 
@@ -580,7 +636,7 @@ public class CreateResourceWizard extends Wizard {
             boolean result = Activator.getDefault().getResourceManager()
                     .createCollectionResource(resource);
             if (result) {
-                status = "Resource created.";
+                status = "Resource created";
                 // Adding child resources.
                 if (childResExist) {
                     Set<Resource> selectedResources = addResourcesToCollectionPage
@@ -592,25 +648,28 @@ public class CreateResourceWizard extends Wizard {
                                 .addResourceToCollection(resource,
                                         selectedResources);
                         if (addedCount > 0) {
-                            status = "[" + addedCount + "/"
+                            status += " and [" + addedCount + "/"
                                     + selectedResources.size()
                                     + "] resources added to the collection";
                         } else {
-                            status = "Failed to add resources to the collection.";
+                            status += " but failed to add resources to the collection.";
                         }
                     }
                 }
+                createdResource = resource;
             } else {
                 status = "Failed to create resource.";
+                createdResource = null;
             }
         } catch (SimulatorException e) {
             status = "Failed to create resource.\n"
                     + Utility.getSimulatorErrorString(e, null);
+            createdResource = null;
         }
     }
 
-    private void createDevice(String deviceName, Set<Resource> childs) {
-        Activator.getDefault().getResourceManager()
+    private Device createDevice(String deviceName, Set<Resource> childs) {
+        return Activator.getDefault().getResourceManager()
                 .createDevice(deviceName, childs);
     }
 
index 4a2cc9e..f2001d7 100644 (file)
@@ -22,7 +22,9 @@ import java.util.Date;
 import java.util.Set;
 
 import oic.simulator.serviceprovider.Activator;
+import oic.simulator.serviceprovider.manager.ResourceManager;
 import oic.simulator.serviceprovider.model.CollectionResource;
+import oic.simulator.serviceprovider.model.Resource;
 import oic.simulator.serviceprovider.model.SingleResource;
 
 import org.eclipse.core.runtime.FileLocator;
@@ -69,6 +71,8 @@ public class DeleteResourceWizard extends Wizard {
                 @Override
                 public void run(IProgressMonitor monitor)
                         throws InvocationTargetException, InterruptedException {
+                    ResourceManager resourceManager = Activator.getDefault()
+                            .getResourceManager();
                     try {
                         monitor.beginTask("Resource Deletion", 2);
                         Set<CollectionResource> collectionResources = page
@@ -80,6 +84,17 @@ public class DeleteResourceWizard extends Wizard {
                                     .getResourceManager()
                                     .removeCollectionResources(
                                             collectionResources);
+
+                            Resource res = resourceManager
+                                    .getCurrentResourceInSelection();
+                            if (null != res
+                                    && res instanceof CollectionResource) {
+                                if (collectionResources
+                                        .contains((CollectionResource) res)) {
+                                    resourceManager
+                                            .resourceSelectionChanged(null);
+                                }
+                            }
                         }
                         monitor.worked(1);
                         Set<SingleResource> singleResources = page
@@ -88,6 +103,16 @@ public class DeleteResourceWizard extends Wizard {
                                 && singleResources.size() > 0) {
                             Activator.getDefault().getResourceManager()
                                     .removeSingleResources(singleResources);
+
+                            Resource res = resourceManager
+                                    .getCurrentResourceInSelection();
+                            if (null != res && res instanceof SingleResource) {
+                                if (singleResources
+                                        .contains((SingleResource) res)) {
+                                    resourceManager
+                                            .resourceSelectionChanged(null);
+                                }
+                            }
                         }
                         monitor.worked(1);
                         status = "Resources deleted.";
index 8cc4928..9f5b7d9 100644 (file)
@@ -21,9 +21,12 @@ import java.lang.reflect.InvocationTargetException;
 import java.util.Date;
 
 import oic.simulator.serviceprovider.Activator;
+import oic.simulator.serviceprovider.model.CollectionResource;
 import oic.simulator.serviceprovider.model.Resource;
+import oic.simulator.serviceprovider.model.SingleResource;
 import oic.simulator.serviceprovider.utils.Constants;
 import oic.simulator.serviceprovider.utils.Utility;
+import oic.simulator.serviceprovider.view.dialogs.MainPage.Option;
 
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jface.dialogs.MessageDialog;
@@ -295,6 +298,27 @@ public class LoadRamlPage extends WizardPage {
             wizard.setStatus("Failed to create Resource.");
             wizard.getWizardDialog().close();
             return null;
+        } else {
+            // Checking whether the resource is single or collection.
+            Option intendedResource = wizard.getMainPage().getOption();
+            if ((intendedResource == Option.SIMPLE_FROM_RAML && resource instanceof CollectionResource)) {
+                MessageDialog
+                        .openError(
+                                getShell(),
+                                "Invalid RAML",
+                                "Uploaded RAML is of type collection. "
+                                        + "Please upload the proper RAML of simple type.");
+                return null;
+            } else if (intendedResource == Option.COLLECTION_FROM_RAML
+                    && resource instanceof SingleResource) {
+                MessageDialog
+                        .openError(
+                                getShell(),
+                                "Invalid RAML",
+                                "Uploaded RAML is of type simple. "
+                                        + "Please upload the proper RAML of collection type.");
+                return null;
+            }
         }
         UpdatePropertiesPage updatePageRef = wizard.getUpdatePropPage();
         updatePageRef.setResName(resource.getResourceName());
index f546f64..bd90dfd 100644 (file)
@@ -24,11 +24,11 @@ public class MainPage extends WizardPage {
     private Button deviceBtn;
     private Text   description;
 
-    public enum ResourceOption {
+    public enum Option {
         SIMPLE, SIMPLE_FROM_RAML, COLLECTION, COLLECTION_FROM_RAML, DEVICE, NONE
     }
 
-    private ResourceOption resOption;
+    private Option option;
 
     protected MainPage() {
         super("Main Page");
@@ -87,7 +87,7 @@ public class MainPage extends WizardPage {
                                 + "\t1. Basic resource details: URI, Name, Resource Types, etc.\n"
                                 + "\t2. Options such as Observable, allowed request types, start/stop resource etc.\n"
                                 + "\t3. Adding attributes.");
-                resOption = ResourceOption.SIMPLE;
+                option = Option.SIMPLE;
                 getWizard().getContainer().updateButtons();
             }
         });
@@ -101,7 +101,7 @@ public class MainPage extends WizardPage {
                                 + "\t2. Supports multi-instance creation.\n"
                                 + "\t3. For single instance creation, allows editing the URI and Name of the resource.\n"
                                 + "\t4. Allows to start or stop the resource(s).");
-                resOption = ResourceOption.SIMPLE_FROM_RAML;
+                option = Option.SIMPLE_FROM_RAML;
                 getWizard().getContainer().updateButtons();
             }
         });
@@ -114,7 +114,7 @@ public class MainPage extends WizardPage {
                                 + "\t1. Basic resource details: URI, Name, Resource Types, etc.\n"
                                 + "\t2. Start/stop the resource.\n"
                                 + "\t3. Adding existing simple resources to this collection.");
-                resOption = ResourceOption.COLLECTION;
+                option = Option.COLLECTION;
                 getWizard().getContainer().updateButtons();
             }
         });
@@ -128,7 +128,7 @@ public class MainPage extends WizardPage {
                                 + "\t2. Supports multi-instance creation.\n"
                                 + "\t3. For single instance creation, allows editing the URI and Name of the resource.\n"
                                 + "\t4. Allows to start or stop the resource(s).");
-                resOption = ResourceOption.COLLECTION_FROM_RAML;
+                option = Option.COLLECTION_FROM_RAML;
                 getWizard().getContainer().updateButtons();
             }
         });
@@ -140,7 +140,7 @@ public class MainPage extends WizardPage {
                         .setText("Create a logical device that acts as a top-level logical classification.\n"
                                 + "\t1. Takes a device name for identication.\n"
                                 + "\t2. One or more simple and collection resources can be added to it.");
-                resOption = ResourceOption.DEVICE;
+                option = Option.DEVICE;
                 getWizard().getContainer().updateButtons();
             }
         });
@@ -148,7 +148,7 @@ public class MainPage extends WizardPage {
 
     @Override
     public boolean canFlipToNextPage() {
-        if (resOption != ResourceOption.NONE) {
+        if (option != Option.NONE) {
             return true;
         }
         return false;
@@ -185,7 +185,7 @@ public class MainPage extends WizardPage {
         return null;
     }
 
-    public ResourceOption getResourceOption() {
-        return resOption;
+    public Option getOption() {
+        return option;
     }
 }
index 5113712..d2aea9f 100644 (file)
@@ -16,6 +16,8 @@
 
 package oic.simulator.serviceprovider.view.dialogs;
 
+import oic.simulator.serviceprovider.view.dialogs.MainPage.Option;
+
 import org.eclipse.jface.wizard.IWizard;
 import org.eclipse.jface.wizard.IWizardPage;
 import org.eclipse.jface.wizard.WizardDialog;
@@ -76,7 +78,11 @@ public class ResourceWizardDialog extends WizardDialog {
                 loadRamlPage.setResource(null);
                 prevPage = loadRamlPage;
             } else if (curPage == addResourcesToCollectionPage) {
-                prevPage = collectionResourceBasicDetailsPage;
+                if (mainPage.getOption() == Option.COLLECTION_FROM_RAML) {
+                    prevPage = updatePropPage;
+                } else {
+                    prevPage = collectionResourceBasicDetailsPage;
+                }
             } else if (curPage == simpleResourceAddAttributesPage) {
                 prevPage = simpleResourceBasicDetailsPage;
             } else if (curPage == simpleResourceOtherDetailsPage) {
index 0e664ca..9bbf836 100644 (file)
@@ -20,7 +20,6 @@ import org.eclipse.jface.viewers.TableViewerColumn;
 import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.jface.viewers.ViewerCell;
 import org.eclipse.jface.window.Window;
-import org.eclipse.jface.wizard.IWizardPage;
 import org.eclipse.jface.wizard.WizardPage;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionAdapter;
index f01939b..60b4dea 100644 (file)
@@ -5,6 +5,7 @@ import java.util.Set;
 
 import oic.simulator.serviceprovider.Activator;
 import oic.simulator.serviceprovider.utils.Constants;
+import oic.simulator.serviceprovider.utils.Utility;
 
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.window.Window;
@@ -164,6 +165,10 @@ public class SimpleResourceBasicDetailsPage extends WizardPage {
             @Override
             public void modifyText(ModifyEvent arg0) {
                 resURI = resUriTxt.getText();
+                if (null == resURI) {
+                    return;
+                }
+
                 getWizard().getContainer().updateButtons();
             }
         });
@@ -234,13 +239,6 @@ public class SimpleResourceBasicDetailsPage extends WizardPage {
                 observable = observeBtn.getSelection();
             }
         });
-
-        /*
-         * startBtn.addSelectionListener(new SelectionAdapter() {
-         * 
-         * @Override public void widgetSelected(SelectionEvent e) { start =
-         * startBtn.getSelection(); } });
-         */
     }
 
     private void changeVisibility() {
@@ -267,6 +265,12 @@ public class SimpleResourceBasicDetailsPage extends WizardPage {
 
     @Override
     public IWizardPage getNextPage() {
+        if (!Utility.isUriValid(resURI)) {
+            MessageDialog.openError(Display.getDefault().getActiveShell(),
+                    "Invalid Resource URI.", Constants.INVALID_URI_MESSAGE);
+            return null;
+        }
+
         // Checking whether the uri is used by any other resource.
         if (Activator.getDefault().getResourceManager().isResourceExist(resURI)) {
             MessageDialog
@@ -276,6 +280,7 @@ public class SimpleResourceBasicDetailsPage extends WizardPage {
             // itself.
             return null;
         }
+
         return ((CreateResourceWizard) getWizard())
                 .getSimpleResourceAddAttributePage();
     }
@@ -295,9 +300,4 @@ public class SimpleResourceBasicDetailsPage extends WizardPage {
     public boolean isObservable() {
         return observable;
     }
-
-    /*
-     * public boolean isStart() { return start; }
-     */
-
 }
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourcePage.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourcePage.java
deleted file mode 100644 (file)
index e743332..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-package oic.simulator.serviceprovider.view.dialogs;
-
-import oic.simulator.serviceprovider.utils.Constants;
-
-import org.eclipse.jface.wizard.IWizardPage;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-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.Label;
-import org.eclipse.swt.widgets.Text;
-
-public class SimpleResourcePage extends WizardPage {
-
-    Button manualBtn;
-    Button ramlBtn;
-
-    protected SimpleResourcePage() {
-        super("Simle Page");
-    }
-
-    @Override
-    public void createControl(Composite parent) {
-        setPageComplete(false);
-        setTitle(Constants.SIMPLE_PAGE_TITLE);
-        setMessage(Constants.SIMPLE_PAGE_MESSAGE);
-        Composite compContent = new Composite(parent, SWT.NONE);
-        GridLayout gridLayout = new GridLayout();
-        compContent.setLayout(gridLayout);
-        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
-        compContent.setLayoutData(gd);
-
-        manualBtn = new Button(compContent, SWT.RADIO);
-        manualBtn.setText("Manually");
-
-        ramlBtn = new Button(compContent, SWT.RADIO);
-        ramlBtn.setText("From RAML file");
-
-        Label lbl = new Label(compContent, SWT.NULL);
-        lbl.setText("Details:");
-        gd = new GridData();
-        gd.verticalIndent = 20;
-        lbl.setLayoutData(gd);
-
-        Text desc = new Text(compContent, SWT.MULTI | SWT.READ_ONLY
-                | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
-        desc.setBackground(compContent.getBackground());
-        desc.setText("[Select an option to view more details]");
-        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
-        desc.setLayoutData(gd);
-
-        addUIListeners();
-
-        setControl(compContent);
-    }
-
-    private void addUIListeners() {
-        manualBtn.addSelectionListener(new SelectionAdapter() {
-            @Override
-            public void widgetSelected(SelectionEvent e) {
-                getWizard().getContainer().updateButtons();
-            }
-        });
-
-        ramlBtn.addSelectionListener(new SelectionAdapter() {
-            @Override
-            public void widgetSelected(SelectionEvent e) {
-                getWizard().getContainer().updateButtons();
-            }
-        });
-    }
-
-    @Override
-    public boolean canFlipToNextPage() {
-        if (manualBtn.getSelection() || ramlBtn.getSelection()) {
-            return true;
-        }
-        return false;
-    }
-
-    @Override
-    public IWizardPage getNextPage() {
-        CreateResourceWizard createWizard = (CreateResourceWizard) getWizard();
-        if (manualBtn.getSelection()) {
-            return createWizard.getSimpleResourceBasicDetailsPage();
-        }
-        if (ramlBtn.getSelection()) {
-            return createWizard.getLoadRamlPage();
-        }
-        return null;
-    }
-}
index e2faddb..116748f 100644 (file)
 
 package oic.simulator.serviceprovider.view.dialogs;
 
-import java.lang.reflect.InvocationTargetException;
-import java.util.Date;
-
 import oic.simulator.serviceprovider.Activator;
 import oic.simulator.serviceprovider.utils.Constants;
 import oic.simulator.serviceprovider.utils.Utility;
-import oic.simulator.serviceprovider.view.dialogs.MainPage.ResourceOption;
+import oic.simulator.serviceprovider.view.dialogs.MainPage.Option;
 
-import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.wizard.IWizardPage;
 import org.eclipse.jface.wizard.WizardPage;
 import org.eclipse.swt.SWT;
@@ -35,11 +30,10 @@ import org.eclipse.swt.events.ModifyListener;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Group;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Text;
-import org.oic.simulator.ILogger.Level;
-import org.oic.simulator.SimulatorException;
 
 public class UpdatePropertiesPage extends WizardPage {
 
@@ -126,7 +120,6 @@ public class UpdatePropertiesPage extends WizardPage {
             public void modifyText(ModifyEvent e) {
                 resName = resNameTxt.getText();
                 setPageComplete(isSelectionDone());
-                // getWizard().getContainer().updateButtons();
             }
         });
 
@@ -134,8 +127,11 @@ public class UpdatePropertiesPage extends WizardPage {
             @Override
             public void modifyText(ModifyEvent e) {
                 resURI = resUriTxt.getText();
+                if (null == resURI) {
+                    return;
+                }
+
                 setPageComplete(isSelectionDone());
-                // getWizard().getContainer().updateButtons();
             }
         });
     }
@@ -144,7 +140,7 @@ public class UpdatePropertiesPage extends WizardPage {
     public boolean canFlipToNextPage() {
         CreateResourceWizard createWizard = (CreateResourceWizard) getWizard();
         if (isSelectionDone()
-                && (createWizard.getMainPage().getResourceOption() == ResourceOption.COLLECTION_FROM_RAML)
+                && (createWizard.getMainPage().getOption() == Option.COLLECTION_FROM_RAML)
                 && Activator.getDefault().getResourceManager()
                         .isAnyResourceExist()) {
             return true;
@@ -163,7 +159,18 @@ public class UpdatePropertiesPage extends WizardPage {
 
     @Override
     public IWizardPage getNextPage() {
-        final boolean done[] = new boolean[1];
+        if (null == resName || resName.trim().length() < 1) {
+            MessageDialog.openError(Display.getDefault().getActiveShell(),
+                    "Invalid Resource Name.", "Resource name is invalid.");
+            return null;
+        }
+
+        if (!Utility.isUriValid(resURI)) {
+            MessageDialog.openError(Display.getDefault().getActiveShell(),
+                    "Invalid Resource URI.", Constants.INVALID_URI_MESSAGE);
+            return null;
+        }
+
         CreateResourceWizard createWizard = (CreateResourceWizard) getWizard();
         // Checking whether the uri is used by any other resource.
         if (Activator.getDefault().getResourceManager().isResourceExist(resURI)) {
@@ -174,38 +181,6 @@ public class UpdatePropertiesPage extends WizardPage {
             // itself.
             return null;
         }
-        try {
-            getContainer().run(true, true, new IRunnableWithProgress() {
-
-                @Override
-                public void run(IProgressMonitor monitor)
-                        throws InvocationTargetException, InterruptedException {
-                    try {
-                        monitor.beginTask(
-                                "Completing Collection Resource Creation With RAML",
-                                2);
-                        monitor.worked(1);
-                        done[0] = completeCollectionResourceCreationWithRAML();
-                        monitor.worked(1);
-                    } finally {
-                        monitor.done();
-                    }
-                }
-            });
-        } catch (InvocationTargetException e) {
-            Activator.getDefault().getLogManager()
-                    .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
-            e.printStackTrace();
-            return null;
-        } catch (InterruptedException e) {
-            Activator.getDefault().getLogManager()
-                    .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
-            e.printStackTrace();
-            return null;
-        }
-        if (!done[0]) {
-            return null;
-        }
         return createWizard.getAddResourcesToCollectionPage();
     }
 
@@ -228,28 +203,4 @@ public class UpdatePropertiesPage extends WizardPage {
     public String getResURI() {
         return resURI;
     }
-
-    private boolean completeCollectionResourceCreationWithRAML() {
-        boolean result = false;
-        String status;
-        CreateResourceWizard createWizard = (CreateResourceWizard) getWizard();
-        try {
-            result = Activator
-                    .getDefault()
-                    .getResourceManager()
-                    .completeCollectionResourceCreationByRAML(
-                            createWizard.getLoadRamlPage().getResource(),
-                            resURI, resName);
-            if (result)
-                status = "Resource created.";
-            else {
-                status = "Failed to create resource.";
-            }
-        } catch (SimulatorException e) {
-            status = "Failed to create resource.\n"
-                    + Utility.getSimulatorErrorString(e, null);
-        }
-        createWizard.setStatus(status);
-        return result;
-    }
 }
index a2f17ed..4ee9baa 100644 (file)
@@ -48,7 +48,7 @@ void JniDeviceInfo::setFieldValue(jobject jDeviceInfo, const std::string &fieldN
     m_env->SetObjectField(jDeviceInfo, fieldID, valueStr);
 }
 
-void onDeviceInfoReceived(jobject listener, DeviceInfo &deviceInfo)
+void onDeviceInfoReceived(jobject listener, const std::string &hostUri, DeviceInfo &deviceInfo)
 {
     JNIEnv *env = getEnv();
     if (!env)
@@ -56,8 +56,10 @@ void onDeviceInfoReceived(jobject listener, DeviceInfo &deviceInfo)
 
     jclass listenerCls = env->GetObjectClass(listener);
     jmethodID listenerMethodId = env->GetMethodID(listenerCls, "onDeviceFound",
-                                 "(Lorg/oic/simulator/DeviceInfo;)V");
+                                 "(Ljava/lang/String;Lorg/oic/simulator/DeviceInfo;)V");
 
+
+    jstring jHostUri = env->NewStringUTF(hostUri.c_str());
     jobject jDeviceInfo = JniDeviceInfo(env).toJava(deviceInfo);
     if (!jDeviceInfo)
     {
@@ -65,7 +67,7 @@ void onDeviceInfoReceived(jobject listener, DeviceInfo &deviceInfo)
         return;
     }
 
-    env->CallVoidMethod(listener, listenerMethodId, jDeviceInfo);
+    env->CallVoidMethod(listener, listenerMethodId, jHostUri, jDeviceInfo);
     if (env->ExceptionCheck())
     {
         releaseEnv();
index 27e845d..c64f825 100644 (file)
@@ -41,6 +41,6 @@ class JniDeviceInfo
         JNIEnv *m_env;
 };
 
-void onDeviceInfoReceived(jobject listener, DeviceInfo &deviceInfo);
+void onDeviceInfoReceived(jobject listener, const std::string &host, DeviceInfo &deviceInfo);
 
 #endif
index ab1a338..4a38aea 100644 (file)
@@ -274,11 +274,11 @@ Java_org_oic_simulator_SimulatorManager_findDevices
 {
     VALIDATE_CALLBACK(env, listener)
 
-    DeviceInfoCallback callback =  std::bind([](DeviceInfo & deviceInfo,
+    DeviceInfoCallback callback =  std::bind([](const std::string & host, DeviceInfo & deviceInfo,
                                    const std::shared_ptr<JniListenerHolder> &listenerRef)
     {
-        onDeviceInfoReceived(listenerRef->get(), deviceInfo);
-    }, std::placeholders::_1, JniListenerHolder::create(env, listener));
+        onDeviceInfoReceived(listenerRef->get(), host, deviceInfo);
+    }, std::placeholders::_1, std::placeholders::_2, JniListenerHolder::create(env, listener));
 
     try
     {
@@ -319,11 +319,11 @@ Java_org_oic_simulator_SimulatorManager_getPlatformInformation
 {
     VALIDATE_CALLBACK(env, listener)
 
-    PlatformInfoCallback callback =  std::bind([](PlatformInfo & platformInfo,
+    PlatformInfoCallback callback =  std::bind([](const std::string & host, PlatformInfo & platformInfo,
                                      const std::shared_ptr<JniListenerHolder> &listenerRef)
     {
-        onPlatformInfoReceived(listenerRef->get(), platformInfo);
-    }, std::placeholders::_1, JniListenerHolder::create(env, listener));
+        onPlatformInfoReceived(listenerRef->get(), host, platformInfo);
+    }, std::placeholders::_1, std::placeholders::_2, JniListenerHolder::create(env, listener));
 
     try
     {
index 4fb7702..8a27507 100644 (file)
@@ -87,7 +87,7 @@ std::string JniPlatformInfo::getFieldValue(jobject jPlatformInfo, const std::str
     return value.get();
 }
 
-void onPlatformInfoReceived(jobject listener, PlatformInfo &platformInfo)
+void onPlatformInfoReceived(jobject listener, const std::string &hostUri, PlatformInfo &platformInfo)
 {
     JNIEnv *env = getEnv();
     if (!env)
@@ -95,8 +95,9 @@ void onPlatformInfoReceived(jobject listener, PlatformInfo &platformInfo)
 
     jclass listenerCls = env->GetObjectClass(listener);
     jmethodID listenerMethodId = env->GetMethodID(listenerCls, "onPlatformFound",
-                                 "(Lorg/oic/simulator/PlatformInfo;)V");
+                                 "(Ljava/lang/String;Lorg/oic/simulator/PlatformInfo;)V");
 
+    jstring jHostUri = env->NewStringUTF(hostUri.c_str());
     jobject jPlatformInfo = JniPlatformInfo(env).toJava(platformInfo);
     if (!jPlatformInfo)
     {
@@ -104,7 +105,7 @@ void onPlatformInfoReceived(jobject listener, PlatformInfo &platformInfo)
         return;
     }
 
-    env->CallVoidMethod(listener, listenerMethodId, jPlatformInfo);
+    env->CallVoidMethod(listener, listenerMethodId, jHostUri, jPlatformInfo);
     if (env->ExceptionCheck())
     {
         releaseEnv();
index ba75df7..52196f4 100644 (file)
@@ -43,6 +43,6 @@ class JniPlatformInfo
         JNIEnv *m_env;
 };
 
-void onPlatformInfoReceived(jobject listener, PlatformInfo &platformInfo);
+void onPlatformInfoReceived(jobject listener, const std::string &host, PlatformInfo &platformInfo);
 
 #endif
index f6254b0..eda545c 100644 (file)
@@ -23,8 +23,10 @@ public interface DeviceListener {
     /**
      * Method which provides remote device information.
      *
+     * @param hostUri
+     *            Holds the address and port information.
      * @param devInfo
      *            {@link DeviceInfo} object holding the device information.
      */
-    public void onDeviceFound(DeviceInfo devInfo);
+    public void onDeviceFound(String hostUri, DeviceInfo devInfo);
 }
index 531729d..bdaf248 100644 (file)
@@ -23,8 +23,10 @@ public interface PlatformListener {
     /**
      * Method which provides remote device platform information.
      *
+     * @param hostUri
+     *            Holds the address and port information.
      * @param platformInfo
      *            {@link PlatformInfo} object holding the platform information.
      */
-    public void onPlatformFound(PlatformInfo platformInfo);
+    public void onPlatformFound(String hostUri, PlatformInfo platformInfo);
 }
index 9490372..f4f4885 100755 (executable)
@@ -562,7 +562,7 @@ std::shared_ptr<OC::OCResourceResponse> SimulatorSingleResourceImpl::requestOnBa
         else
         {
             response = std::make_shared<OC::OCResourceResponse>();
-            response->setErrorCode(400);
+            response->setErrorCode(403);
             response->setResponseResult(OC_EH_ERROR);
             if ("PUT" == request->getRequestType())
             {
index 4b10c14..7a45f32 100644 (file)
@@ -138,7 +138,7 @@ void SimulatorManager::getDeviceInfo(const std::string &host, DeviceInfoCallback
     VALIDATE_CALLBACK(callback)
 
     OC::FindDeviceCallback deviceCallback = std::bind(
-            [](const OC::OCRepresentation & rep, DeviceInfoCallback callback)
+            [](const OC::OCRepresentation & rep, const std::string & hostUri, DeviceInfoCallback callback)
     {
         std::string deviceName = rep.getValue<std::string>("n");
         std::string deviceID = rep.getValue<std::string>("di");
@@ -146,8 +146,8 @@ void SimulatorManager::getDeviceInfo(const std::string &host, DeviceInfoCallback
         std::string deviceDMV = rep.getValue<std::string>("dmv");
 
         DeviceInfo deviceInfo(deviceName, deviceID, deviceSpecVersion, deviceDMV);
-        callback(deviceInfo);
-    }, std::placeholders::_1, callback);
+        callback(hostUri, deviceInfo);
+    }, std::placeholders::_1, host, callback);
 
     typedef OCStackResult (*GetDeviceInfo)(const std::string &, const std::string &,
                                            OCConnectivityType, OC::FindDeviceCallback);
@@ -173,7 +173,7 @@ void SimulatorManager::getPlatformInfo(const std::string &host, PlatformInfoCall
     VALIDATE_CALLBACK(callback)
 
     OC::FindPlatformCallback platformCallback = std::bind(
-                [](const OC::OCRepresentation & rep, PlatformInfoCallback callback)
+                [](const OC::OCRepresentation & rep, const std::string & hostUri, PlatformInfoCallback callback)
     {
         PlatformInfo platformInfo;
         platformInfo.setPlatformID(rep.getValue<std::string>("pi"));
@@ -188,8 +188,8 @@ void SimulatorManager::getPlatformInfo(const std::string &host, PlatformInfoCall
         platformInfo.setSupportUrl(rep.getValue<std::string>("mnsl"));
         platformInfo.setSystemTime(rep.getValue<std::string>("st"));
 
-        callback(platformInfo);
-    }, std::placeholders::_1, callback);
+        callback(hostUri, platformInfo);
+    }, std::placeholders::_1, host, callback);
 
     typedef OCStackResult (*GetPlatformInfo)(const std::string &, const std::string &,
             OCConnectivityType, OC::FindPlatformCallback);