Displaying and editing the complex value types for attributes.
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ClientControllerPlugin / src / oic / simulator / clientcontroller / manager / ResourceManager.java
index 9b8bdb4..3de0d3e 100644 (file)
@@ -16,7 +16,6 @@
 
 package oic.simulator.clientcontroller.manager;
 
-import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
@@ -27,9 +26,11 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.Vector;
 
 import oic.simulator.clientcontroller.Activator;
 import oic.simulator.clientcontroller.listener.IConfigurationUpload;
+import oic.simulator.clientcontroller.listener.IDevicePlatformInfoUIListener;
 import oic.simulator.clientcontroller.listener.IFindResourceUIListener;
 import oic.simulator.clientcontroller.listener.IGetUIListener;
 import oic.simulator.clientcontroller.listener.IObserveUIListener;
@@ -38,31 +39,33 @@ import oic.simulator.clientcontroller.listener.IPutUIListener;
 import oic.simulator.clientcontroller.listener.IResourceSelectionChangedUIListener;
 import oic.simulator.clientcontroller.listener.IVerificationUIListener;
 import oic.simulator.clientcontroller.remoteresource.MetaProperty;
-import oic.simulator.clientcontroller.remoteresource.PutPostAttributeModel;
 import oic.simulator.clientcontroller.remoteresource.RemoteResource;
-import oic.simulator.clientcontroller.remoteresource.RemoteResourceAttribute;
 import oic.simulator.clientcontroller.utils.Constants;
 import oic.simulator.clientcontroller.utils.Utility;
 
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.swt.graphics.Image;
+import org.oic.simulator.AttributeProperty;
+import org.oic.simulator.AttributeProperty.Type;
+import org.oic.simulator.AttributeValue;
+import org.oic.simulator.AttributeValue.TypeInfo;
+import org.oic.simulator.AttributeValue.ValueType;
+import org.oic.simulator.DeviceInfo;
+import org.oic.simulator.DeviceListener;
 import org.oic.simulator.ILogger.Level;
-import org.oic.simulator.InvalidArgsException;
-import org.oic.simulator.ResourceAttribute;
-import org.oic.simulator.ResourceAttribute.Range;
-import org.oic.simulator.ResourceAttribute.Type;
+import org.oic.simulator.PlatformInfo;
+import org.oic.simulator.PlatformListener;
 import org.oic.simulator.SimulatorException;
 import org.oic.simulator.SimulatorManager;
+import org.oic.simulator.SimulatorResourceAttribute;
 import org.oic.simulator.SimulatorResourceModel;
-import org.oic.simulator.clientcontroller.IFindResourceListener;
-import org.oic.simulator.clientcontroller.IGetListener;
-import org.oic.simulator.clientcontroller.IObserveListener;
-import org.oic.simulator.clientcontroller.IPostListener;
-import org.oic.simulator.clientcontroller.IPutListener;
-import org.oic.simulator.clientcontroller.IVerificationListener;
-import org.oic.simulator.clientcontroller.SimulatorObserveType;
-import org.oic.simulator.clientcontroller.SimulatorRemoteResource;
-import org.oic.simulator.clientcontroller.SimulatorVerificationType;
+import org.oic.simulator.SimulatorResult;
+import org.oic.simulator.client.FindResourceListener;
+import org.oic.simulator.client.SimulatorRemoteResource;
+import org.oic.simulator.client.SimulatorRemoteResource.GetResponseListener;
+import org.oic.simulator.client.SimulatorRemoteResource.ObserveNotificationListener;
+import org.oic.simulator.client.SimulatorRemoteResource.PostResponseListener;
+import org.oic.simulator.client.SimulatorRemoteResource.PutResponseListener;
+import org.oic.simulator.client.SimulatorRemoteResource.VerificationListener;
+import org.oic.simulator.client.SimulatorRemoteResource.VerificationType;
 
 /**
  * This class acts as an interface between the simulator java SDK and the
@@ -77,12 +80,14 @@ public class ResourceManager {
 
     private RemoteResource                            currentResourceInSelection;
 
-    private IFindResourceListener                     findResourceListener;
-    private IGetListener                              getListener;
-    private IPutListener                              putListener;
-    private IPostListener                             postListener;
-    private IObserveListener                          observeListener;
-    private IVerificationListener                     verifyListener;
+    private FindResourceListener                      findResourceListener;
+    private GetResponseListener                       getListener;
+    private PutResponseListener                       putListener;
+    private PostResponseListener                      postListener;
+    private ObserveNotificationListener               observeListener;
+    private VerificationListener                      verifyListener;
+    private DeviceListener                            deviceListener;
+    private PlatformListener                          platformListener;
 
     private ResponseSynchronizerThread                synchronizerThread;
 
@@ -96,6 +101,7 @@ public class ResourceManager {
     private List<IObserveUIListener>                  observeUIListeners;
     private List<IVerificationUIListener>             verificationUIListeners;
     private List<IConfigurationUpload>                configUploadUIListeners;
+    private List<IDevicePlatformInfoUIListener>       devicePlatformInfoUIListeners;
 
     // Map with Server ID as key and the complete object as the value
     private Map<String, RemoteResource>               resourceMap;
@@ -106,6 +112,9 @@ public class ResourceManager {
     // Maintaining a list of observed resource URIs.
     private List<String>                              observedResourceURIList;
 
+    private DeviceInfo                                devInfo;
+    private PlatformInfo                              platInfo;
+
     public ResourceManager() {
         resourceMap = new HashMap<String, RemoteResource>();
         favoriteResources = new ArrayList<RemoteResource>();
@@ -119,41 +128,41 @@ public class ResourceManager {
         observeUIListeners = new ArrayList<IObserveUIListener>();
         verificationUIListeners = new ArrayList<IVerificationUIListener>();
         configUploadUIListeners = new ArrayList<IConfigurationUpload>();
+        devicePlatformInfoUIListeners = new ArrayList<IDevicePlatformInfoUIListener>();
 
-        findResourceListener = new IFindResourceListener() {
+        findResourceListener = new FindResourceListener() {
 
             @Override
-            public void onResourceCallback(
-                    final SimulatorRemoteResource resourceN) {
+            public void onResourceFound(final SimulatorRemoteResource resourceN) {
                 synchronizerThread.addToQueue(new Runnable() {
                     @Override
                     public void run() {
-                        System.out.println("onResourceCallback() entry");
                         if (null == resourceN) {
                             return;
                         }
-                        // If resource already exist, then ignore it.
+
+                        // If id is not available, then it cannot be added to
+                        // the local map as null value should not be allowed as
+                        // key.
                         String uid = resourceN.getId();
                         if (null == uid) {
                             return;
                         }
+
+                        // If resource already exist, then ignore it.
                         boolean exist = isUidExist(uid);
                         if (exist) {
-                            System.out.println("Duplicate resource found: ["
-                                    + uid + "]");
                             return;
                         }
 
                         // Fetch the resource data
-                        RemoteResource resource = fetchResourceDetails(resourceN);
-                        if (null == resource) {
-                            return;
-                        }
-
-                        resource.setResource(resourceN);
+                        // RemoteResource resource =
+                        // fetchResourceDetails(resourceN);
+                        RemoteResource resource = new RemoteResource();
+                        resource.setRemoteResourceRef(resourceN);
 
-                        String uri = resource.getResourceURI();
-                        if (null != uri) {
+                        String uri = resourceN.getURI();
+                        if (null != uri && uri.trim().length() > 0) {
                             // Add resource to favorite list if it was in
                             // favorites list during find/refresh operation.
                             if (favoriteURIList.contains(uri)) {
@@ -162,8 +171,15 @@ public class ResourceManager {
                             // Add resource to observed resources list if it was
                             // in observe list during find/refresh operation.
                             if (observedResourceURIList.contains(uri)) {
-                                resource.setObserved(true);
+                                sendObserveRequest(resource);
                             }
+                        } else {
+                            Activator
+                                    .getDefault()
+                                    .getLogManager()
+                                    .log(Level.INFO.ordinal(), new Date(),
+                                            "Found a resource without URI. Ignoring it.");
+                            return;
                         }
 
                         // Add the resource in local data structure
@@ -172,6 +188,14 @@ public class ResourceManager {
                         // Notify the UI listener
                         newResourceFoundNotification(resource);
 
+                        Activator
+                                .getDefault()
+                                .getLogManager()
+                                .log(Level.INFO.ordinal(),
+                                        new Date(),
+                                        "Resource Found [" + resourceN.getURI()
+                                                + "].");
+
                         // Send an initial GET request to get the resource
                         // attributes
                         try {
@@ -182,50 +206,89 @@ public class ResourceManager {
                                     .getLogManager()
                                     .log(Level.ERROR.ordinal(),
                                             new Date(),
-                                            "[" + e.getClass().getSimpleName()
-                                                    + "]" + e.code().toString()
-                                                    + "-" + e.message());
+                                            Utility.getSimulatorErrorString(e,
+                                                    null));
+                        }
+
+                        // Get the device and platform information
+                        try {
+                            SimulatorManager.findDevices(resource
+                                    .getRemoteResourceRef().getHost(),
+                                    deviceListener);
+                            SimulatorManager.getPlatformInformation(resource
+                                    .getRemoteResourceRef().getHost(),
+                                    platformListener);
+                        } catch (SimulatorException e) {
+                            Activator
+                                    .getDefault()
+                                    .getLogManager()
+                                    .log(Level.ERROR.ordinal(),
+                                            new Date(),
+                                            Utility.getSimulatorErrorString(e,
+                                                    null));
                         }
                     }
                 });
             }
         };
 
-        getListener = new IGetListener() {
+        // TODO: Listeners for device and platform information.
+        deviceListener = new DeviceListener() {
+
             @Override
-            public void onGetCompleted(final String uid,
-                    final SimulatorResourceModel resourceModelN) {
+            public void onDeviceFound(final DeviceInfo deviceInfo) {
+                if (null == deviceInfo) {
+                    return;
+                }
                 synchronizerThread.addToQueue(new Runnable() {
                     @Override
                     public void run() {
-                        // Handling the response which includes retrieving the
-                        // attributes and updating the local model.
-                        RemoteResource resource = handleResponse(uid,
-                                resourceModelN);
-                        if (null != resource) {
-                            // Notify the UI listeners
-                            getCompleteNotification(resource);
-                        }
+                        setDeviceInfo(deviceInfo);
+
+                        // Notify UI listeners
+                        deviceInfoReceivedNotification();
                     }
                 });
             }
+        };
+
+        platformListener = new PlatformListener() {
 
             @Override
-            public void onGetFailed(Throwable th) {
+            public void onPlatformFound(final PlatformInfo platformInfo) {
+                if (null == platformInfo) {
+                    return;
+                }
                 synchronizerThread.addToQueue(new Runnable() {
                     @Override
                     public void run() {
+                        setPlatformInfo(platformInfo);
+
+                        // Notify UI listeners
+                        platformInfoReceivedNotification();
                     }
                 });
             }
         };
 
-        putListener = new IPutListener() {
-
+        getListener = new GetResponseListener() {
             @Override
-            public void onPutCompleted(final String uid,
+            public void onGetResponse(final String uid,
+                    final SimulatorResult result,
                     final SimulatorResourceModel resourceModelN) {
-                synchronizerThread.addToQueue(new Thread() {
+                System.out.println(result);
+                if (result != SimulatorResult.SIMULATOR_OK) {
+                    Activator
+                            .getDefault()
+                            .getLogManager()
+                            .log(Level.ERROR.ordinal(),
+                                    new Date(),
+                                    "["
+                                            + result.toString()
+                                            + "] Received error response for GET request.");
+                    return;
+                }
+                synchronizerThread.addToQueue(new Runnable() {
                     @Override
                     public void run() {
                         // Handling the response which includes retrieving the
@@ -234,26 +297,62 @@ public class ResourceManager {
                                 resourceModelN);
                         if (null != resource) {
                             // Notify the UI listeners
-                            putCompleteNotification(resource);
+                            getCompleteNotification(resource);
                         }
                     }
                 });
             }
+        };
+
+        putListener = new PutResponseListener() {
 
             @Override
-            public void onPutFailed(Throwable th) {
-                synchronizerThread.addToQueue(new Runnable() {
+            public void onPutResponse(final String uid,
+                    final SimulatorResult result,
+                    final SimulatorResourceModel resourceModelN) {
+                if (result != SimulatorResult.SIMULATOR_OK) {
+                    Activator
+                            .getDefault()
+                            .getLogManager()
+                            .log(Level.ERROR.ordinal(),
+                                    new Date(),
+                                    "["
+                                            + result.toString()
+                                            + "] Received error response for PUT request.");
+                    return;
+                }
+                synchronizerThread.addToQueue(new Thread() {
                     @Override
                     public void run() {
+                        // Handling the response which includes retrieving the
+                        // attributes and updating the local model.
+                        RemoteResource resource = handleResponse(uid,
+                                resourceModelN);
+                        if (null != resource) {
+                            // Notify the UI listeners
+                            putCompleteNotification(resource);
+                        }
                     }
                 });
             }
         };
 
-        postListener = new IPostListener() {
+        postListener = new PostResponseListener() {
             @Override
-            public void onPostCompleted(final String uid,
+            public void onPostResponse(final String uid,
+                    final SimulatorResult result,
                     final SimulatorResourceModel resourceModelN) {
+                if (result != SimulatorResult.SIMULATOR_OK) {
+                    Activator
+                            .getDefault()
+                            .getLogManager()
+                            .log(Level.ERROR.ordinal(),
+                                    new Date(),
+                                    "["
+                                            + result.toString()
+                                            + "] Received error response for POST request.");
+                    return;
+                }
                 synchronizerThread.addToQueue(new Runnable() {
                     @Override
                     public void run() {
@@ -268,23 +367,13 @@ public class ResourceManager {
                     }
                 });
             }
-
-            @Override
-            public void onPostFailed(Throwable th) {
-                synchronizerThread.addToQueue(new Runnable() {
-                    @Override
-                    public void run() {
-                    }
-                });
-            }
         };
 
-        observeListener = new IObserveListener() {
+        observeListener = new ObserveNotificationListener() {
 
             @Override
-            public void onObserveCompleted(final String uid,
+            public void onObserveNotification(final String uid,
                     final SimulatorResourceModel resourceModelN, final int seq) {
-                System.out.println("ResourceManager: onObserveCallback()");
                 synchronizerThread.addToQueue(new Runnable() {
                     @Override
                     public void run() {
@@ -299,18 +388,12 @@ public class ResourceManager {
                     }
                 });
             }
-
-            @Override
-            public void onObserveFailed(Throwable th) {
-                // TODO Auto-generated method stub
-            }
         };
 
-        verifyListener = new IVerificationListener() {
+        verifyListener = new VerificationListener() {
 
             @Override
             public void onVerificationStarted(final String uid, final int autoId) {
-                System.out.println("onVefificationStarted: " + autoId);
                 synchronizerThread.addToQueue(new Runnable() {
                     @Override
                     public void run() {
@@ -332,7 +415,6 @@ public class ResourceManager {
             @Override
             public void onVerificationCompleted(final String uid,
                     final int autoId) {
-                System.out.println("onVefificationCompleted: " + autoId);
                 synchronizerThread.addToQueue(new Runnable() {
                     @Override
                     public void run() {
@@ -353,7 +435,6 @@ public class ResourceManager {
 
             @Override
             public void onVerificationAborted(final String uid, final int autoId) {
-                System.out.println("onVefificationAborted: " + autoId);
                 synchronizerThread.addToQueue(new Runnable() {
                     @Override
                     public void run() {
@@ -392,20 +473,36 @@ public class ResourceManager {
             return null;
         }
 
-        resource.setResourceModel(resourceModelN);
-        Map<String, RemoteResourceAttribute> attributeMap = fetchResourceAttributesFromModel(resourceModelN);
+        // if(!resource.isConfigUploaded() || null ==
+        // resource.getResourceModelRef())
+        SimulatorResourceModel resourceModel = resource.getResourceModelRef();
+        if (null == resourceModel) {
+            resource.setResourceModelRef(resourceModelN);
+        } else {
+            resourceModel.update(resourceModelN);
+        }
 
-        // TODO: For debugging
-        if (null != attributeMap) {
-            RemoteResourceAttribute.printAttributes(attributeMap);
-            System.out.println("Attributes found: ");
-            System.out.println("No of attributes: " + attributeMap.size());
+        resource.setResourceRepresentation(resourceModelN, false);
 
-            resource.setResourceAttributesMap(attributeMap);
-        }
         return resource;
     }
 
+    public synchronized DeviceInfo getDeviceInfo() {
+        return devInfo;
+    }
+
+    public synchronized void setDeviceInfo(DeviceInfo devInfo) {
+        this.devInfo = devInfo;
+    }
+
+    public synchronized PlatformInfo getPlatformInfo() {
+        return platInfo;
+    }
+
+    public synchronized void setPlatformInfo(PlatformInfo platInfo) {
+        this.platInfo = platInfo;
+    }
+
     private static class ResponseSynchronizerThread implements Runnable {
 
         LinkedList<Runnable> responseQueue = new LinkedList<Runnable>();
@@ -492,6 +589,20 @@ public class ResourceManager {
         }
     }
 
+    public void addDevicePlatformInfoUIListener(
+            IDevicePlatformInfoUIListener deviceUIListener) {
+        synchronized (devicePlatformInfoUIListeners) {
+            devicePlatformInfoUIListeners.add(deviceUIListener);
+        }
+    }
+
+    public void removeDevicePlatformInfoUIListener(
+            IDevicePlatformInfoUIListener platformUIListener) {
+        synchronized (devicePlatformInfoUIListeners) {
+            devicePlatformInfoUIListeners.remove(platformUIListener);
+        }
+    }
+
     public void removeResourceSelectionChangedUIListener(
             IResourceSelectionChangedUIListener listener) {
         synchronized (resourceSelectionChangedUIListeners) {
@@ -546,7 +657,6 @@ public class ResourceManager {
         resource.setFavorite(true);
         synchronized (favoriteResources) {
             favoriteResources.add(resource);
-            favoriteURIList.add(resource.getResourceURI());
         }
     }
 
@@ -560,18 +670,28 @@ public class ResourceManager {
         }
     }
 
+    public void addResourceURItoFavorites(RemoteResource resource) {
+        if (null == resource) {
+            return;
+        }
+        synchronized (favoriteURIList) {
+            favoriteURIList.add(resource.getRemoteResourceRef().getURI());
+        }
+    }
+
     public void removeResourceURIFromFavorites(RemoteResource resource) {
         if (null == resource) {
             return;
         }
         synchronized (favoriteURIList) {
-            favoriteURIList.remove(resource.getResourceURI());
+            favoriteURIList.remove(resource.getRemoteResourceRef().getURI());
         }
     }
 
     public void addObservedResourceURI(String resourceURI) {
         synchronized (observedResourceURIList) {
-            observedResourceURIList.add(resourceURI);
+            if (!observedResourceURIList.contains(resourceURI))
+                observedResourceURIList.add(resourceURI);
         }
     }
 
@@ -582,7 +702,7 @@ public class ResourceManager {
     }
 
     public boolean isResourceObserved(String resourceURI) {
-        boolean observed;
+        boolean observed = false;
         synchronized (observedResourceURIList) {
             observed = observedResourceURIList.contains(resourceURI);
         }
@@ -601,7 +721,8 @@ public class ResourceManager {
     private void addResourceDetails(RemoteResource remoteResource) {
         if (null != remoteResource) {
             synchronized (resourceMap) {
-                resourceMap.put(remoteResource.getuId(), remoteResource);
+                resourceMap.put(remoteResource.getRemoteResourceRef().getId(),
+                        remoteResource);
             }
         }
     }
@@ -624,24 +745,6 @@ public class ResourceManager {
         }
     }
 
-    private RemoteResource fetchResourceDetails(
-            SimulatorRemoteResource remoteResourceN) {
-        if (null == remoteResourceN) {
-            return null;
-        }
-        RemoteResource remoteResource = new RemoteResource();
-        remoteResource.setuId(remoteResourceN.getId());
-        remoteResource.setResourceURI(remoteResourceN.getUri());
-        remoteResource.setHost(remoteResourceN.getHost());
-        remoteResource.setResourceTypes(remoteResourceN.getResourceTypes());
-        remoteResource.setResourceInterfaces(remoteResourceN
-                .getResourceInterfaces());
-        remoteResource.setConnectivityType(remoteResourceN
-                .getConnectivityType());
-        remoteResource.setObservable(remoteResourceN.getIsObservable());
-        return remoteResource;
-    }
-
     private boolean isUidExist(String uid) {
         boolean exist;
         synchronized (resourceMap) {
@@ -661,94 +764,6 @@ public class ResourceManager {
         return resource;
     }
 
-    private Map<String, RemoteResourceAttribute> fetchResourceAttributesFromModel(
-            SimulatorResourceModel resourceModelN) {
-        Map<String, RemoteResourceAttribute> resourceAttributeMap = null;
-        if (null != resourceModelN) {
-            Map<String, ResourceAttribute> attributeMapN;
-            try {
-                attributeMapN = resourceModelN.getAttributes();
-            } catch (SimulatorException e) {
-                Activator
-                        .getDefault()
-                        .getLogManager()
-                        .log(Level.ERROR.ordinal(),
-                                new Date(),
-                                "[" + e.getClass().getSimpleName() + "]"
-                                        + e.code().toString() + "-"
-                                        + e.message());
-                return null;
-            }
-            if (null != attributeMapN) {
-                resourceAttributeMap = new HashMap<String, RemoteResourceAttribute>();
-
-                Set<String> attNameSet = attributeMapN.keySet();
-                String attName;
-                Object attValueObj;
-                ResourceAttribute attributeN;
-                RemoteResourceAttribute attribute;
-                Iterator<String> attNameItr = attNameSet.iterator();
-                while (attNameItr.hasNext()) {
-                    attName = attNameItr.next();
-                    attributeN = attributeMapN.get(attName);
-                    if (null != attributeN) {
-                        attribute = new RemoteResourceAttribute();
-                        attribute.setResourceAttribute(attributeN);
-                        attribute.setAttributeName(attName);
-
-                        attValueObj = attributeN.getValue();
-                        if (null != attValueObj) {
-                            attribute.setAttributeValue(attValueObj);
-                        }
-
-                        // Set the attribute type
-                        attribute.setAttValBaseType(attributeN.getBaseType());
-                        attribute.setAttValType(attributeN.getType());
-
-                        // Set the range and allowed values
-                        Range range = attributeN.getRange();
-                        if (null != range) {
-                            attribute.setMinValue(range.getMin());
-                            attribute.setMaxValue(range.getMax());
-                        } else {
-                            Object[] values = attributeN.getAllowedValues();
-                            if (null != values && values.length > 0) {
-                                List<Object> valueList = new ArrayList<Object>();
-                                for (Object obj : values) {
-                                    valueList.add(obj);
-                                }
-                                attribute.setAllowedValues(valueList);
-                            }
-                            /*
-                             * Type baseType = attribute.getAttValBaseType();
-                             *
-                             * if(baseType == Type.INT) { //int[] values =
-                             * attributeN.getAllowedValues();
-                             * attribute.setAllowedValues
-                             * (attributeN.getAllowedValues()); } else
-                             * if(baseType == Type.DOUBLE) { double[] values =
-                             * attributeN.getAllowedValues();
-                             * attribute.setAllowedValues
-                             * (Utility.converArrayToList(values)); } else
-                             * if(baseType == Type.BOOL) { //boolean[] values =
-                             * attributeN.getAllowedValues(); List<Object> obj =
-                             * new ArrayList<Object>(); obj.add(true);
-                             * obj.add(false); attribute.setAllowedValues(obj);
-                             * } else if(baseType == Type.STRING) { String[]
-                             * values = attributeN.getAllowedValues();
-                             * attribute.
-                             * setAllowedValues(Utility.converArrayToList
-                             * (values)); }
-                             */
-                        }
-                        resourceAttributeMap.put(attName, attribute);
-                    }
-                }
-            }
-        }
-        return resourceAttributeMap;
-    }
-
     private void newResourceFoundNotification(RemoteResource resource) {
         synchronized (findResourceUIListeners) {
             if (findResourceUIListeners.size() > 0) {
@@ -912,31 +927,36 @@ public class ResourceManager {
         }
     }
 
-    // TODO: Temporarily used to display the resource in the UI
-    public List<String> getURIList() {
-        List<String> list = new ArrayList<String>();
-        synchronized (resourceMap) {
-            /*
-             * Set<String> idSet = resourceMap.keySet(); Iterator<String> idItr
-             * = idSet.iterator(); String sId; RemoteResource resource;
-             * while(idItr.hasNext()) { sId = idItr.next(); resource =
-             * resourceMap.get(sId); if(null == resource) { continue; }
-             * list.add(resource.getResourceURI()); }
-             */
-            Set<String> uriSet = resourceMap.keySet();
-            Iterator<String> uriItr = uriSet.iterator();
-            String uri;
-            while (uriItr.hasNext()) {
-                uri = uriItr.next();
-                if (null != uri) {
-                    list.add(uri);
+    private void deviceInfoReceivedNotification() {
+        synchronized (devicePlatformInfoUIListeners) {
+            if (devicePlatformInfoUIListeners.size() > 0) {
+                IDevicePlatformInfoUIListener listener;
+                Iterator<IDevicePlatformInfoUIListener> listenerItr = devicePlatformInfoUIListeners
+                        .iterator();
+                while (listenerItr.hasNext()) {
+                    listener = listenerItr.next();
+                    if (null != listener) {
+                        listener.onDeviceInfoFound();
+                    }
                 }
             }
+        }
+    }
 
-            // Sort the types
-            Collections.sort(list);
+    private void platformInfoReceivedNotification() {
+        synchronized (devicePlatformInfoUIListeners) {
+            if (devicePlatformInfoUIListeners.size() > 0) {
+                IDevicePlatformInfoUIListener listener;
+                Iterator<IDevicePlatformInfoUIListener> listenerItr = devicePlatformInfoUIListeners
+                        .iterator();
+                while (listenerItr.hasNext()) {
+                    listener = listenerItr.next();
+                    if (null != listener) {
+                        listener.onPlatformInfoFound();
+                    }
+                }
+            }
         }
-        return list;
     }
 
     public synchronized Set<String> getLastKnownSearchTypes() {
@@ -949,45 +969,71 @@ public class ResourceManager {
     }
 
     public boolean findResourceRequest(Set<String> searchTypes) {
-        if (null == searchTypes || searchTypes.size() < 1) {
-            return false;
-        }
         boolean result = false;
-        Iterator<String> searchItr = searchTypes.iterator();
-        String rType;
-        while (searchItr.hasNext()) {
-            rType = searchItr.next();
+        if (null == searchTypes || searchTypes.size() < 1) {
             try {
-                SimulatorManager.findResource(rType, findResourceListener);
+                SimulatorManager.findResource(findResourceListener);
                 result = true;
             } catch (SimulatorException e) {
                 Activator
                         .getDefault()
                         .getLogManager()
-                        .log(Level.ERROR.ordinal(),
-                                new Date(),
-                                "[" + e.getClass().getSimpleName() + "]"
-                                        + e.code().toString() + "-"
-                                        + e.message());
+                        .log(Level.ERROR.ordinal(), new Date(),
+                                Utility.getSimulatorErrorString(e, null));
+            }
+        } else {
+            Iterator<String> searchItr = searchTypes.iterator();
+            String rType;
+            while (searchItr.hasNext()) {
+                rType = searchItr.next();
+                try {
+                    SimulatorManager.findResource(rType, findResourceListener);
+                    result = true;
+                } catch (SimulatorException e) {
+                    Activator
+                            .getDefault()
+                            .getLogManager()
+                            .log(Level.ERROR.ordinal(), new Date(),
+                                    Utility.getSimulatorErrorString(e, null));
+                }
             }
         }
         return result;
     }
 
     public void deleteResources(final Set<String> searchTypes) {
-        if (null == searchTypes || searchTypes.size() < 1) {
-            return;
+        synchronized (resourceMap) {
+            if (null == resourceMap && resourceMap.isEmpty()) {
+                return;
+            }
         }
         new Thread() {
             public void run() {
-                Iterator<String> typeItr = searchTypes.iterator();
-                String resType;
-                while (typeItr.hasNext()) {
-                    resType = typeItr.next();
-                    deleteResourcesByType(resType);
-
+                if (null == searchTypes || searchTypes.size() < 1) {
+                    synchronized (resourceMap) {
+                        // Stop observing all the resources
+                        Iterator<String> itr = resourceMap.keySet().iterator();
+                        while (itr.hasNext()) {
+                            sendCancelObserveRequest(
+                                    resourceMap.get(itr.next()), false);
+                        }
+                        // Delete all cached details of resources
+                        resourceMap.clear();
+                        favoriteResources.clear();
+                    }
                     // Change the current resource in selection
-                    updateCurrentResourceInSelection(searchTypes);
+                    setCurrentResourceInSelection(null);
+                    resourceSelectionChangedUINotification(null);
+                } else {
+                    Iterator<String> typeItr = searchTypes.iterator();
+                    String resType;
+                    while (typeItr.hasNext()) {
+                        resType = typeItr.next();
+                        deleteResourcesByType(resType);
+
+                        // Change the current resource in selection
+                        updateCurrentResourceInSelection(searchTypes);
+                    }
                 }
             }
         }.start();
@@ -1001,7 +1047,8 @@ public class ResourceManager {
         if (null == resourceInSelection) {
             return;
         }
-        List<String> typesOfSelection = resourceInSelection.getResourceTypes();
+        List<String> typesOfSelection = resourceInSelection
+                .getRemoteResourceRef().getResourceTypes();
         if (null == typesOfSelection || typesOfSelection.size() < 1) {
             return;
         }
@@ -1037,14 +1084,16 @@ public class ResourceManager {
                 if (null == resource) {
                     continue;
                 }
-                types = resource.getResourceTypes();
+                types = resource.getRemoteResourceRef().getResourceTypes();
                 if (null != types) {
                     exist = types.contains(resourceType);
                     if (exist) {
-                        // Remove the resource
-                        keyItr.remove();
+                        // Cancel observing the resource.
+                        sendCancelObserveRequest(resource, false);
                         // Remove the resource from favorites list.
                         removeResourceFromFavorites(resource);
+                        // Remove the resource
+                        keyItr.remove();
                     }
                 }
             }
@@ -1062,7 +1111,7 @@ public class ResourceManager {
         }.start();
     }
 
-    public List<MetaProperty> getMetaProperties(RemoteResource resource) {
+    public List<MetaProperty> getDefaultProperties(RemoteResource resource) {
         if (null != resource) {
             String propName;
             String propValue;
@@ -1072,22 +1121,26 @@ public class ResourceManager {
             for (int index = 0; index < Constants.META_PROPERTY_COUNT; index++) {
                 propName = Constants.META_PROPERTIES[index];
                 if (propName.equals(Constants.RESOURCE_URI)) {
-                    propValue = resource.getResourceURI();
+                    propValue = resource.getRemoteResourceRef().getURI();
                 } else if (propName.equals(Constants.CONNECTIVITY_TYPE)) {
-                    propValue = resource.getConnectivityType().toString();
+                    propValue = resource.getRemoteResourceRef()
+                            .getConnectivityType().toString();
+                } else if (propName.equals(Constants.ADDRESS)) {
+                    propValue = resource.getRemoteResourceRef().getHost();
                 } else if (propName.equals(Constants.OBSERVABLE)) {
                     propValue = Utility.getObservableInString(resource
-                            .isObservable());
-                    // see in UI
+                            .getRemoteResourceRef().isObservable());
                 } else if (propName.equals(Constants.RESOURCE_TYPES)) {
-                    List<String> types = resource.getResourceTypes();
+                    Vector<String> types = resource.getRemoteResourceRef()
+                            .getResourceTypes();
                     if (null != types) {
                         propValue = types.toString();
                     } else {
                         propValue = Constants.NOT_AVAILABLE;
                     }
                 } else if (propName.equals(Constants.RESOURCE_INTERFACES)) {
-                    List<String> interfaces = resource.getResourceInterfaces();
+                    Vector<String> interfaces = resource.getRemoteResourceRef()
+                            .getResourceInterfaces();
                     if (null != interfaces) {
                         propValue = interfaces.toString();
                     } else {
@@ -1106,6 +1159,84 @@ public class ResourceManager {
         return null;
     }
 
+    public List<MetaProperty> getDeviceProperties() {
+        if (null == devInfo) {
+            return null;
+        }
+
+        List<MetaProperty> metaProperties = new ArrayList<MetaProperty>();
+
+        metaProperties.add(new MetaProperty(Constants.DEVICE_ID, devInfo
+                .getID()));
+        metaProperties.add(new MetaProperty(Constants.DEVICE_NAME, devInfo
+                .getName()));
+        metaProperties.add(new MetaProperty(Constants.DEVICE_SPEC_VERSION,
+                devInfo.getSpecVersion()));
+        metaProperties.add(new MetaProperty(Constants.DEVICE_DMV_VERSION,
+                devInfo.getDataModelVersion()));
+
+        /*
+         * metaProperties.add(new MetaProperty(Constants.DEVICE_ID, ""));
+         * metaProperties.add(new MetaProperty(Constants.DEVICE_NAME, ""));
+         * metaProperties.add(new MetaProperty(Constants.DEVICE_SPEC_VERSION,
+         * "")); metaProperties.add(new
+         * MetaProperty(Constants.DEVICE_DMV_VERSION, ""));
+         */
+        return metaProperties;
+    }
+
+    public List<MetaProperty> getPlatformProperties() {
+        if (null == platInfo) {
+            return null;
+        }
+
+        List<MetaProperty> metaProperties = new ArrayList<MetaProperty>();
+
+        metaProperties.add(new MetaProperty(Constants.PLATFORM_ID, platInfo
+                .getPlatformID()));
+        metaProperties.add(new MetaProperty(Constants.PLATFORM_MANUFAC_NAME,
+                platInfo.getManufacturerName()));
+        metaProperties.add(new MetaProperty(Constants.PLATFORM_MANUFAC_URL,
+                platInfo.getManufacturerUrl()));
+        metaProperties.add(new MetaProperty(Constants.PLATFORM_MODEL_NO,
+                platInfo.getModelNumber()));
+        metaProperties.add(new MetaProperty(Constants.PLATFORM_DATE_OF_MANUFAC,
+                platInfo.getDateOfManufacture()));
+        metaProperties.add(new MetaProperty(Constants.PLATFORM_VERSION,
+                platInfo.getPlatformVersion()));
+        metaProperties.add(new MetaProperty(Constants.PLATFORM_OS_VERSION,
+                platInfo.getOperationSystemVersion()));
+        metaProperties.add(new MetaProperty(
+                Constants.PLATFORM_HARDWARE_VERSION, platInfo
+                        .getHardwareVersion()));
+        metaProperties.add(new MetaProperty(
+                Constants.PLATFORM_FIRMWARE_VERSION, platInfo
+                        .getFirmwareVersion()));
+        metaProperties.add(new MetaProperty(Constants.PLATFORM_SUPPORT_URL,
+                platInfo.getSupportUrl()));
+        metaProperties.add(new MetaProperty(Constants.PLATFORM_SYSTEM_TIME,
+                platInfo.getSystemTime()));
+
+        /*
+         * metaProperties.add(new MetaProperty(Constants.PLATFORM_ID, ""));
+         * metaProperties .add(new MetaProperty(Constants.PLATFORM_MANUFAC_NAME,
+         * "")); metaProperties .add(new
+         * MetaProperty(Constants.PLATFORM_MANUFAC_URL, ""));
+         * metaProperties.add(new MetaProperty(Constants.PLATFORM_MODEL_NO,
+         * "")); metaProperties.add(new
+         * MetaProperty(Constants.PLATFORM_DATE_OF_MANUFAC, ""));
+         * metaProperties.add(new MetaProperty(Constants.PLATFORM_VERSION, ""));
+         * metaProperties.add(new MetaProperty(Constants.PLATFORM_OS_VERSION,
+         * "")); metaProperties.add(new MetaProperty(
+         * Constants.PLATFORM_HARDWARE_VERSION, "")); metaProperties.add(new
+         * MetaProperty( Constants.PLATFORM_FIRMWARE_VERSION, ""));
+         * metaProperties .add(new MetaProperty(Constants.PLATFORM_SUPPORT_URL,
+         * "")); metaProperties .add(new
+         * MetaProperty(Constants.PLATFORM_SYSTEM_TIME, ""));
+         */
+        return metaProperties;
+    }
+
     public Map<String, Boolean> getAutomationStatus(RemoteResource resource) {
         if (null == resource) {
             return null;
@@ -1117,13 +1248,6 @@ public class ResourceManager {
         return autoStatus;
     }
 
-    public Map<String, String> getDummyAttributes() {
-        Map<String, String> attributes = new HashMap<String, String>();
-        attributes.put("intensity", "1");
-        attributes.put("power", "off");
-        return attributes;
-    }
-
     public List<RemoteResource> getResourceList() {
         List<RemoteResource> resourceList = new ArrayList<RemoteResource>();
         synchronized (resourceMap) {
@@ -1140,8 +1264,8 @@ public class ResourceManager {
         // Sort the list
         Collections.sort(resourceList, new Comparator<RemoteResource>() {
             public int compare(RemoteResource res1, RemoteResource res2) {
-                String s1 = res1.getResourceURI();
-                String s2 = res2.getResourceURI();
+                String s1 = res1.getRemoteResourceRef().getURI();
+                String s2 = res2.getRemoteResourceRef().getURI();
 
                 String s1Part = s1.replaceAll("\\d", "");
                 String s2Part = s2.replaceAll("\\d", "");
@@ -1170,18 +1294,140 @@ public class ResourceManager {
         return resourceList;
     }
 
-    public String getAttributeValue(RemoteResource res, String attName) {
-        if (null == res || null == attName) {
+    public List<String> getAllValuesOfAttribute(SimulatorResourceAttribute att) {
+        if (null == att) {
+            return null;
+        }
+
+        AttributeValue val = att.value();
+        if (null == val) {
+            return null;
+        }
+
+        List<String> values = new ArrayList<String>();
+
+        TypeInfo type = val.typeInfo();
+
+        AttributeProperty prop = att.property();
+        if (null == prop || prop.type().ordinal() == Type.UNKNOWN.ordinal()) {
+            values.add(Utility.getAttributeValueAsString(val));
+            return values;
+        }
+
+        Type valuesType = prop.type();
+
+        if (type.mType != ValueType.RESOURCEMODEL) {
+            if (type.mType == ValueType.ARRAY) {
+                if (type.mDepth == 1) {
+                    AttributeProperty childProp = prop.getChildProperty();
+                    if (null != childProp) {
+                        valuesType = childProp.type();
+                        if (valuesType.ordinal() == Type.RANGE.ordinal()) {
+                            List<String> list = getRangeForPrimitiveNonArrayAttributes(
+                                    childProp, type.mBaseType);
+                            if (null != list) {
+                                values.addAll(list);
+                            }
+                        } else if (valuesType.ordinal() == Type.VALUESET
+                                .ordinal()) {
+                            List<String> list = getAllowedValuesForPrimitiveNonArrayAttributes(
+                                    childProp.valueSet(), type.mBaseType);
+                            if (null != list) {
+                                values.addAll(list);
+                            }
+                        }
+                    }
+                }
+            } else {
+                if (valuesType.ordinal() == Type.RANGE.ordinal()) {
+                    List<String> list = getRangeForPrimitiveNonArrayAttributes(
+                            prop, type.mType);
+                    if (null != list) {
+                        values.addAll(list);
+                    }
+                } else if (valuesType.ordinal() == Type.VALUESET.ordinal()) {
+                    List<String> list = getAllowedValuesForPrimitiveNonArrayAttributes(
+                            prop.valueSet(), type.mType);
+                    if (null != list) {
+                        values.addAll(list);
+                    }
+                }
+            }
+        }
+
+        if (values.isEmpty()) {
+            values.add(Utility.getAttributeValueAsString(val));
+        }
+
+        return values;
+    }
+
+    public List<String> getRangeForPrimitiveNonArrayAttributes(
+            AttributeProperty prop, ValueType type) {
+        if (null == prop) {
+            return null;
+        }
+
+        if (type == ValueType.ARRAY || type == ValueType.RESOURCEMODEL) {
+            return null;
+        }
+
+        List<String> values = new ArrayList<String>();
+        switch (type) {
+            case INTEGER:
+                int min = (int) prop.min();
+                int max = (int) prop.max();
+                for (int iVal = min; iVal <= max; iVal++) {
+                    values.add(String.valueOf(iVal));
+                }
+                break;
+            case DOUBLE:
+                double minD = (double) prop.min();
+                double maxD = (double) prop.max();
+                for (double iVal = minD; iVal <= maxD; iVal = iVal + 1.0) {
+                    values.add(String.valueOf(iVal));
+                }
+                break;
+            default:
+        }
+        return values;
+    }
+
+    public List<String> getAllowedValuesForPrimitiveNonArrayAttributes(
+            AttributeValue[] attValues, ValueType type) {
+        if (null == attValues || attValues.length < 1) {
             return null;
         }
-        return res.getAttributeValue(attName);
+
+        if (type == ValueType.ARRAY || type == ValueType.RESOURCEMODEL) {
+            return null;
+        }
+
+        Object obj;
+        List<String> values = new ArrayList<String>();
+        for (AttributeValue val : attValues) {
+            if (null == val) {
+                continue;
+            }
+            obj = val.get();
+            if (null == obj) {
+                continue;
+            }
+            values.add(String.valueOf(obj));
+        }
+        return values;
     }
 
+    /*
+     * public String getAttributeValue(RemoteResource res, String attName) { if
+     * (null == res || null == attName) { return null; } return
+     * res.getAttributeValue(attName); }
+     */
     public void sendGetRequest(RemoteResource resource) {
         if (null == resource) {
             return;
         }
-        SimulatorRemoteResource resourceN = resource.getResource();
+        SimulatorRemoteResource resourceN = resource.getRemoteResourceRef();
         if (null == resourceN) {
             return;
         }
@@ -1191,263 +1437,132 @@ public class ResourceManager {
             Activator
                     .getDefault()
                     .getLogManager()
-                    .log(Level.ERROR.ordinal(),
-                            new Date(),
-                            "[" + e.getClass().getSimpleName() + "]"
-                                    + e.code().toString() + "-" + e.message());
+                    .log(Level.ERROR.ordinal(), new Date(),
+                            Utility.getSimulatorErrorString(e, null));
         }
     }
 
     public void sendPutRequest(RemoteResource resource,
-            List<PutPostAttributeModel> putPostModelList) {
-        System.out.println(putPostModelList);
-        System.out.println("ResourceManager: sendPutRequest");
-        if (null == resource) {
+            SimulatorResourceModel model) {
+        if (null == resource || null == model) {
             return;
         }
-        System.out.println("ResourceManager: resource not null");
-        SimulatorRemoteResource resourceN = resource.getResource();
+        SimulatorRemoteResource resourceN = resource.getRemoteResourceRef();
         if (null == resourceN) {
             return;
         }
-        System.out.println("ResourceManager: Native resource not null");
-        Map<String, RemoteResourceAttribute> attMap = resource
-                .getResourceAttributesMap();
-        if (null == attMap || attMap.size() < 1) {
-            return;
-        }
-        System.out.println("ResourceManager: attrubutes obtained");
-        SimulatorResourceModel resourceModel = getUpdatedResourceModel(attMap,
-                putPostModelList);
-        System.out.println("ResourceModel exist?:" + (resourceModel != null));
         try {
-            resourceN.put(resourceModel, null, putListener);
-        } catch (SimulatorException e) {
+            resourceN.put(null, model, putListener);
+        } catch (Exception e) {
+            String addlInfo;
+            addlInfo = "Invalid Attribute Value. Cannot send PUT request.";
             Activator
                     .getDefault()
                     .getLogManager()
-                    .log(Level.ERROR.ordinal(),
-                            new Date(),
-                            "[" + e.getClass().getSimpleName() + "]"
-                                    + e.code().toString() + "-" + e.message());
+                    .log(Level.ERROR.ordinal(), new Date(),
+                            Utility.getSimulatorErrorString(e, addlInfo));
         }
-        System.out.println("ResourceManager: called native put");
     }
 
     public void sendPostRequest(RemoteResource resource,
-            List<PutPostAttributeModel> putPostModelList) {
-        System.out.println(putPostModelList);
-        if (null == resource) {
+            SimulatorResourceModel model) {
+        if (null == resource || null == model) {
             return;
         }
-        SimulatorRemoteResource resourceN = resource.getResource();
+        SimulatorRemoteResource resourceN = resource.getRemoteResourceRef();
         if (null == resourceN) {
             return;
         }
-        Map<String, RemoteResourceAttribute> attMap = resource
-                .getResourceAttributesMap();
-        if (null == attMap || attMap.size() < 1) {
-            return;
-        }
-        // Filter out the attributes whose modification status is true.
-        Iterator<PutPostAttributeModel> itr = putPostModelList.iterator();
-        PutPostAttributeModel model;
-        while (itr.hasNext()) {
-            model = itr.next();
-            if (!model.isModified()) {
-                itr.remove();
-            }
-        }
-        SimulatorResourceModel resourceModel = getUpdatedResourceModel(attMap,
-                putPostModelList);
         try {
-            resourceN.post(resourceModel, null, postListener);
-        } catch (SimulatorException e) {
+            resourceN.post(null, model, postListener);
+        } catch (Exception e) {
+            String addlInfo;
+            addlInfo = "Invalid Attribute Value. Cannot send POST request.";
             Activator
                     .getDefault()
                     .getLogManager()
-                    .log(Level.ERROR.ordinal(),
-                            new Date(),
-                            "[" + e.getClass().getSimpleName() + "]"
-                                    + e.code().toString() + "-" + e.message());
-        }
-    }
-
-    private SimulatorResourceModel getUpdatedResourceModel(
-            Map<String, RemoteResourceAttribute> attMap,
-            List<PutPostAttributeModel> putPostModelList) {
-        String attName;
-        SimulatorResourceModel resourceModel = new SimulatorResourceModel();
-        PutPostAttributeModel model;
-        RemoteResourceAttribute attribute;
-        Type attType;
-        Iterator<PutPostAttributeModel> itr = putPostModelList.iterator();
-        while (itr.hasNext()) {
-            model = itr.next();
-            attName = model.getAttName();
-            attribute = attMap.get(attName);
-            if (null == attribute) {
-                continue;
-            }
-            attType = attribute.getAttValBaseType();
-            if (attType == Type.INT) {
-                int attValue;
-                try {
-                    attValue = Integer.parseInt(model.getAttValue());
-                    resourceModel.addAttributeInt(attName, attValue);
-                } catch (NumberFormatException e) {
-                    Activator
-                            .getDefault()
-                            .getLogManager()
-                            .log(Level.ERROR.ordinal(), new Date(),
-                                    e.getMessage());
-                } catch (SimulatorException e) {
-                    Activator
-                            .getDefault()
-                            .getLogManager()
-                            .log(Level.ERROR.ordinal(),
-                                    new Date(),
-                                    "[" + e.getClass().getSimpleName() + "]"
-                                            + e.code().toString() + "-"
-                                            + e.message());
-                }
-            } else if (attType == Type.DOUBLE) {
-                double attValue;
-                try {
-                    attValue = Double.parseDouble(model.getAttValue());
-                    resourceModel.addAttributeDouble(attName, attValue);
-                } catch (NumberFormatException e) {
-                    Activator
-                            .getDefault()
-                            .getLogManager()
-                            .log(Level.ERROR.ordinal(), new Date(),
-                                    e.getMessage());
-                } catch (SimulatorException e) {
-                    Activator
-                            .getDefault()
-                            .getLogManager()
-                            .log(Level.ERROR.ordinal(),
-                                    new Date(),
-                                    "[" + e.getClass().getSimpleName() + "]"
-                                            + e.code().toString() + "-"
-                                            + e.message());
-                }
-            } else if (attType == Type.BOOL) {
-                boolean attValue;
-                attValue = Boolean.parseBoolean(model.getAttValue());
-                try {
-                    resourceModel.addAttributeBoolean(attName, attValue);
-                } catch (SimulatorException e) {
-                    Activator
-                            .getDefault()
-                            .getLogManager()
-                            .log(Level.ERROR.ordinal(),
-                                    new Date(),
-                                    "[" + e.getClass().getSimpleName() + "]"
-                                            + e.code().toString() + "-"
-                                            + e.message());
-                }
-            } else if (attType == Type.STRING) {
-                String attValue;
-                attValue = model.getAttValue();
-                try {
-                    resourceModel.addAttributeString(attName, attValue);
-                } catch (SimulatorException e) {
-                    Activator
-                            .getDefault()
-                            .getLogManager()
-                            .log(Level.ERROR.ordinal(),
-                                    new Date(),
-                                    "[" + e.getClass().getSimpleName() + "]"
-                                            + e.code().toString() + "-"
-                                            + e.message());
-                }
-            }
+                    .log(Level.ERROR.ordinal(), new Date(),
+                            Utility.getSimulatorErrorString(e, addlInfo));
         }
-        return resourceModel;
     }
 
-    public void sendObserveRequest(RemoteResource resource) {
-        System.out.println("sendObserverRequest() entry");
+    public boolean sendObserveRequest(RemoteResource resource) {
         if (null == resource) {
-            return;
+            return false;
         }
-        System.out.println("Resource is null:" + (resource == null));
-        resource.setObserved(true);
-        SimulatorRemoteResource resourceN = resource.getResource();
+        SimulatorRemoteResource resourceN = resource.getRemoteResourceRef();
         if (null == resourceN) {
-            return;
+            return false;
         }
         try {
-            resourceN.startObserve(SimulatorObserveType.OBSERVE, null,
-                    observeListener);
+            resourceN.startObserve(null, observeListener);
+            resource.setObserved(true);
             // Add observed resource URI to show the proper status after every
             // find/refresh operations.
-            addObservedResourceURI(resource.getResourceURI());
+            addObservedResourceURI(resource.getRemoteResourceRef().getURI());
         } catch (SimulatorException e) {
             Activator
                     .getDefault()
                     .getLogManager()
-                    .log(Level.ERROR.ordinal(),
-                            new Date(),
-                            "[" + e.getClass().getSimpleName() + "]"
-                                    + e.code().toString() + "-" + e.message());
+                    .log(Level.ERROR.ordinal(), new Date(),
+                            Utility.getSimulatorErrorString(e, null));
+            return false;
         }
-        System.out.println("Observer called.");
+        return true;
     }
 
-    public void sendCancelObserveRequest(RemoteResource resource) {
-        if (null == resource) {
-            return;
+    public boolean sendCancelObserveRequest(RemoteResource resource,
+            boolean removeEntry) {
+        if (null == resource || !resource.isObserved()) {
+            return false;
         }
-        resource.setObserved(false);
-        SimulatorRemoteResource resourceN = resource.getResource();
+        SimulatorRemoteResource resourceN = resource.getRemoteResourceRef();
         if (null == resourceN) {
-            return;
+            return false;
         }
         try {
             resourceN.stopObserve();
+            resource.setObserved(false);
             // Remove observed resource URI to show the proper status after
             // every find/refresh operations.
-            removeObservedResourceURI(resource.getResourceURI());
+            if (removeEntry)
+                removeObservedResourceURI(resource.getRemoteResourceRef()
+                        .getURI());
         } catch (SimulatorException e) {
             Activator
                     .getDefault()
                     .getLogManager()
-                    .log(Level.ERROR.ordinal(),
-                            new Date(),
-                            "[" + e.getClass().getSimpleName() + "]"
-                                    + e.code().toString() + "-" + e.message());
+                    .log(Level.ERROR.ordinal(), new Date(),
+                            Utility.getSimulatorErrorString(e, null));
+            return false;
         }
+        return true;
     }
 
-    public void startAutomationRequest(int reqType, RemoteResource resource) {
+    public void startAutomationRequest(VerificationType reqType,
+            RemoteResource resource) {
         if (null == resource) {
             return;
         }
-        SimulatorRemoteResource resourceN = resource.getResource();
+        SimulatorRemoteResource resourceN = resource.getRemoteResourceRef();
         if (null == resourceN) {
             return;
         }
-        SimulatorVerificationType type = SimulatorVerificationType
-                .getVerificationType(reqType);
-        if (null == type) {
+        if (null == reqType) {
             return;
         }
-        System.out.println("Before calling startVerification: " + reqType);
         int autoId;
         try {
-            autoId = resourceN.startVerification(type, verifyListener);
-            System.out.println("After calling startVerification: " + autoId);
+            autoId = resourceN.startVerification(reqType, verifyListener);
             if (autoId != -1) {
-                if (reqType == Constants.GET_AUTOMATION_INDEX) {
+                if (reqType == VerificationType.GET) {
                     // resource.setGetAutomtnInProgress(true);
                     resource.setGetAutomtnId(autoId);
-                } else if (reqType == Constants.PUT_AUTOMATION_INDEX) {
+                } else if (reqType == VerificationType.PUT) {
                     // resource.setPutAutomtnInProgress(true);
                     resource.setPutAutomtnId(autoId);
                 } else {// if(reqType == Constants.POST_AUTOMATION_INDEX) {
-                        // resource.setPostAutomtnInProgress(true);
+                    // resource.setPostAutomtnInProgress(true);
                     resource.setPostAutomtnId(autoId);
                 }
             }
@@ -1455,26 +1570,25 @@ public class ResourceManager {
             Activator
                     .getDefault()
                     .getLogManager()
-                    .log(Level.ERROR.ordinal(),
-                            new Date(),
-                            "[" + e.getClass().getSimpleName() + "]"
-                                    + e.code().toString() + "-" + e.message());
+                    .log(Level.ERROR.ordinal(), new Date(),
+                            Utility.getSimulatorErrorString(e, null));
         }
     }
 
-    public void stopAutomationRequest(int reqType, RemoteResource resource) {
+    public void stopAutomationRequest(VerificationType reqType,
+            RemoteResource resource) {
         if (null == resource) {
             return;
         }
-        SimulatorRemoteResource resourceN = resource.getResource();
+        SimulatorRemoteResource resourceN = resource.getRemoteResourceRef();
         if (null == resourceN) {
             return;
         }
         int autoId;
-        if (reqType == Constants.GET_AUTOMATION_INDEX) {
+        if (reqType == VerificationType.GET) {
             resource.setGetAutomtnInProgress(false);
             autoId = resource.getGetAutomtnId();
-        } else if (reqType == Constants.PUT_AUTOMATION_INDEX) {
+        } else if (reqType == VerificationType.PUT) {
             resource.setPutAutomtnInProgress(false);
             autoId = resource.getPutAutomtnId();
         } else {// if(reqType == Constants.POST_AUTOMATION_INDEX) {
@@ -1483,74 +1597,55 @@ public class ResourceManager {
         }
         try {
             resourceN.stopVerification(autoId);
-        } catch (InvalidArgsException e) {
-            Activator
-            .getDefault()
-            .getLogManager()
-            .log(Level.ERROR.ordinal(),
-                    new Date(),
-                    "[" + e.getClass().getSimpleName() + "]"
-                            + e.code().toString() + "-"
-                            + e.message());
-            return;
         } catch (SimulatorException e) {
             Activator
                     .getDefault()
                     .getLogManager()
-                    .log(Level.ERROR.ordinal(),
-                            new Date(),
-                            "[" + e.getClass().getSimpleName() + "]"
-                                    + e.code().toString() + "-" + e.message());
+                    .log(Level.ERROR.ordinal(), new Date(),
+                            Utility.getSimulatorErrorString(e, null));
         }
     }
 
-    public void setConfigFilePath(RemoteResource resource, String configFilePath) {
+    public boolean setConfigFilePath(RemoteResource resource,
+            String configFilePath) throws SimulatorException {
         if (null == resource) {
-            return;
+            return false;
         }
-        SimulatorRemoteResource resourceN = resource.getResource();
+        SimulatorRemoteResource resourceN = resource.getRemoteResourceRef();
         if (null == resourceN) {
-            return;
+            return false;
         }
         try {
-            resourceN.setConfigInfo(configFilePath);
+            SimulatorResourceModel configuredResourceModel;
+            configuredResourceModel = resourceN.setConfigInfo(configFilePath);
+            if (null == configuredResourceModel) {
+                return false;
+            }
+
+            // Store the resource model in the local cache
+            SimulatorResourceModel resourceModel = resource
+                    .getResourceModelRef();
+            if (null != resourceModel) {
+                configuredResourceModel.update(resourceModel);
+            }
+            resource.setResourceModelRef(configuredResourceModel);
         } catch (SimulatorException e) {
             Activator
                     .getDefault()
                     .getLogManager()
-                    .log(Level.ERROR.ordinal(),
-                            new Date(),
-                            "[" + e.getClass().getSimpleName() + "]"
-                                    + e.code().toString() + "-" + e.message());
-            return;
+                    .log(Level.ERROR.ordinal(), new Date(),
+                            Utility.getSimulatorErrorString(e, null));
+            throw e;
         }
         // Update the status
         resource.setConfigUploaded(true);
 
         // Notify the UI listeners
         configUploadedNotification(resource);
-    }
-
-    public Image getImage(String resourceURI) {
-        if (null == resourceURI) {
-            return null;
-        }
-        URL url = Activator.getDefault().getBundle()
-                .getEntry(getImageURL(resourceURI));
-        if (null == url) {
-            return null;
-        }
-        return ImageDescriptor.createFromURL(url).createImage();
-    }
 
-    private String getImageURL(String resourceURI) {
-        // TODO: Hard-coding the image file name temporarily.
-        // It will be included in a separate class which manages all image
-        // resources
-        return "/icons/light_16x16.png";
+        return true;
     }
 
     public void shutdown() {
-        // TODO: To be implemented for clean-up activities.
     }
 }