Integrated resource model related changes with eclipse plug-ins.
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ServiceProviderPlugin / src / oic / simulator / serviceprovider / manager / ResourceManager.java
index a58e428..3d22bd7 100644 (file)
@@ -19,6 +19,7 @@ package oic.simulator.serviceprovider.manager;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
@@ -28,8 +29,6 @@ import java.util.Vector;
 
 import oic.simulator.serviceprovider.Activator;
 import oic.simulator.serviceprovider.model.AttributeElement;
-import oic.simulator.serviceprovider.model.CollectionResource;
-import oic.simulator.serviceprovider.model.Device;
 import oic.simulator.serviceprovider.model.MetaProperty;
 import oic.simulator.serviceprovider.model.Resource;
 import oic.simulator.serviceprovider.model.ResourceType;
@@ -37,22 +36,27 @@ import oic.simulator.serviceprovider.model.SingleResource;
 import oic.simulator.serviceprovider.utils.Constants;
 import oic.simulator.serviceprovider.utils.Utility;
 
+import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.swt.widgets.Display;
+import org.oic.simulator.ArrayProperty;
 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.BooleanProperty;
 import org.oic.simulator.DeviceInfo;
 import org.oic.simulator.DeviceListener;
+import org.oic.simulator.DoubleProperty;
 import org.oic.simulator.ILogger.Level;
+import org.oic.simulator.IntegerProperty;
 import org.oic.simulator.PlatformInfo;
 import org.oic.simulator.SimulatorException;
 import org.oic.simulator.SimulatorManager;
 import org.oic.simulator.SimulatorResourceAttribute;
 import org.oic.simulator.SimulatorResourceModel;
+import org.oic.simulator.StringProperty;
 import org.oic.simulator.server.Observer;
-import org.oic.simulator.server.SimulatorCollectionResource;
 import org.oic.simulator.server.SimulatorResource;
 import org.oic.simulator.server.SimulatorResource.AutoUpdateListener;
 import org.oic.simulator.server.SimulatorResource.AutoUpdateType;
@@ -73,8 +77,6 @@ public class ResourceManager {
 
     private Resource                       currentResourceInSelection;
 
-    private Device                         currentDeviceInSelection;
-
     private ResourceModelChangeListener    resourceModelChangeListener;
 
     private AutoUpdateListener             automationListener;
@@ -95,44 +97,6 @@ public class ResourceManager {
     public ResourceManager() {
         data = new Data();
 
-        // Set the default device and platform information
-        deviceName = "IoTivity Simulator";
-        try {
-            SimulatorManager.setDeviceInfo(deviceName);
-        } catch (SimulatorException e) {
-            Activator
-                    .getDefault()
-                    .getLogManager()
-                    .log(Level.ERROR.ordinal(),
-                            new Date(),
-                            "Error while registering the device info.\n"
-                                    + Utility.getSimulatorErrorString(e, null));
-        }
-
-        platformInfo = new PlatformInfo();
-        platformInfo.setPlatformID("Samsung Platform Identifier");
-        platformInfo.setManufacturerName("Samsung");
-        platformInfo.setManufacturerUrl("www.samsung.com");
-        platformInfo.setModelNumber("Samsung Model Num01");
-        platformInfo.setDateOfManufacture("2015-09-10T11:10:30Z");
-        platformInfo.setPlatformVersion("PlatformVersion01");
-        platformInfo.setOperationSystemVersion("OSVersion01");
-        platformInfo.setHardwareVersion("HardwareVersion01");
-        platformInfo.setFirmwareVersion("FirwareVersion01");
-        platformInfo.setSupportUrl("http://www.samsung.com/support");
-        platformInfo.setSystemTime("2015-09-10T11:10:30Z");
-        try {
-            SimulatorManager.setPlatformInfo(platformInfo);
-        } catch (SimulatorException e) {
-            Activator
-                    .getDefault()
-                    .getLogManager()
-                    .log(Level.ERROR.ordinal(),
-                            new Date(),
-                            "Error while registering the platform info.\n"
-                                    + Utility.getSimulatorErrorString(e, null));
-        }
-
         deviceListener = new DeviceListener() {
 
             @Override
@@ -161,19 +125,6 @@ public class ResourceManager {
             }
         };
 
-        // Get the device information to show other details of the device in UI.
-        try {
-            SimulatorManager.findDevices("", deviceListener);
-        } catch (SimulatorException e) {
-            Activator
-                    .getDefault()
-                    .getLogManager()
-                    .log(Level.ERROR.ordinal(),
-                            new Date(),
-                            "Failed to get the local device information.\n"
-                                    + Utility.getSimulatorErrorString(e, null));
-        }
-
         resourceModelChangeListener = new ResourceModelChangeListener() {
 
             @Override
@@ -194,7 +145,7 @@ public class ResourceManager {
                                         .getResourceByURI(resourceURI);
                                 if (null != resource) {
                                     try {
-                                        resource.setResourceRepresentation(resourceModelN);
+                                        resource.updateResourceRepresentation(resourceModelN);
                                     } catch (NumberFormatException e) {
                                         Activator
                                                 .getDefault()
@@ -297,6 +248,58 @@ public class ResourceManager {
         threadHandle = new Thread(synchronizerThread);
         threadHandle.setName("Simulator service provider event queue");
         threadHandle.start();
+
+        // Set the default device name.
+        deviceName = "IoTivity Simulator";
+        try {
+            SimulatorManager.setDeviceInfo(deviceName);
+        } catch (SimulatorException e) {
+            Activator
+                    .getDefault()
+                    .getLogManager()
+                    .log(Level.ERROR.ordinal(),
+                            new Date(),
+                            "Error while registering the device info.\n"
+                                    + Utility.getSimulatorErrorString(e, null));
+        }
+
+        // Set the default platform information.
+        platformInfo = new PlatformInfo();
+        platformInfo.setPlatformID("Samsung Platform Identifier");
+        platformInfo.setManufacturerName("Samsung");
+        platformInfo.setManufacturerUrl("www.samsung.com");
+        platformInfo.setModelNumber("Samsung Model Num01");
+        platformInfo.setDateOfManufacture("2015-09-10T11:10:30Z");
+        platformInfo.setPlatformVersion("PlatformVersion01");
+        platformInfo.setOperationSystemVersion("OSVersion01");
+        platformInfo.setHardwareVersion("HardwareVersion01");
+        platformInfo.setFirmwareVersion("FirwareVersion01");
+        platformInfo.setSupportUrl("http://www.samsung.com/support");
+        platformInfo.setSystemTime("2015-09-10T11:10:30Z");
+        try {
+            SimulatorManager.setPlatformInfo(platformInfo);
+        } catch (SimulatorException e) {
+            Activator
+                    .getDefault()
+                    .getLogManager()
+                    .log(Level.ERROR.ordinal(),
+                            new Date(),
+                            "Error while registering the platform info.\n"
+                                    + Utility.getSimulatorErrorString(e, null));
+        }
+
+        // Get the device information to show other details of the device in UI.
+        try {
+            SimulatorManager.findDevices("", deviceListener);
+        } catch (SimulatorException e) {
+            Activator
+                    .getDefault()
+                    .getLogManager()
+                    .log(Level.ERROR.ordinal(),
+                            new Date(),
+                            "Failed to get the local device information.\n"
+                                    + Utility.getSimulatorErrorString(e, null));
+        }
     }
 
     private static class NotificationSynchronizerThread implements Runnable {
@@ -517,14 +520,6 @@ public class ResourceManager {
         this.currentResourceInSelection = resource;
     }
 
-    public synchronized Device getCurrentDeviceInSelection() {
-        return currentDeviceInSelection;
-    }
-
-    public synchronized void setCurrentDeviceInSelection(Device dev) {
-        this.currentDeviceInSelection = dev;
-    }
-
     public boolean isResourceExist(String resourceURI) {
         return data.isResourceExist(resourceURI);
     }
@@ -539,13 +534,14 @@ public class ResourceManager {
         if (null == resource) {
             return false;
         }
-        String resType = (String) resource.getResourceTypes().toArray()[0];
+
         try {
-            // 1. Create the resource.
+            // Create the resource.
             SimulatorResource jSimulatorResource = SimulatorManager
                     .createResource(SimulatorResource.Type.SINGLE,
                             resource.getResourceName(),
-                            resource.getResourceURI(), resType);
+                            resource.getResourceURI(),
+                            resource.getResourceType());
             if (null == jSimulatorResource
                     || !(jSimulatorResource instanceof SimulatorSingleResource)) {
                 return false;
@@ -553,21 +549,26 @@ public class ResourceManager {
             SimulatorSingleResource jSimulatorSingleResource = (SimulatorSingleResource) jSimulatorResource;
             resource.setSimulatorResource(jSimulatorSingleResource);
 
-            // 2. Cancel observable property if requested by user.
+            // Cancel discoverable property if requested by user.
+            if (!resource.isDiscoverable()) {
+                jSimulatorSingleResource.setDiscoverable(false);
+            }
+
+            // Cancel observable property if requested by user.
             if (!resource.isObservable()) {
                 jSimulatorSingleResource.setObservable(false);
             }
 
-            // 3. Set the model change listener.
+            // Set the model change listener.
             jSimulatorSingleResource
                     .setResourceModelChangeListener(resourceModelChangeListener);
 
-            // 4. Set the observer listener if the resource is observable.
+            // Set the observer listener if the resource is observable.
             if (resource.isObservable()) {
                 jSimulatorSingleResource.setObserverListener(observer);
             }
 
-            // 5. Add attributes.
+            // Add attributes.
             if (null != attributes && !attributes.isEmpty()) {
                 SimulatorResourceAttribute value;
                 for (Map.Entry<String, SimulatorResourceAttribute> entry : attributes
@@ -577,14 +578,20 @@ public class ResourceManager {
                         jSimulatorSingleResource.addAttribute(value);
                 }
 
-                // 6. Get the resource model java object reference.
+                // Get the resource model java object reference.
                 resource.setResourceModel(jSimulatorSingleResource
                         .getResourceModel());
 
-                resource.setResourceRepresentation(resource.getResourceModel());
+                resource.createResourceRepresentation(jSimulatorSingleResource
+                        .getAttributes());
             }
 
-            // 6. Register the resource with the platform.
+            // Set the resource interfaces.
+            jSimulatorSingleResource
+                    .setInterface(Utility.convertSetToVectorString(resource
+                            .getResourceInterfaces()));
+
+            // Register the resource with the platform.
             jSimulatorSingleResource.start();
             resource.setStarted(true);
         } catch (SimulatorException e) {
@@ -596,80 +603,21 @@ public class ResourceManager {
             throw e;
         }
 
-        // 8. Add to local cache.
+        // Add to local cache.
         data.addResource(resource);
 
-        // 9. Update UI listeners
+        // Update UI listeners
         UiListenerHandler.getInstance().resourceCreatedUINotification(
                 ResourceType.SINGLE);
 
         return true;
     }
 
-    public boolean createCollectionResource(CollectionResource resource)
-            throws SimulatorException {
-        if (null == resource) {
-            return false;
-        }
-        String resType = (String) resource.getResourceTypes().toArray()[0];
-        try {
-            // 1. Create the resource.
-            SimulatorResource jSimulatorResource = SimulatorManager
-                    .createResource(SimulatorResource.Type.COLLECTION,
-                            resource.getResourceName(),
-                            resource.getResourceURI(), resType);
-            if (null == jSimulatorResource
-                    || !(jSimulatorResource instanceof SimulatorCollectionResource)) {
-                return false;
-            }
-            SimulatorCollectionResource jSimulatorCollectionResource = (SimulatorCollectionResource) jSimulatorResource;
-            resource.setSimulatorResource(jSimulatorCollectionResource);
-
-            // 2. Cancel observable property if requested by user.
-            if (!resource.isObservable()) {
-                jSimulatorCollectionResource.setObservable(false);
-            }
-
-            // 3. Set the observer listener if the resource is observable.
-            if (resource.isObservable()) {
-                jSimulatorCollectionResource.setObserverListener(observer);
-            }
-
-            // 4. Set the model change listener.
-            jSimulatorCollectionResource
-                    .setResourceModelChangeListener(resourceModelChangeListener);
-
-            // 5. Fetch the model and attributes.
-            resource.setResourceRepresentation(jSimulatorCollectionResource
-                    .getResourceModel());
-
-            // 6. Register the resource with the platform.
-            jSimulatorCollectionResource.start();
-            resource.setStarted(true);
-        } catch (SimulatorException e) {
-            Activator
-                    .getDefault()
-                    .getLogManager()
-                    .log(Level.ERROR.ordinal(), new Date(),
-                            Utility.getSimulatorErrorString(e, null));
-            throw e;
-        }
-
-        // 6. Add to local cache.
-        data.addResource(resource);
-
-        // 7. Update UI listeners
-        UiListenerHandler.getInstance().resourceCreatedUINotification(
-                ResourceType.COLLECTION);
-
-        return true;
-    }
-
     public Resource createResourceByRAML(String configFilePath)
             throws SimulatorException {
         Resource resource = null;
         try {
-            // 1. Create the resource
+            // Create the resource
             SimulatorResource jSimulatorResource = SimulatorManager
                     .createResource(configFilePath);
             if (null == jSimulatorResource) {
@@ -678,11 +626,11 @@ public class ResourceManager {
             if (jSimulatorResource instanceof SimulatorSingleResource) {
                 resource = new SingleResource();
             } else {
-                resource = new CollectionResource();
+                return null;
             }
             resource.setSimulatorResource(jSimulatorResource);
 
-            // 2. Fetch and locally store the resource name and uri.
+            // Fetch and locally store the resource name and uri.
             String uri = jSimulatorResource.getURI();
             if (null == uri || uri.trim().isEmpty()) {
                 return null;
@@ -727,7 +675,7 @@ public class ResourceManager {
                 return false;
             }
 
-            // 1. Update resource URI and Name if they are changed.
+            // Update resource URI and Name if they are changed.
             String newUri = uri.trim();
             String newName = name.trim();
 
@@ -745,17 +693,17 @@ public class ResourceManager {
                 }
             }
 
-            // 2. Set the model change listener.
+            // Set the model change listener.
             jSimulatorSingleResource
                     .setResourceModelChangeListener(resourceModelChangeListener);
 
-            // 3. Set the observer listener if the resource is observable.
+            // Set the observer listener if the resource is observable.
             if (jSimulatorSingleResource.isObservable()) {
                 jSimulatorSingleResource.setObserverListener(observer);
                 singleRes.setObservable(true);
             }
 
-            // 4. Fetch the resource model.
+            // Fetch the resource model.
             SimulatorResourceModel jResModel = jSimulatorSingleResource
                     .getResourceModel();
             if (null == jResModel) {
@@ -763,25 +711,26 @@ public class ResourceManager {
             }
             singleRes.setResourceModel(jResModel);
 
-            // 5. Fetch the basic details of the resource.
-            singleRes.addResourceType(jSimulatorSingleResource
+            // Fetch the basic details of the resource.
+            singleRes.setResourceType(jSimulatorSingleResource
                     .getResourceType());
             singleRes
                     .setResourceInterfaces(Utility
                             .convertVectorToSet(jSimulatorSingleResource
                                     .getInterface()));
 
-            // 6. Fetch the resource attributes.
-            singleRes.setResourceRepresentation(jResModel);
+            // Fetch the resource attributes.
+            singleRes.createResourceRepresentation(jSimulatorSingleResource
+                    .getAttributes());
 
-            // 7. Register the resource with the platform.
+            // Register the resource with the platform.
             jSimulatorSingleResource.start();
             singleRes.setStarted(true);
 
-            // 8. Add to local cache.
+            // Add to local cache.
             data.addResource(singleRes);
 
-            // 9. Update UI listeners for single instance creation
+            // Update UI listeners for single instance creation
             if (!multiInstance)
                 UiListenerHandler.getInstance().resourceCreatedUINotification(
                         ResourceType.SINGLE);
@@ -796,105 +745,28 @@ public class ResourceManager {
         return true;
     }
 
-    /**
-     * This method can set/change the resource uri and name of an already
-     * created resource which is not yet registered with the platform. This
-     * method registers the model change and observer listeners, registers the
-     * resource, fetches the resource attributes, updates the local cache and
-     * notifies the UI listeners.
-     */
-    public boolean completeCollectionResourceCreationByRAML(Resource resource,
-            String uri, String name) throws SimulatorException {
-        if (null == resource || !(resource instanceof CollectionResource)) {
-            return false;
-        }
-
-        CollectionResource collectionRes = (CollectionResource) resource;
-
-        SimulatorCollectionResource jSimulatorCollectionResource = null;
-
-        try {
-            jSimulatorCollectionResource = (SimulatorCollectionResource) resource
-                    .getSimulatorResource();
-            if (null == jSimulatorCollectionResource) {
-                return false;
-            }
-
-            // 1. Update resource URI and Name if they are changed.
-            String newUri = uri.trim();
-            String newName = name.trim();
-
-            if (!collectionRes.getResourceURI().equals(newUri)) {
-                jSimulatorCollectionResource.setURI(newUri);
-                collectionRes.setResourceURI(newUri);
-            }
-            if (!collectionRes.getResourceName().equals(newName)) {
-                jSimulatorCollectionResource.setName(newName);
-                collectionRes.setResourceName(newName);
-            }
-
-            // 2. Set the model change listener.
-            jSimulatorCollectionResource
-                    .setResourceModelChangeListener(resourceModelChangeListener);
-
-            // 3. Fetch the resource model.
-            SimulatorResourceModel jResModel = jSimulatorCollectionResource
-                    .getResourceModel();
-            if (null == jResModel) {
-                return false;
-            }
-            collectionRes.setResourceModel(jResModel);
-
-            // 4. Fetch the basic details of the resource.
-            collectionRes.addResourceType(jSimulatorCollectionResource
-                    .getResourceType());
-            collectionRes.setResourceInterfaces(Utility
-                    .convertVectorToSet(jSimulatorCollectionResource
-                            .getInterface()));
-
-            // 5. Set the observer listener if the resource is observable.
-            if (jSimulatorCollectionResource.isObservable()) {
-                jSimulatorCollectionResource.setObserverListener(observer);
-                collectionRes.setObservable(true);
-            }
-
-            // 6. Fetch the resource attributes.
-            collectionRes.setResourceRepresentation(jResModel);
-
-            // 7. Register the resource with the platform.
-            jSimulatorCollectionResource.start();
-            collectionRes.setStarted(true);
-
-            // 8. Add to local cache.
-            data.addResource(collectionRes);
-
-            // 9. Update UI listeners for single instance creation
-            UiListenerHandler.getInstance().resourceCreatedUINotification(
-                    ResourceType.COLLECTION);
-        } catch (Exception e) {
-            Activator
-                    .getDefault()
-                    .getLogManager()
-                    .log(Level.ERROR.ordinal(), new Date(),
-                            Utility.getSimulatorErrorString(e, null));
-            throw e;
-        }
-        return true;
-    }
-
-    public int createSingleResourceMultiInstances(String configFile, int count)
+    public Set<SingleResource> createSingleResourceMultiInstances(
+            String configFile, int count, IProgressMonitor progressMonitor)
             throws SimulatorException {
-        int createCount = 0;
+        Set<SingleResource> resultSet;
         try {
+            resultSet = new HashSet<SingleResource>();
             Vector<SimulatorResource> jSimulatorResources = SimulatorManager
                     .createResource(configFile, count);
             if (null == jSimulatorResources || jSimulatorResources.size() < 1) {
-                return 0;
+                return null;
             }
             SimulatorSingleResource jResource;
             SingleResource resource;
             boolean result;
             for (SimulatorResource jSimulatorResource : jSimulatorResources) {
+                // If the resource creation progress is canceled, then stop the
+                // creation and stop/delete
+                // the resources created already.
+                if (progressMonitor.isCanceled()) {
+                    removeSingleResources(resultSet);
+                    return null;
+                }
                 jResource = (SimulatorSingleResource) jSimulatorResource;
                 resource = new SingleResource();
                 resource.setSimulatorResource(jResource);
@@ -902,7 +774,7 @@ public class ResourceManager {
                     result = completeSingleResourceCreationByRAML(resource,
                             jResource.getURI(), jResource.getName(), true);
                     if (result) {
-                        createCount++;
+                        resultSet.add(resource);
                     }
                 } catch (SimulatorException eInner) {
                     Activator
@@ -913,10 +785,7 @@ public class ResourceManager {
                                     Utility.getSimulatorErrorString(eInner,
                                             null));
                 }
-            }
-            if (createCount > 0) {
-                UiListenerHandler.getInstance().resourceCreatedUINotification(
-                        ResourceType.SINGLE);
+                progressMonitor.worked(1);
             }
         } catch (SimulatorException eOuter) {
             Activator
@@ -926,23 +795,7 @@ public class ResourceManager {
                             Utility.getSimulatorErrorString(eOuter, null));
             throw eOuter;
         }
-        return createCount;
-    }
-
-    public Device createDevice(String deviceName, Set<Resource> childs) {
-        // 1. Create device
-        Device dev = new Device();
-        dev.setDeviceName(deviceName);
-        data.addDevice(dev);
-
-        // 2. Add children to device
-        if (null != childs && !childs.isEmpty())
-            addResourceToDevice(dev, childs);
-
-        // 3. Update ui listeners
-        UiListenerHandler.getInstance().resourceListUpdateUINotification(
-                ResourceType.DEVICE);
-        return dev;
+        return resultSet;
     }
 
     public List<Resource> getResourceList() {
@@ -967,64 +820,22 @@ public class ResourceManager {
         return resourceList;
     }
 
-    public List<CollectionResource> getCollectionResourceList() {
-        List<CollectionResource> resourceList = data.getCollectionResources();
-        if (null == resourceList) {
-            return null;
-        }
-        // Sort the list
-        Collections.sort(resourceList, Utility.collectionResourceComparator);
-
-        return resourceList;
-    }
-
-    public List<Device> getDeviceList() {
-        List<Device> deviceList = data.getDevices();
-        if (null == deviceList) {
-            return null;
-        }
-        // Sort the list
-        Collections.sort(deviceList, Utility.deviceComparator);
-        return deviceList;
-    }
-
-    // Returns the number of resources which are added properly to the
-    // collection.
-    public int addResourceToCollection(CollectionResource collectionParent,
-            Set<Resource> childs) {
-        if (null == collectionParent || null == childs || childs.isEmpty()) {
-            return -1;
+    public void removeSingleResources(Set<SingleResource> resources)
+            throws SimulatorException {
+        if (null == resources) {
+            return;
         }
-        Iterator<Resource> itr = childs.iterator();
-        Resource res;
-        int count = childs.size();
+        Iterator<SingleResource> itr = resources.iterator();
         while (itr.hasNext()) {
-            res = itr.next();
-            try {
-                addResourceToCollection(collectionParent, res);
-            } catch (SimulatorException e) {
-                count--;
-            }
+            removeResource(itr.next());
         }
-        return count;
     }
 
-    public void addResourceToCollection(CollectionResource collectionParent,
-            Resource child) throws SimulatorException {
-        if (null == collectionParent || null == child) {
-            return;
-        }
+    public void removeResource(Resource res) throws SimulatorException {
+        // Unregister the resource from the platform.
+        SimulatorResource simRes = res.getSimulatorResource();
         try {
-            // 1. Add child to collection
-            collectionParent.addChildResource(child);
-
-            // 2. Add a reference to the collection in the child
-            if (child instanceof SingleResource) {
-                ((SingleResource) child)
-                        .addCollectionMembership(collectionParent);
-            } else {
-                ((CollectionResource) child).addMembership(collectionParent);
-            }
+            simRes.stop();
         } catch (SimulatorException e) {
             Activator
                     .getDefault()
@@ -1033,480 +844,31 @@ public class ResourceManager {
                             Utility.getSimulatorErrorString(e, null));
             throw e;
         }
-    }
 
-    public int addResourceToCollection(Set<CollectionResource> collections,
-            Resource child) {
-        if (null == collections || collections.isEmpty() || null == child) {
-            return -1;
-        }
-        Iterator<CollectionResource> itr = collections.iterator();
-        CollectionResource res;
-        int count = collections.size();
-        while (itr.hasNext()) {
-            res = itr.next();
-            try {
-                addResourceToCollection(res, child);
-            } catch (SimulatorException e) {
-                count--;
-            }
-        }
-        return count;
+        // Delete this resource
+        data.deleteResource(res);
     }
 
-    public void addResourceToDevice(Device dev, Set<Resource> childs) {
-        // 1. Add children to the device.
-        dev.addChildResource(childs);
-
-        // 2. Add a reference to the device in all children.
-        Iterator<Resource> itr = childs.iterator();
-        Resource res;
+    public boolean isUriUnique(List<MetaProperty> properties) {
+        if (null == properties) {
+            return false;
+        }
+        MetaProperty prop;
+        Iterator<MetaProperty> itr = properties.iterator();
         while (itr.hasNext()) {
-            res = itr.next();
-            if (res instanceof SingleResource) {
-                ((SingleResource) res).addDeviceMembership(dev);
-            } else {
-                ((CollectionResource) res).addDeviceMembership(dev);
+            prop = itr.next();
+            if (prop.getPropName().equals(Constants.RESOURCE_URI)) {
+                String uri = prop.getPropValue();
+                return !data.isResourceExist(uri);
             }
         }
-    }
-
-    public void addResourceToDevice(Device dev, Resource child) {
-        // 1. Add child to the device.
-        dev.addChildResource(child);
-
-        // 2. Add a reference to the device in the child.
-        if (child instanceof SingleResource) {
-            ((SingleResource) child).addDeviceMembership(dev);
-        } else {
-            ((CollectionResource) child).addDeviceMembership(dev);
-        }
-    }
-
-    public void addResourceToDevice(Set<Device> devices, Resource child) {
-        // 1. Add device reference in child.
-        if (child instanceof SingleResource)
-            ((SingleResource) child).addDeviceMembership(devices);
-        else
-            ((CollectionResource) child).addDeviceMembership(devices);
-
-        // 2. Add a reference to the child in all devices.
-        Iterator<Device> itr = devices.iterator();
-        Device dev;
-        while (itr.hasNext()) {
-            dev = itr.next();
-            dev.addChildResource(child);
-        }
-    }
-
-    public int removeResourceFromCollection(
-            Set<CollectionResource> collections, Resource resource) {
-        // 1. Remove the reference of resource from all the collections.
-        Iterator<CollectionResource> itr = collections.iterator();
-        CollectionResource colRes;
-        int count = collections.size();
-        while (itr.hasNext()) {
-            colRes = itr.next();
-            try {
-                removeResourceFromCollection(colRes, resource);
-            } catch (SimulatorException e) {
-                count--;
-            }
-        }
-        return count;
-
-    }
-
-    public void removeResourceFromDevice(Set<Device> devices, Resource resource) {
-        // 1. Remove the reference of resource from all the devices.
-        Iterator<Device> itr = devices.iterator();
-        Device dev;
-        while (itr.hasNext()) {
-            dev = itr.next();
-            dev.removeChildResource(resource);
-        }
-
-        // 2. Remove the reference of devices from the resource.
-        resource.removeDeviceMembership(devices);
-    }
-
-    // Returns the count of resources removed from the collection
-    public int removeResourcesFromCollection(CollectionResource colRes,
-            Set<Resource> resources) {
-        Iterator<Resource> itr = resources.iterator();
-        Resource res;
-        int count = resources.size();
-        while (itr.hasNext()) {
-            res = itr.next();
-            try {
-                removeResourceFromCollection(colRes, res);
-            } catch (SimulatorException e) {
-                count--;
-            }
-        }
-        return count;
-    }
-
-    public void removeResourcesFromDevice(Device dev, Set<Resource> resources) {
-        Iterator<Resource> itr = resources.iterator();
-        Resource res;
-        while (itr.hasNext()) {
-            res = itr.next();
-            res.removeDeviceMembership(dev);
-        }
-        dev.removeChildResource(resources);
-    }
-
-    public void removeResourceFromCollection(CollectionResource parent,
-            Resource child) throws SimulatorException {
-        try {
-            // 1. Remove the child from the parent
-            parent.removeChildResource(child);
-
-            // 2. Remove the reference to parent from child
-            if (child instanceof SingleResource) {
-                ((SingleResource) child).removeCollectionMembership(parent);
-            } else {
-                ((CollectionResource) child).removeMembership(parent);
-            }
-        } catch (SimulatorException e) {
-            Activator
-                    .getDefault()
-                    .getLogManager()
-                    .log(Level.ERROR.ordinal(), new Date(),
-                            Utility.getSimulatorErrorString(e, null));
-            throw e;
-        }
-    }
-
-    public void removeResourceFromDevice(Device parent, Resource child) {
-        // 1. Remove the reference to parent from child
-        child.removeDeviceMembership(parent);
-
-        // 2. Remove the child from the parent
-        parent.removeChildResource(child);
-    }
-
-    public void removeSingleResources(Set<SingleResource> resources)
-            throws SimulatorException {
-        if (null == resources) {
-            return;
-        }
-        Iterator<SingleResource> itr = resources.iterator();
-        while (itr.hasNext()) {
-            removeResource(itr.next());
-        }
-    }
-
-    public void removeCollectionResources(Set<CollectionResource> resources)
-            throws SimulatorException {
-        if (null == resources) {
-            return;
-        }
-        Iterator<CollectionResource> itr = resources.iterator();
-        while (itr.hasNext()) {
-            removeResource(itr.next());
-        }
-    }
-
-    public void removeResource(Resource res) throws SimulatorException {
-        // 1. Unregister the resource from the platform.
-        SimulatorResource simRes = res.getSimulatorResource();
-        try {
-            simRes.stop();
-        } catch (SimulatorException e) {
-            Activator
-                    .getDefault()
-                    .getLogManager()
-                    .log(Level.ERROR.ordinal(), new Date(),
-                            Utility.getSimulatorErrorString(e, null));
-            throw e;
-        }
-
-        Set<CollectionResource> collectionMembership;
-        Set<Device> deviceMembership;
-
-        if (res instanceof SingleResource) {
-            collectionMembership = ((SingleResource) res)
-                    .getCollectionMembership();
-            deviceMembership = ((SingleResource) res).getDeviceMembership();
-        } else {
-            collectionMembership = ((CollectionResource) res).getMembership();
-            deviceMembership = ((CollectionResource) res).getDeviceMembership();
-        }
-
-        // 2. Delete from the collections to which this resource is a member.
-        if (null != collectionMembership && !collectionMembership.isEmpty()) {
-            removeResourceFromCollection(collectionMembership, res);
-        }
-
-        // 3. Delete from the devices to which this resource is a member.
-        if (null != deviceMembership && !deviceMembership.isEmpty()) {
-            removeResourceFromDevice(deviceMembership, res);
-        }
-
-        // 4. Delete this resource
-        data.deleteResource(res);
-    }
-
-    public void removeDevice(Device dev) {
-        Set<Resource> childs = dev.getChildResources();
-        if (null != childs && !childs.isEmpty()) {
-            // 1. Remove the reference from all the children.
-            Iterator<Resource> itr = childs.iterator();
-            Resource res;
-            while (itr.hasNext()) {
-                res = itr.next();
-                res.removeDeviceMembership(dev);
-            }
-        }
-        // 2. Delete the device.
-        data.deleteDevice(dev);
-    }
-
-    public boolean isUriUnique(List<MetaProperty> properties) {
-        if (null == properties) {
-            return false;
-        }
-        MetaProperty prop;
-        Iterator<MetaProperty> itr = properties.iterator();
-        while (itr.hasNext()) {
-            prop = itr.next();
-            if (prop.getPropName().equals(Constants.RESOURCE_URI)) {
-                String uri = prop.getPropValue();
-                return !data.isResourceExist(uri);
-            }
-        }
-        return false;
-    }
-
-    public List<CollectionResource> getCollectionsForAddingToSingleResource(
-            SingleResource resource) {
-        List<CollectionResource> collectionResources = data
-                .getCollectionResources();
-        if (null == collectionResources || collectionResources.isEmpty()) {
-            return null;
-        }
-
-        Set<CollectionResource> collectionMembership;
-        collectionMembership = resource.getCollectionMembership();
-        if (null == collectionMembership || collectionMembership.isEmpty()) {
-            return collectionResources;
-        }
-
-        if (collectionMembership.size() == collectionResources.size()) {
-            return null;
-        }
-
-        collectionResources.removeAll(collectionMembership);
-
-        // Sort the list
-        Collections.sort(collectionResources,
-                Utility.collectionResourceComparator);
-
-        return collectionResources;
-    }
-
-    public List<SingleResource> getSingleTypeResourcesForAddingToCollectionResource(
-            CollectionResource colRes) {
-        List<SingleResource> singleResources = data.getSingleResources();
-        if (null == singleResources || singleResources.isEmpty()) {
-            return null;
-        }
-
-        Set<SingleResource> childs;
-        childs = colRes.getSingleTypeChildResources();
-        if (null == childs || childs.isEmpty()) {
-            return singleResources;
-        }
-
-        if (childs.size() == singleResources.size()) {
-            return null;
-        }
-
-        singleResources.removeAll(childs);
-
-        // Sort the list
-        Collections.sort(singleResources, Utility.singleResourceComparator);
-
-        return singleResources;
-    }
-
-    public List<SingleResource> getSingleTypeResourcesForAddingToDevice(
-            Device dev) {
-        List<SingleResource> singleResources = data.getSingleResources();
-        if (null == singleResources || singleResources.isEmpty()) {
-            return null;
-        }
-
-        Set<SingleResource> childs;
-        childs = dev.getSingleTypeChildResources();
-        if (null == childs || childs.isEmpty()) {
-            return singleResources;
-        }
-
-        if (childs.size() == singleResources.size()) {
-            return null;
-        }
-
-        singleResources.removeAll(childs);
-
-        // Sort the list
-        Collections.sort(singleResources, Utility.singleResourceComparator);
-
-        return singleResources;
-    }
-
-    public List<CollectionResource> getCollectionTypeResourcesForAddingToCollectionResource(
-            CollectionResource colRes) {
-        List<CollectionResource> collectionResources = data
-                .getCollectionResources();
-        if (null == collectionResources || collectionResources.isEmpty()) {
-            return null;
-        }
-
-        // Remove the colRes from the list
-        collectionResources.remove(colRes);
-
-        Set<CollectionResource> childs;
-        childs = colRes.getCollectionTypeChildResources();
-        if (null == childs || childs.isEmpty()) {
-            return collectionResources;
-        }
-
-        if (childs.size() == collectionResources.size()) {
-            return null;
-        }
-
-        collectionResources.removeAll(childs);
-
-        // Sort the list
-        Collections.sort(collectionResources,
-                Utility.collectionResourceComparator);
-
-        return collectionResources;
-    }
-
-    public List<CollectionResource> getCollectionTypeResourcesForAddingToDevice(
-            Device dev) {
-        List<CollectionResource> collectionResources = data
-                .getCollectionResources();
-        if (null == collectionResources || collectionResources.isEmpty()) {
-            return null;
-        }
-
-        Set<CollectionResource> childs;
-        childs = dev.getCollectionTypeChildResources();
-        if (null == childs || childs.isEmpty()) {
-            return collectionResources;
-        }
-
-        if (childs.size() == collectionResources.size()) {
-            return null;
-        }
-
-        collectionResources.removeAll(childs);
-
-        // Sort the list
-        Collections.sort(collectionResources,
-                Utility.collectionResourceComparator);
-
-        return collectionResources;
-    }
-
-    public List<Device> getDevicesForAddingToResource(Resource resource) {
-        List<Device> devices = data.getDevices();
-        if (null == devices || devices.isEmpty()) {
-            return null;
-        }
-
-        Set<Device> deviceMembership;
-        if (resource instanceof SingleResource) {
-            deviceMembership = ((SingleResource) resource)
-                    .getDeviceMembership();
-        } else {
-            deviceMembership = ((CollectionResource) resource)
-                    .getDeviceMembership();
-        }
-        if (null == deviceMembership || deviceMembership.isEmpty()) {
-            return devices;
-        }
-
-        if (devices.size() == deviceMembership.size()) {
-            return null;
-        }
-
-        devices.removeAll(deviceMembership);
-
-        // Sort the list
-        Collections.sort(devices, Utility.deviceComparator);
-
-        return devices;
-    }
-
-    public List<CollectionResource> getResourceReferences(
-            SingleResource resource) {
-        List<CollectionResource> resources = Utility
-                .getCollectionResourceListFromSet(resource
-                        .getCollectionMembership());
-        if (null == resources || resources.isEmpty()) {
-            return null;
-        }
-
-        Collections.sort(resources, Utility.collectionResourceComparator);
-
-        return resources;
-    }
-
-    public List<Device> getDeviceReferences(Resource resource) {
-        Set<Device> deviceMembership;
-        if (resource instanceof SingleResource) {
-            deviceMembership = ((SingleResource) resource)
-                    .getDeviceMembership();
-        } else {
-            deviceMembership = ((CollectionResource) resource)
-                    .getDeviceMembership();
-        }
-
-        List<Device> devices = Utility.getDeviceListFromSet(deviceMembership);
-        if (null == devices || devices.isEmpty()) {
-            return null;
-        }
-
-        Collections.sort(devices, Utility.deviceComparator);
-
-        return devices;
-    }
-
-    public List<SingleResource> getSingleTypeChilds(CollectionResource colRes) {
-        Set<SingleResource> childs = colRes.getSingleTypeChildResources();
-        return Utility.getSingleResourceListFromSet(childs);
-    }
-
-    public List<SingleResource> getSingleTypeChilds(Device dev) {
-        Set<SingleResource> childs = dev.getSingleTypeChildResources();
-        return Utility.getSingleResourceListFromSet(childs);
-    }
-
-    public List<CollectionResource> getCollectionTypeChilds(
-            CollectionResource colRes) {
-        Set<CollectionResource> childs = colRes
-                .getCollectionTypeChildResources();
-        return Utility.getCollectionResourceListFromSet(childs);
-    }
-
-    public List<CollectionResource> getCollectionTypeChilds(Device dev) {
-        Set<CollectionResource> childs = dev.getCollectionTypeChildResources();
-        return Utility.getCollectionResourceListFromSet(childs);
+        return false;
     }
 
     public void resourceSelectionChanged(final Resource selectedResource) {
         new Thread() {
             @Override
             public void run() {
-
-                setCurrentDeviceInSelection(null);
-
                 if (null != selectedResource) {
                     setCurrentResourceInSelection(selectedResource);
                 } else {
@@ -1520,25 +882,6 @@ public class ResourceManager {
         }.start();
     }
 
-    public void deviceSelectionChanged(final Device selectedDevice) {
-        new Thread() {
-            @Override
-            public void run() {
-
-                setCurrentResourceInSelection(null);
-
-                if (null != selectedDevice) {
-                    setCurrentDeviceInSelection(selectedDevice);
-                } else {
-                    setCurrentDeviceInSelection(null);
-                }
-                // Notify all observers for resource selection change event
-                UiListenerHandler.getInstance()
-                        .deviceSelectionChangedUINotification(selectedDevice);
-            }
-        }.start();
-    }
-
     public List<MetaProperty> getMetaProperties(Resource resource) {
         if (null != resource) {
             String propName;
@@ -1553,10 +896,12 @@ public class ResourceManager {
                 } else if (propName.equals(Constants.RESOURCE_URI)) {
                     propValue = resource.getResourceURI();
                 } else if (propName.equals(Constants.RESOURCE_TYPE)) {
-                    Set<String> resTypes = resource.getResourceTypes();
-                    if (null != resTypes && !resTypes.isEmpty()) {
+                    propValue = resource.getResourceType();
+                } else if (propName.equals(Constants.INTERFACE_TYPES)) {
+                    Set<String> ifTypes = resource.getResourceInterfaces();
+                    if (null != ifTypes && !ifTypes.isEmpty()) {
                         propValue = "";
-                        Iterator<String> itr = resTypes.iterator();
+                        Iterator<String> itr = ifTypes.iterator();
                         while (itr.hasNext()) {
                             propValue += itr.next();
                             if (itr.hasNext()) {
@@ -1578,16 +923,6 @@ public class ResourceManager {
         return null;
     }
 
-    public List<MetaProperty> getMetaProperties(Device dev) {
-        if (null != dev) {
-            List<MetaProperty> metaPropertyList = new ArrayList<MetaProperty>();
-            metaPropertyList.add(new MetaProperty(Constants.DEVICE_NAME, dev
-                    .getDeviceName()));
-            return metaPropertyList;
-        }
-        return null;
-    }
-
     public boolean startResource(Resource resource) throws SimulatorException {
         if (null == resource) {
             return false;
@@ -1668,14 +1003,6 @@ public class ResourceManager {
         return true;
     }
 
-    public boolean changeDeviceName(Device dev, String newName) {
-        if (null == dev || null == newName) {
-            return false;
-        }
-        data.changeDeviceName(dev, dev.getDeviceName(), newName);
-        return true;
-    }
-
     public boolean changeResourceURI(Resource resource, String newURI)
             throws SimulatorException {
         if (null == resource || null == newURI) {
@@ -1766,37 +1093,60 @@ public class ResourceManager {
         return true;
     }
 
-    public boolean updateDeviceProperties(Device dev,
-            List<MetaProperty> properties) {
-        if (null == dev || null == properties) {
+    public boolean updateResourceInterfaces(Resource resource,
+            Set<String> newIfSet) throws SimulatorException {
+        if (null == resource || null == newIfSet || newIfSet.isEmpty()) {
             return false;
         }
-
-        // Updating the properties
-        Iterator<MetaProperty> itr = properties.iterator();
-        MetaProperty property;
-        String propName;
-        String propValue;
-        String devName = null;
+        SimulatorResource jResource = resource.getSimulatorResource();
+        if (null == jResource) {
+            return false;
+        }
+        Set<String> curIfSet = resource.getResourceInterfaces();
+        Iterator<String> itr = curIfSet.iterator();
+        String interfaceType;
+        boolean resourceRestartRequired = false;
         while (itr.hasNext()) {
-            property = itr.next();
-            if (null == property) {
-                continue;
-            }
-            propName = property.getPropName();
-            propValue = property.getPropValue();
-            if (propName.equals(Constants.DEVICE_NAME)) {
-                devName = propValue;
+            interfaceType = itr.next();
+            if (!newIfSet.contains(interfaceType)) {
+                resourceRestartRequired = true;
+                break;
             }
         }
 
-        if (!changeDeviceName(dev, devName)) {
-            return false;
+        try {
+            // As there is no support from native layer for interface removal,
+            // supporting it from the simulator requires restarting the resource
+            // if any existing interfaces are removed.
+
+            if (resourceRestartRequired) {
+                stopResource(resource);
+                jResource.setInterface(Utility
+                        .convertSetToVectorString(newIfSet));
+                startResource(resource);
+            } else {
+                // Existing interfaces are not removed.
+                itr = newIfSet.iterator();
+                while (itr.hasNext()) {
+                    interfaceType = itr.next();
+                    if (!curIfSet.contains(interfaceType)) {
+                        jResource.addInterface(interfaceType);
+                    }
+                }
+            }
+        } catch (SimulatorException e) {
+            Activator
+                    .getDefault()
+                    .getLogManager()
+                    .log(Level.ERROR.ordinal(),
+                            new Date(),
+                            "There is an error while changing the interface types."
+                                    + Utility.getSimulatorErrorString(e, null));
+            throw e;
         }
 
-        // Notify UI Listeners
-        UiListenerHandler.getInstance().propertiesChangedUINotification(
-                Device.class);
+        // Set the resource interfaces.
+        resource.setResourceInterfaces(newIfSet);
 
         return true;
     }
@@ -1822,7 +1172,6 @@ public class ResourceManager {
         return false;
     }
 
-    // TODO: This method should get the status from the native layer.
     public boolean isResourceStarted(Resource resource) {
         if (null == resource) {
             return false;
@@ -1856,26 +1205,6 @@ public class ResourceManager {
         return invalid;
     }
 
-    public boolean isPropertyValueInvalid(Device dev,
-            List<MetaProperty> properties, String propName) {
-        if (null == dev || null == properties || null == propName) {
-            return false;
-        }
-        boolean invalid = false;
-        MetaProperty prop;
-        Iterator<MetaProperty> itr = properties.iterator();
-        while (itr.hasNext()) {
-            prop = itr.next();
-            if (prop.getPropName().equals(propName)) {
-                String value = prop.getPropValue();
-                if (null == value || value.trim().isEmpty()) {
-                    invalid = true;
-                }
-            }
-        }
-        return invalid;
-    }
-
     public boolean isPropValueChanged(Resource resource,
             List<MetaProperty> properties, String propName) {
         if (null == resource || null == properties || null == propName) {
@@ -1898,28 +1227,6 @@ public class ResourceManager {
         return changed;
     }
 
-    public boolean isPropValueChanged(Device dev,
-            List<MetaProperty> properties, String propName) {
-        if (null == dev || null == properties || null == propName) {
-            return false;
-        }
-        boolean changed = false;
-        MetaProperty prop;
-        String oldValue;
-        Iterator<MetaProperty> itr = properties.iterator();
-        while (itr.hasNext()) {
-            prop = itr.next();
-            if (prop.getPropName().equals(propName)) {
-                oldValue = dev.getDeviceName();
-                if (null != oldValue && !prop.getPropValue().equals(oldValue)) {
-                    changed = true;
-                }
-                break;
-            }
-        }
-        return changed;
-    }
-
     private String getPropertyValueFromResource(Resource resource,
             String propName) {
         if (null == resource || null == propName) {
@@ -1930,81 +1237,12 @@ public class ResourceManager {
         } else if (propName.equals(Constants.RESOURCE_NAME)) {
             return resource.getResourceName();
         } else if (propName.equals(Constants.RESOURCE_TYPE)) {
-            return resource.getResourceTypes().toString();
+            return resource.getResourceType();
         } else {
             return null;
         }
     }
 
-    public boolean isURIChanged(Resource resource, List<MetaProperty> properties) {
-        if (null == resource || null == properties) {
-            return false;
-        }
-        boolean changed = false;
-        MetaProperty prop;
-        Iterator<MetaProperty> itr = properties.iterator();
-        while (itr.hasNext()) {
-            prop = itr.next();
-            if (prop.getPropName().equals(Constants.RESOURCE_URI)) {
-                if (!prop.getPropValue().equals(resource.getResourceURI())) {
-                    changed = true;
-                }
-                break;
-            }
-        }
-        return changed;
-    }
-
-    public boolean startResource(SingleResource resource) {
-        if (null == resource || resource.isStarted()) {
-            return false;
-        }
-        boolean result;
-        SimulatorResource server = resource.getSimulatorResource();
-        if (null == server) {
-            result = false;
-        } else {
-            try {
-                server.start();
-                resource.setStarted(true);
-                result = true;
-            } catch (SimulatorException e) {
-                Activator
-                        .getDefault()
-                        .getLogManager()
-                        .log(Level.ERROR.ordinal(), new Date(),
-                                Utility.getSimulatorErrorString(e, null));
-                result = false;
-            }
-        }
-        return result;
-    }
-
-    public boolean stopResource(SingleResource resource) {
-        if (null == resource || !resource.isStarted()) {
-            return false;
-        }
-        boolean result;
-        SimulatorResource server = resource.getSimulatorResource();
-        if (null == server) {
-            result = false;
-        } else {
-            try {
-                server.stop();
-                resource.setStarted(false);
-                result = true;
-            } catch (SimulatorException e) {
-                Activator
-                        .getDefault()
-                        .getLogManager()
-                        .log(Level.ERROR.ordinal(), new Date(),
-                                Utility.getSimulatorErrorString(e, null));
-                result = false;
-            }
-        }
-        return result;
-    }
-
     public boolean isAttHasRangeOrAllowedValues(SimulatorResourceAttribute att) {
         if (null == att) {
             return false;
@@ -2013,10 +1251,30 @@ public class ResourceManager {
         if (null == prop) {
             return false;
         }
-        Type attProp = prop.type();
-        if (attProp == Type.UNKNOWN) {
-            return false;
+
+        if (prop.getType() == Type.INTEGER) {
+            IntegerProperty intProperty = prop.asInteger();
+            if (null != intProperty) {
+                return (intProperty.hasRange() || intProperty.hasValues());
+            } else {
+                return false;
+            }
+        } else if (prop.getType() == Type.DOUBLE) {
+            DoubleProperty dblProperty = prop.asDouble();
+            if (null != dblProperty) {
+                return (dblProperty.hasRange() || dblProperty.hasValues());
+            } else {
+                return false;
+            }
+        } else if (prop.getType() == Type.STRING) {
+            StringProperty stringProperty = prop.asString();
+            if (null != stringProperty) {
+                return stringProperty.hasValues();
+            } else {
+                return false;
+            }
         }
+
         return true;
     }
 
@@ -2088,7 +1346,6 @@ public class ResourceManager {
             return false;
         }
         boolean status = false;
-        changeResourceLevelAutomationStatus(resource, true);
         // Invoke the native automation method
         SimulatorSingleResource resourceServer = (SimulatorSingleResource) resource
                 .getSimulatorResource();
@@ -2105,12 +1362,10 @@ public class ResourceManager {
                                 Utility.getSimulatorErrorString(e, null));
                 autoId = -1;
             }
-            if (-1 == autoId) {
-                // Automation request failed and hence status is being
-                // rolled back
-                changeResourceLevelAutomationStatus(resource, false);
-            } else {
+            if (-1 != autoId) {
                 // Automation request accepted.
+                changeResourceLevelAutomationStatus(resource, true);
+
                 resource.setAutomationId(autoId);
 
                 // Notify the UI listeners in a different thread.
@@ -2257,10 +1512,6 @@ public class ResourceManager {
         }
     }
 
-    public void shutdown() {
-        threadHandle.interrupt();
-    }
-
     public List<String> getAllValuesOfAttribute(SimulatorResourceAttribute att) {
         if (null == att) {
             return null;
@@ -2280,48 +1531,82 @@ public class ResourceManager {
 
         List<String> values = new ArrayList<String>();
 
-        Type valuesType = prop.type();
-
-        if (valuesType == Type.UNKNOWN) {
-            // Adding the default value
-            values.add(Utility.getAttributeValueAsString(val));
-            return values;
-        }
-
         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 == Type.RANGE) {
-                            List<String> list = getRangeForPrimitiveNonArrayAttributes(
-                                    childProp, type.mBaseType);
-                            if (null != list) {
-                                values.addAll(list);
-                            }
-                        } else if (valuesType == Type.VALUESET) {
-                            List<String> list = getAllowedValuesForPrimitiveNonArrayAttributes(
-                                    childProp.valueSet(), type.mBaseType);
-                            if (null != list) {
-                                values.addAll(list);
-                            }
+                    ArrayProperty arrayProperty = prop.asArray();
+                    if (null != arrayProperty) {
+                        AttributeProperty childProp = arrayProperty
+                                .getElementProperty();
+                        switch (childProp.getType()) {
+                            case INTEGER:
+                                IntegerProperty intProperty = childProp
+                                        .asInteger();
+                                if (null != intProperty) {
+                                    values.addAll(getAllValues(intProperty,
+                                            Type.INTEGER));
+                                }
+                                break;
+                            case DOUBLE:
+                                DoubleProperty dblProperty = childProp
+                                        .asDouble();
+                                if (null != dblProperty) {
+                                    values.addAll(getAllValues(dblProperty,
+                                            Type.DOUBLE));
+                                }
+                                break;
+                            case BOOLEAN:
+                                BooleanProperty boolProperty = childProp
+                                        .asBoolean();
+                                if (null != boolProperty) {
+                                    values.addAll(getAllValues(boolProperty,
+                                            Type.BOOLEAN));
+                                }
+                                break;
+                            case STRING:
+                                StringProperty stringProperty = childProp
+                                        .asString();
+                                if (null != stringProperty) {
+                                    values.addAll(getAllValues(stringProperty,
+                                            Type.STRING));
+                                }
+                                break;
+                            default:
+                                break;
                         }
                     }
                 }
             } else {
-                if (valuesType == Type.RANGE) {
-                    List<String> list = getRangeForPrimitiveNonArrayAttributes(
-                            prop, type.mType);
-                    if (null != list) {
-                        values.addAll(list);
-                    }
-                } else if (valuesType == Type.VALUESET) {
-                    List<String> list = getAllowedValuesForPrimitiveNonArrayAttributes(
-                            prop.valueSet(), type.mType);
-                    if (null != list) {
-                        values.addAll(list);
-                    }
+                switch (prop.getType()) {
+                    case INTEGER:
+                        IntegerProperty intProperty = prop.asInteger();
+                        if (null != intProperty) {
+                            values.addAll(getAllValues(intProperty,
+                                    Type.INTEGER));
+                        }
+                        break;
+                    case DOUBLE:
+                        DoubleProperty dblProperty = prop.asDouble();
+                        if (null != dblProperty) {
+                            values.addAll(getAllValues(dblProperty, Type.DOUBLE));
+                        }
+                        break;
+                    case BOOLEAN:
+                        BooleanProperty boolProperty = prop.asBoolean();
+                        if (null != boolProperty) {
+                            values.addAll(getAllValues(boolProperty,
+                                    Type.BOOLEAN));
+                        }
+                        break;
+                    case STRING:
+                        StringProperty stringProperty = prop.asString();
+                        if (null != stringProperty) {
+                            values.addAll(getAllValues(stringProperty,
+                                    Type.STRING));
+                        }
+                        break;
+                    default:
+                        break;
                 }
             }
         }
@@ -2329,58 +1614,67 @@ public class ResourceManager {
         return values;
     }
 
-    public List<String> getRangeForPrimitiveNonArrayAttributes(
-            AttributeProperty prop, ValueType type) {
-        if (null == prop) {
-            return null;
-        }
+    public List<String> getAllValues(IntegerProperty intProperty,
+            AttributeProperty.Type type) {
+        List<String> values = new ArrayList<String>();
 
-        if (type == ValueType.ARRAY || type == ValueType.RESOURCEMODEL) {
-            return null;
+        if (intProperty.hasRange()) {
+            int min = (int) intProperty.min();
+            int max = (int) intProperty.max();
+            for (int iVal = min; iVal <= max; iVal++) {
+                values.add(String.valueOf(iVal));
+            }
+        } else if (intProperty.hasValues()) {
+            for (Integer val : intProperty.getValues()) {
+                values.add(String.valueOf(val));
+            }
+        } else {
+            // Adding the default value.
+            values.add(String.valueOf(intProperty.getDefaultValue()));
         }
+        return values;
+    }
 
+    public List<String> getAllValues(DoubleProperty dblProperty,
+            AttributeProperty.Type type) {
         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:
+
+        if (dblProperty.hasRange()) {
+            double min = (double) dblProperty.min();
+            double max = (double) dblProperty.max();
+            for (double iVal = min; iVal <= max; iVal = iVal + 1) {
+                values.add(String.valueOf(iVal));
+            }
+        } else if (dblProperty.hasValues()) {
+            for (Double val : dblProperty.getValues()) {
+                values.add(String.valueOf(val));
+            }
+        } else {
+            // Adding the default value.
+            values.add(String.valueOf(dblProperty.getDefaultValue()));
         }
         return values;
     }
 
-    public List<String> getAllowedValuesForPrimitiveNonArrayAttributes(
-            AttributeValue[] attValues, ValueType type) {
-        if (null == attValues || attValues.length < 1) {
-            return null;
-        }
-
-        if (type == ValueType.ARRAY || type == ValueType.RESOURCEMODEL) {
-            return null;
-        }
+    public List<String> getAllValues(BooleanProperty boolProperty,
+            AttributeProperty.Type type) {
+        List<String> values = new ArrayList<String>();
+        values.add("true");
+        values.add("false");
+        return values;
+    }
 
-        Object obj;
+    public List<String> getAllValues(StringProperty stringProperty,
+            AttributeProperty.Type type) {
         List<String> values = new ArrayList<String>();
-        for (AttributeValue val : attValues) {
-            if (null == val) {
-                continue;
-            }
-            obj = val.get();
-            if (null == obj) {
-                continue;
+
+        if (stringProperty.hasValues()) {
+            for (String val : stringProperty.getValues()) {
+                values.add(String.valueOf(val));
             }
-            values.add(String.valueOf(obj));
+        } else {
+            // Adding the default value.
+            values.add(String.valueOf(stringProperty.getDefaultValue()));
         }
         return values;
     }
@@ -2388,4 +1682,8 @@ public class ResourceManager {
     public int getResourceCount() {
         return data.getResourceCount();
     }
+
+    public void shutdown() {
+        threadHandle.interrupt();
+    }
 }
\ No newline at end of file