Fix for klocwork issues.
authorG S Senthil Kumar <senthil.gs@samsung.com>
Fri, 11 Mar 2016 16:29:28 +0000 (21:59 +0530)
committerMadan Lanka <lanka.madan@samsung.com>
Thu, 17 Mar 2016 05:35:50 +0000 (05:35 +0000)
This change includes fix for all klocwork reported issues
in native and java layer.

Change-Id: Ibba5d478e64251636c8ef514c52b9e9bd6f36442
Signed-off-by: G S Senthil Kumar <senthil.gs@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/5749
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
(cherry picked from commit 975f03206382a5a92a1bb6b02797716361103989)
Reviewed-on: https://gerrit.iotivity.org/gerrit/5945

43 files changed:
service/simulator/examples/server/simulator_server.cpp
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/manager/ResourceManager.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/AttributeElement.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/ResourceRepresentation.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/SerializedClientController.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/AttributeValueBuilder.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/AttributeValueStringConverter.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/Utility.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/AttributeEditingSupport.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/AttributeView.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/LoadRAMLDialog.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/LogDetailsDialog.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/ModelArrayAddItemDialog.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/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/UpdatePrimitiveArrayAttributeDialog.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/AttributeElement.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/AttributeHelper.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/AutomationSettingHelper.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/SerializedServiceProvider.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/AttributeValueStringConverter.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/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/CreateResourceWizard.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteResourcePage.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/LogDetailsDialog.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/ModelArrayAddItemDialog.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/UpdatePrimitiveArrayAttributeDialog.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/UpdateResourceInterfaceDialog.java
service/simulator/java/sdk/src/org/oic/simulator/ArrayValueValidator.java
service/simulator/java/sdk/src/org/oic/simulator/AttributeValue.java
service/simulator/java/sdk/src/org/oic/simulator/SimulatorException.java
service/simulator/java/sdk/src/org/oic/simulator/SimulatorManager.java
service/simulator/java/sdk/src/org/oic/simulator/SimulatorResourceAttribute.java
service/simulator/java/sdk/src/org/oic/simulator/StringProperty.java
service/simulator/src/server/simulator_resource_factory.cpp

index 776fc21..a02c24d 100644 (file)
@@ -105,6 +105,12 @@ void simulateResource()
             std::cout << "Single type resource created [URI:  " << resource->getURI() << " ]" << std::endl;
             SimulatorSingleResourceSP singleRes =
                 std::dynamic_pointer_cast<SimulatorSingleResource>(resource);
+            if (!singleRes)
+            {
+                std::cout << "Error occured while converting SimulatorResource to SimulatorSingleResource!" << std::endl;
+                return;
+            }
+
             singleRes->setModelChangeCallback(modelChangeCB);
             singleRes->setObserverCallback(observerCB);
             g_singleResources.push_back(singleRes);
@@ -114,6 +120,12 @@ void simulateResource()
             std::cout << "Collection type resource created [URI:  " << resource->getURI() << " ]" << std::endl;
             SimulatorCollectionResourceSP collectionRes =
                 std::dynamic_pointer_cast<SimulatorCollectionResource>(resource);
+            if (!collectionRes)
+            {
+                std::cout << "Error occured while converting SimulatorResource to SimulatorCollectionResource!" << std::endl;
+                return;
+            }
+
             collectionRes->setObserverCallback(observerCB);
             g_collectionResources.push_back(collectionRes);
         }
index 03d8d35..6a8a17b 100644 (file)
@@ -125,8 +125,9 @@ public class ResourceManager {
                         // Ignore the response if the resource is a device or
                         // platform.
                         Vector<String> resTypes = resourceN.getResourceTypes();
-                        if (null != resTypes && resTypes.contains("oic.wk.d")
-                                || resTypes.contains("oic.wk.p")) {
+                        if (null != resTypes
+                                && (resTypes.contains("oic.wk.d") || resTypes
+                                        .contains("oic.wk.p"))) {
                             return;
                         }
 
@@ -797,7 +798,7 @@ public class ResourceManager {
     }
 
     public boolean isResourceObserved(String resourceURI) {
-        boolean observed = false;
+        boolean observed;
         synchronized (observedResourceURIList) {
             observed = observedResourceURIList.contains(resourceURI);
         }
@@ -885,7 +886,7 @@ public class ResourceManager {
 
     public void deleteResources(final Set<String> searchTypes) {
         synchronized (resourceMap) {
-            if (null == resourceMap && resourceMap.isEmpty()) {
+            if (null == resourceMap || resourceMap.isEmpty()) {
                 return;
             }
         }
@@ -1012,57 +1013,57 @@ public class ResourceManager {
     public List<MetaProperty> getDefaultProperties(RemoteResource resource) {
         if (null != resource) {
             String propName;
-            String propValue;
+            StringBuilder propValue;
 
             List<MetaProperty> metaPropertyList = new ArrayList<MetaProperty>();
 
             for (int index = 0; index < Constants.META_PROPERTY_COUNT; index++) {
                 propName = Constants.META_PROPERTIES[index];
+                propValue = new StringBuilder();
                 if (propName.equals(Constants.RESOURCE_URI)) {
-                    propValue = resource.getRemoteResourceRef().getURI();
+                    propValue.append(resource.getRemoteResourceRef().getURI());
                 } else if (propName.equals(Constants.CONNECTIVITY_TYPE)) {
-                    propValue = resource.getRemoteResourceRef()
-                            .getConnectivityType().toString();
+                    propValue.append(resource.getRemoteResourceRef()
+                            .getConnectivityType().toString());
                 } else if (propName.equals(Constants.ADDRESS)) {
-                    propValue = resource.getRemoteResourceRef().getHost();
+                    propValue.append(resource.getRemoteResourceRef().getHost());
                 } else if (propName.equals(Constants.OBSERVABLE)) {
-                    propValue = Utility.getObservableInString(resource
-                            .getRemoteResourceRef().isObservable());
+                    propValue.append(Utility.getObservableInString(resource
+                            .getRemoteResourceRef().isObservable()));
                 } else if (propName.equals(Constants.RESOURCE_TYPES)) {
                     Vector<String> resTypes = resource.getRemoteResourceRef()
                             .getResourceTypes();
                     if (null != resTypes && !resTypes.isEmpty()) {
-                        propValue = "";
                         Iterator<String> itr = resTypes.iterator();
                         while (itr.hasNext()) {
-                            propValue += itr.next();
+                            propValue.append(itr.next());
                             if (itr.hasNext()) {
-                                propValue += ", ";
+                                propValue.append(", ");
                             }
                         }
                     } else {
-                        propValue = Constants.NOT_AVAILABLE;
+                        propValue.append(Constants.NOT_AVAILABLE);
                     }
                 } else if (propName.equals(Constants.RESOURCE_INTERFACES)) {
                     Vector<String> interfaces = resource.getRemoteResourceRef()
                             .getResourceInterfaces();
                     if (null != interfaces && !interfaces.isEmpty()) {
-                        propValue = "";
                         Iterator<String> itr = interfaces.iterator();
                         while (itr.hasNext()) {
-                            propValue += itr.next();
+                            propValue.append(itr.next());
                             if (itr.hasNext()) {
-                                propValue += ", ";
+                                propValue.append(", ");
                             }
                         }
                     } else {
-                        propValue = Constants.NOT_AVAILABLE;
+                        propValue.append(Constants.NOT_AVAILABLE);
                     }
                 } else {
                     propValue = null;
                 }
                 if (null != propValue) {
-                    metaPropertyList.add(new MetaProperty(propName, propValue));
+                    metaPropertyList.add(new MetaProperty(propName, propValue
+                            .toString()));
                 }
             }
 
index 19f61d9..ac43c02 100644 (file)
 
 package oic.simulator.clientcontroller.remoteresource;
 
+import java.util.Date;
 import java.util.Map;
 import java.util.TreeMap;
 
 import org.oic.simulator.ArrayProperty;
 import org.oic.simulator.AttributeProperty;
 import org.oic.simulator.AttributeValue;
+import org.oic.simulator.ILogger.Level;
 import org.oic.simulator.InvalidArgsException;
 import org.oic.simulator.ModelProperty;
 import org.oic.simulator.SimulatorResourceAttribute;
 import org.oic.simulator.SimulatorResourceModel;
 
+import oic.simulator.clientcontroller.Activator;
 import oic.simulator.clientcontroller.utils.AttributeValueStringConverter;
+import oic.simulator.clientcontroller.utils.Utility;
 
 public class AttributeElement {
     private Object                        mParent          = null;
@@ -65,9 +69,9 @@ public class AttributeElement {
                     SimulatorResourceModel[] resModelArray = (SimulatorResourceModel[]) attribute
                             .value().get();
 
-                    ArrayProperty arrProp = null;
                     ModelProperty modelProp = null;
                     if (null != attribute.property()) {
+                        ArrayProperty arrProp;
                         arrProp = attribute.property().asArray();
                         if (null != arrProp
                                 && null != arrProp.getElementProperty()) {
@@ -85,15 +89,13 @@ public class AttributeElement {
                     SimulatorResourceModel[][] resModelArray = (SimulatorResourceModel[][]) attribute
                             .value().get();
 
-                    ArrayProperty arrProp = null;
-                    ArrayProperty arrChildPropLevel1 = null;
                     ModelProperty modelProp = null;
                     if (null != attribute.property()) {
-                        arrProp = attribute.property().asArray();
+                        ArrayProperty arrProp = attribute.property().asArray();
                         if (null != arrProp
                                 && null != arrProp.getElementProperty()) {
-                            arrChildPropLevel1 = arrProp.getElementProperty()
-                                    .asArray();
+                            ArrayProperty arrChildPropLevel1 = arrProp
+                                    .getElementProperty().asArray();
                             if (null != arrChildPropLevel1
                                     && null != arrChildPropLevel1
                                             .getElementProperty()) {
@@ -114,20 +116,17 @@ public class AttributeElement {
                     SimulatorResourceModel[][][] resModelArray = (SimulatorResourceModel[][][]) attribute
                             .value().get();
 
-                    ArrayProperty arrProp = null;
-                    ArrayProperty arrChildPropLevel1 = null;
-                    ArrayProperty arrChildPropLevel2 = null;
                     ModelProperty modelProp = null;
                     if (null != attribute.property()) {
-                        arrProp = attribute.property().asArray();
+                        ArrayProperty arrProp = attribute.property().asArray();
                         if (null != arrProp
                                 && null != arrProp.getElementProperty()) {
-                            arrChildPropLevel1 = arrProp.getElementProperty()
-                                    .asArray();
+                            ArrayProperty arrChildPropLevel1 = arrProp
+                                    .getElementProperty().asArray();
                             if (null != arrChildPropLevel1
                                     && null != arrChildPropLevel1
                                             .getElementProperty()) {
-                                arrChildPropLevel2 = arrChildPropLevel1
+                                ArrayProperty arrChildPropLevel2 = arrChildPropLevel1
                                         .getElementProperty().asArray();
                                 if (null != arrChildPropLevel2
                                         && null != arrChildPropLevel2
@@ -199,7 +198,7 @@ public class AttributeElement {
     }
 
     public void setAttributeProperty(SimulatorResourceAttribute attribute)
-            throws Exception {
+            throws NullPointerException {
         if (attribute == null)
             return;
 
@@ -346,10 +345,9 @@ public class AttributeElement {
                 SimulatorResourceModel[] resModelArray = (SimulatorResourceModel[]) attribute
                         .value().get();
 
-                ArrayProperty arrProp = null;
                 ModelProperty modelProp = null;
                 if (null != attribute.property()) {
-                    arrProp = attribute.property().asArray();
+                    ArrayProperty arrProp = attribute.property().asArray();
                     if (null != arrProp && null != arrProp.getElementProperty()) {
                         modelProp = arrProp.getElementProperty().asModel();
                     }
@@ -376,14 +374,12 @@ public class AttributeElement {
                 SimulatorResourceModel[][] resModelArray = (SimulatorResourceModel[][]) attribute
                         .value().get();
 
-                ArrayProperty arrProp = null;
-                ArrayProperty arrChildPropLevel1 = null;
                 ModelProperty modelProp = null;
                 if (null != attribute.property()) {
-                    arrProp = attribute.property().asArray();
+                    ArrayProperty arrProp = attribute.property().asArray();
                     if (null != arrProp && null != arrProp.getElementProperty()) {
-                        arrChildPropLevel1 = arrProp.getElementProperty()
-                                .asArray();
+                        ArrayProperty arrChildPropLevel1 = arrProp
+                                .getElementProperty().asArray();
                         if (null != arrChildPropLevel1
                                 && null != arrChildPropLevel1
                                         .getElementProperty()) {
@@ -413,19 +409,16 @@ public class AttributeElement {
                 SimulatorResourceModel[][][] resModelArray = (SimulatorResourceModel[][][]) attribute
                         .value().get();
 
-                ArrayProperty arrProp = null;
-                ArrayProperty arrChildPropLevel1 = null;
-                ArrayProperty arrChildPropLevel2 = null;
                 ModelProperty modelProp = null;
                 if (null != attribute.property()) {
-                    arrProp = attribute.property().asArray();
+                    ArrayProperty arrProp = attribute.property().asArray();
                     if (null != arrProp && null != arrProp.getElementProperty()) {
-                        arrChildPropLevel1 = arrProp.getElementProperty()
-                                .asArray();
+                        ArrayProperty arrChildPropLevel1 = arrProp
+                                .getElementProperty().asArray();
                         if (null != arrChildPropLevel1
                                 && null != arrChildPropLevel1
                                         .getElementProperty()) {
-                            arrChildPropLevel2 = arrChildPropLevel1
+                            ArrayProperty arrChildPropLevel2 = arrChildPropLevel1
                                     .getElementProperty().asArray();
                             if (null != arrChildPropLevel2
                                     && null != arrChildPropLevel2
@@ -466,6 +459,15 @@ public class AttributeElement {
                         ((AttributeElement) mParent)
                                 .deepSetChildValue(mAttribute);
                     } catch (InvalidArgsException e) {
+                        Activator
+                                .getDefault()
+                                .getLogManager()
+                                .log(Level.ERROR.ordinal(),
+                                        new Date(),
+                                        "There is an error while updating the resource model.\n"
+                                                + Utility
+                                                        .getSimulatorErrorString(
+                                                                e, null));
                     }
                 }
             }
index 9ee6dc6..00f76d8 100644 (file)
@@ -79,7 +79,8 @@ public class ResourceRepresentation {
 
     public boolean updateAttributeProperties(
             SimulatorRequestModel requestModel,
-            SimulatorResourceModel resourceModelRef) throws Exception {
+            SimulatorResourceModel resourceModelRef)
+            throws NullPointerException {
         if (null == requestModel || null == resourceModelRef) {
             return false;
         }
index c41a96f..51136a0 100644 (file)
@@ -17,6 +17,7 @@
 package oic.simulator.clientcontroller.remoteresource;
 
 import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.ObjectInputStream;
@@ -42,32 +43,40 @@ public class SerializedClientController implements Serializable {
         this.m_favorites = favorites;
     }
 
-    public void serialize(String filePath) throws Exception {
+    public void serialize(String filePath) throws FileNotFoundException,
+            IOException {
+        FileOutputStream fileOut = null;
+        ObjectOutputStream out = null;
         try {
-            FileOutputStream fileOut = new FileOutputStream(filePath);
-            ObjectOutputStream out = new ObjectOutputStream(fileOut);
+            fileOut = new FileOutputStream(filePath);
+            out = new ObjectOutputStream(fileOut);
             out.writeObject(this);
-            out.close();
-            fileOut.close();
-        } catch (IOException i) {
-            throw new Exception("Failed to Serialize data : IOException");
+        } finally {
+            if (null != fileOut)
+                fileOut.close();
+
+            if (null != out)
+                out.close();
         }
     }
 
     public static SerializedClientController deSerialize(String filePath)
-            throws Exception {
+            throws FileNotFoundException, IOException, ClassNotFoundException {
+        FileInputStream fileIn = null;
+        ObjectInputStream in = null;
         SerializedClientController r = null;
         try {
-            FileInputStream fileIn = new FileInputStream(filePath);
-            ObjectInputStream in = new ObjectInputStream(fileIn);
+            fileIn = new FileInputStream(filePath);
+            in = new ObjectInputStream(fileIn);
             r = (SerializedClientController) in.readObject();
-            in.close();
-            fileIn.close();
-        } catch (IOException i) {
-            throw new Exception("Failed to DeSerialize data : IOException");
-        } catch (ClassNotFoundException c) {
-            throw new Exception("Failed to DeSerialize data : ClassNotFound");
+        } finally {
+            if (null != fileIn)
+                fileIn.close();
+
+            if (null != in)
+                in.close();
         }
+
         return r;
     }
 
index 221f1d4..7816faa 100644 (file)
@@ -22,7 +22,7 @@ import org.oic.simulator.AttributeValue;
 
 public class AttributeValueBuilder {
     public static AttributeValue build(String valueString,
-            AttributeValue.ValueType valueType) throws Exception {
+            AttributeValue.ValueType valueType) throws NullPointerException {
         int depth = findDepth(valueString);
         if (0 == depth) {
             return handleDepth0(valueString, valueType);
@@ -90,9 +90,8 @@ public class AttributeValueBuilder {
         return null;
     }
 
-    private static String[] splitIntoArrays(String value) {
+    private static String[] splitIntoArrays(String valueString) {
         Vector<String> values = new Vector<String>();
-        String valueString = new String(value);
         valueString = valueString.substring(valueString.indexOf('[') + 1,
                 valueString.lastIndexOf(']'));
 
@@ -135,8 +134,12 @@ public class AttributeValueBuilder {
             for (int index = 0; index < valuesString.length; index++) {
                 if (null != valuesString[index]
                         && !valuesString[index].isEmpty()) {
-                    Integer value = (Integer) handleDepth0(valuesString[index],
-                            valueType).get();
+                    AttributeValue attValue = handleDepth0(valuesString[index],
+                            valueType);
+                    if (null == attValue)
+                        return null;
+
+                    Integer value = (Integer) attValue.get();
                     if (null == value)
                         return null;
                     result[index] = value;
@@ -152,8 +155,12 @@ public class AttributeValueBuilder {
             for (int index = 0; index < valuesString.length; index++) {
                 if (null != valuesString[index]
                         && !valuesString[index].isEmpty()) {
-                    Double value = (Double) handleDepth0(valuesString[index],
-                            valueType).get();
+                    AttributeValue attValue = handleDepth0(valuesString[index],
+                            valueType);
+                    if (null == attValue)
+                        return null;
+
+                    Double value = (Double) attValue.get();
                     if (null == value)
                         return null;
                     result[index] = value;
@@ -169,8 +176,12 @@ public class AttributeValueBuilder {
             for (int index = 0; index < valuesString.length; index++) {
                 if (null != valuesString[index]
                         && !valuesString[index].isEmpty()) {
-                    Boolean value = (Boolean) handleDepth0(valuesString[index],
-                            valueType).get();
+                    AttributeValue attValue = handleDepth0(valuesString[index],
+                            valueType);
+                    if (null == attValue)
+                        return null;
+
+                    Boolean value = (Boolean) attValue.get();
                     if (null == value)
                         return null;
                     result[index] = value;
@@ -207,8 +218,12 @@ public class AttributeValueBuilder {
         if (valueType == AttributeValue.ValueType.INTEGER) {
             Integer[][] result = new Integer[valuesString.length][];
             for (int index = 0; index < valuesString.length; index++) {
-                Integer[] value = (Integer[]) handleDepth1(valuesString[index],
-                        valueType).get();
+                AttributeValue attValue = handleDepth1(valuesString[index],
+                        valueType);
+                if (null == attValue)
+                    return null;
+
+                Integer[] value = (Integer[]) attValue.get();
                 if (null == value)
                     return null;
                 result[index] = value;
@@ -217,8 +232,12 @@ public class AttributeValueBuilder {
         } else if (valueType == AttributeValue.ValueType.DOUBLE) {
             Double[][] result = new Double[valuesString.length][];
             for (int index = 0; index < valuesString.length; index++) {
-                Double[] value = (Double[]) handleDepth1(valuesString[index],
-                        valueType).get();
+                AttributeValue attValue = handleDepth1(valuesString[index],
+                        valueType);
+                if (null == attValue)
+                    return null;
+
+                Double[] value = (Double[]) attValue.get();
                 if (null == value)
                     return null;
                 result[index] = value;
@@ -227,8 +246,12 @@ public class AttributeValueBuilder {
         } else if (valueType == AttributeValue.ValueType.BOOLEAN) {
             Boolean[][] result = new Boolean[valuesString.length][];
             for (int index = 0; index < valuesString.length; index++) {
-                Boolean[] value = (Boolean[]) handleDepth1(valuesString[index],
-                        valueType).get();
+                AttributeValue attValue = handleDepth1(valuesString[index],
+                        valueType);
+                if (null == attValue)
+                    return null;
+
+                Boolean[] value = (Boolean[]) attValue.get();
                 if (null == value)
                     return null;
                 result[index] = value;
@@ -237,8 +260,12 @@ public class AttributeValueBuilder {
         } else if (valueType == AttributeValue.ValueType.STRING) {
             String[][] result = new String[valuesString.length][];
             for (int index = 0; index < valuesString.length; index++) {
-                String[] value = (String[]) handleDepth1(valuesString[index],
-                        valueType).get();
+                AttributeValue attValue = handleDepth1(valuesString[index],
+                        valueType);
+                if (null == attValue)
+                    return null;
+
+                String[] value = (String[]) attValue.get();
                 if (null == value)
                     return null;
                 result[index] = value;
@@ -262,8 +289,12 @@ public class AttributeValueBuilder {
         if (valueType == AttributeValue.ValueType.INTEGER) {
             Integer[][][] result = new Integer[valuesString.length][][];
             for (int index = 0; index < valuesString.length; index++) {
-                Integer[][] value = (Integer[][]) handleDepth2(
-                        valuesString[index], valueType).get();
+                AttributeValue attValue = handleDepth2(valuesString[index],
+                        valueType);
+                if (null == attValue)
+                    return null;
+
+                Integer[][] value = (Integer[][]) attValue.get();
                 if (null == value)
                     return null;
                 result[index] = value;
@@ -272,8 +303,12 @@ public class AttributeValueBuilder {
         } else if (valueType == AttributeValue.ValueType.DOUBLE) {
             Double[][][] result = new Double[valuesString.length][][];
             for (int index = 0; index < valuesString.length; index++) {
-                Double[][] value = (Double[][]) handleDepth2(
-                        valuesString[index], valueType).get();
+                AttributeValue attValue = handleDepth2(valuesString[index],
+                        valueType);
+                if (null == attValue)
+                    return null;
+
+                Double[][] value = (Double[][]) attValue.get();
                 if (null == value)
                     return null;
                 result[index] = value;
@@ -282,8 +317,12 @@ public class AttributeValueBuilder {
         } else if (valueType == AttributeValue.ValueType.BOOLEAN) {
             Boolean[][][] result = new Boolean[valuesString.length][][];
             for (int index = 0; index < valuesString.length; index++) {
-                Boolean[][] value = (Boolean[][]) handleDepth2(
-                        valuesString[index], valueType).get();
+                AttributeValue attValue = handleDepth2(valuesString[index],
+                        valueType);
+                if (null == attValue)
+                    return null;
+
+                Boolean[][] value = (Boolean[][]) attValue.get();
                 if (null == value)
                     return null;
                 result[index] = value;
@@ -292,8 +331,12 @@ public class AttributeValueBuilder {
         } else if (valueType == AttributeValue.ValueType.STRING) {
             String[][][] result = new String[valuesString.length][][];
             for (int index = 0; index < valuesString.length; index++) {
-                String[][] value = (String[][]) handleDepth2(
-                        valuesString[index], valueType).get();
+                AttributeValue attValue = handleDepth2(valuesString[index],
+                        valueType);
+                if (null == attValue)
+                    return null;
+
+                String[][] value = (String[][]) attValue.get();
                 if (null == value)
                     return null;
                 result[index] = value;
index 89434dc..f3e3cdb 100644 (file)
@@ -28,6 +28,7 @@ import java.util.Set;
 import org.oic.simulator.AttributeValue;
 import org.oic.simulator.AttributeValue.TypeInfo;
 import org.oic.simulator.AttributeValue.ValueType;
+import org.oic.simulator.InvalidArgsException;
 import org.oic.simulator.SimulatorException;
 import org.oic.simulator.SimulatorResourceModel;
 
@@ -176,8 +177,7 @@ public class Utility {
     }
 
     public static Map<String, String> getResourceInterfaces() {
-        Map<String, String> ifTypes = null;
-        ifTypes = new HashMap<String, String>();
+        Map<String, String> ifTypes = new HashMap<String, String>();
         ifTypes.put(Constants.BASELINE_INTERFACE, "Baseline");
         ifTypes.put(Constants.LINKS_LIST_INTERFACE, "Links List");
         ifTypes.put(Constants.BATCH_INTERFACE, "Batch");
@@ -196,19 +196,19 @@ public class Utility {
         value = value.trim();
 
         String token[] = value.split(",");
-        String result = "";
+        StringBuilder result = new StringBuilder();
         for (int i = 0; i < token.length; i++) {
-            result += token[i].trim();
+            result.append(token[i].trim());
             if (i + 1 < token.length) {
-                result += ",";
+                result.append(",");
             }
         }
 
-        return result;
+        return result.toString();
     }
 
     public static AttributeValue cloneAttributeValue(AttributeValue value)
-            throws Exception {
+            throws InvalidArgsException, NullPointerException {
         AttributeValue clone = null;
 
         AttributeValue.TypeInfo typeInfo = value.typeInfo();
index d99d91c..db3f288 100644 (file)
@@ -35,6 +35,7 @@ import org.eclipse.swt.widgets.Text;
 import org.eclipse.swt.widgets.Tree;
 import org.eclipse.swt.widgets.TreeItem;
 
+import java.util.Date;
 import java.util.List;
 
 import org.oic.simulator.ArrayProperty;
@@ -42,6 +43,7 @@ import org.oic.simulator.AttributeProperty;
 import org.oic.simulator.AttributeValue;
 import org.oic.simulator.AttributeValue.TypeInfo;
 import org.oic.simulator.AttributeValue.ValueType;
+import org.oic.simulator.ILogger.Level;
 import org.oic.simulator.InvalidArgsException;
 import org.oic.simulator.SimulatorResourceAttribute;
 
@@ -287,6 +289,14 @@ public class AttributeEditingSupport {
                     attValue = AttributeValueBuilder.build(newValue,
                             type.mBaseType);
                 } catch (Exception e) {
+                    Activator
+                            .getDefault()
+                            .getLogManager()
+                            .log(Level.ERROR.ordinal(),
+                                    new Date(),
+                                    "There is an error while creating the new attribute value.\n"
+                                            + Utility.getSimulatorErrorString(
+                                                    e, null));
                 }
                 if (null == attValue) {
                     invalid = true;
index c36c0f8..360534c 100644 (file)
@@ -509,22 +509,27 @@ public class AttributeView extends ViewPart {
                                 attributesExist = true;
                             }
                         }
-                        if (!attributesExist) {
-                            MessageDialog
-                                    .openInformation(Display.getDefault()
-                                            .getActiveShell(), "PUT Request",
-                                            "No attributes exist in the resource model.");
-                            return;
-                        }
-                        PutRequestDialog putDialog = new PutRequestDialog(
-                                Display.getDefault().getActiveShell());
-                        if (putDialog.open() == Window.OK) {
-                            // Call the native PUT method
-                            String ifType = putDialog.getIfType();
-                            resourceManager.sendPutRequest(ifType,
-                                    resourceInSelection, putDialog
-                                            .getUpdatedRepresentation()
-                                            .getModel());
+                        if (attributesExist) {
+                            PutRequestDialog putDialog = new PutRequestDialog(
+                                    Display.getDefault().getActiveShell());
+                            if (putDialog.open() == Window.OK) {
+                                // Call the native PUT method
+                                String ifType = putDialog.getIfType();
+                                ResourceRepresentation updatedRepresentation = putDialog
+                                        .getUpdatedRepresentation();
+                                if (null != updatedRepresentation) {
+                                    resourceManager.sendPutRequest(ifType,
+                                            resourceInSelection,
+                                            updatedRepresentation.getModel());
+                                    return;
+                                }
+
+                                MessageDialog
+                                        .openInformation(Display.getDefault()
+                                                .getActiveShell(),
+                                                "PUT Request",
+                                                "No attributes exist in the resource model.");
+                            }
                         }
                     }
                 });
@@ -547,24 +552,28 @@ public class AttributeView extends ViewPart {
                                 attributesExist = true;
                             }
                         }
-                        if (!attributesExist) {
-                            MessageDialog
-                                    .openInformation(Display.getDefault()
-                                            .getActiveShell(), "POST Request",
-                                            "No attributes exist in the resource model.");
-                            return;
-                        }
+                        if (attributesExist) {
+                            PostRequestDialog postDialog = new PostRequestDialog(
+                                    Display.getDefault().getActiveShell());
+                            if (postDialog.open() == Window.OK) {
+                                // Call the native POST method
+                                String ifType = postDialog.getIfType();
+                                ResourceRepresentation updatedRepresentation = postDialog
+                                        .getUpdatedRepresentation();
+                                if (null != updatedRepresentation) {
+                                    resourceManager.sendPostRequest(ifType,
+                                            resourceInSelection,
+                                            updatedRepresentation
+                                                    .getSelectedModel());
+                                    return;
+                                }
 
-                        PostRequestDialog postDialog = new PostRequestDialog(
-                                Display.getDefault().getActiveShell());
-                        if (postDialog.open() == Window.OK) {
-                            // Call the native POST method
-                            String ifType = postDialog.getIfType();
-                            ResourceRepresentation representation = postDialog
-                                    .getUpdatedRepresentation();
-                            resourceManager.sendPostRequest(ifType,
-                                    resourceInSelection,
-                                    representation.getSelectedModel());
+                                MessageDialog
+                                        .openInformation(Display.getDefault()
+                                                .getActiveShell(),
+                                                "POST Request",
+                                                "No attributes exist in the resource model.");
+                            }
                         }
                     }
                 });
@@ -636,8 +645,8 @@ public class AttributeView extends ViewPart {
                                 status = "Failed to perform the requested operation.";
                             } else {
                                 // GET
-                                if (oldStatus.get(Constants.GET) != autoStatus
-                                        .get(Constants.GET)) {
+                                if (!oldStatus.get(Constants.GET).equals(
+                                        autoStatus.get(Constants.GET))) {
                                     if (autoStatus.get(Constants.GET)) {
                                         startMsg += Constants.GET;
                                         startCount++;
@@ -649,8 +658,8 @@ public class AttributeView extends ViewPart {
                                     }
                                 }
                                 // PUT
-                                if (oldStatus.get(Constants.PUT) != autoStatus
-                                        .get(Constants.PUT)) {
+                                if (!oldStatus.get(Constants.PUT).equals(
+                                        autoStatus.get(Constants.PUT))) {
                                     if (autoStatus.get(Constants.PUT)) {
                                         if (startCount == 1) {
                                             startMsg += ", ";
@@ -669,8 +678,8 @@ public class AttributeView extends ViewPart {
 
                                 }
                                 // POST
-                                if (oldStatus.get(Constants.POST) != autoStatus
-                                        .get(Constants.POST)) {
+                                if (!oldStatus.get(Constants.POST).equals(
+                                        autoStatus.get(Constants.POST))) {
                                     if (autoStatus.get(Constants.POST)) {
                                         if (startCount > 0) {
                                             startMsg += ", ";
index 5c53bd9..8fa457b 100644 (file)
@@ -33,8 +33,14 @@ import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.PlatformUI;
 
 import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Date;
 
+import org.oic.simulator.ILogger.Level;
+
+import oic.simulator.clientcontroller.Activator;
 import oic.simulator.clientcontroller.utils.Constants;
+import oic.simulator.clientcontroller.utils.Utility;
 
 /**
  * This dialog is used for loading the RAML file.
@@ -124,13 +130,30 @@ public class LoadRAMLDialog extends TitleAreaDialog {
         if (null == configFilePath) {
             return;
         }
+
+        FileInputStream fileStream = null;
         try {
-            new FileInputStream(configFilePath);
+            fileStream = new FileInputStream(configFilePath);
         } catch (Exception e) {
             MessageDialog
                     .openError(getShell(), "Invalid File",
                             "File doesn't exist. Either the file path or file name is invalid.");
             return;
+        } finally {
+            if (null != fileStream) {
+                try {
+                    fileStream.close();
+                } catch (IOException e) {
+                    Activator
+                            .getDefault()
+                            .getLogManager()
+                            .log(Level.ERROR.ordinal(),
+                                    new Date(),
+                                    "There is an error while closing the file stream.\n"
+                                            + Utility.getSimulatorErrorString(
+                                                    e, null));
+                }
+            }
         }
         close();
     }
index b8ce102..491c74c 100644 (file)
@@ -108,7 +108,8 @@ public class LogDetailsDialog extends Dialog {
         gd.grabExcessHorizontalSpace = true;
         l5.setLayoutData(gd);
 
-        new Label(container, SWT.NONE); // separator
+        Label seperator = new Label(container, SWT.NONE); // separator
+        seperator.setText("");
 
         Label l6 = new Label(container, SWT.NONE);
         l6.setText("Message details");
index e5e1d0f..d6ab842 100644 (file)
@@ -37,6 +37,8 @@ import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Tree;
 import org.eclipse.swt.widgets.TreeColumn;
 
+import java.util.Map;
+
 import org.oic.simulator.AttributeValue.ValueType;
 import org.oic.simulator.SimulatorResourceAttribute;
 
@@ -177,8 +179,11 @@ public class ModelArrayAddItemDialog extends TitleAreaDialog {
         @Override
         public Object[] getChildren(Object attribute) {
             if (attribute instanceof AttributeElement) {
-                return ((AttributeElement) attribute).getChildren().values()
-                        .toArray();
+                Map<String, AttributeElement> children = ((AttributeElement) attribute)
+                        .getChildren();
+                if (null != children) {
+                    return children.values().toArray();
+                }
             }
 
             return new Object[0];
index f8269b5..ee09154 100644 (file)
@@ -54,6 +54,7 @@ import org.eclipse.swt.widgets.TreeItem;
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -65,6 +66,7 @@ import org.oic.simulator.AttributeProperty;
 import org.oic.simulator.AttributeValue;
 import org.oic.simulator.AttributeValue.TypeInfo;
 import org.oic.simulator.AttributeValue.ValueType;
+import org.oic.simulator.ILogger.Level;
 import org.oic.simulator.ModelProperty;
 import org.oic.simulator.SimulatorResourceAttribute;
 import org.oic.simulator.SimulatorResourceModel;
@@ -206,14 +208,22 @@ public class PostRequestDialog extends TitleAreaDialog {
         createTreeViewer(container);
 
         // Clone the resource model for maintaining a local copy of attributes
-        // for PUT requests.
+        // for POST requests.
         SimulatorResourceModel resourceModel = null;
         try {
-            resourceModel = (SimulatorResourceModel) Utility
-                    .cloneAttributeValue(
-                            new AttributeValue(resource.getResourceModelRef()))
-                    .get();
-        } catch (Exception e2) {
+            AttributeValue attValue = Utility
+                    .cloneAttributeValue(new AttributeValue(resource
+                            .getResourceModelRef()));
+            if (null != attValue)
+                resourceModel = (SimulatorResourceModel) attValue.get();
+        } catch (Exception e) {
+            Activator
+                    .getDefault()
+                    .getLogManager()
+                    .log(Level.ERROR.ordinal(),
+                            new Date(),
+                            "There is an error while forming an instance of the attribute value.\n"
+                                    + Utility.getSimulatorErrorString(e, null));
         }
 
         if (null == resourceModel) {
@@ -230,7 +240,15 @@ public class PostRequestDialog extends TitleAreaDialog {
                 updatedRepresentation.updateAttributeProperties(resource
                         .getRequestModels().get(RequestType.POST),
                         resourceModel);
-            } catch (Exception e1) {
+            } catch (Exception e) {
+                Activator
+                        .getDefault()
+                        .getLogManager()
+                        .log(Level.ERROR.ordinal(),
+                                new Date(),
+                                "There is an error while forming an instance of the attribute value.\n"
+                                        + Utility.getSimulatorErrorString(e,
+                                                null));
             }
         }
 
@@ -337,7 +355,7 @@ public class PostRequestDialog extends TitleAreaDialog {
                         }
 
                         if (null != parent
-                                && !(parent instanceof ResourceRepresentation)) {
+                                && parent instanceof AttributeElement) {
                             Object grandParent = ((AttributeElement) parent)
                                     .getParent();
                             if (null == grandParent
@@ -402,6 +420,15 @@ public class PostRequestDialog extends TitleAreaDialog {
                                 .value().get();
 
                         AttributeElement attElement = getSelectedElement();
+                        if (null == attElement) {
+                            MessageDialog
+                                    .openError(Display.getDefault()
+                                            .getActiveShell(),
+                                            "Unable to perform the operation.",
+                                            "Failed to obtain the required data. Operation cannot be performed.");
+                            return;
+                        }
+
                         SimulatorResourceAttribute attribute = attElement
                                 .getSimulatorResourceAttribute();
                         SimulatorResourceModel[] modelArray = (SimulatorResourceModel[]) attribute
@@ -482,6 +509,14 @@ public class PostRequestDialog extends TitleAreaDialog {
                 // Removing the element from the child map.
                 Map<String, AttributeElement> elements = parentElement
                         .getChildren();
+                if (null == elements) {
+                    MessageDialog
+                            .openError(Display.getDefault().getActiveShell(),
+                                    "Operation failed.",
+                                    "There is an error while removing the array items.");
+                    return;
+                }
+
                 List<AttributeElement> attElementList = new ArrayList<AttributeElement>();
                 attElementList.addAll(elements.values());
                 Collections.sort(attElementList, Utility.attributeComparator);
@@ -519,9 +554,9 @@ public class PostRequestDialog extends TitleAreaDialog {
     }
 
     private ResourceRepresentation getRepresentationForOneDimensionTopLevelAttribute() {
-        ResourceRepresentation representation = null;
+        ResourceRepresentation representation;
 
-        AttributeValue value = null;
+        AttributeValue value;
         ModelProperty property = null;
 
         AttributeElement element = getSelectedElement();
@@ -625,10 +660,14 @@ public class PostRequestDialog extends TitleAreaDialog {
         public Object[] getChildren(Object attribute) {
             if (attribute instanceof AttributeElement) {
                 List<AttributeElement> attElementList = new ArrayList<AttributeElement>();
-                attElementList.addAll(((AttributeElement) attribute)
-                        .getChildren().values());
-                Collections.sort(attElementList, Utility.attributeComparator);
-                return attElementList.toArray();
+                Map<String, AttributeElement> children = ((AttributeElement) attribute)
+                        .getChildren();
+                if (null != children) {
+                    attElementList.addAll(children.values());
+                    Collections.sort(attElementList,
+                            Utility.attributeComparator);
+                    return attElementList.toArray();
+                }
             }
 
             return new Object[0];
index cd99ffc..e4e22e6 100644 (file)
@@ -54,6 +54,7 @@ import org.eclipse.swt.widgets.TreeItem;
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -65,6 +66,7 @@ import org.oic.simulator.AttributeProperty;
 import org.oic.simulator.AttributeValue;
 import org.oic.simulator.AttributeValue.TypeInfo;
 import org.oic.simulator.AttributeValue.ValueType;
+import org.oic.simulator.ILogger.Level;
 import org.oic.simulator.ModelProperty;
 import org.oic.simulator.SimulatorResourceAttribute;
 import org.oic.simulator.SimulatorResourceModel;
@@ -209,11 +211,19 @@ public class PutRequestDialog extends TitleAreaDialog {
         // for PUT requests.
         SimulatorResourceModel resourceModel = null;
         try {
-            resourceModel = (SimulatorResourceModel) Utility
-                    .cloneAttributeValue(
-                            new AttributeValue(resource.getResourceModelRef()))
-                    .get();
-        } catch (Exception e2) {
+            AttributeValue attValue = Utility
+                    .cloneAttributeValue(new AttributeValue(resource
+                            .getResourceModelRef()));
+            if (null != attValue)
+                resourceModel = (SimulatorResourceModel) attValue.get();
+        } catch (Exception e) {
+            Activator
+                    .getDefault()
+                    .getLogManager()
+                    .log(Level.ERROR.ordinal(),
+                            new Date(),
+                            "There is an error while forming an instance of the attribute value.\n"
+                                    + Utility.getSimulatorErrorString(e, null));
         }
 
         if (null == resourceModel) {
@@ -230,7 +240,15 @@ public class PutRequestDialog extends TitleAreaDialog {
                 updatedRepresentation.updateAttributeProperties(resource
                         .getRequestModels().get(RequestType.POST),
                         resourceModel);
-            } catch (Exception e1) {
+            } catch (Exception e) {
+                Activator
+                        .getDefault()
+                        .getLogManager()
+                        .log(Level.ERROR.ordinal(),
+                                new Date(),
+                                "There is an error while forming an instance of the attribute value.\n"
+                                        + Utility.getSimulatorErrorString(e,
+                                                null));
             }
         }
 
@@ -330,7 +348,7 @@ public class PutRequestDialog extends TitleAreaDialog {
                         }
 
                         if (null != parent
-                                && !(parent instanceof ResourceRepresentation)) {
+                                && parent instanceof AttributeElement) {
                             Object grandParent = ((AttributeElement) parent)
                                     .getParent();
                             if (null == grandParent
@@ -395,6 +413,15 @@ public class PutRequestDialog extends TitleAreaDialog {
                                 .value().get();
 
                         AttributeElement attElement = getSelectedElement();
+                        if (null == attElement) {
+                            MessageDialog
+                                    .openError(Display.getDefault()
+                                            .getActiveShell(),
+                                            "Unable to perform the operation.",
+                                            "Failed to obtain the required data. Operation cannot be performed.");
+                            return;
+                        }
+
                         SimulatorResourceAttribute attribute = attElement
                                 .getSimulatorResourceAttribute();
                         SimulatorResourceModel[] modelArray = (SimulatorResourceModel[]) attribute
@@ -473,6 +500,14 @@ public class PutRequestDialog extends TitleAreaDialog {
                 // Removing the element from the child map.
                 Map<String, AttributeElement> elements = parentElement
                         .getChildren();
+                if (null == elements) {
+                    MessageDialog
+                            .openError(Display.getDefault().getActiveShell(),
+                                    "Operation failed.",
+                                    "There is an error while removing the array items.");
+                    return;
+                }
+
                 List<AttributeElement> attElementList = new ArrayList<AttributeElement>();
                 attElementList.addAll(elements.values());
                 Collections.sort(attElementList, Utility.attributeComparator);
@@ -508,9 +543,9 @@ public class PutRequestDialog extends TitleAreaDialog {
     }
 
     private ResourceRepresentation getRepresentationForOneDimensionTopLevelAttribute() {
-        ResourceRepresentation representation = null;
+        ResourceRepresentation representation;
 
-        AttributeValue value = null;
+        AttributeValue value;
         ModelProperty property = null;
 
         AttributeElement element = getSelectedElement();
@@ -614,10 +649,14 @@ public class PutRequestDialog extends TitleAreaDialog {
         public Object[] getChildren(Object attribute) {
             if (attribute instanceof AttributeElement) {
                 List<AttributeElement> attElementList = new ArrayList<AttributeElement>();
-                attElementList.addAll(((AttributeElement) attribute)
-                        .getChildren().values());
-                Collections.sort(attElementList, Utility.attributeComparator);
-                return attElementList.toArray();
+                Map<String, AttributeElement> children = ((AttributeElement) attribute)
+                        .getChildren();
+                if (null != children) {
+                    attElementList.addAll(children.values());
+                    Collections.sort(attElementList,
+                            Utility.attributeComparator);
+                    return attElementList.toArray();
+                }
             }
 
             return new Object[0];
index 5224b87..cc99eac 100644 (file)
@@ -29,14 +29,18 @@ import org.eclipse.swt.widgets.MessageBox;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Text;
 
+import java.util.Date;
+
 import org.oic.simulator.ArrayProperty;
 import org.oic.simulator.AttributeProperty;
 import org.oic.simulator.AttributeValue;
 import org.oic.simulator.DoubleProperty;
+import org.oic.simulator.ILogger.Level;
 import org.oic.simulator.IntegerProperty;
 import org.oic.simulator.SimulatorResourceAttribute;
 import org.oic.simulator.StringProperty;
 
+import oic.simulator.clientcontroller.Activator;
 import oic.simulator.clientcontroller.utils.AttributeValueBuilder;
 import oic.simulator.clientcontroller.utils.AttributeValueStringConverter;
 import oic.simulator.clientcontroller.utils.Utility;
@@ -265,60 +269,61 @@ public class UpdatePrimitiveArrayAttributeDialog extends TitleAreaDialog {
         ArrayProperty arrProp = attribute.property().asArray();
         AttributeProperty elementProp = arrProp.getElementProperty();
 
-        String values = "";
+        StringBuilder values = new StringBuilder();
         if (elementProp.isInteger()) {
             IntegerProperty intProp = elementProp.asInteger();
             if (intProp.hasRange()) {
-                values = intProp.min() + " - " + intProp.max();
+                values.append(intProp.min() + " - " + intProp.max());
             } else if (intProp.hasValues()) {
                 int[] arr = intProp.getValues();
                 for (int i = 0; i < arr.length; i++) {
-                    values += arr[i];
+                    values.append(arr[i]);
                     if (i + 1 < arr.length) {
-                        values += ", ";
+                        values.append(", ");
                     }
                 }
 
-                if (!values.isEmpty()) {
-                    values = "[" + values + "]";
+                if (!values.toString().isEmpty()) {
+                    values.append("[" + values + "]");
                 }
             }
         } else if (elementProp.isDouble()) {
             DoubleProperty dblProp = elementProp.asDouble();
             if (dblProp.hasRange()) {
-                values = dblProp.min() + " - " + dblProp.max();
+                values.append(dblProp.min() + " - " + dblProp.max());
             } else if (dblProp.hasValues()) {
                 double[] arr = dblProp.getValues();
                 for (int i = 0; i < arr.length; i++) {
-                    values += arr[i];
+                    values.append(arr[i]);
                     if (i + 1 < arr.length) {
-                        values += ", ";
+                        values.append(", ");
                     }
                 }
 
-                if (!values.isEmpty()) {
-                    values = "[" + values + "]";
+                if (!values.toString().isEmpty()) {
+                    values.append("[" + values + "]");
                 }
             }
         } else if (elementProp.isBoolean()) {
-            values = "[true, false]";
+            values.append("[true, false]");
         } else if (elementProp.isString()) {
             StringProperty strProp = elementProp.asString();
             if (strProp.hasValues()) {
                 String[] arr = strProp.getValues();
                 for (int i = 0; i < arr.length; i++) {
-                    values += arr[i];
+                    values.append(arr[i]);
                     if (i + 1 < arr.length) {
-                        values += ", ";
+                        values.append(", ");
                     }
                 }
 
-                if (!values.isEmpty()) {
-                    values = "[" + values + "]";
+                if (!values.toString().isEmpty()) {
+                    values.append("[" + values + "]");
                 }
             }
         }
-        allowedValuesTxt.setText(values);
+
+        allowedValuesTxt.setText(values.toString());
 
         // Set the current value.
         currentValueTxt.setText(new AttributeValueStringConverter(attribute
@@ -349,18 +354,24 @@ public class UpdatePrimitiveArrayAttributeDialog extends TitleAreaDialog {
             return;
         }
 
-        // ArrayProperty arrProp = attribute.property().asArray();
         try {
             String value = Utility.removeWhiteSpacesInArrayValues(newValue);
-            if (value.startsWith("[") && value.endsWith("]")) {
+            if (null != value && value.startsWith("[") && value.endsWith("]")) {
                 newAttValueObj = AttributeValueBuilder.build(value, attribute
                         .value().typeInfo().mBaseType);
-                if (null != newAttValueObj/* && arrProp.validate(newAttValueObj) */) {
+                if (null != newAttValueObj) {
                     close();
                     return;
                 }
             }
         } catch (Exception e) {
+            Activator
+                    .getDefault()
+                    .getLogManager()
+                    .log(Level.ERROR.ordinal(),
+                            new Date(),
+                            "There is an error while building the new attribute value.\n"
+                                    + Utility.getSimulatorErrorString(e, null));
         }
 
         MessageBox dialog = new MessageBox(Display.getDefault()
index 1e16e09..dc11654 100644 (file)
@@ -624,33 +624,14 @@ public class ResourceManager {
 
     public Resource createResourceByRAML(String configFilePath)
             throws SimulatorException {
-        Resource resource = null;
+        SimulatorResource jSimulatorResource;
         try {
             // Create the resource
-            SimulatorResource jSimulatorResource = SimulatorManager
+            jSimulatorResource = SimulatorManager
                     .createResource(configFilePath);
             if (null == jSimulatorResource) {
                 return null;
             }
-            if (jSimulatorResource instanceof SimulatorSingleResource) {
-                resource = new SingleResource();
-            } else {
-                return null;
-            }
-            resource.setSimulatorResource(jSimulatorResource);
-
-            // Fetch and locally store the resource name and uri.
-            String uri = jSimulatorResource.getURI();
-            if (null == uri || uri.trim().isEmpty()) {
-                return null;
-            }
-            resource.setResourceURI(uri.trim());
-
-            String name = jSimulatorResource.getName();
-            if (null == name || name.trim().isEmpty()) {
-                return null;
-            }
-            resource.setResourceName(name.trim());
         } catch (SimulatorException e) {
             Activator
                     .getDefault()
@@ -659,6 +640,28 @@ public class ResourceManager {
                             Utility.getSimulatorErrorString(e, null));
             throw e;
         }
+
+        if (!(jSimulatorResource instanceof SimulatorSingleResource)) {
+            return null;
+        }
+
+        Resource resource = new SingleResource();
+        resource.setSimulatorResource(jSimulatorResource);
+
+        // Fetch and locally store the resource name and uri.
+        String uri = jSimulatorResource.getURI();
+        if (null == uri || uri.trim().isEmpty()) {
+            return null;
+        }
+        resource.setResourceURI(uri.trim());
+
+        String name = jSimulatorResource.getName();
+        if (null == name || name.trim().isEmpty()) {
+            return null;
+        }
+
+        resource.setResourceName(name.trim());
+
         return resource;
     }
 
@@ -906,27 +909,26 @@ public class ResourceManager {
     public List<MetaProperty> getMetaProperties(Resource resource) {
         if (null != resource) {
             String propName;
-            String propValue;
-
+            StringBuilder propValue;
             List<MetaProperty> metaPropertyList = new ArrayList<MetaProperty>();
 
             for (int index = 0; index < Constants.META_PROPERTY_COUNT; index++) {
                 propName = Constants.META_PROPERTIES[index];
+                propValue = new StringBuilder();
                 if (propName.equals(Constants.RESOURCE_NAME)) {
-                    propValue = resource.getResourceName();
+                    propValue.append(resource.getResourceName());
                 } else if (propName.equals(Constants.RESOURCE_URI)) {
-                    propValue = resource.getResourceURI();
+                    propValue.append(resource.getResourceURI());
                 } else if (propName.equals(Constants.RESOURCE_TYPE)) {
-                    propValue = resource.getResourceType();
+                    propValue.append(resource.getResourceType());
                 } else if (propName.equals(Constants.INTERFACE_TYPES)) {
                     Set<String> ifTypes = resource.getResourceInterfaces();
                     if (null != ifTypes && !ifTypes.isEmpty()) {
-                        propValue = "";
                         Iterator<String> itr = ifTypes.iterator();
                         while (itr.hasNext()) {
-                            propValue += itr.next();
+                            propValue.append(itr.next());
                             if (itr.hasNext()) {
-                                propValue += ", ";
+                                propValue.append(", ");
                             }
                         }
                     } else {
@@ -936,7 +938,8 @@ public class ResourceManager {
                     propValue = null;
                 }
                 if (null != propValue) {
-                    metaPropertyList.add(new MetaProperty(propName, propValue));
+                    metaPropertyList.add(new MetaProperty(propName, propValue
+                            .toString()));
                 }
             }
             return metaPropertyList;
@@ -1171,11 +1174,17 @@ public class ResourceManager {
         if (null == resource || null == newIfSet || newIfSet.isEmpty()) {
             return false;
         }
+
         SimulatorResource jResource = resource.getSimulatorResource();
         if (null == jResource) {
             return false;
         }
+
         Set<String> curIfSet = resource.getResourceInterfaces();
+        if (null == curIfSet || curIfSet.isEmpty()) {
+            return false;
+        }
+
         Iterator<String> itr = curIfSet.iterator();
         String interfaceType;
         boolean resourceRestartRequired = false;
index 61c208e..e98e678 100644 (file)
@@ -16,6 +16,7 @@
 
 package oic.simulator.serviceprovider.model;
 
+import java.util.Date;
 import java.util.Map;
 import java.util.TreeMap;
 
@@ -23,6 +24,7 @@ import org.oic.simulator.ArrayProperty;
 import org.oic.simulator.AttributeProperty;
 import org.oic.simulator.AttributeValue;
 import org.oic.simulator.DoubleProperty;
+import org.oic.simulator.ILogger.Level;
 import org.oic.simulator.IntegerProperty;
 import org.oic.simulator.InvalidArgsException;
 import org.oic.simulator.ModelProperty;
@@ -31,9 +33,11 @@ import org.oic.simulator.SimulatorResourceModel;
 import org.oic.simulator.StringProperty;
 import org.oic.simulator.server.SimulatorResource.AutoUpdateType;
 
+import oic.simulator.serviceprovider.Activator;
 import oic.simulator.serviceprovider.manager.UiListenerHandler;
 import oic.simulator.serviceprovider.utils.AttributeValueStringConverter;
 import oic.simulator.serviceprovider.utils.Constants;
+import oic.simulator.serviceprovider.utils.Utility;
 
 public class AttributeElement {
     private Object                        mParent             = null;
@@ -81,10 +85,9 @@ public class AttributeElement {
                     SimulatorResourceModel[] resModelArray = (SimulatorResourceModel[]) attribute
                             .value().get();
 
-                    ArrayProperty arrProp = null;
                     ModelProperty modelProp = null;
                     if (null != attribute.property()) {
-                        arrProp = attribute.property().asArray();
+                        ArrayProperty arrProp = attribute.property().asArray();
                         if (null != arrProp
                                 && null != arrProp.getElementProperty()) {
                             modelProp = arrProp.getElementProperty().asModel();
@@ -102,15 +105,13 @@ public class AttributeElement {
                     SimulatorResourceModel[][] resModelArray = (SimulatorResourceModel[][]) attribute
                             .value().get();
 
-                    ArrayProperty arrProp = null;
-                    ArrayProperty arrChildPropLevel1 = null;
                     ModelProperty modelProp = null;
                     if (null != attribute.property()) {
-                        arrProp = attribute.property().asArray();
+                        ArrayProperty arrProp = attribute.property().asArray();
                         if (null != arrProp
                                 && null != arrProp.getElementProperty()) {
-                            arrChildPropLevel1 = arrProp.getElementProperty()
-                                    .asArray();
+                            ArrayProperty arrChildPropLevel1 = arrProp
+                                    .getElementProperty().asArray();
                             if (null != arrChildPropLevel1
                                     && null != arrChildPropLevel1
                                             .getElementProperty()) {
@@ -132,20 +133,17 @@ public class AttributeElement {
                     SimulatorResourceModel[][][] resModelArray = (SimulatorResourceModel[][][]) attribute
                             .value().get();
 
-                    ArrayProperty arrProp = null;
-                    ArrayProperty arrChildPropLevel1 = null;
-                    ArrayProperty arrChildPropLevel2 = null;
                     ModelProperty modelProp = null;
                     if (null != attribute.property()) {
-                        arrProp = attribute.property().asArray();
+                        ArrayProperty arrProp = attribute.property().asArray();
                         if (null != arrProp
                                 && null != arrProp.getElementProperty()) {
-                            arrChildPropLevel1 = arrProp.getElementProperty()
-                                    .asArray();
+                            ArrayProperty arrChildPropLevel1 = arrProp
+                                    .getElementProperty().asArray();
                             if (null != arrChildPropLevel1
                                     && null != arrChildPropLevel1
                                             .getElementProperty()) {
-                                arrChildPropLevel2 = arrChildPropLevel1
+                                ArrayProperty arrChildPropLevel2 = arrChildPropLevel1
                                         .getElementProperty().asArray();
                                 if (null != arrChildPropLevel2
                                         && null != arrChildPropLevel2
@@ -305,16 +303,27 @@ public class AttributeElement {
                     AttributeValue currentValue = mAttribute.value();
                     SimulatorResourceModel curModel = (SimulatorResourceModel) currentValue
                             .get();
-                    try {
-                        curModel.set(attName, entry.getValue());
-                    } catch (InvalidArgsException e) {
-                    }
+                    if (null != curModel) {
+                        try {
+                            curModel.set(attName, entry.getValue());
+                        } catch (InvalidArgsException e) {
+                            Activator
+                                    .getDefault()
+                                    .getLogManager()
+                                    .log(Level.ERROR.ordinal(),
+                                            new Date(),
+                                            "There is an error while updating the resource model.\n"
+                                                    + Utility
+                                                            .getSimulatorErrorString(
+                                                                    e, null));
+                        }
 
-                    mChildAttributes.put(attName, newAttribute);
+                        mChildAttributes.put(attName, newAttribute);
 
-                    // Refresh UI to display the new attribute.
-                    UiListenerHandler.getInstance()
-                            .attributeAddedUINotification(newAttribute);
+                        // Refresh UI to display the new attribute.
+                        UiListenerHandler.getInstance()
+                                .attributeAddedUINotification(newAttribute);
+                    }
                 }
             }
         } else if (typeInfo.mType == AttributeValue.ValueType.ARRAY
@@ -323,10 +332,9 @@ public class AttributeElement {
                 SimulatorResourceModel[] resModelArray = (SimulatorResourceModel[]) attribute
                         .value().get();
 
-                ArrayProperty arrProp = null;
                 ModelProperty modelProp = null;
                 if (null != mAttribute.property()) {
-                    arrProp = mAttribute.property().asArray();
+                    ArrayProperty arrProp = mAttribute.property().asArray();
                     if (null != arrProp && null != arrProp.getElementProperty()) {
                         modelProp = arrProp.getElementProperty().asModel();
                     }
@@ -364,14 +372,12 @@ public class AttributeElement {
                 SimulatorResourceModel[][] resModelArray = (SimulatorResourceModel[][]) attribute
                         .value().get();
 
-                ArrayProperty arrProp = null;
-                ArrayProperty arrChildPropLevel1 = null;
                 ModelProperty modelProp = null;
                 if (null != mAttribute.property()) {
-                    arrProp = mAttribute.property().asArray();
+                    ArrayProperty arrProp = mAttribute.property().asArray();
                     if (null != arrProp && null != arrProp.getElementProperty()) {
-                        arrChildPropLevel1 = arrProp.getElementProperty()
-                                .asArray();
+                        ArrayProperty arrChildPropLevel1 = arrProp
+                                .getElementProperty().asArray();
                         if (null != arrChildPropLevel1
                                 && null != arrChildPropLevel1
                                         .getElementProperty()) {
@@ -421,19 +427,16 @@ public class AttributeElement {
                 SimulatorResourceModel[][][] resModelArray = (SimulatorResourceModel[][][]) attribute
                         .value().get();
 
-                ArrayProperty arrProp = null;
-                ArrayProperty arrChildPropLevel1 = null;
-                ArrayProperty arrChildPropLevel2 = null;
                 ModelProperty modelProp = null;
                 if (null != mAttribute.property()) {
-                    arrProp = mAttribute.property().asArray();
+                    ArrayProperty arrProp = mAttribute.property().asArray();
                     if (null != arrProp && null != arrProp.getElementProperty()) {
-                        arrChildPropLevel1 = arrProp.getElementProperty()
-                                .asArray();
+                        ArrayProperty arrChildPropLevel1 = arrProp
+                                .getElementProperty().asArray();
                         if (null != arrChildPropLevel1
                                 && null != arrChildPropLevel1
                                         .getElementProperty()) {
-                            arrChildPropLevel2 = arrChildPropLevel1
+                            ArrayProperty arrChildPropLevel2 = arrChildPropLevel1
                                     .getElementProperty().asArray();
                             if (null != arrChildPropLevel2
                                     && null != arrChildPropLevel2
@@ -494,6 +497,15 @@ public class AttributeElement {
                         ((AttributeElement) mParent)
                                 .deepSetChildValue(mAttribute);
                     } catch (InvalidArgsException e) {
+                        Activator
+                                .getDefault()
+                                .getLogManager()
+                                .log(Level.ERROR.ordinal(),
+                                        new Date(),
+                                        "There is an error while updating the resource model.\n"
+                                                + Utility
+                                                        .getSimulatorErrorString(
+                                                                e, null));
                     }
                 }
                 UiListenerHandler.getInstance().attributeUpdatedUINotification(
index 4e93582..7329569 100644 (file)
@@ -263,7 +263,7 @@ public class AttributeHelper {
                         dflValue = Double.parseDouble(value);
                         boolean found = false;
                         for (double val = min; val <= max; val += 1.0) {
-                            if (dflValue == val) {
+                            if (Double.compare(dflValue, val) == 0) {
                                 found = true;
                                 break;
                             }
@@ -295,7 +295,7 @@ public class AttributeHelper {
                         String val = itr.next();
                         double v1 = Double.parseDouble(val);
                         double v2 = Double.parseDouble(value);
-                        if (v1 == v2) {
+                        if (Double.compare(v1, v2) == 0) {
                             found = true;
                             break;
                         }
index efb7726..b531ba7 100644 (file)
@@ -65,10 +65,8 @@ public class AutomationSettingHelper {
 
     public static List<AutomationSettingHelper> getAutomationSettings(
             AttributeElement attribute) {
-        List<AutomationSettingHelper> settingList = null;
         boolean invalidSetting;
-
-        settingList = new ArrayList<AutomationSettingHelper>();
+        List<AutomationSettingHelper> settingList = new ArrayList<AutomationSettingHelper>();
         for (int count = 0; count < Constants.AUTOMATION_SETTINGS_COUNT; count++) {
             invalidSetting = false;
             AutomationSettingHelper setting = new AutomationSettingHelper();
index 8a98859..3a1690b 100644 (file)
@@ -17,6 +17,7 @@
 package oic.simulator.serviceprovider.model;
 
 import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.ObjectInputStream;
@@ -126,22 +127,39 @@ public class SerializedServiceProvider implements Serializable {
         this.m_resourceAttributesMap = resourceAttributesMap;
     }
 
-    public void serialize(String filePath) throws IOException {
-        FileOutputStream fileOut = new FileOutputStream(filePath);
-        ObjectOutputStream out = new ObjectOutputStream(fileOut);
-        out.writeObject(this);
-        out.close();
-        fileOut.close();
+    public void serialize(String filePath) throws FileNotFoundException,
+            IOException {
+        FileOutputStream fileOut = null;
+        ObjectOutputStream out = null;
+        try {
+            fileOut = new FileOutputStream(filePath);
+            out = new ObjectOutputStream(fileOut);
+            out.writeObject(this);
+        } finally {
+            if (null != fileOut)
+                fileOut.close();
+
+            if (null != out)
+                out.close();
+        }
     }
 
     public static SerializedServiceProvider deSerialize(String filePath)
-            throws Exception {
-        SerializedServiceProvider r = null;
-        FileInputStream fileIn = new FileInputStream(filePath);
-        ObjectInputStream in = new ObjectInputStream(fileIn);
-        r = (SerializedServiceProvider) in.readObject();
-        in.close();
-        fileIn.close();
+            throws FileNotFoundException, IOException, ClassNotFoundException {
+        FileInputStream fileIn = null;
+        ObjectInputStream in = null;
+        SerializedServiceProvider r;
+        try {
+            fileIn = new FileInputStream(filePath);
+            in = new ObjectInputStream(fileIn);
+            r = (SerializedServiceProvider) in.readObject();
+        } finally {
+            if (null != fileIn)
+                fileIn.close();
+
+            if (null != in)
+                in.close();
+        }
         return r;
     }
 
index 421b7c1..4c640e3 100644 (file)
@@ -22,7 +22,7 @@ import org.oic.simulator.AttributeValue;
 
 public class AttributeValueBuilder {
     public static AttributeValue build(String valueString,
-            AttributeValue.ValueType valueType) throws Exception {
+            AttributeValue.ValueType valueType) throws NullPointerException {
         int depth = findDepth(valueString);
         if (0 == depth) {
             return handleDepth0(valueString, valueType);
@@ -90,9 +90,8 @@ public class AttributeValueBuilder {
         return null;
     }
 
-    private static String[] splitIntoArrays(String value) {
+    private static String[] splitIntoArrays(String valueString) {
         Vector<String> values = new Vector<String>();
-        String valueString = new String(value);
         valueString = valueString.substring(valueString.indexOf('[') + 1,
                 valueString.lastIndexOf(']'));
 
@@ -135,8 +134,12 @@ public class AttributeValueBuilder {
             for (int index = 0; index < valuesString.length; index++) {
                 if (null != valuesString[index]
                         && !valuesString[index].isEmpty()) {
-                    Integer value = (Integer) handleDepth0(valuesString[index],
-                            valueType).get();
+                    AttributeValue attValue = handleDepth0(valuesString[index],
+                            valueType);
+                    if (null == attValue)
+                        return null;
+
+                    Integer value = (Integer) attValue.get();
                     if (null == value)
                         return null;
                     result[index] = value;
@@ -152,8 +155,12 @@ public class AttributeValueBuilder {
             for (int index = 0; index < valuesString.length; index++) {
                 if (null != valuesString[index]
                         && !valuesString[index].isEmpty()) {
-                    Double value = (Double) handleDepth0(valuesString[index],
-                            valueType).get();
+                    AttributeValue attValue = handleDepth0(valuesString[index],
+                            valueType);
+                    if (null == attValue)
+                        return null;
+
+                    Double value = (Double) attValue.get();
                     if (null == value)
                         return null;
                     result[index] = value;
@@ -169,8 +176,12 @@ public class AttributeValueBuilder {
             for (int index = 0; index < valuesString.length; index++) {
                 if (null != valuesString[index]
                         && !valuesString[index].isEmpty()) {
-                    Boolean value = (Boolean) handleDepth0(valuesString[index],
-                            valueType).get();
+                    AttributeValue attValue = handleDepth0(valuesString[index],
+                            valueType);
+                    if (null == attValue)
+                        return null;
+
+                    Boolean value = (Boolean) attValue.get();
                     if (null == value)
                         return null;
                     result[index] = value;
@@ -207,8 +218,12 @@ public class AttributeValueBuilder {
         if (valueType == AttributeValue.ValueType.INTEGER) {
             Integer[][] result = new Integer[valuesString.length][];
             for (int index = 0; index < valuesString.length; index++) {
-                Integer[] value = (Integer[]) handleDepth1(valuesString[index],
-                        valueType).get();
+                AttributeValue attValue = handleDepth1(valuesString[index],
+                        valueType);
+                if (null == attValue)
+                    return null;
+
+                Integer[] value = (Integer[]) attValue.get();
                 if (null == value)
                     return null;
                 result[index] = value;
@@ -217,8 +232,12 @@ public class AttributeValueBuilder {
         } else if (valueType == AttributeValue.ValueType.DOUBLE) {
             Double[][] result = new Double[valuesString.length][];
             for (int index = 0; index < valuesString.length; index++) {
-                Double[] value = (Double[]) handleDepth1(valuesString[index],
-                        valueType).get();
+                AttributeValue attValue = handleDepth1(valuesString[index],
+                        valueType);
+                if (null == attValue)
+                    return null;
+
+                Double[] value = (Double[]) attValue.get();
                 if (null == value)
                     return null;
                 result[index] = value;
@@ -227,8 +246,12 @@ public class AttributeValueBuilder {
         } else if (valueType == AttributeValue.ValueType.BOOLEAN) {
             Boolean[][] result = new Boolean[valuesString.length][];
             for (int index = 0; index < valuesString.length; index++) {
-                Boolean[] value = (Boolean[]) handleDepth1(valuesString[index],
-                        valueType).get();
+                AttributeValue attValue = handleDepth1(valuesString[index],
+                        valueType);
+                if (null == attValue)
+                    return null;
+
+                Boolean[] value = (Boolean[]) attValue.get();
                 if (null == value)
                     return null;
                 result[index] = value;
@@ -237,8 +260,12 @@ public class AttributeValueBuilder {
         } else if (valueType == AttributeValue.ValueType.STRING) {
             String[][] result = new String[valuesString.length][];
             for (int index = 0; index < valuesString.length; index++) {
-                String[] value = (String[]) handleDepth1(valuesString[index],
-                        valueType).get();
+                AttributeValue attValue = handleDepth1(valuesString[index],
+                        valueType);
+                if (null == attValue)
+                    return null;
+
+                String[] value = (String[]) attValue.get();
                 if (null == value)
                     return null;
                 result[index] = value;
@@ -262,8 +289,12 @@ public class AttributeValueBuilder {
         if (valueType == AttributeValue.ValueType.INTEGER) {
             Integer[][][] result = new Integer[valuesString.length][][];
             for (int index = 0; index < valuesString.length; index++) {
-                Integer[][] value = (Integer[][]) handleDepth2(
-                        valuesString[index], valueType).get();
+                AttributeValue attValue = handleDepth2(valuesString[index],
+                        valueType);
+                if (null == attValue)
+                    return null;
+
+                Integer[][] value = (Integer[][]) attValue.get();
                 if (null == value)
                     return null;
                 result[index] = value;
@@ -272,8 +303,12 @@ public class AttributeValueBuilder {
         } else if (valueType == AttributeValue.ValueType.DOUBLE) {
             Double[][][] result = new Double[valuesString.length][][];
             for (int index = 0; index < valuesString.length; index++) {
-                Double[][] value = (Double[][]) handleDepth2(
-                        valuesString[index], valueType).get();
+                AttributeValue attValue = handleDepth2(valuesString[index],
+                        valueType);
+                if (null == attValue)
+                    return null;
+
+                Double[][] value = (Double[][]) attValue.get();
                 if (null == value)
                     return null;
                 result[index] = value;
@@ -282,8 +317,12 @@ public class AttributeValueBuilder {
         } else if (valueType == AttributeValue.ValueType.BOOLEAN) {
             Boolean[][][] result = new Boolean[valuesString.length][][];
             for (int index = 0; index < valuesString.length; index++) {
-                Boolean[][] value = (Boolean[][]) handleDepth2(
-                        valuesString[index], valueType).get();
+                AttributeValue attValue = handleDepth2(valuesString[index],
+                        valueType);
+                if (null == attValue)
+                    return null;
+
+                Boolean[][] value = (Boolean[][]) attValue.get();
                 if (null == value)
                     return null;
                 result[index] = value;
@@ -292,8 +331,12 @@ public class AttributeValueBuilder {
         } else if (valueType == AttributeValue.ValueType.STRING) {
             String[][][] result = new String[valuesString.length][][];
             for (int index = 0; index < valuesString.length; index++) {
-                String[][] value = (String[][]) handleDepth2(
-                        valuesString[index], valueType).get();
+                AttributeValue attValue = handleDepth2(valuesString[index],
+                        valueType);
+                if (null == attValue)
+                    return null;
+
+                String[][] value = (String[][]) attValue.get();
                 if (null == value)
                     return null;
                 result[index] = value;
index 42e0b91..a662874 100644 (file)
@@ -32,6 +32,7 @@ import org.oic.simulator.AttributeValue;
 import org.oic.simulator.AttributeValue.TypeInfo;
 import org.oic.simulator.AttributeValue.ValueType;
 import org.oic.simulator.ILogger.Level;
+import org.oic.simulator.InvalidArgsException;
 import org.oic.simulator.SimulatorException;
 import org.oic.simulator.SimulatorResourceModel;
 
@@ -124,7 +125,7 @@ public class Utility {
         Set<String> resultSet = new HashSet<String>();
         Enumeration<String> e = vector.elements();
         while (e.hasMoreElements()) {
-            resultSet.add(e.nextElement().toString());
+            resultSet.add(e.nextElement());
         }
         return resultSet;
     }
@@ -133,7 +134,7 @@ public class Utility {
         if (null == e) {
             return null;
         }
-        String detail = "";
+        String detail;
         if (e instanceof SimulatorException) {
             SimulatorException simEx = (SimulatorException) e;
             detail = simEx.message() + "\n";
@@ -317,7 +318,14 @@ public class Utility {
                     val = Integer.parseInt(itr.next());
                     resultSet.add(val);
                 } catch (NumberFormatException nfe) {
-                    // Added for safety. Nothing to do.
+                    Activator
+                            .getDefault()
+                            .getLogManager()
+                            .log(Level.ERROR.ordinal(),
+                                    new Date(),
+                                    "There is an error while doing internal convertion(string set to object set).\n"
+                                            + Utility.getSimulatorErrorString(
+                                                    nfe, null));
                 }
             }
         } else if (AttributeValue.ValueType.DOUBLE == type) {
@@ -328,7 +336,14 @@ public class Utility {
                     val = Double.parseDouble(itr.next());
                     resultSet.add(val);
                 } catch (NumberFormatException nfe) {
-                    // Added for safety. Nothing to do.
+                    Activator
+                            .getDefault()
+                            .getLogManager()
+                            .log(Level.ERROR.ordinal(),
+                                    new Date(),
+                                    "There is an error while doing internal convertion(string set to object set).\n"
+                                            + Utility.getSimulatorErrorString(
+                                                    nfe, null));
                 }
             }
         } else if (AttributeValue.ValueType.BOOLEAN == type) {
@@ -578,19 +593,19 @@ public class Utility {
         value = value.trim();
 
         String token[] = value.split(",");
-        String result = "";
+        StringBuilder result = new StringBuilder();
         for (int i = 0; i < token.length; i++) {
-            result += token[i].trim();
+            result.append(token[i].trim());
             if (i + 1 < token.length) {
-                result += ",";
+                result.append(",");
             }
         }
 
-        return result;
+        return result.toString();
     }
 
     public static AttributeValue cloneAttributeValue(AttributeValue value)
-            throws Exception {
+            throws InvalidArgsException, NullPointerException {
         AttributeValue clone = null;
 
         AttributeValue.TypeInfo typeInfo = value.typeInfo();
index 58e3f5e..897ddb5 100644 (file)
@@ -69,12 +69,24 @@ public class AttributeEditingSupport {
     private AttributeValueEditor attValueEditor;
     private AutomationEditor     automationEditor;
 
-    private Boolean              valueChangeInProgress;
+    class SyncValueUpdate {
+        private Boolean valueChangeInProgress;
+
+        public boolean isValueChangeInProgress() {
+            return valueChangeInProgress;
+        }
+
+        public void setValueChangeInProgress(boolean value) {
+            valueChangeInProgress = value;
+        }
+    }
+
+    private final SyncValueUpdate syncValueChange = new SyncValueUpdate();
 
     public AttributeValueEditor createAttributeValueEditor(TreeViewer viewer,
             Boolean nativeUpdateValueCall) {
         attValueEditor = new AttributeValueEditor(viewer, nativeUpdateValueCall);
-        valueChangeInProgress = false;
+        syncValueChange.setValueChangeInProgress(false);
         return attValueEditor;
     }
 
@@ -83,14 +95,6 @@ public class AttributeEditingSupport {
         return automationEditor;
     }
 
-    public synchronized boolean isValueChangeInProgress() {
-        return valueChangeInProgress;
-    }
-
-    public synchronized void setValueChangeInProgress(boolean value) {
-        valueChangeInProgress = value;
-    }
-
     class AttributeValueEditor extends EditingSupport {
 
         private final TreeViewer viewer;
@@ -132,7 +136,7 @@ public class AttributeEditingSupport {
                 public void partDeactivated(IWorkbenchPartReference partRef) {
                     String viewId = partRef.getId();
                     if (viewId.equals(AttributeView.VIEW_ID)) {
-                        synchronized (valueChangeInProgress) {
+                        synchronized (syncValueChange) {
                             updateUnSavedData();
                         }
                     }
@@ -166,7 +170,7 @@ public class AttributeEditingSupport {
                 Activator.getDefault().getWorkbench()
                         .getActiveWorkbenchWindow().getActivePage()
                         .addPartListener(partListener);
-            } catch (NullPointerException e) {
+            } catch (Exception e) {
                 Activator
                         .getDefault()
                         .getLogManager()
@@ -206,32 +210,34 @@ public class AttributeEditingSupport {
                 return;
             }
 
-            if (!isValueChangeInProgress()) {
+            synchronized (syncValueChange) {
+                if (!syncValueChange.isValueChangeInProgress()) {
 
-                AttributeValue value = att.value();
-                if (value == null)
-                    return;
+                    AttributeValue value = att.value();
+                    if (value == null)
+                        return;
 
-                TypeInfo type = value.typeInfo();
+                    TypeInfo type = value.typeInfo();
 
-                if (type.mBaseType == ValueType.RESOURCEMODEL
-                        || type.mType == ValueType.ARRAY) {
-                    return;
-                }
+                    if (type.mBaseType == ValueType.RESOURCEMODEL
+                            || type.mType == ValueType.ARRAY) {
+                        return;
+                    }
 
-                if (null == value.get()) {
-                    return;
-                }
+                    if (null == value.get()) {
+                        return;
+                    }
 
-                String oldValue = String.valueOf(Utility
-                        .getAttributeValueAsString(value));
+                    String oldValue = String.valueOf(Utility
+                            .getAttributeValueAsString(value));
 
-                attElement.setEditLock(true);
-                compareAndUpdateAttribute(oldValue, comboBox.getText(),
-                        element, att, type);
-                attElement.setEditLock(false);
+                    attElement.setEditLock(true);
+                    compareAndUpdateAttribute(oldValue, comboBox.getText(),
+                            element, att, type);
+                    attElement.setEditLock(false);
 
-                viewer.refresh();
+                    viewer.refresh();
+                }
             }
         }
 
@@ -282,7 +288,9 @@ public class AttributeEditingSupport {
                 return null;
             }
 
-            setValueChangeInProgress(false);
+            synchronized (syncValueChange) {
+                syncValueChange.setValueChangeInProgress(false);
+            }
 
             CellEditor editor;
             if (type.mType == ValueType.ARRAY) {
@@ -309,6 +317,15 @@ public class AttributeEditingSupport {
                                         .getCurrentResourceInSelection();
 
                                 SimulatorResourceAttribute result = getResultantAttribute();
+                                if (null == result) {
+                                    Activator
+                                            .getDefault()
+                                            .getLogManager()
+                                            .log(Level.ERROR.ordinal(),
+                                                    new Date(),
+                                                    "There is an error while updating the attribute value.\n");
+                                    return;
+                                }
 
                                 boolean updated = resourceManager
                                         .attributeValueUpdated(
@@ -321,6 +338,16 @@ public class AttributeEditingSupport {
                                                         currentAttValue,
                                                         type.mBaseType));
                                     } catch (Exception ex) {
+                                        Activator
+                                                .getDefault()
+                                                .getLogManager()
+                                                .log(Level.ERROR.ordinal(),
+                                                        new Date(),
+                                                        "There is an error while updating the attribute value.\n"
+                                                                + Utility
+                                                                        .getSimulatorErrorString(
+                                                                                ex,
+                                                                                null));
                                     }
                                     MessageDialog
                                             .openInformation(Display
@@ -429,8 +456,8 @@ public class AttributeEditingSupport {
 
         @Override
         protected void setValue(Object element, Object value) {
-            synchronized (valueChangeInProgress) {
-                if (isValueChangeInProgress()) {
+            synchronized (syncValueChange) {
+                if (syncValueChange.isValueChangeInProgress()) {
                     return;
                 }
 
@@ -480,7 +507,9 @@ public class AttributeEditingSupport {
                 return;
             }
 
-            setValueChangeInProgress(true);
+            synchronized (syncValueChange) {
+                syncValueChange.setValueChangeInProgress(true);
+            }
 
             if (!oldValue.equals(newValue)) {
                 boolean invalid = false;
@@ -491,6 +520,14 @@ public class AttributeEditingSupport {
                     attValue = AttributeValueBuilder.build(newValue,
                             type.mBaseType);
                 } catch (Exception e) {
+                    Activator
+                            .getDefault()
+                            .getLogManager()
+                            .log(Level.ERROR.ordinal(),
+                                    new Date(),
+                                    "There is an error while creating the new attribute value.\n"
+                                            + Utility.getSimulatorErrorString(
+                                                    e, null));
                 }
 
                 if (null == attValue) {
@@ -526,10 +563,18 @@ public class AttributeEditingSupport {
                             try {
                                 attValue = AttributeValueBuilder.build(
                                         oldValue, type.mBaseType);
+                                updateAttributeValue(att, attValue);
                             } catch (Exception e) {
+                                Activator
+                                        .getDefault()
+                                        .getLogManager()
+                                        .log(Level.ERROR.ordinal(),
+                                                new Date(),
+                                                "There is an error while updating the attribute value.\n"
+                                                        + Utility
+                                                                .getSimulatorErrorString(
+                                                                        e, null));
                             }
-                            updateAttributeValue(att, attValue);
-
                         } else {
                             ResourceManager resourceManager;
                             resourceManager = Activator.getDefault()
@@ -539,6 +584,14 @@ public class AttributeEditingSupport {
                                     .getCurrentResourceInSelection();
 
                             SimulatorResourceAttribute result = getResultantAttribute();
+                            if (null == result) {
+                                Activator
+                                        .getDefault()
+                                        .getLogManager()
+                                        .log(Level.ERROR.ordinal(), new Date(),
+                                                "There is an error while updating the attribute value.\n");
+                                return;
+                            }
 
                             boolean updated = resourceManager
                                     .attributeValueUpdated(
@@ -548,9 +601,19 @@ public class AttributeEditingSupport {
                                 try {
                                     attValue = AttributeValueBuilder.build(
                                             oldValue, type.mBaseType);
+                                    updateAttributeValue(att, attValue);
                                 } catch (Exception e) {
+                                    Activator
+                                            .getDefault()
+                                            .getLogManager()
+                                            .log(Level.ERROR.ordinal(),
+                                                    new Date(),
+                                                    "There is an error while updating the attribute value.\n"
+                                                            + Utility
+                                                                    .getSimulatorErrorString(
+                                                                            e,
+                                                                            null));
                                 }
-                                updateAttributeValue(att, attValue);
                                 MessageDialog
                                         .openInformation(Display.getDefault()
                                                 .getActiveShell(),
@@ -566,6 +629,10 @@ public class AttributeEditingSupport {
 
         public void updateAttributeValue(SimulatorResourceAttribute att,
                 AttributeValue value) {
+            if (null == att || null == value) {
+                return;
+            }
+
             IStructuredSelection selection = (IStructuredSelection) viewer
                     .getSelection();
             if (null == selection) {
@@ -595,7 +662,15 @@ public class AttributeEditingSupport {
                     try {
                         ((AttributeElement) data).deepSetChildValue(att);
                     } catch (InvalidArgsException e) {
-                        e.printStackTrace();
+                        Activator
+                                .getDefault()
+                                .getLogManager()
+                                .log(Level.ERROR.ordinal(),
+                                        new Date(),
+                                        "There is an error while updating the attribute value.\n"
+                                                + Utility
+                                                        .getSimulatorErrorString(
+                                                                e, null));
                     }
                 }
             }
@@ -619,7 +694,7 @@ public class AttributeEditingSupport {
                 return null;
             }
 
-            SimulatorResourceAttribute result = null;
+            SimulatorResourceAttribute result;
             TreeItem parent = item.getParentItem();
             if (null == parent) {
                 Object data = item.getData();
index 538ebe8..c008f13 100644 (file)
@@ -48,6 +48,7 @@ import org.eclipse.ui.part.ViewPart;
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -57,6 +58,7 @@ import org.oic.simulator.AttributeProperty;
 import org.oic.simulator.AttributeValue;
 import org.oic.simulator.AttributeValue.TypeInfo;
 import org.oic.simulator.AttributeValue.ValueType;
+import org.oic.simulator.ILogger.Level;
 import org.oic.simulator.ModelProperty;
 import org.oic.simulator.SimulatorResourceAttribute;
 import org.oic.simulator.SimulatorResourceModel;
@@ -226,9 +228,6 @@ public class AttributeView extends ViewPart {
                         // displayed by this view.
                         Resource resourceInSelection = resourceManager
                                 .getCurrentResourceInSelection();
-                        if (null == resourceInSelection) {
-                            return;
-                        }
                         if (resource != resourceInSelection) {
                             return;
                         }
@@ -381,7 +380,7 @@ public class AttributeView extends ViewPart {
                         }
 
                         if (null != parent
-                                && !(parent instanceof ResourceRepresentation)) {
+                                && parent instanceof AttributeElement) {
                             Object grandParent = ((AttributeElement) parent)
                                     .getParent();
                             if (null == grandParent
@@ -438,6 +437,15 @@ public class AttributeView extends ViewPart {
                     // the array property of the current attribute in
                     // selection(Model Array type attribute).
                     AttributeElement attElement = getSelectedElement();
+                    if (null == attElement) {
+                        MessageDialog
+                                .openError(Display.getDefault()
+                                        .getActiveShell(),
+                                        "Unable to perform the operation.",
+                                        "Failed to obtain the required data. Operation cannot be performed.");
+                        return;
+                    }
+
                     SimulatorResourceAttribute attribute = attElement
                             .getSimulatorResourceAttribute();
 
@@ -512,10 +520,12 @@ public class AttributeView extends ViewPart {
                                             "Failed to insert a new item in the array.");
                         } else {
                             // Highlight the newly added item.
-                            AttributeElement addedElement = attElement
-                                    .getChildren().get("[" + i + "]");
-                            attViewer.setSelection(new StructuredSelection(
-                                    addedElement), true);
+                            if (attElement.hasChildren()) {
+                                AttributeElement addedElement = attElement
+                                        .getChildren().get("[" + i + "]");
+                                attViewer.setSelection(new StructuredSelection(
+                                        addedElement), true);
+                            }
                         }
                     }
                 }
@@ -593,6 +603,14 @@ public class AttributeView extends ViewPart {
                 // Removing the element from the child map.
                 Map<String, AttributeElement> elements = parentElement
                         .getChildren();
+                if (null == elements) {
+                    MessageDialog
+                            .openError(Display.getDefault().getActiveShell(),
+                                    "Operation failed.",
+                                    "There is an error while removing the array items.");
+                    return;
+                }
+
                 List<AttributeElement> attElementList = new ArrayList<AttributeElement>();
                 attElementList.addAll(elements.values());
                 Collections.sort(attElementList, Utility.attributeComparator);
@@ -633,7 +651,7 @@ public class AttributeView extends ViewPart {
     }
 
     private ResourceRepresentation getRepresentationForOneDimensionTopLevelAttribute() {
-        ResourceRepresentation representation = null;
+        ResourceRepresentation representation;
 
         AttributeValue value = null;
         ModelProperty property = null;
@@ -672,7 +690,13 @@ public class AttributeView extends ViewPart {
             value = Utility.cloneAttributeValue(new AttributeValue(
                     modelValue[0]));
         } catch (Exception e) {
-            return null;
+            Activator
+                    .getDefault()
+                    .getLogManager()
+                    .log(Level.ERROR.ordinal(),
+                            new Date(),
+                            "There is an error while creating an instance of the model element.\n"
+                                    + Utility.getSimulatorErrorString(e, null));
         }
 
         if (null == value) {
index 82ff675..11f2dc1 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.",
@@ -222,9 +221,9 @@ public class MetaPropertiesView extends ViewPart {
                         // 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;
@@ -493,20 +492,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
index 9a09de3..ecbec24 100644 (file)
@@ -49,8 +49,10 @@ import org.eclipse.ui.dialogs.PatternFilter;
 import org.eclipse.ui.part.ViewPart;
 
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 
+import org.oic.simulator.ILogger.Level;
 import org.oic.simulator.SimulatorException;
 import org.oic.simulator.server.SimulatorResource.AutoUpdateType;
 
@@ -68,6 +70,7 @@ import oic.simulator.serviceprovider.utils.Utility;
 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;
 import oic.simulator.serviceprovider.view.dialogs.MainPage.Option;
 import oic.simulator.serviceprovider.view.dialogs.ResourceWizardDialog;
 
@@ -420,8 +423,17 @@ public class ResourceManagerView extends ViewPart {
                         if (open == WizardDialog.OK
                                 || createWizard.isDlgForceClosed()) {
 
-                            Option option = createWizard.getMainPage()
-                                    .getOption();
+                            MainPage mainPage = createWizard.getMainPage();
+                            if (null == mainPage) {
+                                Activator
+                                        .getDefault()
+                                        .getLogManager()
+                                        .log(Level.ERROR.ordinal(), new Date(),
+                                                "There is an error while creating the wizard.\n");
+                                return;
+                            }
+
+                            Option option = mainPage.getOption();
                             if (option == Option.SIMPLE_FROM_RAML
                                     || option == Option.SIMPLE) {
                                 SingleResource res = (SingleResource) createWizard
index a29eecc..f45afec 100644 (file)
@@ -29,6 +29,8 @@ import org.eclipse.jface.wizard.WizardDialog;
 import org.eclipse.swt.widgets.Display;
 
 import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
 import java.net.URL;
 import java.util.Date;
@@ -179,13 +181,27 @@ public class CreateResourceWizard extends Wizard {
             }
         } else if (curPage == loadRamlPage) {
             // Validate the file path.
+            FileInputStream fileStream = null;
             try {
-                new FileInputStream(loadRamlPage.getConfigFilePath());
-            } catch (Exception e) {
+                fileStream = new FileInputStream(
+                        loadRamlPage.getConfigFilePath());
+            } catch (FileNotFoundException e) {
                 MessageDialog
                         .openError(getShell(), "Invalid File",
                                 "File doesn't exist. Either the file path or file name is invalid.");
                 return false;
+            } finally {
+                if (null != fileStream) {
+                    try {
+                        fileStream.close();
+                    } catch (IOException e) {
+                        Activator
+                                .getDefault()
+                                .getLogManager()
+                                .log(Level.ERROR.ordinal(), new Date(),
+                                        "There is an error while closing the file stream.\n");
+                    }
+                }
             }
 
             // Handling multiple instance creation of simple resource with RAML
@@ -422,6 +438,14 @@ public class CreateResourceWizard extends Wizard {
                     Activator.getDefault().getResourceManager()
                             .removeSingleResources(resources);
                 } catch (SimulatorException e) {
+                    Activator
+                            .getDefault()
+                            .getLogManager()
+                            .log(Level.ERROR.ordinal(),
+                                    new Date(),
+                                    "There is an error while updating the resource model.\n"
+                                            + Utility.getSimulatorErrorString(
+                                                    e, null));
                 }
                 return 0;
             }
index b344aeb..9514b7d 100644 (file)
@@ -182,7 +182,7 @@ public class DeleteResourcePage extends WizardPage {
                     return;
                 }
                 for (Object obj : selection) {
-                    if (obj instanceof Resource) {
+                    if (obj instanceof SingleResource) {
                         singles.add((SingleResource) obj);
                     }
                 }
index a09bc36..0a253eb 100644 (file)
@@ -42,6 +42,8 @@ import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.PlatformUI;
 
 import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
 import java.util.Date;
 
@@ -247,13 +249,28 @@ public class LoadRamlPage extends WizardPage {
     @Override
     public IWizardPage getNextPage() {
         // Validate the file path.
+        FileInputStream fileStream = null;
         try {
-            new FileInputStream(configFilePath);
-        } catch (Exception e) {
+            fileStream = new FileInputStream(configFilePath);
+        } catch (FileNotFoundException e) {
             MessageDialog
                     .openError(getShell(), "Invalid File",
                             "File doesn't exist. Either the file path or file name is invalid.");
             return null;
+        } finally {
+            if (null != fileStream)
+                try {
+                    fileStream.close();
+                } catch (IOException e) {
+                    Activator
+                            .getDefault()
+                            .getLogManager()
+                            .log(Level.ERROR.ordinal(),
+                                    new Date(),
+                                    "There is an error while closing the file stream.\n"
+                                            + Utility.getSimulatorErrorString(
+                                                    e, null));
+                }
         }
 
         // Checking the resource count
index f0fda99..4549360 100644 (file)
@@ -108,7 +108,8 @@ public class LogDetailsDialog extends Dialog {
         gd.grabExcessHorizontalSpace = true;
         l5.setLayoutData(gd);
 
-        new Label(container, SWT.NONE); // separator
+        Label seperator = new Label(container, SWT.NONE); // separator
+        seperator.setText("");
 
         Label l6 = new Label(container, SWT.NONE);
         l6.setText("Message details");
index 851d225..e436e9f 100644 (file)
@@ -37,6 +37,8 @@ import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Tree;
 import org.eclipse.swt.widgets.TreeColumn;
 
+import java.util.Map;
+
 import org.oic.simulator.AttributeValue.ValueType;
 import org.oic.simulator.SimulatorResourceAttribute;
 
@@ -173,8 +175,13 @@ public class ModelArrayAddItemDialog extends TitleAreaDialog {
         @Override
         public Object[] getChildren(Object attribute) {
             if (attribute instanceof AttributeElement) {
-                return ((AttributeElement) attribute).getChildren().values()
-                        .toArray();
+                Map<String, AttributeElement> childs = ((AttributeElement) attribute)
+                        .getChildren();
+                if (null == childs) {
+                    return new Object[0];
+                }
+
+                return childs.values().toArray();
             }
 
             return new Object[0];
index 17eae39..64decdd 100644 (file)
@@ -280,13 +280,15 @@ public class SimpleResourceAddAttributePage extends WizardPage {
                         .getDefault().getActiveShell(), att, rTypes, attributes);
                 if (dialog.open() != Window.OK) {
                     AttributeHelper newAtt = dialog.getAttClone();
-                    att.setAttributeName(newAtt.getAttributeName());
-                    att.setAttributeType(newAtt.getAttributeType());
-                    att.setAttributeDflValue(newAtt.getAttributeDflValue());
-                    att.setValidValuesType(newAtt.getValidValuesType());
-                    att.setMin(newAtt.getMin());
-                    att.setMax(newAtt.getMax());
-                    att.setAllowedValues(newAtt.getAllowedValues());
+                    if (null != newAtt) {
+                        att.setAttributeName(newAtt.getAttributeName());
+                        att.setAttributeType(newAtt.getAttributeType());
+                        att.setAttributeDflValue(newAtt.getAttributeDflValue());
+                        att.setValidValuesType(newAtt.getValidValuesType());
+                        att.setMin(newAtt.getMin());
+                        att.setMax(newAtt.getMax());
+                        att.setAllowedValues(newAtt.getAllowedValues());
+                    }
                 }
                 attTblViewer.update(att, null);
             }
index af2669e..bce717e 100644 (file)
@@ -29,14 +29,18 @@ import org.eclipse.swt.widgets.MessageBox;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Text;
 
+import java.util.Date;
+
 import org.oic.simulator.ArrayProperty;
 import org.oic.simulator.AttributeProperty;
 import org.oic.simulator.AttributeValue;
 import org.oic.simulator.DoubleProperty;
+import org.oic.simulator.ILogger.Level;
 import org.oic.simulator.IntegerProperty;
 import org.oic.simulator.SimulatorResourceAttribute;
 import org.oic.simulator.StringProperty;
 
+import oic.simulator.serviceprovider.Activator;
 import oic.simulator.serviceprovider.utils.AttributeValueBuilder;
 import oic.simulator.serviceprovider.utils.AttributeValueStringConverter;
 import oic.simulator.serviceprovider.utils.Utility;
@@ -265,60 +269,60 @@ public class UpdatePrimitiveArrayAttributeDialog extends TitleAreaDialog {
         ArrayProperty arrProp = attribute.property().asArray();
         AttributeProperty elementProp = arrProp.getElementProperty();
 
-        String values = "";
+        StringBuilder values = new StringBuilder();
         if (elementProp.isInteger()) {
             IntegerProperty intProp = elementProp.asInteger();
             if (intProp.hasRange()) {
-                values = intProp.min() + " - " + intProp.max();
+                values.append(intProp.min() + " - " + intProp.max());
             } else if (intProp.hasValues()) {
                 int[] arr = intProp.getValues();
                 for (int i = 0; i < arr.length; i++) {
-                    values += arr[i];
+                    values.append(arr[i]);
                     if (i + 1 < arr.length) {
-                        values += ", ";
+                        values.append(", ");
                     }
                 }
 
-                if (!values.isEmpty()) {
-                    values = "[" + values + "]";
+                if (!values.toString().isEmpty()) {
+                    values.append("[" + values + "]");
                 }
             }
         } else if (elementProp.isDouble()) {
             DoubleProperty dblProp = elementProp.asDouble();
             if (dblProp.hasRange()) {
-                values = dblProp.min() + " - " + dblProp.max();
+                values.append(dblProp.min() + " - " + dblProp.max());
             } else if (dblProp.hasValues()) {
                 double[] arr = dblProp.getValues();
                 for (int i = 0; i < arr.length; i++) {
-                    values += arr[i];
+                    values.append(arr[i]);
                     if (i + 1 < arr.length) {
-                        values += ", ";
+                        values.append(", ");
                     }
                 }
 
-                if (!values.isEmpty()) {
-                    values = "[" + values + "]";
+                if (!values.toString().isEmpty()) {
+                    values.append("[" + values + "]");
                 }
             }
         } else if (elementProp.isBoolean()) {
-            values = "[true, false]";
+            values.append("[true, false]");
         } else if (elementProp.isString()) {
             StringProperty strProp = elementProp.asString();
             if (strProp.hasValues()) {
                 String[] arr = strProp.getValues();
                 for (int i = 0; i < arr.length; i++) {
-                    values += arr[i];
+                    values.append(arr[i]);
                     if (i + 1 < arr.length) {
-                        values += ", ";
+                        values.append(", ");
                     }
                 }
 
-                if (!values.isEmpty()) {
-                    values = "[" + values + "]";
+                if (!values.toString().isEmpty()) {
+                    values.append("[" + values + "]");
                 }
             }
         }
-        allowedValuesTxt.setText(values);
+        allowedValuesTxt.setText(values.toString());
 
         // Set the current value.
         currentValueTxt.setText(new AttributeValueStringConverter(attribute
@@ -352,7 +356,7 @@ public class UpdatePrimitiveArrayAttributeDialog extends TitleAreaDialog {
         ArrayProperty arrProp = attribute.property().asArray();
         try {
             String value = Utility.removeWhiteSpacesInArrayValues(newValue);
-            if (value.startsWith("[") && value.endsWith("]")) {
+            if (null != value && value.startsWith("[") && value.endsWith("]")) {
                 newAttValueObj = AttributeValueBuilder.build(value, attribute
                         .value().typeInfo().mBaseType);
                 if (null != newAttValueObj && arrProp.validate(newAttValueObj)) {
@@ -361,6 +365,13 @@ public class UpdatePrimitiveArrayAttributeDialog extends TitleAreaDialog {
                 }
             }
         } catch (Exception e) {
+            Activator
+                    .getDefault()
+                    .getLogManager()
+                    .log(Level.ERROR.ordinal(),
+                            new Date(),
+                            "There is an error while building the new attribute value.\n"
+                                    + Utility.getSimulatorErrorString(e, null));
         }
 
         MessageBox dialog = new MessageBox(Display.getDefault()
index 60b7349..4fe07b5 100644 (file)
@@ -119,8 +119,11 @@ public class UpdateResourceInterfaceDialog extends TrayDialog {
     }
 
     private void initInterfaceList() {
-        for (Map.Entry<String, String> entry : updatedResInterfaces.entrySet()) {
-            ifTypesList.add(entry.getKey());
+        if (null != updatedResInterfaces) {
+            for (Map.Entry<String, String> entry : updatedResInterfaces
+                    .entrySet()) {
+                ifTypesList.add(entry.getKey());
+            }
         }
     }
 
index 26206c4..d4bbdb3 100644 (file)
@@ -84,7 +84,12 @@ class ArrayValueValidator implements
                 return false;
             }
 
-            if (false == elementProperty.asInteger().validate(value))
+            IntegerProperty intProperty = elementProperty.asInteger();
+            if (null == intProperty) {
+                return false;
+            }
+
+            if (false == intProperty.validate(value))
                 return false;
         }
 
@@ -117,7 +122,12 @@ class ArrayValueValidator implements
                 return false;
             }
 
-            if (false == elementProperty.asDouble().validate(value))
+            DoubleProperty dblProperty = elementProperty.asDouble();
+            if (null == dblProperty) {
+                return false;
+            }
+
+            if (false == dblProperty.validate(value))
                 return false;
         }
 
@@ -150,7 +160,12 @@ class ArrayValueValidator implements
                 return false;
             }
 
-            if (false == elementProperty.asBoolean().validate(value))
+            BooleanProperty boolProperty = elementProperty.asBoolean();
+            if (null == boolProperty) {
+                return false;
+            }
+
+            if (false == boolProperty.validate(value))
                 return false;
         }
 
@@ -183,7 +198,12 @@ class ArrayValueValidator implements
                 return false;
             }
 
-            if (false == elementProperty.asString().validate(value))
+            StringProperty stringProperty = elementProperty.asString();
+            if (null == stringProperty) {
+                return false;
+            }
+
+            if (false == stringProperty.validate(value))
                 return false;
         }
 
@@ -211,7 +231,12 @@ class ArrayValueValidator implements
         }
 
         for (SimulatorResourceModel value : values) {
-            if (false == elementProperty.asModel().validate(value))
+            ModelProperty modelProperty = elementProperty.asModel();
+            if (null == modelProperty) {
+                return false;
+            }
+
+            if (false == modelProperty.validate(value))
                 return false;
         }
 
index b7f759c..281bedd 100644 (file)
@@ -107,7 +107,7 @@ public class AttributeValue {
      *            boolean type value.
      */
     public AttributeValue(boolean value) {
-        mValue = new Boolean(value);
+        mValue = Boolean.valueOf(value);
     }
 
     /**
index ffb4e18..c9a7ba9 100644 (file)
@@ -52,7 +52,7 @@ public class SimulatorException extends Exception {
      */
     public SimulatorException(SimulatorResult code, String message) {
         this.code = code;
-        this.message = new String(message);
+        this.message = message;
     }
 
     /**
index 89f2dd6..7293654 100644 (file)
@@ -90,7 +90,7 @@ public class SimulatorManager {
     public static SimulatorResource createResource(SimulatorResource.Type type,
             String name, String uri, String resourceType)
             throws InvalidArgsException, SimulatorException {
-        SimulatorResource resource = null;
+        SimulatorResource resource;
         if (type == SimulatorResource.Type.SINGLE)
             resource = nativeCreateSingleResource(name, uri, resourceType);
         else
index 35c4fd1..f997444 100644 (file)
@@ -39,7 +39,7 @@ public class SimulatorResourceAttribute {
      */
     public SimulatorResourceAttribute(String name, AttributeValue value,
             AttributeProperty property) {
-        mName = new String(name);
+        mName = name;
         mValue = value;
         mProperty = property;
     }
@@ -54,7 +54,7 @@ public class SimulatorResourceAttribute {
      *            Value of the attribute.
      */
     public SimulatorResourceAttribute(String name, AttributeValue value) {
-        mName = new String(name);
+        mName = name;
         mValue = value;
         mProperty = null;
     }
index 0660d5b..2238a45 100644 (file)
@@ -97,11 +97,11 @@ public class StringProperty extends AttributeProperty {
     }
 
     public static class Builder {
-        private String   mDefaultValue = new String();
+        private String   mDefaultValue;
         private int      mMin;
         private int      mMax;
         private String[] mValues;
-        private boolean  mHasRange     = false;
+        private boolean  mHasRange = false;
 
         public void setDefaultValue(String value) {
             if (null != value)
index c746811..15bc6ff 100644 (file)
@@ -38,7 +38,18 @@ std::shared_ptr<SimulatorResource> SimulatorResourceFactory::createResource(
 {\r
     // Parse the RAML file\r
     std::shared_ptr<RAML::RamlParser> ramlParser = std::make_shared<RAML::RamlParser>(configPath);\r
+    if (!ramlParser)\r
+    {\r
+        OIC_LOG(ERROR, TAG, "RAML parser returned NULL!");\r
+        return nullptr;\r
+    }\r
+\r
     RAML::RamlPtr raml = ramlParser->getRamlPtr();\r
+    if (!raml)\r
+    {\r
+        OIC_LOG(ERROR, TAG, "RAML pointer is NULL!");\r
+        return nullptr;\r
+    }\r
 \r
     // Get the first resource model from RAML\r
     RAML::RamlResourcePtr ramlResource;\r
@@ -59,7 +70,18 @@ std::vector<std::shared_ptr<SimulatorResource> > SimulatorResourceFactory::creat
 \r
     // Parse the RAML file\r
     std::shared_ptr<RAML::RamlParser> ramlParser = std::make_shared<RAML::RamlParser>(configPath);\r
+    if (!ramlParser)\r
+    {\r
+        OIC_LOG(ERROR, TAG, "RAML parser returned NULL!");\r
+        return resources;\r
+    }\r
+\r
     RAML::RamlPtr raml = ramlParser->getRamlPtr();\r
+    if (!raml)\r
+    {\r
+        OIC_LOG(ERROR, TAG, "RAML pointer is NULL!");\r
+        return resources;\r
+    }\r
 \r
     // Get the first resource model from RAML\r
     RAML::RamlResourcePtr ramlResource;\r