Updated URI parsing code in server and added code to keep observed resources list...
authorHarish Kumara Marappa <h.marappa@samsung.com>
Wed, 16 Sep 2015 15:14:29 +0000 (20:44 +0530)
committerMadan Lanka <lanka.madan@samsung.com>
Thu, 17 Sep 2015 02:48:58 +0000 (02:48 +0000)
Change set include below given changes:
1. Updating Javadoc comments
2. Eclipse plugin UI fixes.
3. Updated sample RAML file without OIC related information.
4. Handling exceptions.

Change-Id: I13d51876fdf6df72e09b74277dd4a813aa7ed8c9
Signed-off-by: Harish Kumara Marappa <h.marappa@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2599
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
28 files changed:
service/simulator/java/eclipse-plugin/ClientControllerPlugin/.classpath
service/simulator/java/eclipse-plugin/ClientControllerPlugin/.project
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/manager/ImageManager.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/manager/ResourceManager.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/LogView.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/ResourceManagerView.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/FindResourcePage.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/FindResourceWizard.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/resource/Light/oic.r.light.raml [deleted file]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/resource/Light/simple-light-error.json [moved from service/simulator/java/eclipse-plugin/ServiceProviderPlugin/resource/Light/oic.r.light-error.json with 50% similarity]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/resource/Light/simple-light.json [moved from service/simulator/java/eclipse-plugin/ServiceProviderPlugin/resource/Light/oic.r.light.json with 57% similarity]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/resource/Light/simple-light.raml [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/ILogUIListener.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ImageManager.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.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/LogView.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/CreateResourceWizard.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteResourceWizard.java
service/simulator/java/sdk/src/org/oic/simulator/InvalidArgsException.java
service/simulator/java/sdk/src/org/oic/simulator/NoSupportException.java
service/simulator/java/sdk/src/org/oic/simulator/OperationInProgressException.java
service/simulator/java/sdk/src/org/oic/simulator/SimulatorManager.java
service/simulator/java/sdk/src/org/oic/simulator/SimulatorManagerNativeInterface.java
service/simulator/java/sdk/src/org/oic/simulator/SimulatorResourceModel.java
service/simulator/java/sdk/src/org/oic/simulator/serviceprovider/SimulatorResourceServer.java

index 89756a7..cd0df03 100644 (file)
@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
-    <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
-    <classpathentry kind="src" path="src"/>
-    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
-    <classpathentry kind="lib" path="libs/Simulator.jar"/>
-    <classpathentry kind="output" path="bin"/>
+       <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+       <classpathentry kind="src" path="src"/>
+       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+       <classpathentry kind="lib" path="libs/Simulator.jar"/>
+       <classpathentry kind="output" path="bin"/>
 </classpath>
index f865f6c..39567c3 100644 (file)
@@ -1,28 +1,28 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <projectDescription>
-    <name>ClientControllerPlugin</name>
-    <comment></comment>
-    <projects>
-    </projects>
-    <buildSpec>
-        <buildCommand>
-            <name>org.eclipse.jdt.core.javabuilder</name>
-            <arguments>
-            </arguments>
-        </buildCommand>
-        <buildCommand>
-            <name>org.eclipse.pde.ManifestBuilder</name>
-            <arguments>
-            </arguments>
-        </buildCommand>
-        <buildCommand>
-            <name>org.eclipse.pde.SchemaBuilder</name>
-            <arguments>
-            </arguments>
-        </buildCommand>
-    </buildSpec>
-    <natures>
-        <nature>org.eclipse.pde.PluginNature</nature>
-        <nature>org.eclipse.jdt.core.javanature</nature>
-    </natures>
+       <name>ClientControllerPlugin</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.eclipse.jdt.core.javabuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.pde.ManifestBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.pde.SchemaBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.eclipse.pde.PluginNature</nature>
+               <nature>org.eclipse.jdt.core.javanature</nature>
+       </natures>
 </projectDescription>
index ec37672..b0b1f6c 100644 (file)
@@ -68,9 +68,8 @@ public class ImageManager {
     }
 
     public static Image getImage(String imagePath) {
-        Image img = null;
         if (null == imagePath || imagePath.length() < 1) {
-            return img;
+            return null;
         }
         URL imageURL = Activator.getDefault().getBundle().getEntry(imagePath);
         ImageDescriptor descriptor = ImageDescriptor.createFromURL(imageURL);
index 392888f..20e7d6c 100644 (file)
@@ -66,9 +66,9 @@ import org.oic.simulator.clientcontroller.SimulatorVerificationType;
 /**
  * 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
- * other UI modules with the information required. It also handles responses for find,
- * GET, PUT, POST, Observe and automatic verification operations from native layer and propagates
- * those events to the registered UI listeners.
+ * other UI modules with the information required. It also handles responses for
+ * find, GET, PUT, POST, Observe and automatic verification operations from
+ * native layer and propagates those events to the registered UI listeners.
  */
 public class ResourceManager {
 
@@ -384,11 +384,13 @@ public class ResourceManager {
         Map<String, RemoteResourceAttribute> attributeMap = fetchResourceAttributesFromModel(resourceModelN);
 
         // TODO: For debugging
-        RemoteResourceAttribute.printAttributes(attributeMap);
-        System.out.println("Attributes found: " + (null != attributeMap));
-        System.out.println("No of attributes: " + attributeMap.size());
+        if (null != attributeMap) {
+            RemoteResourceAttribute.printAttributes(attributeMap);
+            System.out.println("Attributes found: " + (null != attributeMap));
+            System.out.println("No of attributes: " + attributeMap.size());
 
-        resource.setResourceAttributesMap(attributeMap);
+            resource.setResourceAttributesMap(attributeMap);
+        }
         return resource;
     }
 
@@ -632,7 +634,19 @@ public class ResourceManager {
         Map<String, RemoteResourceAttribute> resourceAttributeMap = null;
         if (null != resourceModelN) {
             Map<String, ResourceAttribute> attributeMapN;
-            attributeMapN = resourceModelN.getAttributes();
+            try {
+                attributeMapN = resourceModelN.getAttributes();
+            } catch (SimulatorException e) {
+                Activator
+                        .getDefault()
+                        .getLogManager()
+                        .log(Level.ERROR.ordinal(),
+                                new Date(),
+                                "[" + e.getClass().getSimpleName() + "]"
+                                        + e.code().toString() + "-"
+                                        + e.message());
+                return null;
+            }
             if (null != attributeMapN) {
                 resourceAttributeMap = new HashMap<String, RemoteResourceAttribute>();
 
@@ -1239,31 +1253,82 @@ public class ResourceManager {
             model = itr.next();
             attName = model.getAttName();
             attribute = attMap.get(attName);
+            if (null == attribute) {
+                continue;
+            }
             attType = attribute.getAttValBaseType();
             if (attType == Type.INT) {
                 int attValue;
                 try {
                     attValue = Integer.parseInt(model.getAttValue());
+                    resourceModel.addAttributeInt(attName, attValue);
                 } catch (NumberFormatException e) {
-                    attValue = -1;
+                    Activator
+                            .getDefault()
+                            .getLogManager()
+                            .log(Level.ERROR.ordinal(), new Date(),
+                                    e.getMessage());
+                } catch (SimulatorException e) {
+                    Activator
+                            .getDefault()
+                            .getLogManager()
+                            .log(Level.ERROR.ordinal(),
+                                    new Date(),
+                                    "[" + e.getClass().getSimpleName() + "]"
+                                            + e.code().toString() + "-"
+                                            + e.message());
                 }
-                resourceModel.addAttribute(attName, attValue);
             } else if (attType == Type.DOUBLE) {
                 double attValue;
                 try {
                     attValue = Double.parseDouble(model.getAttValue());
+                    resourceModel.addAttributeDouble(attName, attValue);
                 } catch (NumberFormatException e) {
-                    attValue = -1.0;
+                    Activator
+                            .getDefault()
+                            .getLogManager()
+                            .log(Level.ERROR.ordinal(), new Date(),
+                                    e.getMessage());
+                } catch (SimulatorException e) {
+                    Activator
+                            .getDefault()
+                            .getLogManager()
+                            .log(Level.ERROR.ordinal(),
+                                    new Date(),
+                                    "[" + e.getClass().getSimpleName() + "]"
+                                            + e.code().toString() + "-"
+                                            + e.message());
                 }
-                resourceModel.addAttribute(attName, attValue);
             } else if (attType == Type.BOOL) {
                 boolean attValue;
                 attValue = Boolean.parseBoolean(model.getAttValue());
-                resourceModel.addAttribute(attName, attValue);
+                try {
+                    resourceModel.addAttributeBoolean(attName, attValue);
+                } catch (SimulatorException e) {
+                    Activator
+                            .getDefault()
+                            .getLogManager()
+                            .log(Level.ERROR.ordinal(),
+                                    new Date(),
+                                    "[" + e.getClass().getSimpleName() + "]"
+                                            + e.code().toString() + "-"
+                                            + e.message());
+                }
             } else if (attType == Type.STRING) {
                 String attValue;
                 attValue = model.getAttValue();
-                resourceModel.addAttribute(attName, attValue);
+                try {
+                    resourceModel.addAttributeString(attName, attValue);
+                } catch (SimulatorException e) {
+                    Activator
+                            .getDefault()
+                            .getLogManager()
+                            .log(Level.ERROR.ordinal(),
+                                    new Date(),
+                                    "[" + e.getClass().getSimpleName() + "]"
+                                            + e.code().toString() + "-"
+                                            + e.message());
+                }
             }
         }
         return resourceModel;
index cd286db..f91a752 100644 (file)
@@ -729,9 +729,7 @@ public class AttributeView extends ViewPart {
                         }
                         VerificationDialog ad = new VerificationDialog(Display
                                 .getDefault().getActiveShell(), autoStatus);
-                        if (ad.open() == Window.OK) {
-
-                        }
+                        ad.open();
                     }
                 });
             }
index 65a7e71..3c4d76e 100644 (file)
@@ -440,9 +440,11 @@ public class LogView extends ViewPart {
                                     + e.getMessage());
                 } finally {
                     try {
-                        out.close();
+                        if (null != out) {
+                            out.close();
+                        }
                     } catch (IOException e) {
-                        // Error occurred during close. Ignoring
+                        System.out.println("Error occurred during close.");
                     }
                 }
             }
index eecc4a7..2082a42 100644 (file)
@@ -467,34 +467,38 @@ public class ResourceManagerView extends ViewPart {
 
                             Set<String> searchTypes = findWizard
                                     .getSearchTypes();
-                            System.out.println(searchTypes);
-                            // Call native method to clear existing resources of
-                            // the given search types.
-                            resourceManager.deleteResources(searchTypes);
+                            if (null != searchTypes) {
+                                System.out.println(searchTypes);
+                                // Call native method to clear existing
+                                // resources of
+                                // the given search types.
+                                resourceManager.deleteResources(searchTypes);
+
+                                // Update the tree
+                                treeViewer.refresh();
+                                favTreeViewer.refresh();
+
+                                // Call native method to find Resources
+                                boolean result = resourceManager
+                                        .findResourceRequest(searchTypes);
+                                if (result) {
+                                    searchUIOperation(false);
+                                } else {
+                                    MessageDialog
+                                            .openError(Display.getDefault()
+                                                    .getActiveShell(),
+                                                    "Find Resource status",
+                                                    "Operation failed due to some problems in core layer.");
+                                }
 
-                            // Update the tree
-                            treeViewer.refresh();
-                            favTreeViewer.refresh();
+                                // Store this information for refresh
+                                // functionality
+                                resourceManager
+                                        .setLastKnownSearchTypes(searchTypes);
 
-                            // Call native method to find Resources
-                            boolean result = resourceManager
-                                    .findResourceRequest(searchTypes);
-                            if (result) {
-                                searchUIOperation(false);
-                            } else {
-                                MessageDialog
-                                        .openError(Display.getDefault()
-                                                .getActiveShell(),
-                                                "Find Resource status",
-                                                "Operation failed due to some problems in core layer.");
+                                // Change the refresh visibility
+                                refreshButton.setEnabled(true);
                             }
-
-                            // Store this information for refresh functionality
-                            resourceManager
-                                    .setLastKnownSearchTypes(searchTypes);
-
-                            // Change the refresh visibility
-                            refreshButton.setEnabled(true);
                         }
                     }
                 });
index cba84d9..9b0d603 100644 (file)
@@ -143,7 +143,8 @@ public class FindResourcePage extends WizardPage {
          */
 
         // TODO: Temporarily adding a resourceType for testing
-        resourceTypeCmb.add("oic.r.light");
+       // resourceTypeCmb.add("oic.r.light");
+        resourceTypeCmb.add("sample.light");
 
         // By default, selecting the first item in the resourceType combo
         if (resourceTypeCmb.getItemCount() > 0) {
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/resource/Light/oic.r.light.raml b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/resource/Light/oic.r.light.raml
deleted file mode 100644 (file)
index 810e061..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-#%RAML 0.8
-title: OICLight
-version: v1.0-20150910
-schemas:
-  - OICLight: !include oic.r.light.json
-    OICLightError: !include oic.r.light-error.json
-
-traits:
-  - interface:
-      queryParameters:
-        if:
-          enum: ["oic.if.a"]
-
-/oic/r/light:
-  description: |
-    Resource to be exposed by any OIC Device that can act as Light.
-  displayName: OIC Light
-  is: [ interface ] # valid for all methods
-
-  get:
-    responses:
-      200:
-        body:
-          application/json:
-            schema: OICLight
-            example: |
-              {
-                "rt":     "oic.r.light",
-                "id":     "light_id",
-                "power":  "off"
-              }
-  post:
-    body:
-      application/json:
-        schema: OICLight
-        example: |
-          {
-            "id":    "light_id",
-            "power":  "off"
-          }
-    responses:
-      200:
-        body:
-          application/json:
-            schema: OICLight
-            example: |
-              {
-                "id":    "light_id",
-                "power":  "off"
-              }
-      403:
-        description: |
-          This response is generated by the OIC Server when the client sends:
-            An update with an out of range property value for intensity.
-          The server responds with the range property illustrating the error.
-        body:
-          application/json:
-            schema: OICLightError
-            example: |
-              {
-                "id":     "light_id",
-                "range":  "10,20"
-              }
\ No newline at end of file
@@ -1,29 +1,23 @@
 {
-  "id": "http://openinterconnect.org/schemas/oic.r.light#",
+  "id": "simple.light#",
   "$schema": "http://json-schema.org/draft-04/schema#",
-  "title": "OIC Light",
-  "$ref": "#/definitions/oic.r.light",
+  "title": "Simple Light",
+  "$ref": "#/definitions/light",
   "definitions": {
-    "oic.r.light": {
+    "light": {
       "type": "object",
       "properties": {
-               "rt": {
+               "resourceType": {
           "type": "string",
           "description": "Description about resource type",
-          "default": "oic.r.light"
-        },
-               "if": {
-          "type": "string",
-          "description": "Interface supported",
-          "default": "oic.if.baseline"
+          "default": "sample.light"
         },
         "intensity":  {
-          "type": "integer",
+          "type": "string",
           "description": "ReadOnly, Comma separated min,max values for intensity on this device",
-          "default": "10,20"
+          "default": "1,20"
         }
       }
     }
-  },
-   "required": ["rt","if"]
+  }
 }
@@ -1,21 +1,16 @@
 {
-  "id": "http://openinterconnect.org/schemas/oic.r.light#",
+  "id": "simple.light#",
   "$schema": "http://json-schema.org/schema#",
-  "title": "OIC Light",
-  "$ref": "#/definitions/oic.r.light",
+  "title": "Simple Light",
+  "$ref": "#/definitions/light",
   "definitions": {
-    "oic.r.light": {
+    "light": {
       "type": "object",
       "properties": {
-               "rt": {
+               "resourceType": {
           "type": "string",
           "description": "Description about resource type",
-          "default": "oic.r.light"
-        },
-               "if": {
-          "type": "string",
-          "description": "Interface supported",
-          "default": "oic.if.baseline"
+          "default": "sample.light"
         },
                "power": {
                  "type": "string",
                  "description": "brightness of the light",
                  "default": 1,
                  "minimum": 1,
-          "maximum": 9,                  
+          "maximum": 20,                 
                  "update_frequency": 1001
                  }
                 }
                }
        },      
-  "required": [ "rt","if","power" ]
+  "required": [ "resourceType", "power" ]
 }
\ No newline at end of file
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/resource/Light/simple-light.raml b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/resource/Light/simple-light.raml
new file mode 100644 (file)
index 0000000..3725c6b
--- /dev/null
@@ -0,0 +1,81 @@
+#%RAML 0.8
+title: Simple Light
+version: v1.0-20150910
+schemas:
+  - LightSchema: !include simple-light.json
+    LightSchemaError: !include simple-light-error.json
+
+/sample/light:
+  description: Resource to be exposed by any Simple Device that can act as Light.
+  displayName: Simple Light
+  get:
+    responses:
+      200:
+        body:
+          application/json:
+            schema: LightSchema
+            example: |
+              {
+                "resourceType": "sample.light",
+                "power":  "off"
+              }
+  put:
+    body:
+      application/json:
+        schema: LightSchema
+        example: |
+          {
+            "power":  "off",
+            "intensity": 5
+          }
+    responses:
+      200:
+        body:
+          application/json:
+            schema: LightSchema
+            example: |
+              {
+                "power":  "off",
+                "intensity": 5
+              }
+      403:
+        description: |
+          This response is generated by the Server when the client sends:
+            An update with an out of range property value for intensity.
+          The server responds with the range property illustrating the error.
+        body:
+          application/json:
+            schema: LightSchemaError
+            example: |
+              {
+                "range":  "1,20"
+              }
+  post:
+    body:
+      application/json:
+        schema: LightSchema
+        example: |
+          {
+            "power":  "off"
+          }
+    responses:
+      200:
+        body:
+          application/json:
+            schema: LightSchema
+            example: |
+              {
+                "power":  "off"
+              }
+      403:
+        description: |
+          This response is generated by the Server when the client sends:
+            An update with an out of range property value for intensity.
+          The server responds with the range property illustrating the error.
+        body:
+          application/json:
+            schema: LightSchemaError
+            example: |
+              {
+                "range":  "1,20"
+              }
index 2f20853..940c1b3 100644 (file)
@@ -73,9 +73,8 @@ public class ImageManager {
     }
 
     public static Image getImage(String imagePath) {
-        Image img = null;
         if (null == imagePath || imagePath.length() < 1) {
-            return img;
+            return null;
         }
         URL imageURL = Activator.getDefault().getBundle().getEntry(imagePath);
         ImageDescriptor descriptor = ImageDescriptor.createFromURL(imageURL);
index 32e70ba..08a7037 100644 (file)
@@ -634,7 +634,19 @@ public class ResourceManager {
         Map<String, LocalResourceAttribute> resourceAttributeMap = null;
         if (null != resourceModelN) {
             Map<String, ResourceAttribute> attributeMapN;
-            attributeMapN = resourceModelN.getAttributes();
+            try {
+                attributeMapN = resourceModelN.getAttributes();
+            } catch (SimulatorException e) {
+                Activator
+                        .getDefault()
+                        .getLogManager()
+                        .log(Level.ERROR.ordinal(),
+                                new Date(),
+                                "[" + e.getClass().getSimpleName() + "]"
+                                        + e.code().toString() + "-"
+                                        + e.message());
+                return null;
+            }
             if (null != attributeMapN) {
                 resourceAttributeMap = new HashMap<String, LocalResourceAttribute>();
 
@@ -1049,7 +1061,7 @@ public class ResourceManager {
             Set<String> typeSet = orderedResourceUriMap.keySet();
             List<String> typeList = Utility.convertSetToList(typeSet);
             if (null == typeList || typeList.size() < 1) {
-                return null;
+                return list;
             }
             list = new ArrayList<String>();
 
index 3de0cb5..06f6ebd 100644 (file)
@@ -127,7 +127,8 @@ public class Utility {
             try {
                 result = Integer.parseInt(value);
             } catch (NumberFormatException nfe) {
-                // Do nothing
+                System.out
+                        .println("Getting UpdateInterval from string failed!");
             }
         }
         return result;
index ba5f839..aa686b0 100644 (file)
@@ -440,9 +440,11 @@ public class LogView extends ViewPart {
                                     + e.getMessage());
                 } finally {
                     try {
-                        out.close();
+                        if (null != out) {
+                            out.close();
+                        }
                     } catch (IOException e) {
-                        // Error occurred during close. Ignoring
+                        System.out.println("Error occurred during close.");
                     }
                 }
             }
index 99a609a..fb56e5c 100644 (file)
@@ -213,13 +213,16 @@ public class ResourceManagerView extends ViewPart {
                             System.out.println("Resultant config file path is "
                                     + configFilePath);
                             count = createWizard.getResourceCount();
-                            if (count <= 1) {
-                                // Single resource creation
-                                resourceManager.createResource(configFilePath);
-                            } else {
-                                // Multi-resource creation
-                                resourceManager.createResource(configFilePath,
-                                        count);
+                            if (count > 0) {
+                                if (count == 1) {
+                                    // Single resource creation
+                                    resourceManager
+                                            .createResource(configFilePath);
+                                } else {
+                                    // Multi-resource creation
+                                    resourceManager.createResource(
+                                            configFilePath, count);
+                                }
                             }
                         }
                     }
@@ -244,12 +247,14 @@ public class ResourceManagerView extends ViewPart {
                                     .getDeleteCategory();
                             if (deleteCategory == DeleteCategory.BY_URI) {
                                 String uri = deleteWizard.getDeleteCandidate();
-                                boolean completeURI = Utility
-                                        .isUriComplete(uri);
-                                if (!completeURI) {
-                                    uri = Utility.displayNameToUri(uri);
+                                if (null != uri) {
+                                    boolean completeURI = Utility
+                                            .isUriComplete(uri);
+                                    if (!completeURI) {
+                                        uri = Utility.displayNameToUri(uri);
+                                    }
+                                    resourceManager.deleteResourceByURI(uri);
                                 }
-                                resourceManager.deleteResourceByURI(uri);
                             } else if (deleteCategory == DeleteCategory.BY_TYPE) {
                                 resourceManager
                                         .deleteResourceByType(deleteWizard
index 47452cf..5a11cc0 100644 (file)
@@ -48,10 +48,16 @@ public class CreateResourceWizard extends Wizard {
     }
 
     public String getConfigFilePath() {
+        if (null == page) {
+            return null;
+        }
         return page.getConfigFilePath();
     }
 
     public int getResourceCount() {
+        if (null == page) {
+            return 0;
+        }
         return page.getResourceCount();
     }
 
index 16c3c9c..980b881 100644 (file)
@@ -54,6 +54,9 @@ public class DeleteResourceWizard extends Wizard {
 
     @Override
     public boolean performFinish() {
+        if (null == page) {
+            return false;
+        }
         // Check the existence of the resource if the user has entered the uri
         if (page.getDeleteCategory() == DeleteCategory.BY_URI) {
             // Check whether the uri is in full form or short form
@@ -81,10 +84,16 @@ public class DeleteResourceWizard extends Wizard {
     }
 
     public DeleteCategory getDeleteCategory() {
+        if (null == page) {
+            return DeleteCategory.NONE;
+        }
         return page.getDeleteCategory();
     }
 
     public String getDeleteCandidate() {
+        if (null == page) {
+            return null;
+        }
         return page.getDeleteCandidate();
     }
 }
\ No newline at end of file
index 67bc590..d62fbdd 100644 (file)
@@ -21,7 +21,7 @@ package org.oic.simulator;
  */
 @SuppressWarnings("serial")
 public class InvalidArgsException extends SimulatorException {
-    private InvalidArgsException(int errorCode, String errMessage) {
+    public InvalidArgsException(int errorCode, String errMessage) {
         super(errorCode, errMessage);
     }
 }
index 3329fd2..914641f 100644 (file)
@@ -21,7 +21,7 @@ package org.oic.simulator;
  */
 @SuppressWarnings("serial")
 public class NoSupportException extends SimulatorException {
-    private NoSupportException(int errorCode, String errMessage) {
+    public NoSupportException(int errorCode, String errMessage) {
         super(errorCode, errMessage);
     }
 }
\ No newline at end of file
index 0a95097..c9127b5 100644 (file)
@@ -22,7 +22,7 @@ package org.oic.simulator;
  */
 @SuppressWarnings("serial")
 public class OperationInProgressException extends SimulatorException {
-    private OperationInProgressException(int errorCode, String errMessage) {
+    public OperationInProgressException(int errorCode, String errMessage) {
         super(errorCode, errMessage);
     }
 }
index ca14557..a70d4ce 100644 (file)
@@ -108,13 +108,11 @@ public class SimulatorManager {
      * @param resourceType
      *            Type of resource to be deleted.
      *
-     * @throws InvalidArgsException
-     *             Thrown if the input parameter is empty.
      * @throws SimulatorException
      *             Thrown for other errors.
      */
     public static void deleteResources(String resourceType)
-            throws InvalidArgsException, SimulatorException {
+            throws SimulatorException {
         SimulatorManagerNativeInterface.deleteResources(resourceType);
     }
 
@@ -130,9 +128,9 @@ public class SimulatorManager {
      * @throws SimulatorException
      *             Thrown for other errors.
      */
-    public static void findResource(IFindResourceListener listener)
+    public static void findResources(IFindResourceListener listener)
             throws InvalidArgsException, SimulatorException {
-        SimulatorManagerNativeInterface.findResource(listener);
+        SimulatorManagerNativeInterface.findResources(null, listener);
     }
 
     /**
@@ -152,6 +150,11 @@ public class SimulatorManager {
     public static void findResources(String resourceType,
             IFindResourceListener listener) throws InvalidArgsException,
             SimulatorException {
+        if (null == resourceType || resourceType.isEmpty()) {
+            throw new InvalidArgsException(
+                    SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
+                    "Resource type is empty");
+        }
         SimulatorManagerNativeInterface.findResources(resourceType, listener);
     }
 
index 62410cc..42da05c 100644 (file)
@@ -100,21 +100,7 @@ class SimulatorManagerNativeInterface {
             throws InvalidArgsException, SimulatorException;
 
     /**
-     * Native function for discovering all types of resources.
-     *
-     * @param listener
-     *            Interface to receive the discovered remote resources.
-     * 
-     * @throws InvalidArgsException
-     *             Thrown if the input parameter is empty.
-     * @throws SimulatorException
-     *             Thrown for other errors.
-     */
-    public static native void findResource(IFindResourceListener listener)
-            throws InvalidArgsException, SimulatorException;
-
-    /**
-     * Native function for discovering specific type of resources.
+     * Native function for discovering resources.
      *
      * @param resourceType
      *            required resource type
index 49bc4c0..4b89502 100644 (file)
@@ -27,7 +27,7 @@ public class SimulatorResourceModel {
 
     /**
      * Constructor for creating a native resource model object. Client requests
-     * such as PUT and POST uses this method for passing the new new/updated
+     * such as PUT and POST uses this method for passing the new/updated
      * resource model.
      */
     public SimulatorResourceModel() {
@@ -41,10 +41,16 @@ public class SimulatorResourceModel {
      *            Name of the attribute
      * @param value
      *            Value of the attribute
+     *
+     * @throws InvalidArgsException
+     *             This exception will be thrown if the attribute name is
+     *             invalid.
+     * @throws SimulatorException
+     *             This exception will be thrown either if the resource model is
+     *             not found or for some general errors.
      */
-    public void addAttribute(String name, int value) {
-        addAttributeInt(name, value);
-    }
+    public native void addAttributeInt(String name, int value)
+            throws InvalidArgsException, SimulatorException;
 
     /**
      * Method for adding an attribute whose value is of type double.
@@ -53,10 +59,16 @@ public class SimulatorResourceModel {
      *            Name of the attribute
      * @param value
      *            Value of the attribute
+     *
+     * @throws InvalidArgsException
+     *             This exception will be thrown if the attribute name is
+     *             invalid.
+     * @throws SimulatorException
+     *             This exception will be thrown either if the resource model is
+     *             not found or for some general errors.
      */
-    public void addAttribute(String name, double value) {
-        addAttributeDouble(name, value);
-    }
+    public native void addAttributeDouble(String name, double value)
+            throws InvalidArgsException, SimulatorException;
 
     /**
      * Method for adding an attribute whose value is of type boolean.
@@ -65,10 +77,16 @@ public class SimulatorResourceModel {
      *            Name of the attribute
      * @param value
      *            Value of the attribute
+     *
+     * @throws InvalidArgsException
+     *             This exception will be thrown if the attribute name is
+     *             invalid.
+     * @throws SimulatorException
+     *             This exception will be thrown either if the resource model is
+     *             not found or for some general errors.
      */
-    public void addAttribute(String name, boolean value) {
-        addAttributeBoolean(name, value);
-    }
+    public native void addAttributeBoolean(String name, boolean value)
+            throws InvalidArgsException, SimulatorException;
 
     /**
      * Method for adding an attribute whose value is of type string.
@@ -77,25 +95,40 @@ public class SimulatorResourceModel {
      *            Name of the attribute
      * @param value
      *            Value of the attribute
+     *
+     * @throws InvalidArgsException
+     *             This exception will be thrown if the attribute name is
+     *             invalid.
+     * @throws SimulatorException
+     *             This exception will be thrown either if the resource model is
+     *             not found or for some general errors.
      */
-    public void addAttribute(String name, String value) {
-        addAttributeString(name, value);
-    }
+    public native void addAttributeString(String name, String value)
+            throws InvalidArgsException, SimulatorException;
 
     /**
      * Method for getting the number of attributes this model comprised of.
      *
      * @return Number of attributes.
+     * 
+     * @throws SimulatorException
+     *             This exception will be thrown either if the resource model is
+     *             not found or for some general errors.
      */
-    public native int size();
+    public native int size() throws SimulatorException;
 
     /**
      * Method for getting all attributes.
      *
      * @return Map of attributes with attribute name as the key and its
      *         corresponding {@link ResourceAttribute} object as the value.
+     * 
+     * @throws SimulatorException
+     *             This exception will be thrown either if the resource model is
+     *             not found or for some general errors.
      */
-    public native Map<String, ResourceAttribute> getAttributes();
+    public native Map<String, ResourceAttribute> getAttributes()
+            throws SimulatorException;
 
     /**
      * Method for getting a specific attribute by its name.
@@ -104,16 +137,17 @@ public class SimulatorResourceModel {
      *            Name of the attribute
      *
      * @return An object of {@link ResourceAttribute}.
+     * 
+     * @throws InvalidArgsException
+     *             This exception will be thrown if the attribute does not
+     *             exist.
+     * 
+     * @throws SimulatorException
+     *             This exception will be thrown either if the resource model is
+     *             not found or for some general errors.
      */
-    public native ResourceAttribute getAttribute(String attrName);
-
-    private native void addAttributeInt(String name, int value);
-
-    private native void addAttributeDouble(String name, double value);
-
-    private native void addAttributeBoolean(String name, boolean value);
-
-    private native void addAttributeString(String name, String value);
+    public native ResourceAttribute getAttribute(String attrName)
+            throws InvalidArgsException, SimulatorException;
 
     private SimulatorResourceModel(long nativeHandle) {
         this.nativeHandle = nativeHandle;
@@ -121,7 +155,14 @@ public class SimulatorResourceModel {
 
     @Override
     protected void finalize() throws Throwable {
-        dispose();
+        try {
+            dispose();
+        } catch(Throwable t){
+            throw t;
+        } finally{
+            System.out.println("Calling finalize of Super Class");
+            super.finalize();
+        }
     }
 
     private native void create();
index eacfc4c..a352e4c 100644 (file)
@@ -81,7 +81,14 @@ public class SimulatorResourceServer {
 
     @Override
     protected void finalize() throws Throwable {
-        dispose();
+        try {
+            dispose();
+        } catch(Throwable t){
+            throw t;
+        } finally{
+            System.out.println("Calling finalize of Super Class");
+            super.finalize();
+        }
     }
 
     /**
@@ -440,7 +447,7 @@ public class SimulatorResourceServer {
             throws InvalidArgsException, SimulatorException;
 
     /**
-     * Native function to set the observation callback.
+     * Native function to set callback to receive the clients information who are started or stopped observing the simulated resource.
      * 
      * @param observer
      *            Listener to be notified when clients start/stop observing.