Fix for SVACE reported issues on Simulator Java layer.
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ServiceProviderPlugin / src / oic / simulator / serviceprovider / view / MetaPropertiesView.java
index 936df8f..d5fd2d6 100644 (file)
@@ -148,15 +148,14 @@ public class MetaPropertiesView extends ViewPart {
                         updatedIfSet = resource.getResourceInterfaces();
                     }
                 } else {
-                    boolean result = false;
                     Resource resourceInSelection = resourceManagerRef
                             .getCurrentResourceInSelection();
                     if (null != resourceInSelection) {
 
                         // Null Check
-                        result = resourceManagerRef.isPropertyValueInvalid(
-                                resourceInSelection, properties,
-                                Constants.RESOURCE_URI);
+                        boolean result = resourceManagerRef
+                                .isPropertyValueInvalid(resourceInSelection,
+                                        properties, Constants.RESOURCE_URI);
                         if (result) {
                             MessageDialog.openError(parent.getShell(),
                                     "Invalid Resource URI.",
@@ -174,8 +173,19 @@ public class MetaPropertiesView extends ViewPart {
                             return;
                         }
 
+                        result = resourceManagerRef.isPropertyValueInvalid(
+                                resourceInSelection, properties,
+                                Constants.RESOURCE_TYPE);
+                        if (result) {
+                            MessageDialog.openError(parent.getShell(),
+                                    "Invalid Resource Type.",
+                                    Constants.INVALID_RESOURCE_TYPE_MESSAGE);
+                            return;
+                        }
+
                         boolean update = false;
                         boolean uriChange = false;
+                        boolean typeChange = false;
                         boolean nameChange = false;
                         boolean interfaceChange = false;
 
@@ -185,6 +195,7 @@ public class MetaPropertiesView extends ViewPart {
                             update = true;
                             nameChange = true;
                         }
+
                         if (resourceManagerRef.isPropValueChanged(
                                 resourceInSelection, properties,
                                 Constants.RESOURCE_URI)) {
@@ -196,27 +207,23 @@ public class MetaPropertiesView extends ViewPart {
                                 return;
                             }
 
-                            if (resourceManagerRef
-                                    .isResourceStarted(resourceInSelection)) {
-                                update = MessageDialog.openQuestion(
-                                        parent.getShell(), "Save Details",
-                                        "Resource will be restarted to take the changes."
-                                                + " Do you want to continue?");
-                                if (!update) {
-                                    return;
-                                }
-                            }
-
                             update = true;
                             uriChange = true;
                         }
+
+                        if (resourceManagerRef.isPropValueChanged(
+                                resourceInSelection, properties,
+                                Constants.RESOURCE_TYPE)) {
+                            update = true;
+                            typeChange = true;
+                        }
                         // Checking whether any changes made in resource
                         // interfaces by
                         // comparing the current interface set and updated
                         // interface set.
-                        if (null != updatedIfSet) {
-                            Set<String> curIfSet = resourceInSelection
-                                    .getResourceInterfaces();
+                        Set<String> curIfSet = resourceInSelection
+                                .getResourceInterfaces();
+                        if (null != curIfSet && null != updatedIfSet) {
                             if (curIfSet.size() != updatedIfSet.size()) {
                                 update = true;
                                 interfaceChange = true;
@@ -232,8 +239,21 @@ public class MetaPropertiesView extends ViewPart {
                             }
                         }
                         if (update) {
+                            if (uriChange || typeChange || interfaceChange) {
+                                if (resourceManagerRef
+                                        .isResourceStarted(resourceInSelection)) {
+                                    update = MessageDialog.openQuestion(
+                                            parent.getShell(),
+                                            "Save Details",
+                                            "Resource will be restarted to take the changes."
+                                                    + " Do you want to continue?");
+                                    if (!update) {
+                                        return;
+                                    }
+                                }
+                            }
                             try {
-                                if (uriChange || nameChange)
+                                if (uriChange || nameChange || typeChange)
                                     result = Activator
                                             .getDefault()
                                             .getResourceManager()
@@ -241,7 +261,7 @@ public class MetaPropertiesView extends ViewPart {
                                                     resourceManagerRef
                                                             .getCurrentResourceInSelection(),
                                                     properties, uriChange,
-                                                    nameChange);
+                                                    nameChange, typeChange);
                                 if (interfaceChange)
                                     result = Activator
                                             .getDefault()
@@ -253,11 +273,7 @@ public class MetaPropertiesView extends ViewPart {
                             } catch (SimulatorException ex) {
                                 result = false;
                             }
-                            if (result) {
-                                MessageDialog.openInformation(
-                                        parent.getShell(), "Operation status",
-                                        "Resource properties updated.");
-                            } else {
+                            if (!result) {
                                 MessageDialog.openInformation(
                                         parent.getShell(), "Operation status",
                                         "Failed to update the resource properties.");
@@ -400,7 +416,8 @@ public class MetaPropertiesView extends ViewPart {
                 resourceSelectionChangedListener);
     }
 
-    class PropertycontentProvider implements IStructuredContentProvider {
+    private static class PropertycontentProvider implements
+            IStructuredContentProvider {
 
         @Override
         public void dispose() {
@@ -446,12 +463,7 @@ public class MetaPropertiesView extends ViewPart {
             if (!getEnableEdit()) {
                 return null;
             }
-            // Disabling edit for resource type
             String propName = ((MetaProperty) element).getPropName();
-            if (null != propName && propName.equals(Constants.RESOURCE_TYPE)) {
-                return null;
-            }
-
             CellEditor editor = new TextCellEditor(viewer.getTable());
             if (null != propName && propName.equals(Constants.INTERFACE_TYPES)) {
                 editor.setStyle(SWT.READ_ONLY);
@@ -481,20 +493,20 @@ public class MetaPropertiesView extends ViewPart {
                             // Update the local copy of the current resource
                             // interfaces to keep the state for save operation.
                             updatedIfSet.clear();
-                            String newPropValue = "";
+                            StringBuilder newPropValue = new StringBuilder();
                             for (Map.Entry<String, String> entry : curResInterfaces
                                     .entrySet()) {
-                                if (!newPropValue.isEmpty()) {
-                                    newPropValue += ", ";
+                                if (!newPropValue.toString().isEmpty()) {
+                                    newPropValue.append(", ");
                                 }
                                 String value = ifTypes.get(entry.getKey());
-                                newPropValue += value;
+                                newPropValue.append(value);
 
                                 updatedIfSet.add(value);
                             }
                             // Update the model
                             MetaProperty prop = (MetaProperty) element;
-                            prop.setPropValue(newPropValue);
+                            prop.setPropValue(newPropValue.toString());
                             // Update the viewer in a separate UI thread.
                             Display.getDefault().asyncExec(new Runnable() {
                                 @Override