Collection resource support in plugin UI.
authorHarish Kumara Marappa <h.marappa@samsung.com>
Mon, 9 Nov 2015 07:56:41 +0000 (13:26 +0530)
committerMadan Lanka <lanka.madan@samsung.com>
Tue, 10 Nov 2015 11:29:37 +0000 (11:29 +0000)
Handling life cycle of collection in UI and supporting displaying resource attributes of SimulatorResourceModel and vector type.

Change-Id: I1f1edb6822c0061ca2fcfe50bad63a3326732683
Signed-off-by: G S Senthil Kumar <senthil.gs@samsung.com>
Signed-off-by: Harish Kumara Marappa <h.marappa@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/4069
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: RadhaBhavani <radha.p@samsung.com>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
133 files changed:
service/simulator/examples/client/simulator_client.cpp
service/simulator/examples/server/simulator_server.cpp
service/simulator/inc/simulator_resource.h
service/simulator/inc/simulator_resource_model.h
service/simulator/inc/simulator_single_resource.h
service/simulator/java/eclipse-plugin/ClientControllerPlugin/icons/light_16x16.png [deleted file]
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/listener/IDevicePlatformInfoUIListener.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/listener/IGetUIListener.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/listener/IObserveUIListener.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/listener/IPostUIListener.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/listener/IPutUIListener.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/manager/ImageManager.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/manager/LogManager.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/manager/ResourceManager.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/PutPostAttributeModel.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/RemoteResource.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/RemoteResourceAttribute.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/SerializedClientController.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/Constants.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/AttributeView.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/MetaPropertiesView.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/ResourceManagerView.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/LoadRAMLDialog.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/PostRequestDialog.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/PutRequestDialog.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/VerificationDialog.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/build.properties
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/collection_resource.gif [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/device.gif [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/single_resource.gif [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/plugin.xml
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IAutomationUIListener.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IObserverListChangedUIListener.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IPropertiesChangedUIListener.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IResourceListChangedUIListener.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IResourceModelChangedUIListener.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/ISelectionChangedUIListener.java [moved from service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IResourceSelectionChangedUIListener.java with 74% similarity]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/Data.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ImageManager.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/LogManager.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/UiListenerHandler.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/AttributeHelper.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/AutomationSettingHelper.java [moved from service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/AutomationSettingHelper.java with 63% similarity]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/CollectionResource.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/DeleteCategory.java [moved from service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/DeleteCategory.java with 93% similarity]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/Device.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/LocalResourceAttribute.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/MetaProperty.java [moved from service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/MetaProperty.java with 96% similarity]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/ModelChangeNotificationType.java [moved from service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/ModelChangeNotificationType.java with 94% similarity]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/ObserverDetail.java [moved from service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/ObserverDetail.java with 77% similarity]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/Resource.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/ResourceCategory.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/ResourceType.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/SRMItem.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/SerializedServiceProvider.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/SimulatorPluginException.java [moved from service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/MultiResourceOrchestrationView.java with 54% similarity]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/SingleResource.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/perspective/PerspectiveFactory.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/LocalResourceAttribute.java [deleted file]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/SimulatorResource.java [deleted file]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/AttributeValueBuilder.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Constants.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Utility.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeEditingSupport.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeView.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/DevicePlatformInfoView.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/MetaPropertiesView.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/ResourceManagerView.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/ResourceObserverView.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddAttributeDialog.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddResourceToCollections.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddResourceToDevices.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddResources.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddResourcesToCollectionPage.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AutomationSettingDialog.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CollectionResourceBasicDetailsPage.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CreateResourceWizard.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteResourcePage.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteResourceWizard.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DevicePage.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/LoadRamlPage.java [moved from service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CreateResourcePage.java with 53% similarity]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/MainPage.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/RemoveResourceFromCollections.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/RemoveResourceFromDevices.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/RemoveResources.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/ResourceWizardDialog.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourceAddAttributePage.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourceBasicDetailsPage.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourceOtherDetailsPage.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourcePage.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SingleTextInputDialog.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/StartStopResourcePage.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/UpdatePropertiesPage.java [new file with mode: 0644]
service/simulator/java/jni/simulator_resource_jni.cpp
service/simulator/java/jni/simulator_resource_model_jni.cpp
service/simulator/java/jni/simulator_single_resource_jni.cpp
service/simulator/java/sdk/src/org/oic/simulator/AttributeProperty.java
service/simulator/java/sdk/src/org/oic/simulator/AttributeValue.java
service/simulator/java/sdk/src/org/oic/simulator/AttributeValueValidation.java [new file with mode: 0644]
service/simulator/java/sdk/src/org/oic/simulator/AttributeValueVisitor.java [new file with mode: 0644]
service/simulator/java/sdk/src/org/oic/simulator/ILogger.java
service/simulator/java/sdk/src/org/oic/simulator/SimulatorManager.java
service/simulator/java/sdk/src/org/oic/simulator/SimulatorResourceAttribute.java
service/simulator/java/sdk/src/org/oic/simulator/SimulatorResourceModel.java
service/simulator/java/sdk/src/org/oic/simulator/SimulatorResult.java
service/simulator/java/sdk/src/org/oic/simulator/client/FindResourceListener.java
service/simulator/java/sdk/src/org/oic/simulator/client/SimulatorRemoteResource.java
service/simulator/java/sdk/src/org/oic/simulator/server/SimulatorCollectionResource.java
service/simulator/java/sdk/src/org/oic/simulator/server/SimulatorResource.java
service/simulator/java/sdk/src/org/oic/simulator/server/SimulatorSingleResource.java
service/simulator/ramlparser/SConscript
service/simulator/ramlparser/example/SConscript [deleted file]
service/simulator/ramlparser/example/raml_parser.cpp [deleted file]
service/simulator/ramlparser/raml/jsonSchemaParser/Properties.h
service/simulator/src/client/attribute_generator.cpp
service/simulator/src/client/attribute_generator.h
service/simulator/src/common/response_model.cpp
service/simulator/src/common/simulator_resource_model.cpp
service/simulator/src/common/simulator_utils.cpp
service/simulator/src/server/simulator_collection_resource_impl.cpp
service/simulator/src/server/simulator_collection_resource_impl.h
service/simulator/src/server/simulator_resource_factory.cpp
service/simulator/src/server/simulator_resource_factory.h
service/simulator/src/server/simulator_single_resource_impl.cpp
service/simulator/src/server/simulator_single_resource_impl.h
service/simulator/src/simulator_manager.cpp
service/simulator/unittests/SimulatorTest/.gitignore [new file with mode: 0644]
service/simulator/unittests/SimulatorTest/ramls/oic.r.light-error.json [deleted file]
service/simulator/unittests/SimulatorTest/ramls/oic.r.light.json [deleted file]
service/simulator/unittests/SimulatorTest/ramls/oic.r.light.raml [deleted file]
service/simulator/unittests/SimulatorTest/src/org/oic/simulator/server/test/SimulatorCollectionResourceTest.java
service/simulator/unittests/SimulatorTest/src/org/oic/simulator/test/AttributeValueValidationTest.java [new file with mode: 0644]

index 9577d83..f0f3148 100644 (file)
@@ -120,7 +120,7 @@ class ClientController
             std::lock_guard<std::recursive_mutex> lock(m_mutex);
             if (0 == m_resList.size())
             {
-                std::cout << "No resouces!" << std::endl;
+                std::cout << "No resources!" << std::endl;
                 return nullptr;
             }
 
@@ -169,7 +169,8 @@ class ClientController
             try
             {
                 SimulatorManager::getInstance()->findResource(resourceType, callback);
-                std::cout << "SimulatorManager::findResource is successfull" << std::endl;
+                std::cout << "SimulatorManager::findResource is successful" << std::endl;
+                m_resList.clear();
             }
             catch (InvalidArgsException &e)
             {
@@ -226,7 +227,7 @@ class ClientController
             try
             {
                 resource->observe(ObserveType::OBSERVE, callback);
-                std::cout << "Observe is successfull!" << std::endl;
+                std::cout << "Observe is successful!" << std::endl;
             }
             catch (InvalidArgsException &e)
             {
@@ -248,7 +249,7 @@ class ClientController
             try
             {
                 resource->cancelObserve();
-                std::cout << "Cancelling observe is successfull!" << std::endl;
+                std::cout << "Cancelling observe is successful!" << std::endl;
             }
             catch (SimulatorException &e)
             {
@@ -276,7 +277,7 @@ class ClientController
             try
             {
                 resource->get(std::map <std::string, std::string>(), callback);
-                std::cout << "GET is successfull!" << std::endl;
+                std::cout << "GET is successful!" << std::endl;
             }
             catch (InvalidArgsException &e)
             {
@@ -319,7 +320,7 @@ class ClientController
                 rep->add("intensity", 5);
 
                 resource->put(std::map <std::string, std::string>(), rep, callback);
-                std::cout << "PUT is successfull!" << std::endl;
+                std::cout << "PUT is successful!" << std::endl;
             }
             catch (InvalidArgsException &e)
             {
@@ -362,7 +363,7 @@ class ClientController
                 rep->add("intensity", 7);
 
                 resource->post(std::map <std::string, std::string>(), rep, callback);
-                std::cout << "POST is successfull!" << std::endl;
+                std::cout << "POST is successful!" << std::endl;
             }
             catch (InvalidArgsException &e)
             {
@@ -397,7 +398,7 @@ class ClientController
             try
             {
                 int id = resource->startVerification(RequestType::RQ_TYPE_GET, callback);
-                std::cout << "startVerification for GET is successfull!id: " << id << std::endl;
+                std::cout << "startVerification for GET is successful!id: " << id << std::endl;
             }
             catch (InvalidArgsException &e)
             {
@@ -432,7 +433,7 @@ class ClientController
             try
             {
                 int id = resource->startVerification(RequestType::RQ_TYPE_PUT, callback);
-                std::cout << "startVerification for PUT is successfull!id: " << id << std::endl;
+                std::cout << "startVerification for PUT is successful!id: " << id << std::endl;
             }
             catch (InvalidArgsException &e)
             {
@@ -467,7 +468,7 @@ class ClientController
             try
             {
                 int id = resource->startVerification(RequestType::RQ_TYPE_POST, callback);
-                std::cout << "startVerification for POST is successfull!id: " << id << std::endl;
+                std::cout << "startVerification for POST is successful!id: " << id << std::endl;
             }
             catch (InvalidArgsException &e)
             {
@@ -501,7 +502,7 @@ class ClientController
                 SimulatorResourceModelSP representation = resource->configure(configPath);
                 if (representation)
                 {
-                    std::cout << "configuration is successfull!" << std::endl;
+                    std::cout << "configuration is successful!" << std::endl;
                     std::map<std::string, SimulatorResourceModel::Attribute> attributes =
                     representation->getAttributes();
                     std::cout << "##### Attributes [" << attributes.size() << "]" << std::endl;
index 56114ce..d22eaf2 100644 (file)
@@ -21,6 +21,7 @@
 #include "simulator_manager.h"
 
 std::vector<SimulatorSingleResourceSP> g_singleResources;
+std::vector<SimulatorCollectionResourceSP> g_collectionResources;
 
 std::string getPropertyTypeString(SimulatorResourceModel::AttributeProperty::Type type)
 {
@@ -111,23 +112,33 @@ void simulateResource()
         SimulatorResourceSP resource =
             SimulatorManager::getInstance()->createResource(configPath);
 
-        SimulatorSingleResourceSP singleRes =
-            std::dynamic_pointer_cast<SimulatorSingleResource>(resource);
-        singleRes->setModelChangeCallback(modelChangeCB);
-        singleRes->setObserverCallback(observerCB);
-
-        g_singleResources.push_back(singleRes);
-
-        std::cout << "Resource created successfully! URI= " << resource->getURI() << std::endl;
+        // Add resource to appropriate list
+        if (SimulatorResource::Type::SINGLE_RESOURCE == resource->getType())
+        {
+            std::cout << "Single type resource created [URI:  " << resource->getURI() << " ]" << std::endl;
+            SimulatorSingleResourceSP singleRes =
+                std::dynamic_pointer_cast<SimulatorSingleResource>(resource);
+            singleRes->setModelChangeCallback(modelChangeCB);
+            singleRes->setObserverCallback(observerCB);
+            g_singleResources.push_back(singleRes);
+        }
+        else
+        {
+            std::cout << "Collection type resource created [URI:  " << resource->getURI() << " ]" << std::endl;
+            SimulatorCollectionResourceSP collectionRes =
+                std::dynamic_pointer_cast<SimulatorCollectionResource>(resource);
+            collectionRes->setObserverCallback(observerCB);
+            g_collectionResources.push_back(collectionRes);
+        }
     }
     catch (InvalidArgsException &e)
     {
-        std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: "
+        std::cout << "InvalidArgsException occured [code : " << e.code() << " Details: "
                   << e.what() << "]" << std::endl;
     }
     catch (SimulatorException &e)
     {
-        std::cout << "SimulatorException occured [code : " << e.code() << " Detail: "
+        std::cout << "SimulatorException occured [code : " << e.code() << " Details: "
                   << e.what() << "]" << std::endl;
     }
 }
@@ -223,7 +234,7 @@ void automateResourceUpdate()
     }
     catch (SimulatorException &e)
     {
-        std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " <<
+        std::cout << "SimulatorException occured [code : " << e.code() << " Details: " <<
                   e.what() << "]" << std::endl;
     }
 }
@@ -326,12 +337,10 @@ void stopAutomation()
     }
 
     for (auto & id : ids)
+    {
         std::cout <<  id  << " ";
-
-    int automationid;
-    std::cout << "\nEnter automation id: " << std::endl;
-    std::cin >> automationid;
-    resource->stopUpdation(automationid);
+        resource->stopUpdation(id);
+    }
 }
 
 void getObservers()
index 074a308..d5b99ca 100644 (file)
@@ -91,6 +91,27 @@ class SimulatorResource : public UnCopyable
         virtual std::vector<std::string> getInterface() const = 0;
 
         /**
+         * API to get the observable state of resource.
+         *
+         * @return bool - true if resource is observable, otherwise false.
+         */
+        virtual bool isObservable() = 0;
+
+        /**
+         * API to get the start state of resource.
+         *
+         * @return bool - true if resource is started, otherwise false.
+         */
+        virtual bool isStarted() = 0;
+
+        /**
+         * API to get SimulatorResourceModel of resource.
+         *
+         * @return Resource model of the resource.
+         */
+        virtual SimulatorResourceModel getResourceModel() = 0;
+
+        /**
          * API to set the name of the resource.
          *
          * @param name - Name to be set.
@@ -144,18 +165,12 @@ class SimulatorResource : public UnCopyable
         virtual void setObserverCallback(ObserverCallback callback) = 0;
 
         /**
-         * API to get the observable state of resource.
-         *
-         * @return bool - true if resource is observable, otherwise false.
-         */
-        virtual bool isObservable() = 0;
-
-        /**
-         * API to get the start state of resource.
+         * API to set the callback for receiving the notifications when the
+         * resource model changes.
          *
-         * @return bool - true if resource is started, otherwise false.
+         * @param callback - Callback to be set for receiving the notifications.
          */
-        virtual bool isStarted() = 0;
+        virtual void setModelChangeCallback(ResourceModelChangedCallback callback) = 0;
 
         /**
          * API to start the resource.
index 5ea64c0..40a112b 100644 (file)
@@ -118,7 +118,7 @@ class SimulatorResourceModel
                 AttributeProperty(AttributeProperty &&) = default;
                 AttributeProperty &operator=(AttributeProperty &&) = default;
 
-                explicit AttributeProperty(int min, int max);
+                explicit AttributeProperty(double min, double max);
                 explicit AttributeProperty(const std::vector<int> &valueSet);
                 explicit AttributeProperty(const std::vector<double> &valueSet);
                 explicit AttributeProperty(const std::vector<bool> &valueSet);
@@ -126,17 +126,20 @@ class SimulatorResourceModel
                 explicit AttributeProperty(const std::vector<ValueVariant> &valueSet);
 
                 Type type() const;
-                int min() const;
-                int max() const;
+                double min() const;
+                double max() const;
                 int valueSetSize() const;
                 std::vector<ValueVariant> valueSet() const;
                 std::string valueSetToString() const;
+                void setChildProperty(AttributeProperty &childProperty);
+                std::shared_ptr<AttributeProperty> getChildProperty();
 
             private:
                 Type m_type;
-                int m_min;
-                int m_max;
+                double m_min;
+                double m_max;
                 std::vector<ValueVariant> m_valueSet;
+                std::shared_ptr<AttributeProperty> m_childProperty;
         };
 
         class Attribute
index 6025f88..3fb7935 100644 (file)
@@ -123,21 +123,6 @@ class SimulatorSingleResource : public SimulatorResource
                                           bool notify = true) = 0;
 
         /**
-         * API to get SimulatorResourceModel of resource.
-         *
-         * @return Resource model of the resource.
-         */
-        virtual SimulatorResourceModel getResourceModel() = 0;
-
-        /**
-         * API to set the callback for receiving the notifications when the
-         * resource model changes.
-         *
-         * @param callback - Callback to be set for receiving the notifications.
-         */
-        virtual void setModelChangeCallback(ResourceModelChangedCallback callback) = 0;
-
-        /**
          * API to start the attribute value update automation for all attributes.
          * Values for the attributes will be selected from their allowed range
          * and the updated resource model will be notified to all the observers of the resource.
diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/icons/light_16x16.png b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/icons/light_16x16.png
deleted file mode 100644 (file)
index 8b3abbd..0000000
Binary files a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/icons/light_16x16.png and /dev/null differ
diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/listener/IDevicePlatformInfoUIListener.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/listener/IDevicePlatformInfoUIListener.java
new file mode 100644 (file)
index 0000000..58c2e12
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package oic.simulator.clientcontroller.listener;
+
+public interface IDevicePlatformInfoUIListener {
+    public void onDeviceInfoFound();
+
+    public void onPlatformInfoFound();
+}
index b0b1f6c..cb7f17e 100644 (file)
@@ -50,10 +50,6 @@ public class ImageManager {
         r.put(Constants.UNCHECKED, ImageDescriptor.createFromURL(bundle
                 .getEntry("icons/unchecked.gif")));
 
-        // Resource icons based on the resource type
-        r.put(Constants.OIC_R_LIGHT, ImageDescriptor.createFromURL(bundle
-                .getEntry("/icons/light_16x16.png")));
-
         // Log View related icons
         r.put(Constants.DEBUG_LOG, ImageDescriptor.createFromURL(bundle
                 .getEntry("/icons/debug_log.gif")));
index 03700e4..ffdb442 100644 (file)
@@ -24,6 +24,7 @@ import java.util.LinkedList;
 import oic.simulator.clientcontroller.Activator;
 import oic.simulator.clientcontroller.listener.ILogUIListener;
 import oic.simulator.clientcontroller.utils.Constants;
+import oic.simulator.clientcontroller.utils.Utility;
 import oic.simulator.logger.LogEntry;
 import oic.simulator.logger.LoggerCallback;
 
@@ -31,6 +32,7 @@ import org.eclipse.jface.resource.ImageRegistry;
 import org.eclipse.swt.graphics.Image;
 import org.oic.simulator.ILogger;
 import org.oic.simulator.ILogger.Level;
+import org.oic.simulator.SimulatorException;
 import org.oic.simulator.SimulatorManager;
 
 /**
@@ -55,7 +57,14 @@ public class LogManager {
 
         // Set the logger callback with the native layer
         logger = new LoggerCallback();
-        SimulatorManager.setLogger(logger);
+        try {
+            SimulatorManager.setLogger(logger);
+        } catch (SimulatorException e) {
+            log(Level.ERROR.ordinal(),
+                    new Date(),
+                    "Failed to register the logger.\n"
+                            + Utility.getSimulatorErrorString(e, null));
+        }
     }
 
     private static class LogManagerSynchronizerThread implements Runnable {
index 545f0a4..4ceca67 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;
@@ -44,24 +45,29 @@ 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.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
@@ -76,12 +82,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;
 
@@ -95,6 +103,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;
@@ -105,6 +114,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>();
@@ -118,41 +130,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;
-                        }
+                        // RemoteResource resource =
+                        // fetchResourceDetails(resourceN);
+                        RemoteResource resource = new RemoteResource();
+                        resource.setRemoteResourceRef(resourceN);
 
-                        resource.setResource(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)) {
@@ -161,8 +173,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
@@ -176,8 +195,7 @@ public class ResourceManager {
                                 .getLogManager()
                                 .log(Level.INFO.ordinal(),
                                         new Date(),
-                                        "Resource Found ["
-                                                + resource.getResourceURI()
+                                        "Resource Found [" + resourceN.getURI()
                                                 + "].");
 
                         // Send an initial GET request to get the resource
@@ -193,46 +211,83 @@ public class ResourceManager {
                                             Utility.getSimulatorErrorString(e,
                                                     null));
                         }
+
+                        // Get the device and platform information
+                        try {
+                            SimulatorManager.findDevices(deviceListener);
+                            SimulatorManager
+                                    .getPlatformInformation(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
@@ -241,26 +296,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() {
@@ -275,23 +366,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() {
@@ -306,18 +387,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() {
@@ -339,7 +414,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() {
@@ -360,7 +434,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() {
@@ -399,9 +472,13 @@ public class ResourceManager {
             return null;
         }
 
-        resource.setResourceModel(resourceModelN);
+        resource.setResourceModelRef(resourceModelN);
         Map<String, RemoteResourceAttribute> attributeMap = fetchResourceAttributesFromModel(resourceModelN);
-        resource.setResourceAttributesMap(attributeMap);
+        if (resource.isConfigUploaded()) {
+            updateResourceAttributesFromResponse(resource, attributeMap);
+        } else {
+            resource.setResourceAttributesMap(attributeMap);
+        }
         // TODO: Printing the values for debugging
         if (null != attributeMap) {
             RemoteResourceAttribute.printAttributes(attributeMap);
@@ -409,6 +486,61 @@ public class ResourceManager {
         return resource;
     }
 
+    private void updateResourceAttributesFromResponse(RemoteResource res,
+            Map<String, RemoteResourceAttribute> newAttributeMap) {
+        if (null == res || null == newAttributeMap) {
+            return;
+        }
+        Map<String, RemoteResourceAttribute> oldAttributeMap = res
+                .getResourceAttributesMap();
+        if (null == oldAttributeMap) {
+            return;
+        }
+        Iterator<String> itr = oldAttributeMap.keySet().iterator();
+        String attName;
+        RemoteResourceAttribute newAtt;
+        RemoteResourceAttribute oldAtt;
+        while (itr.hasNext()) {
+            attName = itr.next();
+            newAtt = newAttributeMap.get(attName);
+            if (null == newAtt) {
+                // Attribute does not exist in the received model. Hence
+                // removing it from local model.
+                itr.remove();
+            } else {
+                oldAtt = oldAttributeMap.get(attName);
+                if (null != oldAtt) {
+                    oldAtt.setAttributeValue(newAtt.getAttributeValue());
+                } else {
+                    itr.remove();
+                }
+                newAttributeMap.remove(attName);
+            }
+        }
+        // Adding new attributes in the received model.
+        itr = newAttributeMap.keySet().iterator();
+        while (itr.hasNext()) {
+            attName = itr.next();
+            oldAttributeMap.put(attName, newAttributeMap.get(attName));
+        }
+    }
+
+    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>();
@@ -495,6 +627,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) {
@@ -567,7 +713,7 @@ public class ResourceManager {
             return;
         }
         synchronized (favoriteURIList) {
-            favoriteURIList.add(resource.getResourceURI());
+            favoriteURIList.add(resource.getRemoteResourceRef().getURI());
         }
     }
 
@@ -576,7 +722,7 @@ public class ResourceManager {
             return;
         }
         synchronized (favoriteURIList) {
-            favoriteURIList.remove(resource.getResourceURI());
+            favoriteURIList.remove(resource.getRemoteResourceRef().getURI());
         }
     }
 
@@ -612,7 +758,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);
             }
         }
     }
@@ -635,24 +782,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) {
@@ -676,24 +805,19 @@ public class ResourceManager {
             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(),
-                                Utility.getSimulatorErrorString(e, null));
-                return null;
-            }
+            Map<String, SimulatorResourceAttribute> attributeMapN;
+            attributeMapN = resourceModelN.getAttributes();
             if (null != attributeMapN) {
                 resourceAttributeMap = new HashMap<String, RemoteResourceAttribute>();
 
                 Set<String> attNameSet = attributeMapN.keySet();
                 String attName;
                 Object attValueObj;
-                ResourceAttribute attributeN;
+                AttributeValue attValueN;
+                AttributeProperty attPropN;
+                TypeInfo typeInfo;
+                Type valuesType;
+                SimulatorResourceAttribute attributeN;
                 RemoteResourceAttribute attribute;
                 Iterator<String> attNameItr = attNameSet.iterator();
                 while (attNameItr.hasNext()) {
@@ -701,29 +825,39 @@ public class ResourceManager {
                     attributeN = attributeMapN.get(attName);
                     if (null != attributeN) {
                         attribute = new RemoteResourceAttribute();
-                        attribute.setResourceAttribute(attributeN);
+                        attribute.setResourceAttributeRef(attributeN);
                         attribute.setAttributeName(attName);
 
-                        attValueObj = attributeN.getValue();
-                        if (null != attValueObj) {
-                            attribute.setAttributeValue(attValueObj);
-                        }
+                        attValueN = attributeN.value();
+                        if (null != attValueN) {
+                            attValueObj = attValueN.get();
+                            if (null != attValueObj) {
+                                attribute.setAttributeValue(attValueObj);
+                            }
 
-                        // Set the attribute type
-                        attribute.setAttValBaseType(attributeN.getBaseType());
-                        attribute.setAttValType(attributeN.getType());
+                            // Set the attribute type
+                            typeInfo = attValueN.typeInfo();
+                            if (null != typeInfo) {
+                                attribute.setAttValBaseType(typeInfo.mBaseType);
+                                attribute.setAttValType(typeInfo.mType);
+                                attribute.setDepth(typeInfo.mDepth);
+                            }
+
+                        }
 
                         // 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();
+                        attPropN = attributeN.property();
+                        valuesType = attPropN.type();
+                        attribute.setValuesType(valuesType);
+                        if (valuesType == Type.RANGE) {
+                            attribute.setMinValue(attPropN.min());
+                            attribute.setMaxValue(attPropN.max());
+                        } else if (valuesType == Type.VALUESET) {
+                            Object[] values = attPropN.valueSet();
                             if (null != values && values.length > 0) {
                                 List<Object> valueList = new ArrayList<Object>();
                                 for (Object obj : values) {
-                                    valueList.add(obj);
+                                    valueList.add(((AttributeValue) obj).get());
                                 }
                                 attribute.setAllowedValues(valueList);
                             }
@@ -899,6 +1033,38 @@ public class ResourceManager {
         }
     }
 
+    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();
+                    }
+                }
+            }
+        }
+    }
+
+    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();
+                    }
+                }
+            }
+        }
+    }
+
     public synchronized Set<String> getLastKnownSearchTypes() {
         return lastKnownSearchTypes;
     }
@@ -942,13 +1108,25 @@ public class ResourceManager {
     }
 
     public void deleteResources(final Set<String> searchTypes) {
+        synchronized (resourceMap) {
+            if (null == resourceMap && resourceMap.isEmpty()) {
+                return;
+            }
+        }
         new Thread() {
             public void run() {
                 if (null == searchTypes || searchTypes.size() < 1) {
-                    // Delete all cached details of resources
-                    resourceMap.clear();
-                    favoriteResources.clear();
-
+                    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
                     setCurrentResourceInSelection(null);
                     resourceSelectionChangedUINotification(null);
@@ -975,7 +1153,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;
         }
@@ -1011,10 +1190,12 @@ public class ResourceManager {
                 if (null == resource) {
                     continue;
                 }
-                types = resource.getResourceTypes();
+                types = resource.getRemoteResourceRef().getResourceTypes();
                 if (null != types) {
                     exist = types.contains(resourceType);
                     if (exist) {
+                        // Cancel observing the resource.
+                        sendCancelObserveRequest(resource, false);
                         // Remove the resource from favorites list.
                         removeResourceFromFavorites(resource);
                         // Remove the resource
@@ -1036,7 +1217,7 @@ public class ResourceManager {
         }.start();
     }
 
-    public List<MetaProperty> getMetaProperties(RemoteResource resource) {
+    public List<MetaProperty> getDefaultProperties(RemoteResource resource) {
         if (null != resource) {
             String propName;
             String propValue;
@@ -1046,22 +1227,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 {
@@ -1080,6 +1265,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;
@@ -1107,8 +1370,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", "");
@@ -1148,7 +1411,7 @@ public class ResourceManager {
         if (null == resource) {
             return;
         }
-        SimulatorRemoteResource resourceN = resource.getResource();
+        SimulatorRemoteResource resourceN = resource.getRemoteResourceRef();
         if (null == resourceN) {
             return;
         }
@@ -1165,45 +1428,39 @@ public class ResourceManager {
 
     public void sendPutRequest(RemoteResource resource,
             List<PutPostAttributeModel> putPostModelList) {
-        System.out.println(putPostModelList);
-        System.out.println("ResourceManager: sendPutRequest");
         if (null == resource) {
             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) {
+            SimulatorResourceModel resourceModel = getUpdatedResourceModel(
+                    attMap, putPostModelList);
+            resourceN.put(null, resourceModel, putListener);
+        } catch (Exception e) {
+            String addlInfo;
+            addlInfo = "Invalid Attribute Value. Cannot send PUT request.";
             Activator
                     .getDefault()
                     .getLogManager()
                     .log(Level.ERROR.ordinal(), new Date(),
-                            Utility.getSimulatorErrorString(e, null));
+                            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) {
             return;
         }
-        SimulatorRemoteResource resourceN = resource.getResource();
+        SimulatorRemoteResource resourceN = resource.getRemoteResourceRef();
         if (null == resourceN) {
             return;
         }
@@ -1221,27 +1478,29 @@ public class ResourceManager {
                 itr.remove();
             }
         }
-        SimulatorResourceModel resourceModel = getUpdatedResourceModel(attMap,
-                putPostModelList);
         try {
-            resourceN.post(resourceModel, null, postListener);
-        } catch (SimulatorException e) {
+            SimulatorResourceModel resourceModel = getUpdatedResourceModel(
+                    attMap, putPostModelList);
+            resourceN.post(null, resourceModel, postListener);
+        } catch (Exception e) {
+            String addlInfo;
+            addlInfo = "Invalid Attribute Value. Cannot send POST request.";
             Activator
                     .getDefault()
                     .getLogManager()
                     .log(Level.ERROR.ordinal(), new Date(),
-                            Utility.getSimulatorErrorString(e, null));
+                            Utility.getSimulatorErrorString(e, addlInfo));
         }
     }
 
     private SimulatorResourceModel getUpdatedResourceModel(
             Map<String, RemoteResourceAttribute> attMap,
-            List<PutPostAttributeModel> putPostModelList) {
+            List<PutPostAttributeModel> putPostModelList) throws Exception {
         String attName;
         SimulatorResourceModel resourceModel = new SimulatorResourceModel();
         PutPostAttributeModel model;
         RemoteResourceAttribute attribute;
-        Type attType;
+        ValueType attType;
         Iterator<PutPostAttributeModel> itr = putPostModelList.iterator();
         while (itr.hasNext()) {
             model = itr.next();
@@ -1251,152 +1510,113 @@ public class ResourceManager {
                 continue;
             }
             attType = attribute.getAttValBaseType();
-            if (attType == Type.INT) {
+            if (attType == ValueType.INTEGER) {
                 int attValue;
-                try {
-                    attValue = Integer.parseInt(model.getAttValue());
-                    resourceModel.addAttributeInt(attName, attValue);
-                } catch (NumberFormatException e) {
-                    Activator
-                            .getDefault()
-                            .getLogManager()
-                            .log(Level.ERROR.ordinal(),
-                                    new Date(),
-                                    Utility.getSimulatorErrorString(e,
-                                            "Failed to convert the attribute value."));
-                } catch (SimulatorException e) {
-                    Activator
-                            .getDefault()
-                            .getLogManager()
-                            .log(Level.ERROR.ordinal(), new Date(),
-                                    Utility.getSimulatorErrorString(e, null));
-                }
-            } else if (attType == Type.DOUBLE) {
+                attValue = Integer.parseInt(model.getAttValue());
+                resourceModel.addAttribute(attName,
+                        new AttributeValue(attValue));
+            } else if (attType == ValueType.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(),
-                                    Utility.getSimulatorErrorString(e,
-                                            "Failed to convert the attribute value."));
-                } catch (SimulatorException e) {
-                    Activator
-                            .getDefault()
-                            .getLogManager()
-                            .log(Level.ERROR.ordinal(), new Date(),
-                                    Utility.getSimulatorErrorString(e, null));
-                }
-            } 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(),
-                                    Utility.getSimulatorErrorString(e, null));
+                attValue = Double.parseDouble(model.getAttValue());
+                resourceModel.addAttribute(attName,
+                        new AttributeValue(attValue));
+            } else if (attType == ValueType.BOOLEAN) {
+                String attValue = model.getAttValue();
+                if (null != attValue && attValue.length() > 0) {
+                    attValue = attValue.toLowerCase();
+                    if (!(attValue.equals("true") || attValue.equals("false"))) {
+                        throw new Exception("Invalid attribute value");
+                    }
                 }
-            } else if (attType == Type.STRING) {
+                resourceModel.addAttribute(attName,
+                        new AttributeValue(attValue));
+            } else if (attType == ValueType.STRING) {
                 String attValue;
                 attValue = model.getAttValue();
-                try {
-                    resourceModel.addAttributeString(attName, attValue);
-                } catch (SimulatorException e) {
-                    Activator
-                            .getDefault()
-                            .getLogManager()
-                            .log(Level.ERROR.ordinal(), new Date(),
-                                    Utility.getSimulatorErrorString(e, null));
-                }
+                resourceModel.addAttribute(attName,
+                        new AttributeValue(attValue));
             }
         }
         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(),
                             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(),
                             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);
                 }
             }
@@ -1409,19 +1629,20 @@ public class ResourceManager {
         }
     }
 
-    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) {
@@ -1439,51 +1660,48 @@ public class ResourceManager {
         }
     }
 
-    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 resourceModel;
+            resourceModel = resourceN.setConfigInfo(configFilePath);
+            if (null == resourceModel) {
+                return false;
+            }
+            // Store the resource model in the local cache
+            resource.setResourceModelRef(resourceModel);
+
+            // Fetching the allowed values and range for all the attributes
+            Map<String, RemoteResourceAttribute> attributeMap = fetchResourceAttributesFromModel(resourceModel);
+            resource.setResourceAttributesMap(attributeMap);
+            // TODO: Printing the values for debugging
+            if (null != attributeMap) {
+                RemoteResourceAttribute.printAttributes(attributeMap);
+            }
         } catch (SimulatorException e) {
             Activator
                     .getDefault()
                     .getLogManager()
                     .log(Level.ERROR.ordinal(), new Date(),
                             Utility.getSimulatorErrorString(e, null));
-            return;
+            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.
     }
 }
index 0b566a0..de3f384 100644 (file)
@@ -53,6 +53,13 @@ public class PutPostAttributeModel {
         this.values = values;
     }
 
+    public void prependNewValue(String customValue) {
+        if (values.contains(customValue)) {
+            values.remove(customValue);
+        }
+        values.add(0, customValue);
+    }
+
     public boolean isModified() {
         return modified;
     }
@@ -79,5 +86,4 @@ public class PutPostAttributeModel {
     public String toString() {
         return attName + "," + attValue + "\n";
     }
-
 }
index 17a052e..04c39d1 100644 (file)
@@ -18,34 +18,25 @@ package oic.simulator.clientcontroller.remoteresource;
 
 import java.util.ArrayList;
 import java.util.Iterator;
-import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 
 import oic.simulator.clientcontroller.utils.Constants;
 
 import org.oic.simulator.SimulatorResourceModel;
-import org.oic.simulator.clientcontroller.SimulatorConnectivityType;
-import org.oic.simulator.clientcontroller.SimulatorRemoteResource;
+import org.oic.simulator.client.SimulatorRemoteResource;
 
 /**
  * This class represents a remote resource. It maintains all the necessary
  * information about the resource.
  */
 public class RemoteResource {
-    private String                               uId;
-    private String                               resourceURI;
-    private String                               host;
-    private LinkedList<String>                   resourceTypes;
-    private LinkedList<String>                   resourceInterfaces;
-    private SimulatorConnectivityType            connectivityType;
-    private boolean                              isObservable;
 
     private boolean                              observed;
 
     // Native object references
-    private SimulatorRemoteResource              resourceN;
-    private SimulatorResourceModel               resourceModel;
+    private SimulatorRemoteResource              remoteResourceRef;
+    private SimulatorResourceModel               resourceModelRef;
     private Map<String, RemoteResourceAttribute> resourceAttributesMap;
 
     private boolean                              configUploaded;
@@ -60,12 +51,12 @@ public class RemoteResource {
 
     private boolean                              isFavorite;
 
-    public SimulatorResourceModel getResourceModel() {
-        return resourceModel;
+    public SimulatorResourceModel getResourceModelRef() {
+        return resourceModelRef;
     }
 
-    public void setResourceModel(SimulatorResourceModel resourceModel) {
-        this.resourceModel = resourceModel;
+    public void setResourceModelRef(SimulatorResourceModel resourceModel) {
+        this.resourceModelRef = resourceModel;
     }
 
     public Map<String, RemoteResourceAttribute> getResourceAttributesMap() {
@@ -101,54 +92,6 @@ public class RemoteResource {
         this.postAutomtnId = postAutomtnId;
     }
 
-    public String getResourceURI() {
-        return resourceURI;
-    }
-
-    public void setResourceURI(String resourceURI) {
-        this.resourceURI = resourceURI;
-    }
-
-    public String getHost() {
-        return host;
-    }
-
-    public void setHost(String host) {
-        this.host = host;
-    }
-
-    public LinkedList<String> getResourceTypes() {
-        return resourceTypes;
-    }
-
-    public void setResourceTypes(LinkedList<String> resourceTypes) {
-        this.resourceTypes = resourceTypes;
-    }
-
-    public LinkedList<String> getResourceInterfaces() {
-        return resourceInterfaces;
-    }
-
-    public void setResourceInterfaces(LinkedList<String> resourceInterfaces) {
-        this.resourceInterfaces = resourceInterfaces;
-    }
-
-    public SimulatorConnectivityType getConnectivityType() {
-        return connectivityType;
-    }
-
-    public void setConnectivityType(SimulatorConnectivityType connectivityType) {
-        this.connectivityType = connectivityType;
-    }
-
-    public boolean isObservable() {
-        return isObservable;
-    }
-
-    public void setObservable(boolean isObservable) {
-        this.isObservable = isObservable;
-    }
-
     public boolean isGetAutomtnInProgress() {
         return getAutomtnInProgress;
     }
@@ -181,12 +124,12 @@ public class RemoteResource {
         this.configUploaded = configUploaded;
     }
 
-    public SimulatorRemoteResource getResource() {
-        return resourceN;
+    public SimulatorRemoteResource getRemoteResourceRef() {
+        return remoteResourceRef;
     }
 
-    public void setResource(SimulatorRemoteResource resource) {
-        this.resourceN = resource;
+    public void setRemoteResourceRef(SimulatorRemoteResource resource) {
+        this.remoteResourceRef = resource;
     }
 
     public boolean isObserved() {
@@ -226,14 +169,6 @@ public class RemoteResource {
         return String.valueOf(attribute.getAttributeValue());
     }
 
-    public String getuId() {
-        return uId;
-    }
-
-    public void setuId(String uId) {
-        this.uId = uId;
-    }
-
     public int getAutomationtype(int autoId) {
         if (getAutomtnId == autoId) {
             return Constants.GET_AUTOMATION_INDEX;
index 8a908cc..e014bdc 100644 (file)
@@ -21,8 +21,10 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
-import org.oic.simulator.ResourceAttribute;
-import org.oic.simulator.ResourceAttribute.Type;
+import org.oic.simulator.AttributeProperty.Type;
+import org.oic.simulator.AttributeValue;
+import org.oic.simulator.AttributeValue.ValueType;
+import org.oic.simulator.SimulatorResourceAttribute;
 
 /**
  * This class represents an attribute in the remote resource.
@@ -30,23 +32,27 @@ import org.oic.simulator.ResourceAttribute.Type;
 public class RemoteResourceAttribute {
 
     // Native object reference
-    private ResourceAttribute resourceAttribute;
+    private SimulatorResourceAttribute resourceAttributeRef;
 
-    private String            attributeName;
-    private Object            attributeValue;
-    private Type              attValType;
-    private Type              attValBaseType;
-    private List<Object>      allowedValues;
+    private String                     attributeName;
+    private Object                     attributeValue;
 
-    private Object            minValue;
-    private Object            maxValue;
+    private ValueType                  attValType;
+    private ValueType                  attValBaseType;
+    private int                        depth;
 
-    public ResourceAttribute getResourceAttribute() {
-        return resourceAttribute;
+    private Type                       valuesType;
+    private List<Object>               allowedValues;
+    private Object                     minValue;
+    private Object                     maxValue;
+
+    public SimulatorResourceAttribute getResourceAttributeRef() {
+        return resourceAttributeRef;
     }
 
-    public void setResourceAttribute(ResourceAttribute resourceAttribute) {
-        this.resourceAttribute = resourceAttribute;
+    public void setResourceAttributeRef(
+            SimulatorResourceAttribute resourceAttribute) {
+        this.resourceAttributeRef = resourceAttribute;
     }
 
     public String getAttributeName() {
@@ -112,7 +118,7 @@ public class RemoteResourceAttribute {
             clone.setAttValType(attribute.getAttValType());
             clone.setMinValue(attribute.getMinValue());
             clone.setMaxValue(attribute.getMaxValue());
-            clone.setResourceAttribute(null);
+            clone.setResourceAttributeRef(null);
         }
         return clone;
     }
@@ -132,18 +138,10 @@ public class RemoteResourceAttribute {
                 }
             }
         } else if (null != minValue && null != maxValue) {
-            if (attributeValue.getClass() == Integer.class) {
-                int min = (Integer) minValue;
-                int max = (Integer) maxValue;
-                for (int value = min; value <= max; value++) {
-                    valueList.add(String.valueOf(value));
-                }
-            } else if (attributeValue.getClass() == Double.class) {
-                double min = (Double) minValue;
-                double max = (Double) maxValue;
-                for (double value = min; value <= max; value++) {
-                    valueList.add(String.valueOf(value));
-                }
+            double min = (Double) minValue;
+            double max = (Double) maxValue;
+            for (double value = min; value <= max; value++) {
+                valueList.add(String.valueOf(value));
             }
         }
         if (valueList.size() < 1 && null != attributeValue) {
@@ -168,19 +166,35 @@ public class RemoteResourceAttribute {
         }
     }
 
-    public Type getAttValType() {
+    public ValueType getAttValType() {
         return attValType;
     }
 
-    public void setAttValType(Type attValType) {
+    public void setAttValType(ValueType attValType) {
         this.attValType = attValType;
     }
 
-    public Type getAttValBaseType() {
+    public ValueType getAttValBaseType() {
         return attValBaseType;
     }
 
-    public void setAttValBaseType(Type attValBaseType) {
+    public void setAttValBaseType(ValueType attValBaseType) {
         this.attValBaseType = attValBaseType;
     }
+
+    public Type getValuesType() {
+        return valuesType;
+    }
+
+    public void setValuesType(Type valuesType) {
+        this.valuesType = valuesType;
+    }
+
+    public int getDepth() {
+        return depth;
+    }
+
+    public void setDepth(int depth) {
+        this.depth = depth;
+    }
 }
\ No newline at end of file
diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/SerializedClientController.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/SerializedClientController.java
new file mode 100644 (file)
index 0000000..c41a96f
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package oic.simulator.clientcontroller.remoteresource;
+
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.List;
+
+public class SerializedClientController implements Serializable {
+
+    public List<String> getResourceTypes() {
+        return m_resourceTypes;
+    }
+
+    public void setResourceTypes(List<String> resourceTypes) {
+        this.m_resourceTypes = resourceTypes;
+    }
+
+    public List<String> getFavorites() {
+        return m_favorites;
+    }
+
+    public void setFavorites(List<String> favorites) {
+        this.m_favorites = favorites;
+    }
+
+    public void serialize(String filePath) throws Exception {
+        try {
+            FileOutputStream fileOut = new FileOutputStream(filePath);
+            ObjectOutputStream out = new ObjectOutputStream(fileOut);
+            out.writeObject(this);
+            out.close();
+            fileOut.close();
+        } catch (IOException i) {
+            throw new Exception("Failed to Serialize data : IOException");
+        }
+    }
+
+    public static SerializedClientController deSerialize(String filePath)
+            throws Exception {
+        SerializedClientController r = null;
+        try {
+            FileInputStream fileIn = new FileInputStream(filePath);
+            ObjectInputStream in = new ObjectInputStream(fileIn);
+            r = (SerializedClientController) in.readObject();
+            in.close();
+            fileIn.close();
+        } catch (IOException i) {
+            throw new Exception("Failed to DeSerialize data : IOException");
+        } catch (ClassNotFoundException c) {
+            throw new Exception("Failed to DeSerialize data : ClassNotFound");
+        }
+        return r;
+    }
+
+    private List<String> m_resourceTypes;
+    private List<String> m_favorites;
+
+}
\ No newline at end of file
index 53e73e5..eba2905 100644 (file)
 
 package oic.simulator.clientcontroller.utils;
 
-import org.oic.simulator.serviceprovider.AutomationType;
-
 /**
  * This class maintains all constants which are used throughout the client
  * controller plug-in.
  */
 public class Constants {
-    public static final String         FIND_PAGE_TITLE               = "Find Resources";
-
-    public static final String         FIND_PAGE_MESSAGE             = "Select the resource type of the resources to be discovered";
-
-    public static final int            FIND_RESOURCES_TIMEOUT        = 10;
-
-    public static final String         RESOURCE_URI                  = "Resource URI";
-    public static final String         CONNECTIVITY_TYPE             = "Connectivity Type";
-    public static final String         OBSERVABLE                    = "Observable";
-    public static final String         RESOURCE_TYPES                = "Resource Types";
-    public static final String         RESOURCE_INTERFACES           = "Resource Interfaces";
-
-    public static final String[]       META_PROPERTIES               = {
-            RESOURCE_URI, CONNECTIVITY_TYPE, OBSERVABLE, RESOURCE_TYPES,
-            RESOURCE_INTERFACES                                     };
-
-    public static final int            META_PROPERTY_COUNT           = META_PROPERTIES.length;
-
-    public static final AutomationType DEFAULT_AUTOMATION_TYPE       = AutomationType.NORMAL;
-
-    public static final int            DEFAULT_AUTOMATION_INTERVAL   = 500;
-
-    public static final String         YES                           = "Yes";
-    public static final String         NO                            = "No";
-
-    public static final String         GET                           = "Get";
-    public static final String         PUT                           = "Put";
-    public static final String         POST                          = "Post";
-    public static final String         OBSERVE                       = "Observe";
-    public static final String         STOP_OBSERVE                  = "Stop Observe";
-
-    public static final String         ENABLE                        = "Enable";
-    public static final String         DISABLE                       = "Disable";
-    public static final String         ENABLED                       = "Enabled";
-    public static final String         DISABLED                      = "Disabled";
-
-    public static final String         NOT_AVAILABLE                 = "Not Available";
-
-    public static final int            PROPER_LOG_TIME_TOKEN_LENGTH  = 3;
-
-    public static final int            LOG_SIZE                      = 1000;
-
-    public static final String         INFO_LOG                      = "info_log";
-    public static final String         WARNING_LOG                   = "warning_log";
-    public static final String         ERROR_LOG                     = "error_log";
-    public static final String         DEBUG_LOG                     = "debug_log";
-    public static final String         UNKNOWN_LOG                   = "unknown_log";
-
-    public static final String         CHECKED                       = "Checked";
-    public static final String         UNCHECKED                     = "Unchecked";
-
-    public static final String         INFO                          = "Info";
-    public static final String         WARNING                       = "Warning";
-    public static final String         ERROR                         = "Error";
-    public static final String         DEBUG                         = "Debug";
-    public static final String         UNKNOWN                       = "Unknown";
-
-    public static final String[]       BROWSE_RAML_FILTER_EXTENSIONS = new String[] {
-            "*.raml", "*"                                           };
-    public static final String[]       SAVE_LOG_FILTER_EXTENSIONS    = new String[] {
-            "*.log", "*"                                            };
-
-    public static final int            GET_AUTOMATION_INDEX          = 0;
-    public static final int            PUT_AUTOMATION_INDEX          = 1;
-    public static final int            POST_AUTOMATION_INDEX         = 2;
-    public static final int            DELETE_AUTOMATION_INDEX       = 3;
-
-    public static final String         OIC_R_LIGHT                   = "oic.r.light";
+    public static final String   FIND_PAGE_TITLE               = "Find Resources";
+
+    public static final String   FIND_PAGE_MESSAGE             = "Select the resource type of the resources to be discovered";
+
+    public static final int      FIND_RESOURCES_TIMEOUT        = 10;
+
+    public static final String   RESOURCE_URI                  = "Resource URI";
+    public static final String   ADDRESS                       = "Address";
+    public static final String   CONNECTIVITY_TYPE             = "Connectivity Type";
+    public static final String   OBSERVABLE                    = "Observable";
+    public static final String   RESOURCE_TYPES                = "Resource Types";
+    public static final String   RESOURCE_INTERFACES           = "Resource Interfaces";
+
+    public static final String[] META_PROPERTIES               = {
+            RESOURCE_URI, ADDRESS, CONNECTIVITY_TYPE, OBSERVABLE,
+            RESOURCE_TYPES, RESOURCE_INTERFACES               };
+
+    public static final int      META_PROPERTY_COUNT           = META_PROPERTIES.length;
+
+    public static final String   YES                           = "Yes";
+    public static final String   NO                            = "No";
+
+    public static final String   GET                           = "Get";
+    public static final String   PUT                           = "Put";
+    public static final String   POST                          = "Post";
+    public static final String   OBSERVE                       = "Observe";
+    public static final String   STOP_OBSERVE                  = "Stop Observe";
+
+    public static final String   ENABLE                        = "Enable";
+    public static final String   DISABLE                       = "Disable";
+    public static final String   ENABLED                       = "Enabled";
+    public static final String   DISABLED                      = "Disabled";
+
+    public static final String   NOT_AVAILABLE                 = "Not Available";
+
+    public static final int      PROPER_LOG_TIME_TOKEN_LENGTH  = 3;
+
+    public static final int      LOG_SIZE                      = 1000;
+
+    public static final String   INFO_LOG                      = "info_log";
+    public static final String   WARNING_LOG                   = "warning_log";
+    public static final String   ERROR_LOG                     = "error_log";
+    public static final String   DEBUG_LOG                     = "debug_log";
+    public static final String   UNKNOWN_LOG                   = "unknown_log";
+
+    public static final String   CHECKED                       = "Checked";
+    public static final String   UNCHECKED                     = "Unchecked";
+
+    public static final String   INFO                          = "Info";
+    public static final String   WARNING                       = "Warning";
+    public static final String   ERROR                         = "Error";
+    public static final String   DEBUG                         = "Debug";
+    public static final String   UNKNOWN                       = "Unknown";
+
+    public static final String[] BROWSE_RAML_FILTER_EXTENSIONS = new String[] {
+            "*.raml", "*"                                     };
+    public static final String[] SAVE_LOG_FILTER_EXTENSIONS    = new String[] {
+            "*.log", "*"                                      };
+
+    public static final int      GET_AUTOMATION_INDEX          = 0;
+    public static final int      PUT_AUTOMATION_INDEX          = 1;
+    public static final int      POST_AUTOMATION_INDEX         = 2;
+    public static final int      DELETE_AUTOMATION_INDEX       = 3;
+
+    // Device information
+    public static final String   DEVICE_NAME                   = "Name";
+    public static final String   DEVICE_ID                     = "Id";
+    public static final String   DEVICE_SPEC_VERSION           = "Spec Version";
+    public static final String   DEVICE_DMV_VERSION            = "DMV Version";
+
+    // Platform information
+    public static final String   PLATFORM_ID                   = "Id";
+    public static final String   PLATFORM_MANUFAC_NAME         = "Manufacturer Name";
+    public static final String   PLATFORM_MANUFAC_URL          = "Manufacturer URL";
+    public static final String   PLATFORM_MODEL_NO             = "Model Number";
+    public static final String   PLATFORM_DATE_OF_MANUFAC      = "Date of Manufacture";
+    public static final String   PLATFORM_VERSION              = "Version";
+    public static final String   PLATFORM_OS_VERSION           = "OS Version";
+    public static final String   PLATFORM_HARDWARE_VERSION     = "HardWare Version";
+    public static final String   PLATFORM_FIRMWARE_VERSION     = "Firmware Version";
+    public static final String   PLATFORM_SUPPORT_URL          = "Support URL";
+    public static final String   PLATFORM_SYSTEM_TIME          = "System Time";
 }
index af503ce..e61d484 100644 (file)
@@ -57,6 +57,7 @@ import org.eclipse.swt.widgets.Group;
 import org.eclipse.swt.widgets.Table;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.part.ViewPart;
+import org.oic.simulator.client.SimulatorRemoteResource.VerificationType;
 
 /**
  * This class manages and shows the attribute view in the perspective.
@@ -100,8 +101,6 @@ public class AttributeView extends ViewPart {
 
                     @Override
                     public void run() {
-                        System.out
-                                .println("AttributeView: onResourceSelectionChange");
                         resourceInSelection = resource;
 
                         // Set visibility of manual and automation controls
@@ -110,14 +109,11 @@ public class AttributeView extends ViewPart {
                         // Update the attribute table
                         if (null != attTblViewer
                                 && !attTblViewer.getControl().isDisposed()) {
-                            System.out.println("viewer is alive");
                             updateViewer(getData(resource));
                         }
 
                         // Update the observe status
                         updateObserve(resource);
-
-                        // Update the pay-load details if any
                     }
                 });
             }
@@ -131,30 +127,20 @@ public class AttributeView extends ViewPart {
 
                     @Override
                     public void run() {
-
-                        System.out.println("AttributeView: onGetCompleted");
                         if (null == resource) {
                             return;
                         }
                         // Update the attribute table
                         if (resourceInSelection != resource) {
-                            System.out
-                                    .println("AttributeView: get response arrived for a different resource");
                             return;
                         }
                         updateViewer(getData(resource));
 
                         // Update the observe status
                         updateObserve(resource);
-
-                        // Update the pay-load details if any
                     }
                 });
             }
-
-            @Override
-            public void onGetFailed(RemoteResource resource) {
-            }
         };
 
         putUIListener = new IPutUIListener() {
@@ -165,30 +151,20 @@ public class AttributeView extends ViewPart {
 
                     @Override
                     public void run() {
-
-                        System.out.println("AttributeView: onPutCompleted");
                         if (null == resource) {
                             return;
                         }
                         // Update the attribute table
                         if (resourceInSelection != resource) {
-                            System.out
-                                    .println("AttributeView: put response arrived for a different resource");
                             return;
                         }
                         updateViewer(getData(resource));
 
                         // Update the observe status
                         updateObserve(resource);
-
-                        // Update the pay-load details if any
                     }
                 });
             }
-
-            @Override
-            public void onPutFailed(RemoteResource resource) {
-            }
         };
 
         postUIListener = new IPostUIListener() {
@@ -199,30 +175,20 @@ public class AttributeView extends ViewPart {
 
                     @Override
                     public void run() {
-
-                        System.out.println("AttributeView: onPostCompleted");
                         if (null == resource) {
                             return;
                         }
                         // Update the attribute table
                         if (resourceInSelection != resource) {
-                            System.out
-                                    .println("AttributeView: post response arrived for a different resource");
                             return;
                         }
                         updateViewer(getData(resource));
 
                         // Update the observe status
                         updateObserve(resource);
-
-                        // Update the pay-load details if any
                     }
                 });
             }
-
-            @Override
-            public void onPostFailed(RemoteResource resource) {
-            }
         };
 
         observeUIListener = new IObserveUIListener() {
@@ -233,30 +199,20 @@ public class AttributeView extends ViewPart {
 
                     @Override
                     public void run() {
-
-                        System.out.println("AttributeView: onObserveCompleted");
                         if (null == resource) {
                             return;
                         }
                         // Update the attribute table
                         if (resourceInSelection != resource) {
-                            System.out
-                                    .println("AttributeView: observe response arrived for a different resource");
                             return;
                         }
                         updateViewer(getData(resource));
 
                         // Update the observe status
                         updateObserve(resource);
-
-                        // Update the pay-load details if any
                     }
                 });
             }
-
-            @Override
-            public void onObserveFailed(RemoteResource resource) {
-            }
         };
 
         verificationUIListener = new IVerificationUIListener() {
@@ -306,15 +262,10 @@ public class AttributeView extends ViewPart {
 
                     @Override
                     public void run() {
-
-                        System.out
-                                .println("AttributeView: onConfigurationUploaded");
                         if (null == resource) {
                             return;
                         }
                         if (resourceInSelection != resource) {
-                            System.out
-                                    .println("AttributeView: config upload response arrived for a different resource");
                             return;
                         }
                         if (!automateButton.isDisposed()) {
@@ -348,7 +299,6 @@ public class AttributeView extends ViewPart {
         }
         Map<String, RemoteResourceAttribute> attMap = resource
                 .getResourceAttributesMap();
-        System.out.println("AttributeView: \n" + attMap);
         return attMap;
     }
 
@@ -616,13 +566,29 @@ public class AttributeView extends ViewPart {
         observeResButton.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
+                boolean result;
                 if (observeResButton.getText().equals(Constants.OBSERVE)) {
-                    resourceManager.sendObserveRequest(resourceInSelection);
-                    observeResButton.setText(Constants.STOP_OBSERVE);
+                    result = resourceManager
+                            .sendObserveRequest(resourceInSelection);
+                    if (result) {
+                        observeResButton.setText(Constants.STOP_OBSERVE);
+                    } else {
+                        MessageDialog.openError(Display.getDefault()
+                                .getActiveShell(), "Observe failed",
+                                "Failed to observe the resource. Try again.");
+                    }
                 } else {
-                    resourceManager
-                            .sendCancelObserveRequest(resourceInSelection);
-                    observeResButton.setText(Constants.OBSERVE);
+                    result = resourceManager.sendCancelObserveRequest(
+                            resourceInSelection, true);
+                    if (result) {
+                        observeResButton.setText(Constants.OBSERVE);
+                    } else {
+                        MessageDialog
+                                .openError(Display.getDefault()
+                                        .getActiveShell(),
+                                        "Cancel Observe failed",
+                                        "Failed to stop observing the resource. Try again.");
+                    }
                 }
             }
         });
@@ -643,15 +609,123 @@ public class AttributeView extends ViewPart {
                         if (null == autoStatus) {
                             return;
                         }
+
+                        int startCount = 0;
+                        int stopCount = 0;
+                        boolean startGet, startPut, startPost;
+                        boolean stopGet, stopPut, stopPost;
+                        startGet = startPut = startPost = false;
+                        stopGet = stopPut = stopPost = false;
+                        String status = null;
+                        String startMsg = "Verification will be started for: ";
+                        String stopMsg = "Verification will be stopped for: ";
                         VerificationDialog ad = new VerificationDialog(Display
                                 .getDefault().getActiveShell(), autoStatus);
-                        ad.open();
+                        if (ad.open() == Window.OK) {
+                            Map<String, Boolean> oldStatus = resourceManager
+                                    .getAutomationStatus(resource);
+                            if (null == oldStatus || oldStatus.size() < 1) {
+                                status = "Failed to perform the requested operation.";
+                            } else {
+                                // GET
+                                if (oldStatus.get(Constants.GET) != autoStatus
+                                        .get(Constants.GET)) {
+                                    if (autoStatus.get(Constants.GET)) {
+                                        startMsg += Constants.GET;
+                                        startCount++;
+                                        startGet = true;
+                                    } else {
+                                        stopMsg += Constants.GET;
+                                        stopCount++;
+                                        stopGet = true;
+                                    }
+                                }
+                                // PUT
+                                if (oldStatus.get(Constants.PUT) != autoStatus
+                                        .get(Constants.PUT)) {
+                                    if (autoStatus.get(Constants.PUT)) {
+                                        if (startCount == 1) {
+                                            startMsg += ", ";
+                                        }
+                                        startMsg += Constants.PUT;
+                                        startCount++;
+                                        startPut = true;
+                                    } else {
+                                        if (stopCount == 1) {
+                                            stopMsg += ", ";
+                                        }
+                                        stopMsg += Constants.PUT;
+                                        stopCount++;
+                                        stopPut = true;
+                                    }
+
+                                }
+                                // POST
+                                if (oldStatus.get(Constants.POST) != autoStatus
+                                        .get(Constants.POST)) {
+                                    if (autoStatus.get(Constants.POST)) {
+                                        if (startCount > 0) {
+                                            startMsg += ", ";
+                                        }
+                                        startMsg += Constants.POST;
+                                        startCount++;
+                                        startPost = true;
+                                    } else {
+                                        if (stopCount > 0) {
+                                            stopMsg += ", ";
+                                        }
+                                        stopMsg += Constants.POST;
+                                        stopCount++;
+                                        stopPost = true;
+                                    }
+                                }
+                                if (startCount > 0) {
+                                    status = startMsg + ".";
+                                }
+                                if (stopCount > 0) {
+                                    if (startCount <= 0) {
+                                        status = stopMsg;
+                                    } else {
+                                        status += "\n" + stopMsg + ".";
+                                    }
+                                }
+                            }
+                            if (startCount == 0 && stopCount == 0) {
+                                MessageDialog.openInformation(Display
+                                        .getDefault().getActiveShell(),
+                                        "Verification", "No New Changes.");
+                            } else {
+                                boolean answer = MessageDialog.openQuestion(
+                                        Display.getDefault().getActiveShell(),
+                                        "Verification", status
+                                                + "\nDo you want to proceed?");
+                                if (answer) {
+                                    if (startGet || stopGet)
+                                        automate(VerificationType.GET,
+                                                autoStatus.get(Constants.GET));
+                                    if (startPut || stopPut)
+                                        automate(VerificationType.PUT,
+                                                autoStatus.get(Constants.PUT));
+                                    if (startPost || stopPost)
+                                        automate(VerificationType.POST,
+                                                autoStatus.get(Constants.POST));
+                                }
+                            }
+                        }
                     }
                 });
             }
         });
     }
 
+    private void automate(VerificationType type, boolean start) {
+        if (start) {
+            resourceManager.startAutomationRequest(type, resourceInSelection);
+        } else {
+            resourceManager.stopAutomationRequest(type, resourceInSelection);
+        }
+    }
+
     private void addManagerListeners() {
         resourceManager
                 .addResourceSelectionChangedUIListener(resourceSelectionChangedListener);
index ae9fa40..acf8933 100644 (file)
@@ -19,6 +19,7 @@ package oic.simulator.clientcontroller.view;
 import java.util.List;
 
 import oic.simulator.clientcontroller.Activator;
+import oic.simulator.clientcontroller.listener.IDevicePlatformInfoUIListener;
 import oic.simulator.clientcontroller.listener.IResourceSelectionChangedUIListener;
 import oic.simulator.clientcontroller.manager.ResourceManager;
 import oic.simulator.clientcontroller.remoteresource.MetaProperty;
@@ -30,10 +31,14 @@ import org.eclipse.jface.viewers.TableViewer;
 import org.eclipse.jface.viewers.TableViewerColumn;
 import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CTabFolder;
+import org.eclipse.swt.custom.CTabItem;
+import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Group;
 import org.eclipse.swt.widgets.Table;
 import org.eclipse.ui.part.ViewPart;
 
@@ -44,7 +49,9 @@ public class MetaPropertiesView extends ViewPart {
 
     public static final String                  VIEW_ID       = "oic.simulator.clientcontroller.view.metaproperties";
 
-    private TableViewer                         tableViewer;
+    private TableViewer                         defaultTblViewer;
+    private TableViewer                         deviceTblViewer;
+    private TableViewer                         platformTblViewer;
 
     private final String[]                      columnHeaders = { "Property",
             "Value"                                          };
@@ -52,9 +59,15 @@ public class MetaPropertiesView extends ViewPart {
     private final Integer[]                     columnWidth   = { 150, 150 };
 
     private IResourceSelectionChangedUIListener resourceSelectionChangedListener;
+    private IDevicePlatformInfoUIListener       devicePlatformInfoUIListener;
 
     private ResourceManager                     resourceManager;
 
+    private CTabFolder                          folder;
+    private CTabItem                            defaultPropTab;
+    private CTabItem                            devicePropTab;
+    private CTabItem                            platformPropTab;
+
     public MetaPropertiesView() {
 
         resourceManager = Activator.getDefault().getResourceManager();
@@ -67,8 +80,37 @@ public class MetaPropertiesView extends ViewPart {
 
                     @Override
                     public void run() {
-                        if (null != tableViewer) {
-                            updateViewer(getData(resource));
+                        updateUI(resource);
+                    }
+                });
+            }
+        };
+
+        devicePlatformInfoUIListener = new IDevicePlatformInfoUIListener() {
+
+            @Override
+            public void onPlatformInfoFound() {
+                Display.getDefault().asyncExec(new Runnable() {
+
+                    @Override
+                    public void run() {
+                        if (null != deviceTblViewer) {
+                            updateViewer(deviceTblViewer, getDevicePropData());
+                        }
+                    }
+                });
+
+            }
+
+            @Override
+            public void onDeviceInfoFound() {
+                Display.getDefault().asyncExec(new Runnable() {
+
+                    @Override
+                    public void run() {
+                        if (null != platformTblViewer) {
+                            updateViewer(platformTblViewer,
+                                    getPlatformPropData());
                         }
                     }
                 });
@@ -76,48 +118,164 @@ public class MetaPropertiesView extends ViewPart {
         };
     }
 
+    private void updateUI(final RemoteResource resource) {
+        if (null != defaultTblViewer) {
+            updateViewer(defaultTblViewer, getDefaultPropData(resource));
+        }
+        if (null != deviceTblViewer) {
+            updateViewer(deviceTblViewer, getDevicePropData());
+        }
+        if (null != platformTblViewer) {
+            updateViewer(platformTblViewer, getPlatformPropData());
+        }
+    }
+
     @Override
     public void createPartControl(Composite parent) {
-        parent.setLayout(new GridLayout(1, false));
+        parent.setLayout(new GridLayout());
+        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        parent.setLayoutData(gd);
+
+        // Create a Tab Folder.
+        folder = new CTabFolder(parent, SWT.BORDER);
+        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        folder.setLayoutData(gd);
+        folder.setSimple(false);
+        folder.setUnselectedCloseVisible(false);
+        folder.setUnselectedImageVisible(false);
+
+        createDefaultPropertiesTab();
+
+        createDevicePropertiesTab();
+
+        createPlatformPropertiesTab();
+
+        folder.setSelection(defaultPropTab);
+
+        addManagerListeners();
+
+        // Check whether there is any resource selected already
+        updateUI(null);
+    }
+
+    private void createDefaultPropertiesTab() {
+        defaultPropTab = new CTabItem(folder, SWT.NULL);
+        defaultPropTab.setText("Default");
+
+        // Adding the group to the folder.
+        Group propGroup = new Group(folder, SWT.NONE);
 
-        tableViewer = new TableViewer(parent, SWT.SINGLE | SWT.H_SCROLL
+        Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
+        propGroup.setBackground(color);
+
+        propGroup.setLayout(new GridLayout());
+        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        propGroup.setLayoutData(gd);
+
+        defaultTblViewer = new TableViewer(propGroup, SWT.SINGLE | SWT.H_SCROLL
                 | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
 
-        createColumns(tableViewer);
+        createColumns(defaultTblViewer);
 
-        // make lines and header visible
-        final Table table = tableViewer.getTable();
+        // Make lines and header visible
+        final Table table = defaultTblViewer.getTable();
         table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
         table.setHeaderVisible(true);
         table.setLinesVisible(true);
 
-        tableViewer.setContentProvider(new PropertycontentProvider());
+        defaultTblViewer.setContentProvider(new PropertycontentProvider());
 
-        addManagerListeners();
+        defaultPropTab.setControl(propGroup);
+    }
 
-        // Check whether there is any resource selected already
-        List<MetaProperty> propertyList = getData(null);
-        if (null != propertyList) {
-            updateViewer(propertyList);
-        }
+    private void createDevicePropertiesTab() {
+        devicePropTab = new CTabItem(folder, SWT.NULL);
+        devicePropTab.setText("Device");
+
+        // Adding the group to the folder.
+        Group propGroup = new Group(folder, SWT.NONE);
+
+        Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
+        propGroup.setBackground(color);
+
+        propGroup.setLayout(new GridLayout());
+        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        propGroup.setLayoutData(gd);
+
+        deviceTblViewer = new TableViewer(propGroup, SWT.SINGLE | SWT.H_SCROLL
+                | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
+
+        createColumns(deviceTblViewer);
+
+        // Make lines and header visible
+        final Table table = deviceTblViewer.getTable();
+        table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+        table.setHeaderVisible(true);
+        table.setLinesVisible(true);
+
+        deviceTblViewer.setContentProvider(new PropertycontentProvider());
+
+        devicePropTab.setControl(propGroup);
+    }
+
+    private void createPlatformPropertiesTab() {
+        platformPropTab = new CTabItem(folder, SWT.NULL);
+        platformPropTab.setText("Platform");
 
+        // Adding the group to the folder.
+        Group propGroup = new Group(folder, SWT.NONE);
+
+        Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
+        propGroup.setBackground(color);
+
+        propGroup.setLayout(new GridLayout());
+        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        propGroup.setLayoutData(gd);
+
+        platformTblViewer = new TableViewer(propGroup, SWT.SINGLE
+                | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
+
+        createColumns(platformTblViewer);
+
+        // Make lines and header visible
+        final Table table = platformTblViewer.getTable();
+        table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+        table.setHeaderVisible(true);
+        table.setLinesVisible(true);
+
+        platformTblViewer.setContentProvider(new PropertycontentProvider());
+
+        platformPropTab.setControl(propGroup);
     }
 
-    private List<MetaProperty> getData(RemoteResource resource) {
+    private List<MetaProperty> getDefaultPropData(RemoteResource resource) {
         if (null == resource) {
             resource = Activator.getDefault().getResourceManager()
                     .getCurrentResourceInSelection();
         }
         List<MetaProperty> metaPropertyList = resourceManager
-                .getMetaProperties(resource);
+                .getDefaultProperties(resource);
         return metaPropertyList;
     }
 
-    private void updateViewer(List<MetaProperty> metaPropertyList) {
-        if (null != tableViewer) {
-            Table tbl = tableViewer.getTable();
+    private List<MetaProperty> getDevicePropData() {
+        List<MetaProperty> metaPropertyList = resourceManager
+                .getDeviceProperties();
+        return metaPropertyList;
+    }
+
+    private List<MetaProperty> getPlatformPropData() {
+        List<MetaProperty> metaPropertyList = resourceManager
+                .getPlatformProperties();
+        return metaPropertyList;
+    }
+
+    private void updateViewer(TableViewer tblViewer,
+            List<MetaProperty> metaPropertyList) {
+        if (null != tblViewer) {
+            Table tbl = tblViewer.getTable();
             if (null != metaPropertyList) {
-                tableViewer.setInput(metaPropertyList.toArray());
+                tblViewer.setInput(metaPropertyList.toArray());
                 if (!tbl.isDisposed()) {
                     tbl.setLinesVisible(true);
                 }
@@ -167,6 +325,8 @@ public class MetaPropertiesView extends ViewPart {
     private void addManagerListeners() {
         resourceManager
                 .addResourceSelectionChangedUIListener(resourceSelectionChangedListener);
+        resourceManager
+                .addDevicePlatformInfoUIListener(devicePlatformInfoUIListener);
     }
 
     class PropertycontentProvider implements IStructuredContentProvider {
@@ -183,7 +343,6 @@ public class MetaPropertiesView extends ViewPart {
         public Object[] getElements(Object element) {
             return (Object[]) element;
         }
-
     }
 
     @Override
index db5e91f..b059a4d 100644 (file)
@@ -60,6 +60,7 @@ import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.dialogs.FilteredTree;
 import org.eclipse.ui.dialogs.PatternFilter;
 import org.eclipse.ui.part.ViewPart;
+import org.oic.simulator.SimulatorException;
 
 /**
  * This class manages and shows the resource manager view in the perspective.
@@ -266,68 +267,10 @@ public class ResourceManagerView extends ViewPart {
                         for (int index = 0; index < items.length; index++) {
                             items[index].dispose();
                         }
-                        MenuItem uploadRAMLItem = new MenuItem(menu, SWT.NONE);
-                        uploadRAMLItem.setText("Upload RAML Configuration");
-                        uploadRAMLItem
-                                .addSelectionListener(new SelectionAdapter() {
-                                    @Override
-                                    public void widgetSelected(SelectionEvent e) {
-                                        // Open the RAML configuration dialog if
-                                        // RAML file is not yet uploaded for the
-                                        // currently selected resource
-                                        RemoteResource resource = resourceManager
-                                                .getCurrentResourceInSelection();
-                                        if (null == resource) {
-                                            return;
-                                        }
-                                        if (!resource.isConfigUploaded()) {
-                                            // Open the dialog in a separate
-                                            // UI thread.
-                                            PlatformUI.getWorkbench()
-                                                    .getDisplay()
-                                                    .syncExec(new Thread() {
-                                                        @Override
-                                                        public void run() {
-                                                            LoadRAMLDialog ramlDialog = new LoadRAMLDialog(
-                                                                    Display.getDefault()
-                                                                            .getActiveShell());
-                                                            if (ramlDialog
-                                                                    .open() != Window.OK) {
-                                                                return;
-                                                            }
-                                                            String configFilePath = ramlDialog
-                                                                    .getConfigFilePath();
-                                                            if (null == configFilePath
-                                                                    || configFilePath
-                                                                            .length() < 1) {
-                                                                MessageDialog
-                                                                        .openInformation(
-                                                                                Display.getDefault()
-                                                                                        .getActiveShell(),
-                                                                                "Invalid RAML Config path",
-                                                                                "Configuration file path is invalid.");
-                                                                return;
-                                                            }
-                                                            resourceManager
-                                                                    .setConfigFilePath(
-                                                                            resourceManager
-                                                                                    .getCurrentResourceInSelection(),
-                                                                            configFilePath);
-                                                        }
-                                                    });
-                                        } else {
-                                            MessageDialog
-                                                    .openInformation(Display
-                                                            .getDefault()
-                                                            .getActiveShell(),
-                                                            "Already Uploaded",
-                                                            "Configuration file for the selected resource is already uploaded");
-                                        }
-                                    }
-                                });
+                        setupUploadRamlMenuItem(menu);
 
-                        RemoteResource resource = resourceManager
-                                .getCurrentResourceInSelection();
+                        final RemoteResource resource = (RemoteResource) ((IStructuredSelection) treeViewer
+                                .getSelection()).getFirstElement();
                         if (null == resource) {
                             return;
                         }
@@ -339,12 +282,6 @@ public class ResourceManagerView extends ViewPart {
                                 .addSelectionListener(new SelectionAdapter() {
                                     @Override
                                     public void widgetSelected(SelectionEvent e) {
-                                        RemoteResource resource = (RemoteResource) ((IStructuredSelection) treeViewer
-                                                .getSelection())
-                                                .getFirstElement();
-                                        if (null == resource) {
-                                            return;
-                                        }
                                         if (!resource.isFavorite()) {
                                             resourceManager
                                                     .addResourcetoFavorites(resource);
@@ -412,6 +349,9 @@ public class ResourceManagerView extends ViewPart {
                         for (int index = 0; index < items.length; index++) {
                             items[index].dispose();
                         }
+
+                        setupUploadRamlMenuItem(menu);
+
                         MenuItem addToFavMenuItem = new MenuItem(menu, SWT.NONE);
                         addToFavMenuItem.setText("Remove from favorites");
                         addToFavMenuItem
@@ -437,6 +377,73 @@ public class ResourceManagerView extends ViewPart {
         }
     }
 
+    private void setupUploadRamlMenuItem(Menu menu) {
+        MenuItem uploadRAMLItem = new MenuItem(menu, SWT.NONE);
+        uploadRAMLItem.setText("Upload RAML Configuration");
+        uploadRAMLItem.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                // Open the RAML configuration dialog if
+                // RAML file is not yet uploaded for the
+                // currently selected resource
+                RemoteResource resource = resourceManager
+                        .getCurrentResourceInSelection();
+                if (null == resource) {
+                    return;
+                }
+                if (resource.isConfigUploaded()) {
+                    boolean answer = MessageDialog
+                            .openQuestion(
+                                    Display.getDefault().getActiveShell(),
+                                    "Upload Another RAML",
+                                    "This resource is already configured with RAML.\n"
+                                            + "Do you want to upload a new configuration?");
+                    if (!answer) {
+                        return;
+                    }
+                }
+                // Open the dialog in a separate
+                // UI thread.
+                PlatformUI.getWorkbench().getDisplay().syncExec(new Thread() {
+                    @Override
+                    public void run() {
+                        LoadRAMLDialog ramlDialog = new LoadRAMLDialog(Display
+                                .getDefault().getActiveShell());
+                        if (ramlDialog.open() != Window.OK) {
+                            return;
+                        }
+                        String configFilePath = ramlDialog.getConfigFilePath();
+                        if (null == configFilePath
+                                || configFilePath.length() < 1) {
+                            MessageDialog.openInformation(Display.getDefault()
+                                    .getActiveShell(),
+                                    "Invalid RAML Config path",
+                                    "Configuration file path is invalid.");
+                            return;
+                        }
+                        try {
+                            boolean result = resourceManager.setConfigFilePath(
+                                    resourceManager
+                                            .getCurrentResourceInSelection(),
+                                    configFilePath);
+                            if (!result) {
+                                MessageDialog
+                                        .openInformation(Display.getDefault()
+                                                .getActiveShell(),
+                                                "Operation failed",
+                                                "Failed to obtain the details from the given RAML.");
+                            }
+                        } catch (SimulatorException e) {
+                            MessageDialog.openInformation(Display.getDefault()
+                                    .getActiveShell(), "Invalid RAML",
+                                    "Given configuration file is invalid.");
+                        }
+                    }
+                });
+            }
+        });
+    }
+
     private void addUIListeners() {
         findResButton.addSelectionListener(new SelectionAdapter() {
             @Override
@@ -736,15 +743,11 @@ class TreeLabelProvider extends LabelProvider {
     @Override
     public String getText(Object element) {
         RemoteResource resource = (RemoteResource) element;
-        return resource.getResourceURI();
+        return resource.getRemoteResourceRef().getURI();
     }
 
-    // TODO: Commenting temporarily until resource icons are finalized.
-    /*@Override
+    @Override
     public Image getImage(Object element) {
-        RemoteResource resource = (RemoteResource) element;
-        ResourceManager resourceManager = Activator.getDefault()
-                .getResourceManager();
-        return resourceManager.getImage(resource.getResourceURI());
-    }*/
+        return null;
+    }
 }
\ No newline at end of file
index d19e1d4..90ace2b 100644 (file)
 
 package oic.simulator.clientcontroller.view.dialogs;
 
+import java.io.FileInputStream;
+
 import oic.simulator.clientcontroller.utils.Constants;
 
+import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.dialogs.TitleAreaDialog;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionAdapter;
@@ -100,10 +103,11 @@ public class LoadRAMLDialog extends TitleAreaDialog {
                         .getWorkbench().getDisplay().getActiveShell(), SWT.NONE);
                 fileDialog
                         .setFilterExtensions(Constants.BROWSE_RAML_FILTER_EXTENSIONS);
-                configFilePath = fileDialog.open();
-                if (null == configFilePath) {
-                    System.out.println("Config file path is null");
+                String path = fileDialog.open();
+                if (null == path) {
                     configFilePath = "";
+                } else {
+                    configFilePath = path;
                 }
                 locationTxt.setText(configFilePath);
             }
@@ -115,6 +119,25 @@ public class LoadRAMLDialog extends TitleAreaDialog {
     }
 
     @Override
+    protected void okPressed() {
+        configFilePath = locationTxt.getText();
+        if (null == configFilePath) {
+            return;
+        }
+        try {
+            new FileInputStream(configFilePath);
+        } catch (Exception e) {
+            MessageDialog
+                    .openError(getShell(), "Invalid File",
+                            "File doesn't exist. Either the file path or file name is invalid.");
+            // TODO: Instead of MessageDialog, errors may be shown on wizard
+            // itself.
+            return;
+        }
+        close();
+    }
+
+    @Override
     public boolean isHelpAvailable() {
         return false;
     }
index 0938acc..934cbb3 100644 (file)
 
 package oic.simulator.clientcontroller.view.dialogs;
 
+import java.util.Iterator;
 import java.util.List;
 
 import oic.simulator.clientcontroller.Activator;
+import oic.simulator.clientcontroller.manager.ResourceManager;
 import oic.simulator.clientcontroller.remoteresource.PutPostAttributeModel;
 import oic.simulator.clientcontroller.utils.Constants;
 
 import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.dialogs.TitleAreaDialog;
 import org.eclipse.jface.viewers.CellEditor;
 import org.eclipse.jface.viewers.CheckboxCellEditor;
 import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.ComboBoxCellEditor;
 import org.eclipse.jface.viewers.EditingSupport;
 import org.eclipse.jface.viewers.IStructuredContentProvider;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.StyledCellLabelProvider;
 import org.eclipse.jface.viewers.TableViewer;
 import org.eclipse.jface.viewers.TableViewerColumn;
-import org.eclipse.jface.viewers.TextCellEditor;
 import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.jface.viewers.ViewerCell;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CCombo;
 import org.eclipse.swt.events.ModifyEvent;
 import org.eclipse.swt.events.ModifyListener;
 import org.eclipse.swt.graphics.Image;
@@ -45,9 +49,9 @@ import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.Text;
 
 /**
  * This dialog is used for generating a POST request.
@@ -66,6 +70,7 @@ public class PostRequestDialog extends TitleAreaDialog {
             List<PutPostAttributeModel> modelList) {
         super(parentShell);
         this.modelList = modelList;
+        resourceManager = Activator.getDefault().getResourceManager();
     }
 
     @Override
@@ -139,6 +144,7 @@ public class PostRequestDialog extends TitleAreaDialog {
                 }
             }
         });
+
         attValue.setEditingSupport(new AttributeValueEditor(attTblViewer));
 
         TableViewerColumn updateColumn = new TableViewerColumn(tableViewer,
@@ -203,62 +209,97 @@ public class PostRequestDialog extends TitleAreaDialog {
 
     class AttributeValueEditor extends EditingSupport {
         private final TableViewer viewer;
-        private final CellEditor  editor;
-        private final Text txt;
+        private CCombo            comboBox;
+
         public AttributeValueEditor(TableViewer viewer) {
             super(viewer);
             this.viewer = viewer;
-            editor = new TextCellEditor(viewer.getTable());
-            txt = (Text)editor.getControl();
-            if(null != txt) {
-                txt.addModifyListener(new ModifyListener() {
+        }
+
+        @Override
+        protected boolean canEdit(Object arg0) {
+            return true;
+        }
+
+        @Override
+        protected CellEditor getCellEditor(Object element) {
+            PutPostAttributeModel attributeInSelection = (PutPostAttributeModel) element;
+
+            String values[] = null;
+            List<String> valueSet = attributeInSelection.getValues();
+            values = convertListToStringArray(valueSet);
+
+            ComboBoxCellEditor comboEditor = new ComboBoxCellEditor(
+                    viewer.getTable(), values);
+            comboBox = (CCombo) comboEditor.getControl();
+            if (null != comboBox) {
+                comboBox.addModifyListener(new ModifyListener() {
                     @Override
                     public void modifyText(ModifyEvent e) {
-                        IStructuredSelection selection = (IStructuredSelection)AttributeValueEditor.this.viewer.getSelection();
-                        PutPostAttributeModel att = (PutPostAttributeModel)selection.getFirstElement();
-                        if(null == att) {
+                        IStructuredSelection selection = (IStructuredSelection) AttributeValueEditor.this.viewer
+                                .getSelection();
+                        PutPostAttributeModel att = (PutPostAttributeModel) selection
+                                .getFirstElement();
+                        if (null == att) {
                             return;
                         }
-                        String newValue = txt.getText();
-                        if(null != newValue && !newValue.isEmpty()) {
+                        String newValue = comboBox.getText();
+                        if (null != newValue && !newValue.isEmpty()) {
                             att.setModified(true);
-                        }
-                        else {
+                        } else {
                             att.setModified(false);
                         }
                         AttributeValueEditor.this.viewer.update(att, null);
                     }
                 });
-
             }
-        }
-
-        @Override
-        protected boolean canEdit(Object arg0) {
-            return true;
-        }
-
-        @Override
-        protected CellEditor getCellEditor(Object element) {
-            return editor;
+            return comboEditor;
         }
 
         @Override
         protected Object getValue(Object element) {
-            PutPostAttributeModel model = (PutPostAttributeModel) element;
-            return model.getAttValue();
+            int indexOfItem = 0;
+            PutPostAttributeModel att = (PutPostAttributeModel) element;
+            String valueString = att.getAttValue();
+            List<String> valueSet = att.getValues();
+            if (null != valueSet) {
+                indexOfItem = valueSet.indexOf(valueString);
+            }
+            if (indexOfItem == -1) {
+                indexOfItem = 0;
+            }
+            return indexOfItem;
         }
 
         @Override
         protected void setValue(Object element, Object value) {
-            PutPostAttributeModel model = (PutPostAttributeModel) element;
-            // Compare the actual value and the new value
-            // If there is a change, then its corresponding check box should be
-            // checked.
-            String newValue = String.valueOf(value);
-            model.setAttValue(newValue);
+            PutPostAttributeModel att = (PutPostAttributeModel) element;
+            int index;
+            try {
+                index = Integer.parseInt(String.valueOf(value));
+            } catch (NumberFormatException nfe) {
+                index = -1;
+            }
+            String newValue;
+            if (index == -1) {
+                newValue = comboBox.getText();
+                att.prependNewValue(newValue);
+            } else {
+                newValue = att.getValues().get(index);
+            }
+            att.setAttValue(newValue);
             viewer.update(element, null);
         }
+
+        public String[] convertListToStringArray(List<String> valueList) {
+            String[] strArr;
+            if (null != valueList && valueList.size() > 0) {
+                strArr = valueList.toArray(new String[1]);
+            } else {
+                strArr = new String[1];
+            }
+            return strArr;
+        }
     }
 
     class UpdateEditor extends EditingSupport {
@@ -294,4 +335,25 @@ public class PostRequestDialog extends TitleAreaDialog {
             viewer.update(element, null);
         }
     }
+
+    @Override
+    protected void okPressed() {
+        String value;
+        PutPostAttributeModel attModel;
+        Iterator<PutPostAttributeModel> itr;
+        itr = modelList.iterator();
+        while (itr.hasNext()) {
+            attModel = itr.next();
+            if (null == attModel) {
+                return;
+            }
+            value = attModel.getAttValue();
+            if (null == value || value.isEmpty()) {
+                MessageDialog.openError(Display.getDefault().getActiveShell(),
+                        "Empty value", "Attribute value should not be empty.");
+                return;
+            }
+        }
+        close();
+    }
 }
index 3ba0c87..69dbeeb 100644 (file)
 
 package oic.simulator.clientcontroller.view.dialogs;
 
+import java.util.Iterator;
 import java.util.List;
 
 import oic.simulator.clientcontroller.remoteresource.PutPostAttributeModel;
 
 import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.dialogs.TitleAreaDialog;
 import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.ComboBoxCellEditor;
 import org.eclipse.jface.viewers.EditingSupport;
 import org.eclipse.jface.viewers.IStructuredContentProvider;
 import org.eclipse.jface.viewers.StyledCellLabelProvider;
 import org.eclipse.jface.viewers.TableViewer;
 import org.eclipse.jface.viewers.TableViewerColumn;
-import org.eclipse.jface.viewers.TextCellEditor;
 import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.jface.viewers.ViewerCell;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CCombo;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Table;
 
@@ -148,12 +152,11 @@ public class PutRequestDialog extends TitleAreaDialog {
 
     class AttributeValueEditor extends EditingSupport {
         private final TableViewer viewer;
-        private final CellEditor  editor;
+        private CCombo            comboBox;
 
         public AttributeValueEditor(TableViewer viewer) {
             super(viewer);
             this.viewer = viewer;
-            editor = new TextCellEditor(viewer.getTable());
         }
 
         @Override
@@ -163,21 +166,62 @@ public class PutRequestDialog extends TitleAreaDialog {
 
         @Override
         protected CellEditor getCellEditor(Object element) {
-            return editor;
+            PutPostAttributeModel attributeInSelection = (PutPostAttributeModel) element;
+
+            String values[] = null;
+            List<String> valueSet = attributeInSelection.getValues();
+            values = convertListToStringArray(valueSet);
+
+            ComboBoxCellEditor comboEditor = new ComboBoxCellEditor(
+                    viewer.getTable(), values);
+            comboBox = (CCombo) comboEditor.getControl();
+            return comboEditor;
         }
 
         @Override
         protected Object getValue(Object element) {
-            PutPostAttributeModel model = (PutPostAttributeModel) element;
-            return model.getAttValue();
+            int indexOfItem = 0;
+            PutPostAttributeModel att = (PutPostAttributeModel) element;
+            String valueString = att.getAttValue();
+            List<String> valueSet = att.getValues();
+            if (null != valueSet) {
+                indexOfItem = valueSet.indexOf(valueString);
+            }
+            if (indexOfItem == -1) {
+                indexOfItem = 0;
+            }
+            return indexOfItem;
         }
 
         @Override
         protected void setValue(Object element, Object value) {
-            PutPostAttributeModel model = (PutPostAttributeModel) element;
-            model.setAttValue(String.valueOf(value));
+            PutPostAttributeModel att = (PutPostAttributeModel) element;
+            int index;
+            try {
+                index = Integer.parseInt(String.valueOf(value));
+            } catch (NumberFormatException nfe) {
+                index = -1;
+            }
+            if (index == -1) {
+                String customValue = comboBox.getText();
+                att.prependNewValue(customValue);
+                att.setAttValue(customValue);
+            } else {
+                String attValue = att.getValues().get(index);
+                att.setAttValue(attValue);
+            }
             viewer.update(element, null);
         }
+
+        public String[] convertListToStringArray(List<String> valueList) {
+            String[] strArr;
+            if (null != valueList && valueList.size() > 0) {
+                strArr = valueList.toArray(new String[1]);
+            } else {
+                strArr = new String[1];
+            }
+            return strArr;
+        }
     }
 
     public List<PutPostAttributeModel> getUpdatedModel() {
@@ -202,4 +246,25 @@ public class PutRequestDialog extends TitleAreaDialog {
         }
         return super.createButton(parent, id, label, defaultButton);
     }
+
+    @Override
+    protected void okPressed() {
+        String value;
+        PutPostAttributeModel attModel;
+        Iterator<PutPostAttributeModel> itr;
+        itr = modelList.iterator();
+        while (itr.hasNext()) {
+            attModel = itr.next();
+            if (null == attModel) {
+                return;
+            }
+            value = attModel.getAttValue();
+            if (null == value || value.isEmpty()) {
+                MessageDialog.openError(Display.getDefault().getActiveShell(),
+                        "Empty value", "Attribute value should not be empty.");
+                return;
+            }
+        }
+        close();
+    }
 }
index a221760..b6ab69f 100644 (file)
@@ -20,12 +20,9 @@ import java.util.ArrayList;
 import java.util.Map;
 import java.util.Set;
 
-import oic.simulator.clientcontroller.Activator;
-import oic.simulator.clientcontroller.manager.ResourceManager;
 import oic.simulator.clientcontroller.utils.Constants;
 
 import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.dialogs.TrayDialog;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionAdapter;
@@ -35,7 +32,6 @@ import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Group;
 import org.eclipse.swt.widgets.Shell;
 
@@ -89,38 +85,18 @@ public class VerificationDialog extends TrayDialog {
 
                 @Override
                 public void widgetSelected(SelectionEvent e) {
-                    boolean checked = checkbox.getSelection();
-                    boolean answer = MessageDialog.openQuestion(Display
-                            .getDefault().getActiveShell(), "Verification",
-                            "Do you want to "
-                                    + (checked ? "enable" : "disable")
-                                    + " the verification?");
-                    if (!answer) {
-                        checkbox.setSelection(!checked);
-                        checked = !checked;
-                    } else {
-                        ResourceManager resourceManager = Activator
-                                .getDefault().getResourceManager();
-                        String reqTypeTxt = checkbox.getText();
-                        int reqType;
-                        if (reqTypeTxt.equals("Get")) {
-                            reqType = Constants.GET_AUTOMATION_INDEX;
-                        } else if (reqTypeTxt.equals("Put")) {
-                            reqType = Constants.PUT_AUTOMATION_INDEX;
-                        } else {// if(reqTypeTxt.equals("Post")) {
-                            reqType = Constants.POST_AUTOMATION_INDEX;
-                        }
-                        if (checked) {
-                            resourceManager.startAutomationRequest(reqType,
-                                    resourceManager
-                                            .getCurrentResourceInSelection());
-                        } else {
-                            resourceManager.stopAutomationRequest(reqType,
-                                    resourceManager
-                                            .getCurrentResourceInSelection());
-                        }
+                    Button btn = (Button) e.getSource();
+                    if (null == btn) {
+                        return;
+                    }
+                    String btnText = btn.getText();
+                    if (btnText.equalsIgnoreCase(Constants.GET)) {
+                        automationStatus.put(Constants.GET, btn.getSelection());
+                    } else if (btnText.equalsIgnoreCase(Constants.PUT)) {
+                        automationStatus.put(Constants.PUT, btn.getSelection());
+                    } else if (btnText.equalsIgnoreCase(Constants.POST)) {
+                        automationStatus.put(Constants.POST, btn.getSelection());
                     }
-                    automationStatus.put(str, checked);
                 }
             });
         }
@@ -139,4 +115,8 @@ public class VerificationDialog extends TrayDialog {
     public boolean isHelpAvailable() {
         return false;
     }
+
+    public Map<String, Boolean> getAutomationStatus() {
+        return automationStatus;
+    }
 }
index 8940d85..8dc5385 100644 (file)
@@ -4,4 +4,5 @@ bin.includes = META-INF/,\
                .,\
                icons/,\
                plugin.xml,\
-               libs/,\
\ No newline at end of file
+               libs/,\
+
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/collection_resource.gif b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/collection_resource.gif
new file mode 100644 (file)
index 0000000..173661c
Binary files /dev/null and b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/collection_resource.gif differ
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/device.gif b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/device.gif
new file mode 100644 (file)
index 0000000..e3ecc55
Binary files /dev/null and b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/device.gif differ
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/single_resource.gif b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/single_resource.gif
new file mode 100644 (file)
index 0000000..0f07692
Binary files /dev/null and b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/single_resource.gif differ
index 52ec74b..8fe0d3a 100644 (file)
             restorable="true">
          </view>
          <view category="oic.simulator.serviceprovider.category"
-            class="oic.simulator.serviceprovider.view.MultiResourceOrchestrationView"
+            class="oic.simulator.serviceprovider.view.DevicePlatformInfoView"
             icon="icons/oic_logo_16x16.png"
-            id="oic.simulator.serviceprovider.view.orchestration"
-            name="Multi-Resource Automation"
+            id="oic.simulator.serviceprovider.view.devplatinfo"
+            name="Device/Platform Info"
             restorable="true">
          </view>
          <view category="oic.simulator.serviceprovider.category"
@@ -76,7 +76,7 @@
                id="oic.simulator.serviceprovider.view.attribute">
          </viewShortcut>
          <viewShortcut
-               id="oic.simulator.serviceprovider.view.orchestration">
+               id="oic.simulator.serviceprovider.view.devplatinfo">
          </viewShortcut>
          <viewShortcut
                id="oic.simulator.serviceprovider.view.log">
index 215fb5f..395a744 100644 (file)
 
 package oic.simulator.serviceprovider.listener;
 
+import oic.simulator.serviceprovider.model.SingleResource;
+
 /**
  * Interface through which the automation events are notified to the UI
  * listeners.
  */
 public interface IAutomationUIListener {
-    public void onResourceAutomationStart(String resourceURI);
+    public void onResourceAutomationStart(SingleResource resource);
 
-    public void onAutomationComplete(String resourceURI, String attName);
+    public void onAutomationComplete(SingleResource resource, String attName);
 }
index 3beb52a..a3bde63 100644 (file)
 
 package oic.simulator.serviceprovider.listener;
 
+import oic.simulator.serviceprovider.model.Resource;
+
 /**
  * Interface through which the resource observer events are sent to the UI
  * listeners.
  */
 public interface IObserverListChangedUIListener {
-    public void onObserverListChanged(String resourceURI);
+    public void onObserverListChanged(Resource resource);
 }
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IPropertiesChangedUIListener.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IPropertiesChangedUIListener.java
new file mode 100644 (file)
index 0000000..864d5c0
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package oic.simulator.serviceprovider.listener;
+
+/**
+ * Interface through which the resource property change UI events are sent to
+ * the other UI listeners.
+ */
+public interface IPropertiesChangedUIListener {
+    public void onResourcePropertyChange();
+
+    public void onDevicePropertyChange();
+}
\ No newline at end of file
index b5eb331..fac61eb 100644 (file)
 
 package oic.simulator.serviceprovider.listener;
 
+import oic.simulator.serviceprovider.model.ResourceType;
+
 /**
  * Interface through which the resource creation/deletion events are sent to the
  * UI listeners.
  */
 public interface IResourceListChangedUIListener {
-    public void onResourceCreation();
+    public void onResourceCreation(ResourceType type);
+
+    public void onResourceDeletion(ResourceType type);
 
-    public void onResourceDeletion();
+    public void onResourceListUpdate(ResourceType type);
 }
\ No newline at end of file
index b778e0e..e55539d 100644 (file)
 
 package oic.simulator.serviceprovider.listener;
 
-import java.util.Set;
-
-import oic.simulator.serviceprovider.resource.ModelChangeNotificationType;
-import oic.simulator.serviceprovider.resource.LocalResourceAttribute;
+import oic.simulator.serviceprovider.model.Resource;
 
 /**
  * Interface through which the resource model change events are sent to the UI
  * listeners.
  */
 public interface IResourceModelChangedUIListener {
-    public void onResourceModelChange(
-            ModelChangeNotificationType notificationType, String resourceURI,
-            Set<LocalResourceAttribute> valueChangeSet);
+    public void onResourceModelChange(Resource resource);
 }
 
 package oic.simulator.serviceprovider.listener;
 
+import oic.simulator.serviceprovider.model.Device;
+import oic.simulator.serviceprovider.model.Resource;
+
 /**
  * Interface through which the resource selection UI event is sent to the other
  * UI listeners.
  */
-public interface IResourceSelectionChangedUIListener {
-    public void onResourceSelectionChange();
+public interface ISelectionChangedUIListener {
+    public void onResourceSelectionChange(Resource resource);
+
+    public void onDeviceSelectionChange(Device dev);
 }
\ No newline at end of file
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/Data.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/Data.java
new file mode 100644 (file)
index 0000000..17517f1
--- /dev/null
@@ -0,0 +1,294 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package oic.simulator.serviceprovider.manager;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import oic.simulator.serviceprovider.model.CollectionResource;
+import oic.simulator.serviceprovider.model.Device;
+import oic.simulator.serviceprovider.model.Resource;
+import oic.simulator.serviceprovider.model.SingleResource;
+
+public class Data {
+    private Map<String, SingleResource>     singleResourceMap;
+
+    private Map<String, CollectionResource> collectionResourceMap;
+
+    private Map<String, Device>             deviceMap;
+
+    // Holds resource type as key and a resource URI set as values.
+    // Helps in performing operations based on resource type.
+    private Map<String, Set<String>>        resTypeToResUriMap;
+
+    public Data() {
+        singleResourceMap = new HashMap<String, SingleResource>();
+        collectionResourceMap = new HashMap<String, CollectionResource>();
+        deviceMap = new HashMap<String, Device>();
+        resTypeToResUriMap = new HashMap<String, Set<String>>();
+    }
+
+    public synchronized void addResource(Resource resource) {
+        if (null == resource) {
+            return;
+        }
+        if (resource instanceof SingleResource) {
+            singleResourceMap.put(resource.getResourceURI(),
+                    (SingleResource) resource);
+        } else {
+            collectionResourceMap.put(resource.getResourceURI(),
+                    (CollectionResource) resource);
+        }
+        addToTypeAndUriMap(resource);
+    }
+
+    public synchronized void addToTypeAndUriMap(Resource resource) {
+        if (null == resource) {
+            return;
+        }
+        Set<String> resTypes = resource.getResourceTypes();
+        if (null == resTypes || resTypes.isEmpty()) {
+            return;
+        }
+        String uri = resource.getResourceURI();
+        if (null == uri || uri.isEmpty()) {
+            return;
+        }
+        Iterator<String> itr = resTypes.iterator();
+        String rType;
+        Set<String> newTypeSet;
+        while (itr.hasNext()) {
+            rType = itr.next();
+            newTypeSet = resTypeToResUriMap.get(rType);
+            if (null == newTypeSet) {
+                newTypeSet = new HashSet<String>();
+                resTypeToResUriMap.put(rType, newTypeSet);
+            }
+            newTypeSet.add(uri);
+        }
+    }
+
+    public void addDevice(Device dev) {
+        if (null == dev) {
+            return;
+        }
+        synchronized (deviceMap) {
+            deviceMap.put(dev.getDeviceName(), dev);
+        }
+    }
+
+    public synchronized void deleteResource(Resource resource) {
+        if (null == resource) {
+            return;
+        }
+        if (resource instanceof SingleResource) {
+            singleResourceMap.remove(resource.getResourceURI());
+        } else {
+            collectionResourceMap.remove(resource.getResourceURI());
+        }
+        removeFromTypeAndUriMap(resource);
+    }
+
+    public synchronized void deleteDevice(Device dev) {
+        if (null == dev) {
+            return;
+        }
+        deviceMap.remove(dev.getDeviceName());
+    }
+
+    public synchronized void removeFromTypeAndUriMap(Resource resource) {
+        if (null == resource) {
+            return;
+        }
+        Set<String> resTypes = resource.getResourceTypes();
+        if (null == resTypes || resTypes.isEmpty()) {
+            return;
+        }
+        String uri = resource.getResourceURI();
+        if (null == uri || uri.isEmpty()) {
+            return;
+        }
+        Iterator<String> itr = resTypes.iterator();
+        String rType;
+        Set<String> newTypeSet;
+        while (itr.hasNext()) {
+            rType = itr.next();
+            newTypeSet = resTypeToResUriMap.get(rType);
+            if (null != newTypeSet) {
+                newTypeSet.remove(uri);
+            }
+            if (null == newTypeSet || newTypeSet.isEmpty()) {
+                resTypeToResUriMap.remove(rType);
+            }
+        }
+    }
+
+    public List<SingleResource> getSingleResources() {
+        List<SingleResource> resources;
+        synchronized (singleResourceMap) {
+            if (singleResourceMap.isEmpty()) {
+                return null;
+            }
+            resources = new ArrayList<SingleResource>();
+            Set<String> uriSet = singleResourceMap.keySet();
+            Iterator<String> itr = uriSet.iterator();
+            while (itr.hasNext()) {
+                resources.add(singleResourceMap.get(itr.next()));
+            }
+        }
+        return resources;
+    }
+
+    public List<CollectionResource> getCollectionResources() {
+        List<CollectionResource> resources;
+        synchronized (collectionResourceMap) {
+            if (collectionResourceMap.isEmpty()) {
+                return null;
+            }
+            resources = new ArrayList<CollectionResource>();
+            Set<String> uriSet = collectionResourceMap.keySet();
+            Iterator<String> itr = uriSet.iterator();
+            while (itr.hasNext()) {
+                resources.add(collectionResourceMap.get(itr.next()));
+            }
+        }
+        return resources;
+    }
+
+    public List<Resource> getResources() {
+        if (singleResourceMap.isEmpty() && collectionResourceMap.isEmpty()) {
+            return null;
+        }
+        List<Resource> resourceList = new ArrayList<Resource>();
+        synchronized (singleResourceMap) {
+            Set<String> uriSet = singleResourceMap.keySet();
+            Iterator<String> itr = uriSet.iterator();
+            while (itr.hasNext()) {
+                resourceList.add(singleResourceMap.get(itr.next()));
+            }
+        }
+        synchronized (collectionResourceMap) {
+            Set<String> uriSet = collectionResourceMap.keySet();
+            Iterator<String> itr = uriSet.iterator();
+            while (itr.hasNext()) {
+                resourceList.add(collectionResourceMap.get(itr.next()));
+            }
+        }
+        return resourceList;
+    }
+
+    public List<Device> getDevices() {
+        List<Device> devices;
+        synchronized (deviceMap) {
+            if (deviceMap.isEmpty()) {
+                return null;
+            }
+            devices = new ArrayList<Device>();
+            Set<String> uriSet = deviceMap.keySet();
+            Iterator<String> itr = uriSet.iterator();
+            while (itr.hasNext()) {
+                devices.add(deviceMap.get(itr.next()));
+            }
+        }
+        return devices;
+    }
+
+    public synchronized boolean isResourceExist(String resourceURI) {
+        if (null == resourceURI || resourceURI.isEmpty()) {
+            return false;
+        }
+        if ((null != singleResourceMap && singleResourceMap
+                .containsKey(resourceURI))
+                || (null != collectionResourceMap && collectionResourceMap
+                        .containsKey(resourceURI))) {
+            return true;
+        }
+        return false;
+    }
+
+    public synchronized boolean isAnyResourceExist() {
+        return ((null != singleResourceMap && !singleResourceMap.isEmpty()) || (null != collectionResourceMap && !collectionResourceMap
+                .isEmpty()));
+    }
+
+    public void changeResourceURI(Resource resource, String curURI,
+            String newURI) {
+        if (null == resource || null == curURI || null == newURI) {
+            return;
+        }
+        if (resource instanceof SingleResource) {
+            synchronized (singleResourceMap) {
+                singleResourceMap.remove(curURI);
+                singleResourceMap.put(newURI, (SingleResource) resource);
+            }
+        } else {
+            synchronized (collectionResourceMap) {
+                collectionResourceMap.remove(curURI);
+                collectionResourceMap
+                        .put(newURI, (CollectionResource) resource);
+            }
+        }
+        resource.setResourceURI(newURI);
+    }
+
+    public void changeDeviceName(Device dev, String curName, String newName) {
+        if (null == dev || null == curName || null == newName) {
+            return;
+        }
+        synchronized (deviceMap) {
+            deviceMap.remove(curName);
+            deviceMap.put(newName, dev);
+        }
+        dev.setDeviceName(newName);
+    }
+
+    public SingleResource getSingleResourceByURI(String resourceURI) {
+        if (null == resourceURI) {
+            return null;
+        }
+        SingleResource res;
+        synchronized (singleResourceMap) {
+            res = singleResourceMap.get(resourceURI);
+        }
+        return res;
+    }
+
+    public CollectionResource getCollectionResourceByURI(String resourceURI) {
+        if (null == resourceURI) {
+            return null;
+        }
+        CollectionResource res;
+        synchronized (collectionResourceMap) {
+            res = collectionResourceMap.get(resourceURI);
+        }
+        return res;
+    }
+
+    public Resource getResourceByURI(String resourceURI) {
+        Resource res = getSingleResourceByURI(resourceURI);
+        if (null == res) {
+            res = getCollectionResourceByURI(resourceURI);
+        }
+        return res;
+    }
+
+}
index efdb577..9e58424 100644 (file)
@@ -55,6 +55,15 @@ public class ImageManager {
         r.put(Constants.NOTIFY_BUTTON_SELECTED, ImageDescriptor
                 .createFromURL(bundle.getEntry("icons/button_pressed.PNG")));
 
+        // Resource icons based on the resource type
+        r.put(Constants.SINGLE_RESOURCE, ImageDescriptor.createFromURL(bundle
+                .getEntry("/icons/single_resource.gif")));
+        r.put(Constants.COLLECTION_RESOURCE, ImageDescriptor
+                .createFromURL(bundle
+                        .getEntry("/icons/collection_resource.gif")));
+        r.put(Constants.DEVICE, ImageDescriptor.createFromURL(bundle
+                .getEntry("/icons/device.gif")));
+
         // Log View related icons
         r.put(Constants.DEBUG_LOG, ImageDescriptor.createFromURL(bundle
                 .getEntry("/icons/debug_log.gif")));
index e7ca9a9..765d87c 100644 (file)
@@ -26,11 +26,13 @@ import oic.simulator.logger.LoggerCallback;
 import oic.simulator.serviceprovider.Activator;
 import oic.simulator.serviceprovider.listener.ILogUIListener;
 import oic.simulator.serviceprovider.utils.Constants;
+import oic.simulator.serviceprovider.utils.Utility;
 
 import org.eclipse.jface.resource.ImageRegistry;
 import org.eclipse.swt.graphics.Image;
 import org.oic.simulator.ILogger;
 import org.oic.simulator.ILogger.Level;
+import org.oic.simulator.SimulatorException;
 import org.oic.simulator.SimulatorManager;
 
 /**
@@ -55,7 +57,14 @@ public class LogManager {
 
         // Set the logger callback with the native layer
         logger = new LoggerCallback();
-        SimulatorManager.setLogger(logger);
+        try {
+            SimulatorManager.setLogger(logger);
+        } catch (SimulatorException e) {
+            log(Level.ERROR.ordinal(),
+                    new Date(),
+                    "Failed to register the logger.\n"
+                            + Utility.getSimulatorErrorString(e, null));
+        }
     }
 
     private static class LogManagerSynchronizerThread implements Runnable {
index 2a0473b..3e80941 100644 (file)
@@ -20,40 +20,44 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.Vector;
 
 import oic.simulator.serviceprovider.Activator;
-import oic.simulator.serviceprovider.listener.IAutomationUIListener;
-import oic.simulator.serviceprovider.listener.IObserverListChangedUIListener;
-import oic.simulator.serviceprovider.listener.IResourceListChangedUIListener;
-import oic.simulator.serviceprovider.listener.IResourceModelChangedUIListener;
-import oic.simulator.serviceprovider.listener.IResourceSelectionChangedUIListener;
-import oic.simulator.serviceprovider.resource.LocalResourceAttribute;
-import oic.simulator.serviceprovider.resource.MetaProperty;
-import oic.simulator.serviceprovider.resource.ModelChangeNotificationType;
-import oic.simulator.serviceprovider.resource.SimulatorResource;
+import oic.simulator.serviceprovider.model.CollectionResource;
+import oic.simulator.serviceprovider.model.Device;
+import oic.simulator.serviceprovider.model.LocalResourceAttribute;
+import oic.simulator.serviceprovider.model.MetaProperty;
+import oic.simulator.serviceprovider.model.Resource;
+import oic.simulator.serviceprovider.model.ResourceType;
+import oic.simulator.serviceprovider.model.SRMItem;
+import oic.simulator.serviceprovider.model.SingleResource;
 import oic.simulator.serviceprovider.utils.Constants;
 import oic.simulator.serviceprovider.utils.Utility;
 
-import org.eclipse.swt.graphics.Image;
-import org.oic.simulator.IAutomation;
+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.ILogger.Level;
-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.SimulatorException;
 import org.oic.simulator.SimulatorManager;
+import org.oic.simulator.SimulatorResourceAttribute;
 import org.oic.simulator.SimulatorResourceModel;
-import org.oic.simulator.serviceprovider.AutomationType;
-import org.oic.simulator.serviceprovider.IObserver;
-import org.oic.simulator.serviceprovider.IResourceModelChangedListener;
-import org.oic.simulator.serviceprovider.ObserverInfo;
-import org.oic.simulator.serviceprovider.SimulatorResourceServer;
+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;
+import org.oic.simulator.server.SimulatorResource.ObserverListener;
+import org.oic.simulator.server.SimulatorResource.ResourceModelChangeListener;
+import org.oic.simulator.server.SimulatorSingleResource;
 
 /**
  * This class acts as an interface between the simulator java SDK and the
@@ -64,46 +68,67 @@ import org.oic.simulator.serviceprovider.SimulatorResourceServer;
  */
 public class ResourceManager {
 
-    private Map<String, Map<String, SimulatorResource>> resourceMap;
+    private Data                           data;
 
-    private Map<String, ArrayList<String>>              orderedResourceUriMap;
+    private Resource                       currentResourceInSelection;
 
-    private Map<String, String>                         displayNameMap;
+    private Device                         currentDeviceInSelection;
 
-    private SimulatorResource                           currentResourceInSelection;
+    private ResourceModelChangeListener    resourceModelChangeListener;
 
-    private List<IResourceListChangedUIListener>        resourceListChangedUIListeners;
+    private AutoUpdateListener             automationListener;
 
-    private List<IResourceSelectionChangedUIListener>   resourceSelectionChangedUIListeners;
+    private ObserverListener               observer;
 
-    private List<IResourceModelChangedUIListener>       resourceModelChangedUIListeners;
+    private NotificationSynchronizerThread synchronizerThread;
 
-    private List<IAutomationUIListener>                 automationUIListeners;
+    private Thread                         threadHandle;
 
-    private List<IObserverListChangedUIListener>        observerUIListeners;
-
-    private IResourceModelChangedListener               resourceModelChangeListener;
-
-    private IAutomation                                 automationListener;
-
-    private IObserver                                   observer;
-
-    private NotificationSynchronizerThread              synchronizerThread;
-
-    private Thread                                      threadHandle;
+    private String                         deviceName;
+    private PlatformInfo                   platformInfo;
 
     public ResourceManager() {
-        resourceMap = new HashMap<String, Map<String, SimulatorResource>>();
-        orderedResourceUriMap = new HashMap<String, ArrayList<String>>();
-        displayNameMap = new HashMap<String, String>();
+        data = new Data();
 
-        resourceListChangedUIListeners = new ArrayList<IResourceListChangedUIListener>();
-        resourceSelectionChangedUIListeners = new ArrayList<IResourceSelectionChangedUIListener>();
-        resourceModelChangedUIListeners = new ArrayList<IResourceModelChangedUIListener>();
-        automationUIListeners = new ArrayList<IAutomationUIListener>();
-        observerUIListeners = new ArrayList<IObserverListChangedUIListener>();
+        // 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));
+        }
 
-        resourceModelChangeListener = new IResourceModelChangedListener() {
+        resourceModelChangeListener = new ResourceModelChangeListener() {
 
             @Override
             public void onResourceModelChanged(final String resourceURI,
@@ -115,59 +140,44 @@ public class ResourceManager {
                         if (null == resourceURI || null == resourceModelN) {
                             return;
                         }
-                        SimulatorResource resource = getSimulatorResourceByURI(resourceURI);
+
+                        Resource resource = data.getResourceByURI(resourceURI);
                         if (null == resource) {
                             return;
                         }
 
-                        ModelChangeNotificationType notificationType;
-                        // Fetch the resource attributes
-                        Map<String, LocalResourceAttribute> resourceAttributeMapNew;
-                        resourceAttributeMapNew = fetchResourceAttributesFromModel(resourceModelN);
-                        if (null == resourceAttributeMapNew) {
-                            resource.setResourceAttributesMap(null);
-                            resourceModelChangedUINotification(
-                                    ModelChangeNotificationType.NO_ATTRIBUTES_IN_MODEL,
-                                    resourceURI, null);
-                            return;
-                        }
+                        resource.setResourceModel(resourceModelN);
 
-                        // Update the resource with new model data
-                        Map<String, LocalResourceAttribute> resourceAttributeMapOld;
-                        resourceAttributeMapOld = resource
-                                .getResourceAttributesMap();
-                        if (null == resourceAttributeMapOld) {
-                            resource.setResourceAttributesMap(resourceAttributeMapNew);
-                            resourceModelChangedUINotification(
-                                    ModelChangeNotificationType.ATTRIBUTE_ADDED,
-                                    resourceURI, null);
-                            return;
-                        }
-                        Set<LocalResourceAttribute> valueChangeSet = new HashSet<LocalResourceAttribute>();
-                        notificationType = compareAndUpdateLocalAttributes(
-                                resourceAttributeMapOld,
-                                resourceAttributeMapNew, valueChangeSet);
-                        if (notificationType != ModelChangeNotificationType.NONE) {
-                            // Update the UI listeners
-                            resourceModelChangedUINotification(
-                                    notificationType, resourceURI,
-                                    valueChangeSet);
+                        // 7. Fetch the resource attributes.
+                        Map<String, LocalResourceAttribute> resourceAttributeMap;
+                        try {
+                            resourceAttributeMap = fetchResourceAttributesFromModel(resourceModelN);
+                            if (null != resourceAttributeMap) {
+                                resource.setResourceAttributes(resourceAttributeMap);
+                            }
+                        } catch (SimulatorException e) {
+                            // TODO Auto-generated catch block
+                            e.printStackTrace();
                         }
+
+                        UiListenerHandler.getInstance()
+                                .resourceModelChangedUINotification(resource);
                     }
                 });
             }
         };
 
-        automationListener = new IAutomation() {
+        automationListener = new AutoUpdateListener() {
 
             @Override
-            public void onAutomationComplete(final String resourceURI,
+            public void onUpdateComplete(final String resourceURI,
                     final int automationId) {
                 synchronizerThread.addToQueue(new Runnable() {
 
                     @Override
                     public void run() {
-                        SimulatorResource resource = getSimulatorResourceByURI(resourceURI);
+                        SingleResource resource = data
+                                .getSingleResourceByURI(resourceURI);
                         if (null == resource) {
                             return;
                         }
@@ -176,7 +186,9 @@ public class ResourceManager {
                         if (resource.isResourceAutomationInProgress()) {
                             changeResourceLevelAutomationStatus(resource, false);
                             // Notify the UI listeners
-                            automationCompleteUINotification(resourceURI, null);
+                            UiListenerHandler.getInstance()
+                                    .automationCompleteUINotification(resource,
+                                            null);
                         } else if (resource.isAttributeAutomationInProgress()) {
                             // Find the attribute with the given automation id
                             LocalResourceAttribute attribute;
@@ -186,30 +198,37 @@ public class ResourceManager {
                                 attribute.setAutomationInProgress(false);
                                 resource.setAttributeAutomationInProgress(isAnyAttributeInAutomation(resource));
                                 // Notify the UI listeners
-                                automationCompleteUINotification(resourceURI,
-                                        attribute.getAttributeName());
+                                UiListenerHandler
+                                        .getInstance()
+                                        .automationCompleteUINotification(
+                                                resource,
+                                                attribute
+                                                        .getResourceAttributeRef()
+                                                        .name());
+                            } else {
+                                // TODO: Temporarily reset the attribute
+                                // automation status to false for making
+                                // resource-level automation work after
+                                // attribute-level automations.
+                                resource.setAttributeAutomationInProgress(false);
                             }
-                        } else {
-                            // Ignoring the notification as there are no
-                            // known automation for the current resource.
                         }
                     }
                 });
             }
         };
 
-        observer = new IObserver() {
+        observer = new ObserverListener() {
 
-            @Override
             public void onObserverChanged(final String resourceURI,
-                    final int status, final ObserverInfo observer) {
+                    final int status, final Observer observer) {
                 new Thread() {
                     @Override
                     public void run() {
                         if (null == resourceURI || null == observer) {
                             return;
                         }
-                        SimulatorResource resource = getSimulatorResourceByURI(resourceURI);
+                        Resource resource = data.getResourceByURI(resourceURI);
                         if (null == resource) {
                             return;
                         }
@@ -220,10 +239,21 @@ public class ResourceManager {
                             resource.removeObserverInfo(observer);
                         }
                         // Notify the UI listeners
-                        observerListChangedUINotification(resourceURI);
+                        UiListenerHandler.getInstance()
+                                .observerListChangedUINotification(resource);
                     }
                 }.start();
             }
+
+            @Override
+            public void onObserverAdded(String resourceURI, Observer observer) {
+                onObserverChanged(resourceURI, 0, observer);
+            }
+
+            @Override
+            public void onObserverRemoved(String resourceURI, Observer observer) {
+                onObserverChanged(resourceURI, 1, observer);
+            }
         };
 
         synchronizerThread = new NotificationSynchronizerThread();
@@ -273,891 +303,1319 @@ public class ResourceManager {
         }
     }
 
-    public void addResourceListChangedUIListener(
-            IResourceListChangedUIListener resourceListChangedUIListener) {
-        synchronized (resourceListChangedUIListeners) {
-            resourceListChangedUIListeners.add(resourceListChangedUIListener);
-        }
+    public String getDeviceName() {
+        return deviceName;
     }
 
-    public void addResourceSelectionChangedUIListener(
-            IResourceSelectionChangedUIListener resourceSelectionChangedUIListener) {
-        synchronized (resourceSelectionChangedUIListeners) {
-            resourceSelectionChangedUIListeners
-                    .add(resourceSelectionChangedUIListener);
+    public void setDeviceName(String deviceName) {
+        this.deviceName = deviceName;
+        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));
+        }
+    }
+
+    public List<MetaProperty> getPlatformInfo() {
+        List<MetaProperty> metaProperties = new ArrayList<MetaProperty>();
+        metaProperties.add(new MetaProperty(Constants.PLATFORM_ID, platformInfo
+                .getPlatformID()));
+        metaProperties.add(new MetaProperty(Constants.PLATFORM_MANUFAC_NAME,
+                platformInfo.getManufacturerName()));
+        metaProperties.add(new MetaProperty(Constants.PLATFORM_MANUFAC_URL,
+                platformInfo.getManufacturerUrl()));
+        metaProperties.add(new MetaProperty(Constants.PLATFORM_MODEL_NO,
+                platformInfo.getModelNumber()));
+        metaProperties.add(new MetaProperty(Constants.PLATFORM_DATE_OF_MANUFAC,
+                platformInfo.getDateOfManufacture()));
+        metaProperties.add(new MetaProperty(Constants.PLATFORM_VERSION,
+                platformInfo.getPlatformVersion()));
+        metaProperties.add(new MetaProperty(Constants.PLATFORM_OS_VERSION,
+                platformInfo.getOperationSystemVersion()));
+        metaProperties.add(new MetaProperty(
+                Constants.PLATFORM_HARDWARE_VERSION, platformInfo
+                        .getHardwareVersion()));
+        metaProperties.add(new MetaProperty(
+                Constants.PLATFORM_FIRMWARE_VERSION, platformInfo
+                        .getFirmwareVersion()));
+        metaProperties.add(new MetaProperty(Constants.PLATFORM_SUPPORT_URL,
+                platformInfo.getSupportUrl()));
+        metaProperties.add(new MetaProperty(Constants.PLATFORM_SYSTEM_TIME,
+                platformInfo.getSystemTime()));
+        return metaProperties;
+    }
+
+    public void setPlatformInfo(List<MetaProperty> metaProperties) {
+        if (null == metaProperties || metaProperties.size() < 1) {
+            return;
         }
-    }
-
-    public void addResourceModelChangedUIListener(
-            IResourceModelChangedUIListener resourceModelChangedUIListener) {
-        synchronized (resourceModelChangedUIListeners) {
-            resourceModelChangedUIListeners.add(resourceModelChangedUIListener);
+        Iterator<MetaProperty> itr = metaProperties.iterator();
+        MetaProperty prop;
+        String propName;
+        String propValue;
+        while (itr.hasNext()) {
+            prop = itr.next();
+            propName = prop.getPropName();
+            propValue = prop.getPropValue();
+            if (propName.equals(Constants.PLATFORM_ID)) {
+                platformInfo.setPlatformID(propValue);
+            } else if (propName.equals(Constants.PLATFORM_MANUFAC_NAME)) {
+                platformInfo.setManufacturerName(propValue);
+            } else if (propName.equals(Constants.PLATFORM_MANUFAC_URL)) {
+                platformInfo.setManufacturerUrl(propValue);
+            } else if (propName.equals(Constants.PLATFORM_MODEL_NO)) {
+                platformInfo.setModelNumber(propValue);
+            } else if (propName.equals(Constants.PLATFORM_DATE_OF_MANUFAC)) {
+                platformInfo.setDateOfManufacture(propValue);
+            } else if (propName.equals(Constants.PLATFORM_VERSION)) {
+                platformInfo.setPlatformVersion(propValue);
+            } else if (propName.equals(Constants.PLATFORM_OS_VERSION)) {
+                platformInfo.setOperationSystemVersion(propValue);
+            } else if (propName.equals(Constants.PLATFORM_HARDWARE_VERSION)) {
+                platformInfo.setHardwareVersion(propValue);
+            } else if (propName.equals(Constants.PLATFORM_FIRMWARE_VERSION)) {
+                platformInfo.setFirmwareVersion(propValue);
+            } else if (propName.equals(Constants.PLATFORM_SUPPORT_URL)) {
+                platformInfo.setSupportUrl(propValue);
+            } else if (propName.equals(Constants.PLATFORM_SYSTEM_TIME)) {
+                platformInfo.setSystemTime(propValue);
+            }
+        }
+        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));
         }
     }
 
-    public void addAutomationUIListener(
-            IAutomationUIListener automationUIListener) {
-        synchronized (automationUIListeners) {
-            automationUIListeners.add(automationUIListener);
-        }
+    public synchronized Resource getCurrentResourceInSelection() {
+        return currentResourceInSelection;
     }
 
-    public void addObserverListChangedUIListener(
-            IObserverListChangedUIListener observerListChangedUIListener) {
-        synchronized (observerUIListeners) {
-            observerUIListeners.add(observerListChangedUIListener);
-        }
+    public synchronized void setCurrentResourceInSelection(Resource resource) {
+        this.currentResourceInSelection = resource;
     }
 
-    public void removeResourceListChangedUIListener(
-            IResourceListChangedUIListener listener) {
-        synchronized (resourceListChangedUIListeners) {
-            if (null != listener && resourceListChangedUIListeners.size() > 0) {
-                resourceListChangedUIListeners.remove(listener);
-            }
-        }
+    public synchronized Device getCurrentDeviceInSelection() {
+        return currentDeviceInSelection;
     }
 
-    public void removeResourceSelectionChangedUIListener(
-            IResourceSelectionChangedUIListener listener) {
-        synchronized (resourceSelectionChangedUIListeners) {
-            if (null != listener
-                    && resourceSelectionChangedUIListeners.size() > 0) {
-                resourceSelectionChangedUIListeners.remove(listener);
-            }
-        }
+    public synchronized void setCurrentDeviceInSelection(Device dev) {
+        this.currentDeviceInSelection = dev;
     }
 
-    public void removeResourceModelChangedUIListener(
-            IResourceModelChangedUIListener listener) {
-        synchronized (resourceModelChangedUIListeners) {
-            if (null != listener && resourceModelChangedUIListeners.size() > 0) {
-                resourceModelChangedUIListeners.remove(listener);
-            }
-        }
+    public boolean isResourceExist(String resourceURI) {
+        return data.isResourceExist(resourceURI);
     }
 
-    public void removeAutomationUIListener(IAutomationUIListener listener) {
-        synchronized (automationUIListeners) {
-            if (null != listener && automationUIListeners.size() > 0) {
-                automationUIListeners.remove(listener);
-            }
-        }
+    public boolean isAnyResourceExist() {
+        return data.isAnyResourceExist();
     }
 
-    public void removeObserverListChangedUIListener(
-            IObserverListChangedUIListener listener) {
-        synchronized (observerUIListeners) {
-            if (null != listener && observerUIListeners.size() > 0) {
-                observerUIListeners.remove(listener);
-            }
+    public boolean createSingleResource(SingleResource 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.SINGLE,
+                            resource.getResourceName(),
+                            resource.getResourceURI(), resType);
+            if (null == jSimulatorResource
+                    || !(jSimulatorResource instanceof SimulatorSingleResource)) {
+                return false;
+            }
+            SimulatorSingleResource jSimulatorSingleResource = (SimulatorSingleResource) jSimulatorResource;
+            resource.setSimulatorResource(jSimulatorSingleResource);
 
-    public synchronized SimulatorResource getCurrentResourceInSelection() {
-        return currentResourceInSelection;
-    }
+            // 2. Cancel observable property if requested by user.
+            if (!resource.isObservable()) {
+                jSimulatorSingleResource.setObservable(false);
+            }
 
-    public synchronized void setCurrentResourceInSelection(
-            SimulatorResource resource) {
-        this.currentResourceInSelection = resource;
-    }
+            // 3. Set the model change listener.
+            jSimulatorSingleResource
+                    .setResourceModelChangeListener(resourceModelChangeListener);
 
-    private void addResourceUriToOrderedMap(String resourceType,
-            String resourceURI) {
-        if (null != resourceURI && null != resourceType) {
-            synchronized (orderedResourceUriMap) {
-                ArrayList<String> uriListForType = orderedResourceUriMap
-                        .get(resourceType);
-                if (null == uriListForType) {
-                    uriListForType = new ArrayList<String>();
-                    orderedResourceUriMap.put(resourceType, uriListForType);
-                }
-                uriListForType.add(resourceURI);
+            // 4. Set the observer listener if the resource is observable.
+            if (resource.isObservable()) {
+                jSimulatorSingleResource.setObserverListener(observer);
             }
-        }
-    }
 
-    private void removeResourceUriFromOrderedMap(String resourceType,
-            String resourceURI) {
-        synchronized (orderedResourceUriMap) {
-            if (null != resourceURI && null != resourceType) {
-                ArrayList<String> uriListForType = orderedResourceUriMap
-                        .get(resourceType);
-                if (null != uriListForType) {
-                    uriListForType.remove(resourceURI);
-                    if (uriListForType.size() < 1) {
-                        orderedResourceUriMap.remove(resourceType);
+            // 5. Add attributes.
+            Map<String, LocalResourceAttribute> attributes = resource
+                    .getResourceAttributes();
+            if (null != attributes && !attributes.isEmpty()) {
+                Set<String> keySet = attributes.keySet();
+                Iterator<String> itr = keySet.iterator();
+
+                String attName;
+                LocalResourceAttribute localAtt;
+                SimulatorResourceAttribute simResAtt;
+
+                while (itr.hasNext()) {
+                    attName = itr.next();
+                    localAtt = attributes.get(attName);
+                    if (null == localAtt) {
+                        continue;
                     }
+                    simResAtt = localAtt.getResourceAttributeRef();
+                    if (null == simResAtt) {
+                        continue;
+                    }
+                    jSimulatorSingleResource.addAttribute(simResAtt);
                 }
-            } else if (null != resourceType) {
-                orderedResourceUriMap.remove(resourceType);
-            } else {
-                orderedResourceUriMap.clear();
-            }
-        }
-    }
 
-    private void addResourceToMap(SimulatorResource simulatorResource) {
-        if (null != simulatorResource) {
-            synchronized (resourceMap) {
-                Map<String, SimulatorResource> resourceTypeMap;
-                resourceTypeMap = resourceMap.get(simulatorResource
-                        .getResourceType());
-                if (null == resourceTypeMap) {
-                    resourceTypeMap = new HashMap<String, SimulatorResource>();
-                    resourceMap.put(simulatorResource.getResourceType(),
-                            resourceTypeMap);
-                }
-                resourceTypeMap.put(simulatorResource.getResourceURI(),
-                        simulatorResource);
+                // 6. Get the resource model java object reference.
+                resource.setResourceModel(jSimulatorSingleResource
+                        .getResourceModel());
             }
+
+            // 7. Register the resource with the platform.
+            jSimulatorSingleResource.start();
+            resource.setStarted(true);
+        } catch (SimulatorException e) {
+            Activator
+                    .getDefault()
+                    .getLogManager()
+                    .log(Level.ERROR.ordinal(), new Date(),
+                            Utility.getSimulatorErrorString(e, null));
+            throw e;
         }
+
+        // 8. Add to local cache.
+        data.addResource(resource);
+
+        // 9. Update UI listeners
+        UiListenerHandler.getInstance().resourceCreatedUINotification(
+                ResourceType.SINGLE);
+
+        return true;
     }
 
-    private void addResourceToMap(String resourceType,
-            Map<String, SimulatorResource> newResourceTypeMap) {
-        if (null != resourceType && null != newResourceTypeMap) {
-            synchronized (resourceMap) {
-                Map<String, SimulatorResource> resourceTypeMap = resourceMap
-                        .get(resourceType);
-                if (null != resourceTypeMap) {
-                    resourceTypeMap.putAll(newResourceTypeMap);
-                } else {
-                    resourceMap.put(resourceType, newResourceTypeMap);
-                }
-            }
+    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);
 
-    private void removeResourceFromMap(String resourceType, String resourceURI) {
-        if (null != resourceURI && null != resourceType) {
-            synchronized (resourceMap) {
-                Map<String, SimulatorResource> resourceTypeMap = resourceMap
-                        .get(resourceType);
-                if (null != resourceTypeMap) {
-                    resourceTypeMap.remove(resourceURI);
-                    if (resourceTypeMap.size() < 1) {
-                        resourceMap.remove(resourceType);
-                    }
-                }
+            // 2. Cancel observable property if requested by user.
+            if (!resource.isObservable()) {
+                jSimulatorCollectionResource.setObservable(false);
             }
-        }
-    }
 
-    public boolean isResourceExist(String resourceURI) {
-        boolean result = false;
-        if (null != resourceURI) {
-            SimulatorResource resource = getSimulatorResourceByURI(resourceURI);
-            if (null != resource) {
-                result = true;
+            // 3. Set the observer listener if the resource is observable.
+            if (resource.isObservable()) {
+                jSimulatorCollectionResource.setObserverListener(observer);
             }
-        }
-        return result;
-    }
 
-    public void addResourceDisplayName(String displayName, String completeURI) {
-        synchronized (displayNameMap) {
-            displayNameMap.put(displayName, completeURI);
-        }
-    }
+            // 4. Set the model change listener.
+            jSimulatorCollectionResource
+                    .setResourceModelChangeListener(resourceModelChangeListener);
 
-    public void removeResourceDisplayName(String displayName) {
-        synchronized (displayNameMap) {
-            displayNameMap.remove(displayName);
+            // 5. 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 boolean isDisplayName(String displayName) {
-        boolean exist = false;
-        synchronized (displayNameMap) {
-            exist = displayNameMap.containsKey(displayName);
+    public Resource createResourceByRAML(String configFilePath)
+            throws SimulatorException {
+        Resource resource = null;
+        try {
+            // 1. Create the resource
+            SimulatorResource jSimulatorResource = SimulatorManager
+                    .createResource(configFilePath);
+            if (null == jSimulatorResource) {
+                return null;
+            }
+            if (jSimulatorResource instanceof SimulatorSingleResource) {
+                resource = new SingleResource();
+            } else {
+                resource = new CollectionResource();
+            }
+            resource.setSimulatorResource(jSimulatorResource);
+
+            // 2. Fetch and locally store the resource name and uri.
+            String uri = jSimulatorResource.getURI();
+            if (null == uri || uri.trim().isEmpty()) {
+                return null;
+            }
+            resource.setResourceURI(uri.trim());
+
+            String name = jSimulatorResource.getName();
+            if (null == name || name.trim().isEmpty()) {
+                return null;
+            }
+            resource.setResourceName(name.trim());
+        } catch (SimulatorException e) {
+            Activator
+                    .getDefault()
+                    .getLogManager()
+                    .log(Level.ERROR.ordinal(), new Date(),
+                            Utility.getSimulatorErrorString(e, null));
+            throw e;
         }
-        return exist;
+        return resource;
     }
 
-    public String getCompleteUriFromDisplayName(String displayName) {
-        String completeURI = null;
-        synchronized (displayNameMap) {
-            completeURI = displayNameMap.get(displayName);
+    /**
+     * 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 completeSingleResourceCreationByRAML(Resource resource,
+            String uri, String name, boolean multiInstance)
+            throws SimulatorException {
+        if (null == resource || !(resource instanceof SingleResource)) {
+            return false;
         }
-        return completeURI;
-    }
+        try {
+            SingleResource singleRes = (SingleResource) resource;
 
-    public void createResource(final String configFilePath) {
-        new Thread() {
-            @Override
-            public void run() {
-                SimulatorResourceServer resourceServerN;
-                try {
-                    resourceServerN = SimulatorManager.createResource(
-                            configFilePath, resourceModelChangeListener);
-                } catch (SimulatorException e) {
-                    Activator
-                            .getDefault()
-                            .getLogManager()
-                            .log(Level.ERROR.ordinal(),
-                                    new Date(),
-                                    "[" + e.getClass().getSimpleName() + "]"
-                                            + e.code().toString() + "-"
-                                            + e.message());
-                    return;
-                }
-                SimulatorResource simulatorResource;
-                simulatorResource = fetchResourceData(resourceServerN);
-                if (null != simulatorResource) {
-                    String uri = simulatorResource.getResourceURI();
-                    addResourceToMap(simulatorResource);
-                    addResourceUriToOrderedMap(
-                            simulatorResource.getResourceType(), uri);
-                    resourceCreatedUINotification();
-
-                    // Form the display URI
-                    String displayName = Utility.uriToDisplayName(uri);
-                    if (null != displayName) {
-                        addResourceDisplayName(displayName, uri);
-                    } else {
-                        Activator
-                                .getDefault()
-                                .getLogManager()
-                                .log(Level.ERROR.ordinal(),
-                                        new Date(),
-                                        "Converting the URI to display format for "
-                                                + uri + "failed!");
-                    }
+            SimulatorSingleResource jSimulatorSingleResource = (SimulatorSingleResource) resource
+                    .getSimulatorResource();
+            if (null == jSimulatorSingleResource) {
+                return false;
+            }
 
-                    // Set the observer for the created resource
-                    try {
-                        resourceServerN.setObserverCallback(observer);
-                    } catch (SimulatorException e) {
-                        Activator
-                                .getDefault()
-                                .getLogManager()
-                                .log(Level.ERROR.ordinal(),
-                                        new Date(),
-                                        "[" + e.getClass().getSimpleName()
-                                                + "]" + e.code().toString()
-                                                + "-" + e.message());
-                    }
+            // 1. Update resource URI and Name if they are changed.
+            String newUri = uri.trim();
+            String newName = name.trim();
 
-                    // Print the resource data
-                    simulatorResource.printResourceInfo();
+            if (multiInstance) {
+                singleRes.setResourceURI(newUri);
+                singleRes.setResourceName(newName);
+            } else {
+                if (!singleRes.getResourceURI().equals(newUri)) {
+                    jSimulatorSingleResource.setURI(newUri);
+                    singleRes.setResourceURI(newUri);
+                }
+                if (!singleRes.getResourceName().equals(newName)) {
+                    jSimulatorSingleResource.setName(newName);
+                    singleRes.setResourceName(newName);
                 }
             }
-        }.start();
-    }
 
-    public void createResource(final String configFilePath,
-            final int noOfInstances) {
-        new Thread() {
-            @Override
-            public void run() {
-                Map<String, SimulatorResource> resourceTypeMap;
-                SimulatorResourceServer[] simulatorResourceServers = null;
-                try {
-                    simulatorResourceServers = SimulatorManager.createResource(
-                            configFilePath, noOfInstances,
-                            resourceModelChangeListener);
-                } catch (SimulatorException e) {
-                    Activator
-                            .getDefault()
-                            .getLogManager()
-                            .log(Level.ERROR.ordinal(),
-                                    new Date(),
-                                    "[" + e.getClass().getSimpleName() + "]"
-                                            + e.code().toString() + "-"
-                                            + e.message());
-                    return;
-                }
-                if (null == simulatorResourceServers) {
-                    return;
-                }
-                resourceTypeMap = new HashMap<String, SimulatorResource>();
-                SimulatorResource resource;
-                String uri;
-                String displayName;
-                for (SimulatorResourceServer resourceServerN : simulatorResourceServers) {
-                    resource = fetchResourceData(resourceServerN);
-                    if (null != resource) {
-                        uri = resource.getResourceURI();
-                        resourceTypeMap.put(uri, resource);
-                        addResourceUriToOrderedMap(resource.getResourceType(),
-                                uri);
-
-                        // Form the display URI
-                        displayName = Utility.uriToDisplayName(uri);
-                        if (null != displayName) {
-                            addResourceDisplayName(displayName, uri);
-                        } else {
-                            Activator
-                                    .getDefault()
-                                    .getLogManager()
-                                    .log(Level.ERROR.ordinal(),
-                                            new Date(),
-                                            "Converting the URI to display format for "
-                                                    + uri + "failed!");
-                        }
-                    }
-                    // Set the observer for the created resource
-                    try {
-                        resourceServerN.setObserverCallback(observer);
-                    } catch (SimulatorException e) {
-                        Activator
-                                .getDefault()
-                                .getLogManager()
-                                .log(Level.ERROR.ordinal(),
-                                        new Date(),
-                                        "[" + e.getClass().getSimpleName()
-                                                + "]" + e.code().toString()
-                                                + "-" + e.message());
-                    }
-                }
+            // 2. Set the model change listener.
+            jSimulatorSingleResource
+                    .setResourceModelChangeListener(resourceModelChangeListener);
 
-                // Find the resourceType and add it to the local data
-                // structure and notify UI Listeners
-                if (resourceTypeMap.size() > 0) {
-                    String resourceType;
-                    Set<String> uriSet = resourceTypeMap.keySet();
-                    Iterator<String> itr = uriSet.iterator();
-                    if (itr.hasNext()) {
-                        SimulatorResource simResource = resourceTypeMap.get(itr
-                                .next());
-                        if (null != simResource) {
-                            resourceType = simResource.getResourceType();
-
-                            addResourceToMap(resourceType, resourceTypeMap);
-                            resourceCreatedUINotification();
-                        }
-                    }
-                }
+            // 3. Set the observer listener if the resource is observable.
+            if (jSimulatorSingleResource.isObservable()) {
+                jSimulatorSingleResource.setObserverListener(observer);
+                singleRes.setObservable(true);
             }
-        }.start();
-    }
 
-    private SimulatorResource fetchResourceData(
-            SimulatorResourceServer resourceServerN) {
-        SimulatorResource simulatorResource = null;
-        if (null != resourceServerN) {
-            simulatorResource = new SimulatorResource();
-            simulatorResource.setResourceServer(resourceServerN);
-            simulatorResource.setResourceURI(resourceServerN.getURI());
-            simulatorResource
-                    .setResourceType(resourceServerN.getResourceType());
-            simulatorResource.setResourceName(resourceServerN.getName());
-            simulatorResource.setResourceInterface(resourceServerN
-                    .getInterfaceType());
-
-            SimulatorResourceModel resourceModelN;
-            try {
-                resourceModelN = resourceServerN.getModel();
-            } catch (SimulatorException e) {
-                Activator
-                        .getDefault()
-                        .getLogManager()
-                        .log(Level.ERROR.ordinal(),
-                                new Date(),
-                                "[" + e.getClass().getSimpleName() + "]"
-                                        + e.code().toString() + "-"
-                                        + e.message());
-                return null;
+            // 4. Fetch the resource model.
+            SimulatorResourceModel jResModel = jSimulatorSingleResource
+                    .getResourceModel();
+            if (null == jResModel) {
+                return false;
             }
-            if (null != resourceModelN) {
-                simulatorResource.setResourceModel(resourceModelN);
-
-                // Fetch the resource attributes
-                Map<String, LocalResourceAttribute> resourceAttributeMap;
-                resourceAttributeMap = fetchResourceAttributesFromModel(resourceModelN);
-                if (null != resourceAttributeMap) {
-                    simulatorResource
-                            .setResourceAttributesMap(resourceAttributeMap);
-                }
+            singleRes.setResourceModel(jResModel);
+
+            // 5. Fetch the basic details of the resource.
+            singleRes.addResourceType(jSimulatorSingleResource
+                    .getResourceType());
+            singleRes
+                    .setResourceInterfaces(Utility
+                            .convertVectorToSet(jSimulatorSingleResource
+                                    .getInterface()));
+
+            // 6. Register the resource with the platform.
+            jSimulatorSingleResource.start();
+            singleRes.setStarted(true);
+
+            // 7. Fetch the resource attributes.
+            Map<String, LocalResourceAttribute> resourceAttributeMap;
+            resourceAttributeMap = fetchResourceAttributesFromModel(jResModel);
+            if (null != resourceAttributeMap) {
+                singleRes.setResourceAttributes(resourceAttributeMap);
             }
+
+            // 8. Add to local cache.
+            data.addResource(singleRes);
+
+            // 9. Update UI listeners for single instance creation
+            if (!multiInstance)
+                UiListenerHandler.getInstance().resourceCreatedUINotification(
+                        ResourceType.SINGLE);
+        } catch (SimulatorException e) {
+            Activator
+                    .getDefault()
+                    .getLogManager()
+                    .log(Level.ERROR.ordinal(), new Date(),
+                            Utility.getSimulatorErrorString(e, null));
+            throw e;
         }
-        return simulatorResource;
+        return true;
     }
 
-    private Map<String, LocalResourceAttribute> fetchResourceAttributesFromModel(
-            SimulatorResourceModel resourceModelN) {
-        Map<String, LocalResourceAttribute> 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;
+    /**
+     * 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;
+        }
+        try {
+            CollectionResource collectionRes = (CollectionResource) resource;
+
+            SimulatorCollectionResource jSimulatorCollectionResource = (SimulatorCollectionResource) resource
+                    .getSimulatorResource();
+            if (null == jSimulatorCollectionResource) {
+                return false;
             }
-            if (null != attributeMapN) {
-                resourceAttributeMap = new HashMap<String, LocalResourceAttribute>();
 
-                Set<String> attNameSet = attributeMapN.keySet();
-                String attName;
-                ResourceAttribute attributeN;
-                LocalResourceAttribute attribute;
-                Iterator<String> attNameItr = attNameSet.iterator();
-                while (attNameItr.hasNext()) {
-                    attName = attNameItr.next();
-                    attributeN = attributeMapN.get(attName);
-                    if (null != attributeN) {
-                        attribute = new LocalResourceAttribute();
-                        attribute.setResourceAttribute(attributeN);
-
-                        // Set the attribute value
-                        Object valueObj = attributeN.getValue();
-                        if (null != valueObj) {
-                            attribute.setAttributeValue(valueObj);
-                        }
+            // 1. Update resource URI and Name if they are changed.
+            String newUri = uri.trim();
+            String newName = name.trim();
 
-                        // Set the attribute value list.
-                        attribute.setAttValues(getValueList(attributeN));
+            if (!collectionRes.getResourceURI().equals(newUri)) {
+                jSimulatorCollectionResource.setURI(newUri);
+                collectionRes.setResourceURI(newUri);
+            }
+            if (!collectionRes.getResourceName().equals(newName)) {
+                jSimulatorCollectionResource.setName(newName);
+                collectionRes.setResourceName(newName);
+            }
 
-                        // Initially disabling the automation
-                        attribute.setAutomationInProgress(false);
+            // 2. Set the model change listener.
+            jSimulatorCollectionResource
+                    .setResourceModelChangeListener(resourceModelChangeListener);
 
-                        // TODO: Temporarily setting the interval to 500.
-                        // This value should come from the native layer.
-                        // Native implementation is in progress.
-                        attribute
-                                .setAutomationUpdateInterval(Constants.DEFAULT_AUTOMATION_INTERVAL);
+            // 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);
+            }
 
-                        // Setting the default automation type
-                        attribute
-                                .setAutomationType(Constants.DEFAULT_AUTOMATION_TYPE);
+            // 6. Register the resource with the platform.
+            jSimulatorCollectionResource.start();
+            collectionRes.setStarted(true);
 
-                        resourceAttributeMap.put(attName, attribute);
-                    }
-                }
+            // 7. Fetch the resource attributes.
+            Map<String, LocalResourceAttribute> resourceAttributeMap;
+            resourceAttributeMap = fetchResourceAttributesFromModel(jResModel);
+            if (null != resourceAttributeMap) {
+                collectionRes.setResourceAttributes(resourceAttributeMap);
             }
+
+            // 6. Add to local cache.
+            data.addResource(collectionRes);
+
+            // 7. Update UI listeners for single instance creation
+            UiListenerHandler.getInstance().resourceCreatedUINotification(
+                    ResourceType.COLLECTION);
+        } catch (SimulatorException e) {
+            Activator
+                    .getDefault()
+                    .getLogManager()
+                    .log(Level.ERROR.ordinal(), new Date(),
+                            Utility.getSimulatorErrorString(e, null));
+            throw e;
         }
-        return resourceAttributeMap;
+        return true;
     }
 
-    // This method gives all known possible values of the attribute in string
-    // format. It takes allowed values or range of values whichever is available
-    private List<String> getValueList(ResourceAttribute attributeN) {
-        Object[] allowedValues = attributeN.getAllowedValues();
-        List<String> valueList = new ArrayList<String>();
-        if (null != allowedValues && allowedValues.length > 0) {
-            for (Object value : allowedValues) {
-                if (null != value) {
-                    valueList.add(String.valueOf(value));
-                }
+    public int createSingleResourceMultiInstances(String configFile, int count)
+            throws SimulatorException {
+        int createCount = 0;
+        try {
+            Vector<SimulatorResource> jSimulatorResources = SimulatorManager
+                    .createResource(configFile, count);
+            if (null == jSimulatorResources || jSimulatorResources.size() < 1) {
+                return 0;
             }
-        } else {
-            Type valueType = attributeN.getBaseType();
-            Range range = attributeN.getRange();
-            if (null != range) {
-                Object min = range.getMin();
-                Object max = range.getMax();
-                if (valueType == Type.INT) {
-                    int minI = (Integer) min;
-                    int maxI = (Integer) max;
-                    for (int value = minI; value <= maxI; value++) {
-                        valueList.add(String.valueOf(value));
-                    }
-                } else if (valueType == Type.DOUBLE) {
-                    double minD = (Double) min;
-                    double maxD = (Double) max;
-                    for (double value = minD; value <= maxD; value++) {
-                        valueList.add(String.valueOf(value));
+            SimulatorSingleResource jResource;
+            SingleResource resource;
+            boolean result;
+            for (SimulatorResource jSimulatorResource : jSimulatorResources) {
+                jResource = (SimulatorSingleResource) jSimulatorResource;
+                resource = new SingleResource();
+                resource.setSimulatorResource(jResource);
+                try {
+                    result = completeSingleResourceCreationByRAML(resource,
+                            jResource.getURI(), jResource.getName(), true);
+                    if (result) {
+                        createCount++;
                     }
-                }
-            }
-        }
-        Object attValue = attributeN.getValue();
-        if (valueList.size() < 1 && null != attValue) {
-            valueList.add(String.valueOf(attValue));
+                } catch (SimulatorException eInner) {
+                    Activator
+                            .getDefault()
+                            .getLogManager()
+                            .log(Level.ERROR.ordinal(),
+                                    new Date(),
+                                    Utility.getSimulatorErrorString(eInner,
+                                            null));
+                }
+            }
+            if (createCount > 0) {
+                UiListenerHandler.getInstance().resourceCreatedUINotification(
+                        ResourceType.SINGLE);
+            }
+        } catch (SimulatorException eOuter) {
+            Activator
+                    .getDefault()
+                    .getLogManager()
+                    .log(Level.ERROR.ordinal(), new Date(),
+                            Utility.getSimulatorErrorString(eOuter, null));
+            throw eOuter;
         }
-        return valueList;
+        return createCount;
     }
 
-    public void deleteResourceByURI(final String resourceURI) {
-        if (null != resourceURI) {
-            new Thread() {
-                @Override
-                public void run() {
-                    SimulatorResource resource = getSimulatorResourceByURI(resourceURI);
-                    if (null != resource) {
-                        String resourceType = resource.getResourceType();
+    public void createDevice(String deviceName, Set<Resource> childs) {
+        // 1. Create device
+        Device dev = new Device();
+        dev.setDeviceName(deviceName);
+        data.addDevice(dev);
 
-                        // Unregister the resource from the platform
-                        deleteResource(resource);
+        // 2. Add children to device
+        if (null != childs && !childs.isEmpty())
+            addResourceToDevice(dev, childs);
 
-                        // Delete from the local data structure
-                        deleteLocalResourceDetails(resourceType, resourceURI);
+        // 3. Update ui listeners
+        UiListenerHandler.getInstance().resourceListUpdateUINotification(
+                ResourceType.DEVICE);
+    }
 
-                        // Notify the UI listener for removing this resource
-                        // from UI
-                        resourceDeletedUINotification();
+    private Map<String, LocalResourceAttribute> fetchResourceAttributesFromModel(
+            SimulatorResourceModel jResModel) throws SimulatorException {
+        Map<String, LocalResourceAttribute> resourceAttributeMap = null;
+        if (null != jResModel) {
+            Map<String, SimulatorResourceAttribute> jAttributeMap;
+            jAttributeMap = jResModel.getAttributes();
+            if (null != jAttributeMap) {
+                resourceAttributeMap = new HashMap<String, LocalResourceAttribute>();
+                Iterator<String> itr = jAttributeMap.keySet().iterator();
+                String attName;
+                SimulatorResourceAttribute jResAtt;
+                LocalResourceAttribute localAtt;
+                while (itr.hasNext()) {
+                    attName = itr.next();
+                    if (null != attName) {
+                        jResAtt = jAttributeMap.get(attName);
+                        if (null != jResAtt) {
+                            localAtt = new LocalResourceAttribute();
 
-                        if (null != currentResourceInSelection
-                                && resource == currentResourceInSelection) {
-                            // Listeners might query the resource being deleted
-                            // if exists. So set the currently selection to
-                            // null.
-                            setCurrentResourceInSelection(null);
+                            localAtt.setResourceAttributeRef(jResAtt);
 
-                            // Notify all observers for resource selection
-                            // change event
-                            resourceSelectionChangedUINotification();
-                        }
-                    }
-                }
-            }.start();
-        }
-    }
-
-    private SimulatorResource getSimulatorResourceByURI(String resourceURI) {
-        SimulatorResource resource = null;
-        if (null != resourceURI) {
-            synchronized (resourceMap) {
-                Set<String> typeSet = resourceMap.keySet();
-                Iterator<String> typeItr = typeSet.iterator();
-                String resourceType;
-                Map<String, SimulatorResource> resourceTypeMap;
-                while (typeItr.hasNext()) {
-                    resourceType = typeItr.next();
-                    resourceTypeMap = resourceMap.get(resourceType);
-                    if (null != resourceTypeMap) {
-                        resource = resourceTypeMap.get(resourceURI);
-                        if (null != resource) {
-                            break;
+                            // Initially disabling the automation
+                            localAtt.setAutomationInProgress(false);
+
+                            // Assigning the default automation interval
+                            localAtt.setAutomationUpdateInterval(Constants.DEFAULT_AUTOMATION_INTERVAL);
+
+                            // Setting the default automation type
+                            localAtt.setAutomationType(Constants.DEFAULT_AUTOMATION_TYPE);
+
+                            resourceAttributeMap.put(attName, localAtt);
                         }
                     }
                 }
             }
         }
-        return resource;
+        return resourceAttributeMap;
+
     }
 
-    private void deleteResource(SimulatorResource resource) {
-        if (null != resource) {
-            SimulatorResourceServer resourceServerN = resource
-                    .getResourceServer();
-            if (null != resourceServerN) {
-                try {
-                    SimulatorManager.deleteResource(resourceServerN);
-                } catch (SimulatorException e) {
-                    Activator
-                            .getDefault()
-                            .getLogManager()
-                            .log(Level.ERROR.ordinal(),
-                                    new Date(),
-                                    "[" + e.getClass().getSimpleName() + "]"
-                                            + e.code().toString() + "-"
-                                            + e.message());
+    // This method gives all known possible values of the attribute in string
+    // format. It takes allowed values or range of values whichever is available
+    private List<String> getValueList(SimulatorResourceAttribute attributeN) {
+        AttributeProperty attProp = attributeN.property();
+        if (null == attProp) {
+            return null;
+        }
+        List<String> valueList = new ArrayList<String>();
+        Type valuesType = attProp.type();
+        if (valuesType == Type.VALUESET) {
+            Object[] allowedValues = attProp.valueSet();
+            if (null != allowedValues && allowedValues.length > 0) {
+                for (Object value : allowedValues) {
+                    if (null != value) {
+                        valueList.add(String.valueOf(((AttributeValue) value)
+                                .get()));
+                    }
                 }
             }
+        } else if (valuesType == Type.RANGE) {
+            double minD = attProp.min();
+            double maxD = attProp.max();
+            for (double value = minD; value <= maxD; value++) {
+                valueList.add(String.valueOf(value));
+            }
+        }
+        Object attValue = attributeN.value().get();
+        if (valueList.size() < 1 && null != attValue) {
+            valueList.add(String.valueOf(attValue));
+        }
+        return valueList;
+    }
+
+    public List<Resource> getResourceList() {
+        List<Resource> resourceList = data.getResources();
+        if (null == resourceList) {
+            return null;
+        }
+        // Sort the list
+        Collections.sort(resourceList, Utility.resourceComparator);
+
+        return resourceList;
+    }
+
+    public List<SingleResource> getSingleResourceList() {
+        List<SingleResource> resourceList = data.getSingleResources();
+        if (null == resourceList) {
+            return null;
         }
+        // Sort the list
+        Collections.sort(resourceList, Utility.singleResourceComparator);
+
+        return resourceList;
     }
 
-    public void deleteResourceByType(final String resourceType) {
-        if (null != resourceType) {
-            new Thread() {
-                @Override
-                public void run() {
-                    // Unregister the resources from the platform
-                    deleteResource(resourceType);
+    public List<CollectionResource> getCollectionResourceList() {
+        List<CollectionResource> resourceList = data.getCollectionResources();
+        if (null == resourceList) {
+            return null;
+        }
+        // Sort the list
+        Collections.sort(resourceList, Utility.collectionResourceComparator);
 
-                    // Delete from the local data structure
-                    deleteLocalResourceDetails(resourceType, null);
+        return resourceList;
+    }
 
-                    // Notify the UI listener for removing this resource from UI
-                    resourceDeletedUINotification();
+    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;
+        }
+        Iterator<Resource> itr = childs.iterator();
+        Resource res;
+        int count = childs.size();
+        while (itr.hasNext()) {
+            res = itr.next();
+            try {
+                addResourceToCollection(collectionParent, res);
+            } catch (SimulatorException e) {
+                count--;
+            }
+        }
+        return count;
+    }
 
-                    if (null != currentResourceInSelection
-                            && resourceType.equals(currentResourceInSelection
-                                    .getResourceType())) {
-                        // Listeners might query the resource being deleted if
-                        // exists. So set the currently selection to null.
-                        setCurrentResourceInSelection(null);
+    public void addResourceToCollection(CollectionResource collectionParent,
+            Resource child) throws SimulatorException {
+        if (null == collectionParent || null == child) {
+            return;
+        }
+        try {
+            // 1. Add child to collection
+            collectionParent.addChildResource(child);
 
-                        // Notify all observers for resource selection change
-                        // event
-                        resourceSelectionChangedUINotification();
-                    }
-                }
-            }.start();
+            // 2. Add a reference to the collection in the child
+            if (child instanceof SingleResource) {
+                ((SingleResource) child)
+                        .addCollectionMembership(collectionParent);
+            } else {
+                ((CollectionResource) child).addMembership(collectionParent);
+            }
+        } catch (SimulatorException e) {
+            Activator
+                    .getDefault()
+                    .getLogManager()
+                    .log(Level.ERROR.ordinal(), new Date(),
+                            Utility.getSimulatorErrorString(e, null));
+            throw e;
         }
     }
 
-    private void deleteResource(String resourceType) {
-        if (null != resourceType) {
+    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 {
-                SimulatorManager.deleteResources(resourceType);
+                addResourceToCollection(res, child);
             } catch (SimulatorException e) {
-                Activator
-                        .getDefault()
-                        .getLogManager()
-                        .log(Level.ERROR.ordinal(),
-                                new Date(),
-                                "[" + e.getClass().getSimpleName() + "]"
-                                        + e.code().toString() + "-"
-                                        + e.message());
+                count--;
             }
         }
+        return count;
     }
 
-    public void deleteAllResources() {
-        new Thread() {
-            @Override
-            public void run() {
-                // Unregister the resources from the platform
-                deleteResource();
+    public void addResourceToDevice(Device dev, Set<Resource> childs) {
+        // 1. Add children to the device.
+        dev.addChildResource(childs);
 
-                // Delete from the local data structure
-                deleteLocalResourceDetails(null, null);
+        // 2. Add a reference to the device in all children.
+        Iterator<Resource> itr = childs.iterator();
+        Resource res;
+        while (itr.hasNext()) {
+            res = itr.next();
+            if (res instanceof SingleResource) {
+                ((SingleResource) res).addDeviceMembership(dev);
+            } else {
+                ((CollectionResource) res).addDeviceMembership(dev);
+            }
+        }
+    }
 
-                // Notify the UI listener for removing this resource from UI
-                resourceDeletedUINotification();
+    public void addResourceToDevice(Device dev, Resource child) {
+        // 1. Add child to the device.
+        dev.addChildResource(child);
 
-                // Listeners might query the resource being deleted if exists.
-                // So set the currently selection to null.
-                setCurrentResourceInSelection(null);
+        // 2. Add a reference to the device in the child.
+        if (child instanceof SingleResource) {
+            ((SingleResource) child).addDeviceMembership(dev);
+        } else {
+            ((CollectionResource) child).addDeviceMembership(dev);
+        }
+    }
 
-                // Notify all observers for resource selection change event
-                resourceSelectionChangedUINotification();
+    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--;
             }
-        }.start();
+        }
+        return count;
+
     }
 
-    private void deleteResource() {
+    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 {
-            SimulatorManager.deleteResources(null);
+            // 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(),
-                            "[" + e.getClass().getSimpleName() + "]"
-                                    + e.code().toString() + "-" + e.message());
+                    .log(Level.ERROR.ordinal(), new Date(),
+                            Utility.getSimulatorErrorString(e, null));
+            throw e;
         }
     }
 
-    private void deleteLocalResourceDetails(String resourceType,
-            String resourceURI) {
-        if (null != resourceType && null != resourceURI) {
-            removeResourceFromMap(resourceType, resourceURI);
-            removeResourceUriFromOrderedMap(resourceType, resourceURI);
+    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 {
-            synchronized (resourceMap) {
-                if (null != resourceType) {
-                    removeResourceUriFromOrderedMap(resourceType, null);
-                    resourceMap.remove(resourceType);
-                } else {
-                    resourceMap.clear();
-                    removeResourceUriFromOrderedMap(null, null);
-                }
-            }
+            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);
         }
-        // Remove the display name from the map
-        if (null != resourceURI) {
-            String dispName = Utility.uriToDisplayName(resourceURI);
-            if (null != dispName)
-                removeResourceDisplayName(dispName);
+
+        // 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);
     }
 
-    private void resourceCreatedUINotification() {
-        synchronized (resourceListChangedUIListeners) {
-            if (resourceListChangedUIListeners.size() > 0) {
-                IResourceListChangedUIListener listener;
-                Iterator<IResourceListChangedUIListener> listenerItr = resourceListChangedUIListeners
-                        .iterator();
-                while (listenerItr.hasNext()) {
-                    listener = listenerItr.next();
-                    if (null != listener) {
-                        listener.onResourceCreation();
-                    }
-                }
+    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);
     }
 
-    private void resourceDeletedUINotification() {
-        synchronized (resourceListChangedUIListeners) {
-            if (resourceListChangedUIListeners.size() > 0) {
-                IResourceListChangedUIListener listener;
-                Iterator<IResourceListChangedUIListener> listenerItr = resourceListChangedUIListeners
-                        .iterator();
-                while (listenerItr.hasNext()) {
-                    listener = listenerItr.next();
-                    if (null != listener) {
-                        listener.onResourceDeletion();
-                    }
-                }
+    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;
     }
 
-    private void resourceSelectionChangedUINotification() {
-        synchronized (resourceSelectionChangedUIListeners) {
-            if (resourceSelectionChangedUIListeners.size() > 0) {
-                IResourceSelectionChangedUIListener listener;
-                Iterator<IResourceSelectionChangedUIListener> listenerItr = resourceSelectionChangedUIListeners
-                        .iterator();
-                while (listenerItr.hasNext()) {
-                    listener = listenerItr.next();
-                    if (null != listener) {
-                        listener.onResourceSelectionChange();
-                    }
-                }
-            }
+    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;
     }
 
-    private void resourceModelChangedUINotification(
-            ModelChangeNotificationType notificationType, String resourceURI,
-            Set<LocalResourceAttribute> valueChangeSet) {
-        synchronized (resourceModelChangedUIListeners) {
-            if (resourceModelChangedUIListeners.size() > 0
-                    && notificationType != ModelChangeNotificationType.NONE
-                    && null != resourceURI) {
-                IResourceModelChangedUIListener listener;
-                Iterator<IResourceModelChangedUIListener> listenerItr = resourceModelChangedUIListeners
-                        .iterator();
-                while (listenerItr.hasNext()) {
-                    listener = listenerItr.next();
-                    if (null != listener) {
-                        listener.onResourceModelChange(notificationType,
-                                resourceURI, valueChangeSet);
-                    }
-                }
-            }
+    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;
     }
 
-    private void resourceAutomationStartedUINotification(String resourceURI) {
-        synchronized (automationUIListeners) {
-            if (automationUIListeners.size() > 0 && null != resourceURI) {
-                IAutomationUIListener listener;
-                Iterator<IAutomationUIListener> listenerItr = automationUIListeners
-                        .iterator();
-                while (listenerItr.hasNext()) {
-                    listener = listenerItr.next();
-                    if (null != listener) {
-                        listener.onResourceAutomationStart(resourceURI);
-                    }
-                }
-            }
+    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;
     }
 
-    private void automationCompleteUINotification(String resourceURI,
-            String attName) {
-        synchronized (automationUIListeners) {
-            if (automationUIListeners.size() > 0 && null != resourceURI) {
-                IAutomationUIListener listener;
-                Iterator<IAutomationUIListener> listenerItr = automationUIListeners
-                        .iterator();
-                while (listenerItr.hasNext()) {
-                    listener = listenerItr.next();
-                    if (null != listener) {
-                        listener.onAutomationComplete(resourceURI, attName);
-                    }
-                }
-            }
+    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;
     }
 
-    private void observerListChangedUINotification(String resourceURI) {
-        synchronized (observerUIListeners) {
-            if (observerUIListeners.size() > 0 && null != resourceURI) {
-                IObserverListChangedUIListener listener;
-                Iterator<IObserverListChangedUIListener> listenerItr = observerUIListeners
-                        .iterator();
-                while (listenerItr.hasNext()) {
-                    listener = listenerItr.next();
-                    if (null != listener) {
-                        listener.onObserverListChanged(resourceURI);
-                    }
-                }
-            }
+    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<String> getResourceTypeList() {
-        List<String> typeList = null;
-        synchronized (resourceMap) {
-            if (resourceMap.size() > 0) {
-                typeList = new ArrayList<String>();
-                Set<String> typeSet = resourceMap.keySet();
-                Iterator<String> typeItr = typeSet.iterator();
-                while (typeItr.hasNext()) {
-                    typeList.add(typeItr.next());
-                }
-            }
+    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();
         }
-        return typeList;
+        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 boolean isTypeExist(String resType) {
-        synchronized (resourceMap) {
-            if (resourceMap.containsKey(resType)) {
-                return true;
-            }
+    public List<CollectionResource> getResourceReferences(
+            SingleResource resource) {
+        List<CollectionResource> resources = Utility
+                .getCollectionResourceListFromSet(resource
+                        .getCollectionMembership());
+        if (null == resources || resources.isEmpty()) {
+            return null;
         }
-        return false;
+
+        Collections.sort(resources, Utility.collectionResourceComparator);
+
+        return resources;
     }
 
-    public List<String> getURIList() {
-        List<String> list = null;
-        synchronized (orderedResourceUriMap) {
-            Set<String> typeSet = orderedResourceUriMap.keySet();
-            List<String> typeList = Utility.convertSetToList(typeSet);
-            if (null == typeList || typeList.size() < 1) {
-                return list;
-            }
-            list = new ArrayList<String>();
+    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);
+    }
+
+    /*
+     * public void deleteResourceByURI(String resourceURI) { if (null !=
+     * resourceURI) { Resource resource =
+     * getSimulatorResourceByURI(resourceURI); if (null != resource) { //
+     * Unregister the resource from the platform deleteResource(resource);
+     * 
+     * // Delete from the local data structure deleteLocalResourceDetails(null,
+     * resourceURI);
+     * 
+     * // Notify the UI listener for removing this resource // from UI //
+     * resourceDeletedUINotification(); if (resource ==
+     * getCurrentResourceInSelection()) { // Listeners might query the resource
+     * being deleted // if exists. So set the currently selection to // null.
+     * setCurrentResourceInSelection(null);
+     * 
+     * // Notify all observers for resource selection // change event //
+     * resourceSelectionChangedUINotification(); } } } }
+     * 
+     * private SingleResource getSimulatorResourceByURI(String resourceURI) {
+     * SingleResource resource = null; if (null != resourceURI) { synchronized
+     * (resourceMap) { resource = resourceMap.get(resourceURI); } } return
+     * resource; }
+     * 
+     * private void deleteResource(SingleResource resource) { if (null !=
+     * resource) { SimulatorResourceServer resourceServerN = resource
+     * .getResourceServer(); if (null != resourceServerN) { try {
+     * SimulatorManager.deleteResource(resourceServerN); } catch
+     * (SimulatorException e) { Activator .getDefault() .getLogManager()
+     * .log(Level.ERROR.ordinal(), new Date(),
+     * Utility.getSimulatorErrorString(e, null)); } } } }
+     * 
+     * public void deleteResourceByType(final String resourceType) {
+     * System.out.println(resourceType + "to be deleted."); if (null !=
+     * resourceType) { new Thread() {
+     * 
+     * @Override public void run() { // Unregister the resources from the
+     * platform deleteResource(resourceType);
+     * 
+     * // Delete from the local data structure
+     * deleteLocalResourceDetails(resourceType, null);
+     * 
+     * // Notify the UI listener for removing this resource from UI
+     * resourceDeletedUINotification();
+     * 
+     * if (null != currentResourceInSelection &&
+     * currentResourceInSelection.getResourceTypes() .contains(resourceType)) {
+     * // Listeners might query the resource being deleted if // exists. So set
+     * the currently selection to null. setCurrentResourceInSelection(null);
+     * 
+     * // Notify all observers for resource selection change // event
+     * resourceSelectionChangedUINotification(null); } } }.start(); } }
+     * 
+     * private void deleteResource(String resourceType) { if (null !=
+     * resourceType) { try { SimulatorManager.deleteResources(resourceType); }
+     * catch (SimulatorException e) { Activator .getDefault() .getLogManager()
+     * .log(Level.ERROR.ordinal(), new Date(),
+     * Utility.getSimulatorErrorString(e, null)); } } }
+     * 
+     * public void deleteAllResources() { new Thread() {
+     * 
+     * @Override public void run() { // Unregister the resources from the
+     * platform deleteResource();
+     * 
+     * // Delete from the local data structure deleteLocalResourceDetails(null,
+     * null);
+     * 
+     * // Notify the UI listener for removing this resource from UI
+     * resourceDeletedUINotification();
+     * 
+     * // Listeners might query the resource being deleted if exists. // So set
+     * the currently selection to null. setCurrentResourceInSelection(null);
+     * 
+     * // Notify all observers for resource selection change event
+     * resourceSelectionChangedUINotification(null); } }.start(); }
+     * 
+     * private void deleteResource() { try {
+     * SimulatorManager.deleteResources(null); } catch (SimulatorException e) {
+     * Activator .getDefault() .getLogManager() .log(Level.ERROR.ordinal(), new
+     * Date(), Utility.getSimulatorErrorString(e, null)); } }
+     * 
+     * private void deleteLocalResourceDetails(String resourceType, String
+     * resourceURI) { synchronized (resourceMap) { if (null == resourceType &&
+     * null == resourceURI) { resourceMap.clear(); } else if (null !=
+     * resourceType) { Set<String> uriSet = resourceMap.keySet(); if (null ==
+     * uriSet) { return; } String uri; SingleResource simpleRes;
+     * Iterator<String> uriItr = uriSet.iterator(); while (uriItr.hasNext()) {
+     * uri = uriItr.next(); simpleRes = resourceMap.get(uri); if
+     * (simpleRes.getResourceTypes().contains(resourceType)) { uriItr.remove();
+     * } } } else { removeResourceFromMap(resourceURI); } } }
+     * 
+     * 
+     * 
+     * public Set<String> getResourceTypeList() { Set<String> types = null;
+     * synchronized (resourceMap) { if (resourceMap.size() > 0) { types = new
+     * TreeSet<String>(); Set<String> typeSet = resourceMap.keySet();
+     * Iterator<String> typeItr = typeSet.iterator(); SingleResource resource;
+     * while (typeItr.hasNext()) { resource = resourceMap.get(typeItr.next());
+     * Set<String> subTypes = resource.getResourceTypes();
+     * types.addAll(subTypes); } } } return types; }
+     */
+
+    public void resourceSelectionChanged(final Resource selectedResource) {
+        new Thread() {
+            @Override
+            public void run() {
 
-            // Sort the types
-            Collections.sort(typeList);
+                setCurrentDeviceInSelection(null);
 
-            // Add all URIs to the output list
-            Iterator<String> typeItr = typeList.iterator();
-            while (typeItr.hasNext()) {
-                List<String> l = orderedResourceUriMap.get(typeItr.next());
-                if (null != l) {
-                    list.addAll(l);
+                if (null != selectedResource) {
+                    setCurrentResourceInSelection(selectedResource);
+                } else {
+                    setCurrentResourceInSelection(null);
                 }
+                // Notify all observers for resource selection change event
+                UiListenerHandler.getInstance()
+                        .resourceSelectionChangedUINotification(
+                                selectedResource);
             }
-        }
-        return list;
+        }.start();
     }
 
-    public void resourceSelectionChanged(final String selectedItem) {
+    public void deviceSelectionChanged(final Device selectedDevice) {
         new Thread() {
             @Override
             public void run() {
-                // Check whether the item selected is a resource or resource
-                // category
-                if (isTypeExist(selectedItem)) {
-                    // Given item is a resource Type
-                    setCurrentResourceInSelection(null);
+
+                setCurrentResourceInSelection(null);
+
+                if (null != selectedDevice) {
+                    setCurrentDeviceInSelection(selectedDevice);
                 } else {
-                    // Given item is a resource URI
-                    SimulatorResource resource = getSimulatorResourceByURI(selectedItem);
-                    if (null != resource) {
-                        setCurrentResourceInSelection(resource);
-                    } else {
-                        setCurrentResourceInSelection(null);
-                    }
+                    setCurrentDeviceInSelection(null);
                 }
                 // Notify all observers for resource selection change event
-                resourceSelectionChangedUINotification();
+                UiListenerHandler.getInstance()
+                        .deviceSelectionChangedUINotification(selectedDevice);
             }
         }.start();
     }
 
-    public List<MetaProperty> getMetaProperties(SimulatorResource resource) {
+    public List<MetaProperty> getMetaProperties(Resource resource) {
         if (null != resource) {
             String propName;
             String propValue;
@@ -1166,13 +1624,12 @@ public class ResourceManager {
 
             for (int index = 0; index < Constants.META_PROPERTY_COUNT; index++) {
                 propName = Constants.META_PROPERTIES[index];
-                if (propName.equals(Constants.RESOURCE_URI)) {
+                if (propName.equals(Constants.RESOURCE_NAME)) {
+                    propValue = resource.getResourceName();
+                } else if (propName.equals(Constants.RESOURCE_URI)) {
                     propValue = resource.getResourceURI();
                 } else if (propName.equals(Constants.RESOURCE_TYPE)) {
-                    propValue = resource.getResourceType();
-                } else if (propName.equals(Constants.CONNECTIVITY_TYPE)) {
-                    // TODO: Temporarily ignoring till the implementation.
-                    propValue = null;
+                    propValue = resource.getResourceTypes().toString();
                 } else {
                     propValue = null;
                 }
@@ -1180,17 +1637,228 @@ public class ResourceManager {
                     metaPropertyList.add(new MetaProperty(propName, propValue));
                 }
             }
+            return metaPropertyList;
+        }
+        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 List<LocalResourceAttribute> getAttributes(SimulatorResource resource) {
+    public boolean startResource(Resource resource) throws SimulatorException {
+        if (null == resource) {
+            return false;
+        }
+        SimulatorResource server = resource.getSimulatorResource();
+        if (null == server) {
+            return false;
+        }
+        try {
+            server.start();
+            resource.setStarted(true);
+        } catch (SimulatorException e) {
+            Activator
+                    .getDefault()
+                    .getLogManager()
+                    .log(Level.ERROR.ordinal(),
+                            new Date(),
+                            "There is an error while starting the resource.\n"
+                                    + Utility.getSimulatorErrorString(e, null));
+            throw e;
+        }
+        return true;
+    }
+
+    public boolean stopResource(Resource resource) throws SimulatorException {
+        if (null == resource) {
+            return false;
+        }
+        SimulatorResource server = resource.getSimulatorResource();
+        if (null == server) {
+            return false;
+        }
+        try {
+            server.stop();
+            resource.setStarted(false);
+        } catch (SimulatorException e) {
+            Activator
+                    .getDefault()
+                    .getLogManager()
+                    .log(Level.ERROR.ordinal(),
+                            new Date(),
+                            "There is an error while stopping the resource.\n"
+                                    + Utility.getSimulatorErrorString(e, null));
+            throw e;
+        }
+        return true;
+    }
+
+    public boolean changeResourceName(Resource resource, String newName)
+            throws SimulatorException {
+        if (null == resource || null == newName) {
+            return false;
+        }
+
+        if (!stopResource(resource)) {
+            return false;
+        }
+
+        SimulatorResource server = resource.getSimulatorResource();
+        try {
+            server.setName(newName);
+            resource.setResourceName(newName);
+        } catch (SimulatorException e) {
+            Activator
+                    .getDefault()
+                    .getLogManager()
+                    .log(Level.ERROR.ordinal(),
+                            new Date(),
+                            "There is an error while changing the resource name.\n"
+                                    + Utility.getSimulatorErrorString(e, null));
+            throw e;
+        }
+
+        if (!startResource(resource)) {
+            return false;
+        }
+
+        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) {
+            return false;
+        }
+
+        if (!stopResource(resource)) {
+            return false;
+        }
+
+        String curURI = resource.getResourceURI();
+        SimulatorResource server = resource.getSimulatorResource();
+        try {
+            server.setURI(newURI);
+            data.changeResourceURI(resource, curURI, newURI);
+        } catch (SimulatorException e) {
+            Activator
+                    .getDefault()
+                    .getLogManager()
+                    .log(Level.ERROR.ordinal(),
+                            new Date(),
+                            "There is an error while changing the resource URI.\n"
+                                    + Utility.getSimulatorErrorString(e, null));
+            throw e;
+        }
+
+        if (!startResource(resource)) {
+            return false;
+        }
+        return true;
+    }
+
+    public boolean updateResourceProperties(Resource resource,
+            List<MetaProperty> properties, boolean uriChanged,
+            boolean nameChanged) throws SimulatorException {
+        if (null == resource || null == properties) {
+            return false;
+        }
+
+        // Updating the properties
+        Iterator<MetaProperty> itr = properties.iterator();
+        MetaProperty property;
+        String propName;
+        String propValue;
+        String resName = null;
+        String resURI = null;
+        while (itr.hasNext()) {
+            property = itr.next();
+            if (null == property) {
+                continue;
+            }
+            propName = property.getPropName();
+            propValue = property.getPropValue();
+            if (propName.equals(Constants.RESOURCE_NAME)) {
+                resName = propValue;
+            } else if (propName.equals(Constants.RESOURCE_URI)) {
+                resURI = propValue;
+            }
+        }
+
+        if (nameChanged) {
+            if (!changeResourceName(resource, resName)) {
+                return false;
+            }
+
+            // Notify UI Listeners
+            UiListenerHandler.getInstance().propertiesChangedUINotification(
+                    Resource.class);
+        }
+
+        if (uriChanged) {
+            if (!changeResourceURI(resource, resURI)) {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+    public boolean updateDeviceProperties(Device dev,
+            List<MetaProperty> properties) {
+        if (null == dev || null == properties) {
+            return false;
+        }
+
+        // Updating the properties
+        Iterator<MetaProperty> itr = properties.iterator();
+        MetaProperty property;
+        String propName;
+        String propValue;
+        String devName = null;
+        while (itr.hasNext()) {
+            property = itr.next();
+            if (null == property) {
+                continue;
+            }
+            propName = property.getPropName();
+            propValue = property.getPropValue();
+            if (propName.equals(Constants.DEVICE_NAME)) {
+                devName = propValue;
+            }
+        }
+
+        if (!changeDeviceName(dev, devName)) {
+            return false;
+        }
+
+        // Notify UI Listeners
+        UiListenerHandler.getInstance().propertiesChangedUINotification(
+                Device.class);
+
+        return true;
+    }
+
+    public List<LocalResourceAttribute> getAttributes(Resource resource) {
         List<LocalResourceAttribute> attList = null;
         if (null != resource) {
             Map<String, LocalResourceAttribute> attMap = resource
-                    .getResourceAttributesMap();
+                    .getResourceAttributes();
             if (null != attMap && attMap.size() > 0) {
                 attList = new ArrayList<LocalResourceAttribute>();
                 Set<String> attNameSet = attMap.keySet();
@@ -1206,137 +1874,313 @@ public class ResourceManager {
                 }
             }
         }
-        return attList;
+        return attList;
+    }
+
+    public List<SimulatorResourceAttribute> getAttributes(
+            SimulatorResourceModel model) {
+        List<SimulatorResourceAttribute> attList = null;
+        if (null != model) {
+            Map<String, SimulatorResourceAttribute> attMap = model
+                    .getAttributes();
+            if (null != attMap && attMap.size() > 0) {
+                attList = new ArrayList<SimulatorResourceAttribute>();
+                Set<String> attNameSet = attMap.keySet();
+                String attName;
+                SimulatorResourceAttribute attribute;
+                Iterator<String> attNameItr = attNameSet.iterator();
+                while (attNameItr.hasNext()) {
+                    attName = attNameItr.next();
+                    attribute = attMap.get(attName);
+                    if (null != attribute) {
+                        attList.add(attribute);
+                    }
+                }
+            }
+        }
+        return attList;
+    }
+
+    public List<SRMItem> getIndexedAttributes(SimulatorResourceModel[] model) {
+        List<SRMItem> indexedAttList = null;
+        if (null != model && model.length > 0) {
+            indexedAttList = new ArrayList<SRMItem>();
+            int i = 0;
+            for (SimulatorResourceModel m : model) {
+                indexedAttList.add(new SRMItem(i++, m));
+            }
+        }
+        return indexedAttList;
+    }
+
+    public void attributeValueUpdated(SingleResource resource,
+            String attributeName, AttributeValue value) {
+        if (null != resource && null != attributeName && null != value) {
+            SimulatorSingleResource simRes = (SimulatorSingleResource) resource
+                    .getSimulatorResource();
+            if (null != simRes) {
+                try {
+                    simRes.updateAttribute(attributeName, value);
+                } catch (SimulatorException e) {
+                    Activator
+                            .getDefault()
+                            .getLogManager()
+                            .log(Level.ERROR.ordinal(), new Date(),
+                                    Utility.getSimulatorErrorString(e, null));
+                }
+            }
+        }
+    }
+
+    /*
+     * private ModelChangeNotificationType compareAndUpdateLocalAttributes(
+     * Map<String, LocalResourceAttribute> resourceAttributeMapOld, Map<String,
+     * LocalResourceAttribute> resourceAttributeMapNew,
+     * Set<LocalResourceAttribute> valueChangeSet) { ModelChangeNotificationType
+     * notificationType = ModelChangeNotificationType.NONE; if (null !=
+     * resourceAttributeMapOld && null != resourceAttributeMapNew) { Set<String>
+     * oldMapKeySet = resourceAttributeMapOld.keySet(); Iterator<String>
+     * attributeMapOldItr = oldMapKeySet.iterator(); String attName;
+     * LocalResourceAttribute attributeOld; LocalResourceAttribute attributeNew;
+     * Object attValueOld; Object attValueNew; String oldValueStr; String
+     * newValueStr; while (attributeMapOldItr.hasNext()) { attName =
+     * attributeMapOldItr.next(); if
+     * (resourceAttributeMapNew.containsKey(attName)) { attributeOld =
+     * resourceAttributeMapOld.get(attName); attributeNew =
+     * resourceAttributeMapNew.get(attName); // Copy the attribute value from
+     * new to old if the value // has been changed // Comparing only the
+     * attribute's value considering the // fact that only the value can be
+     * changed if (null != attributeOld && null != attributeNew) { attValueOld =
+     * attributeOld.getAttributeValue(); attValueNew =
+     * attributeNew.getAttributeValue();
+     * 
+     * oldValueStr = String.valueOf(attValueOld); newValueStr =
+     * String.valueOf(attValueNew);
+     * 
+     * if (null != oldValueStr && null != newValueStr) { if
+     * (!oldValueStr.equals(newValueStr)) {
+     * attributeOld.setAttributeValue(attValueNew); notificationType =
+     * ModelChangeNotificationType.ATTRIBUTE_VALUE_CHANGED;
+     * valueChangeSet.add(attributeOld); } } }
+     * resourceAttributeMapNew.remove(attName); } else { // Attribute doesn't
+     * exist in the new model. Hence // removing it from the model.
+     * resourceAttributeMapOld.remove(attName); notificationType =
+     * ModelChangeNotificationType.ATTRIBUTE_REMOVED; } } // Check for new
+     * attributes in the new model if (resourceAttributeMapNew.size() > 0) {
+     * Set<String> remainingAttSet = resourceAttributeMapNew.keySet();
+     * Iterator<String> remainingAttItr = remainingAttSet.iterator();
+     * LocalResourceAttribute attribute; while (remainingAttItr.hasNext()) {
+     * attName = remainingAttItr.next(); if (null != attName) { attribute =
+     * resourceAttributeMapNew.get(attName); if (null != attribute) {
+     * resourceAttributeMapOld.put(attName, attribute); } } } notificationType =
+     * ModelChangeNotificationType.ATTRIBUTE_ADDED; } } return notificationType;
+     * }
+     */
+
+    // TODO: This method should get the status from the native layer.
+    public boolean isResourceStarted(Resource resource) {
+        if (null == resource) {
+            return false;
+        }
+        return resource.isStarted();
+    }
+
+    public boolean isPropertyValueInvalid(Resource resource,
+            List<MetaProperty> properties, String propName) {
+        if (null == resource || 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 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) {
+            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 = getPropertyValueFromResource(resource, propName);
+                if (null != oldValue && !prop.getPropValue().equals(oldValue)) {
+                    changed = true;
+                }
+                break;
+            }
+        }
+        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) {
+            return null;
+        }
+        if (propName.equals(Constants.RESOURCE_URI)) {
+            return resource.getResourceURI();
+        } else if (propName.equals(Constants.RESOURCE_NAME)) {
+            return resource.getResourceName();
+        } else if (propName.equals(Constants.RESOURCE_TYPE)) {
+            return resource.getResourceTypes().toString();
+        } else {
+            return null;
+        }
     }
 
-    public void attributeValueUpdated(SimulatorResource resource,
-            String attributeName, String value) {
-        if (null != resource && null != attributeName && null != value) {
-            SimulatorResourceServer server = resource.getResourceServer();
-            if (null != server) {
-                LocalResourceAttribute att = resource
-                        .getAttribute(attributeName);
-                if (null == att) {
-                    return;
-                }
-                Type baseType = att.getAttValBaseType();
-                try {
-                    if (baseType == Type.STRING) {
-                        server.updateAttributeString(attributeName, value);
-                    } else if (baseType == Type.INT) {
-                        int val;
-                        try {
-                            val = Integer.parseInt(value);
-                            server.updateAttributeInteger(attributeName, val);
-                        } catch (NumberFormatException nfe) {
-                            return;
-                        }
-                    } else if (baseType == Type.DOUBLE) {
-                        double val;
-                        try {
-                            val = Double.parseDouble(value);
-                            server.updateAttributeDouble(attributeName, val);
-                        } catch (NumberFormatException nfe) {
-                            return;
-                        }
-                    } else if (baseType == Type.BOOL) {
-                        boolean val;
-                        val = Boolean.parseBoolean(value);
-                        server.updateAttributeBoolean(attributeName, val);
-                    }
-                } catch (SimulatorException e) {
-                    Activator
-                            .getDefault()
-                            .getLogManager()
-                            .log(Level.ERROR.ordinal(),
-                                    new Date(),
-                                    "[" + e.getClass().getSimpleName() + "]"
-                                            + e.code().toString() + "-"
-                                            + e.message());
+    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;
     }
 
-    private ModelChangeNotificationType compareAndUpdateLocalAttributes(
-            Map<String, LocalResourceAttribute> resourceAttributeMapOld,
-            Map<String, LocalResourceAttribute> resourceAttributeMapNew,
-            Set<LocalResourceAttribute> valueChangeSet) {
-        ModelChangeNotificationType notificationType = ModelChangeNotificationType.NONE;
-        if (null != resourceAttributeMapOld && null != resourceAttributeMapNew) {
-            Set<String> oldMapKeySet = resourceAttributeMapOld.keySet();
-            Iterator<String> attributeMapOldItr = oldMapKeySet.iterator();
-            String attName;
-            LocalResourceAttribute attributeOld;
-            LocalResourceAttribute attributeNew;
-            Object attValueOld;
-            Object attValueNew;
-            String oldValueStr;
-            String newValueStr;
-            while (attributeMapOldItr.hasNext()) {
-                attName = attributeMapOldItr.next();
-                if (resourceAttributeMapNew.containsKey(attName)) {
-                    attributeOld = resourceAttributeMapOld.get(attName);
-                    attributeNew = resourceAttributeMapNew.get(attName);
-                    // Copy the attribute value from new to old if the value
-                    // has been changed
-                    // Comparing only the attribute's value considering the
-                    // fact that only the value can be changed
-                    if (null != attributeOld && null != attributeNew) {
-                        attValueOld = attributeOld.getAttributeValue();
-                        attValueNew = attributeNew.getAttributeValue();
-
-                        oldValueStr = String.valueOf(attValueOld);
-                        newValueStr = String.valueOf(attValueNew);
-
-                        if (null != oldValueStr && null != newValueStr) {
-                            if (!oldValueStr.equals(newValueStr)) {
-                                attributeOld.setAttributeValue(attValueNew);
-                                notificationType = ModelChangeNotificationType.ATTRIBUTE_VALUE_CHANGED;
-                                valueChangeSet.add(attributeOld);
-                            }
-                        }
-                    }
-                    resourceAttributeMapNew.remove(attName);
-                } else {
-                    // Attribute doesn't exist in the new model. Hence
-                    // removing it from the model.
-                    resourceAttributeMapOld.remove(attName);
-                    notificationType = ModelChangeNotificationType.ATTRIBUTE_REMOVED;
-                }
+    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;
             }
-            // Check for new attributes in the new model
-            if (resourceAttributeMapNew.size() > 0) {
-                Set<String> remainingAttSet = resourceAttributeMapNew.keySet();
-                Iterator<String> remainingAttItr = remainingAttSet.iterator();
-                LocalResourceAttribute attribute;
-                while (remainingAttItr.hasNext()) {
-                    attName = remainingAttItr.next();
-                    if (null != attName) {
-                        attribute = resourceAttributeMapNew.get(attName);
-                        if (null != attribute) {
-                            resourceAttributeMapOld.put(attName, attribute);
-                        }
-                    }
-                }
-                notificationType = ModelChangeNotificationType.ATTRIBUTE_ADDED;
+        }
+        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 notificationType;
+        return result;
+    }
+
+    public boolean isAttHasRangeOrAllowedValues(SimulatorResourceAttribute att) {
+        if (null == att) {
+            return false;
+        }
+        AttributeProperty prop = att.property();
+        if (null == prop) {
+            return false;
+        }
+        Type attProp = prop.type();
+        if (attProp == Type.UNKNOWN) {
+            return false;
+        }
+        return true;
     }
 
-    public int startAutomation(SimulatorResource resource,
-            LocalResourceAttribute attribute, AutomationType autoType,
+    public int startAutomation(SingleResource resource,
+            LocalResourceAttribute attribute, AutoUpdateType autoType,
             int autoUpdateInterval) {
         int autoId = -1;
         if (null != resource && null != attribute) {
-            SimulatorResourceServer resourceServerN = resource
-                    .getResourceServer();
-            if (null != resourceServerN) {
-                String attrName = attribute.getAttributeName();
+            SimulatorSingleResource server = (SimulatorSingleResource) resource
+                    .getSimulatorResource();
+            if (null != server) {
+                String attrName = attribute.getResourceAttributeRef().name();
                 try {
-                    autoId = resourceServerN.startAttributeAutomation(attrName,
-                            autoType, autoUpdateInterval, automationListener);
+                    autoId = server.startAttributeUpdation(attrName, autoType,
+                            autoUpdateInterval, automationListener);
                 } catch (SimulatorException e) {
                     Activator
                             .getDefault()
@@ -1362,14 +2206,14 @@ public class ResourceManager {
         return autoId;
     }
 
-    public void stopAutomation(SimulatorResource resource,
+    public void stopAutomation(SingleResource resource,
             LocalResourceAttribute att, int autoId) {
         if (null != resource) {
-            SimulatorResourceServer resourceServerN = resource
-                    .getResourceServer();
-            if (null != resourceServerN) {
+            SimulatorSingleResource server = (SimulatorSingleResource) resource
+                    .getSimulatorResource();
+            if (null != server) {
                 try {
-                    resourceServerN.stopAutomation(autoId);
+                    server.stopUpdation(autoId);
                 } catch (SimulatorException e) {
                     Activator
                             .getDefault()
@@ -1388,113 +2232,55 @@ public class ResourceManager {
         }
     }
 
-    private boolean isAnyAttributeInAutomation(SimulatorResource resource) {
+    public boolean startResourceAutomationUIRequest(AutoUpdateType autoType,
+            int autoUpdateInterval, final SingleResource resource) {
         if (null == resource) {
             return false;
         }
-        Map<String, LocalResourceAttribute> attMap = resource
-                .getResourceAttributesMap();
-        if (null == attMap) {
-            return false;
-        }
         boolean status = false;
-        Set<String> keySet = attMap.keySet();
-        Iterator<String> attItr = keySet.iterator();
-        while (attItr.hasNext()) {
-            LocalResourceAttribute attribute = attMap.get(attItr.next());
-            if (attribute.isAutomationInProgress()) {
-                status = true;
-                break;
-            }
-        }
-        return status;
-    }
-
-    private LocalResourceAttribute getAttributeWithGivenAutomationId(
-            SimulatorResource resource, int automationId) {
-        LocalResourceAttribute targetAttribute = null;
-        if (null != resource) {
-            Map<String, LocalResourceAttribute> attributeMap = resource
-                    .getResourceAttributesMap();
-            if (null != attributeMap) {
-                Set<String> attNameSet = attributeMap.keySet();
-                Iterator<String> attNameItr = attNameSet.iterator();
-                String attName;
-                LocalResourceAttribute attribute;
-                while (attNameItr.hasNext()) {
-                    attName = attNameItr.next();
-                    if (null != attName) {
-                        attribute = attributeMap.get(attName);
-                        if (null != attribute) {
-                            if (attribute.isAutomationInProgress()
-                                    && (attribute.getAutomationId() == automationId)) {
-                                targetAttribute = attribute;
-                                break;
-                            }
-                        }
-                    }
-                }
+        changeResourceLevelAutomationStatus(resource, true);
+        // Invoke the native automation method
+        SimulatorSingleResource resourceServer = (SimulatorSingleResource) resource
+                .getSimulatorResource();
+        if (null != resourceServer) {
+            int autoId = -1;
+            try {
+                autoId = resourceServer.startResourceUpdation(autoType,
+                        autoUpdateInterval, automationListener);
+            } catch (SimulatorException e) {
+                Activator
+                        .getDefault()
+                        .getLogManager()
+                        .log(Level.ERROR.ordinal(), new Date(),
+                                Utility.getSimulatorErrorString(e, null));
+                autoId = -1;
             }
-        }
-        return targetAttribute;
-    }
+            if (-1 == autoId) {
+                // Automation request failed and hence status is being
+                // rolled back
+                changeResourceLevelAutomationStatus(resource, false);
+            } else {
+                // Automation request accepted.
+                resource.setAutomationId(autoId);
 
-    public boolean startResourceAutomationUIRequest(final String resourceURI) {
-        if (null == resourceURI) {
-            return false;
-        }
-        boolean status = false;
-        SimulatorResource resource = getSimulatorResourceByURI(resourceURI);
-        if (null != resource) {
-            changeResourceLevelAutomationStatus(resource, true);
-
-            // Invoke the native automation method
-            SimulatorResourceServer resourceServer = resource
-                    .getResourceServer();
-            if (null != resourceServer) {
-                // TODO: Temporarily handling the normal one-time automation for
-                // resources
-                int autoId = -1;
-                try {
-                    autoId = resourceServer.startResourceAutomation(
-                            AutomationType.NORMAL, 500, automationListener);
-                } catch (SimulatorException e) {
-                    Activator
-                            .getDefault()
-                            .getLogManager()
-                            .log(Level.ERROR.ordinal(),
-                                    new Date(),
-                                    "[" + e.getClass().getSimpleName() + "]"
-                                            + e.code().toString() + "-"
-                                            + e.message());
-                    autoId = -1;
-                }
-                if (-1 == autoId) {
-                    // Automation request failed and hence status is being
-                    // rolled back
-                    changeResourceLevelAutomationStatus(resource, false);
-                } else {
-                    // Automation request accepted.
-                    resource.setAutomationId(autoId);
-
-                    // Notify the UI listeners in a different thread.
-                    Thread notifyThread = new Thread() {
-                        public void run() {
-                            resourceAutomationStartedUINotification(resourceURI);
-                        };
+                // Notify the UI listeners in a different thread.
+                Thread notifyThread = new Thread() {
+                    public void run() {
+                        UiListenerHandler.getInstance()
+                                .resourceAutomationStartedUINotification(
+                                        resource);
                     };
-                    notifyThread.setPriority(Thread.MAX_PRIORITY);
-                    notifyThread.start();
+                };
+                notifyThread.setPriority(Thread.MAX_PRIORITY);
+                notifyThread.start();
 
-                    status = true;
-                }
+                status = true;
             }
         }
         return status;
     }
 
-    public boolean stopResourceAutomationUIRequest(final String resourceURI) {
-        SimulatorResource resource = getSimulatorResourceByURI(resourceURI);
+    public boolean stopResourceAutomationUIRequest(final SingleResource resource) {
         if (null == resource) {
             return false;
         }
@@ -1502,40 +2288,62 @@ public class ResourceManager {
         if (-1 == autoId) {
             return false;
         }
-        SimulatorResourceServer resourceServer = resource.getResourceServer();
+        SimulatorSingleResource resourceServer = (SimulatorSingleResource) resource
+                .getSimulatorResource();
         if (null == resourceServer) {
             return false;
         }
         // Call native method
         try {
-            resourceServer.stopAutomation(autoId);
+            resourceServer.stopUpdation(autoId);
         } 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;
         }
 
         // Notify the UI Listeners. Invoke the automation complete callback.
         Thread stopThread = new Thread() {
             public void run() {
-                automationListener.onAutomationComplete(resourceURI, autoId);
+                automationListener.onUpdateComplete(resource.getResourceURI(),
+                        autoId);
             }
         };
         stopThread.start();
         return true;
     }
 
+    private boolean isAnyAttributeInAutomation(SingleResource resource) {
+        if (null == resource) {
+            return false;
+        }
+        Map<String, LocalResourceAttribute> attMap = resource
+                .getResourceAttributes();
+        if (null == attMap) {
+            return false;
+        }
+        boolean status = false;
+        Set<String> keySet = attMap.keySet();
+        Iterator<String> attItr = keySet.iterator();
+        while (attItr.hasNext()) {
+            LocalResourceAttribute attribute = attMap.get(attItr.next());
+            if (attribute.isAutomationInProgress()) {
+                status = true;
+                break;
+            }
+        }
+        return status;
+    }
+
     // Changes the automation state of the resource and its attributes
-    private void changeResourceLevelAutomationStatus(
-            SimulatorResource resource, boolean status) {
+    private void changeResourceLevelAutomationStatus(SingleResource resource,
+            boolean status) {
 
         Map<String, LocalResourceAttribute> attributeMap = resource
-                .getResourceAttributesMap();
+                .getResourceAttributes();
         if (null != attributeMap) {
             Set<String> attrNameSet = attributeMap.keySet();
             Iterator<String> attrNameItr = attrNameSet.iterator();
@@ -1552,128 +2360,207 @@ public class ResourceManager {
         resource.setResourceAutomationInProgress(status);
     }
 
-    public boolean isResourceAutomationStarted(String resourceURI) {
-        boolean status = false;
-        if (null == resourceURI) {
-            return status;
-        }
-
-        SimulatorResource resource = getSimulatorResourceByURI(resourceURI);
+    private LocalResourceAttribute getAttributeWithGivenAutomationId(
+            SingleResource resource, int automationId) {
+        LocalResourceAttribute targetAttribute = null;
         if (null != resource) {
-            status = resource.isResourceAutomationInProgress();
+            Map<String, LocalResourceAttribute> attributeMap = resource
+                    .getResourceAttributes();
+            if (null != attributeMap) {
+                Set<String> attNameSet = attributeMap.keySet();
+                Iterator<String> attNameItr = attNameSet.iterator();
+                String attName;
+                LocalResourceAttribute attribute;
+                while (attNameItr.hasNext()) {
+                    attName = attNameItr.next();
+                    if (null != attName) {
+                        attribute = attributeMap.get(attName);
+                        if (null != attribute) {
+                            if (attribute.isAutomationInProgress()
+                                    && (attribute.getAutomationId() == automationId)) {
+                                targetAttribute = attribute;
+                                break;
+                            }
+                        }
+                    }
+                }
+            }
         }
-        return status;
+        return targetAttribute;
     }
 
-    public boolean isAttributeAutomationStarted(String resourceURI) {
+    public boolean isResourceAutomationStarted(SingleResource resource) {
         boolean status = false;
-        if (null == resourceURI) {
-            return status;
-        }
-        SimulatorResource resource = getSimulatorResourceByURI(resourceURI);
         if (null != resource) {
-            status = resource.isAttributeAutomationInProgress();
+            status = resource.isResourceAutomationInProgress();
         }
         return status;
     }
 
-    public LocalResourceAttribute getAttributeByResourceURI(String uri,
-            String attName) {
-        if (null == uri || null == attName) {
-            return null;
-        }
-        SimulatorResource resource = getSimulatorResourceByURI(uri);
+    public boolean isAttributeAutomationStarted(SingleResource resource) {
         if (null == resource) {
+            return false;
+        }
+        return resource.isAttributeAutomationInProgress();
+    }
+
+    public LocalResourceAttribute getAttributeByResourceURI(
+            SingleResource resource, String attName) {
+        if (null == resource || null == attName) {
             return null;
         }
         Map<String, LocalResourceAttribute> attMap = resource
-                .getResourceAttributesMap();
+                .getResourceAttributes();
         if (null == attMap) {
             return null;
         }
         return attMap.get(attName);
     }
 
-    public void notifyObserverRequest(SimulatorResource res, int observerId) {
-        if (null == res) {
+    public void notifyObserverRequest(Resource resource, int observerId) {
+        if (null == resource) {
             return;
         }
-        SimulatorResourceServer server = res.getResourceServer();
-        if (null == server) {
+        SimulatorResource simulatorResource = resource.getSimulatorResource();
+        if (null == simulatorResource) {
             return;
         }
         try {
-            server.notifyObserver(observerId);
+            simulatorResource.notifyObserver(observerId);
         } 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 boolean isAttHasRangeOrAllowedValues(LocalResourceAttribute att) {
+    public void shutdown() {
+        threadHandle.interrupt();
+    }
+
+    public List<String> getAllValuesOfAttribute(SimulatorResourceAttribute att) {
         if (null == att) {
-            return false;
-        }
-        Object[] obj = att.getAllowedValues();
-        if (null != obj && obj.length > 0) {
-            return true;
-        }
-        Object min = att.getMinValue();
-        Object max = att.getMaxValue();
-        if (null != min && null != max) {
-            return true;
+            return null;
         }
-        return false;
-    }
 
-    public boolean isResourceAutomationAllowed(String resourceURI) {
-        if (null == resourceURI) {
-            return false;
+        AttributeValue val = att.value();
+        if (null == val) {
+            return null;
         }
-        SimulatorResource resource = getSimulatorResourceByURI(resourceURI);
-        if (null == resource) {
-            return false;
+
+        TypeInfo type = val.typeInfo();
+
+        AttributeProperty prop = att.property();
+        if (null == prop) {
+            return null;
         }
-        Map<String, LocalResourceAttribute> attributes = resource
-                .getResourceAttributesMap();
-        if (null == attributes || attributes.size() < 1) {
-            return false;
+
+        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;
         }
-        Set<String> keySet = attributes.keySet();
-        Iterator<String> itr = keySet.iterator();
-        String attName;
-        boolean allowed = false;
-        LocalResourceAttribute att;
-        while (itr.hasNext()) {
-            attName = itr.next();
-            if (null != attName) {
-                att = attributes.get(attName);
-                if (null != att) {
-                    allowed = allowed | isAttHasRangeOrAllowedValues(att);
+
+        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);
+                            }
+                        }
+                    }
+                }
+            } 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);
+                    }
                 }
             }
         }
-        return allowed;
+
+        return values;
     }
 
-    public Image getImage(String resourceURI) {
-        if (null == resourceURI) {
+    public List<String> getRangeForPrimitiveNonArrayAttributes(
+            AttributeProperty prop, ValueType type) {
+        if (null == prop) {
             return null;
         }
-        SimulatorResource resource = getSimulatorResourceByURI(resourceURI);
-        if (null == resource) {
+
+        if (type == ValueType.ARRAY || type == ValueType.RESOURCEMODEL) {
             return null;
         }
-        return Activator.getDefault().getImageRegistry()
-                .get(resource.getResourceType());
+
+        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 void shutdown() {
-        threadHandle.interrupt();
+    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;
+        }
+
+        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;
     }
 }
\ No newline at end of file
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/UiListenerHandler.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/UiListenerHandler.java
new file mode 100644 (file)
index 0000000..8d1535f
--- /dev/null
@@ -0,0 +1,325 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package oic.simulator.serviceprovider.manager;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import oic.simulator.serviceprovider.listener.IAutomationUIListener;
+import oic.simulator.serviceprovider.listener.IObserverListChangedUIListener;
+import oic.simulator.serviceprovider.listener.IPropertiesChangedUIListener;
+import oic.simulator.serviceprovider.listener.IResourceListChangedUIListener;
+import oic.simulator.serviceprovider.listener.IResourceModelChangedUIListener;
+import oic.simulator.serviceprovider.listener.ISelectionChangedUIListener;
+import oic.simulator.serviceprovider.model.Device;
+import oic.simulator.serviceprovider.model.Resource;
+import oic.simulator.serviceprovider.model.ResourceType;
+import oic.simulator.serviceprovider.model.SingleResource;
+
+public class UiListenerHandler {
+
+    private static UiListenerHandler              uiHandler;
+
+    private List<IResourceListChangedUIListener>  resourceListChangedUIListeners;
+
+    private List<ISelectionChangedUIListener>     selectionChangedUIListeners;
+
+    private List<IResourceModelChangedUIListener> resourceModelChangedUIListeners;
+
+    private List<IAutomationUIListener>           automationUIListeners;
+
+    private List<IObserverListChangedUIListener>  observerUIListeners;
+
+    private List<IPropertiesChangedUIListener>    propertiesChangedUIListeners;
+
+    private UiListenerHandler() {
+        resourceListChangedUIListeners = new ArrayList<IResourceListChangedUIListener>();
+        selectionChangedUIListeners = new ArrayList<ISelectionChangedUIListener>();
+        resourceModelChangedUIListeners = new ArrayList<IResourceModelChangedUIListener>();
+        automationUIListeners = new ArrayList<IAutomationUIListener>();
+        observerUIListeners = new ArrayList<IObserverListChangedUIListener>();
+        propertiesChangedUIListeners = new ArrayList<IPropertiesChangedUIListener>();
+    }
+
+    public static UiListenerHandler getInstance() {
+        if (null == uiHandler) {
+            uiHandler = new UiListenerHandler();
+        }
+        return uiHandler;
+    }
+
+    public void addResourceListChangedUIListener(
+            IResourceListChangedUIListener resourceListChangedUIListener) {
+        synchronized (resourceListChangedUIListeners) {
+            resourceListChangedUIListeners.add(resourceListChangedUIListener);
+        }
+    }
+
+    public void addResourceSelectionChangedUIListener(
+            ISelectionChangedUIListener resourceSelectionChangedUIListener) {
+        synchronized (selectionChangedUIListeners) {
+            selectionChangedUIListeners.add(resourceSelectionChangedUIListener);
+        }
+    }
+
+    public void addResourceModelChangedUIListener(
+            IResourceModelChangedUIListener resourceModelChangedUIListener) {
+        synchronized (resourceModelChangedUIListeners) {
+            resourceModelChangedUIListeners.add(resourceModelChangedUIListener);
+        }
+    }
+
+    public void addAutomationUIListener(
+            IAutomationUIListener automationUIListener) {
+        synchronized (automationUIListeners) {
+            automationUIListeners.add(automationUIListener);
+        }
+    }
+
+    public void addObserverListChangedUIListener(
+            IObserverListChangedUIListener observerListChangedUIListener) {
+        synchronized (observerUIListeners) {
+            observerUIListeners.add(observerListChangedUIListener);
+        }
+    }
+
+    public void addResourcePropertiesChangedUIListener(
+            IPropertiesChangedUIListener resourcePropertiesChangedUIListener) {
+        synchronized (propertiesChangedUIListeners) {
+            propertiesChangedUIListeners
+                    .add(resourcePropertiesChangedUIListener);
+        }
+    }
+
+    public void removeResourceListChangedUIListener(
+            IResourceListChangedUIListener listener) {
+        synchronized (resourceListChangedUIListeners) {
+            if (null != listener && resourceListChangedUIListeners.size() > 0) {
+                resourceListChangedUIListeners.remove(listener);
+            }
+        }
+    }
+
+    public void removeResourceSelectionChangedUIListener(
+            ISelectionChangedUIListener listener) {
+        synchronized (selectionChangedUIListeners) {
+            if (null != listener && selectionChangedUIListeners.size() > 0) {
+                selectionChangedUIListeners.remove(listener);
+            }
+        }
+    }
+
+    public void removeResourceModelChangedUIListener(
+            IResourceModelChangedUIListener listener) {
+        synchronized (resourceModelChangedUIListeners) {
+            if (null != listener && resourceModelChangedUIListeners.size() > 0) {
+                resourceModelChangedUIListeners.remove(listener);
+            }
+        }
+    }
+
+    public void removeAutomationUIListener(IAutomationUIListener listener) {
+        synchronized (automationUIListeners) {
+            if (null != listener && automationUIListeners.size() > 0) {
+                automationUIListeners.remove(listener);
+            }
+        }
+    }
+
+    public void removeObserverListChangedUIListener(
+            IObserverListChangedUIListener listener) {
+        synchronized (observerUIListeners) {
+            if (null != listener && observerUIListeners.size() > 0) {
+                observerUIListeners.remove(listener);
+            }
+        }
+    }
+
+    public void removeResourcePropertiesChangedUIListener(
+            IPropertiesChangedUIListener resourcePropertiesChangedUIListener) {
+        synchronized (propertiesChangedUIListeners) {
+            propertiesChangedUIListeners
+                    .remove(resourcePropertiesChangedUIListener);
+        }
+    }
+
+    public void resourceCreatedUINotification(ResourceType type) {
+        synchronized (resourceListChangedUIListeners) {
+            if (resourceListChangedUIListeners.size() > 0) {
+                IResourceListChangedUIListener listener;
+                Iterator<IResourceListChangedUIListener> listenerItr = resourceListChangedUIListeners
+                        .iterator();
+                while (listenerItr.hasNext()) {
+                    listener = listenerItr.next();
+                    if (null != listener) {
+                        listener.onResourceCreation(type);
+                    }
+                }
+            }
+        }
+    }
+
+    public void resourceDeletedUINotification(ResourceType type) {
+        synchronized (resourceListChangedUIListeners) {
+            if (resourceListChangedUIListeners.size() > 0) {
+                IResourceListChangedUIListener listener;
+                Iterator<IResourceListChangedUIListener> listenerItr = resourceListChangedUIListeners
+                        .iterator();
+                while (listenerItr.hasNext()) {
+                    listener = listenerItr.next();
+                    if (null != listener) {
+                        listener.onResourceDeletion(type);
+                    }
+                }
+            }
+        }
+    }
+
+    public void resourceListUpdateUINotification(ResourceType type) {
+        synchronized (resourceListChangedUIListeners) {
+            if (resourceListChangedUIListeners.size() > 0) {
+                IResourceListChangedUIListener listener;
+                Iterator<IResourceListChangedUIListener> listenerItr = resourceListChangedUIListeners
+                        .iterator();
+                while (listenerItr.hasNext()) {
+                    listener = listenerItr.next();
+                    if (null != listener) {
+                        listener.onResourceListUpdate(type);
+                    }
+                }
+            }
+        }
+    }
+
+    public void resourceSelectionChangedUINotification(Resource resource) {
+        synchronized (selectionChangedUIListeners) {
+            if (selectionChangedUIListeners.size() > 0) {
+                ISelectionChangedUIListener listener;
+                Iterator<ISelectionChangedUIListener> listenerItr = selectionChangedUIListeners
+                        .iterator();
+                while (listenerItr.hasNext()) {
+                    listener = listenerItr.next();
+                    if (null != listener) {
+                        listener.onResourceSelectionChange(resource);
+                    }
+                }
+            }
+        }
+    }
+
+    public void deviceSelectionChangedUINotification(Device dev) {
+        synchronized (selectionChangedUIListeners) {
+            if (selectionChangedUIListeners.size() > 0) {
+                ISelectionChangedUIListener listener;
+                Iterator<ISelectionChangedUIListener> listenerItr = selectionChangedUIListeners
+                        .iterator();
+                while (listenerItr.hasNext()) {
+                    listener = listenerItr.next();
+                    if (null != listener) {
+                        listener.onDeviceSelectionChange(dev);
+                    }
+                }
+            }
+        }
+    }
+
+    public void resourceModelChangedUINotification(Resource resource) {
+        synchronized (resourceModelChangedUIListeners) {
+            if (resourceModelChangedUIListeners.size() > 0 && null != resource) {
+                IResourceModelChangedUIListener listener;
+                Iterator<IResourceModelChangedUIListener> listenerItr = resourceModelChangedUIListeners
+                        .iterator();
+                while (listenerItr.hasNext()) {
+                    listener = listenerItr.next();
+                    if (null != listener) {
+                        listener.onResourceModelChange(resource);
+                    }
+                }
+            }
+        }
+    }
+
+    public void resourceAutomationStartedUINotification(SingleResource resource) {
+        synchronized (automationUIListeners) {
+            if (automationUIListeners.size() > 0 && null != resource) {
+                IAutomationUIListener listener;
+                Iterator<IAutomationUIListener> listenerItr = automationUIListeners
+                        .iterator();
+                while (listenerItr.hasNext()) {
+                    listener = listenerItr.next();
+                    if (null != listener) {
+                        listener.onResourceAutomationStart(resource);
+                    }
+                }
+            }
+        }
+    }
+
+    public void automationCompleteUINotification(SingleResource resource,
+            String attName) {
+        synchronized (automationUIListeners) {
+            if (automationUIListeners.size() > 0 && null != resource) {
+                IAutomationUIListener listener;
+                Iterator<IAutomationUIListener> listenerItr = automationUIListeners
+                        .iterator();
+                while (listenerItr.hasNext()) {
+                    listener = listenerItr.next();
+                    if (null != listener) {
+                        listener.onAutomationComplete(resource, attName);
+                    }
+                }
+            }
+        }
+    }
+
+    public void observerListChangedUINotification(Resource resource) {
+        synchronized (observerUIListeners) {
+            if (observerUIListeners.size() > 0 && null != resource) {
+                IObserverListChangedUIListener listener;
+                Iterator<IObserverListChangedUIListener> listenerItr = observerUIListeners
+                        .iterator();
+                while (listenerItr.hasNext()) {
+                    listener = listenerItr.next();
+                    if (null != listener) {
+                        listener.onObserverListChanged(resource);
+                    }
+                }
+            }
+        }
+    }
+
+    public void propertiesChangedUINotification(Class targetClass) {
+        synchronized (propertiesChangedUIListeners) {
+            if (propertiesChangedUIListeners.size() > 0) {
+                IPropertiesChangedUIListener listener;
+                Iterator<IPropertiesChangedUIListener> listenerItr = propertiesChangedUIListeners
+                        .iterator();
+                while (listenerItr.hasNext()) {
+                    listener = listenerItr.next();
+                    if (null != listener) {
+                        if (targetClass == Resource.class) {
+                            listener.onResourcePropertyChange();
+                        } else {
+                            listener.onDevicePropertyChange();
+                        }
+                    }
+                }
+            }
+        }
+    }
+}
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/AttributeHelper.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/AttributeHelper.java
new file mode 100644 (file)
index 0000000..50d6a49
--- /dev/null
@@ -0,0 +1,364 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package oic.simulator.serviceprovider.model;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import oic.simulator.serviceprovider.utils.Constants;
+import oic.simulator.serviceprovider.utils.Utility;
+
+import org.oic.simulator.AttributeProperty;
+import org.oic.simulator.AttributeProperty.Type;
+import org.oic.simulator.AttributeValue;
+import org.oic.simulator.AttributeValue.ValueType;
+import org.oic.simulator.SimulatorResourceAttribute;
+
+public class AttributeHelper {
+    private String      attributeName;
+    private String      attributeType;
+    private String      min;
+    private String      max;
+    private Set<String> allowedValues;
+    private String      attributeDflValue;
+
+    private Type        validValuesType;
+
+    public AttributeHelper() {
+        allowedValues = new HashSet<String>();
+        setValidValuesType(Type.UNKNOWN);
+        min = max = "";
+    }
+
+    public AttributeHelper clone() {
+        AttributeHelper att = new AttributeHelper();
+        att.setAttributeName(attributeName);
+        att.setAttributeType(attributeType);
+        att.setMin(min);
+        att.setMax(max);
+        if (null != allowedValues) {
+            Set<String> values = new HashSet<String>();
+            values.addAll(allowedValues);
+            att.setAllowedValues(values);
+        }
+        att.setAttributeDflValue(attributeDflValue);
+        att.setValidValuesType(validValuesType);
+        return att;
+    }
+
+    public String toString() {
+        return attributeName + "," + attributeType + "," + attributeDflValue
+                + "," + validValuesType + ",(" + min + max + "),("
+                + allowedValues + ")";
+    }
+
+    public String getAttributeName() {
+        return attributeName;
+    }
+
+    public void setAttributeName(String attributeName) {
+        this.attributeName = attributeName;
+    }
+
+    public String getAttributeType() {
+        return attributeType;
+    }
+
+    public void setAttributeType(String attributeType) {
+        this.attributeType = attributeType;
+    }
+
+    public String getMin() {
+        return min;
+    }
+
+    public void setMin(String min) {
+        this.min = min;
+    }
+
+    public String getMax() {
+        return max;
+    }
+
+    public void setMax(String max) {
+        this.max = max;
+    }
+
+    public Set<String> getAllowedValues() {
+        return allowedValues;
+    }
+
+    public void setAllowedValues(Set<String> allowedValues) {
+        this.allowedValues = allowedValues;
+    }
+
+    public void addValueToAllowedValues(String value) {
+        if (null != value && value.trim().length() > 0) {
+            if (null == allowedValues) {
+                allowedValues = new HashSet<String>();
+            }
+            allowedValues.add(value);
+        }
+    }
+
+    public void removeValueFromAllowedValues(String value) {
+        if (null != allowedValues && null != value && value.trim().length() > 0) {
+            allowedValues.remove(value);
+        }
+    }
+
+    public void removeAllCustomValues() {
+        allowedValues.clear();
+    }
+
+    public String getAttributeDflValue() {
+        return attributeDflValue;
+    }
+
+    public void setAttributeDflValue(String attributeDflValue) {
+        this.attributeDflValue = attributeDflValue;
+    }
+
+    public Type getValidValuesType() {
+        return validValuesType;
+    }
+
+    public void setValidValuesType(Type validValuesType) {
+        this.validValuesType = validValuesType;
+    }
+
+    public boolean isValueValid(String value, String type) {
+        if (null == value || value.trim().length() < 1 || null == type
+                || type.trim().length() < 1)
+            return false;
+        if (type.equalsIgnoreCase(Constants.INT)) {
+            return isIntValue(value);
+        } else if (type.equalsIgnoreCase(Constants.DOUBLE)) {
+            return isDoubleValue(value);
+        } else if (type.equalsIgnoreCase(Constants.BOOL)) {
+            return isBoolValue(value);
+        }
+        return true;
+    }
+
+    public boolean isBoolValue(String value) {
+        boolean isBool = false;
+        if (null != value
+                && (value.equalsIgnoreCase("true") || value
+                        .equalsIgnoreCase("false"))) {
+            isBool = true;
+        }
+        return isBool;
+    }
+
+    public boolean isIntValue(String value) {
+        boolean isInt = true;
+        try {
+            Integer.parseInt(value);
+        } catch (Exception e) {
+            isInt = false;
+        }
+        return isInt;
+    }
+
+    public boolean isDoubleValue(String value) {
+        boolean isDouble = true;
+        try {
+            Double.parseDouble(value);
+        } catch (Exception e) {
+            isDouble = false;
+        }
+        return isDouble;
+    }
+
+    public boolean isRangeValid(String minStr, String maxStr, String type) {
+        if (null == type || type.trim().isEmpty()) {
+            return false;
+        }
+        boolean result = true;
+        if (type.equals(Constants.INT)) {
+            int min, max;
+            try {
+                min = Integer.parseInt(minStr);
+                max = Integer.parseInt(maxStr);
+                if (max <= min) {
+                    result = false;
+                }
+            } catch (Exception e) {
+                result = false;
+            }
+        } else if (type.equals(Constants.DOUBLE)) {
+            double min, max;
+            try {
+                min = Double.parseDouble(minStr);
+                max = Double.parseDouble(maxStr);
+                if (max <= min) {
+                    result = false;
+                }
+            } catch (Exception e) {
+                result = false;
+            }
+        }
+        return result;
+    }
+
+    public boolean isDefaultValueValid(String value) {
+        if (null == attributeType || attributeType.trim().isEmpty()) {
+            return false;
+        }
+        boolean result = true;
+        if (attributeType.equals(Constants.STRING)) {
+            if (validValuesType == Type.VALUESET && null != allowedValues) {
+                result = allowedValues.contains(value);
+            } else {
+                result = true;
+            }
+        } else if (attributeType.equals(Constants.BOOL)) {
+            String val = value.toLowerCase();
+            if (!(val.equals("true") || val.equals("false"))) {
+                result = false;
+            }
+        } else {
+            if (validValuesType == Type.RANGE) {
+                if (attributeType.equals(Constants.INT)) {
+                    int min, max, dflValue;
+                    try {
+                        min = Integer.parseInt(this.min);
+                        max = Integer.parseInt(this.max);
+                        dflValue = Integer.parseInt(value);
+                        if (dflValue < min || dflValue > max) {
+                            result = false;
+                        }
+                    } catch (Exception e) {
+                        result = false;
+                    }
+                } else if (attributeType.equals(Constants.DOUBLE)) {
+                    double min, max, dflValue;
+                    try {
+                        min = Double.parseDouble(this.min);
+                        max = Double.parseDouble(this.max);
+                        dflValue = Double.parseDouble(value);
+                        if (dflValue < min || dflValue > max) {
+                            result = false;
+                        }
+                    } catch (Exception e) {
+                        result = false;
+                    }
+                }
+            } else if (validValuesType == Type.VALUESET
+                    && null != allowedValues && !allowedValues.isEmpty()) {
+                result = allowedValues.contains(value);
+            }
+        }
+        return result;
+    }
+
+    public void setAllowedValuesByArray(String[] cusItems) {
+        if (null == cusItems) {
+            return;
+        }
+        for (String item : cusItems) {
+            addValueToAllowedValues(item);
+        }
+    }
+
+    public boolean isAllowedValueExist(String[] items, String value) {
+        if (null == items || items.length < 1 || null == value
+                || value.isEmpty())
+            return false;
+        for (String item : items) {
+            if (value.equalsIgnoreCase(item)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public LocalResourceAttribute convertToLocalResourceAttribute() {
+        LocalResourceAttribute attribute = new LocalResourceAttribute();
+
+        // Initially disabling the automation
+        attribute.setAutomationInProgress(false);
+
+        // Assigning the default automation interval
+        attribute
+                .setAutomationUpdateInterval(Constants.DEFAULT_AUTOMATION_INTERVAL);
+
+        // Setting the default automation type
+        attribute.setAutomationType(Constants.DEFAULT_AUTOMATION_TYPE);
+
+        AttributeValue attValue = null;
+        AttributeProperty attProperty = null;
+        SimulatorResourceAttribute simResAtt;
+
+        ValueType valueType = Utility.getAttributeTypeEnum(attributeType);
+        switch (valueType) {
+            case INTEGER:
+                attValue = new AttributeValue(
+                        Integer.parseInt(attributeDflValue));
+                if (validValuesType == Type.VALUESET) {
+                    attProperty = new AttributeProperty(
+                            Utility.convertSetToArrayInt(Utility
+                                    .convertSetStringToSetObject(allowedValues,
+                                            valueType)));
+                } else if (validValuesType == Type.RANGE) {
+                    attProperty = new AttributeProperty(
+                            Double.parseDouble(min), Double.parseDouble(max));
+                } else {
+                    attProperty = null;
+                }
+            case DOUBLE:
+                attValue = new AttributeValue(
+                        Double.parseDouble(attributeDflValue));
+                if (validValuesType == Type.VALUESET) {
+                    attProperty = new AttributeProperty(
+                            Utility.convertSetToArrayDouble(Utility
+                                    .convertSetStringToSetObject(allowedValues,
+                                            valueType)));
+                } else if (validValuesType == Type.RANGE) {
+                    attProperty = new AttributeProperty(
+                            Double.parseDouble(min), Double.parseDouble(max));
+                } else {
+                    attProperty = null;
+                }
+                break;
+            case BOOLEAN:
+                attValue = new AttributeValue(
+                        Boolean.parseBoolean(attributeDflValue));
+                boolean[] arr = { true, false };
+                attProperty = new AttributeProperty(arr);
+                break;
+            case STRING:
+                attValue = new AttributeValue(attributeDflValue);
+                if (validValuesType == Type.VALUESET) {
+                    attProperty = new AttributeProperty(
+                            Utility.convertSetToArrayString(Utility
+                                    .convertSetStringToSetObject(allowedValues,
+                                            valueType)));
+                } else {
+                    attProperty = null;
+                }
+                break;
+            default:
+                break;
+        }
+        simResAtt = new SimulatorResourceAttribute(attributeName, attValue,
+                attProperty);
+        attribute.setResourceAttributeRef(simResAtt);
+        return attribute;
+    }
+}
\ No newline at end of file
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package oic.simulator.serviceprovider.resource;
+package oic.simulator.serviceprovider.model;
 
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -22,7 +22,7 @@ import java.util.List;
 
 import oic.simulator.serviceprovider.utils.Constants;
 
-import org.oic.simulator.serviceprovider.AutomationType;
+import org.oic.simulator.server.SimulatorResource.AutoUpdateType;
 
 /**
  * This is a helper class for providing the automation settings information to
@@ -67,36 +67,44 @@ public class AutomationSettingHelper {
             LocalResourceAttribute attribute) {
         List<AutomationSettingHelper> settingList = null;
         boolean invalidSetting;
-        if (null != attribute) {
-            settingList = new ArrayList<AutomationSettingHelper>();
-            for (int count = 0; count < Constants.AUTOMATION_SETTINGS_COUNT; count++) {
-                invalidSetting = false;
-                AutomationSettingHelper setting = new AutomationSettingHelper();
-                if (Constants.AUTOMATION_SETTINGS[count]
-                        .equals(Constants.AUTOMATION_TYPE)) {
-                    setting.setSettingID(Constants.AUTOMATION_TYPE);
+
+        settingList = new ArrayList<AutomationSettingHelper>();
+        for (int count = 0; count < Constants.AUTOMATION_SETTINGS_COUNT; count++) {
+            invalidSetting = false;
+            AutomationSettingHelper setting = new AutomationSettingHelper();
+            if (Constants.AUTOMATION_SETTINGS[count]
+                    .equals(Constants.AUTOMATION_TYPE)) {
+                setting.setSettingID(Constants.AUTOMATION_TYPE);
+                if (null != attribute) {
                     setting.setSettingValue(attribute.getAutomationType()
                             .toString());
-                    List<String> valueList = new ArrayList<String>();
-                    valueList.add(AutomationType.NORMAL.toString());
-                    valueList.add(AutomationType.RECURRENT.toString());
-                    setting.setAllowedValues(valueList);
-                } else if (Constants.AUTOMATION_SETTINGS[count]
-                        .equals(Constants.UPDATE_INTERVAL_IN_MS)) {
-                    setting.setSettingID(Constants.UPDATE_INTERVAL_IN_MS);
+                } else {
+                    setting.setSettingValue(AutoUpdateType.ONE_TIME.toString());
+                }
+                List<String> valueList = new ArrayList<String>();
+                valueList.add(AutoUpdateType.ONE_TIME.toString());
+                valueList.add(AutoUpdateType.REPEAT.toString());
+                setting.setAllowedValues(valueList);
+            } else if (Constants.AUTOMATION_SETTINGS[count]
+                    .equals(Constants.UPDATE_INTERVAL_IN_MS)) {
+                setting.setSettingID(Constants.UPDATE_INTERVAL_IN_MS);
+                if (null != attribute) {
                     setting.setSettingValue(String.valueOf(attribute
                             .getAutomationUpdateInterval()));
-                    List<String> valueList = new ArrayList<String>();
-                    for (int index = 1; index <= 10; index++) {
-                        valueList.add(String.valueOf(index * 500));
-                    }
-                    setting.setAllowedValues(valueList);
                 } else {
-                    invalidSetting = true;
+                    setting.setSettingValue(String
+                            .valueOf(Constants.DEFAULT_AUTOMATION_INTERVAL));
                 }
-                if (!invalidSetting) {
-                    settingList.add(setting);
+                List<String> valueList = new ArrayList<String>();
+                for (int index = 1; index <= 10; index++) {
+                    valueList.add(String.valueOf(index * 500));
                 }
+                setting.setAllowedValues(valueList);
+            } else {
+                invalidSetting = true;
+            }
+            if (!invalidSetting) {
+                settingList.add(setting);
             }
         }
         return settingList;
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/CollectionResource.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/CollectionResource.java
new file mode 100644 (file)
index 0000000..ff41152
--- /dev/null
@@ -0,0 +1,221 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package oic.simulator.serviceprovider.model;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.oic.simulator.SimulatorException;
+import org.oic.simulator.server.SimulatorCollectionResource;
+import org.oic.simulator.server.SimulatorResource;
+
+public class CollectionResource extends Resource {
+    private Set<Resource>           childResources;
+    private Set<String>             supportedResourceTypes;
+
+    private Set<CollectionResource> membership;
+
+    public CollectionResource() {
+        childResources = new HashSet<Resource>();
+        supportedResourceTypes = new HashSet<String>();
+        membership = new HashSet<CollectionResource>();
+        setDeviceMembership(new HashSet<Device>());
+    }
+
+    public Set<String> getSupportedResourceTypes() {
+        return supportedResourceTypes;
+    }
+
+    public void setSupportedResourceTypes(Set<String> supportedResourceTypes) {
+        this.supportedResourceTypes = supportedResourceTypes;
+    }
+
+    public void addSupportedResourceType(String rType) {
+        if (null == supportedResourceTypes) {
+            supportedResourceTypes = new HashSet<String>();
+        }
+        supportedResourceTypes.add(rType);
+    }
+
+    public void removeSupportedResourceType(String rType) {
+        if (null != supportedResourceTypes) {
+            supportedResourceTypes.remove(rType);
+        }
+    }
+
+    public Set<Resource> getChildResources() {
+        return childResources;
+    }
+
+    public Set<SingleResource> getSingleTypeChildResources() {
+        if (null == childResources || childResources.isEmpty()) {
+            return null;
+        }
+        Set<SingleResource> resultSet = new HashSet<SingleResource>();
+        Iterator<Resource> itr = childResources.iterator();
+        Resource res;
+        while (itr.hasNext()) {
+            res = itr.next();
+            if (null != res) {
+                if (res instanceof SingleResource) {
+                    resultSet.add((SingleResource) res);
+                }
+            }
+        }
+        return resultSet;
+    }
+
+    public Set<CollectionResource> getCollectionTypeChildResources() {
+        if (null == childResources || childResources.isEmpty()) {
+            return null;
+        }
+        Set<CollectionResource> resultSet = new HashSet<CollectionResource>();
+        Iterator<Resource> itr = childResources.iterator();
+        Resource res;
+        while (itr.hasNext()) {
+            res = itr.next();
+            if (null != res) {
+                if (res instanceof CollectionResource) {
+                    resultSet.add((CollectionResource) res);
+                }
+            }
+        }
+        return resultSet;
+    }
+
+    public void setChildResources(Set<Resource> childResources) {
+        this.childResources = childResources;
+    }
+
+    public void addChildResource(Resource resource) throws SimulatorException {
+        if (null == resource) {
+            return;
+        }
+        if (null == childResources) {
+            childResources = new HashSet<Resource>();
+        }
+
+        // Native call to add child resource
+        SimulatorResource simRes;
+        simRes = resource.getSimulatorResource();
+        ((SimulatorCollectionResource) simulatorResource)
+                .addChildResource(simRes);
+
+        childResources.add(resource);
+    }
+
+    public void addChildResource(Set<Resource> resources)
+            throws SimulatorException {
+        if (null == resources || resources.isEmpty()) {
+            return;
+        }
+        if (null == childResources) {
+            childResources = new HashSet<Resource>();
+        }
+
+        // Native call to add child resource
+        SimulatorResource simRes;
+        Resource res;
+        Iterator<Resource> itr = resources.iterator();
+        while (itr.hasNext()) {
+            res = itr.next();
+            simRes = res.getSimulatorResource();
+            ((SimulatorCollectionResource) simulatorResource)
+                    .addChildResource(simRes);
+
+            childResources.add(res);
+        }
+    }
+
+    public void removeChildResource(Resource resource)
+            throws SimulatorException {
+        if (null == resource || null == childResources) {
+            return;
+        }
+
+        // Native call to add child resource
+        SimulatorResource simRes;
+        simRes = resource.getSimulatorResource();
+        ((SimulatorCollectionResource) simulatorResource)
+                .removeChildResource(simRes);
+
+        childResources.remove(resource);
+    }
+
+    public void removeChildResource(Set<Resource> resources)
+            throws SimulatorException {
+        if (null == resources || null == childResources) {
+            return;
+        }
+
+        // Native call to add child resource
+        SimulatorResource simRes;
+        Resource res;
+        Iterator<Resource> itr = resources.iterator();
+        while (itr.hasNext()) {
+            res = itr.next();
+            simRes = res.getSimulatorResource();
+            ((SimulatorCollectionResource) simulatorResource)
+                    .removeChildResource(simRes);
+
+            childResources.remove(res);
+        }
+    }
+
+    public Set<CollectionResource> getMembership() {
+        return membership;
+    }
+
+    public void setMembership(Set<CollectionResource> membership) {
+        this.membership = membership;
+    }
+
+    public void addMembership(CollectionResource resource) {
+        if (null == resource) {
+            return;
+        }
+        if (null == membership) {
+            membership = new HashSet<CollectionResource>();
+        }
+        membership.add(resource);
+    }
+
+    public void addMembership(Set<CollectionResource> resources) {
+        if (null == resources) {
+            return;
+        }
+        if (null == membership) {
+            membership = new HashSet<CollectionResource>();
+        }
+        membership.addAll(resources);
+    }
+
+    public void removeMembership(CollectionResource resource) {
+        if (null == resource || null == membership) {
+            return;
+        }
+        membership.remove(resource);
+    }
+
+    public void removeMembership(Set<CollectionResource> collections) {
+        if (null == collections || null == membership) {
+            return;
+        }
+        membership.removeAll(collections);
+    }
+}
\ No newline at end of file
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/Device.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/Device.java
new file mode 100644 (file)
index 0000000..f1a9879
--- /dev/null
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package oic.simulator.serviceprovider.model;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+public class Device {
+    private String        deviceName;
+
+    private Set<Resource> childResources;
+
+    public Device() {
+        childResources = new HashSet<Resource>();
+    }
+
+    public String getDeviceName() {
+        return deviceName;
+    }
+
+    public void setDeviceName(String deviceName) {
+        this.deviceName = deviceName;
+    }
+
+    public Set<Resource> getChildResources() {
+        return childResources;
+    }
+
+    public void setChildResources(Set<Resource> childResources) {
+        this.childResources = childResources;
+    }
+
+    public void addChildResource(Resource resource) {
+        if (null == resource) {
+            return;
+        }
+        if (null == childResources) {
+            childResources = new HashSet<Resource>();
+        }
+        childResources.add(resource);
+    }
+
+    public void addChildResource(Set<Resource> resources) {
+        if (null == resources) {
+            return;
+        }
+        if (null == childResources) {
+            childResources = new HashSet<Resource>();
+        }
+        childResources.addAll(resources);
+    }
+
+    public void removeChildResource(Resource resource) {
+        if (null == resource || null == childResources) {
+            return;
+        }
+        childResources.remove(resource);
+    }
+
+    public void removeChildResource(Set<Resource> resources) {
+        if (null == resources || null == childResources) {
+            return;
+        }
+        childResources.removeAll(resources);
+    }
+
+    public Set<SingleResource> getSingleTypeChildResources() {
+        if (null == childResources || childResources.isEmpty()) {
+            return null;
+        }
+        Set<SingleResource> resultSet = new HashSet<SingleResource>();
+        Iterator<Resource> itr = childResources.iterator();
+        Resource res;
+        while (itr.hasNext()) {
+            res = itr.next();
+            if (null != res) {
+                if (res instanceof SingleResource) {
+                    resultSet.add((SingleResource) res);
+                }
+            }
+        }
+        return resultSet;
+    }
+
+    public Set<CollectionResource> getCollectionTypeChildResources() {
+        if (null == childResources || childResources.isEmpty()) {
+            return null;
+        }
+        Set<CollectionResource> resultSet = new HashSet<CollectionResource>();
+        Iterator<Resource> itr = childResources.iterator();
+        Resource res;
+        while (itr.hasNext()) {
+            res = itr.next();
+            if (null != res) {
+                if (res instanceof CollectionResource) {
+                    resultSet.add((CollectionResource) res);
+                }
+            }
+        }
+        return resultSet;
+    }
+}
\ No newline at end of file
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/LocalResourceAttribute.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/LocalResourceAttribute.java
new file mode 100644 (file)
index 0000000..e958fa1
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package oic.simulator.serviceprovider.model;
+
+import org.oic.simulator.SimulatorResourceAttribute;
+import org.oic.simulator.server.SimulatorResource.AutoUpdateType;
+
+/**
+ * This class represents an attribute in the simulated resource.
+ */
+public class LocalResourceAttribute {
+
+    // Java SDK object reference
+    private SimulatorResourceAttribute resourceAttributeRef;
+
+    private int                        automationId;
+
+    private boolean                    automationInProgress;
+
+    private int                        automationUpdateInterval;
+
+    private AutoUpdateType             automationType;
+
+    public SimulatorResourceAttribute getResourceAttributeRef() {
+        return resourceAttributeRef;
+    }
+
+    public void setResourceAttributeRef(
+            SimulatorResourceAttribute resourceAttribute) {
+        this.resourceAttributeRef = resourceAttribute;
+    }
+
+    public int getAutomationId() {
+        return automationId;
+    }
+
+    public void setAutomationId(int automationId) {
+        this.automationId = automationId;
+    }
+
+    public boolean isAutomationInProgress() {
+        return automationInProgress;
+    }
+
+    public void setAutomationInProgress(boolean automationInProgress) {
+        this.automationInProgress = automationInProgress;
+    }
+
+    public int getAutomationUpdateInterval() {
+        return automationUpdateInterval;
+    }
+
+    public void setAutomationUpdateInterval(int automationUpdateInterval) {
+        this.automationUpdateInterval = automationUpdateInterval;
+    }
+
+    public AutoUpdateType getAutomationType() {
+        return automationType;
+    }
+
+    public void setAutomationType(AutoUpdateType automationType) {
+        this.automationType = automationType;
+    }
+}
\ No newline at end of file
  * limitations under the License.
  */
 
-package oic.simulator.serviceprovider.resource;
+package oic.simulator.serviceprovider.model;
 
-import org.oic.simulator.serviceprovider.ObserverInfo;
+import org.oic.simulator.server.Observer;
 
 /**
  * This class holds observer details of resources.
  */
 public class ObserverDetail {
 
-    private ObserverInfo observerInfo;
-    private boolean      isClicked;
+    private Observer observerInfo;
+    private boolean  isClicked;
 
-    public ObserverInfo getObserverInfo() {
+    public Observer getObserverInfo() {
         return observerInfo;
     }
 
-    public void setObserverInfo(ObserverInfo observerInfo) {
+    public void setObserverInfo(Observer observerInfo) {
         this.observerInfo = observerInfo;
     }
 
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/Resource.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/Resource.java
new file mode 100644 (file)
index 0000000..5772cc2
--- /dev/null
@@ -0,0 +1,260 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package oic.simulator.serviceprovider.model;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.oic.simulator.SimulatorResourceModel;
+import org.oic.simulator.server.Observer;
+import org.oic.simulator.server.SimulatorResource;
+
+public abstract class Resource {
+
+    // Java SDK object reference
+    SimulatorResource                           simulatorResource;
+    private SimulatorResourceModel              resourceModel;
+
+    private String                              resourceURI;
+    private String                              resourceName;
+    private Set<String>                         resourceTypes;
+    private Set<String>                         resourceInterfaces;
+    private boolean                             started;
+    private boolean                             observable;
+
+    private Set<Device>                         deviceMembership;
+
+    private Map<String, LocalResourceAttribute> attributes;
+
+    private Map<Integer, ObserverDetail>        observers;
+
+    public Resource() {
+        resourceTypes = new HashSet<String>();
+        resourceInterfaces = new HashSet<String>();
+        observers = new HashMap<Integer, ObserverDetail>();
+    }
+
+    public SimulatorResource getSimulatorResource() {
+        return simulatorResource;
+    }
+
+    public void setSimulatorResource(SimulatorResource simulatorResource) {
+        this.simulatorResource = simulatorResource;
+    }
+
+    public SimulatorResourceModel getResourceModel() {
+        return resourceModel;
+    }
+
+    public void setResourceModel(SimulatorResourceModel resourceModel) {
+        this.resourceModel = resourceModel;
+    }
+
+    public String getResourceURI() {
+        return resourceURI;
+    }
+
+    public void setResourceURI(String resourceURI) {
+        this.resourceURI = resourceURI;
+    }
+
+    public String getResourceName() {
+        return resourceName;
+    }
+
+    public void setResourceName(String resourceName) {
+        this.resourceName = resourceName;
+    }
+
+    public Set<String> getResourceTypes() {
+        return resourceTypes;
+    }
+
+    public void setResourceTypes(Set<String> resourceTypes) {
+        this.resourceTypes = resourceTypes;
+    }
+
+    public Set<String> getResourceInterfaces() {
+        return resourceInterfaces;
+    }
+
+    public void setResourceInterfaces(Set<String> resourceInterfaces) {
+        this.resourceInterfaces = resourceInterfaces;
+    }
+
+    public boolean isStarted() {
+        return started;
+    }
+
+    public void setStarted(boolean started) {
+        this.started = started;
+    }
+
+    public boolean isObservable() {
+        return observable;
+    }
+
+    public void setObservable(boolean observable) {
+        this.observable = observable;
+    }
+
+    public void addResourceType(String resType) {
+        if (null == resType) {
+            return;
+        }
+        if (null == resourceTypes) {
+            resourceTypes = new HashSet<String>();
+        }
+        resourceTypes.add(resType);
+    }
+
+    public void removeResourceType(String resType) {
+        if (null == resType || null == resourceTypes) {
+            return;
+        }
+        resourceTypes.remove(resType);
+    }
+
+    public boolean isResourceTypeExist(String resType) {
+        if (null == resType || null == resourceTypes) {
+            return false;
+        }
+        return resourceTypes.contains(resType);
+    }
+
+    public void addInterfaceType(String ifType) {
+        if (null == ifType) {
+            return;
+        }
+        if (null == resourceInterfaces) {
+            resourceInterfaces = new HashSet<String>();
+        }
+        resourceInterfaces.add(ifType);
+    }
+
+    public void removeInterfaceType(String ifType) {
+        if (null == ifType || null == resourceInterfaces) {
+            return;
+        }
+        resourceInterfaces.remove(ifType);
+    }
+
+    public boolean isInterfaceTypeExist(String ifType) {
+        if (null == ifType || null == resourceInterfaces) {
+            return false;
+        }
+        return resourceInterfaces.contains(ifType);
+    }
+
+    public Map<Integer, ObserverDetail> getObserver() {
+        return observers;
+    }
+
+    public void addObserverInfo(Observer observer) {
+        if (null == observer) {
+            return;
+        }
+        int id = observer.getId();
+        if (!observers.containsKey(id)) {
+            ObserverDetail obsDetail = new ObserverDetail();
+            obsDetail.setObserverInfo(observer);
+            observers.put(id, obsDetail);
+        }
+    }
+
+    public void removeObserverInfo(Observer observer) {
+        if (null == observer) {
+            return;
+        }
+        observers.remove(observer.getId());
+    }
+
+    public Set<Device> getDeviceMembership() {
+        return deviceMembership;
+    }
+
+    public void setDeviceMembership(Set<Device> deviceMembership) {
+        this.deviceMembership = deviceMembership;
+    }
+
+    public void addDeviceMembership(Device dev) {
+        if (null == dev) {
+            return;
+        }
+        if (null == deviceMembership) {
+            deviceMembership = new HashSet<Device>();
+        }
+        deviceMembership.add(dev);
+    }
+
+    public void addDeviceMembership(Set<Device> devices) {
+        if (null == devices) {
+            return;
+        }
+        if (null == deviceMembership) {
+            deviceMembership = new HashSet<Device>();
+        }
+        deviceMembership.addAll(devices);
+    }
+
+    public void removeDeviceMembership(Device dev) {
+        if (null == dev || null == deviceMembership) {
+            return;
+        }
+        deviceMembership.remove(dev);
+    }
+
+    public void removeDeviceMembership(Set<Device> devices) {
+        if (null == devices || null == deviceMembership) {
+            return;
+        }
+        deviceMembership.removeAll(devices);
+    }
+
+    public boolean isMemberOfAnyDevice() {
+        if (null == deviceMembership || deviceMembership.isEmpty()) {
+            return false;
+        }
+        return true;
+    }
+
+    public Map<String, LocalResourceAttribute> getResourceAttributes() {
+        return attributes;
+    }
+
+    public void setResourceAttributes(
+            Map<String, LocalResourceAttribute> attributes) {
+        this.attributes = attributes;
+    }
+
+    // Added for debugging purpose
+    public void printResourceInfo() {
+        System.out.println("Resource URI: " + getResourceURI());
+        System.out.println("Resource Name: " + getResourceName());
+        System.out.println("Resource types: " + getResourceTypes());
+        System.out.println("Resource Interfaces: " + getResourceInterfaces());
+        System.out.println("Resource Attributes:-");
+        /*
+         * if (null != resourceAttributesMap) { Iterator<String> attItr =
+         * resourceAttributesMap.keySet().iterator(); while (attItr.hasNext()) {
+         * resourceAttributesMap.get(attItr.next()) .printAttributeDetails();; }
+         * }
+         */
+    }
+}
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/ResourceCategory.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/ResourceCategory.java
new file mode 100644 (file)
index 0000000..b932abc
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package oic.simulator.serviceprovider.model;
+
+public enum ResourceCategory {
+    SIMPLE, COLLECTION
+}
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/ResourceType.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/ResourceType.java
new file mode 100644 (file)
index 0000000..f9ec137
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package oic.simulator.serviceprovider.model;
+
+public enum ResourceType {
+    SINGLE, COLLECTION, DEVICE
+}
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/SRMItem.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/SRMItem.java
new file mode 100644 (file)
index 0000000..f003e3a
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package oic.simulator.serviceprovider.model;
+
+import org.oic.simulator.SimulatorResourceModel;
+
+public class SRMItem {
+    private int                    index;
+    private SimulatorResourceModel model;
+
+    public SRMItem(int index, SimulatorResourceModel model) {
+        this.index = index;
+        this.model = model;
+    }
+
+    public int getIndex() {
+        return index;
+    }
+
+    public void setIndex(int index) {
+        this.index = index;
+    }
+
+    public SimulatorResourceModel getModel() {
+        return model;
+    }
+
+    public void setModel(SimulatorResourceModel model) {
+        this.model = model;
+    }
+}
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/SerializedServiceProvider.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/SerializedServiceProvider.java
new file mode 100644 (file)
index 0000000..6db7486
--- /dev/null
@@ -0,0 +1,167 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package oic.simulator.serviceprovider.model;
+
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+
+public class SerializedServiceProvider implements Serializable {
+
+    public class SerializedAttribute implements Serializable {
+
+        public String getName() {
+            return m_name;
+        }
+
+        public void setName(String name) {
+            this.m_name = name;
+        }
+
+        public Object getValue() {
+            return m_value;
+        }
+
+        public void setValue(Object value) {
+            this.m_value = value;
+        }
+
+        public String getType() {
+            return m_type;
+        }
+
+        public void setType(String type) {
+            this.m_type = type;
+        }
+
+        public int getMin() {
+            return m_min;
+        }
+
+        public void setMin(int min) {
+            this.m_min = min;
+        }
+
+        public int getMax() {
+            return m_max;
+        }
+
+        public void setMax(int max) {
+            this.m_max = max;
+        }
+
+        public Object getAllowedValues() {
+            return m_AllowedValues;
+        }
+
+        public void setAllowedValues(Object allowedValues) {
+            this.m_AllowedValues = allowedValues;
+        }
+
+        private String m_name          = null;
+        private Object m_value         = null;
+        private String m_type          = null;
+        private int    m_min           = 0;
+        private int    m_max           = 0;
+        private Object m_AllowedValues = null;
+    }
+
+    public String getResourceName() {
+        return m_resourceName;
+    }
+
+    public void setResourceName(String resourceName) {
+        this.m_resourceName = resourceName;
+    }
+
+    public String getUri() {
+        return m_uri;
+    }
+
+    public void setUri(String uri) {
+        this.m_uri = uri;
+    }
+
+    public String getResourceType() {
+        return m_resourceType;
+    }
+
+    public void setResourceType(String resourceType) {
+        this.m_resourceType = resourceType;
+    }
+
+    public List<String> getInterfaceType() {
+        return m_interfaceType;
+    }
+
+    public void setInterfaceType(List<String> interfaceType) {
+        this.m_interfaceType = interfaceType;
+    }
+
+    public Map<String, SerializedAttribute> getResourceAttributesMap() {
+        return m_resourceAttributesMap;
+    }
+
+    public void setResourceAttributesMap(
+            Map<String, SerializedAttribute> resourceAttributesMap) {
+        this.m_resourceAttributesMap = resourceAttributesMap;
+    }
+
+    public void serialize(String filePath) throws SimulatorPluginException {
+        try {
+            FileOutputStream fileOut = new FileOutputStream(filePath);
+            ObjectOutputStream out = new ObjectOutputStream(fileOut);
+            out.writeObject(this);
+            out.close();
+            fileOut.close();
+        } catch (IOException i) {
+            throw new SimulatorPluginException(
+                    "Failed to Serialize data : IOException");
+        }
+    }
+
+    public static SerializedServiceProvider deSerialize(String filePath)
+            throws SimulatorPluginException {
+        SerializedServiceProvider r = null;
+        try {
+            FileInputStream fileIn = new FileInputStream(filePath);
+            ObjectInputStream in = new ObjectInputStream(fileIn);
+            r = (SerializedServiceProvider) in.readObject();
+            in.close();
+            fileIn.close();
+        } catch (IOException i) {
+            throw new SimulatorPluginException(
+                    "Failed to DeSerialize data : IOException");
+        } catch (ClassNotFoundException c) {
+            throw new SimulatorPluginException(
+                    "Failed to DeSerialize data : ClassNotFound");
+        }
+        return r;
+    }
+
+    private String                           m_resourceName;
+    private String                           m_uri;
+    private String                           m_resourceType;
+    private List<String>                     m_interfaceType;
+    private Map<String, SerializedAttribute> m_resourceAttributesMap;
+
+}
\ No newline at end of file
  * limitations under the License.
  */
 
-package oic.simulator.serviceprovider.view;
-
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.ui.part.ViewPart;
+package oic.simulator.serviceprovider.model;
 
 /**
- * This class manages and shows the multi-resource automation view in the
- * perspective.
+ * This class represents the plug-in level exceptions.
  */
-public class MultiResourceOrchestrationView extends ViewPart {
-
-    public static final String VIEW_ID = "oic.simulator.serviceprovider.view.orchestration";
+@SuppressWarnings("serial")
+public class SimulatorPluginException extends Exception {
+    String msg;
 
-    @Override
-    public void createPartControl(Composite arg0) {
-        // TODO: To be done
+    public SimulatorPluginException(String msg) {
+        this.msg = msg;
     }
 
-    @Override
-    public void setFocus() {
-        // TODO To be done
+    public String toString() {
+        return msg;
     }
-}
\ No newline at end of file
+}
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/SingleResource.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/SingleResource.java
new file mode 100644 (file)
index 0000000..899bc60
--- /dev/null
@@ -0,0 +1,173 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package oic.simulator.serviceprovider.model;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.oic.simulator.server.SimulatorResource.AutoUpdateType;
+
+/**
+ * This class represents a simulated resource. It maintains all the necessary
+ * information about the resource.
+ */
+public class SingleResource extends Resource {
+    private Set<CollectionResource> collectionMembership;
+
+    private boolean                 getAllowed;
+
+    private boolean                 putAllowed;
+
+    private boolean                 postAllowed;
+
+    private int                     automationId;
+
+    private boolean                 resourceAutomationInProgress;
+
+    private boolean                 attributeAutomationInProgress;
+
+    private int                     automationUpdateInterval;
+
+    private AutoUpdateType          automationType;
+
+    public SingleResource() {
+        setCollectionMembership(new HashSet<CollectionResource>());
+    }
+
+    public Set<CollectionResource> getCollectionMembership() {
+        return collectionMembership;
+    }
+
+    public void setCollectionMembership(
+            Set<CollectionResource> collectionMembership) {
+        this.collectionMembership = collectionMembership;
+    }
+
+    public void addCollectionMembership(CollectionResource resource) {
+        if (null == resource) {
+            return;
+        }
+        if (null == collectionMembership) {
+            collectionMembership = new HashSet<CollectionResource>();
+        }
+        collectionMembership.add(resource);
+    }
+
+    public void addCollectionMembership(Set<CollectionResource> resources) {
+        if (null == resources) {
+            return;
+        }
+        if (null == collectionMembership) {
+            collectionMembership = new HashSet<CollectionResource>();
+        }
+        collectionMembership.addAll(resources);
+    }
+
+    public void removeCollectionMembership(CollectionResource resource) {
+        if (null == resource || null == collectionMembership) {
+            return;
+        }
+        collectionMembership.remove(resource);
+    }
+
+    public void removeCollectionMembership(Set<CollectionResource> collections) {
+        if (null == collections || null == collectionMembership) {
+            return;
+        }
+        collectionMembership.removeAll(collections);
+    }
+
+    public boolean isMemberOfAnyCollection() {
+        if (null == collectionMembership || collectionMembership.isEmpty()) {
+            return false;
+        }
+        return true;
+    }
+
+    public boolean isGetAllowed() {
+        return getAllowed;
+    }
+
+    public void setGetAllowed(boolean getAllowed) {
+        this.getAllowed = getAllowed;
+    }
+
+    public boolean isPutAllowed() {
+        return putAllowed;
+    }
+
+    public void setPutAllowed(boolean putAllowed) {
+        this.putAllowed = putAllowed;
+    }
+
+    public boolean isPostAllowed() {
+        return postAllowed;
+    }
+
+    public void setPostAllowed(boolean postAllowed) {
+        this.postAllowed = postAllowed;
+    }
+
+    public int getAutomationUpdateInterval() {
+        return automationUpdateInterval;
+    }
+
+    public void setAutomationUpdateInterval(int automationUpdateInterval) {
+        this.automationUpdateInterval = automationUpdateInterval;
+    }
+
+    public AutoUpdateType getAutomationType() {
+        return automationType;
+    }
+
+    public void setAutomationType(AutoUpdateType automationType) {
+        this.automationType = automationType;
+    }
+
+    public int getAutomationId() {
+        return automationId;
+    }
+
+    public void setAutomationId(int automationId) {
+        this.automationId = automationId;
+    }
+
+    public boolean isResourceAutomationInProgress() {
+        return resourceAutomationInProgress;
+    }
+
+    public void setResourceAutomationInProgress(
+            boolean resourceAutomationInProgress) {
+        this.resourceAutomationInProgress = resourceAutomationInProgress;
+    }
+
+    public boolean isAttributeAutomationInProgress() {
+        return attributeAutomationInProgress;
+    }
+
+    public void setAttributeAutomationInProgress(
+            boolean attributeAutomationInProgress) {
+        this.attributeAutomationInProgress = attributeAutomationInProgress;
+    }
+
+    /*
+     * public LocalResourceAttribute getAttribute(String attributeName) { if
+     * (null == attributeName || null == resourceAttributesMap ||
+     * resourceAttributesMap.size() < 1) { return null; } return
+     * resourceAttributesMap.get(attributeName); }
+     */
+}
\ No newline at end of file
index 079f645..e24a456 100644 (file)
@@ -19,7 +19,7 @@ package oic.simulator.serviceprovider.perspective;
 import oic.simulator.serviceprovider.view.AttributeView;
 import oic.simulator.serviceprovider.view.LogView;
 import oic.simulator.serviceprovider.view.MetaPropertiesView;
-import oic.simulator.serviceprovider.view.MultiResourceOrchestrationView;
+import oic.simulator.serviceprovider.view.DevicePlatformInfoView;
 import oic.simulator.serviceprovider.view.ResourceManagerView;
 import oic.simulator.serviceprovider.view.ResourceObserverView;
 
@@ -58,7 +58,7 @@ public class PerspectiveFactory implements IPerspectiveFactory {
                 factory.getEditorArea());
         factory.addView(LogView.VIEW_ID, IPageLayout.BOTTOM, 0.65f,
                 AttributeView.VIEW_ID);
-        factory.addView(MultiResourceOrchestrationView.VIEW_ID,
-                IPageLayout.RIGHT, 0.6f, AttributeView.VIEW_ID);
+        factory.addView(DevicePlatformInfoView.VIEW_ID, IPageLayout.RIGHT,
+                0.6f, AttributeView.VIEW_ID);
     }
 }
\ No newline at end of file
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/LocalResourceAttribute.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/LocalResourceAttribute.java
deleted file mode 100644 (file)
index b1c8de6..0000000
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package oic.simulator.serviceprovider.resource;
-
-import java.util.List;
-
-import org.oic.simulator.ResourceAttribute;
-import org.oic.simulator.ResourceAttribute.Range;
-import org.oic.simulator.ResourceAttribute.Type;
-import org.oic.simulator.serviceprovider.AutomationType;
-
-/**
- * This class represents an attribute in the simulated resource.
- */
-public class LocalResourceAttribute {
-
-    // Native object reference
-    private ResourceAttribute resourceAttribute;
-
-    private Object            attributeValue;
-    private List<String>      attValues;
-
-    private int               automationId;
-
-    private boolean           automationInProgress;
-
-    private int               automationUpdateInterval;
-
-    private AutomationType    automationType;
-
-    public ResourceAttribute getResourceAttribute() {
-        return resourceAttribute;
-    }
-
-    public void setResourceAttribute(ResourceAttribute resourceAttribute) {
-        this.resourceAttribute = resourceAttribute;
-    }
-
-    public String getAttributeName() {
-        return resourceAttribute.getName();
-    }
-
-    public Object getAttributeValue() {
-        return attributeValue;
-    }
-
-    public void setAttributeValue(Object attributeValue) {
-        this.attributeValue = attributeValue;
-    }
-
-    public Object[] getAllowedValues() {
-        return resourceAttribute.getAllowedValues();
-    }
-
-    public Object getMinValue() {
-        Range range = resourceAttribute.getRange();
-        if (null == range)
-            return null;
-        return range.getMin();
-    }
-
-    public Object getMaxValue() {
-        Range range = resourceAttribute.getRange();
-        if (null == range)
-            return null;
-        return range.getMax();
-    }
-
-    public boolean isAutomationInProgress() {
-        return automationInProgress;
-    }
-
-    public void setAutomationInProgress(boolean automationInProgress) {
-        this.automationInProgress = automationInProgress;
-    }
-
-    public int getAutomationUpdateInterval() {
-        return automationUpdateInterval;
-    }
-
-    public void setAutomationUpdateInterval(int automationUpdateInterval) {
-        this.automationUpdateInterval = automationUpdateInterval;
-    }
-
-    public AutomationType getAutomationType() {
-        return automationType;
-    }
-
-    public void setAutomationType(AutomationType automationType) {
-        this.automationType = automationType;
-    }
-
-    public int getAutomationId() {
-        return automationId;
-    }
-
-    public void setAutomationId(int automationId) {
-        this.automationId = automationId;
-    }
-
-    public Type getAttValType() {
-        return resourceAttribute.getType();
-    }
-
-    public Type getAttValBaseType() {
-        return resourceAttribute.getBaseType();
-    }
-
-    public List<String> getAttValues() {
-        return attValues;
-    }
-
-    public void setAttValues(List<String> attValues) {
-        this.attValues = attValues;
-    }
-
-    public void printAttributeDetails() {
-        System.out.println("Attribute Name:" + resourceAttribute.getName());
-        System.out.println("Attribute Value:" + resourceAttribute.getValue());
-        System.out.println("Attribute Base Type:"
-                + resourceAttribute.getBaseType());
-        System.out.println("Attribute Type:" + resourceAttribute.getType());
-        System.out.print("Allowed Values:");
-        Object[] values = getAllowedValues();
-        for (Object obj : values) {
-            System.out.print(obj);
-        }
-        Range range = resourceAttribute.getRange();
-        if (null != range) {
-            System.out.println("Range:" + range.getMin() + " to "
-                    + range.getMax());
-        }
-    }
-}
\ No newline at end of file
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/SimulatorResource.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/SimulatorResource.java
deleted file mode 100644 (file)
index 38d9730..0000000
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package oic.simulator.serviceprovider.resource;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.oic.simulator.SimulatorResourceModel;
-import org.oic.simulator.serviceprovider.AutomationType;
-import org.oic.simulator.serviceprovider.ObserverInfo;
-import org.oic.simulator.serviceprovider.SimulatorResourceServer;
-
-/**
- * This class represents a simulated resource. It maintains all the necessary
- * information about the resource.
- */
-public class SimulatorResource {
-    private String                              resourceURI;
-    private String                              resourceName;
-    private String                              resourceType;
-    private String                              resourceInterface;
-
-    // Native Object references
-    private SimulatorResourceServer             resourceServer;
-    private SimulatorResourceModel              resourceModel;
-
-    private int                                 automationId;
-
-    private boolean                             resourceAutomationInProgress;
-
-    private boolean                             attributeAutomationInProgress;
-
-    private int                                 automationUpdateInterval;
-
-    private AutomationType                      automationType;
-
-    private Map<String, LocalResourceAttribute> resourceAttributesMap;
-
-    private Map<Integer, ObserverDetail>        observers;
-
-    public SimulatorResource() {
-        observers = new HashMap<Integer, ObserverDetail>();
-    }
-
-    public String getResourceURI() {
-        return resourceURI;
-    }
-
-    public void setResourceURI(String resourceURI) {
-        this.resourceURI = resourceURI;
-    }
-
-    public String getResourceName() {
-        return resourceName;
-    }
-
-    public void setResourceName(String resourceName) {
-        this.resourceName = resourceName;
-    }
-
-    public String getResourceType() {
-        return resourceType;
-    }
-
-    public void setResourceType(String resourceType) {
-        this.resourceType = resourceType;
-    }
-
-    public String getResourceInterface() {
-        return resourceInterface;
-    }
-
-    public void setResourceInterface(String resourceInterface) {
-        this.resourceInterface = resourceInterface;
-    }
-
-    public SimulatorResourceServer getResourceServer() {
-        return resourceServer;
-    }
-
-    public void setResourceServer(SimulatorResourceServer resourceServer) {
-        this.resourceServer = resourceServer;
-    }
-
-    public SimulatorResourceModel getResourceModel() {
-        return resourceModel;
-    }
-
-    public void setResourceModel(SimulatorResourceModel resourceModel) {
-        this.resourceModel = resourceModel;
-    }
-
-    public Map<String, LocalResourceAttribute> getResourceAttributesMap() {
-        return resourceAttributesMap;
-    }
-
-    public void setResourceAttributesMap(
-            Map<String, LocalResourceAttribute> resourceAttributesMap) {
-        this.resourceAttributesMap = resourceAttributesMap;
-    }
-
-    public int getAutomationUpdateInterval() {
-        return automationUpdateInterval;
-    }
-
-    public void setAutomationUpdateInterval(int automationUpdateInterval) {
-        this.automationUpdateInterval = automationUpdateInterval;
-    }
-
-    public AutomationType getAutomationType() {
-        return automationType;
-    }
-
-    public void setAutomationType(AutomationType automationType) {
-        this.automationType = automationType;
-    }
-
-    public int getAutomationId() {
-        return automationId;
-    }
-
-    public void setAutomationId(int automationId) {
-        this.automationId = automationId;
-    }
-
-    public boolean isResourceAutomationInProgress() {
-        return resourceAutomationInProgress;
-    }
-
-    public void setResourceAutomationInProgress(
-            boolean resourceAutomationInProgress) {
-        this.resourceAutomationInProgress = resourceAutomationInProgress;
-    }
-
-    public boolean isAttributeAutomationInProgress() {
-        return attributeAutomationInProgress;
-    }
-
-    public void setAttributeAutomationInProgress(
-            boolean attributeAutomationInProgress) {
-        this.attributeAutomationInProgress = attributeAutomationInProgress;
-    }
-
-    public Map<Integer, ObserverDetail> getObserver() {
-        return observers;
-    }
-
-    public void addObserverInfo(ObserverInfo observer) {
-        if (null == observer) {
-            return;
-        }
-        int id = observer.getId();
-        if (!observers.containsKey(id)) {
-            ObserverDetail obsDetail = new ObserverDetail();
-            obsDetail.setObserverInfo(observer);
-            observers.put(id, obsDetail);
-        }
-    }
-
-    public void removeObserverInfo(ObserverInfo observer) {
-        if (null == observer) {
-            return;
-        }
-        observers.remove(observer.getId());
-    }
-
-    public void printResourceInfo() {
-        System.out.println("Resource URI: " + resourceURI);
-        System.out.println("Resource Name: " + resourceName);
-        System.out.println("Resource type: " + resourceType);
-        System.out.println("Resource Interface: " + resourceInterface);
-        System.out.println("Resource Attributes:-");
-        if (null != resourceAttributesMap) {
-            Iterator<String> attItr = resourceAttributesMap.keySet().iterator();
-            while (attItr.hasNext()) {
-                resourceAttributesMap.get(attItr.next())
-                        .printAttributeDetails();;
-            }
-        }
-    }
-
-    public LocalResourceAttribute getAttribute(String attributeName) {
-        if (null == attributeName || null == resourceAttributesMap
-                || resourceAttributesMap.size() < 1) {
-            return null;
-        }
-        return resourceAttributesMap.get(attributeName);
-    }
-
-}
\ No newline at end of file
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/AttributeValueBuilder.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/AttributeValueBuilder.java
new file mode 100644 (file)
index 0000000..fdebf0e
--- /dev/null
@@ -0,0 +1,266 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package oic.simulator.serviceprovider.utils;
+
+import java.util.Vector;
+
+import org.oic.simulator.AttributeValue;
+
+public class AttributeValueBuilder {
+    public static AttributeValue build(String valueString,
+            AttributeValue.ValueType valueType) {
+        int depth = findDepth(valueString);
+        if (0 == depth) {
+            return handleDepth0(valueString, valueType);
+        } else if (1 == depth) {
+            return handleDepth1(valueString, valueType);
+        } else if (2 == depth) {
+            return handleDepth2(valueString, valueType);
+        } else if (3 == depth) {
+            return handleDepth3(valueString, valueType);
+        }
+
+        return null;
+    }
+
+    private static int findDepth(String value) {
+        int depth = 0;
+        for (char ch : value.toCharArray()) {
+            if (ch == '[')
+                depth++;
+            else
+                break;
+        }
+
+        return depth;
+    }
+
+    private static boolean isValidSyntax(String value) {
+        int count = 0;
+        for (char ch : value.toCharArray()) {
+            if (ch == '[')
+                count++;
+            if (ch == ']')
+                count--;
+        }
+
+        if (count == 0)
+            return true;
+        return false;
+
+    }
+
+    private static AttributeValue handleDepth0(String valueString,
+            AttributeValue.ValueType valueType) {
+        valueString = valueString.trim();
+        if (0 != findDepth(valueString))
+            return null;
+
+        if (valueType == AttributeValue.ValueType.INTEGER)
+            return new AttributeValue(Integer.parseInt(valueString));
+        else if (valueType == AttributeValue.ValueType.DOUBLE)
+            return new AttributeValue(Double.parseDouble(valueString));
+        else if (valueType == AttributeValue.ValueType.BOOLEAN)
+            return new AttributeValue(Boolean.parseBoolean(valueString));
+        else if (valueType == AttributeValue.ValueType.STRING)
+            return new AttributeValue(valueString);
+        return null;
+    }
+
+    private static String[] splitIntoArrays(String value) {
+        Vector<String> values = new Vector<String>();
+        String valueString = new String(value);
+        valueString = valueString.substring(valueString.indexOf('[') + 1,
+                valueString.lastIndexOf(']'));
+
+        int count = 0;
+        int startPos = 0;
+        char[] charArray = valueString.toCharArray();
+        for (int index = 0; index < charArray.length; index++) {
+            if (charArray[index] == '[' && 0 == count++) {
+                startPos = index;
+            }
+
+            if (charArray[index] == ']' && 0 == --count) {
+                values.add(valueString.substring(startPos, index + 1));
+            }
+        }
+
+        String[] result = new String[values.size()];
+        values.toArray(result);
+        return result;
+    }
+
+    private static AttributeValue handleDepth1(String valueString,
+            AttributeValue.ValueType valueType) {
+        valueString = valueString.trim();
+        if (1 != findDepth(valueString) || false == isValidSyntax(valueString))
+            return null;
+
+        valueString = valueString.substring(valueString.indexOf('[') + 1,
+                valueString.lastIndexOf(']'));
+        String[] valuesString = valueString.split(",");
+        if (null == valuesString || 0 == valuesString.length)
+            return null;
+
+        if (valueType == AttributeValue.ValueType.INTEGER) {
+            Integer[] result = new Integer[valuesString.length];
+            for (int index = 0; index < valuesString.length; index++) {
+                Integer value = (Integer) handleDepth0(valuesString[index],
+                        valueType).get();
+                if (null == value)
+                    return null;
+                result[index] = value;
+            }
+            return new AttributeValue(result);
+        } else if (valueType == AttributeValue.ValueType.DOUBLE) {
+            Double[] result = new Double[valuesString.length];
+            for (int index = 0; index < valuesString.length; index++) {
+                Double value = (Double) handleDepth0(valuesString[index],
+                        valueType).get();
+                if (null == value)
+                    return null;
+                result[index] = value;
+            }
+            return new AttributeValue(result);
+        } else if (valueType == AttributeValue.ValueType.BOOLEAN) {
+            Boolean[] result = new Boolean[valuesString.length];
+            for (int index = 0; index < valuesString.length; index++) {
+                Boolean value = (Boolean) handleDepth0(valuesString[index],
+                        valueType).get();
+                if (null == value)
+                    return null;
+                result[index] = value;
+            }
+            return new AttributeValue(result);
+        } else if (valueType == AttributeValue.ValueType.STRING) {
+            return new AttributeValue(valuesString);
+        }
+
+        return null;
+    }
+
+    private static AttributeValue handleDepth2(String valueString,
+            AttributeValue.ValueType valueType) {
+        valueString = valueString.trim();
+        if (2 != findDepth(valueString) || false == isValidSyntax(valueString))
+            return null;
+
+        String[] valuesString = splitIntoArrays(valueString);
+        if (null == valuesString || 0 == valuesString.length)
+            return null;
+
+        if (valueType == AttributeValue.ValueType.INTEGER) {
+            Integer[][] result = new Integer[valuesString.length][];
+            for (int index = 0; index < valuesString.length; index++) {
+                Integer[] value = (Integer[]) handleDepth1(valuesString[index],
+                        valueType).get();
+                if (null == value)
+                    return null;
+                result[index] = value;
+            }
+            return new AttributeValue(result);
+        } else if (valueType == AttributeValue.ValueType.DOUBLE) {
+            Double[][] result = new Double[valuesString.length][];
+            for (int index = 0; index < valuesString.length; index++) {
+                Double[] value = (Double[]) handleDepth1(valuesString[index],
+                        valueType).get();
+                if (null == value)
+                    return null;
+                result[index] = value;
+            }
+            return new AttributeValue(result);
+        } else if (valueType == AttributeValue.ValueType.BOOLEAN) {
+            Boolean[][] result = new Boolean[valuesString.length][];
+            for (int index = 0; index < valuesString.length; index++) {
+                Boolean[] value = (Boolean[]) handleDepth1(valuesString[index],
+                        valueType).get();
+                if (null == value)
+                    return null;
+                result[index] = value;
+            }
+            return new AttributeValue(result);
+        } else if (valueType == AttributeValue.ValueType.STRING) {
+            String[][] result = new String[valuesString.length][];
+            for (int index = 0; index < valuesString.length; index++) {
+                String[] value = (String[]) handleDepth1(valuesString[index],
+                        valueType).get();
+                if (null == value)
+                    return null;
+                result[index] = value;
+            }
+            return new AttributeValue(result);
+        }
+
+        return null;
+    }
+
+    public static AttributeValue handleDepth3(String valueString,
+            AttributeValue.ValueType valueType) {
+        valueString = valueString.trim();
+        if (3 != findDepth(valueString) || false == isValidSyntax(valueString))
+            return null;
+
+        String[] valuesString = splitIntoArrays(valueString);
+        if (null == valuesString || 0 == valuesString.length)
+            return null;
+
+        if (valueType == AttributeValue.ValueType.INTEGER) {
+            Integer[][][] result = new Integer[valuesString.length][][];
+            for (int index = 0; index < valuesString.length; index++) {
+                Integer[][] value = (Integer[][]) handleDepth2(
+                        valuesString[index], valueType).get();
+                if (null == value)
+                    return null;
+                result[index] = value;
+            }
+            return new AttributeValue(result);
+        } else if (valueType == AttributeValue.ValueType.DOUBLE) {
+            Double[][][] result = new Double[valuesString.length][][];
+            for (int index = 0; index < valuesString.length; index++) {
+                Double[][] value = (Double[][]) handleDepth2(
+                        valuesString[index], valueType).get();
+                if (null == value)
+                    return null;
+                result[index] = value;
+            }
+            return new AttributeValue(result);
+        } else if (valueType == AttributeValue.ValueType.BOOLEAN) {
+            Boolean[][][] result = new Boolean[valuesString.length][][];
+            for (int index = 0; index < valuesString.length; index++) {
+                Boolean[][] value = (Boolean[][]) handleDepth2(
+                        valuesString[index], valueType).get();
+                if (null == value)
+                    return null;
+                result[index] = value;
+            }
+            return new AttributeValue(result);
+        } else if (valueType == AttributeValue.ValueType.STRING) {
+            String[][][] result = new String[valuesString.length][][];
+            for (int index = 0; index < valuesString.length; index++) {
+                String[][] value = (String[][]) handleDepth2(
+                        valuesString[index], valueType).get();
+                if (null == value)
+                    return null;
+                result[index] = value;
+            }
+            return new AttributeValue(result);
+        }
+
+        return null;
+    }
+}
index 7b8a6fd..ac64d5b 100644 (file)
@@ -16,7 +16,7 @@
 
 package oic.simulator.serviceprovider.utils;
 
-import org.oic.simulator.serviceprovider.AutomationType;
+import org.oic.simulator.server.SimulatorResource.AutoUpdateType;
 
 /**
  * This class maintains all constants which are used throughout the service
@@ -24,82 +24,146 @@ import org.oic.simulator.serviceprovider.AutomationType;
  */
 public class Constants {
 
-    public static final String         CONFIG_DIRECTORY_PATH            = "/resource";
+    public static final String         INT                                                  = "Int";
+    public static final String         DOUBLE                                               = "Double";
+    public static final String         BOOL                                                 = "Bool";
+    public static final String         STRING                                               = "String";
+    public static final String         UNKNOWN                                              = "Unknown";
 
-    public static final String         UNDERSCORE                       = "_";
-    public static final String         FORWARD_SLASH                    = "/";
+    public static final String         CONFIG_DIRECTORY_PATH                                = "/resource";
 
-    public static final String         OIC_PREFIX                       = "/oic/r";
-    public static final String         SIMULATOR                        = "simulator";
+    public static final String         UNDERSCORE                                           = "_";
+    public static final String         FORWARD_SLASH                                        = "/";
 
-    public static final String         RESOURCE_URI                     = "Resource URI";
-    public static final String         RESOURCE_TYPE                    = "Resource Type";
-    public static final String         RESOURCE_UID                     = "Resource ID";
-    public static final String         CONNECTIVITY_TYPE                = "Connectivity Type";
+    public static final String         OIC_PREFIX                                           = "/oic/r";
+    public static final String         SIMULATOR                                            = "simulator";
 
-    public static final String[]       META_PROPERTIES                  = {
-            RESOURCE_URI, RESOURCE_TYPE, CONNECTIVITY_TYPE             };
+    public static final String         RESOURCE_URI                                         = "Resource URI";
+    public static final String         RESOURCE_TYPE                                        = "Resource Type";
+    public static final String         RESOURCE_TYPES                                       = "Resource Types";
+    public static final String         RESOURCE_NAME                                        = "Resource Name";
+    public static final String         DEVICE_NAME                                          = "Device Name";
+    public static final String         RESOURCE_UID                                         = "Resource ID";
+    public static final String         CONNECTIVITY_TYPE                                    = "Connectivity Type";
 
-    public static final int            META_PROPERTY_COUNT              = META_PROPERTIES.length;
+    public static final String[]       META_PROPERTIES                                      = {
+            RESOURCE_NAME, RESOURCE_URI, RESOURCE_TYPE                                     };
 
-    public static final String         ENABLE                           = "Enable";
-    public static final String         DISABLE                          = "Disable";
-    public static final String         ENABLED                          = "Enabled";
-    public static final String         DISABLED                         = "Disabled";
+    public static final int            META_PROPERTY_COUNT                                  = META_PROPERTIES.length;
 
-    public static final String         AUTOMATION                       = "Automation";
-    public static final String         AUTOMATION_TYPE                  = "Automation Type";
-    public static final String         UPDATE_INTERVAL_IN_MS            = "Update Interval(ms)";
+    public static final String         ENABLE                                               = "Enable";
+    public static final String         DISABLE                                              = "Disable";
+    public static final String         ENABLED                                              = "Enabled";
+    public static final String         DISABLED                                             = "Disabled";
 
-    public static final String[]       AUTOMATION_SETTINGS              = {
-            AUTOMATION_TYPE, UPDATE_INTERVAL_IN_MS                     };
+    public static final String         AUTOMATION                                           = "Automation";
+    public static final String         AUTOMATION_TYPE                                      = "Automation Type";
+    public static final String         UPDATE_INTERVAL_IN_MS                                = "Update Interval(ms)";
 
-    public static final int            AUTOMATION_SETTINGS_COUNT        = AUTOMATION_SETTINGS.length;
+    public static final String[]       AUTOMATION_SETTINGS                                  = {
+            AUTOMATION_TYPE, UPDATE_INTERVAL_IN_MS                                         };
 
-    public static final String         START_RESOURCE_AUTOMATION        = "Start Automation";
-    public static final String         STOP_RESOURCE_AUTOMATION         = "Stop Automation";
+    public static final int            AUTOMATION_SETTINGS_COUNT                            = AUTOMATION_SETTINGS.length;
 
-    public static final int            DISPLAY_RESOURCE_URI_TOKEN_COUNT = 2;
+    public static final String         START_RESOURCE_AUTOMATION                            = "Start Automation";
+    public static final String         STOP_RESOURCE_AUTOMATION                             = "Stop Automation";
 
-    public static final AutomationType DEFAULT_AUTOMATION_TYPE          = AutomationType.NORMAL;
+    public static final int            DISPLAY_RESOURCE_URI_TOKEN_COUNT                     = 2;
 
-    public static final int            DEFAULT_AUTOMATION_INTERVAL      = 500;
+    public static final AutoUpdateType DEFAULT_AUTOMATION_TYPE                              = AutoUpdateType.ONE_TIME;
 
-    public static final int            PROPER_LOG_TIME_TOKEN_LENGTH     = 3;
+    public static final int            DEFAULT_AUTOMATION_INTERVAL                          = 500;
 
-    public static final String[]       BROWSE_RAML_FILTER_EXTENSIONS    = new String[] { "*.raml" };
-    public static final String[]       SAVE_LOG_FILTER_EXTENSIONS       = new String[] {
-            "*.log", "*"                                               };
+    public static final int            PROPER_LOG_TIME_TOKEN_LENGTH                         = 3;
 
-    public static final int            LOG_SIZE                         = 1000;
+    public static final String[]       BROWSE_RAML_FILTER_EXTENSIONS                        = new String[] { "*.raml" };
+    public static final String[]       SAVE_LOG_FILTER_EXTENSIONS                           = new String[] {
+            "*.log", "*"                                                                   };
 
-    public static final String         INFO_LOG                         = "info_log";
-    public static final String         WARNING_LOG                      = "warning_log";
-    public static final String         ERROR_LOG                        = "error_log";
-    public static final String         DEBUG_LOG                        = "debug_log";
-    public static final String         UNKNOWN_LOG                      = "unknown_log";
+    public static final int            LOG_SIZE                                             = 1000;
 
-    public static final String         INFO                             = "Info";
-    public static final String         WARNING                          = "Warning";
-    public static final String         ERROR                            = "Error";
-    public static final String         DEBUG                            = "Debug";
-    public static final String         UNKNOWN                          = "Unknown";
+    public static final String         INFO_LOG                                             = "info_log";
+    public static final String         WARNING_LOG                                          = "warning_log";
+    public static final String         ERROR_LOG                                            = "error_log";
+    public static final String         DEBUG_LOG                                            = "debug_log";
+    public static final String         UNKNOWN_LOG                                          = "unknown_log";
 
-    public static final String         CHECKED                          = "Checked";
-    public static final String         UNCHECKED                        = "Unchecked";
-    public static final String         NOTIFY_BUTTON_SELECTED           = "Notify_Selected";
-    public static final String         NOTIFY_BUTTON_UNSELECTED         = "Notify_Unselected";
+    public static final String         INFO                                                 = "Info";
+    public static final String         WARNING                                              = "Warning";
+    public static final String         ERROR                                                = "Error";
+    public static final String         DEBUG                                                = "Debug";
 
-    public static final String         CREATE_PAGE_TITLE                = "Create Resource";
-    public static final String         CREATE_PAGE_MESSAGE              = "Create one or more resources from RAML configuration file";
+    public static final String         CHECKED                                              = "Checked";
+    public static final String         UNCHECKED                                            = "Unchecked";
+    public static final String         NOTIFY_BUTTON_SELECTED                               = "Notify_Selected";
+    public static final String         NOTIFY_BUTTON_UNSELECTED                             = "Notify_Unselected";
 
-    public static final String         DELETE_PAGE_TITLE                = "Delete Resource";
-    public static final String         DELETE_PAGE_MESSAGE              = "Select the resource(s) to be deleted";
+    public static final String         CREATE_PAGE_TITLE                                    = "Create Resource";
+    public static final String         CREATE_PAGE_MESSAGE                                  = "Create a simple resource from RAML file";
 
-    public static final String         RAML_FILE_PREFIX                 = "/resource/";
+    public static final String         DELETE_PAGE_TITLE                                    = "Delete Resource";
+    public static final String         DELETE_PAGE_MESSAGE                                  = "Select the resource(s) to be deleted";
 
-    public static final String         RAML_FILE_EXTENSION              = ".raml";
-    public static final String         JSON_FILE_EXTENSION              = ".json";
+    public static final String         RAML_FILE_PREFIX                                     = "/resource/";
+
+    public static final String         RAML_FILE_EXTENSION                                  = ".raml";
+    public static final String         JSON_FILE_EXTENSION                                  = ".json";
+
+    public static final String         SPLIT_BY_DOT_PATTERN                                 = "\\.";
+
+    // Platform information
+    public static final String         PLATFORM_ID                                          = "Id";
+    public static final String         PLATFORM_MANUFAC_NAME                                = "Manufacturer Name";
+    public static final String         PLATFORM_MANUFAC_URL                                 = "Manufacturer URL";
+    public static final String         PLATFORM_MODEL_NO                                    = "Model Number";
+    public static final String         PLATFORM_DATE_OF_MANUFAC                             = "Date of Manufacture";
+    public static final String         PLATFORM_VERSION                                     = "Version";
+    public static final String         PLATFORM_OS_VERSION                                  = "OS Version";
+    public static final String         PLATFORM_HARDWARE_VERSION                            = "HardWare Version";
+    public static final String         PLATFORM_FIRMWARE_VERSION                            = "Firmware Version";
+    public static final String         PLATFORM_SUPPORT_URL                                 = "Support URL";
+    public static final String         PLATFORM_SYSTEM_TIME                                 = "System Time";
+
+    public static final String         SAMPLE_LIGHT                                         = "sample.light";
+
+    public static final String         UPDATE_PROP_PAGE_TITLE                               = "Update Properties";
+    public static final String         UPDATE_PROP_PAGE_MESSAGE                             = "Update the default values of resource properties";
+
+    public static final String         START_STOP_PAGE_TITLE                                = "Start/Stop Resource";
+    public static final String         START_STOP_PAGE_MESSAGE                              = "This page allows to start or stop the created resource(s)";
+
+    public static final String         START_RESOURCE                                       = "Start Resource";
+    public static final String         STOP_RESOURCE                                        = "Stop Resource";
+
+    public static final String         DELETE_RESOURCE                                      = "Delete Resource";
+
+    public static final String         MAIN_PAGE_TITLE                                      = "Create Resource";
+    public static final String         MAIN_PAGE_MESSAGE                                    = "Simple resource or Collection resource";
+
+    public static final String         SIMPLE_PAGE_TITLE                                    = "Create Simple Resource";
+    public static final String         SIMPLE_PAGE_MESSAGE                                  = "Either manually or from RAML file";
+
+    public static final String         SIMPLE_RESOURCE_BASIC_DETAILS_PAGE_TITLE             = "Create Simple Resource(Step 1 of 3)";
+    public static final String         SIMPLE_RESOURCE_BASIC_DETAILS_PAGE_MESSAGE           = "Fill basic details of the resource";
+
+    public static final String         SIMPLE_RESOURCE_ADD_ATTRIBUTE_PAGE_TITLE             = "Create Simple Resource(Step 2 of 3)";
+    public static final String         SIMPLE_RESOURCE_ADD_ATTRIBUTE_PAGE_MESSAGE           = "Add attributes to the resource";
+
+    public static final String         SIMPLE_RESOURCE_OTHER_DETAILS_PAGE_TITLE             = "Create Simple Resource(Step 3 of 3)";
+    public static final String         SIMPLE_RESOURCE_OTHER_DETAILS_PAGE_MESSAGE           = "Fill other details of the resource";
+
+    public static final String         COLLECTION_RESOURCE_BASIC_DETAILS_PAGE_TITLE1        = "Create Collection Resource";
+    public static final String         COLLECTION_RESOURCE_BASIC_DETAILS_PAGE_TITLE2        = "Create Collection Resource(Step 1 of 2)";
+    public static final String         COLLECTION_RESOURCE_BASIC_DETAILS_PAGE_MESSAGE       = "Fill basic details of the resource";
+
+    public static final String         COLLECTION_RESOURCE_ADD_OTHER_RESOURCES_PAGE_TITLE   = "Create Collection Resource(Step 2 of 2)";
+    public static final String         COLLECTION_RESOURCE_ADD_OTHER_RESOURCES_PAGE_MESSAGE = "Add other resources to this collection resource";
+
+    public static final String         CREATE_DEVICE_PAGE_TITLE                             = "Create Device";
+    public static final String         CREATE_DEVICE_PAGE_MESSAGE                           = "Create a logical device which holds a group of resources";
+
+    public static final String         DEVICE                                               = "Create Device";
+    public static final String         SINGLE_RESOURCE                                      = "Single Resource";
+    public static final String         COLLECTION_RESOURCE                                  = "Collection Resource";
 
-    public static final String         SPLIT_BY_DOT_PATTERN             = "\\.";
 }
\ No newline at end of file
index 4c053d3..73d559c 100644 (file)
 package oic.simulator.serviceprovider.utils;
 
 import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
+import java.util.Vector;
+
+import oic.simulator.serviceprovider.Activator;
+import oic.simulator.serviceprovider.model.CollectionResource;
+import oic.simulator.serviceprovider.model.Device;
+import oic.simulator.serviceprovider.model.LocalResourceAttribute;
+import oic.simulator.serviceprovider.model.Resource;
+import oic.simulator.serviceprovider.model.SingleResource;
+
+import org.oic.simulator.AttributeValue;
+import org.oic.simulator.AttributeValue.TypeInfo;
+import org.oic.simulator.AttributeValue.ValueType;
+import org.oic.simulator.ILogger.Level;
+import org.oic.simulator.InvalidArgsException;
+import org.oic.simulator.SimulatorException;
+import org.oic.simulator.SimulatorResourceAttribute;
+import org.oic.simulator.SimulatorResourceModel;
 
 /**
  * This class has common utility methods.
  */
 public class Utility {
 
-    public static String uriToDisplayName(String uri) {
-        String result = null;
-        if (null != uri) {
-            String tokens[] = uri.split(Constants.FORWARD_SLASH);
-            if (null != tokens && tokens.length > 2) {
-                result = tokens[tokens.length - 3] + Constants.UNDERSCORE
-                        + tokens[tokens.length - 1];
-            }
-        }
-        return result;
-    }
-
     public static String fileNameToDisplay(String fileName) {
         if (null == fileName || fileName.length() < 1) {
             return null;
@@ -100,9 +109,18 @@ public class Utility {
         if (null != value) {
             try {
                 result = Integer.parseInt(value);
-            } catch (NumberFormatException nfe) {
-                System.out
-                        .println("Getting UpdateInterval from string failed!");
+            } catch (NumberFormatException e) {
+                Activator
+                        .getDefault()
+                        .getLogManager()
+                        .log(Level.ERROR.ordinal(),
+                                new Date(),
+                                getSimulatorErrorString(
+                                        e,
+                                        "Update interval convertion failed."
+                                                + "Taking the default value("
+                                                + Constants.DEFAULT_AUTOMATION_INTERVAL
+                                                + ")"));
             }
         }
         return result;
@@ -119,4 +137,669 @@ public class Utility {
         }
         return list;
     }
+
+    public static List<SingleResource> getSingleResourceListFromSet(
+            Set<SingleResource> resources) {
+        if (null == resources) {
+            return null;
+        }
+        List<SingleResource> list = new ArrayList<SingleResource>();
+        Iterator<SingleResource> typeItr = resources.iterator();
+        while (typeItr.hasNext()) {
+            list.add(typeItr.next());
+        }
+        return list;
+    }
+
+    public static List<CollectionResource> getCollectionResourceListFromSet(
+            Set<CollectionResource> resources) {
+        if (null == resources) {
+            return null;
+        }
+        List<CollectionResource> list = new ArrayList<CollectionResource>();
+        Iterator<CollectionResource> typeItr = resources.iterator();
+        while (typeItr.hasNext()) {
+            list.add(typeItr.next());
+        }
+        return list;
+    }
+
+    public static List<Device> getDeviceListFromSet(Set<Device> devices) {
+        if (null == devices) {
+            return null;
+        }
+        List<Device> list = new ArrayList<Device>();
+        Iterator<Device> typeItr = devices.iterator();
+        while (typeItr.hasNext()) {
+            list.add(typeItr.next());
+        }
+        return list;
+    }
+
+    public static Set<String> convertVectorToSet(Vector<String> vector) {
+        if (null == vector || vector.isEmpty()) {
+            return null;
+        }
+        Set<String> resultSet = new HashSet<String>();
+        Enumeration<String> e = vector.elements();
+        while (e.hasMoreElements()) {
+            resultSet.add(e.nextElement().toString());
+        }
+        return resultSet;
+    }
+
+    public static String getSimulatorErrorString(Exception e, String info) {
+        if (null == e) {
+            return null;
+        }
+        String detail;
+        if (e instanceof SimulatorException) {
+            SimulatorException simEx = (SimulatorException) e;
+            detail = simEx.message() + "\n";
+            detail += "Exception Type: " + simEx.getClass().getSimpleName()
+                    + "\n";
+            detail += "Error code: " + simEx.code().toString();
+        } else {
+            detail = info + "\n";
+            detail += "Exception Type: " + e.getClass().getSimpleName() + "\n";
+            detail += "Message: " + e.getMessage();
+        }
+        return detail;
+    }
+
+    public static Set<String> getAttributeTypes() {
+        Set<String> attTypes = new HashSet<String>();
+        ValueType[] types = ValueType.values();
+        if (null != types) {
+            attTypes.add(Constants.INT);
+            attTypes.add(Constants.DOUBLE);
+            attTypes.add(Constants.BOOL);
+            attTypes.add(Constants.STRING);
+        }
+        return attTypes;
+    }
+
+    public static ValueType getAttributeTypeEnum(String type) {
+        if (null != type && type.trim().length() > 0) {
+            if (type.equalsIgnoreCase(Constants.INT)) {
+                return ValueType.INTEGER;
+            }
+            if (type.equalsIgnoreCase(Constants.DOUBLE)) {
+                return ValueType.DOUBLE;
+            }
+            if (type.equalsIgnoreCase(Constants.BOOL)) {
+                return ValueType.BOOLEAN;
+            }
+            if (type.equalsIgnoreCase(Constants.STRING)) {
+                return ValueType.STRING;
+            }
+        }
+        return ValueType.UNKNOWN;
+    }
+
+    public static int[] convertSetToArrayInt(Set<Object> allowedValues) {
+        if (null == allowedValues || allowedValues.size() < 1) {
+            return null;
+        }
+        int[] arr = new int[allowedValues.size()];
+        Iterator<Object> itr = allowedValues.iterator();
+        try {
+            int i = 0;
+            while (itr.hasNext()) {
+                arr[i++] = (int) itr.next();
+            }
+        } catch (Exception e) {
+            return null;
+        }
+        return arr;
+    }
+
+    public static double[] convertSetToArrayDouble(Set<Object> allowedValues) {
+        if (null == allowedValues || allowedValues.size() < 1) {
+            return null;
+        }
+        double[] arr = new double[allowedValues.size()];
+        Iterator<Object> itr = allowedValues.iterator();
+        try {
+            int i = 0;
+            while (itr.hasNext()) {
+                arr[i++] = (double) itr.next();
+            }
+        } catch (Exception e) {
+            return null;
+        }
+        return arr;
+    }
+
+    public static boolean[] convertSetToArrayBoolean(Set<Object> allowedValues) {
+        if (null == allowedValues || allowedValues.size() < 1) {
+            return null;
+        }
+        boolean[] arr = new boolean[allowedValues.size()];
+        Iterator<Object> itr = allowedValues.iterator();
+        try {
+            int i = 0;
+            while (itr.hasNext()) {
+                arr[i++] = (boolean) itr.next();
+            }
+        } catch (Exception e) {
+            return null;
+        }
+        return arr;
+    }
+
+    public static String[] convertSetToArrayString(Set<Object> allowedValues) {
+        if (null == allowedValues || allowedValues.size() < 1) {
+            return null;
+        }
+        String[] arr = new String[allowedValues.size()];
+        Iterator<Object> itr = allowedValues.iterator();
+        try {
+            int i = 0;
+            while (itr.hasNext()) {
+                arr[i++] = (String) itr.next();
+            }
+        } catch (Exception e) {
+            return null;
+        }
+        return arr;
+    }
+
+    public static Vector<Integer> convertSetToVectorInt(
+            Set<Object> allowedValues) {
+        if (null == allowedValues || allowedValues.size() < 1) {
+            return null;
+        }
+        Vector<Integer> resultVec = new Vector<Integer>();
+        Iterator<Object> itr = allowedValues.iterator();
+        try {
+            while (itr.hasNext()) {
+                resultVec.add((Integer) itr.next());
+            }
+        } catch (Exception e) {
+            return null;
+        }
+        return resultVec;
+    }
+
+    public static Vector<Double> convertSetToVectorDouble(
+            Set<Object> allowedValues) {
+        if (null == allowedValues || allowedValues.size() < 1) {
+            return null;
+        }
+        Vector<Double> resultVec = new Vector<Double>();
+        Iterator<Object> itr = allowedValues.iterator();
+        try {
+            while (itr.hasNext()) {
+                resultVec.add((Double) itr.next());
+            }
+        } catch (Exception e) {
+            return null;
+        }
+        return resultVec;
+    }
+
+    public static Vector<String> convertSetToVectorString(
+            Set<Object> allowedValues) {
+        if (null == allowedValues || allowedValues.size() < 1) {
+            return null;
+        }
+        Vector<String> resultVec = new Vector<String>();
+        Iterator<Object> itr = allowedValues.iterator();
+        try {
+            while (itr.hasNext()) {
+                resultVec.add((String) itr.next());
+            }
+        } catch (Exception e) {
+            return null;
+        }
+        return resultVec;
+    }
+
+    public static Set<Object> convertSetStringToSetObject(Set<String> values,
+            ValueType type) {
+        if (null == values || values.isEmpty()) {
+            return null;
+        }
+        Set<Object> resultSet = new HashSet<Object>();
+        if (type.equals(Constants.INT)) {
+            int val;
+            Iterator<String> itr = values.iterator();
+            while (itr.hasNext()) {
+                try {
+                    val = Integer.parseInt(itr.next());
+                    resultSet.add(val);
+                } catch (NumberFormatException nfe) {
+                    // Added for safety. Nothing to do.
+                }
+            }
+        } else if (type.equals(Constants.DOUBLE)) {
+            double val;
+            Iterator<String> itr = values.iterator();
+            while (itr.hasNext()) {
+                try {
+                    val = Double.parseDouble(itr.next());
+                    resultSet.add(val);
+                } catch (NumberFormatException nfe) {
+                    // Added for safety. Nothing to do.
+                }
+            }
+        } else if (type.equals(Constants.BOOL)) {
+            resultSet.add(true);
+            resultSet.add(false);
+        } else {
+            Iterator<String> itr = values.iterator();
+            while (itr.hasNext()) {
+                resultSet.add(itr.next());
+            }
+        }
+        return resultSet;
+    }
+
+    public static List<Resource> convertSingleTypeResourceListToBaseType(
+            List<SingleResource> resources) {
+        if (null == resources || resources.isEmpty()) {
+            return null;
+        }
+        List<Resource> resultSet = new ArrayList<Resource>();
+        Iterator<SingleResource> itr = resources.iterator();
+        while (itr.hasNext()) {
+            resultSet.add(itr.next());
+        }
+        return resultSet;
+    }
+
+    public static List<Resource> convertCollectionTypeResourceListToBaseType(
+            List<CollectionResource> resources) {
+        if (null == resources || resources.isEmpty()) {
+            return null;
+        }
+        List<Resource> resultSet = new ArrayList<Resource>();
+        Iterator<CollectionResource> itr = resources.iterator();
+        while (itr.hasNext()) {
+            resultSet.add(itr.next());
+        }
+        return resultSet;
+    }
+
+    public static Comparator<Resource>           resourceComparator           = new Comparator<Resource>() {
+                                                                                  public int compare(
+                                                                                          Resource res1,
+                                                                                          Resource res2) {
+                                                                                      String s1 = res1
+                                                                                              .getResourceName();
+                                                                                      String s2 = res2
+                                                                                              .getResourceName();
+
+                                                                                      String s1Part = s1
+                                                                                              .replaceAll(
+                                                                                                      "\\d",
+                                                                                                      "");
+                                                                                      String s2Part = s2
+                                                                                              .replaceAll(
+                                                                                                      "\\d",
+                                                                                                      "");
+
+                                                                                      if (s1Part
+                                                                                              .equalsIgnoreCase(s2Part)) {
+                                                                                          return extractInt(s1)
+                                                                                                  - extractInt(s2);
+                                                                                      }
+                                                                                      return s1
+                                                                                              .compareTo(s2);
+                                                                                  }
+
+                                                                                  int extractInt(
+                                                                                          String s) {
+                                                                                      String num = s
+                                                                                              .replaceAll(
+                                                                                                      "\\D",
+                                                                                                      "");
+                                                                                      // return
+                                                                                      // 0
+                                                                                      // if
+                                                                                      // no
+                                                                                      // digits
+                                                                                      // found
+                                                                                      return num
+                                                                                              .isEmpty() ? 0
+                                                                                              : Integer
+                                                                                                      .parseInt(num);
+                                                                                  }
+                                                                              };
+
+    public static Comparator<SingleResource>     singleResourceComparator     = new Comparator<SingleResource>() {
+                                                                                  public int compare(
+                                                                                          SingleResource res1,
+                                                                                          SingleResource res2) {
+                                                                                      String s1 = res1
+                                                                                              .getResourceName();
+                                                                                      String s2 = res2
+                                                                                              .getResourceName();
+
+                                                                                      String s1Part = s1
+                                                                                              .replaceAll(
+                                                                                                      "\\d",
+                                                                                                      "");
+                                                                                      String s2Part = s2
+                                                                                              .replaceAll(
+                                                                                                      "\\d",
+                                                                                                      "");
+
+                                                                                      if (s1Part
+                                                                                              .equalsIgnoreCase(s2Part)) {
+                                                                                          return extractInt(s1)
+                                                                                                  - extractInt(s2);
+                                                                                      }
+                                                                                      return s1
+                                                                                              .compareTo(s2);
+                                                                                  }
+
+                                                                                  int extractInt(
+                                                                                          String s) {
+                                                                                      String num = s
+                                                                                              .replaceAll(
+                                                                                                      "\\D",
+                                                                                                      "");
+                                                                                      // return
+                                                                                      // 0
+                                                                                      // if
+                                                                                      // no
+                                                                                      // digits
+                                                                                      // found
+                                                                                      return num
+                                                                                              .isEmpty() ? 0
+                                                                                              : Integer
+                                                                                                      .parseInt(num);
+                                                                                  }
+                                                                              };
+
+    public static Comparator<CollectionResource> collectionResourceComparator = new Comparator<CollectionResource>() {
+                                                                                  public int compare(
+                                                                                          CollectionResource res1,
+                                                                                          CollectionResource res2) {
+                                                                                      String s1 = res1
+                                                                                              .getResourceName();
+                                                                                      String s2 = res2
+                                                                                              .getResourceName();
+
+                                                                                      String s1Part = s1
+                                                                                              .replaceAll(
+                                                                                                      "\\d",
+                                                                                                      "");
+                                                                                      String s2Part = s2
+                                                                                              .replaceAll(
+                                                                                                      "\\d",
+                                                                                                      "");
+
+                                                                                      if (s1Part
+                                                                                              .equalsIgnoreCase(s2Part)) {
+                                                                                          return extractInt(s1)
+                                                                                                  - extractInt(s2);
+                                                                                      }
+                                                                                      return s1
+                                                                                              .compareTo(s2);
+                                                                                  }
+
+                                                                                  int extractInt(
+                                                                                          String s) {
+                                                                                      String num = s
+                                                                                              .replaceAll(
+                                                                                                      "\\D",
+                                                                                                      "");
+                                                                                      // return
+                                                                                      // 0
+                                                                                      // if
+                                                                                      // no
+                                                                                      // digits
+                                                                                      // found
+                                                                                      return num
+                                                                                              .isEmpty() ? 0
+                                                                                              : Integer
+                                                                                                      .parseInt(num);
+                                                                                  }
+                                                                              };
+
+    public static Comparator<Device>             deviceComparator             = new Comparator<Device>() {
+                                                                                  public int compare(
+                                                                                          Device res1,
+                                                                                          Device res2) {
+                                                                                      String s1 = res1
+                                                                                              .getDeviceName();
+                                                                                      String s2 = res2
+                                                                                              .getDeviceName();
+
+                                                                                      String s1Part = s1
+                                                                                              .replaceAll(
+                                                                                                      "\\d",
+                                                                                                      "");
+                                                                                      String s2Part = s2
+                                                                                              .replaceAll(
+                                                                                                      "\\d",
+                                                                                                      "");
+
+                                                                                      if (s1Part
+                                                                                              .equalsIgnoreCase(s2Part)) {
+                                                                                          return extractInt(s1)
+                                                                                                  - extractInt(s2);
+                                                                                      }
+                                                                                      return s1
+                                                                                              .compareTo(s2);
+                                                                                  }
+
+                                                                                  int extractInt(
+                                                                                          String s) {
+                                                                                      String num = s
+                                                                                              .replaceAll(
+                                                                                                      "\\D",
+                                                                                                      "");
+                                                                                      // return
+                                                                                      // 0
+                                                                                      // if
+                                                                                      // no
+                                                                                      // digits
+                                                                                      // found
+                                                                                      return num
+                                                                                              .isEmpty() ? 0
+                                                                                              : Integer
+                                                                                                      .parseInt(num);
+                                                                                  }
+                                                                              };
+
+    // This method only works for attributes whose values are of type int,
+    // double, bool, string and 1-D array of primitive types
+    public static String getAttributeValueAsString(AttributeValue val) {
+        if (null == val) {
+            return null;
+        }
+        Object value = val.get();
+        if (null == value) {
+            return null;
+        }
+        TypeInfo type = val.typeInfo();
+        if (type.mType == ValueType.RESOURCEMODEL
+                || (type.mType == ValueType.ARRAY && type.mBaseType == ValueType.RESOURCEMODEL)
+                || (type.mType == ValueType.ARRAY && type.mDepth > 1)) {
+            return null;
+        }
+        if (type.mType == ValueType.ARRAY) {
+            if (type.mBaseType == ValueType.INTEGER) {
+                Integer[] values = (Integer[]) value;
+                if (null == values || values.length < 1) {
+                    return null;
+                }
+                List<Integer> list = new ArrayList<Integer>();
+                for (Integer i : values) {
+                    list.add(i);
+                }
+                return list.toString();
+            } else if (type.mBaseType == ValueType.DOUBLE) {
+                Double[] values = (Double[]) value;
+                if (null == values || values.length < 1) {
+                    return null;
+                }
+                List<Double> list = new ArrayList<Double>();
+                for (Double i : values) {
+                    list.add(i);
+                }
+                return list.toString();
+            } else if (type.mBaseType == ValueType.BOOLEAN) {
+                Boolean[] values = (Boolean[]) value;
+                if (null == values || values.length < 1) {
+                    return null;
+                }
+                List<Boolean> list = new ArrayList<Boolean>();
+                for (Boolean i : values) {
+                    list.add(i);
+                }
+                return list.toString();
+            } else if (type.mBaseType == ValueType.STRING) {
+                String[] values = (String[]) value;
+                if (null == values || values.length < 1) {
+                    return null;
+                }
+                List<String> list = new ArrayList<String>();
+                for (String i : values) {
+                    list.add(i);
+                }
+                return list.toString();
+            } else {
+                return null;
+            }
+        } else {
+            return String.valueOf(value);
+        }
+    }
+
+    public static List<LocalResourceAttribute> getDummyAttributes() {
+        List<LocalResourceAttribute> attributes = null;
+        attributes = new ArrayList<LocalResourceAttribute>();
+
+        // Integer attribute
+        SimulatorResourceAttribute attribute = new SimulatorResourceAttribute(
+                "integer", new AttributeValue(2), null);
+        attributes.add(addAttribute(attribute));
+
+        // Boolean attribute
+        attribute = new SimulatorResourceAttribute("boolean",
+                new AttributeValue(false), null);
+        attributes.add(addAttribute(attribute));
+
+        // String attribute
+        attribute = new SimulatorResourceAttribute("string",
+                new AttributeValue("india"), null);
+        attributes.add(addAttribute(attribute));
+
+        // Integer array attribute
+        int iarr[] = { 1, 2, 3 };
+        attribute = new SimulatorResourceAttribute("integerArr",
+                new AttributeValue(iarr), null);
+        attributes.add(addAttribute(attribute));
+
+        // Double array attribute
+        double darr[] = { 1.5, 2.51, 3.15 };
+        attribute = new SimulatorResourceAttribute("doubleArr",
+                new AttributeValue(darr), null);
+        attributes.add(addAttribute(attribute));
+
+        // Boolean array attribute
+        boolean barr[] = { false, true, false };
+        attribute = new SimulatorResourceAttribute("boolArr",
+                new AttributeValue(barr), null);
+        attributes.add(addAttribute(attribute));
+
+        // String array attribute
+        String sarr[] = { "senthil", "muruga", "sriram" };
+        attribute = new SimulatorResourceAttribute("stringArr",
+                new AttributeValue(sarr), null);
+        attributes.add(addAttribute(attribute));
+
+        // Model type complex attribute
+        attribute = new SimulatorResourceAttribute("subAtt1",
+                new AttributeValue("chennai"), null);
+        SimulatorResourceModel model = new SimulatorResourceModel();
+        try {
+            model.addAttribute(attribute);
+        } catch (InvalidArgsException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        attribute = new SimulatorResourceAttribute("subAtt2",
+                new AttributeValue("madurai"), null);
+        try {
+            model.addAttribute(attribute);
+        } catch (InvalidArgsException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+
+        SimulatorResourceModel subModel = new SimulatorResourceModel();
+        try {
+            subModel.addAttribute(attribute);
+        } catch (InvalidArgsException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        attribute = new SimulatorResourceAttribute("modelsubAtt3",
+                new AttributeValue(subModel), null);
+        try {
+            model.addAttribute(attribute);
+        } catch (InvalidArgsException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+
+        SimulatorResourceAttribute modelAtt = new SimulatorResourceAttribute(
+                "modelAtt1", new AttributeValue(model));
+        attributes.add(addAttribute(modelAtt));
+
+        // 1-D array of model
+        attribute = new SimulatorResourceAttribute("subAtt1",
+                new AttributeValue("chennai"), null);
+        SimulatorResourceModel[] modelArr = new SimulatorResourceModel[2];
+        model = new SimulatorResourceModel();
+        try {
+            model.addAttribute(attribute);
+            modelArr[0] = model;
+        } catch (InvalidArgsException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        attribute = new SimulatorResourceAttribute("subAtt2",
+                new AttributeValue("madurai"), null);
+        model = new SimulatorResourceModel();
+        try {
+            model.addAttribute(attribute);
+            modelArr[1] = model;
+        } catch (InvalidArgsException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        modelAtt = new SimulatorResourceAttribute("modelAtt2",
+                new AttributeValue(modelArr));
+        attributes.add(addAttribute(modelAtt));
+
+        return attributes;
+    }
+
+    private static LocalResourceAttribute addAttribute(
+            SimulatorResourceAttribute att) {
+        LocalResourceAttribute localAtt = new LocalResourceAttribute();
+
+        localAtt = new LocalResourceAttribute();
+
+        localAtt.setResourceAttributeRef(att);
+
+        // Initially disabling the automation
+        localAtt.setAutomationInProgress(false);
+
+        // Assigning the default automation interval
+        localAtt.setAutomationUpdateInterval(Constants.DEFAULT_AUTOMATION_INTERVAL);
+
+        // Setting the default automation type
+        localAtt.setAutomationType(Constants.DEFAULT_AUTOMATION_TYPE);
+
+        return localAtt;
+    }
+
 }
\ No newline at end of file
index 21586d8..1544fb6 100644 (file)
@@ -20,9 +20,13 @@ import java.util.List;
 
 import oic.simulator.serviceprovider.Activator;
 import oic.simulator.serviceprovider.manager.ResourceManager;
-import oic.simulator.serviceprovider.resource.AutomationSettingHelper;
-import oic.simulator.serviceprovider.resource.LocalResourceAttribute;
-import oic.simulator.serviceprovider.resource.SimulatorResource;
+import oic.simulator.serviceprovider.model.AutomationSettingHelper;
+import oic.simulator.serviceprovider.model.CollectionResource;
+import oic.simulator.serviceprovider.model.LocalResourceAttribute;
+import oic.simulator.serviceprovider.model.Resource;
+import oic.simulator.serviceprovider.model.SRMItem;
+import oic.simulator.serviceprovider.model.SingleResource;
+import oic.simulator.serviceprovider.utils.AttributeValueBuilder;
 import oic.simulator.serviceprovider.utils.Utility;
 import oic.simulator.serviceprovider.view.dialogs.AutomationSettingDialog;
 
@@ -31,7 +35,8 @@ import org.eclipse.jface.viewers.CellEditor;
 import org.eclipse.jface.viewers.CheckboxCellEditor;
 import org.eclipse.jface.viewers.ComboBoxCellEditor;
 import org.eclipse.jface.viewers.EditingSupport;
-import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
 import org.eclipse.jface.window.Window;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.CCombo;
@@ -39,7 +44,16 @@ import org.eclipse.swt.events.ModifyEvent;
 import org.eclipse.swt.events.ModifyListener;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.MessageBox;
-import org.oic.simulator.serviceprovider.AutomationType;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+import org.oic.simulator.AttributeProperty;
+import org.oic.simulator.AttributeValue;
+import org.oic.simulator.AttributeValue.TypeInfo;
+import org.oic.simulator.AttributeValue.ValueType;
+import org.oic.simulator.InvalidArgsException;
+import org.oic.simulator.SimulatorResourceAttribute;
+import org.oic.simulator.SimulatorResourceModel;
+import org.oic.simulator.server.SimulatorResource.AutoUpdateType;
 
 /**
  * This class provides editing support to the resources attributes table in the
@@ -50,23 +64,22 @@ public class AttributeEditingSupport {
     private AttributeValueEditor attValueEditor;
     private AutomationEditor     automationEditor;
 
-    public AttributeValueEditor createAttributeValueEditor(TableViewer viewer) {
+    public AttributeValueEditor createAttributeValueEditor(TreeViewer viewer) {
         attValueEditor = new AttributeValueEditor(viewer);
         return attValueEditor;
     }
 
-    public AutomationEditor createAutomationEditor(TableViewer viewer) {
+    public AutomationEditor createAutomationEditor(TreeViewer viewer) {
         automationEditor = new AutomationEditor(viewer);
         return automationEditor;
     }
 
     class AttributeValueEditor extends EditingSupport {
 
-        private final TableViewer      viewer;
-        private LocalResourceAttribute attributeInSelection;
-        private CCombo                 comboBox;
+        private final TreeViewer viewer;
+        private CCombo           comboBox;
 
-        public AttributeValueEditor(TableViewer viewer) {
+        public AttributeValueEditor(TreeViewer viewer) {
             super(viewer);
             this.viewer = viewer;
         }
@@ -77,56 +90,130 @@ public class AttributeEditingSupport {
         }
 
         @Override
-        protected CellEditor getCellEditor(Object element) {
-            attributeInSelection = (LocalResourceAttribute) element;
-
+        protected CellEditor getCellEditor(final Object element) {
             ResourceManager resourceManager = Activator.getDefault()
                     .getResourceManager();
-            if (!resourceManager
-                    .isAttHasRangeOrAllowedValues(attributeInSelection)) {
+
+            Resource res = resourceManager.getCurrentResourceInSelection();
+            if (null == res) {
+                return null;
+            }
+
+            // If selected resource is a collection, then editor support is not
+            // required.
+            if (res instanceof CollectionResource) {
+                return null;
+            }
+
+            final SimulatorResourceAttribute att;
+            if (element instanceof SimulatorResourceAttribute
+                    || element instanceof LocalResourceAttribute) {
+                if (element instanceof LocalResourceAttribute) {
+                    LocalResourceAttribute localAtt = (LocalResourceAttribute) element;
+                    att = localAtt.getResourceAttributeRef();
+                } else {
+                    att = (SimulatorResourceAttribute) element;
+                }
+            } else {
+                return null;
+            }
+
+            if (null == att) {
+                return null;
+            }
+
+            final AttributeValue val = att.value();
+            if (null == val) {
+                return null;
+            }
+
+            final TypeInfo type = val.typeInfo();
+            if (type.mType == ValueType.RESOURCEMODEL
+                    || (type.mType == ValueType.ARRAY && type.mBaseType == ValueType.RESOURCEMODEL)) {
+                return null;
+            }
+
+            AttributeProperty prop = att.property();
+            if (null == prop) {
+                return null;
+            }
+
+            if (!resourceManager.isAttHasRangeOrAllowedValues(att)) {
                 return null;
             }
 
             // CellEditor is not required as the automation is in progress.
-            if (attributeInSelection.isAutomationInProgress()) {
+            if (element instanceof LocalResourceAttribute
+                    && ((LocalResourceAttribute) element)
+                            .isAutomationInProgress()) {
                 return null;
             }
 
             String values[] = null;
-            List<String> valueSet = attributeInSelection.getAttValues();
+            List<String> valueSet = resourceManager
+                    .getAllValuesOfAttribute(att);
             values = convertListToStringArray(valueSet);
 
-            ComboBoxCellEditor comboEditor = new ComboBoxCellEditor(
-                    viewer.getTable(), values, SWT.READ_ONLY);
+            ComboBoxCellEditor comboEditor;
+            if (type.mType == ValueType.ARRAY) {
+                comboEditor = new ComboBoxCellEditor(viewer.getTree(), values);
+            } else {
+                comboEditor = new ComboBoxCellEditor(viewer.getTree(), values,
+                        SWT.READ_ONLY);
+            }
             comboBox = (CCombo) comboEditor.getControl();
             comboBox.addModifyListener(new ModifyListener() {
 
                 @Override
                 public void modifyText(ModifyEvent event) {
-                    String oldValue = String.valueOf(attributeInSelection
-                            .getAttributeValue());
+                    if (type.mType == ValueType.ARRAY) {
+                        return;
+                    }
+                    String oldValue = String.valueOf(Utility
+                            .getAttributeValueAsString(val));
                     String newValue = comboBox.getText();
                     if (!oldValue.equals(newValue)) {
-                        attributeInSelection.setAttributeValue(newValue);
-                        MessageBox dialog = new MessageBox(viewer.getTable()
-                                .getShell(), SWT.ICON_QUESTION | SWT.OK
-                                | SWT.CANCEL);
-                        dialog.setText("Confirm action");
-                        dialog.setMessage("Do you want to modify the value?");
-                        int retval = dialog.open();
-                        if (retval != SWT.OK) {
-                            attributeInSelection.setAttributeValue(oldValue);
+                        // Get the AttriuteValue from the string
+                        AttributeValue value = AttributeValueBuilder.build(
+                                newValue, type.mBaseType);
+                        TypeInfo resTypeInfo = value.typeInfo();
+                        if (null == value || type.mDepth != resTypeInfo.mDepth
+                                || type.mType != resTypeInfo.mType
+                                || type.mBaseType != resTypeInfo.mBaseType) {
+                            MessageBox dialog = new MessageBox(viewer.getTree()
+                                    .getShell(), SWT.ICON_ERROR | SWT.OK);
+                            dialog.setText("Invalid Value");
+                            dialog.setMessage("Given value is invalid");
+                            dialog.open();
                         } else {
-                            ResourceManager resourceManager;
-                            resourceManager = Activator.getDefault()
-                                    .getResourceManager();
-                            SimulatorResource resource = resourceManager
-                                    .getCurrentResourceInSelection();
-                            resourceManager.attributeValueUpdated(resource,
-                                    attributeInSelection.getAttributeName(),
-                                    newValue);
+                            updateAttributeValue(att, value);
+                            MessageBox dialog = new MessageBox(viewer.getTree()
+                                    .getShell(), SWT.ICON_QUESTION | SWT.OK
+                                    | SWT.CANCEL);
+                            dialog.setText("Confirm action");
+                            dialog.setMessage("Do you want to modify the value?");
+                            int retval = dialog.open();
+                            if (retval != SWT.OK) {
+                                value = AttributeValueBuilder.build(oldValue,
+                                        type.mBaseType);
+                                updateAttributeValue(att, value);
+                            } else {
+                                ResourceManager resourceManager;
+                                resourceManager = Activator.getDefault()
+                                        .getResourceManager();
+
+                                Resource resource = resourceManager
+                                        .getCurrentResourceInSelection();
+
+                                AttributeValue resultValue = getResultantValue(value);
+
+                                resourceManager.attributeValueUpdated(
+                                        (SingleResource) resource, att.name(),
+                                        resultValue);
+
+                            }
                         }
-                        viewer.update(attributeInSelection, null);
+                        viewer.update(element, null);
                         comboBox.setVisible(false);
                     }
                 }
@@ -137,9 +224,23 @@ public class AttributeEditingSupport {
         @Override
         protected Object getValue(Object element) {
             int indexOfItem = 0;
-            LocalResourceAttribute att = (LocalResourceAttribute) element;
-            String valueString = String.valueOf(att.getAttributeValue());
-            List<String> valueSet = att.getAttValues();
+            SimulatorResourceAttribute att;
+
+            if (element instanceof LocalResourceAttribute) {
+                LocalResourceAttribute localAtt = (LocalResourceAttribute) element;
+                att = localAtt.getResourceAttributeRef();
+                if (null == att) {
+                    return 0;
+                }
+            } else if (element instanceof SimulatorResourceAttribute) {
+                att = (SimulatorResourceAttribute) element;
+            } else {
+                return 0;
+            }
+
+            String valueString = Utility.getAttributeValueAsString(att.value());
+            List<String> valueSet = Activator.getDefault().getResourceManager()
+                    .getAllValuesOfAttribute(att);
             if (null != valueSet) {
                 indexOfItem = valueSet.indexOf(valueString);
             }
@@ -151,11 +252,81 @@ public class AttributeEditingSupport {
 
         @Override
         protected void setValue(Object element, Object value) {
-            Object valueObj = attributeInSelection.getAttributeValue();
-            if (null == valueObj)
+            SimulatorResourceAttribute att;
+
+            if (element instanceof LocalResourceAttribute) {
+                LocalResourceAttribute localAtt = (LocalResourceAttribute) element;
+                att = localAtt.getResourceAttributeRef();
+                if (null == att) {
+                    return;
+                }
+            } else if (element instanceof SimulatorResourceAttribute) {
+                att = (SimulatorResourceAttribute) element;
+            } else {
                 return;
-            String attValue = String.valueOf(valueObj);
-            ((LocalResourceAttribute) element).setAttributeValue(attValue);
+            }
+
+            AttributeValue val = att.value();
+            if (null == val) {
+                return;
+            }
+            TypeInfo type = val.typeInfo();
+            if (type.mType == ValueType.ARRAY) {
+                int index;
+                try {
+                    index = Integer.parseInt(String.valueOf(value));
+                } catch (NumberFormatException nfe) {
+                    index = -1;
+                }
+                if (index == -1) {
+                    String oldValue = String.valueOf(Utility
+                            .getAttributeValueAsString(val));
+                    String newValue = comboBox.getText();
+                    if (!oldValue.equals(newValue)) {
+                        // Get the AttriuteValue from the string
+                        AttributeValue attValue = AttributeValueBuilder.build(
+                                newValue, type.mBaseType);
+                        TypeInfo resTypeInfo = attValue.typeInfo();
+                        if (null == attValue
+                                || type.mDepth != resTypeInfo.mDepth
+                                || type.mType != resTypeInfo.mType
+                                || type.mBaseType != resTypeInfo.mBaseType) {
+                            MessageBox dialog = new MessageBox(viewer.getTree()
+                                    .getShell(), SWT.ICON_ERROR | SWT.OK);
+                            dialog.setText("Invalid Value");
+                            dialog.setMessage("Given value is invalid");
+                            dialog.open();
+                        } else {
+                            updateAttributeValue(att, attValue);
+                            MessageBox dialog = new MessageBox(viewer.getTree()
+                                    .getShell(), SWT.ICON_QUESTION | SWT.OK
+                                    | SWT.CANCEL);
+                            dialog.setText("Confirm action");
+                            dialog.setMessage("Do you want to modify the value?");
+                            int retval = dialog.open();
+                            if (retval != SWT.OK) {
+                                attValue = AttributeValueBuilder.build(
+                                        oldValue, type.mBaseType);
+                                updateAttributeValue(att, attValue);
+                            } else {
+                                ResourceManager resourceManager;
+                                resourceManager = Activator.getDefault()
+                                        .getResourceManager();
+
+                                Resource resource = resourceManager
+                                        .getCurrentResourceInSelection();
+
+                                AttributeValue resultValue = getResultantValue(attValue);
+
+                                resourceManager.attributeValueUpdated(
+                                        (SingleResource) resource, att.name(),
+                                        resultValue);
+                            }
+                        }
+                    }
+                }
+            }
+
             viewer.update(element, null);
         }
 
@@ -168,13 +339,119 @@ public class AttributeEditingSupport {
             }
             return strArr;
         }
+
+        public void updateAttributeValue(SimulatorResourceAttribute att,
+                AttributeValue value) {
+            att.setValue(value);
+
+            IStructuredSelection selection = (IStructuredSelection) viewer
+                    .getSelection();
+            if (null == selection) {
+                return;
+            }
+
+            Object obj = selection.getFirstElement();
+            if (null == obj) {
+                return;
+            }
+
+            Tree t = viewer.getTree();
+            TreeItem item = t.getSelection()[0];
+            if (null == item) {
+                return;
+            }
+            TreeItem parent = item.getParentItem();
+
+            // Get the parent model
+            if (null == parent) {
+                // Top-level attribute
+                Resource res = Activator.getDefault().getResourceManager()
+                        .getCurrentResourceInSelection();
+                if (null == res) {
+                    return;
+                }
+                SimulatorResourceModel model = res.getResourceModel();
+                if (null == model) {
+                    return;
+                }
+                try {
+                    model.setAttributeValue(att.name(), value);
+                } catch (InvalidArgsException e) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                }
+            } else {
+                SimulatorResourceModel model;
+                Object data = parent.getData();
+                if (null == data) {
+                    return;
+                }
+                if (data instanceof SRMItem) {
+                    model = ((SRMItem) data).getModel();
+                } else {
+                    SimulatorResourceAttribute parentAtt;
+                    if (data instanceof LocalResourceAttribute) {
+                        parentAtt = ((LocalResourceAttribute) data)
+                                .getResourceAttributeRef();
+                    } else {
+                        parentAtt = (SimulatorResourceAttribute) data;
+                    }
+                    model = (SimulatorResourceModel) parentAtt.value().get();
+                }
+                try {
+                    model.setAttributeValue(att.name(), value);
+                } catch (InvalidArgsException e) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                }
+            }
+        }
+
+        public AttributeValue getResultantValue(AttributeValue newValue) {
+            AttributeValue val = null;
+            IStructuredSelection selection = (IStructuredSelection) viewer
+                    .getSelection();
+            if (null == selection) {
+                return null;
+            }
+
+            Object obj = selection.getFirstElement();
+            if (null == obj) {
+                return null;
+            }
+
+            Tree t = viewer.getTree();
+            TreeItem item = t.getSelection()[0];
+            if (null == item) {
+                return null;
+            }
+
+            TreeItem parent = item.getParentItem();
+            if (null == parent) {
+                Object data = item.getData();
+                // SimulatorResourceAttribute att =
+                // ((LocalResourceAttribute)data).getResourceAttributeRef();
+                val = newValue;
+            } else {
+                while (parent.getParentItem() != null) {
+                    parent = parent.getParentItem();
+                }
+                // Parent will point to the top-level attribute of type
+                // LocalResourceAttribute
+                Object data = parent.getData();
+                val = ((LocalResourceAttribute) data).getResourceAttributeRef()
+                        .value();
+            }
+
+            return val;
+        }
     }
 
     class AutomationEditor extends EditingSupport {
 
-        private final TableViewer viewer;
+        private final TreeViewer viewer;
 
-        public AutomationEditor(TableViewer viewer) {
+        public AutomationEditor(TreeViewer viewer) {
             super(viewer);
             this.viewer = viewer;
         }
@@ -189,16 +466,41 @@ public class AttributeEditingSupport {
             // CellEditor is not required as the automation is in progress.
             ResourceManager resourceManager = Activator.getDefault()
                     .getResourceManager();
-            LocalResourceAttribute att = (LocalResourceAttribute) element;
-            if (!resourceManager.isAttHasRangeOrAllowedValues(att)) {
+            Resource resource = resourceManager.getCurrentResourceInSelection();
+
+            if (null == resource) {
                 return null;
             }
 
-            SimulatorResource resource = resourceManager
-                    .getCurrentResourceInSelection();
-            if (null != resource && resource.isResourceAutomationInProgress()) {
+            if (resource instanceof CollectionResource) {
+                return null;
+            }
+            if (((SingleResource) resource).isResourceAutomationInProgress()) {
                 return null;
             }
+
+            SimulatorResourceAttribute att = null;
+            if (element instanceof LocalResourceAttribute) {
+                LocalResourceAttribute localAtt = (LocalResourceAttribute) element;
+                att = localAtt.getResourceAttributeRef();
+            }
+
+            if (null == att) {
+                return null;
+            }
+
+            AttributeValue val = att.value();
+            if (null == val) {
+                return null;
+            }
+
+            TypeInfo type = val.typeInfo();
+
+            if (type.mType == ValueType.RESOURCEMODEL
+                    || type.mType == ValueType.ARRAY) {
+                return null;
+            }
+
             return new CheckboxCellEditor(null, SWT.CHECK | SWT.READ_ONLY);
         }
 
@@ -214,8 +516,7 @@ public class AttributeEditingSupport {
                     .getResourceManager();
             // As automation depends on the current resource in selection, its
             // presence is being checked.
-            SimulatorResource resource = resourceManager
-                    .getCurrentResourceInSelection();
+            Resource resource = resourceManager.getCurrentResourceInSelection();
             if (null == resource) {
                 return;
             }
@@ -231,18 +532,18 @@ public class AttributeEditingSupport {
 
                 // Open the settings dialog
                 AutomationSettingDialog dialog = new AutomationSettingDialog(
-                        viewer.getTable().getShell(), automationSettings);
+                        viewer.getTree().getShell(), automationSettings);
                 dialog.create();
                 if (dialog.open() == Window.OK) {
                     String automationType = dialog.getAutomationType();
                     String updateFreq = dialog.getUpdateFrequency();
 
-                    AutomationType autoType = AutomationType
+                    AutoUpdateType autoType = AutoUpdateType
                             .valueOf(automationType);
                     int updFreq = Utility
                             .getUpdateIntervalFromString(updateFreq);
-                    int autoId = resourceManager.startAutomation(resource, att,
-                            autoType, updFreq);
+                    int autoId = resourceManager.startAutomation(
+                            (SingleResource) resource, att, autoType, updFreq);
                     if (autoId == -1) {
                         MessageDialog.openInformation(Display.getDefault()
                                 .getActiveShell(), "Automation Status",
@@ -253,7 +554,7 @@ public class AttributeEditingSupport {
                 }
             } else {
                 // Stop the automation
-                resourceManager.stopAutomation(resource, att,
+                resourceManager.stopAutomation((SingleResource) resource, att,
                         att.getAutomationId());
                 MessageDialog.openInformation(Display.getDefault()
                         .getActiveShell(), "Automation Status",
index 5f76435..f81bda6 100644 (file)
 package oic.simulator.serviceprovider.view;
 
 import java.util.List;
-import java.util.Set;
+import java.util.Map;
 
 import oic.simulator.serviceprovider.Activator;
 import oic.simulator.serviceprovider.listener.IAutomationUIListener;
 import oic.simulator.serviceprovider.listener.IResourceModelChangedUIListener;
-import oic.simulator.serviceprovider.listener.IResourceSelectionChangedUIListener;
+import oic.simulator.serviceprovider.listener.ISelectionChangedUIListener;
 import oic.simulator.serviceprovider.manager.ResourceManager;
-import oic.simulator.serviceprovider.resource.LocalResourceAttribute;
-import oic.simulator.serviceprovider.resource.ModelChangeNotificationType;
-import oic.simulator.serviceprovider.resource.SimulatorResource;
+import oic.simulator.serviceprovider.manager.UiListenerHandler;
+import oic.simulator.serviceprovider.model.CollectionResource;
+import oic.simulator.serviceprovider.model.Device;
+import oic.simulator.serviceprovider.model.LocalResourceAttribute;
+import oic.simulator.serviceprovider.model.Resource;
+import oic.simulator.serviceprovider.model.SRMItem;
+import oic.simulator.serviceprovider.model.SingleResource;
 import oic.simulator.serviceprovider.utils.Constants;
+import oic.simulator.serviceprovider.utils.Utility;
 
-import org.eclipse.jface.viewers.ColumnLabelProvider;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.StyledCellLabelProvider;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.TreeViewerColumn;
 import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerCell;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.graphics.Image;
@@ -44,81 +48,90 @@ import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeColumn;
 import org.eclipse.ui.part.ViewPart;
+import org.oic.simulator.AttributeValue;
+import org.oic.simulator.AttributeValue.TypeInfo;
+import org.oic.simulator.AttributeValue.ValueType;
+import org.oic.simulator.SimulatorResourceAttribute;
+import org.oic.simulator.SimulatorResourceModel;
 
 /**
  * This class manages and shows the attribute view in the perspective.
  */
 public class AttributeView extends ViewPart {
 
-    public static final String                  VIEW_ID        = "oic.simulator.serviceprovider.view.attribute";
+    public static final String              VIEW_ID        = "oic.simulator.serviceprovider.view.attribute";
 
-    private TableViewer                         attTblViewer;
+    private TreeViewer                      attViewer;
 
-    private AttributeEditingSupport             attributeEditor;
+    private AttributeEditingSupport         attributeEditor;
 
-    private IResourceSelectionChangedUIListener resourceSelectionChangedListener;
-    private IResourceModelChangedUIListener     resourceModelChangedUIListener;
-    private IAutomationUIListener               automationUIListener;
+    private ISelectionChangedUIListener     resourceSelectionChangedListener;
+    private IResourceModelChangedUIListener resourceModelChangedUIListener;
+    private IAutomationUIListener           automationUIListener;
 
-    private final String[]                      attTblHeaders  = { "Name",
-            "Value", "Automation"                             };
-    private final Integer[]                     attTblColWidth = { 150, 190,
-            150                                               };
+    private final String[]                  attTblHeaders  = { "Name", "Value",
+            "Automation"                                  };
+    private final Integer[]                 attTblColWidth = { 150, 190, 150 };
 
-    private ResourceManager                     resourceManager;
+    private ResourceManager                 resourceManager;
 
     public AttributeView() {
 
         resourceManager = Activator.getDefault().getResourceManager();
 
-        resourceSelectionChangedListener = new IResourceSelectionChangedUIListener() {
+        resourceSelectionChangedListener = new ISelectionChangedUIListener() {
 
             @Override
-            public void onResourceSelectionChange() {
+            public void onResourceSelectionChange(final Resource resource) {
                 Display.getDefault().asyncExec(new Runnable() {
-
                     @Override
                     public void run() {
-                        if (null != attTblViewer) {
-                            updateViewer(getData());
-                            SimulatorResource resource = resourceManager
-                                    .getCurrentResourceInSelection();
-                            Table tbl = attTblViewer.getTable();
-                            if (!tbl.isDisposed()) {
+                        if (null != attViewer) {
+                            updateViewer(getData(resource));
+                            Tree tree = attViewer.getTree();
+                            if (!tree.isDisposed()) {
                                 if (null != resource
-                                        && resource
-                                                .isResourceAutomationInProgress()) {
-                                    tbl.setEnabled(false);
+                                        && (resource instanceof SingleResource && ((SingleResource) resource)
+                                                .isResourceAutomationInProgress())) {
+                                    tree.setEnabled(false);
                                 } else {
-                                    tbl.setEnabled(true);
+                                    tree.setEnabled(true);
                                 }
                             }
                         }
                     }
                 });
             }
+
+            @Override
+            public void onDeviceSelectionChange(Device dev) {
+                Display.getDefault().asyncExec(new Runnable() {
+                    @Override
+                    public void run() {
+                        updateViewer(null);
+                    }
+                });
+            }
         };
 
         resourceModelChangedUIListener = new IResourceModelChangedUIListener() {
 
             @Override
-            public void onResourceModelChange(
-                    final ModelChangeNotificationType notificationType,
-                    final String resourceURI,
-                    final Set<LocalResourceAttribute> valueChangeSet) {
+            public void onResourceModelChange(final Resource resource) {
                 Display.getDefault().asyncExec(new Runnable() {
                     @Override
                     public void run() {
                         // Handle the notification only if it is for the current
                         // resource in selection
-                        SimulatorResource resource = resourceManager
+                        Resource resourceInSelection = resourceManager
                                 .getCurrentResourceInSelection();
-                        if (null == resource) {
+                        if (null == resourceInSelection) {
                             return;
                         }
-                        if (!resourceURI.equals(resource.getResourceURI())) {
+                        if (resource != resourceInSelection) {
                             // This notification is for a different resource
                             // whose attributes are not
                             // currently not being shown in UI. So ignoring this
@@ -127,17 +140,11 @@ public class AttributeView extends ViewPart {
                         }
                         // Refresh the table viewers which will display
                         // the updated values
-                        if (null != attTblViewer) {
-                            if (notificationType == ModelChangeNotificationType.ATTRIBUTE_ADDED
-                                    || notificationType == ModelChangeNotificationType.ATTRIBUTE_REMOVED) {
-                                updateViewer(getData());
-                            } else if (notificationType == ModelChangeNotificationType.NO_ATTRIBUTES_IN_MODEL) {
-                                attTblViewer.setInput(null);
-                            } else if (notificationType == ModelChangeNotificationType.ATTRIBUTE_VALUE_CHANGED) {
-                                if (null != valueChangeSet) {
-                                    attTblViewer.update(
-                                            valueChangeSet.toArray(), null);
-                                }
+                        if (null != attViewer) {
+                            if (resource instanceof CollectionResource) {
+                                updateViewer(getData(resource));
+                            } else {
+                                updateViewer(getData(resource));
                             }
                         }
                     }
@@ -148,33 +155,32 @@ public class AttributeView extends ViewPart {
         automationUIListener = new IAutomationUIListener() {
 
             @Override
-            public void onResourceAutomationStart(final String resourceURI) {
+            public void onResourceAutomationStart(final SingleResource resource) {
                 Display.getDefault().asyncExec(new Runnable() {
 
                     @Override
                     public void run() {
-                        if (null == resourceURI) {
+                        if (null == resource) {
                             return;
                         }
-                        SimulatorResource resource = resourceManager
+                        Resource resourceInSelection = resourceManager
                                 .getCurrentResourceInSelection();
-                        if (null == resource) {
+                        if (null == resourceInSelection) {
                             return;
                         }
-                        String uri = resource.getResourceURI();
                         // Checking whether attributes view is currently
                         // displaying the attributes of the
                         // resource whose automation has just started
-                        if (null != uri && uri.equals(resourceURI)) {
-                            Table tbl;
-                            tbl = attTblViewer.getTable();
-                            if (!tbl.isDisposed()) {
-                                attTblViewer.refresh();
+                        if (resource == resourceInSelection) {
+                            Tree tree;
+                            tree = attViewer.getTree();
+                            if (!tree.isDisposed()) {
+                                attViewer.refresh();
 
                                 // Disabling the table to prevent interactions
                                 // during the automation
-                                tbl.setEnabled(false);
-                                tbl.deselectAll();
+                                tree.setEnabled(false);
+                                tree.deselectAll();
                             }
                         }
                     }
@@ -182,7 +188,7 @@ public class AttributeView extends ViewPart {
             }
 
             @Override
-            public void onAutomationComplete(final String resourceURI,
+            public void onAutomationComplete(final SingleResource resource,
                     final String attName) {
                 // This method notifies the completion of attribute level
                 // automation.
@@ -190,40 +196,39 @@ public class AttributeView extends ViewPart {
 
                     @Override
                     public void run() {
-                        if (null == resourceURI) {
+                        if (null == resource) {
                             return;
                         }
                         // Check if the given resourceURI is the uri of the
                         // resource whose attributes are currently being
                         // displayed by this view.
-                        SimulatorResource resource = resourceManager
+                        Resource resourceInSelection = resourceManager
                                 .getCurrentResourceInSelection();
-                        if (null == resource) {
+                        if (null == resourceInSelection) {
                             return;
                         }
-                        String uri = resource.getResourceURI();
-                        if (null == uri || !uri.equals(resourceURI)) {
+                        if (resource != resourceInSelection) {
                             return;
                         }
-                        Table tbl;
-                        tbl = attTblViewer.getTable();
-                        if (!tbl.isDisposed()) {
+                        Tree tree;
+                        tree = attViewer.getTree();
+                        if (!tree.isDisposed()) {
                             if (null != attName) {
                                 // Attribute level automation has stopped
                                 LocalResourceAttribute att = resourceManager
-                                        .getAttributeByResourceURI(resourceURI,
+                                        .getAttributeByResourceURI(resource,
                                                 attName);
                                 if (null == att) {
                                     return;
                                 } else {
-                                    attTblViewer.update(att, null);
+                                    attViewer.update(att, null);
                                 }
                             } else {
                                 // Resource level automation has stopped
                                 // Enabling the table which was disabled at the
                                 // beginning of automation
-                                tbl.setEnabled(true);
-                                attTblViewer.refresh();
+                                tree.setEnabled(true);
+                                attViewer.refresh();
                             }
                         }
                     }
@@ -247,122 +252,74 @@ public class AttributeView extends ViewPart {
         attGroup.setText("Attributes");
         attGroup.setBackground(color);
 
-        attTblViewer = new TableViewer(attGroup, SWT.SINGLE | SWT.H_SCROLL
-                | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
+        Tree addressTree = new Tree(attGroup, SWT.SINGLE | SWT.BORDER
+                | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
+        addressTree.setHeaderVisible(true);
 
-        createAttributeColumns(attTblViewer);
+        attViewer = new TreeViewer(addressTree);
+
+        createAttributeColumns(attViewer);
 
         // make lines and header visible
-        Table table = attTblViewer.getTable();
-        table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-        table.setHeaderVisible(true);
-        table.setLinesVisible(true);
+        Tree tree = attViewer.getTree();
+        tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+        tree.setHeaderVisible(true);
+        tree.setLinesVisible(true);
 
-        attTblViewer.setContentProvider(new AttributeContentProvider());
+        attViewer.setContentProvider(new AttributeContentProvider());
+        attViewer.setLabelProvider(new AttributeLabelProvider());
 
         addManagerListeners();
 
         // Check whether there is any resource selected already
-        List<LocalResourceAttribute> propertyList = getData();
+        List<LocalResourceAttribute> propertyList = getData(resourceManager
+                .getCurrentResourceInSelection());
         if (null != propertyList) {
             updateViewer(propertyList);
         }
     }
 
-    public void createAttributeColumns(TableViewer tableViewer) {
+    public void createAttributeColumns(TreeViewer viewer) {
+        Tree tree = viewer.getTree();
 
         attributeEditor = new AttributeEditingSupport();
 
-        TableViewerColumn attName = new TableViewerColumn(tableViewer, SWT.NONE);
-        attName.getColumn().setWidth(attTblColWidth[0]);
-        attName.getColumn().setText(attTblHeaders[0]);
-        attName.setLabelProvider(new StyledCellLabelProvider() {
-            @Override
-            public void update(ViewerCell cell) {
-                Object element = cell.getElement();
-                if (element instanceof LocalResourceAttribute) {
-                    LocalResourceAttribute attribute = (LocalResourceAttribute) element;
-                    if (null != attribute) {
-                        cell.setText(attribute.getAttributeName());
-                    }
-                }
-            }
-        });
-
-        TableViewerColumn attValue = new TableViewerColumn(tableViewer,
-                SWT.NONE);
-        attValue.getColumn().setWidth(attTblColWidth[1]);
-        attValue.getColumn().setText(attTblHeaders[1]);
-        attValue.setLabelProvider(new ColumnLabelProvider() {
-            @Override
-            public String getText(Object element) {
-                if (element instanceof LocalResourceAttribute) {
-                    LocalResourceAttribute attribute = (LocalResourceAttribute) element;
-                    if (null != attribute) {
-                        Object val = attribute.getAttributeValue();
-                        if (null != val) {
-                            return String.valueOf(val);
-                        }
-                    }
-                }
-                return "";
-            }
-        });
-        attValue.setEditingSupport(attributeEditor
-                .createAttributeValueEditor(attTblViewer));
-
-        TableViewerColumn automation = new TableViewerColumn(tableViewer,
-                SWT.NONE);
-        automation.getColumn().setWidth(attTblColWidth[2]);
-        automation.getColumn().setText(attTblHeaders[2]);
-        automation.setLabelProvider(new ColumnLabelProvider() {
-            @Override
-            public String getText(Object element) {
-                LocalResourceAttribute att = (LocalResourceAttribute) element;
-                if (!resourceManager.isAttHasRangeOrAllowedValues(att)) {
-                    System.out.println("No range or allowed values");
-                    return "Read Only";
-                }
-                if (att.isAutomationInProgress()) {
-                    return Constants.ENABLED;
-                }
-                return Constants.DISABLED;
-            }
-
-            @Override
-            public Image getImage(Object element) {
-                LocalResourceAttribute att = (LocalResourceAttribute) element;
-                if (!resourceManager.isAttHasRangeOrAllowedValues(att)) {
-                    System.out.println("No range or allowed values");
-                    return null;
-                }
-                if (att.isAutomationInProgress()) {
-                    return Activator.getDefault().getImageRegistry()
-                            .get(Constants.CHECKED);
-                } else {
-                    return Activator.getDefault().getImageRegistry()
-                            .get(Constants.UNCHECKED);
-                }
-            }
-        });
-        automation.setEditingSupport(attributeEditor
-                .createAutomationEditor(attTblViewer));
+        TreeColumn attName = new TreeColumn(tree, SWT.NONE);
+        attName.setWidth(attTblColWidth[0]);
+        attName.setText(attTblHeaders[0]);
+
+        TreeColumn attValue = new TreeColumn(tree, SWT.NONE);
+        attValue.setWidth(attTblColWidth[1]);
+        attValue.setText(attTblHeaders[1]);
+        TreeViewerColumn attValueVwrCol = new TreeViewerColumn(attViewer,
+                attValue);
+        attValueVwrCol.setEditingSupport(attributeEditor
+                .createAttributeValueEditor(attViewer));
+
+        TreeColumn automation = new TreeColumn(tree, SWT.NONE);
+        automation.setWidth(attTblColWidth[2]);
+        automation.setText(attTblHeaders[2]);
+        TreeViewerColumn automationVwrCol = new TreeViewerColumn(attViewer,
+                automation);
+        automationVwrCol.setEditingSupport(attributeEditor
+                .createAutomationEditor(attViewer));
     }
 
     private void addManagerListeners() {
-        resourceManager
-                .addResourceSelectionChangedUIListener(resourceSelectionChangedListener);
-        resourceManager
-                .addResourceModelChangedUIListener(resourceModelChangedUIListener);
-        resourceManager.addAutomationUIListener(automationUIListener);
+        UiListenerHandler.getInstance().addResourceSelectionChangedUIListener(
+                resourceSelectionChangedListener);
+        UiListenerHandler.getInstance().addResourceModelChangedUIListener(
+                resourceModelChangedUIListener);
+        UiListenerHandler.getInstance().addAutomationUIListener(
+                automationUIListener);
     }
 
-    private List<LocalResourceAttribute> getData() {
-        SimulatorResource resourceInSelection = resourceManager
-                .getCurrentResourceInSelection();
-        if (null != resourceInSelection) {
+    private List<LocalResourceAttribute> getData(Resource resource) {
+        if (null != resource) {
             List<LocalResourceAttribute> attList = resourceManager
-                    .getAttributes(resourceInSelection);
+                    .getAttributes((Resource) resource);
+            // List<LocalResourceAttribute> attList =
+            // Utility.getDummyAttributes();
             return attList;
         } else {
             return null;
@@ -370,27 +327,25 @@ public class AttributeView extends ViewPart {
     }
 
     private void updateViewer(List<LocalResourceAttribute> attList) {
-        Table tbl;
+        Tree tree = attViewer.getTree();;
         if (null != attList) {
-            tbl = attTblViewer.getTable();
-            if (null != tbl && !tbl.isDisposed()) {
-                tbl.setLinesVisible(true);
-                attTblViewer.setInput(attList.toArray());
+            if (null != tree && !tree.isDisposed()) {
+                tree.setLinesVisible(true);
+                attViewer.setInput(attList.toArray());
             }
         } else {
             // Clear the attributes table viewer
-            if (null != attTblViewer) {
-                tbl = attTblViewer.getTable();
-                if (null != tbl && !tbl.isDisposed()) {
+            if (null != attViewer) {
+                if (null != tree && !tree.isDisposed()) {
                     // tbl.deselectAll();
-                    tbl.removeAll();
-                    tbl.setLinesVisible(false);
+                    tree.removeAll();
+                    tree.setLinesVisible(false);
                 }
             }
         }
     }
 
-    class AttributeContentProvider implements IStructuredContentProvider {
+    class AttributeContentProvider implements ITreeContentProvider {
 
         @Override
         public void dispose() {
@@ -401,8 +356,248 @@ public class AttributeView extends ViewPart {
         }
 
         @Override
+        public Object[] getChildren(Object element) {
+            if (element instanceof SimulatorResourceAttribute
+                    || element instanceof LocalResourceAttribute) {
+                SimulatorResourceAttribute att;
+                if (element instanceof LocalResourceAttribute) {
+                    LocalResourceAttribute localAtt = (LocalResourceAttribute) element;
+                    att = localAtt.getResourceAttributeRef();
+                    if (null == att) {
+                        return new Object[1];
+                    }
+                } else {
+                    att = (SimulatorResourceAttribute) element;
+                }
+                AttributeValue val = att.value();
+                if (null == val) {
+                    return new Object[1];
+                }
+                TypeInfo type = val.typeInfo();
+                if (type.mType == ValueType.RESOURCEMODEL) {
+                    SimulatorResourceModel model = (SimulatorResourceModel) val
+                            .get();
+                    if (null == model) {
+                        return new Object[1];
+                    }
+                    return resourceManager.getAttributes(model).toArray();
+                } else if (type.mType == ValueType.ARRAY
+                        && type.mBaseType == ValueType.RESOURCEMODEL
+                        && type.mDepth == 1) {
+                    SimulatorResourceModel[] model = (SimulatorResourceModel[]) val
+                            .get();
+                    if (null == model || model.length < 1) {
+                        return new Object[1];
+                    }
+                    return resourceManager.getIndexedAttributes(model)
+                            .toArray();
+                }
+            } else if (element instanceof SRMItem) {
+                SRMItem item = (SRMItem) element;
+                SimulatorResourceModel model = (SimulatorResourceModel) item
+                        .getModel();
+                if (null == model) {
+                    return new Object[1];
+                }
+                return resourceManager.getAttributes(model).toArray();
+            }
+            return new Object[1];
+        }
+
+        @Override
         public Object[] getElements(Object element) {
-            return (Object[]) element;
+            Object[] elements = (Object[]) element;
+            return elements;
+        }
+
+        @Override
+        public Object getParent(Object element) {
+            return null;
+        }
+
+        @Override
+        public boolean hasChildren(Object element) {
+            if (element instanceof SimulatorResourceAttribute
+                    || element instanceof LocalResourceAttribute) {
+                SimulatorResourceAttribute att;
+                if (element instanceof LocalResourceAttribute) {
+                    LocalResourceAttribute localAtt = (LocalResourceAttribute) element;
+                    att = localAtt.getResourceAttributeRef();
+                    if (null == att) {
+                        return false;
+                    }
+                } else {
+                    att = (SimulatorResourceAttribute) element;
+                }
+                AttributeValue val = att.value();
+                if (null == val) {
+                    return false;
+                }
+                TypeInfo type = val.typeInfo();
+                if (type.mType == ValueType.RESOURCEMODEL) {
+                    SimulatorResourceModel model = (SimulatorResourceModel) val
+                            .get();
+                    if (null == model) {
+                        return false;
+                    }
+                    Map<String, SimulatorResourceAttribute> attributes = model
+                            .getAttributes();
+                    if (null != attributes && attributes.size() > 0) {
+                        return true;
+                    }
+                } else if (type.mType == ValueType.ARRAY
+                        && type.mBaseType == ValueType.RESOURCEMODEL
+                        && type.mDepth == 1) {
+                    SimulatorResourceModel[] model = (SimulatorResourceModel[]) val
+                            .get();
+                    if (null != model && model.length > 0) {
+                        return true;
+                    }
+                }
+            } else if (element instanceof SRMItem) {
+                SRMItem srmItem = (SRMItem) element;
+                SimulatorResourceModel model = srmItem.getModel();
+                if (null == model) {
+                    return false;
+                }
+                Map<String, SimulatorResourceAttribute> attributes = model
+                        .getAttributes();
+                if (null != attributes && attributes.size() > 0) {
+                    return true;
+                }
+            }
+            return false;
+        }
+    }
+
+    class AttributeLabelProvider implements ITableLabelProvider {
+
+        @Override
+        public void addListener(ILabelProviderListener arg0) {
+        }
+
+        @Override
+        public void dispose() {
+        }
+
+        @Override
+        public boolean isLabelProperty(Object arg0, String arg1) {
+            return false;
+        }
+
+        @Override
+        public void removeListener(ILabelProviderListener arg0) {
+
+        }
+
+        @Override
+        public Image getColumnImage(Object element, int col) {
+            if (col == 2) {
+                if (element instanceof SimulatorResourceAttribute
+                        || element instanceof LocalResourceAttribute) {
+                    SimulatorResourceAttribute att;
+                    if (element instanceof LocalResourceAttribute) {
+                        LocalResourceAttribute localAtt = (LocalResourceAttribute) element;
+                        att = localAtt.getResourceAttributeRef();
+                    } else {
+                        att = (SimulatorResourceAttribute) element;
+                    }
+                    AttributeValue val = att.value();
+                    if (null == val) {
+                        return null;
+                    }
+                    TypeInfo type = val.typeInfo();
+                    if (type.mType == ValueType.RESOURCEMODEL
+                            || type.mType == ValueType.ARRAY) {
+                        return null;
+                    }
+                    if (element instanceof LocalResourceAttribute) {
+                        if (!resourceManager.isAttHasRangeOrAllowedValues(att)) {
+                            System.out.println("No range or allowed values");
+                            return null;
+                        }
+                        if (((LocalResourceAttribute) element)
+                                .isAutomationInProgress()) {
+                            return Activator.getDefault().getImageRegistry()
+                                    .get(Constants.CHECKED);
+                        }
+                        return Activator.getDefault().getImageRegistry()
+                                .get(Constants.UNCHECKED);
+                    }
+                    return null;
+                }
+            }
+            return null;
+        }
+
+        @Override
+        public String getColumnText(Object element, int col) {
+            if (element instanceof SimulatorResourceAttribute
+                    || element instanceof LocalResourceAttribute) {
+                SimulatorResourceAttribute att;
+                if (element instanceof LocalResourceAttribute) {
+                    LocalResourceAttribute localAtt = (LocalResourceAttribute) element;
+                    att = localAtt.getResourceAttributeRef();
+                } else {
+                    att = (SimulatorResourceAttribute) element;
+                }
+                AttributeValue val = att.value();
+                if (null == val) {
+                    return "";
+                }
+                TypeInfo type = val.typeInfo();
+                switch (col) {
+                    case 0:
+                        return att.name();
+                    case 1:
+                        if (!(type.mType == ValueType.RESOURCEMODEL || (type.mType == ValueType.ARRAY && type.mBaseType == ValueType.RESOURCEMODEL))) {
+                            String value = Utility
+                                    .getAttributeValueAsString(val);
+                            if (null == value) {
+                                value = "";
+                            }
+                            return value;
+                        } else {
+                            return "";
+                        }
+                    case 2:
+                        Resource res = resourceManager
+                                .getCurrentResourceInSelection();
+                        if (null != res && res instanceof CollectionResource) {
+                            return "-";
+                        }
+
+                        if (type.mType == ValueType.RESOURCEMODEL
+                                || type.mType == ValueType.ARRAY) {
+                            return "";
+                        }
+                        if (element instanceof LocalResourceAttribute) {
+                            if (!resourceManager
+                                    .isAttHasRangeOrAllowedValues(att)) {
+                                System.out
+                                        .println("No range or allowed values");
+                                return "Read Only";
+                            }
+                            if (((LocalResourceAttribute) element)
+                                    .isAutomationInProgress()) {
+                                return Constants.ENABLED;
+                            }
+                            return Constants.DISABLED;
+                        }
+                        return "NA";
+                }
+            } else if (element instanceof SRMItem) {
+                SRMItem item = (SRMItem) element;
+                switch (col) {
+                    case 0:
+                        return "[" + item.getIndex() + "]";
+                    case 1:
+                        return "";
+                    case 2:
+                        return "";
+                }
+            }
+            return null;
         }
 
     }
@@ -411,19 +606,22 @@ public class AttributeView extends ViewPart {
     public void dispose() {
         // Unregister the selection listener
         if (null != resourceSelectionChangedListener) {
-            resourceManager
-                    .removeResourceSelectionChangedUIListener(resourceSelectionChangedListener);
+            UiListenerHandler.getInstance()
+                    .removeResourceSelectionChangedUIListener(
+                            resourceSelectionChangedListener);
         }
 
         // Unregister the model change listener
         if (null != resourceModelChangedUIListener) {
-            resourceManager
-                    .removeResourceModelChangedUIListener(resourceModelChangedUIListener);
+            UiListenerHandler.getInstance()
+                    .removeResourceModelChangedUIListener(
+                            resourceModelChangedUIListener);
         }
 
         // Unregister the automation complete listener
         if (null != automationUIListener) {
-            resourceManager.removeAutomationUIListener(automationUIListener);
+            UiListenerHandler.getInstance().removeAutomationUIListener(
+                    automationUIListener);
         }
 
         super.dispose();
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/DevicePlatformInfoView.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/DevicePlatformInfoView.java
new file mode 100644 (file)
index 0000000..b8ebf77
--- /dev/null
@@ -0,0 +1,377 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package oic.simulator.serviceprovider.view;
+
+import java.util.List;
+
+import oic.simulator.serviceprovider.Activator;
+import oic.simulator.serviceprovider.model.MetaProperty;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.EditingSupport;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.StyledCellLabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.TextCellEditor;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerCell;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CTabFolder;
+import org.eclipse.swt.custom.CTabItem;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.part.ViewPart;
+
+/**
+ * This class is used to set the platform and device information. The
+ * information is only one per stack and hence only one instance can be
+ * stored/used at a time.
+ */
+public class DevicePlatformInfoView extends ViewPart {
+
+    public static final String VIEW_ID       = "oic.simulator.serviceprovider.view.devplatinfo";
+
+    private final String[]     columnHeaders = { "Property", "Value" };
+
+    private final Integer[]    columnWidth   = { 150, 150 };
+
+    private List<MetaProperty> metaProperties;
+
+    private boolean            enable_edit;
+
+    private Text               deviceNameTxt;
+    private Button             devEditBtn;
+    private Button             devCancelBtn;
+    private Button             platEditBtn;
+    private Button             platCancelBtn;
+
+    private TableViewer        platformTblViewer;
+
+    private CTabFolder         folder;
+    private CTabItem           devicePropTab;
+    private CTabItem           platformPropTab;
+
+    @Override
+    public void createPartControl(Composite parent) {
+        parent.setLayout(new GridLayout());
+        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        parent.setLayoutData(gd);
+
+        // Create a Tab Folder.
+        folder = new CTabFolder(parent, SWT.BORDER);
+        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        folder.setLayoutData(gd);
+        folder.setSimple(false);
+        folder.setUnselectedCloseVisible(false);
+        folder.setUnselectedImageVisible(false);
+
+        createDevicePropertiesTab();
+
+        createPlatformPropertiesTab();
+
+        folder.setSelection(devicePropTab);
+
+        metaProperties = getPlatformPropData();
+
+        updateViewer(metaProperties);
+    }
+
+    private void createDevicePropertiesTab() {
+        devicePropTab = new CTabItem(folder, SWT.NULL);
+        devicePropTab.setText("Device");
+
+        // Adding the group to the folder.
+        Group propGroup = new Group(folder, SWT.NONE);
+
+        Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
+        propGroup.setBackground(color);
+
+        propGroup.setLayout(new GridLayout(2, false));
+        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        gd.horizontalIndent = 5;
+        gd.verticalIndent = 5;
+        propGroup.setLayoutData(gd);
+
+        Label devNameLbl = new Label(propGroup, SWT.NULL);
+        devNameLbl.setText("Device Name");
+        gd = new GridData();
+        gd.horizontalAlignment = SWT.FILL;
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalSpan = 2;
+        devNameLbl.setLayoutData(gd);
+
+        deviceNameTxt = new Text(propGroup, SWT.BORDER);
+        deviceNameTxt.setText(Activator.getDefault().getResourceManager()
+                .getDeviceName());
+        gd = new GridData();
+        gd.horizontalAlignment = SWT.FILL;
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalSpan = 2;
+        deviceNameTxt.setLayoutData(gd);
+        deviceNameTxt.setEnabled(false);
+
+        devEditBtn = new Button(propGroup, SWT.PUSH);
+        devEditBtn.setText("Edit");
+        gd = new GridData();
+        gd.widthHint = 50;
+        devEditBtn.setLayoutData(gd);
+        devEditBtn.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                if (devEditBtn.getText().equals("Edit")) {
+                    deviceNameTxt.setEnabled(true);
+                    devCancelBtn.setEnabled(true);
+
+                    deviceNameTxt.selectAll();
+                    deviceNameTxt.setFocus();
+                    devEditBtn.setText("Save");
+                } else {
+                    String devName = deviceNameTxt.getText();
+                    if (null == devName || devName.trim().length() < 1) {
+                        MessageDialog.openError(Display.getDefault()
+                                .getActiveShell(), "Invalid Device Name",
+                                "Device name is Invalid!!");
+                        deviceNameTxt.setFocus();
+                        return;
+                    }
+                    Activator.getDefault().getResourceManager()
+                            .setDeviceName(devName);
+                    deviceNameTxt.setEnabled(false);
+                    devCancelBtn.setEnabled(false);
+                    devEditBtn.setText("Edit");
+                }
+            }
+        });
+
+        devCancelBtn = new Button(propGroup, SWT.PUSH);
+        devCancelBtn.setText("Cancel");
+        devCancelBtn.setEnabled(false);
+        gd = new GridData();
+        gd.widthHint = 70;
+        devCancelBtn.setLayoutData(gd);
+        devCancelBtn.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                deviceNameTxt.setText(Activator.getDefault()
+                        .getResourceManager().getDeviceName());
+                deviceNameTxt.setEnabled(false);
+                devCancelBtn.setEnabled(false);
+                devEditBtn.setText("Edit");
+            }
+        });
+
+        devicePropTab.setControl(propGroup);
+    }
+
+    private void createPlatformPropertiesTab() {
+        platformPropTab = new CTabItem(folder, SWT.NULL);
+        platformPropTab.setText("Platform");
+
+        // Adding the group to the folder.
+        Group propGroup = new Group(folder, SWT.NONE);
+
+        Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
+        propGroup.setBackground(color);
+
+        propGroup.setLayout(new GridLayout(2, false));
+        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        propGroup.setLayoutData(gd);
+
+        platformTblViewer = new TableViewer(propGroup, SWT.SINGLE
+                | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
+
+        createColumns(platformTblViewer);
+
+        // Make lines and header visible
+        final Table table = platformTblViewer.getTable();
+        table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+        table.setHeaderVisible(true);
+        table.setLinesVisible(true);
+        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        gd.horizontalSpan = 2;
+        table.setLayoutData(gd);
+
+        platformTblViewer.setContentProvider(new PropertycontentProvider());
+
+        platEditBtn = new Button(propGroup, SWT.PUSH);
+        platEditBtn.setText("Edit");
+        gd = new GridData();
+        gd.widthHint = 50;
+        platEditBtn.setLayoutData(gd);
+        platEditBtn.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                if (platEditBtn.getText().equals("Edit")) {
+                    platCancelBtn.setEnabled(true);
+                    platEditBtn.setText("Save");
+                    enable_edit = true;
+                } else {
+                    Activator.getDefault().getResourceManager()
+                            .setPlatformInfo(metaProperties);
+                    platCancelBtn.setEnabled(false);
+                    platEditBtn.setText("Edit");
+                    enable_edit = false;
+                }
+            }
+        });
+
+        platCancelBtn = new Button(propGroup, SWT.PUSH);
+        platCancelBtn.setText("Cancel");
+        platCancelBtn.setEnabled(false);
+        gd = new GridData();
+        gd.widthHint = 70;
+        platCancelBtn.setLayoutData(gd);
+        platCancelBtn.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                metaProperties = getPlatformPropData();
+                updateViewer(metaProperties);
+
+                platCancelBtn.setEnabled(false);
+                platEditBtn.setText("Edit");
+                enable_edit = false;
+            }
+        });
+
+        platformPropTab.setControl(propGroup);
+    }
+
+    public void createColumns(TableViewer tableViewer) {
+        TableViewerColumn propName = new TableViewerColumn(tableViewer,
+                SWT.NONE);
+        propName.getColumn().setWidth(columnWidth[0]);
+        propName.getColumn().setText(columnHeaders[0]);
+        propName.setLabelProvider(new StyledCellLabelProvider() {
+            @Override
+            public void update(ViewerCell cell) {
+                MetaProperty prop = (MetaProperty) cell.getElement();
+                cell.setText(prop.getPropName());
+                super.update(cell);
+            }
+        });
+
+        TableViewerColumn propValue = new TableViewerColumn(tableViewer,
+                SWT.NONE);
+        propValue.getColumn().setWidth(columnWidth[1]);
+        propValue.getColumn().setText(columnHeaders[1]);
+        propValue.setLabelProvider(new ColumnLabelProvider() {
+            @Override
+            public String getText(Object element) {
+                MetaProperty prop = (MetaProperty) element;
+                if (null != prop) {
+                    return prop.getPropValue();
+                } else {
+                    return "";
+                }
+            }
+        });
+        propValue.setEditingSupport(new PropValueEditor(platformTblViewer));
+    }
+
+    class PropertycontentProvider implements IStructuredContentProvider {
+
+        @Override
+        public void dispose() {
+        }
+
+        @Override
+        public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
+        }
+
+        @Override
+        public Object[] getElements(Object element) {
+            return (Object[]) element;
+        }
+    }
+
+    private List<MetaProperty> getPlatformPropData() {
+        List<MetaProperty> metaPropertyList = Activator.getDefault()
+                .getResourceManager().getPlatformInfo();
+        return metaPropertyList;
+    }
+
+    private void updateViewer(List<MetaProperty> metaPropertyList) {
+        if (null != platformTblViewer) {
+            Table tbl = platformTblViewer.getTable();
+            if (null != metaPropertyList) {
+                platformTblViewer.setInput(metaPropertyList.toArray());
+                if (!tbl.isDisposed()) {
+                    tbl.setLinesVisible(true);
+                }
+            } else {
+                if (!tbl.isDisposed()) {
+                    tbl.removeAll();
+                    tbl.setLinesVisible(false);
+                }
+            }
+        }
+    }
+
+    class PropValueEditor extends EditingSupport {
+
+        private final TableViewer viewer;
+
+        public PropValueEditor(TableViewer viewer) {
+            super(viewer);
+            this.viewer = viewer;
+        }
+
+        @Override
+        protected boolean canEdit(Object element) {
+            return true;
+        }
+
+        @Override
+        protected CellEditor getCellEditor(Object element) {
+            if (!enable_edit) {
+                return null;
+            }
+            CellEditor editor = new TextCellEditor(viewer.getTable());
+            return editor;
+        }
+
+        @Override
+        protected Object getValue(Object element) {
+            return ((MetaProperty) element).getPropValue();
+        }
+
+        @Override
+        protected void setValue(Object element, Object value) {
+            MetaProperty prop = (MetaProperty) element;
+            prop.setPropValue(String.valueOf(value));
+            viewer.update(element, null);
+        }
+
+    }
+
+    @Override
+    public void setFocus() {
+    }
+}
\ No newline at end of file
index 8f8ff18..c8f6668 100644 (file)
@@ -19,57 +19,92 @@ package oic.simulator.serviceprovider.view;
 import java.util.List;
 
 import oic.simulator.serviceprovider.Activator;
-import oic.simulator.serviceprovider.listener.IResourceSelectionChangedUIListener;
+import oic.simulator.serviceprovider.listener.ISelectionChangedUIListener;
 import oic.simulator.serviceprovider.manager.ResourceManager;
-import oic.simulator.serviceprovider.resource.MetaProperty;
-import oic.simulator.serviceprovider.resource.SimulatorResource;
-
+import oic.simulator.serviceprovider.manager.UiListenerHandler;
+import oic.simulator.serviceprovider.model.Device;
+import oic.simulator.serviceprovider.model.MetaProperty;
+import oic.simulator.serviceprovider.model.Resource;
+import oic.simulator.serviceprovider.utils.Constants;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.CellEditor;
 import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.EditingSupport;
 import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.StyledCellLabelProvider;
 import org.eclipse.jface.viewers.TableViewer;
 import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.TextCellEditor;
 import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerCell;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Table;
 import org.eclipse.ui.part.ViewPart;
+import org.oic.simulator.SimulatorException;
 
 /**
  * This class manages and shows the meta properties view in the perspective.
  */
 public class MetaPropertiesView extends ViewPart {
 
-    public static final String                  VIEW_ID       = "oic.simulator.serviceprovider.view.metaproperties";
+    public static final String          VIEW_ID       = "oic.simulator.serviceprovider.view.metaproperties";
+
+    private TableViewer                 tableViewer;
+
+    private final String[]              columnHeaders = { "Property", "Value" };
 
-    private TableViewer                         tableViewer;
+    private final Integer[]             columnWidth   = { 150, 150 };
 
-    private final String[]                      columnHeaders = { "Property",
-            "Value"                                          };
+    private ISelectionChangedUIListener resourceSelectionChangedListener;
 
-    private final Integer[]                     columnWidth   = { 150, 150 };
+    private ResourceManager             resourceManagerRef;
 
-    private IResourceSelectionChangedUIListener resourceSelectionChangedListener;
+    private List<MetaProperty>          properties;
 
-    private ResourceManager                     resourceManagerRef;
+    private boolean                     enable_edit;
+    private Button                      editBtn;
+    private Button                      cancelBtn;
 
     public MetaPropertiesView() {
 
         resourceManagerRef = Activator.getDefault().getResourceManager();
 
-        resourceSelectionChangedListener = new IResourceSelectionChangedUIListener() {
+        resourceSelectionChangedListener = new ISelectionChangedUIListener() {
 
             @Override
-            public void onResourceSelectionChange() {
+            public void onResourceSelectionChange(final Resource resource) {
                 Display.getDefault().asyncExec(new Runnable() {
 
                     @Override
                     public void run() {
                         if (null != tableViewer) {
-                            updateViewer(getData());
+                            properties = getData(resource);
+                            updateViewer(properties);
                         }
+                        updateEditControls(resource);
+                    }
+                });
+            }
+
+            @Override
+            public void onDeviceSelectionChange(final Device dev) {
+                Display.getDefault().asyncExec(new Runnable() {
+
+                    @Override
+                    public void run() {
+                        if (null != tableViewer) {
+                            properties = getData(dev);
+                            updateViewer(properties);
+                        }
+                        updateEditControls(dev);
                     }
                 });
             }
@@ -77,8 +112,8 @@ public class MetaPropertiesView extends ViewPart {
     }
 
     @Override
-    public void createPartControl(Composite parent) {
-        parent.setLayout(new GridLayout(1, false));
+    public void createPartControl(final Composite parent) {
+        parent.setLayout(new GridLayout(2, false));
 
         tableViewer = new TableViewer(parent, SWT.SINGLE | SWT.H_SCROLL
                 | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
@@ -87,28 +122,211 @@ public class MetaPropertiesView extends ViewPart {
 
         // Make lines and header visible
         final Table table = tableViewer.getTable();
-        table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        gd.horizontalSpan = 2;
+        table.setLayoutData(gd);
         table.setHeaderVisible(true);
         table.setLinesVisible(true);
 
         tableViewer.setContentProvider(new PropertycontentProvider());
 
+        editBtn = new Button(parent, SWT.PUSH);
+        editBtn.setText("Edit");
+        gd = new GridData();
+        gd.widthHint = 50;
+        editBtn.setLayoutData(gd);
+        editBtn.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                if (editBtn.getText().equals("Edit")) {
+                    cancelBtn.setEnabled(true);
+                    editBtn.setText("Save");
+                    enable_edit = true;
+                } else {
+                    boolean result = false;
+                    Resource resourceInSelection = resourceManagerRef
+                            .getCurrentResourceInSelection();
+                    if (null != resourceInSelection) {
+
+                        // Null Check
+                        result = resourceManagerRef.isPropertyValueInvalid(
+                                resourceInSelection, properties,
+                                Constants.RESOURCE_URI);
+                        if (result) {
+                            MessageDialog.openError(parent.getShell(),
+                                    "Invalid Input", "Resource URI is invalid.");
+                            return;
+                        }
+
+                        result = resourceManagerRef.isPropertyValueInvalid(
+                                resourceInSelection, properties,
+                                Constants.RESOURCE_NAME);
+                        if (result) {
+                            MessageDialog.openError(parent.getShell(),
+                                    "Invalid Input",
+                                    "Resource Name is invalid.");
+                            return;
+                        }
+
+                        boolean update = false;
+                        boolean uriChange = false;
+                        boolean nameChange = false;
+                        if (resourceManagerRef.isPropValueChanged(
+                                resourceInSelection, properties,
+                                Constants.RESOURCE_NAME)) {
+                            update = true;
+                            nameChange = true;
+                        }
+                        if (resourceManagerRef.isPropValueChanged(
+                                resourceInSelection, properties,
+                                Constants.RESOURCE_URI)) {
+                            // Check whether the new URI is unique.
+                            if (!resourceManagerRef.isUriUnique(properties)) {
+                                MessageDialog.openError(parent.getShell(),
+                                        "Resource URI in use",
+                                        "Resource URI is in use. Please try a different URI.");
+                                return;
+                            }
+
+                            update = true;
+                            uriChange = true;
+
+                            if (resourceManagerRef
+                                    .isResourceStarted(resourceInSelection)) {
+                                update = MessageDialog.openQuestion(
+                                        parent.getShell(), "Save Details",
+                                        "Resource will be restarted to take the changes."
+                                                + " Do you want to continue?");
+                                if (!update) {
+                                    return;
+                                }
+                            }
+                        }
+                        if (update) {
+                            try {
+                                result = Activator
+                                        .getDefault()
+                                        .getResourceManager()
+                                        .updateResourceProperties(
+                                                resourceManagerRef
+                                                        .getCurrentResourceInSelection(),
+                                                properties, uriChange,
+                                                nameChange);
+                            } catch (SimulatorException ex) {
+                                result = false;
+                            }
+                            if (result) {
+                                MessageDialog.openInformation(
+                                        parent.getShell(), "Operation status",
+                                        "Resource properties updated.");
+                            } else {
+                                MessageDialog.openInformation(
+                                        parent.getShell(), "Operation status",
+                                        "Failed to update the resource properties.");
+
+                                // Reset the old property values.
+                                properties = getData(resourceManagerRef
+                                        .getCurrentResourceInSelection());
+                                updateViewer(properties);
+                            }
+                        }
+                    } else {
+                        Device dev = resourceManagerRef
+                                .getCurrentDeviceInSelection();
+
+                        // Null check
+                        result = resourceManagerRef.isPropertyValueInvalid(dev,
+                                properties, Constants.DEVICE_NAME);
+                        if (result) {
+                            MessageDialog.openError(parent.getShell(),
+                                    "Invalid Input", "Device Name is invalid.");
+                            return;
+                        }
+
+                        if (resourceManagerRef.isPropValueChanged(dev,
+                                properties, Constants.DEVICE_NAME)) {
+                            resourceManagerRef.updateDeviceProperties(dev,
+                                    properties);
+                        }
+
+                    }
+                    cancelBtn.setEnabled(false);
+                    editBtn.setText("Edit");
+                    enable_edit = false;
+                }
+            }
+        });
+
+        cancelBtn = new Button(parent, SWT.PUSH);
+        cancelBtn.setText("Cancel");
+        cancelBtn.setEnabled(false);
+        gd = new GridData();
+        gd.widthHint = 70;
+        cancelBtn.setLayoutData(gd);
+        cancelBtn.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                Resource res = resourceManagerRef
+                        .getCurrentResourceInSelection();
+                if (null != res) {
+                    properties = getData(res);
+                } else {
+                    Device dev = resourceManagerRef
+                            .getCurrentDeviceInSelection();
+                    if (null != dev) {
+                        properties = getData(dev);
+                    }
+                }
+                updateViewer(properties);
+
+                cancelBtn.setEnabled(false);
+                editBtn.setText("Edit");
+                enable_edit = false;
+            }
+        });
+
         addManagerListeners();
 
         // Check whether there is any resource selected already
-        List<MetaProperty> propertyList = getData();
-        if (null != propertyList) {
-            updateViewer(propertyList);
+        Resource resource = resourceManagerRef.getCurrentResourceInSelection();
+        properties = getData(resource);
+        if (null != properties) {
+            updateViewer(properties);
         }
+        updateEditControls(resource);
+    }
 
+    private void updateEditControls(Object obj) {
+        if (!editBtn.isDisposed() && !cancelBtn.isDisposed()) {
+
+            if (editBtn.getText().equals("Save")) {
+                editBtn.setText("Edit");
+                enable_edit = false;
+            }
+
+            if (null == obj) {
+                editBtn.setEnabled(false);
+            } else {
+                editBtn.setEnabled(true);
+            }
+            cancelBtn.setEnabled(false);
+        }
+    }
+
+    private List<MetaProperty> getData(Resource resource) {
+        if (null != resource) {
+            List<MetaProperty> metaPropertyList = resourceManagerRef
+                    .getMetaProperties(resource);
+            return metaPropertyList;
+        } else {
+            return null;
+        }
     }
 
-    private List<MetaProperty> getData() {
-        SimulatorResource resourceInSelection = resourceManagerRef
-                .getCurrentResourceInSelection();
-        if (null != resourceInSelection) {
+    private List<MetaProperty> getData(Device dev) {
+        if (null != dev) {
             List<MetaProperty> metaPropertyList = resourceManagerRef
-                    .getMetaProperties(resourceInSelection);
+                    .getMetaProperties(dev);
             return metaPropertyList;
         } else {
             return null;
@@ -137,15 +355,12 @@ public class MetaPropertiesView extends ViewPart {
                 SWT.NONE);
         propName.getColumn().setWidth(columnWidth[0]);
         propName.getColumn().setText(columnHeaders[0]);
-        propName.setLabelProvider(new ColumnLabelProvider() {
+        propName.setLabelProvider(new StyledCellLabelProvider() {
             @Override
-            public String getText(Object element) {
-                MetaProperty prop = (MetaProperty) element;
-                if (null != prop) {
-                    return prop.getPropName();
-                } else {
-                    return "";
-                }
+            public void update(ViewerCell cell) {
+                MetaProperty prop = (MetaProperty) cell.getElement();
+                cell.setText(prop.getPropName());
+                super.update(cell);
             }
         });
 
@@ -164,11 +379,12 @@ public class MetaPropertiesView extends ViewPart {
                 }
             }
         });
+        propValue.setEditingSupport(new PropValueEditor(tableViewer));
     }
 
     private void addManagerListeners() {
-        resourceManagerRef
-                .addResourceSelectionChangedUIListener(resourceSelectionChangedListener);
+        UiListenerHandler.getInstance().addResourceSelectionChangedUIListener(
+                resourceSelectionChangedListener);
     }
 
     class PropertycontentProvider implements IStructuredContentProvider {
@@ -185,19 +401,61 @@ public class MetaPropertiesView extends ViewPart {
         public Object[] getElements(Object element) {
             return (Object[]) element;
         }
-
     }
 
     @Override
     public void dispose() {
         // Unregister the listener
         if (null != resourceSelectionChangedListener) {
-            resourceManagerRef
-                    .removeResourceSelectionChangedUIListener(resourceSelectionChangedListener);
+            UiListenerHandler.getInstance()
+                    .removeResourceSelectionChangedUIListener(
+                            resourceSelectionChangedListener);
         }
         super.dispose();
     }
 
+    class PropValueEditor extends EditingSupport {
+
+        private final TableViewer viewer;
+
+        public PropValueEditor(TableViewer viewer) {
+            super(viewer);
+            this.viewer = viewer;
+        }
+
+        @Override
+        protected boolean canEdit(Object element) {
+            return true;
+        }
+
+        @Override
+        protected CellEditor getCellEditor(Object element) {
+            if (!enable_edit) {
+                return null;
+            }
+            // Disabling edit for resource type
+            String propName = ((MetaProperty) element).getPropName();
+            if (null != propName && propName.equals(Constants.RESOURCE_TYPE)) {
+                return null;
+            }
+            CellEditor editor = new TextCellEditor(viewer.getTable());
+            return editor;
+        }
+
+        @Override
+        protected Object getValue(Object element) {
+            return ((MetaProperty) element).getPropValue();
+        }
+
+        @Override
+        protected void setValue(Object element, Object value) {
+            MetaProperty prop = (MetaProperty) element;
+            prop.setPropValue(String.valueOf(value));
+            viewer.update(element, null);
+        }
+
+    }
+
     @Override
     public void setFocus() {
     }
index a09fa4a..6585b60 100644 (file)
@@ -18,24 +18,45 @@ package oic.simulator.serviceprovider.view;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Set;
 
 import oic.simulator.serviceprovider.Activator;
+import oic.simulator.serviceprovider.listener.IPropertiesChangedUIListener;
 import oic.simulator.serviceprovider.listener.IResourceListChangedUIListener;
 import oic.simulator.serviceprovider.manager.ResourceManager;
-import oic.simulator.serviceprovider.resource.DeleteCategory;
+import oic.simulator.serviceprovider.manager.UiListenerHandler;
+import oic.simulator.serviceprovider.model.AutomationSettingHelper;
+import oic.simulator.serviceprovider.model.CollectionResource;
+import oic.simulator.serviceprovider.model.Device;
+import oic.simulator.serviceprovider.model.Resource;
+import oic.simulator.serviceprovider.model.ResourceType;
+import oic.simulator.serviceprovider.model.SingleResource;
 import oic.simulator.serviceprovider.utils.Constants;
 import oic.simulator.serviceprovider.utils.Utility;
+import oic.simulator.serviceprovider.view.dialogs.AddResourceToCollections;
+import oic.simulator.serviceprovider.view.dialogs.AddResourceToDevices;
+import oic.simulator.serviceprovider.view.dialogs.AddResources;
+import oic.simulator.serviceprovider.view.dialogs.AutomationSettingDialog;
 import oic.simulator.serviceprovider.view.dialogs.CreateResourceWizard;
 import oic.simulator.serviceprovider.view.dialogs.DeleteResourceWizard;
+import oic.simulator.serviceprovider.view.dialogs.RemoveResourceFromCollections;
+import oic.simulator.serviceprovider.view.dialogs.RemoveResourceFromDevices;
+import oic.simulator.serviceprovider.view.dialogs.RemoveResources;
 import oic.simulator.serviceprovider.view.dialogs.ResourceWizardDialog;
 
 import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.ITreeContentProvider;
 import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
 import org.eclipse.jface.viewers.TreeViewer;
 import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.window.Window;
 import org.eclipse.jface.wizard.WizardDialog;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CTabFolder;
+import org.eclipse.swt.custom.CTabItem;
 import org.eclipse.swt.events.MenuAdapter;
 import org.eclipse.swt.events.MenuEvent;
 import org.eclipse.swt.events.SelectionAdapter;
@@ -56,6 +77,8 @@ import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.dialogs.FilteredTree;
 import org.eclipse.ui.dialogs.PatternFilter;
 import org.eclipse.ui.part.ViewPart;
+import org.oic.simulator.SimulatorException;
+import org.oic.simulator.server.SimulatorResource.AutoUpdateType;
 
 /**
  * This class manages and shows the resource manager view in the perspective.
@@ -67,10 +90,19 @@ public class ResourceManagerView extends ViewPart {
     private Button                         createButton;
     private Button                         deleteButton;
 
-    private TreeViewer                     treeViewer;
+    private TreeViewer                     singleResTreeViewer;
+    private TreeViewer                     collectionResTreeViewer;
+    private TreeViewer                     deviceTreeViewer;
+
+    private CTabFolder                     folder;
+    private CTabItem                       singleResTab;
+    private CTabItem                       collectionResTab;
+    private CTabItem                       deviceTab;
 
     private IResourceListChangedUIListener resourceListChangedListener;
 
+    private IPropertiesChangedUIListener   resourcePropertiesChangedListener;
+
     private ResourceManager                resourceManager;
 
     public ResourceManagerView() {
@@ -80,13 +112,23 @@ public class ResourceManagerView extends ViewPart {
         resourceListChangedListener = new IResourceListChangedUIListener() {
 
             @Override
-            public void onResourceCreation() {
+            public void onResourceCreation(final ResourceType type) {
                 Display.getDefault().asyncExec(new Runnable() {
 
                     @Override
                     public void run() {
-                        if (null != treeViewer) {
-                            treeViewer.refresh();
+                        if (type == ResourceType.SINGLE) {
+                            if (null != singleResTreeViewer) {
+                                singleResTreeViewer.refresh();
+                            }
+                        } else if (type == ResourceType.COLLECTION) {
+                            if (null != collectionResTreeViewer) {
+                                collectionResTreeViewer.refresh();
+                            }
+                        } else {
+                            if (null != deviceTreeViewer) {
+                                deviceTreeViewer.refresh();
+                            }
                         }
 
                         // Trigger the visibility of delete button
@@ -96,34 +138,86 @@ public class ResourceManagerView extends ViewPart {
             }
 
             @Override
-            public void onResourceDeletion() {
+            public void onResourceDeletion(final ResourceType type) {
                 Display.getDefault().asyncExec(new Runnable() {
 
                     @Override
                     public void run() {
-                        if (null != treeViewer) {
-                            treeViewer.refresh();
+                        if (null != singleResTreeViewer
+                                && null != collectionResTreeViewer
+                                && null != deviceTreeViewer) {
+                            switch (type) {
+                                case SINGLE:
+                                    singleResTreeViewer.refresh();
+                                case COLLECTION:
+                                    collectionResTreeViewer.refresh();
+                                default:
+                                    deviceTreeViewer.refresh();
+                            }
                         }
-
                         // Trigger the visibility of delete button
                         changeDeleteVisibility();
                     }
                 });
             }
+
+            @Override
+            public void onResourceListUpdate(final ResourceType type) {
+                Display.getDefault().asyncExec(new Runnable() {
+
+                    @Override
+                    public void run() {
+                        if (null != singleResTreeViewer
+                                && null != collectionResTreeViewer
+                                && null != deviceTreeViewer) {
+                            switch (type) {
+                                case SINGLE:
+                                    singleResTreeViewer.refresh();
+                                case COLLECTION:
+                                    collectionResTreeViewer.refresh();
+                                default:
+                                    deviceTreeViewer.refresh();
+                            }
+                        }
+                    }
+                });
+            }
+        };
+
+        resourcePropertiesChangedListener = new IPropertiesChangedUIListener() {
+
+            @Override
+            public void onResourcePropertyChange() {
+                Display.getDefault().asyncExec(new Runnable() {
+                    @Override
+                    public void run() {
+                        if (null != singleResTreeViewer
+                                && null != collectionResTreeViewer
+                                && null != deviceTreeViewer) {
+                            singleResTreeViewer.refresh();
+                            collectionResTreeViewer.refresh();
+                            deviceTreeViewer.refresh();
+                        }
+                    }
+                });
+            }
+
+            @Override
+            public void onDevicePropertyChange() {
+                Display.getDefault().asyncExec(new Runnable() {
+                    @Override
+                    public void run() {
+                        if (null != deviceTreeViewer) {
+                            deviceTreeViewer.refresh();
+                        }
+                    }
+                });
+            }
         };
     }
 
     public void changeDeleteVisibility() {
-        if (null == treeViewer) {
-            return;
-        }
-        boolean visibility;
-        Tree tree = treeViewer.getTree();
-        if (null != tree && !tree.isDisposed() && tree.getItemCount() > 0) {
-            visibility = true;
-        } else {
-            visibility = false;
-        }
+        boolean visibility = resourceManager.isAnyResourceExist();
         if (null != deleteButton && !deleteButton.isDisposed()) {
             deleteButton.setEnabled(visibility);
         }
@@ -163,135 +257,883 @@ public class ResourceManagerView extends ViewPart {
         gd.widthHint = 90;
         deleteButton.setLayoutData(gd);
 
-        Group resourceGroup = new Group(compContent, SWT.NONE);
-        resourceGroup.setText("Created Resources");
+        // Create a Tab Folder.
+        folder = new CTabFolder(compContent, SWT.BORDER);
+        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        folder.setLayoutData(gd);
+        folder.setSimple(false);
+        folder.setUnselectedCloseVisible(false);
+        folder.setUnselectedImageVisible(false);
+        folder.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                // Tab is switched.
+                singleResTreeViewer.setSelection(null);
+                collectionResTreeViewer.setSelection(null);
+                deviceTreeViewer.setSelection(null);
+                resourceManager.resourceSelectionChanged(null);
+            }
+        });
+
+        createSimpleResourcesArea();
+
+        createCollectionResourcesArea();
+
+        createDeviceArea();
+
+        folder.setSelection(singleResTab);
+
+        addUIListeners();
+
+        addManagerListeners();
+
+        // If there is at least one resource exist, then enable the delete
+        // resource button
+        changeDeleteVisibility();
+    }
+
+    private void createSimpleResourcesArea() {
+        singleResTab = new CTabItem(folder, SWT.NULL);
+        singleResTab.setText("Single Resources");
+
+        // Create a group to show all the discovered resources.
+        // Adding the group to the folder.
+        Group resourceGroup = new Group(folder, SWT.NONE);
+        // resourceGroup.setText("Discovered Resources");
 
         Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
         resourceGroup.setBackground(color);
 
         resourceGroup.setLayout(new GridLayout(1, false));
-        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
         resourceGroup.setLayoutData(gd);
 
         PatternFilter filter = new PatternFilter();
         FilteredTree filteredTree = new FilteredTree(resourceGroup,
                 SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE, filter, true);
-        treeViewer = filteredTree.getViewer();
-        treeViewer.getTree().setLayoutData(
+        singleResTreeViewer = filteredTree.getViewer();
+        singleResTreeViewer.getTree().setLayoutData(
                 new GridData(SWT.FILL, SWT.FILL, true, true));
-        treeViewer.setContentProvider(new TreeContentProvider());
-        treeViewer.setLabelProvider(new TreeLabelProvider());
-        treeViewer.setInput(new Object());
+        singleResTreeViewer
+                .setContentProvider(new SingleResourceContentProvider());
+        singleResTreeViewer.setLabelProvider(new TreeLabelProvider());
+        singleResTreeViewer.setInput(new Object());
 
-        addUIListeners();
+        singleResTreeViewer
+                .addSelectionChangedListener(new ISelectionChangedListener() {
+                    @Override
+                    public void selectionChanged(SelectionChangedEvent e) {
+                        IStructuredSelection selection = (IStructuredSelection) e
+                                .getSelection();
+                        if (null == selection) {
+                            return;
+                        }
 
-        addManagerListeners();
+                        Resource res = null;
+                        int size = selection.size();
+                        if (size == 1) {
+                            res = (Resource) selection.getFirstElement();
+                        }
+                        resourceManager.resourceSelectionChanged(res);
+                    }
+                });
 
-        // If there is at least one resource exist, then enable the delete
-        // resource button
-        changeDeleteVisibility();
+        // TODO: Add menu items
+        addMenuToSimpleResources();
+
+        singleResTab.setControl(resourceGroup);
     }
 
-    private void addUIListeners() {
+    private void addMenuToSimpleResources() {
+        if (null != singleResTreeViewer) {
+            final Tree resourceTreeHead = singleResTreeViewer.getTree();
+            if (null != resourceTreeHead) {
+                // Below code creates menu entries and shows them on right
+                // clicking a resource
+                final Menu menu = new Menu(resourceTreeHead);
+                resourceTreeHead.setMenu(menu);
+                menu.addMenuListener(new MenuAdapter() {
+                    @Override
+                    public void menuShown(MenuEvent e) {
+                        // Clear existing menu items
+                        MenuItem[] items = menu.getItems();
+                        for (int index = 0; index < items.length; index++) {
+                            items[index].dispose();
+                        }
 
-        createButton.addSelectionListener(new SelectionAdapter() {
-            @Override
-            public void widgetSelected(SelectionEvent e) {
-                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
+                        IStructuredSelection selection = ((IStructuredSelection) singleResTreeViewer
+                                .getSelection());
+                        final SingleResource resource = (SingleResource) selection
+                                .getFirstElement();
+                        if (null == resource) {
+                            return;
+                        }
+
+                        addAutomationMenu(menu, resource);
+
+                        // Menu to add resource to one or more collections.
+                        MenuItem addToCollection = new MenuItem(menu, SWT.NONE);
+                        addToCollection.setText("Add to Collection");
+                        addToCollection
+                                .addSelectionListener(new SelectionAdapter() {
+                                    @Override
+                                    public void widgetSelected(SelectionEvent e) {
+                                        List<CollectionResource> possibleCollections;
+                                        possibleCollections = resourceManager
+                                                .getCollectionsForAddingToSingleResource(resource);
+                                        if (null == possibleCollections
+                                                || possibleCollections
+                                                        .isEmpty()) {
+                                            MessageDialog
+                                                    .openError(
+                                                            Display.getDefault()
+                                                                    .getActiveShell(),
+                                                            "No possible candidates",
+                                                            "There are no possible collections to which the resource can be added.");
+                                            return;
+                                        }
+
+                                        AddResourceToCollections addToCollectionsDlg = new AddResourceToCollections(
+                                                Display.getDefault()
+                                                        .getActiveShell(),
+                                                possibleCollections);
+                                        if (addToCollectionsDlg.open() != Window.OK) {
+                                            return;
+                                        }
+
+                                        Set<CollectionResource> resultSet = addToCollectionsDlg
+                                                .getSelectedResourceList();
+
+                                        int addedCount = resourceManager
+                                                .addResourceToCollection(
+                                                        resultSet, resource);
+                                        if (addedCount <= 0) {
+                                            MessageDialog
+                                                    .openInformation(Display
+                                                            .getDefault()
+                                                            .getActiveShell(),
+                                                            "Operation failed",
+                                                            "Failed to add resources to the collection.");
+                                            return;
+                                        }
+
+                                        collectionResTreeViewer.refresh();
+
+                                        deviceTreeViewer.refresh();
+
+                                        MessageDialog.openInformation(
+                                                Display.getDefault()
+                                                        .getActiveShell(),
+                                                "Added",
+                                                "["
+                                                        + addedCount
+                                                        + "/"
+                                                        + resultSet.size()
+                                                        + "] added to selected collections");
+                                    }
+                                });
+
+                        // Menu to remove resource from one or more collections
+                        // to which it is a member.
+                        MenuItem removeFromCollection = new MenuItem(menu,
+                                SWT.NONE);
+                        removeFromCollection.setText("Remove from Collection");
+                        removeFromCollection
+                                .addSelectionListener(new SelectionAdapter() {
+                                    @Override
+                                    public void widgetSelected(SelectionEvent e) {
+                                        List<CollectionResource> possibleCollectionstoRemoveFrom;
+                                        possibleCollectionstoRemoveFrom = resourceManager
+                                                .getResourceReferences(resource);
+                                        if (null == possibleCollectionstoRemoveFrom
+                                                || possibleCollectionstoRemoveFrom
+                                                        .isEmpty()) {
+                                            MessageDialog
+                                                    .openError(
+                                                            Display.getDefault()
+                                                                    .getActiveShell(),
+                                                            "No possible candidates",
+                                                            "Resource has not been added to any collections.");
+                                            return;
+                                        }
+
+                                        RemoveResourceFromCollections removeFromCollectionsDlg = new RemoveResourceFromCollections(
+                                                Display.getDefault()
+                                                        .getActiveShell(),
+                                                possibleCollectionstoRemoveFrom);
+                                        if (removeFromCollectionsDlg.open() != Window.OK) {
+                                            return;
+                                        }
+
+                                        Set<CollectionResource> resultSet = removeFromCollectionsDlg
+                                                .getSelectedResourceList();
+
+                                        int removeCount = resourceManager
+                                                .removeResourceFromCollection(
+                                                        resultSet, resource);
+                                        if (removeCount <= 0) {
+                                            MessageDialog
+                                                    .openInformation(Display
+                                                            .getDefault()
+                                                            .getActiveShell(),
+                                                            "Operation failed",
+                                                            "Failed to remove resources from the collection.");
+                                            return;
+                                        }
+
+                                        collectionResTreeViewer.refresh();
+
+                                        deviceTreeViewer.refresh();
+
+                                        MessageDialog.openInformation(
+                                                Display.getDefault()
+                                                        .getActiveShell(),
+                                                "Removed",
+                                                "["
+                                                        + removeCount
+                                                        + "/"
+                                                        + resultSet.size()
+                                                        + "] resource removed from selected collections");
+                                    }
+                                });
+
+                        // Menu to add resource to one or more devices.
+                        MenuItem addToDevice = new MenuItem(menu, SWT.NONE);
+                        addToDevice.setText("Add to Device");
+                        addToDevice
+                                .addSelectionListener(new SelectionAdapter() {
+                                    @Override
+                                    public void widgetSelected(SelectionEvent e) {
+                                        List<Device> possibleDevices;
+                                        possibleDevices = resourceManager
+                                                .getDevicesForAddingToResource(resource);
+                                        if (null == possibleDevices
+                                                || possibleDevices.isEmpty()) {
+                                            MessageDialog
+                                                    .openError(
+                                                            Display.getDefault()
+                                                                    .getActiveShell(),
+                                                            "No possible candidates",
+                                                            "There are no possible devices to which the resource can be added.");
+                                            return;
+                                        }
+
+                                        AddResourceToDevices addToDevicesDlg = new AddResourceToDevices(
+                                                Display.getDefault()
+                                                        .getActiveShell(),
+                                                possibleDevices);
+                                        if (addToDevicesDlg.open() != Window.OK) {
+                                            return;
+                                        }
+
+                                        Set<Device> resultSet = addToDevicesDlg
+                                                .getSelectedDeviceList();
+
+                                        resourceManager.addResourceToDevice(
+                                                resultSet, resource);
+
+                                        deviceTreeViewer.refresh();
+
+                                        MessageDialog
+                                                .openInformation(Display
+                                                        .getDefault()
+                                                        .getActiveShell(),
+                                                        "Added",
+                                                        "Resource added to selected devices.");
+                                    }
+                                });
+
+                        // Menu to remove resource from one or more device to
+                        // which it is a member.
+                        MenuItem removeFromDevice = new MenuItem(menu, SWT.NONE);
+                        removeFromDevice.setText("Remove from Device");
+                        removeFromDevice
+                                .addSelectionListener(new SelectionAdapter() {
+                                    @Override
+                                    public void widgetSelected(SelectionEvent e) {
+                                        List<Device> possibleDevices;
+                                        possibleDevices = resourceManager
+                                                .getDeviceReferences(resource);
+                                        if (null == possibleDevices
+                                                || possibleDevices.isEmpty()) {
+                                            MessageDialog
+                                                    .openError(
+                                                            Display.getDefault()
+                                                                    .getActiveShell(),
+                                                            "No possible candidates",
+                                                            "Resource has not been added to any devices.");
+                                            return;
+                                        }
+
+                                        RemoveResourceFromDevices removeFromDevicesDlg = new RemoveResourceFromDevices(
+                                                Display.getDefault()
+                                                        .getActiveShell(),
+                                                possibleDevices);
+                                        if (removeFromDevicesDlg.open() != Window.OK) {
+                                            return;
+                                        }
+
+                                        Set<Device> resultSet = removeFromDevicesDlg
+                                                .getSelectedDeviceList();
+
+                                        resourceManager
+                                                .removeResourceFromDevice(
+                                                        resultSet, resource);
+
+                                        deviceTreeViewer.refresh();
 
+                                        MessageDialog
+                                                .openInformation(Display
+                                                        .getDefault()
+                                                        .getActiveShell(),
+                                                        "Removed",
+                                                        "Resource removed from selected devices");
+                                    }
+                                });
+
+                        // Menu to remove resource from one or more device to
+                        // which it is a member.
+                        MenuItem deleteResource = new MenuItem(menu, SWT.NONE);
+                        deleteResource.setText("Delete");
+                        deleteResource
+                                .addSelectionListener(new SelectionAdapter() {
+                                    @Override
+                                    public void widgetSelected(SelectionEvent e) {
+                                        try {
+                                            resourceManager
+                                                    .removeResource(resource);
+                                            singleResTreeViewer.refresh();
+                                            // if(refreshCollectionTree)
+                                            collectionResTreeViewer.refresh();
+                                            // if(refreshDeviceTree)
+                                            deviceTreeViewer.refresh();
+                                            MessageDialog.openInformation(
+                                                    Display.getDefault()
+                                                            .getActiveShell(),
+                                                    "Deleted",
+                                                    "Resource deleted.");
+                                        } catch (SimulatorException e1) {
+                                            MessageDialog
+                                                    .openInformation(Display
+                                                            .getDefault()
+                                                            .getActiveShell(),
+                                                            "Deletion Failed",
+                                                            "Failed to delete the resource.");
+                                        }
+                                        changeDeleteVisibility();
+                                    }
+                                });
+                    }
+                });
+            }
+        }
+    }
+
+    private void createCollectionResourcesArea() {
+        collectionResTab = new CTabItem(folder, SWT.NULL);
+        collectionResTab.setText("Collection Resources");
+
+        // Create a group to show all the discovered resources.
+        // Adding the group to the folder.
+        Group resourceGroup = new Group(folder, SWT.NONE);
+        // resourceGroup.setText("Discovered Resources");
+
+        Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
+        resourceGroup.setBackground(color);
+
+        resourceGroup.setLayout(new GridLayout(1, false));
+        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        resourceGroup.setLayoutData(gd);
+
+        PatternFilter filter = new PatternFilter();
+        FilteredTree filteredTree = new FilteredTree(resourceGroup,
+                SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE, filter, true);
+        collectionResTreeViewer = filteredTree.getViewer();
+        collectionResTreeViewer.getTree().setLayoutData(
+                new GridData(SWT.FILL, SWT.FILL, true, true));
+        collectionResTreeViewer
+                .setContentProvider(new CollectionResourceContentProvider());
+        collectionResTreeViewer.setLabelProvider(new TreeLabelProvider());
+        collectionResTreeViewer.setInput(new Object());
+
+        collectionResTreeViewer
+                .addSelectionChangedListener(new ISelectionChangedListener() {
                     @Override
-                    public void run() {
-                        CreateResourceWizard createWizard = new CreateResourceWizard();
-                        ResourceWizardDialog wizardDialog = new ResourceWizardDialog(
-                                PlatformUI.getWorkbench().getDisplay()
-                                        .getActiveShell(), createWizard);
-                        int open = wizardDialog.open();
-                        if (open == WizardDialog.OK) {
-                            String configFilePath;
-                            int count;
-                            configFilePath = createWizard.getConfigFilePath();
-                            System.out.println("Resultant config file path is "
-                                    + configFilePath);
-                            count = createWizard.getResourceCount();
-                            if (count > 0) {
-                                if (count == 1) {
-                                    // Single resource creation
-                                    resourceManager
-                                            .createResource(configFilePath);
-                                } else {
-                                    // Multi-resource creation
-                                    resourceManager.createResource(
-                                            configFilePath, count);
-                                }
+                    public void selectionChanged(SelectionChangedEvent e) {
+                        IStructuredSelection selection = (IStructuredSelection) e
+                                .getSelection();
+                        if (null == selection) {
+                            return;
+                        }
+
+                        Resource res = null;
+                        int size = selection.size();
+                        if (size == 1) {
+                            res = (Resource) selection.getFirstElement();
+                        }
+                        resourceManager.resourceSelectionChanged(res);
+                    }
+                });
+
+        // TODO: Add menu items
+        addMenuToCollectionResources();
+
+        collectionResTab.setControl(resourceGroup);
+    }
+
+    private void addMenuToCollectionResources() {
+        if (null != collectionResTreeViewer) {
+            final Tree resourceTreeHead = collectionResTreeViewer.getTree();
+            if (null != resourceTreeHead) {
+                // Below code creates menu entries and shows them on right
+                // clicking a resource
+                final Menu menu = new Menu(resourceTreeHead);
+                resourceTreeHead.setMenu(menu);
+                menu.addMenuListener(new MenuAdapter() {
+                    @Override
+                    public void menuShown(MenuEvent e) {
+                        // Clear existing menu items
+                        MenuItem[] items = menu.getItems();
+                        for (int index = 0; index < items.length; index++) {
+                            items[index].dispose();
+                        }
+
+                        IStructuredSelection selection = ((IStructuredSelection) collectionResTreeViewer
+                                .getSelection());
+                        final Resource resource = (Resource) selection
+                                .getFirstElement();
+                        TreeItem[] treeItems = resourceTreeHead.getSelection();
+                        if (null == resource || null == treeItems) {
+                            return;
+                        }
+
+                        final TreeItem parent = treeItems[0].getParentItem();
+                        if (null == parent) {
+                            System.out.println("No parent exist");
+                            // Selected item is a top-level collection
+                            addMenuToTopLevelCollectionResources(menu,
+                                    (CollectionResource) resource);
+                        } else {
+                            if (resource instanceof SingleResource)
+                                addAutomationMenu(menu,
+                                        (SingleResource) resource);
+
+                            MenuItem remFromParent = new MenuItem(menu,
+                                    SWT.NONE);
+                            remFromParent.setText("Remove from Parent");
+                            remFromParent
+                                    .addSelectionListener(new SelectionAdapter() {
+                                        @Override
+                                        public void widgetSelected(
+                                                SelectionEvent e) {
+                                            CollectionResource parentCollection = (CollectionResource) parent
+                                                    .getData();
+                                            String status;
+                                            try {
+                                                resourceManager
+                                                        .removeResourceFromCollection(
+                                                                parentCollection,
+                                                                resource);
+                                                collectionResTreeViewer
+                                                        .refresh();
+                                                deviceTreeViewer.refresh();
+
+                                                status = "Resource removed from its parent";
+                                            } catch (SimulatorException e1) {
+                                                status = "Failed to remove the resource from its parent";
+                                            }
+                                            MessageDialog.openInformation(
+                                                    Display.getDefault()
+                                                            .getActiveShell(),
+                                                    "Status", status);
+                                        }
+                                    });
+
+                            if (resource instanceof SingleResource) {
+                                // Menu Items for single resource will be added
+                                // here.
                             }
                         }
                     }
                 });
             }
+        }
+    }
+
+    private void addMenuToTopLevelCollectionResources(final Menu menu,
+            final CollectionResource colRes) {
+        // Menu to add one or more resources to the collection.
+        MenuItem addResources = new MenuItem(menu, SWT.CASCADE);
+        addResources.setText("Add Resources");
+
+        Menu addSubMenu = new Menu(menu);
+        addResources.setMenu(addSubMenu);
+
+        MenuItem simpleResources = new MenuItem(addSubMenu, SWT.NONE);
+        simpleResources.setText("Single");
+        simpleResources.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                List<SingleResource> possibleResources;
+                possibleResources = resourceManager
+                        .getSingleTypeResourcesForAddingToCollectionResource(colRes);
+                if (null == possibleResources || possibleResources.isEmpty()) {
+                    MessageDialog
+                            .openError(Display.getDefault().getActiveShell(),
+                                    "No possible candidates",
+                                    "There are no possible single resources that can be added.");
+                    return;
+                }
+
+                List<Resource> resources = Utility
+                        .convertSingleTypeResourceListToBaseType(possibleResources);
+
+                AddResources addToCollectionsDlg = new AddResources(Display
+                        .getDefault().getActiveShell(), resources);
+                if (addToCollectionsDlg.open() != Window.OK) {
+                    return;
+                }
+
+                Set<Resource> resultSet = addToCollectionsDlg
+                        .getSelectedResourceList();
+
+                int addedCount = resourceManager.addResourceToCollection(
+                        colRes, resultSet);
+                if (addedCount <= 0) {
+                    MessageDialog.openInformation(Display.getDefault()
+                            .getActiveShell(), "Operation failed",
+                            "Failed to add resources to the collection.");
+                    return;
+                }
+
+                collectionResTreeViewer.refresh();
+
+                deviceTreeViewer.refresh();
+
+                MessageDialog.openInformation(Display.getDefault()
+                        .getActiveShell(), "Added", "[" + addedCount + "/"
+                        + resultSet.size()
+                        + "] resources added to the collection");
+            }
         });
 
-        deleteButton.addSelectionListener(new SelectionAdapter() {
+        MenuItem collectionResources = new MenuItem(addSubMenu, SWT.NONE);
+        collectionResources.setText("Collection");
+        collectionResources.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
-                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
+                List<CollectionResource> possibleResources;
+                possibleResources = resourceManager
+                        .getCollectionTypeResourcesForAddingToCollectionResource(colRes);
+                if (null == possibleResources || possibleResources.isEmpty()) {
+                    MessageDialog
+                            .openError(Display.getDefault().getActiveShell(),
+                                    "No possible candidates",
+                                    "There are no possible collections that can be added.");
+                    return;
+                }
+
+                List<Resource> resources = Utility
+                        .convertCollectionTypeResourceListToBaseType(possibleResources);
+
+                AddResources addToCollectionsDlg = new AddResources(Display
+                        .getDefault().getActiveShell(), resources);
+                if (addToCollectionsDlg.open() != Window.OK) {
+                    return;
+                }
+
+                Set<Resource> resultSet = addToCollectionsDlg
+                        .getSelectedResourceList();
+
+                int addedCount = resourceManager.addResourceToCollection(
+                        colRes, resultSet);
+                if (addedCount <= 0) {
+                    MessageDialog.openInformation(Display.getDefault()
+                            .getActiveShell(), "Operation failed",
+                            "Failed to add resources to the collection.");
+                    return;
+                }
+
+                collectionResTreeViewer.refresh();
+
+                deviceTreeViewer.refresh();
+
+                MessageDialog.openInformation(Display.getDefault()
+                        .getActiveShell(), "Added", "[" + addedCount + "/"
+                        + resultSet.size()
+                        + "] resources added to the collection");
+            }
+        });
+
+        // Menu to remove one or more resources from the collection.
+        MenuItem removeResources = new MenuItem(menu, SWT.CASCADE);
+        removeResources.setText("Remove Resources");
+
+        Menu removeSubMenu = new Menu(menu);
+        removeResources.setMenu(removeSubMenu);
+
+        simpleResources = new MenuItem(removeSubMenu, SWT.NONE);
+        simpleResources.setText("Single");
+        simpleResources.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                List<SingleResource> possibleResources;
+                possibleResources = resourceManager.getSingleTypeChilds(colRes);
+                if (null == possibleResources || possibleResources.isEmpty()) {
+                    MessageDialog
+                            .openError(Display.getDefault().getActiveShell(),
+                                    "No possible candidates",
+                                    "There are no possible single resources which can be removed.");
+                    return;
+                }
+
+                List<Resource> resources = Utility
+                        .convertSingleTypeResourceListToBaseType(possibleResources);
+
+                RemoveResources removeFromCollectionsDlg = new RemoveResources(
+                        Display.getDefault().getActiveShell(), resources);
+                if (removeFromCollectionsDlg.open() != Window.OK) {
+                    return;
+                }
+
+                Set<Resource> resultSet = removeFromCollectionsDlg
+                        .getSelectedResourceList();
+
+                int removeCount = resourceManager
+                        .removeResourcesFromCollection(colRes, resultSet);
+                if (removeCount <= 0) {
+                    MessageDialog.openInformation(Display.getDefault()
+                            .getActiveShell(), "Operation failed",
+                            "Failed to remove resources from the collection.");
+                    return;
+                }
+
+                collectionResTreeViewer.refresh();
+
+                deviceTreeViewer.refresh();
+
+                MessageDialog.openInformation(Display.getDefault()
+                        .getActiveShell(), "Removed", "[" + removeCount + "/"
+                        + resultSet.size()
+                        + "] resources removed from the collection");
+            }
+        });
+
+        collectionResources = new MenuItem(removeSubMenu, SWT.NONE);
+        collectionResources.setText("Collection");
+        collectionResources.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                List<CollectionResource> possibleResources;
+                possibleResources = resourceManager
+                        .getCollectionTypeChilds(colRes);
+                if (null == possibleResources || possibleResources.isEmpty()) {
+                    MessageDialog
+                            .openError(Display.getDefault().getActiveShell(),
+                                    "No possible candidates",
+                                    "There are no possible collections which can be removed.");
+                    return;
+                }
+
+                List<Resource> resources = Utility
+                        .convertCollectionTypeResourceListToBaseType(possibleResources);
+
+                RemoveResources removeFromCollectionsDlg = new RemoveResources(
+                        Display.getDefault().getActiveShell(), resources);
+                if (removeFromCollectionsDlg.open() != Window.OK) {
+                    return;
+                }
+
+                Set<Resource> resultSet = removeFromCollectionsDlg
+                        .getSelectedResourceList();
+
+                int removeCount = resourceManager
+                        .removeResourcesFromCollection(colRes, resultSet);
+                if (removeCount <= 0) {
+                    MessageDialog.openInformation(Display.getDefault()
+                            .getActiveShell(), "Operation failed",
+                            "Failed to remove resources from the collection.");
+                    return;
+                }
+
+                collectionResTreeViewer.refresh();
+
+                deviceTreeViewer.refresh();
+
+                MessageDialog.openInformation(Display.getDefault()
+                        .getActiveShell(), "Removed", "[" + removeCount + "/"
+                        + resultSet.size()
+                        + "] resources removed from the collection");
+            }
+        });
+
+        // Menu to add resource to one or more devices.
+        MenuItem addToDevice = new MenuItem(menu, SWT.NONE);
+        addToDevice.setText("Add to Device");
+        addToDevice.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                List<Device> possibleDevices;
+                possibleDevices = resourceManager
+                        .getDevicesForAddingToResource(colRes);
+                if (null == possibleDevices || possibleDevices.isEmpty()) {
+                    MessageDialog
+                            .openError(Display.getDefault().getActiveShell(),
+                                    "No possible candidates",
+                                    "There are no possible devices to which the resource can be added.");
+                    return;
+                }
+
+                AddResourceToDevices addToDevicesDlg = new AddResourceToDevices(
+                        Display.getDefault().getActiveShell(), possibleDevices);
+                if (addToDevicesDlg.open() != Window.OK) {
+                    return;
+                }
+
+                Set<Device> resultSet = addToDevicesDlg.getSelectedDeviceList();
+
+                resourceManager.addResourceToDevice(resultSet, colRes);
+
+                deviceTreeViewer.refresh();
+
+                MessageDialog.openInformation(Display.getDefault()
+                        .getActiveShell(), "Added",
+                        "Resource added to selected devices.");
+            }
+        });
 
+        // Menu to remove resource from one or more device to which it is a
+        // member.
+        MenuItem removeFromDevice = new MenuItem(menu, SWT.NONE);
+        removeFromDevice.setText("Remove from Device");
+        removeFromDevice.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                List<Device> possibleDevices;
+                possibleDevices = resourceManager.getDeviceReferences(colRes);
+                if (null == possibleDevices || possibleDevices.isEmpty()) {
+                    MessageDialog.openError(Display.getDefault()
+                            .getActiveShell(), "No possible candidates",
+                            "Resource has not been added to any devices.");
+                    return;
+                }
+
+                RemoveResourceFromDevices removeFromDevicesDlg = new RemoveResourceFromDevices(
+                        Display.getDefault().getActiveShell(), possibleDevices);
+                if (removeFromDevicesDlg.open() != Window.OK) {
+                    return;
+                }
+
+                Set<Device> resultSet = removeFromDevicesDlg
+                        .getSelectedDeviceList();
+
+                resourceManager.removeResourceFromDevice(resultSet, colRes);
+
+                deviceTreeViewer.refresh();
+
+                MessageDialog.openInformation(Display.getDefault()
+                        .getActiveShell(), "Removed",
+                        "Resource removed from selected devices");
+            }
+        });
+
+        // Menu to remove resource from one or more device to which it is a
+        // member.
+        MenuItem deleteResource = new MenuItem(menu, SWT.NONE);
+        deleteResource.setText("Delete");
+        deleteResource.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                /*
+                 * boolean refreshCollectionTree = false; boolean
+                 * refreshDeviceTree = false;
+                 * if(resource.isMemberOfAnyCollection()) {
+                 * refreshCollectionTree = true; }
+                 * if(resource.isMemberOfAnyDevice()) { refreshDeviceTree =
+                 * true; }
+                 */
+                try {
+                    resourceManager.removeResource(colRes);
+                    // if(refreshCollectionTree)
+                    collectionResTreeViewer.refresh();
+                    // if(refreshDeviceTree)
+                    deviceTreeViewer.refresh();
+                    MessageDialog.openInformation(Display.getDefault()
+                            .getActiveShell(), "Deleted", "Resource deleted.");
+                } catch (SimulatorException e1) {
+                    MessageDialog.openInformation(Display.getDefault()
+                            .getActiveShell(), "Deletion Failed",
+                            "Failed to delete the resource.");
+                }
+
+                changeDeleteVisibility();
+            }
+        });
+
+    }
+
+    private void createDeviceArea() {
+        deviceTab = new CTabItem(folder, SWT.NULL);
+        deviceTab.setText("Devices");
+
+        // Create a group to show all the discovered resources.
+        // Adding the group to the folder.
+        Group resourceGroup = new Group(folder, SWT.NONE);
+        // resourceGroup.setText("Discovered Resources");
+
+        Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
+        resourceGroup.setBackground(color);
+
+        resourceGroup.setLayout(new GridLayout(1, false));
+        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        resourceGroup.setLayoutData(gd);
+
+        PatternFilter filter = new PatternFilter();
+        FilteredTree filteredTree = new FilteredTree(resourceGroup,
+                SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE, filter, true);
+        deviceTreeViewer = filteredTree.getViewer();
+        deviceTreeViewer.getTree().setLayoutData(
+                new GridData(SWT.FILL, SWT.FILL, true, true));
+        deviceTreeViewer.setContentProvider(new DeviceContentProvider());
+        deviceTreeViewer.setLabelProvider(new TreeLabelProvider());
+        deviceTreeViewer.setInput(new Object());
+
+        deviceTreeViewer
+                .addSelectionChangedListener(new ISelectionChangedListener() {
                     @Override
-                    public void run() {
-                        DeleteResourceWizard deleteWizard = new DeleteResourceWizard();
-                        ResourceWizardDialog wizardDialog = new ResourceWizardDialog(
-                                PlatformUI.getWorkbench().getDisplay()
-                                        .getActiveShell(), deleteWizard);
-                        int open = wizardDialog.open();
-                        if (open == WizardDialog.OK) {
-                            DeleteCategory deleteCategory = deleteWizard
-                                    .getDeleteCategory();
-                            if (deleteCategory == DeleteCategory.BY_URI) {
-                                String uri = deleteWizard.getDeleteCandidate();
-                                if (null != uri) {
-                                    boolean dispName = Activator.getDefault()
-                                            .getResourceManager()
-                                            .isDisplayName(uri);
-                                    if (dispName) {
-                                        uri = Activator
-                                                .getDefault()
-                                                .getResourceManager()
-                                                .getCompleteUriFromDisplayName(
-                                                        uri);
-                                    }
-                                    resourceManager.deleteResourceByURI(uri);
-                                }
-                            } else if (deleteCategory == DeleteCategory.BY_TYPE) {
+                    public void selectionChanged(SelectionChangedEvent e) {
+                        IStructuredSelection selection = (IStructuredSelection) e
+                                .getSelection();
+                        if (null == selection) {
+                            return;
+                        }
+
+                        int size = selection.size();
+                        if (size == 1) {
+                            Object obj = selection.getFirstElement();
+                            if (obj instanceof Device) {
                                 resourceManager
-                                        .deleteResourceByType(deleteWizard
-                                                .getDeleteCandidate());
-                            } else if (deleteCategory == DeleteCategory.ALL) {
-                                resourceManager.deleteAllResources();
+                                        .deviceSelectionChanged((Device) obj);
+                            } else {
+                                resourceManager
+                                        .resourceSelectionChanged((Resource) obj);
                             }
+                        } else {
+                            resourceManager.deviceSelectionChanged(null);
                         }
                     }
                 });
-            }
-        });
 
-        if (null != treeViewer) {
-            final Tree resourceTreeHead = treeViewer.getTree();
+        // TODO: Add menu items
+        addMenuToDevices();
+
+        deviceTab.setControl(resourceGroup);
+    }
+
+    private void addMenuToDevices() {
+        if (null != deviceTreeViewer) {
+            final Tree resourceTreeHead = deviceTreeViewer.getTree();
             if (null != resourceTreeHead) {
-                // Below code adds a listener to the tree for selection changes
-                // and notifies the resource manager
-                resourceTreeHead.addSelectionListener(new SelectionAdapter() {
-                    @Override
-                    public void widgetSelected(SelectionEvent e) {
-                        TreeItem selectedItem = (TreeItem) e.item;
-                        if (null != selectedItem) {
-                            String selectedItemText = selectedItem.getText();
-                            selectedItemText = resourceManager
-                                    .getCompleteUriFromDisplayName(selectedItemText);
-                            // Propagate this selection change event to manager
-                            resourceManager
-                                    .resourceSelectionChanged(selectedItemText);
-                        }
-                    }
-                });
                 // Below code creates menu entries and shows them on right
                 // clicking a resource
                 final Menu menu = new Menu(resourceTreeHead);
@@ -305,78 +1147,393 @@ public class ResourceManagerView extends ViewPart {
                             items[index].dispose();
                         }
 
-                        final String selectedItem = resourceTreeHead
-                                .getSelection()[0].getText();
-                        // Check whether automation can be done on this
-                        // resource.
-                        if (!resourceManager.isResourceAutomationAllowed(resourceManager
-                                .getCompleteUriFromDisplayName(selectedItem))) {
-                            return;
-                        }
+                        IStructuredSelection selection = ((IStructuredSelection) deviceTreeViewer
+                                .getSelection());
+                        final Object element = selection.getFirstElement();
+                        if (element instanceof Device) {
+                            addMenuToDevices(menu, (Device) element);
+                        } else {
+                            final Resource resource = (Resource) element;
+                            TreeItem[] treeItems = resourceTreeHead
+                                    .getSelection();
+                            if (null == resource || null == treeItems) {
+                                return;
+                            }
+
+                            if (resource instanceof SingleResource)
+                                addAutomationMenu(menu,
+                                        (SingleResource) resource);
 
-                        MenuItem startItem = new MenuItem(menu, SWT.NONE);
-                        startItem.setText(Constants.START_RESOURCE_AUTOMATION);
-                        startItem.addSelectionListener(new SelectionAdapter() {
-                            @Override
-                            public void widgetSelected(SelectionEvent e) {
-                                // Block starting resource level
-                                // automation if any attribute level
-                                // automation is in progress for the
-                                // selected resource
-                                boolean started = resourceManager
-                                        .isAttributeAutomationStarted(resourceManager
-                                                .getCompleteUriFromDisplayName(selectedItem));
-                                if (started) {
-                                    MessageDialog
-                                            .openInformation(
+                            final TreeItem parent = treeItems[0]
+                                    .getParentItem();
+                            MenuItem remFromParent = new MenuItem(menu,
+                                    SWT.NONE);
+                            remFromParent.setText("Remove from Parent");
+                            remFromParent
+                                    .addSelectionListener(new SelectionAdapter() {
+                                        @Override
+                                        public void widgetSelected(
+                                                SelectionEvent e) {
+                                            String status = "Resource removed from its parent.";
+                                            Object obj = parent.getData();
+                                            if (obj instanceof Device) {
+                                                resourceManager
+                                                        .removeResourceFromDevice(
+                                                                (Device) obj,
+                                                                resource);
+                                            } else {
+                                                try {
+                                                    resourceManager
+                                                            .removeResourceFromCollection(
+                                                                    (CollectionResource) obj,
+                                                                    resource);
+                                                    collectionResTreeViewer
+                                                            .refresh();
+                                                    status = "Resource removed from its parent";
+                                                } catch (SimulatorException e1) {
+                                                    status = "Failed to remove the resource from its parent";
+                                                }
+                                            }
+
+                                            deviceTreeViewer.refresh();
+
+                                            MessageDialog.openInformation(
                                                     Display.getDefault()
                                                             .getActiveShell(),
-                                                    "Attribute automation is in progress",
-                                                    "Attribute level automation for this resource is already in progress!!!\nPlease stop all "
-                                                            + "running attribute level automations to start resource level automation.");
-                                } else {
-                                    boolean status = resourceManager
-                                            .startResourceAutomationUIRequest(resourceManager
-                                                    .getCompleteUriFromDisplayName(selectedItem));
-                                    String statusMsg = status ? "Automation started successfully!!!"
-                                            : "Automation request failed!!!";
-                                    MessageDialog.openInformation(Display
-                                            .getDefault().getActiveShell(),
-                                            "Automation Status", statusMsg);
-                                }
-                            }
-                        });
-
-                        MenuItem stopItem = new MenuItem(menu, SWT.NONE);
-                        stopItem.setText(Constants.STOP_RESOURCE_AUTOMATION);
-                        stopItem.addSelectionListener(new SelectionAdapter() {
-                            @Override
-                            public void widgetSelected(SelectionEvent e) {
-                                boolean status = resourceManager
-                                        .stopResourceAutomationUIRequest(resourceManager
-                                                .getCompleteUriFromDisplayName(selectedItem));
-                                String statusMsg = status ? "Automation stop requested!!!"
-                                        : "Automation stop failed.";
-                                MessageDialog.openInformation(Display
-                                        .getDefault().getActiveShell(),
-                                        "Automation Status", statusMsg);
-                            }
-                        });
+                                                    "Status", status);
+                                        }
+                                    });
 
-                        // Set the initial visibility of menu items
-                        boolean status = resourceManager.isResourceAutomationStarted(resourceManager
-                                .getCompleteUriFromDisplayName(selectedItem));
-                        startItem.setEnabled(!status);
-                        stopItem.setEnabled(status);
+                            if (resource instanceof SingleResource) {
+                                // Menu Items for single resource will be added
+                                // here.
+                            }
+                        }
                     }
                 });
             }
         }
     }
 
+    private void addMenuToDevices(Menu menu, final Device dev) {
+        // Menu to add one or more resources to the collection.
+        MenuItem addResources = new MenuItem(menu, SWT.CASCADE);
+        addResources.setText("Add Resources");
+
+        Menu addSubMenu = new Menu(menu);
+        addResources.setMenu(addSubMenu);
+
+        MenuItem simpleResources = new MenuItem(addSubMenu, SWT.NONE);
+        simpleResources.setText("Single");
+        simpleResources.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                List<SingleResource> possibleResources;
+                possibleResources = resourceManager
+                        .getSingleTypeResourcesForAddingToDevice(dev);
+                if (null == possibleResources || possibleResources.isEmpty()) {
+                    MessageDialog
+                            .openError(Display.getDefault().getActiveShell(),
+                                    "No possible candidates",
+                                    "There are no possible single resources that can be added.");
+                    return;
+                }
+
+                List<Resource> resources = Utility
+                        .convertSingleTypeResourceListToBaseType(possibleResources);
+
+                AddResources addDlg = new AddResources(Display.getDefault()
+                        .getActiveShell(), resources);
+                if (addDlg.open() != Window.OK) {
+                    return;
+                }
+
+                Set<Resource> resultSet = addDlg.getSelectedResourceList();
+
+                resourceManager.addResourceToDevice(dev, resultSet);
+
+                deviceTreeViewer.refresh();
+
+                MessageDialog.openInformation(Display.getDefault()
+                        .getActiveShell(), "Added",
+                        "Single Resources added to the device");
+            }
+        });
+
+        MenuItem collectionResources = new MenuItem(addSubMenu, SWT.NONE);
+        collectionResources.setText("Collection");
+        collectionResources.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                List<CollectionResource> possibleResources;
+                possibleResources = resourceManager
+                        .getCollectionTypeResourcesForAddingToDevice(dev);
+                if (null == possibleResources || possibleResources.isEmpty()) {
+                    MessageDialog
+                            .openError(Display.getDefault().getActiveShell(),
+                                    "No possible candidates",
+                                    "There are no possible collections that can be added.");
+                    return;
+                }
+
+                List<Resource> resources = Utility
+                        .convertCollectionTypeResourceListToBaseType(possibleResources);
+
+                AddResources addDlg = new AddResources(Display.getDefault()
+                        .getActiveShell(), resources);
+                if (addDlg.open() != Window.OK) {
+                    return;
+                }
+
+                Set<Resource> resultSet = addDlg.getSelectedResourceList();
+
+                resourceManager.addResourceToDevice(dev, resultSet);
+
+                deviceTreeViewer.refresh();
+
+                MessageDialog.openInformation(Display.getDefault()
+                        .getActiveShell(), "Added",
+                        "Collection Resources added to the device");
+            }
+        });
+
+        // Menu to remove one or more resources from the collection.
+        MenuItem removeResources = new MenuItem(menu, SWT.CASCADE);
+        removeResources.setText("Remove Resources");
+
+        Menu removeSubMenu = new Menu(menu);
+        removeResources.setMenu(removeSubMenu);
+
+        simpleResources = new MenuItem(removeSubMenu, SWT.NONE);
+        simpleResources.setText("Single");
+        simpleResources.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                List<SingleResource> possibleResources;
+                possibleResources = resourceManager.getSingleTypeChilds(dev);
+                if (null == possibleResources || possibleResources.isEmpty()) {
+                    MessageDialog
+                            .openError(Display.getDefault().getActiveShell(),
+                                    "No possible candidates",
+                                    "There are no possible single resources which can be removed.");
+                    return;
+                }
+
+                List<Resource> resources = Utility
+                        .convertSingleTypeResourceListToBaseType(possibleResources);
+
+                RemoveResources removeDlg = new RemoveResources(Display
+                        .getDefault().getActiveShell(), resources);
+                if (removeDlg.open() != Window.OK) {
+                    return;
+                }
+
+                Set<Resource> resultSet = removeDlg.getSelectedResourceList();
+
+                resourceManager.removeResourcesFromDevice(dev, resultSet);
+
+                collectionResTreeViewer.refresh();
+
+                deviceTreeViewer.refresh();
+
+                MessageDialog.openInformation(Display.getDefault()
+                        .getActiveShell(), "Removed",
+                        "Single Resources removed from the device");
+            }
+        });
+
+        collectionResources = new MenuItem(removeSubMenu, SWT.NONE);
+        collectionResources.setText("Collection");
+        collectionResources.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                List<CollectionResource> possibleResources;
+                possibleResources = resourceManager
+                        .getCollectionTypeChilds(dev);
+                if (null == possibleResources || possibleResources.isEmpty()) {
+                    MessageDialog
+                            .openError(Display.getDefault().getActiveShell(),
+                                    "No possible candidates",
+                                    "There are no possible collections which can be removed.");
+                    return;
+                }
+
+                List<Resource> resources = Utility
+                        .convertCollectionTypeResourceListToBaseType(possibleResources);
+
+                RemoveResources removeDlg = new RemoveResources(Display
+                        .getDefault().getActiveShell(), resources);
+                if (removeDlg.open() != Window.OK) {
+                    return;
+                }
+
+                Set<Resource> resultSet = removeDlg.getSelectedResourceList();
+
+                resourceManager.removeResourcesFromDevice(dev, resultSet);
+
+                collectionResTreeViewer.refresh();
+
+                deviceTreeViewer.refresh();
+
+                MessageDialog.openInformation(Display.getDefault()
+                        .getActiveShell(), "Removed",
+                        "Collection Resources removed from the device");
+            }
+        });
+
+        // Menu to remove the device.
+        MenuItem deleteDevice = new MenuItem(menu, SWT.NONE);
+        deleteDevice.setText("Delete");
+        deleteDevice.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                resourceManager.removeDevice(dev);
+                deviceTreeViewer.refresh();
+            }
+        });
+    }
+
+    private void addAutomationMenu(final Menu menu,
+            final SingleResource selectedResource) {
+        MenuItem startItem = new MenuItem(menu, SWT.NONE);
+        startItem.setText(Constants.START_RESOURCE_AUTOMATION);
+        startItem.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                // Block starting resource level
+                // automation if any attribute level
+                // automation is in progress for the
+                // selected resource
+                boolean started = resourceManager
+                        .isAttributeAutomationStarted(selectedResource);
+                if (started) {
+                    MessageDialog
+                            .openInformation(
+                                    Display.getDefault().getActiveShell(),
+                                    "Attribute automation is in progress",
+                                    "Attribute level automation for this resource is already in progress!!!\nPlease stop all "
+                                            + "running attribute level automations to start resource level automation.");
+                } else {
+
+                    // Start the automation
+                    // Fetch the settings data
+                    List<AutomationSettingHelper> automationSettings;
+                    automationSettings = AutomationSettingHelper
+                            .getAutomationSettings(null);
+
+                    // Open the settings dialog
+                    AutomationSettingDialog dialog = new AutomationSettingDialog(
+                            Activator.getDefault().getWorkbench()
+                                    .getActiveWorkbenchWindow().getShell(),
+                            automationSettings);
+                    dialog.create();
+                    if (dialog.open() == Window.OK) {
+                        String automationType = dialog.getAutomationType();
+                        String updateFreq = dialog.getUpdateFrequency();
+
+                        AutoUpdateType autoType = AutoUpdateType
+                                .valueOf(automationType);
+                        int updFreq = Utility
+                                .getUpdateIntervalFromString(updateFreq);
+                        boolean status = resourceManager
+                                .startResourceAutomationUIRequest(autoType,
+                                        updFreq, selectedResource);
+                        String statusMsg = status ? "Automation started successfully!!!"
+                                : "Automation request failed!!!";
+                        MessageDialog.openInformation(Display.getDefault()
+                                .getActiveShell(), "Automation Status",
+                                statusMsg);
+                    }
+                }
+            }
+        });
+
+        MenuItem stopItem = new MenuItem(menu, SWT.NONE);
+        stopItem.setText(Constants.STOP_RESOURCE_AUTOMATION);
+        stopItem.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                boolean status = resourceManager
+                        .stopResourceAutomationUIRequest(selectedResource);
+                String statusMsg = status ? "Automation stopped!!!"
+                        : "Automation stop failed.";
+                MessageDialog.openInformation(Display.getDefault()
+                        .getActiveShell(), "Automation Status", statusMsg);
+            }
+        });
+
+        // Set the initial visibility of menu items
+        boolean status = resourceManager
+                .isResourceAutomationStarted(selectedResource);
+        startItem.setEnabled(!status);
+        stopItem.setEnabled(status);
+    }
+
+    private void addUIListeners() {
+
+        createButton.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
+
+                    @Override
+                    public void run() {
+                        CreateResourceWizard createWizard = new CreateResourceWizard();
+                        ResourceWizardDialog wizardDialog = new ResourceWizardDialog(
+                                PlatformUI.getWorkbench().getDisplay()
+                                        .getActiveShell(), createWizard);
+                        createWizard.setWizardDialog(wizardDialog);
+                        int open = wizardDialog.open();
+                        if (open == WizardDialog.OK
+                                || createWizard.isDlgForceClosed()) {
+                            MessageDialog.openInformation(Display.getDefault()
+                                    .getActiveShell(),
+                                    "Resource Creation Status", createWizard
+                                            .getStatus());
+                        }
+                    }
+                });
+            }
+        });
+
+        deleteButton.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
+
+                    @Override
+                    public void run() {
+                        boolean exist = resourceManager.isAnyResourceExist();
+                        if (!exist) {
+                            return;
+                        }
+                        DeleteResourceWizard deleteWizard = new DeleteResourceWizard();
+                        ResourceWizardDialog wizardDialog = new ResourceWizardDialog(
+                                PlatformUI.getWorkbench().getDisplay()
+                                        .getActiveShell(), deleteWizard);
+                        int open = wizardDialog.open();
+                        if (open == Window.OK) {
+                            singleResTreeViewer.refresh();
+                            collectionResTreeViewer.refresh();
+                            deviceTreeViewer.refresh();
+                            MessageDialog.openInformation(Display.getDefault()
+                                    .getActiveShell(),
+                                    "Resource Deletion Status", deleteWizard
+                                            .getStatus());
+
+                            changeDeleteVisibility();
+                        }
+                    }
+                });
+            }
+        });
+    }
+
     public void addManagerListeners() {
-        resourceManager
-                .addResourceListChangedUIListener(resourceListChangedListener);
+        UiListenerHandler.getInstance().addResourceListChangedUIListener(
+                resourceListChangedListener);
+        UiListenerHandler.getInstance().addResourcePropertiesChangedUIListener(
+                resourcePropertiesChangedListener);
     }
 
     @Override
@@ -387,15 +1544,21 @@ public class ResourceManagerView extends ViewPart {
     public void dispose() {
         // Unregister the listener
         if (null != resourceListChangedListener) {
-            resourceManager
-                    .removeResourceListChangedUIListener(resourceListChangedListener);
+            UiListenerHandler.getInstance()
+                    .removeResourceListChangedUIListener(
+                            resourceListChangedListener);
             resourceManager.resourceSelectionChanged(null);
         }
+        if (null != resourcePropertiesChangedListener) {
+            UiListenerHandler.getInstance()
+                    .removeResourcePropertiesChangedUIListener(
+                            resourcePropertiesChangedListener);
+        }
         super.dispose();
     }
 }
 
-class TreeContentProvider implements ITreeContentProvider {
+class SingleResourceContentProvider implements ITreeContentProvider {
 
     @Override
     public void dispose() {
@@ -412,12 +1575,13 @@ class TreeContentProvider implements ITreeContentProvider {
 
     @Override
     public Object[] getElements(Object parent) {
-        List<String> uriList;
-        uriList = Activator.getDefault().getResourceManager().getURIList();
-        if (null == uriList) {
-            uriList = new ArrayList<String>();
+        List<SingleResource> resList;
+        resList = Activator.getDefault().getResourceManager()
+                .getSingleResourceList();
+        if (null == resList) {
+            resList = new ArrayList<SingleResource>();
         }
-        return uriList.toArray();
+        return resList.toArray();
     }
 
     @Override
@@ -431,18 +1595,144 @@ class TreeContentProvider implements ITreeContentProvider {
     }
 }
 
+class CollectionResourceContentProvider implements ITreeContentProvider {
+
+    @Override
+    public void dispose() {
+    }
+
+    @Override
+    public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
+    }
+
+    @Override
+    public Object[] getChildren(Object parent) {
+        if (parent instanceof CollectionResource) {
+            CollectionResource cRes = (CollectionResource) parent;
+            Set<Resource> childs = cRes.getChildResources();
+            if (null == childs) {
+                return null;
+            }
+            return childs.toArray();
+        }
+        return null;
+    }
+
+    @Override
+    public Object[] getElements(Object parent) {
+        List<CollectionResource> resList;
+        resList = Activator.getDefault().getResourceManager()
+                .getCollectionResourceList();
+        if (null == resList) {
+            resList = new ArrayList<CollectionResource>();
+        }
+        return resList.toArray();
+    }
+
+    @Override
+    public Object getParent(Object child) {
+        return null;
+    }
+
+    @Override
+    public boolean hasChildren(Object parent) {
+        if (parent instanceof CollectionResource) {
+            CollectionResource cRes = (CollectionResource) parent;
+            Set<Resource> children = cRes.getChildResources();
+            if (null != children && children.size() > 0) {
+                return true;
+            }
+        }
+        return false;
+    }
+}
+
+class DeviceContentProvider implements ITreeContentProvider {
+
+    @Override
+    public void dispose() {
+    }
+
+    @Override
+    public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
+    }
+
+    @Override
+    public Object[] getChildren(Object parent) {
+        if (parent instanceof Device) {
+            Device dev = (Device) parent;
+            Set<Resource> children = dev.getChildResources();
+            if (null != children && children.size() > 0) {
+                return children.toArray();
+            }
+        } else if (parent instanceof CollectionResource) {
+            CollectionResource res = (CollectionResource) parent;
+            Set<Resource> children = res.getChildResources();
+            if (null != children && children.size() > 0) {
+                return children.toArray();
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public Object[] getElements(Object parent) {
+        List<Device> deviceList;
+        deviceList = Activator.getDefault().getResourceManager()
+                .getDeviceList();
+        if (null == deviceList) {
+            deviceList = new ArrayList<Device>();
+        }
+        return deviceList.toArray();
+    }
+
+    @Override
+    public Object getParent(Object child) {
+        return null;
+    }
+
+    @Override
+    public boolean hasChildren(Object parent) {
+        if (parent instanceof Device) {
+            Device dev = (Device) parent;
+            Set<Resource> children = dev.getChildResources();
+            if (null != children && children.size() > 0) {
+                return true;
+            }
+        } else if (parent instanceof CollectionResource) {
+            CollectionResource res = (CollectionResource) parent;
+            Set<Resource> children = res.getChildResources();
+            if (null != children && children.size() > 0) {
+                return true;
+            }
+        }
+        return false;
+    }
+}
+
 class TreeLabelProvider extends LabelProvider {
     @Override
     public String getText(Object element) {
-        String value = (String) element;
-        value = Utility.uriToDisplayName(value);
-        return value;
+        if (element instanceof Resource) {
+            Resource res = (Resource) element;
+            return res.getResourceName();
+        } else {
+            Device dev = (Device) element;
+            return dev.getDeviceName();
+        }
     }
 
     @Override
     public Image getImage(Object element) {
-        ResourceManager resourceManager = Activator.getDefault()
-                .getResourceManager();
-        return resourceManager.getImage((String) element);
+        if (element instanceof SingleResource) {
+            return Activator.getDefault().getImageRegistry()
+                    .get(Constants.SINGLE_RESOURCE);
+        } else if (element instanceof CollectionResource) {
+            return Activator.getDefault().getImageRegistry()
+                    .get(Constants.COLLECTION_RESOURCE);
+        } else {
+            return Activator.getDefault().getImageRegistry()
+                    .get(Constants.DEVICE);
+        }
     }
 }
\ No newline at end of file
index 5e9361f..14fd2b2 100644 (file)
@@ -22,10 +22,12 @@ import java.util.Set;
 
 import oic.simulator.serviceprovider.Activator;
 import oic.simulator.serviceprovider.listener.IObserverListChangedUIListener;
-import oic.simulator.serviceprovider.listener.IResourceSelectionChangedUIListener;
+import oic.simulator.serviceprovider.listener.ISelectionChangedUIListener;
 import oic.simulator.serviceprovider.manager.ResourceManager;
-import oic.simulator.serviceprovider.resource.ObserverDetail;
-import oic.simulator.serviceprovider.resource.SimulatorResource;
+import oic.simulator.serviceprovider.manager.UiListenerHandler;
+import oic.simulator.serviceprovider.model.Device;
+import oic.simulator.serviceprovider.model.ObserverDetail;
+import oic.simulator.serviceprovider.model.Resource;
 import oic.simulator.serviceprovider.utils.Constants;
 
 import org.eclipse.jface.viewers.CellEditor;
@@ -51,60 +53,65 @@ import org.eclipse.ui.part.ViewPart;
  * This class manages and shows the resource observer view in the perspective.
  */
 public class ResourceObserverView extends ViewPart {
-    public static final String                  VIEW_ID       = "oic.simulator.serviceprovider.view.observer";
+    public static final String             VIEW_ID       = "oic.simulator.serviceprovider.view.observer";
 
-    private TableViewer                         tblViewer;
+    private TableViewer                    tblViewer;
 
-    private final String[]                      columnHeaders = {
-            "Client Address", "Port", "Notify"               };
+    private final String[]                 columnHeaders = { "Client Address",
+            "Port", "Notify"                            };
 
-    private final Integer[]                     columnWidth   = { 150, 75, 50 };
+    private final Integer[]                columnWidth   = { 150, 75, 50 };
 
-    private IResourceSelectionChangedUIListener resourceSelectionChangedListener;
+    private ISelectionChangedUIListener    resourceSelectionChangedListener;
 
-    private IObserverListChangedUIListener      resourceObserverListChangedListener;
+    private IObserverListChangedUIListener resourceObserverListChangedListener;
 
-    private ResourceManager                     resourceManagerRef;
+    private ResourceManager                resourceManagerRef;
 
     public ResourceObserverView() {
 
         resourceManagerRef = Activator.getDefault().getResourceManager();
 
-        resourceSelectionChangedListener = new IResourceSelectionChangedUIListener() {
+        resourceSelectionChangedListener = new ISelectionChangedUIListener() {
 
             @Override
-            public void onResourceSelectionChange() {
+            public void onResourceSelectionChange(final Resource resource) {
                 Display.getDefault().asyncExec(new Runnable() {
 
                     @Override
                     public void run() {
                         if (null != tblViewer) {
                             changeButtonStatus();
-                            updateViewer(getData(resourceManagerRef
-                                    .getCurrentResourceInSelection()));
+                            updateViewer(getData(resource));
                         }
                     }
                 });
             }
+
+            @Override
+            public void onDeviceSelectionChange(Device dev) {
+                // TODO Auto-generated method stub
+
+            }
         };
 
         resourceObserverListChangedListener = new IObserverListChangedUIListener() {
 
             @Override
-            public void onObserverListChanged(final String resourceURI) {
+            public void onObserverListChanged(final Resource resource) {
                 Display.getDefault().asyncExec(new Runnable() {
 
                     @Override
                     public void run() {
-                        if (null == resourceURI) {
+                        if (null == resource) {
                             return;
                         }
-                        SimulatorResource resource = resourceManagerRef
+                        Resource resourceInSelection = resourceManagerRef
                                 .getCurrentResourceInSelection();
-                        if (null == resource) {
+                        if (null == resourceInSelection) {
                             return;
                         }
-                        if (resource.getResourceURI().equals(resourceURI)) {
+                        if (resource == resourceInSelection) {
                             if (null != tblViewer) {
                                 updateViewer(getData(resource));
                             }
@@ -116,7 +123,7 @@ public class ResourceObserverView extends ViewPart {
         };
     }
 
-    private Map<Integer, ObserverDetail> getData(SimulatorResource resource) {
+    private Map<Integer, ObserverDetail> getData(Resource resource) {
         if (null == resource) {
             return null;
         }
@@ -229,10 +236,10 @@ public class ResourceObserverView extends ViewPart {
     }
 
     private void addManagerListeners() {
-        resourceManagerRef
-                .addResourceSelectionChangedUIListener(resourceSelectionChangedListener);
-        resourceManagerRef
-                .addObserverListChangedUIListener(resourceObserverListChangedListener);
+        UiListenerHandler.getInstance().addResourceSelectionChangedUIListener(
+                resourceSelectionChangedListener);
+        UiListenerHandler.getInstance().addObserverListChangedUIListener(
+                resourceObserverListChangedListener);
     }
 
     class ObserverContentProvider implements IStructuredContentProvider {
@@ -273,7 +280,6 @@ public class ResourceObserverView extends ViewPart {
 
         @Override
         protected Object getValue(Object element) {
-            System.out.println("getValue()");
             @SuppressWarnings("unchecked")
             Map.Entry<Integer, ObserverDetail> observer = (Map.Entry<Integer, ObserverDetail>) element;
             return observer.getValue().isClicked();
@@ -281,7 +287,6 @@ public class ResourceObserverView extends ViewPart {
 
         @Override
         protected void setValue(Object element, Object value) {
-            System.out.println("setValue()");
             // Change the button status of all the resources
             changeButtonStatus();
 
@@ -298,8 +303,7 @@ public class ResourceObserverView extends ViewPart {
     }
 
     private void changeButtonStatus() {
-        SimulatorResource resource = resourceManagerRef
-                .getCurrentResourceInSelection();
+        Resource resource = resourceManagerRef.getCurrentResourceInSelection();
         if (null == resource) {
             return;
         }
@@ -318,13 +322,15 @@ public class ResourceObserverView extends ViewPart {
     public void dispose() {
         // Unregister the listener
         if (null != resourceSelectionChangedListener) {
-            resourceManagerRef
-                    .removeResourceSelectionChangedUIListener(resourceSelectionChangedListener);
+            UiListenerHandler.getInstance()
+                    .removeResourceSelectionChangedUIListener(
+                            resourceSelectionChangedListener);
         }
 
         if (null != resourceObserverListChangedListener) {
-            resourceManagerRef
-                    .removeObserverListChangedUIListener(resourceObserverListChangedListener);
+            UiListenerHandler.getInstance()
+                    .removeObserverListChangedUIListener(
+                            resourceObserverListChangedListener);
         }
         super.dispose();
     }
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddAttributeDialog.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddAttributeDialog.java
new file mode 100644 (file)
index 0000000..6fc69fa
--- /dev/null
@@ -0,0 +1,731 @@
+package oic.simulator.serviceprovider.view.dialogs;
+
+import java.util.Iterator;
+import java.util.Set;
+
+import oic.simulator.serviceprovider.model.AttributeHelper;
+import oic.simulator.serviceprovider.utils.Constants;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CCombo;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.List;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.oic.simulator.AttributeProperty.Type;
+
+public class AddAttributeDialog extends TitleAreaDialog {
+
+    private Text                 attNameTxt;
+    private Text                 minRangeTxt;
+    private Text                 maxRangeTxt;
+    private CCombo               attTypeCmb;
+    private Text                 dflValueTxt;
+    private Button               rangeBtn;
+    private Button               cusValuesBtn;
+    private Button               noneBtn;
+    private Button               addBtn;
+    private Button               remBtn;
+    private Label                minLbl;
+    private Label                maxLbl;
+    private List                 customValuesList;
+    private Text                 detail;
+
+    private AttributeHelper      attHelper;
+
+    private AttributeHelper      attClone;
+
+    private Set<AttributeHelper> attributes;
+
+    private final String         defaultMessage   = "Name, Type, and Default Value fields "
+                                                          + "are mandatory.\n\nRange and custom fields allow to set the valid "
+                                                          + "values of the attribute.\n\n";
+    private final String         msgForBoolType   = "Possible attribute values of Bool are "
+                                                          + "true and false.\nSo range and custom options are disabled.";
+    private final String         msgForIntType    = "Valid values for Int type can either be "
+                                                          + "of range type (Ex: 1 - 10) or custom values (Ex: 10, 20, 50, and 100).\n";
+    private final String         msgForDoubleType = "Valid values for Double type can either be "
+                                                          + "of range type (Ex: 18.0 - 22.0) or custom values (Ex: 1.5, 2.5, 3.9, 4.8, etc).\n";
+    private final String         msgForStringType = "For String type, range option is not"
+                                                          + "applicable. Hence it is disabled.\n\n"
+                                                          + "Custom option is available to provide the valid values.\n\n"
+                                                          + "Ex: low, mid, high, etc.";
+
+    private Set<String>          attValueTypes;
+
+    private boolean              editOperation;
+
+    public AddAttributeDialog(Shell parentShell, AttributeHelper att,
+            Set<String> attValueTypes, Set<AttributeHelper> attributes) {
+        super(parentShell);
+        if (null == att) {
+            att = new AttributeHelper();
+        } else {
+            attClone = att.clone();
+            System.out.println("Cloned attribute's data:" + attClone);
+            editOperation = true;
+        }
+        attHelper = att;
+        this.attValueTypes = attValueTypes;
+        this.attributes = attributes;
+    }
+
+    @Override
+    public void create() {
+        super.create();
+        setTitle("Add Attribute");
+        setMessage("Fill the details for creating an attribute");
+    }
+
+    @Override
+    protected Control createDialogArea(Composite parent) {
+        Composite compLayout = (Composite) super.createDialogArea(parent);
+        Composite container = new Composite(compLayout, SWT.NONE);
+        container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+        GridLayout layout = new GridLayout(5, false);
+        /*
+         * layout.verticalSpacing = 10; layout.marginTop = 10;
+         */
+        container.setLayout(layout);
+
+        Label attNameLbl = new Label(container, SWT.NULL);
+        attNameLbl.setText("Attribute Name:");
+
+        attNameTxt = new Text(container, SWT.BORDER);
+        GridData gd = new GridData();
+        gd.horizontalAlignment = SWT.FILL;
+        gd.horizontalSpan = 4;
+        gd.grabExcessHorizontalSpace = true;
+        attNameTxt.setLayoutData(gd);
+
+        Label attTypeLbl = new Label(container, SWT.NULL);
+        attTypeLbl.setText("Attribute Type:");
+
+        attTypeCmb = new CCombo(container, SWT.READ_ONLY | SWT.BORDER);
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalSpan = 4;
+        gd.horizontalAlignment = SWT.FILL;
+        attTypeCmb.setLayoutData(gd);
+        initTypes();
+
+        Group valuesGrp = new Group(container, SWT.NULL);
+        valuesGrp.setText("Attribute Values");
+        gd = new GridData();
+        gd.verticalIndent = 10;
+        gd.horizontalSpan = 3;
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        gd.grabExcessVerticalSpace = true;
+        gd.verticalAlignment = SWT.FILL;
+        valuesGrp.setLayoutData(gd);
+        layout = new GridLayout(4, false);
+        valuesGrp.setLayout(layout);
+
+        rangeBtn = new Button(valuesGrp, SWT.RADIO);
+        rangeBtn.setText("Range");
+        gd = new GridData();
+        gd.horizontalSpan = 4;
+        rangeBtn.setLayoutData(gd);
+
+        minLbl = new Label(valuesGrp, SWT.NONE);
+        minLbl.setText("Min:");
+        gd = new GridData();
+        gd.horizontalIndent = 25;
+        minLbl.setLayoutData(gd);
+
+        minRangeTxt = new Text(valuesGrp, SWT.BORDER);
+        gd = new GridData();
+        gd.widthHint = 70;
+        minRangeTxt.setLayoutData(gd);
+
+        maxLbl = new Label(valuesGrp, SWT.NONE);
+        maxLbl.setText("Max:");
+        gd = new GridData();
+        gd.horizontalIndent = 25;
+        maxLbl.setLayoutData(gd);
+
+        maxRangeTxt = new Text(valuesGrp, SWT.BORDER);
+        gd = new GridData();
+        gd.widthHint = 70;
+        maxRangeTxt.setLayoutData(gd);
+
+        cusValuesBtn = new Button(valuesGrp, SWT.RADIO);
+        cusValuesBtn.setText("Custom");
+        gd = new GridData();
+        gd.horizontalSpan = 4;
+        cusValuesBtn.setLayoutData(gd);
+
+        Composite cusValuesComp = new Composite(valuesGrp, SWT.NONE);
+        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        gd.horizontalSpan = 4;
+        cusValuesComp.setLayoutData(gd);
+        layout = new GridLayout(2, false);
+        cusValuesComp.setLayout(layout);
+
+        customValuesList = new List(cusValuesComp, SWT.BORDER | SWT.MULTI
+                | SWT.V_SCROLL);
+        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        gd.heightHint = 75;
+        gd.horizontalIndent = 25;
+        customValuesList.setLayoutData(gd);
+
+        Composite cusValuesActionsComp = new Composite(cusValuesComp, SWT.NONE);
+        layout = new GridLayout();
+        cusValuesActionsComp.setLayout(layout);
+        gd = new GridData();
+        gd.verticalAlignment = SWT.TOP;
+        cusValuesActionsComp.setLayoutData(gd);
+
+        addBtn = new Button(cusValuesActionsComp, SWT.PUSH);
+        addBtn.setText("Add");
+        gd = new GridData();
+        gd.widthHint = 70;
+        addBtn.setLayoutData(gd);
+
+        remBtn = new Button(cusValuesActionsComp, SWT.PUSH);
+        remBtn.setText("Remove");
+        gd = new GridData();
+        gd.widthHint = 70;
+        remBtn.setLayoutData(gd);
+        remBtn.setEnabled(false);
+
+        noneBtn = new Button(valuesGrp, SWT.RADIO);
+        noneBtn.setText("None");
+        gd = new GridData();
+        gd.horizontalSpan = 4;
+        noneBtn.setLayoutData(gd);
+
+        Composite detailsComp = new Composite(container, SWT.NULL);
+        detailsComp.setLayout(new GridLayout());
+        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        gd.horizontalSpan = 2;
+        gd.widthHint = 100;
+        detailsComp.setLayoutData(gd);
+
+        Label lbl = new Label(detailsComp, SWT.NULL);
+        lbl.setText("Details");
+
+        Group detailsGrp = new Group(detailsComp, SWT.NULL);
+        detailsGrp.setLayout(new GridLayout());
+        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        detailsGrp.setLayoutData(gd);
+
+        detail = new Text(detailsGrp, SWT.MULTI | SWT.READ_ONLY | SWT.BORDER
+                | SWT.WRAP | SWT.V_SCROLL);
+        detail.setBackground(detailsGrp.getBackground());
+        detail.setText(defaultMessage);
+        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        detail.setLayoutData(gd);
+
+        Label dflValueLbl = new Label(container, SWT.NULL);
+        dflValueLbl.setText("Default value");
+
+        dflValueTxt = new Text(container, SWT.BORDER);
+        gd = new GridData();
+        gd.horizontalSpan = 4;
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        dflValueTxt.setLayoutData(gd);
+
+        setUiListeners();
+
+        if (editOperation) {
+            initData();
+            attNameTxt.setFocus();
+        } else {
+            setInitialSelection();
+        }
+
+        return compLayout;
+    }
+
+    private void initTypes() {
+        if (null != attValueTypes && attValueTypes.size() > 0) {
+            Iterator<String> itr = attValueTypes.iterator();
+            while (itr.hasNext()) {
+                attTypeCmb.add(itr.next());
+            }
+        }
+    }
+
+    private void setInitialSelection() {
+        enable(false);
+        rangeOptionSelected(false);
+        customOptionSelected(false);
+    }
+
+    private void initData() {
+        if (editOperation) {
+            // Populate the UI controls with the data.
+            attNameTxt.setText(attHelper.getAttributeName());
+            attTypeCmb.select(attTypeCmb.indexOf(attHelper.getAttributeType()));
+            updateControls();
+            dflValueTxt.setText(attHelper.getAttributeDflValue());
+            Type valuesType = attHelper.getValidValuesType();
+            /*
+             * if (valuesType == Type.UNKNOWN) { noneBtn.setSelection(true); }
+             * else
+             */if (valuesType == Type.RANGE) {
+                rangeBtn.setSelection(true);
+                noneBtn.setSelection(false);
+                rangeOptionSelected(true);
+                minRangeTxt.setText(attHelper.getMin());
+                maxRangeTxt.setText(attHelper.getMax());
+            } else if (valuesType == Type.VALUESET) {
+                cusValuesBtn.setSelection(true);
+                noneBtn.setSelection(false);
+                customOptionSelected(true);
+                Set<String> allowedValues = attHelper.getAllowedValues();
+                customValuesList.setItems(allowedValues.toArray(new String[1]));
+            }
+        }
+    }
+
+    private void setUiListeners() {
+
+        /*
+         * attNameTxt.addModifyListener(new ModifyListener() {
+         * 
+         * @Override public void modifyText(ModifyEvent e) { String value =
+         * attNameTxt.getText(); if(null != value) { value = value.trim(); }
+         * attHelper.setAttributeName(value); } });
+         * 
+         * dflValueTxt.addModifyListener(new ModifyListener() {
+         * 
+         * @Override public void modifyText(ModifyEvent arg0) { String value =
+         * dflValueTxt.getText(); if(null != value) { value = value.trim(); }
+         * attHelper.setAttributeDflValue(value); } });
+         */
+        rangeBtn.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                rangeOptionSelected(true);
+                customOptionSelected(false);
+                minRangeTxt.setFocus();
+            }
+        });
+
+        cusValuesBtn.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                addBtn.setFocus();
+                rangeOptionSelected(false);
+                customOptionSelected(true);
+            }
+        });
+
+        noneBtn.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                rangeOptionSelected(false);
+                customOptionSelected(false);
+            }
+        });
+
+        attTypeCmb.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                updateControls();
+            }
+        });
+
+        minRangeTxt.addListener(SWT.Verify, new Listener() {
+            @Override
+            public void handleEvent(Event e) {
+                String string = e.text;
+                System.out.println(string);
+                char[] chars = new char[string.length()];
+                string.getChars(0, chars.length, chars, 0);
+                for (int i = 0; i < chars.length; i++) {
+                    if (!('0' <= chars[i] && chars[i] <= '9')) {
+                        if (attTypeCmb.getText().equals(Constants.INT)) {
+                            e.doit = false;
+                            return;
+                        } else if (attTypeCmb.getText()
+                                .equals(Constants.DOUBLE)) {
+                            if (!(chars[i] == '.')) {
+                                e.doit = false;
+                                return;
+                            }
+                        }
+                    }
+                }
+                // attHelper.setMin(minRangeTxt.getText() + string);
+            }
+        });
+
+        maxRangeTxt.addListener(SWT.Verify, new Listener() {
+            @Override
+            public void handleEvent(Event e) {
+                String string = e.text;
+                char[] chars = new char[string.length()];
+                string.getChars(0, chars.length, chars, 0);
+                for (int i = 0; i < chars.length; i++) {
+                    if (!('0' <= chars[i] && chars[i] <= '9')) {
+                        if (attTypeCmb.getText().equals(Constants.INT)) {
+                            e.doit = false;
+                            return;
+                        } else if (attTypeCmb.getText()
+                                .equals(Constants.DOUBLE)) {
+                            if (!(chars[i] == '.')) {
+                                e.doit = false;
+                                return;
+                            }
+                        }
+                    }
+                }
+                // attHelper.setMax(maxRangeTxt.getText() + string);
+            }
+        });
+
+        addBtn.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                SingleTextInputDialog dialog = new SingleTextInputDialog(
+                        getShell(), "Add Attribute Value", "Attribute Value");
+                if (dialog.open() == Window.OK) {
+                    System.out.println(dialog.getValue());
+                    String value = dialog.getValue();
+                    String type = attTypeCmb.getText();
+                    if (!attHelper.isValueValid(value, type)) {
+                        MessageDialog.openError(getParentShell(),
+                                "Invalid value", "Attribute value is invalid.");
+                    } else if (attHelper.isAllowedValueExist(
+                            customValuesList.getItems(), value)) {
+                        MessageDialog.openError(getParentShell(),
+                                "Duplicate value",
+                                "Attribute value already exists.");
+                    } else {
+                        customValuesList.add(value);
+                        customValuesList.deselectAll();
+                        customValuesList.select(customValuesList.getItemCount() - 1);
+                        customValuesList.showSelection();
+                        remBtn.setEnabled(true);
+                        // attHelper.addValueToAllowedValues(value);
+                    }
+                }
+            }
+        });
+
+        remBtn.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                int[] selection = customValuesList.getSelectionIndices();
+                // String[] selectionStr = customValuesList.getSelection();
+                if (null != selection && selection.length > 0) {
+                    customValuesList.remove(selection);
+                    /*
+                     * for (String selected : selectionStr) {
+                     * attHelper.removeValueFromAllowedValues(selected); }
+                     */
+                }
+
+                changeRemBtnVisibility();
+            }
+        });
+
+        customValuesList.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                changeRemBtnVisibility();
+            }
+        });
+    }
+
+    private void updateControls() {
+        rangeBtn.setSelection(false);
+        cusValuesBtn.setSelection(false);
+        noneBtn.setSelection(true);
+
+        cleanRangeAndCustomValues();
+        dflValueTxt.setText("");
+
+        String selected = attTypeCmb.getText();
+        // attHelper.setAttributeType(selected);
+
+        if (selected.equals(Constants.INT)) {
+            enable(true);
+            rangeOptionSelected(false);
+            customOptionSelected(false);
+            detail.setText(defaultMessage + msgForIntType);
+        } else if (selected.equals(Constants.DOUBLE)) {
+            enable(true);
+            rangeOptionSelected(false);
+            customOptionSelected(false);
+            detail.setText(defaultMessage + msgForDoubleType);
+        } else if (selected.equals(Constants.BOOL)) {
+            // noneBtn.setSelection(true);
+            enable(false);
+            rangeOptionSelected(false);
+            customOptionSelected(false);
+            detail.setText(defaultMessage + msgForBoolType);
+        } else if (selected.equals(Constants.STRING)) {
+            rangeBtn.setEnabled(false);
+            rangeOptionSelected(false);
+            cusValuesBtn.setEnabled(true);
+            noneBtn.setEnabled(true);
+            // cusValuesBtn.setSelection(true);
+            detail.setText(defaultMessage + msgForStringType);
+        } else {
+            // noneBtn.setSelection(true);
+            enable(false);
+            rangeOptionSelected(false);
+            customOptionSelected(false);
+            detail.setText(defaultMessage);
+        }
+    }
+
+    private void changeRemBtnVisibility() {
+        if (cusValuesBtn.isEnabled() && cusValuesBtn.getSelection()) {
+            int[] selection = customValuesList.getSelectionIndices();
+            if (null != selection && selection.length > 0) {
+                remBtn.setEnabled(true);
+            } else {
+                remBtn.setEnabled(false);
+            }
+        } else {
+            remBtn.setEnabled(false);
+        }
+    }
+
+    private void enable(boolean enable) {
+        rangeBtn.setEnabled(enable);
+        cusValuesBtn.setEnabled(enable);
+        noneBtn.setEnabled(enable);
+    }
+
+    private void rangeOptionSelected(boolean enable) {
+        minRangeTxt.setEnabled(enable);
+        maxRangeTxt.setEnabled(enable);
+        minLbl.setEnabled(enable);
+        maxLbl.setEnabled(enable);
+    }
+
+    private void customOptionSelected(boolean enable) {
+        customValuesList.setEnabled(enable);
+        addBtn.setEnabled(enable);
+        changeRemBtnVisibility();
+    }
+
+    private void cleanRangeAndCustomValues() {
+        cleanRangeValues();
+        cleanCustomValues();
+    }
+
+    private void cleanRangeValues() {
+        minRangeTxt.setText("");
+        maxRangeTxt.setText("");
+    }
+
+    private void cleanCustomValues() {
+        customValuesList.removeAll();
+    }
+
+    public AttributeHelper getAttHelper() {
+        return attHelper;
+    }
+
+    public AttributeHelper getAttClone() {
+        return attClone;
+    }
+
+    @Override
+    protected void okPressed() {
+        // Attribute Name
+        String attName = attNameTxt.getText();
+        if (null == attName || attName.isEmpty()) {
+            MessageDialog.openError(getParentShell(),
+                    "Mandatory field is empty",
+                    "Please fill the attribute name.");
+            attNameTxt.setFocus();
+            return;
+        }
+        attName = attName.trim();
+        if (attName.length() < 1) {
+            MessageDialog.openError(getParentShell(),
+                    "Mandatory field is empty", "Attribute name is invalid.");
+            attNameTxt.setFocus();
+            return;
+        }
+        attHelper.setAttributeName(attName);
+
+        // Duplicate check for attribute name if this is not editing operation
+        if (!editOperation) {
+            if (!attributes.isEmpty()) {
+                Iterator<AttributeHelper> itr = attributes.iterator();
+                AttributeHelper att;
+                while (itr.hasNext()) {
+                    att = itr.next();
+                    if (att.getAttributeName().equals(attName)) {
+                        MessageDialog
+                                .openError(
+                                        getParentShell(),
+                                        "Duplicate Attribute",
+                                        "Another attribute with the same attribute name exist. Please enter a new attribute name.");
+                        attNameTxt.setFocus();
+                        return;
+                    }
+                }
+            }
+        }
+
+        // Attribute Type
+        String attType = attTypeCmb.getText();
+        if (null == attType || attType.isEmpty()) {
+            MessageDialog.openError(getParentShell(),
+                    "Mandatory field is empty",
+                    "Please select an attribute type.");
+            return;
+        }
+        attHelper.setAttributeType(attType);
+
+        // Attribute values
+        if (rangeBtn.isEnabled() && rangeBtn.getSelection()) { // Range option
+            String min = minRangeTxt.getText();
+            String max = maxRangeTxt.getText();
+            if (null == min && null == max) {
+                MessageDialog
+                        .openError(getParentShell(), "Range is empty",
+                                "Please enter the minimum and maximum value of the range.");
+                minRangeTxt.setFocus();
+                return;
+            }
+            if (null == min || null == max) {
+                String msg;
+                msg = "Please enter the "
+                        + ((null == min) ? "minimum value" : "maximum value")
+                        + "of the range.";
+                MessageDialog
+                        .openError(getParentShell(), "Range is empty", msg);
+                ((null == min) ? minRangeTxt : maxRangeTxt).setFocus();
+                return;
+            }
+            if (min.isEmpty() && max.isEmpty()) {
+                MessageDialog
+                        .openError(getParentShell(), "Range is empty",
+                                "Please enter the minimum and maximum value of the range.");
+                minRangeTxt.setFocus();
+                return;
+            }
+            if (min.isEmpty()) {
+                MessageDialog.openError(getParentShell(), "Range is empty",
+                        "Please enter the minimum value for the range.");
+                minRangeTxt.setFocus();
+                return;
+            }
+            if (max.isEmpty()) {
+                MessageDialog.openError(getParentShell(), "Range is empty",
+                        "Please enter the maximum value for the range.");
+                maxRangeTxt.setFocus();
+                return;
+            }
+
+            if (!min.isEmpty() && !max.isEmpty()
+                    && !attHelper.isRangeValid(min, max, attType)) {
+                MessageDialog.openError(getParentShell(), "Invalid range",
+                        "Range is invalid.");
+                maxRangeTxt.setFocus();
+                return;
+            }
+            attHelper.setValidValuesType(Type.RANGE);
+            attHelper.setMin(min);
+            attHelper.setMax(max);
+
+            if (editOperation) {
+                // Remove all existing custom values
+                attHelper.setAllowedValues(null);
+            }
+        } else if (cusValuesBtn.isEnabled() && cusValuesBtn.getSelection()) {
+            String[] cusItems = customValuesList.getItems();
+            if (null == cusItems || cusItems.length < 1) {
+                MessageDialog.openError(getParentShell(),
+                        "Custom list is empty.",
+                        "No values are added to the custom list.");
+                maxRangeTxt.setFocus();
+                return;
+            }
+            attHelper.setValidValuesType(Type.VALUESET);
+            attHelper.setAllowedValuesByArray(cusItems);
+
+            if (editOperation) {
+                // Remove min and max values
+                attHelper.setMin(null);
+                attHelper.setMax(null);
+            }
+        } else if (noneBtn.isEnabled() && noneBtn.getSelection()) {
+            attHelper.setValidValuesType(Type.UNKNOWN);
+            if (editOperation) {
+                // Remove min, max and custom values
+                attHelper.setAllowedValues(null);
+                attHelper.setMin(null);
+                attHelper.setMax(null);
+            }
+        }
+
+        // Attribute Default Value
+        String attDflValue = dflValueTxt.getText();
+        if (null == attDflValue || attDflValue.isEmpty()) {
+            MessageDialog.openError(getParentShell(),
+                    "Mandatory field is empty",
+                    "Please enter a default value for the attribute.");
+            dflValueTxt.setFocus();
+            return;
+        }
+        attDflValue = attDflValue.trim();
+        if (attDflValue.length() < 1
+                || !attHelper.isValueValid(attDflValue, attType)) {
+            MessageDialog.openError(getParentShell(), "Invalid value",
+                    "Default value is invalid.");
+            dflValueTxt.setFocus();
+            return;
+        }
+        if (!attHelper.isDefaultValueValid(attDflValue)) {
+            MessageDialog.openError(getParentShell(), "Invalid value",
+                    "Default value is not in the valid values.");
+            dflValueTxt.setFocus();
+            return;
+        }
+
+        attHelper.setAttributeDflValue(attDflValue.toLowerCase());
+
+        close();
+    }
+
+    @Override
+    public boolean isHelpAvailable() {
+        return false;
+    }
+
+    /*
+     * @Override protected Point getInitialSize() { Point curSize =
+     * super.getInitialSize(); return new Point(curSize.x, curSize.y + 200); }
+     */
+
+    @Override
+    protected Point getInitialLocation(Point initialSize) {
+        Rectangle shellBounds = Display.getDefault().getActiveShell()
+                .getBounds();
+        Point dialogSize = getInitialSize();
+
+        return new Point(
+                shellBounds.x + (shellBounds.width - dialogSize.x) / 2,
+                shellBounds.y + (shellBounds.height - dialogSize.y) / 2);
+    }
+}
\ No newline at end of file
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddResourceToCollections.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddResourceToCollections.java
new file mode 100644 (file)
index 0000000..914e515
--- /dev/null
@@ -0,0 +1,206 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package oic.simulator.serviceprovider.view.dialogs;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import oic.simulator.serviceprovider.Activator;
+import oic.simulator.serviceprovider.model.CollectionResource;
+import oic.simulator.serviceprovider.utils.Constants;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTreeViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * This dialog is used for loading the RAML file.
+ */
+public class AddResourceToCollections extends TitleAreaDialog {
+
+    private CheckboxTreeViewer treeViewer;
+
+    List<CollectionResource>   sourceList;
+
+    Set<CollectionResource>    selectedResourceList;
+
+    public AddResourceToCollections(Shell parentShell,
+            List<CollectionResource> sourceList) {
+        super(parentShell);
+        this.sourceList = sourceList;
+        selectedResourceList = new HashSet<CollectionResource>();
+    }
+
+    @Override
+    public void create() {
+        super.create();
+        setTitle("Add To Collections");
+        setMessage("Select one or more collection resources to which the single resource will be added.");
+    }
+
+    @Override
+    protected Control createDialogArea(Composite parent) {
+        Composite compLayout = (Composite) super.createDialogArea(parent);
+        Composite container = new Composite(compLayout, SWT.NONE);
+        container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+        GridLayout layout = new GridLayout();
+        layout.verticalSpacing = 10;
+        layout.marginTop = 10;
+        container.setLayout(layout);
+
+        Label lbl = new Label(container, SWT.NONE);
+        lbl.setText("Select Resources from:");
+        GridData gd;
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        lbl.setLayoutData(gd);
+
+        Group resourceGroup = new Group(container, SWT.NONE);
+
+        Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
+
+        resourceGroup.setLayout(new GridLayout());
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        gd.heightHint = 300;
+        gd.horizontalSpan = 2;
+        resourceGroup.setLayoutData(gd);
+
+        treeViewer = new CheckboxTreeViewer(resourceGroup);
+        treeViewer.getTree().setBackground(color);
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        gd.grabExcessVerticalSpace = true;
+        gd.verticalAlignment = SWT.FILL;
+        // gd.heightHint = 300;
+        treeViewer.getTree().setLayoutData(gd);
+        treeViewer.setContentProvider(new TreeContentProvider());
+        treeViewer.setLabelProvider(new TreeLabelProvider());
+        treeViewer.setInput(new Object());
+        treeViewer.addCheckStateListener(new ICheckStateListener() {
+
+            @Override
+            public void checkStateChanged(CheckStateChangedEvent e) {
+                CollectionResource res = (CollectionResource) e.getElement();
+                if (null != res) {
+                    if (e.getChecked()) {
+                        selectedResourceList.add(res);
+                        System.out.println("Checked" + res.getResourceName());
+                    } else {
+                        selectedResourceList.remove(res);
+                        System.out.println("Unchecked:" + res.getResourceName());
+                    }
+                }
+            }
+        });
+
+        return compLayout;
+    }
+
+    public Set<CollectionResource> getSelectedResourceList() {
+        return selectedResourceList;
+    }
+
+    class TreeContentProvider implements ITreeContentProvider {
+
+        @Override
+        public void dispose() {
+        }
+
+        @Override
+        public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
+        }
+
+        @Override
+        public Object[] getChildren(Object parent) {
+            return null;
+        }
+
+        @Override
+        public Object[] getElements(Object parent) {
+            if (null == sourceList) {
+                sourceList = new ArrayList<CollectionResource>();
+            }
+            return sourceList.toArray();
+        }
+
+        @Override
+        public Object getParent(Object child) {
+            return null;
+        }
+
+        @Override
+        public boolean hasChildren(Object parent) {
+            return false;
+        }
+    }
+
+    class TreeLabelProvider extends LabelProvider {
+        @Override
+        public String getText(Object element) {
+            CollectionResource res = (CollectionResource) element;
+            return res.getResourceName();
+        }
+
+        @Override
+        public Image getImage(Object element) {
+            if (element instanceof CollectionResource) {
+                return Activator.getDefault().getImageRegistry()
+                        .get(Constants.COLLECTION_RESOURCE);
+            } else {
+                return null;
+            }
+        }
+    }
+
+    @Override
+    protected void okPressed() {
+        if (selectedResourceList.isEmpty()) {
+            MessageDialog.openInformation(
+                    Display.getDefault().getActiveShell(),
+                    "No selection done.", "No resources are selected.");
+            return;
+        }
+        close();
+    }
+
+    @Override
+    public boolean isHelpAvailable() {
+        return false;
+    }
+}
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddResourceToDevices.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddResourceToDevices.java
new file mode 100644 (file)
index 0000000..8eaaa5f
--- /dev/null
@@ -0,0 +1,205 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package oic.simulator.serviceprovider.view.dialogs;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import oic.simulator.serviceprovider.Activator;
+import oic.simulator.serviceprovider.model.Device;
+import oic.simulator.serviceprovider.utils.Constants;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTreeViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * This dialog is used for loading the RAML file.
+ */
+public class AddResourceToDevices extends TitleAreaDialog {
+
+    private CheckboxTreeViewer treeViewer;
+
+    List<Device>               sourceList;
+
+    Set<Device>                selectedDeviceList;
+
+    public AddResourceToDevices(Shell parentShell, List<Device> sourceList) {
+        super(parentShell);
+        this.sourceList = sourceList;
+        selectedDeviceList = new HashSet<Device>();
+    }
+
+    @Override
+    public void create() {
+        super.create();
+        setTitle("Add To Devices");
+        setMessage("Select one or more devices to which the single resource will be added.");
+    }
+
+    @Override
+    protected Control createDialogArea(Composite parent) {
+        Composite compLayout = (Composite) super.createDialogArea(parent);
+        Composite container = new Composite(compLayout, SWT.NONE);
+        container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+        GridLayout layout = new GridLayout();
+        layout.verticalSpacing = 10;
+        layout.marginTop = 10;
+        container.setLayout(layout);
+
+        Label lbl = new Label(container, SWT.NONE);
+        lbl.setText("Select Resources from:");
+        GridData gd;
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        lbl.setLayoutData(gd);
+
+        Group resourceGroup = new Group(container, SWT.NONE);
+
+        Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
+
+        resourceGroup.setLayout(new GridLayout());
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        gd.heightHint = 300;
+        gd.horizontalSpan = 2;
+        resourceGroup.setLayoutData(gd);
+
+        treeViewer = new CheckboxTreeViewer(resourceGroup);
+        treeViewer.getTree().setBackground(color);
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        gd.grabExcessVerticalSpace = true;
+        gd.verticalAlignment = SWT.FILL;
+        // gd.heightHint = 300;
+        treeViewer.getTree().setLayoutData(gd);
+        treeViewer.setContentProvider(new TreeContentProvider());
+        treeViewer.setLabelProvider(new TreeLabelProvider());
+        treeViewer.setInput(new Object());
+        treeViewer.addCheckStateListener(new ICheckStateListener() {
+
+            @Override
+            public void checkStateChanged(CheckStateChangedEvent e) {
+                Device dev = (Device) e.getElement();
+                if (null != dev) {
+                    if (e.getChecked()) {
+                        selectedDeviceList.add(dev);
+                        System.out.println("Checked" + dev.getDeviceName());
+                    } else {
+                        selectedDeviceList.remove(dev);
+                        System.out.println("Unchecked:" + dev.getDeviceName());
+                    }
+                }
+            }
+        });
+
+        return compLayout;
+    }
+
+    public Set<Device> getSelectedDeviceList() {
+        return selectedDeviceList;
+    }
+
+    class TreeContentProvider implements ITreeContentProvider {
+
+        @Override
+        public void dispose() {
+        }
+
+        @Override
+        public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
+        }
+
+        @Override
+        public Object[] getChildren(Object parent) {
+            return null;
+        }
+
+        @Override
+        public Object[] getElements(Object parent) {
+            if (null == sourceList) {
+                sourceList = new ArrayList<Device>();
+            }
+            return sourceList.toArray();
+        }
+
+        @Override
+        public Object getParent(Object child) {
+            return null;
+        }
+
+        @Override
+        public boolean hasChildren(Object parent) {
+            return false;
+        }
+    }
+
+    class TreeLabelProvider extends LabelProvider {
+        @Override
+        public String getText(Object element) {
+            Device dev = (Device) element;
+            return dev.getDeviceName();
+        }
+
+        @Override
+        public Image getImage(Object element) {
+            if (element instanceof Device) {
+                return Activator.getDefault().getImageRegistry()
+                        .get(Constants.DEVICE);
+            } else {
+                return null;
+            }
+        }
+    }
+
+    @Override
+    protected void okPressed() {
+        if (selectedDeviceList.isEmpty()) {
+            MessageDialog.openInformation(
+                    Display.getDefault().getActiveShell(),
+                    "No selection done.", "No devices are selected.");
+            return;
+        }
+        close();
+    }
+
+    @Override
+    public boolean isHelpAvailable() {
+        return false;
+    }
+}
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddResources.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddResources.java
new file mode 100644 (file)
index 0000000..6e13f6c
--- /dev/null
@@ -0,0 +1,207 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package oic.simulator.serviceprovider.view.dialogs;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import oic.simulator.serviceprovider.Activator;
+import oic.simulator.serviceprovider.model.CollectionResource;
+import oic.simulator.serviceprovider.model.Resource;
+import oic.simulator.serviceprovider.utils.Constants;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTreeViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * This dialog is used for loading the RAML file.
+ */
+public class AddResources extends TitleAreaDialog {
+
+    private CheckboxTreeViewer treeViewer;
+
+    List<Resource>             sourceList;
+
+    Set<Resource>              selectedResourceList;
+
+    public AddResources(Shell parentShell, List<Resource> sourceList) {
+        super(parentShell);
+        this.sourceList = sourceList;
+        selectedResourceList = new HashSet<Resource>();
+    }
+
+    @Override
+    public void create() {
+        super.create();
+        setTitle("Add Resources");
+        setMessage("Select one or more resources to be added.");
+    }
+
+    @Override
+    protected Control createDialogArea(Composite parent) {
+        Composite compLayout = (Composite) super.createDialogArea(parent);
+        Composite container = new Composite(compLayout, SWT.NONE);
+        container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+        GridLayout layout = new GridLayout();
+        layout.verticalSpacing = 10;
+        layout.marginTop = 10;
+        container.setLayout(layout);
+
+        Label lbl = new Label(container, SWT.NONE);
+        lbl.setText("Select Resources from:");
+        GridData gd;
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        lbl.setLayoutData(gd);
+
+        Group resourceGroup = new Group(container, SWT.NONE);
+
+        Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
+
+        resourceGroup.setLayout(new GridLayout());
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        gd.heightHint = 300;
+        gd.horizontalSpan = 2;
+        resourceGroup.setLayoutData(gd);
+
+        treeViewer = new CheckboxTreeViewer(resourceGroup);
+        treeViewer.getTree().setBackground(color);
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        gd.grabExcessVerticalSpace = true;
+        gd.verticalAlignment = SWT.FILL;
+        // gd.heightHint = 300;
+        treeViewer.getTree().setLayoutData(gd);
+        treeViewer.setContentProvider(new TreeContentProvider());
+        treeViewer.setLabelProvider(new TreeLabelProvider());
+        treeViewer.setInput(new Object());
+        treeViewer.addCheckStateListener(new ICheckStateListener() {
+
+            @Override
+            public void checkStateChanged(CheckStateChangedEvent e) {
+                Resource res = (Resource) e.getElement();
+                if (null != res) {
+                    if (e.getChecked()) {
+                        selectedResourceList.add(res);
+                        System.out.println("Checked" + res.getResourceName());
+                    } else {
+                        selectedResourceList.remove(res);
+                        System.out.println("Unchecked:" + res.getResourceName());
+                    }
+                }
+            }
+        });
+
+        return compLayout;
+    }
+
+    public Set<Resource> getSelectedResourceList() {
+        return selectedResourceList;
+    }
+
+    class TreeContentProvider implements ITreeContentProvider {
+
+        @Override
+        public void dispose() {
+        }
+
+        @Override
+        public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
+        }
+
+        @Override
+        public Object[] getChildren(Object parent) {
+            return null;
+        }
+
+        @Override
+        public Object[] getElements(Object parent) {
+            if (null == sourceList) {
+                sourceList = new ArrayList<Resource>();
+            }
+            return sourceList.toArray();
+        }
+
+        @Override
+        public Object getParent(Object child) {
+            return null;
+        }
+
+        @Override
+        public boolean hasChildren(Object parent) {
+            return false;
+        }
+    }
+
+    class TreeLabelProvider extends LabelProvider {
+        @Override
+        public String getText(Object element) {
+            Resource res = (Resource) element;
+            return res.getResourceName();
+        }
+
+        @Override
+        public Image getImage(Object element) {
+            if (element instanceof CollectionResource) {
+                return Activator.getDefault().getImageRegistry()
+                        .get(Constants.COLLECTION_RESOURCE);
+            } else {
+                return Activator.getDefault().getImageRegistry()
+                        .get(Constants.SINGLE_RESOURCE);
+            }
+        }
+    }
+
+    @Override
+    protected void okPressed() {
+        if (selectedResourceList.isEmpty()) {
+            MessageDialog.openInformation(
+                    Display.getDefault().getActiveShell(),
+                    "No selection done.", "No resources are selected.");
+            return;
+        }
+        close();
+    }
+
+    @Override
+    public boolean isHelpAvailable() {
+        return false;
+    }
+}
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddResourcesToCollectionPage.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddResourcesToCollectionPage.java
new file mode 100644 (file)
index 0000000..d745c38
--- /dev/null
@@ -0,0 +1,169 @@
+package oic.simulator.serviceprovider.view.dialogs;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import oic.simulator.serviceprovider.Activator;
+import oic.simulator.serviceprovider.model.CollectionResource;
+import oic.simulator.serviceprovider.model.Resource;
+import oic.simulator.serviceprovider.model.SingleResource;
+import oic.simulator.serviceprovider.utils.Constants;
+
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTreeViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Group;
+
+public class AddResourcesToCollectionPage extends WizardPage {
+
+    private CheckboxTreeViewer treeViewer;
+
+    Set<Resource>              selectedResourceList;
+
+    protected AddResourcesToCollectionPage() {
+        super("Add Resources To Collection");
+        selectedResourceList = new HashSet<Resource>();
+    }
+
+    @Override
+    public void createControl(Composite parent) {
+        setPageComplete(false);
+        setTitle(Constants.COLLECTION_RESOURCE_ADD_OTHER_RESOURCES_PAGE_TITLE);
+        setMessage(Constants.COLLECTION_RESOURCE_ADD_OTHER_RESOURCES_PAGE_MESSAGE);
+
+        Composite container = new Composite(parent, SWT.NONE);
+        GridLayout gridLayout = new GridLayout();
+        container.setLayout(gridLayout);
+        GridData gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        gd.heightHint = 300;
+        container.setLayoutData(gd);
+
+        Group resourceGroup = new Group(container, SWT.NONE);
+
+        Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
+
+        resourceGroup.setLayout(new GridLayout());
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        gd.heightHint = 300;
+        resourceGroup.setLayoutData(gd);
+
+        treeViewer = new CheckboxTreeViewer(resourceGroup);
+        treeViewer.getTree().setBackground(color);
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        gd.grabExcessVerticalSpace = true;
+        gd.verticalAlignment = SWT.FILL;
+        // gd.heightHint = 300;
+        treeViewer.getTree().setLayoutData(gd);
+        treeViewer.setContentProvider(new TreeContentProvider());
+        treeViewer.setLabelProvider(new TreeLabelProvider());
+        treeViewer.setInput(new Object());
+        treeViewer.addCheckStateListener(new ICheckStateListener() {
+
+            @Override
+            public void checkStateChanged(CheckStateChangedEvent e) {
+                Resource res = (Resource) e.getElement();
+                if (null != res) {
+                    if (e.getChecked()) {
+                        selectedResourceList.add(res);
+                        System.out.println("Checked" + res.getResourceName());
+                    } else {
+                        selectedResourceList.remove(res);
+                        System.out.println("Unchecked:" + res.getResourceName());
+                    }
+                }
+            }
+        });
+
+        setControl(container);
+    }
+
+    @Override
+    public IWizardPage getNextPage() {
+        return null;
+    }
+
+    public Set<Resource> getSelectedResourceList() {
+        return selectedResourceList;
+    }
+
+    class TreeContentProvider implements ITreeContentProvider {
+
+        @Override
+        public void dispose() {
+        }
+
+        @Override
+        public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
+        }
+
+        @Override
+        public Object[] getChildren(Object parent) {
+            System.out.println("getChildren()");
+
+            return null;
+        }
+
+        @Override
+        public Object[] getElements(Object parent) {
+            List<Resource> resList;
+            resList = Activator.getDefault().getResourceManager()
+                    .getResourceList();
+            if (null == resList) {
+                resList = new ArrayList<Resource>();
+            }
+            return resList.toArray();
+        }
+
+        @Override
+        public Object getParent(Object child) {
+            return null;
+        }
+
+        @Override
+        public boolean hasChildren(Object parent) {
+            return false;
+        }
+    }
+
+    class TreeLabelProvider extends LabelProvider {
+        @Override
+        public String getText(Object element) {
+            Resource res = (Resource) element;
+            return res.getResourceName();
+        }
+
+        @Override
+        public Image getImage(Object element) {
+            if (element instanceof SingleResource) {
+                return Activator.getDefault().getImageRegistry()
+                        .get(Constants.SINGLE_RESOURCE);
+            } else if (element instanceof CollectionResource) {
+                return Activator.getDefault().getImageRegistry()
+                        .get(Constants.COLLECTION_RESOURCE);
+            } else {
+                return Activator.getDefault().getImageRegistry()
+                        .get(Constants.DEVICE);
+            }
+        }
+    }
+}
index e2bb48f..f6ab64b 100644 (file)
@@ -19,7 +19,7 @@ package oic.simulator.serviceprovider.view.dialogs;
 import java.util.Iterator;
 import java.util.List;
 
-import oic.simulator.serviceprovider.resource.AutomationSettingHelper;
+import oic.simulator.serviceprovider.model.AutomationSettingHelper;
 import oic.simulator.serviceprovider.utils.Constants;
 
 import org.eclipse.jface.dialogs.TitleAreaDialog;
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CollectionResourceBasicDetailsPage.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CollectionResourceBasicDetailsPage.java
new file mode 100644 (file)
index 0000000..5024c6d
--- /dev/null
@@ -0,0 +1,337 @@
+package oic.simulator.serviceprovider.view.dialogs;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import oic.simulator.serviceprovider.Activator;
+import oic.simulator.serviceprovider.utils.Constants;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.window.Window;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.List;
+import org.eclipse.swt.widgets.Text;
+
+public class CollectionResourceBasicDetailsPage extends WizardPage {
+
+    private Text        resNameTxt;
+    private Text        resUriTxt;
+    private List        resTypeslist;
+    private Button      addToListBtn;
+    private Button      remFromListBtn;
+    private Button      observeBtn;
+    // private Button startBtn;
+
+    private String      resName;
+    private String      resURI;
+    private Set<String> resTypes;
+    // private boolean start;
+    private boolean     observable;
+    private boolean     anyResourceExist;
+
+    protected CollectionResourceBasicDetailsPage() {
+        super("Basic Details");
+        resTypes = new HashSet<String>();
+        anyResourceExist = Activator.getDefault().getResourceManager()
+                .isAnyResourceExist();
+    }
+
+    @Override
+    public void createControl(Composite parent) {
+        setPageComplete(false);
+        if (anyResourceExist)
+            setTitle(Constants.COLLECTION_RESOURCE_BASIC_DETAILS_PAGE_TITLE2);
+        else
+            setTitle(Constants.COLLECTION_RESOURCE_BASIC_DETAILS_PAGE_TITLE1);
+        setMessage(Constants.COLLECTION_RESOURCE_BASIC_DETAILS_PAGE_MESSAGE);
+
+        Composite container = new Composite(parent, SWT.NONE);
+        GridLayout gridLayout = new GridLayout();
+        container.setLayout(gridLayout);
+        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        container.setLayoutData(gd);
+
+        Group resDetGrp = new Group(container, SWT.NONE);
+        resDetGrp.setText("Resource Details");
+        gridLayout = new GridLayout(4, false);
+        resDetGrp.setLayout(gridLayout);
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        resDetGrp.setLayoutData(gd);
+
+        Label resNameLbl = new Label(resDetGrp, SWT.NULL);
+        resNameLbl.setText(Constants.RESOURCE_NAME);
+        gd = new GridData();
+        resNameLbl.setLayoutData(gd);
+
+        resNameTxt = new Text(resDetGrp, SWT.BORDER);
+        gd = new GridData();
+        // gd.widthHint = 300;
+        gd.horizontalAlignment = SWT.FILL;
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalSpan = 3;
+        resNameTxt.setLayoutData(gd);
+        resNameTxt.setFocus();
+
+        Label resUriLbl = new Label(resDetGrp, SWT.NULL);
+        resUriLbl.setText(Constants.RESOURCE_URI);
+
+        resUriTxt = new Text(resDetGrp, SWT.BORDER);
+        gd = new GridData();
+        // gd.widthHint = 300;
+        gd.horizontalSpan = 3;
+        gd.horizontalAlignment = SWT.FILL;
+        gd.grabExcessHorizontalSpace = true;
+        resUriTxt.setLayoutData(gd);
+        /*
+         * Composite resTypesComp = new Composite(compContent, SWT.NONE);
+         * gridLayout = new GridLayout(3, false);
+         * resTypesComp.setLayout(gridLayout); gd = new GridData();
+         * gd.grabExcessHorizontalSpace = true; gd.horizontalAlignment =
+         * SWT.FILL; resTypesComp.setLayoutData(gd);
+         */
+
+        Label resTypesLbl = new Label(resDetGrp, SWT.NULL);
+        resTypesLbl.setText(Constants.RESOURCE_TYPES);
+
+        resTypeslist = new List(resDetGrp, SWT.BORDER | SWT.MULTI
+                | SWT.V_SCROLL);
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        gd.horizontalSpan = 2;
+        gd.heightHint = 100;
+        /* gd.widthHint = 200; */
+        resTypeslist.setLayoutData(gd);
+        // resTypeslist.setBackground(new Color());
+
+        Composite resTypesActionsComp = new Composite(resDetGrp, SWT.NONE);
+        gridLayout = new GridLayout();
+        resTypesActionsComp.setLayout(gridLayout);
+        gd = new GridData();
+        gd.verticalAlignment = SWT.TOP;
+        /*
+         * gd.grabExcessHorizontalSpace = true; gd.horizontalAlignment =
+         * SWT.FILL;
+         */
+        resTypesActionsComp.setLayoutData(gd);
+
+        addToListBtn = new Button(resTypesActionsComp, SWT.PUSH);
+        addToListBtn.setText("Add");
+        gd = new GridData();
+        gd.widthHint = 70;
+        addToListBtn.setLayoutData(gd);
+
+        remFromListBtn = new Button(resTypesActionsComp, SWT.PUSH);
+        remFromListBtn.setText("Remove");
+        gd = new GridData();
+        gd.widthHint = 70;
+        remFromListBtn.setLayoutData(gd);
+        remFromListBtn.setEnabled(false);
+
+        Group otherOptionsGrp = new Group(container, SWT.NONE);
+        otherOptionsGrp.setText("Other options");
+        gridLayout = new GridLayout();
+        otherOptionsGrp.setLayout(gridLayout);
+        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        otherOptionsGrp.setLayoutData(gd);
+
+        observeBtn = new Button(otherOptionsGrp, SWT.CHECK);
+        observeBtn.setText("Observable");
+        observeBtn.setSelection(true);
+        observable = true;
+
+        /*
+         * startBtn = new Button(otherOptionsGrp, SWT.CHECK);
+         * startBtn.setText("Start the resource immediately after creation");
+         * startBtn.setSelection(true);
+         */
+
+        addUiListeners();
+
+        setControl(container);
+    }
+
+    private void addUiListeners() {
+
+        resUriTxt.addModifyListener(new ModifyListener() {
+            @Override
+            public void modifyText(ModifyEvent arg0) {
+                resURI = resUriTxt.getText();
+                if (null == resURI) {
+                    return;
+                }
+                if (anyResourceExist)
+                    getWizard().getContainer().updateButtons();
+                else
+                    setPageComplete(isSelectionDone());
+            }
+        });
+
+        resNameTxt.addModifyListener(new ModifyListener() {
+            @Override
+            public void modifyText(ModifyEvent arg0) {
+                resName = resNameTxt.getText();
+                if (null == resName) {
+                    return;
+                }
+                if (anyResourceExist)
+                    getWizard().getContainer().updateButtons();
+                else
+                    setPageComplete(isSelectionDone());
+            }
+        });
+
+        addToListBtn.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                SingleTextInputDialog dialog = new SingleTextInputDialog(
+                        getShell(), "Add Resource Type", "Resource Type");
+                if (dialog.open() == Window.OK) {
+                    System.out.println(dialog.getValue());
+                    String resType = dialog.getValue();
+                    // Duplicate check.
+                    if (resTypes.contains(resType)) {
+                        MessageDialog.openError(Display.getDefault()
+                                .getActiveShell(), "Duplicate value",
+                                "value already exist.");
+                        return;
+                    }
+                    resTypeslist.add(resType);
+                    resTypeslist.deselectAll();
+                    resTypeslist.select(resTypeslist.getItemCount() - 1);
+                    resTypeslist.showSelection();
+                    remFromListBtn.setEnabled(true);
+                    resTypes.add(resType);
+                    if (anyResourceExist)
+                        getWizard().getContainer().updateButtons();
+                    else
+                        setPageComplete(isSelectionDone());
+                }
+            }
+        });
+
+        remFromListBtn.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                int[] selection = resTypeslist.getSelectionIndices();
+                String[] selectionStr = resTypeslist.getSelection();
+                if (null != selection && selection.length > 0) {
+                    resTypeslist.remove(selection);
+                    for (String selected : selectionStr) {
+                        resTypes.remove(selected);
+                    }
+                }
+                changeVisibility();
+                if (anyResourceExist)
+                    getWizard().getContainer().updateButtons();
+                else
+                    setPageComplete(isSelectionDone());
+            }
+        });
+
+        resTypeslist.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                changeVisibility();
+            }
+        });
+
+        observeBtn.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                observable = observeBtn.getSelection();
+            }
+        });
+
+        /*
+         * startBtn.addSelectionListener(new SelectionAdapter() {
+         * 
+         * @Override public void widgetSelected(SelectionEvent e) { start =
+         * startBtn.getSelection(); } });
+         */
+    }
+
+    private void changeVisibility() {
+        int[] selection = resTypeslist.getSelectionIndices();
+        if (null != selection && selection.length > 0) {
+            remFromListBtn.setEnabled(true);
+        } else {
+            remFromListBtn.setEnabled(false);
+        }
+    }
+
+    @Override
+    public boolean canFlipToNextPage() {
+        System.out.println("canFlipToNextPage()");
+        if (!anyResourceExist) {
+            return false;
+        }
+        return isSelectionDone();
+    }
+
+    public boolean isSelectionDone() {
+        if (null == resName || resName.trim().length() < 1 || null == resURI
+                || resURI.trim().length() < 1 || null == resTypes
+                || resTypes.size() < 1) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public IWizardPage getNextPage() {
+        // Checking whether the uri is used by any other resource.
+        if (Activator.getDefault().getResourceManager().isResourceExist(resURI)) {
+            MessageDialog
+                    .openError(getShell(), "Resource URI in use",
+                            "Entered resource URI is in use. Please try a different one.");
+            // TODO: Instead of MessageDialog, errors may be shown on wizard
+            // itself.
+            return null;
+        }
+        if (anyResourceExist) {
+            return ((CreateResourceWizard) getWizard())
+                    .getAddResourcesToCollectionPage();
+        }
+        return null;
+    }
+
+    public String getResName() {
+        return resName;
+    }
+
+    public String getResURI() {
+        return resURI;
+    }
+
+    public Set<String> getResTypes() {
+        return resTypes;
+    }
+
+    /*
+     * public boolean isStart() { return start; }
+     */
+
+    public boolean isObservable() {
+        return observable;
+    }
+
+    public boolean isAnyResourceExist() {
+        return anyResourceExist;
+    }
+}
index 5a11cc0..9098bcf 100644 (file)
 
 package oic.simulator.serviceprovider.view.dialogs;
 
+import java.lang.reflect.InvocationTargetException;
 import java.net.URL;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
 
 import oic.simulator.serviceprovider.Activator;
+import oic.simulator.serviceprovider.manager.UiListenerHandler;
+import oic.simulator.serviceprovider.model.AttributeHelper;
+import oic.simulator.serviceprovider.model.CollectionResource;
+import oic.simulator.serviceprovider.model.LocalResourceAttribute;
+import oic.simulator.serviceprovider.model.Resource;
+import oic.simulator.serviceprovider.model.ResourceType;
+import oic.simulator.serviceprovider.model.SingleResource;
+import oic.simulator.serviceprovider.utils.Utility;
+import oic.simulator.serviceprovider.view.dialogs.MainPage.ResourceOption;
 
 import org.eclipse.core.runtime.FileLocator;
 import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.wizard.IWizardPage;
 import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.oic.simulator.ILogger.Level;
+import org.oic.simulator.SimulatorException;
 
 /**
  * This class creates a UI wizard for create resource operation.
  */
 public class CreateResourceWizard extends Wizard {
 
-    private CreateResourcePage page;
+    private MainPage                           mainPage;
+    private SimpleResourceBasicDetailsPage     simpleResourceBasicDetailsPage;
+    private SimpleResourceAddAttributePage     simpleResourceAddAttributePage;
+    private SimpleResourceOtherDetailsPage     simpleResourceOtherDetailsPage;
+    private CollectionResourceBasicDetailsPage collectionResourceBasicDetailsPage;
+    private AddResourcesToCollectionPage       addResourcesToCollectionPage;
+    private LoadRamlPage                       loadRamlPage;
+    private UpdatePropertiesPage               updatePropPage;
+    private DevicePage                         devicePage;
+    private StartStopResourcePage              startStopPage;
+
+    // private SingleResource simResource;
+    private String                             status;
+
+    private WizardDialog                       wizDialog;
+    private boolean                            dlgForceClosed;
 
     public CreateResourceWizard() {
         setWindowTitle("Create resources");
@@ -39,30 +76,544 @@ public class CreateResourceWizard extends Wizard {
         URL find = FileLocator.find(Activator.getDefault().getBundle(), path,
                 null);
         setDefaultPageImageDescriptor(ImageDescriptor.createFromURL(find));
+
+        setNeedsProgressMonitor(true);
     }
 
     @Override
     public void addPages() {
-        page = new CreateResourcePage();
-        addPage(page);
+        mainPage = new MainPage();
+        simpleResourceBasicDetailsPage = new SimpleResourceBasicDetailsPage();
+        simpleResourceAddAttributePage = new SimpleResourceAddAttributePage();
+        simpleResourceOtherDetailsPage = new SimpleResourceOtherDetailsPage();
+        collectionResourceBasicDetailsPage = new CollectionResourceBasicDetailsPage();
+        addResourcesToCollectionPage = new AddResourcesToCollectionPage();
+        loadRamlPage = new LoadRamlPage();
+        updatePropPage = new UpdatePropertiesPage();
+        devicePage = new DevicePage();
+        startStopPage = new StartStopResourcePage();
+
+        addPage(mainPage);
+        addPage(simpleResourceBasicDetailsPage);
+        addPage(simpleResourceAddAttributePage);
+        addPage(simpleResourceOtherDetailsPage);
+        addPage(collectionResourceBasicDetailsPage);
+        if (Activator.getDefault().getResourceManager().isAnyResourceExist())
+            addPage(addResourcesToCollectionPage);
+        addPage(loadRamlPage);
+        addPage(updatePropPage);
+        addPage(devicePage);
+        addPage(startStopPage);
+    }
+
+    public void setWizardDialog(WizardDialog dlg) {
+        wizDialog = dlg;
+    }
+
+    public WizardDialog getWizardDialog() {
+        return wizDialog;
+    }
+
+    public boolean isDlgForceClosed() {
+        return dlgForceClosed;
+    }
+
+    public void setDlgForceClosed(boolean dlgForceClosed) {
+        this.dlgForceClosed = dlgForceClosed;
     }
 
     public String getConfigFilePath() {
-        if (null == page) {
+        if (null == loadRamlPage) {
             return null;
         }
-        return page.getConfigFilePath();
+        return loadRamlPage.getConfigFilePath();
     }
 
     public int getResourceCount() {
-        if (null == page) {
+        if (null == loadRamlPage) {
             return 0;
         }
-        return page.getResourceCount();
+        return loadRamlPage.getResourceCount();
+    }
+
+    @Override
+    public boolean canFinish() {
+        System.out.println("canFinish()");
+        IWizardPage curPage = this.getContainer().getCurrentPage();
+        System.out.println(curPage.getName());
+        if ((curPage == updatePropPage && ((mainPage.getResourceOption() == ResourceOption.SIMPLE_FROM_RAML) || !Activator
+                .getDefault().getResourceManager().isAnyResourceExist()))
+                || (curPage == collectionResourceBasicDetailsPage
+                        && !Activator.getDefault().getResourceManager()
+                                .isAnyResourceExist() && collectionResourceBasicDetailsPage
+                            .isSelectionDone())
+                || curPage == addResourcesToCollectionPage
+                || curPage == simpleResourceAddAttributePage
+                || (curPage == loadRamlPage && loadRamlPage.isSelectionDone() && loadRamlPage
+                        .isMultiResourceCreation()) || curPage == devicePage) {
+            return true;
+        }
+        return false;
     }
 
     @Override
     public boolean performFinish() {
+        System.out.println("performFinish()");
+        final IWizardPage curPage = this.getContainer().getCurrentPage();
+        System.out.println(curPage.getClass().getSimpleName());
+        if (curPage == simpleResourceAddAttributePage) { // Handling Simple
+            // Resource Creation
+            // without RAML
+            try {
+                getContainer().run(true, true, new IRunnableWithProgress() {
+
+                    @Override
+                    public void run(IProgressMonitor monitor)
+                            throws InvocationTargetException,
+                            InterruptedException {
+                        try {
+                            monitor.beginTask(
+                                    "Single Resource Creation Without RAML", 2);
+                            monitor.worked(1);
+                            createSingleResourceWithoutRAML();
+                            monitor.worked(1);
+                        } finally {
+                            monitor.done();
+                        }
+                    }
+                });
+            } catch (InvocationTargetException e) {
+                Activator.getDefault().getLogManager()
+                        .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
+                e.printStackTrace();
+            } catch (InterruptedException e) {
+                Activator.getDefault().getLogManager()
+                        .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
+                e.printStackTrace();
+            }
+        } else if (curPage == loadRamlPage) { // Handling multi-instance
+            // creation of simple resource
+            // with RAML
+            try {
+                getContainer().run(true, true, new IRunnableWithProgress() {
+
+                    @Override
+                    public void run(IProgressMonitor monitor)
+                            throws InvocationTargetException,
+                            InterruptedException {
+                        try {
+                            monitor.beginTask(
+                                    "Single Resource Creation(multi-instance) With RAML",
+                                    3);
+                            monitor.worked(1);
+                            createMultiInstanceSingleResourceWithoutRAML();
+                            monitor.worked(2);
+                        } finally {
+                            monitor.done();
+                        }
+                    }
+                });
+            } catch (InvocationTargetException e) {
+                Activator.getDefault().getLogManager()
+                        .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
+                e.printStackTrace();
+            } catch (InterruptedException e) {
+                Activator.getDefault().getLogManager()
+                        .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
+                e.printStackTrace();
+            }
+        } else if (curPage == updatePropPage) { // Handling the single instance
+            // creation of simple resource
+            // with RAML
+            // String resURI = updatePropPage.getResURI();
+            // Checking whether the uri is used by any other resource.
+            if (Activator.getDefault().getResourceManager()
+                    .isResourceExist(updatePropPage.getResURI())) {
+                MessageDialog
+                        .openError(getShell(), "Resource URI in use",
+                                "Entered resource URI is in use. Please try a different one.");
+                // TODO: Instead of MessageDialog, errors may be shown on wizard
+                // itself.
+                return false;
+            }
+            // Resource resource = loadRamlPage.getResource();
+            // resource.setResourceName(updatePropPage.getResName());
+            try {
+                getContainer().run(true, true, new IRunnableWithProgress() {
+
+                    @Override
+                    public void run(IProgressMonitor monitor)
+                            throws InvocationTargetException,
+                            InterruptedException {
+                        try {
+                            monitor.beginTask("Completing Resource Creation", 2);
+                            monitor.worked(1);
+                            completeResourceCreationWithRAML();
+                            monitor.worked(1);
+                        } finally {
+                            monitor.done();
+                        }
+                    }
+                });
+            } catch (InvocationTargetException e) {
+                Activator.getDefault().getLogManager()
+                        .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
+                e.printStackTrace();
+            } catch (InterruptedException e) {
+                Activator.getDefault().getLogManager()
+                        .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
+                e.printStackTrace();
+            }
+        } else if (curPage == collectionResourceBasicDetailsPage
+                || curPage == addResourcesToCollectionPage) { // Handling
+            // Collection
+            // Resource
+            // Creation
+            // without RAML
+            if (mainPage.getResourceOption() == ResourceOption.COLLECTION_FROM_RAML) {
+                Resource res = loadRamlPage.getResource();
+                if (null != res && res instanceof CollectionResource) {
+                    Set<Resource> selectedResources = addResourcesToCollectionPage
+                            .getSelectedResourceList();
+                    if (!selectedResources.isEmpty()) {
+                        int addedCount = Activator
+                                .getDefault()
+                                .getResourceManager()
+                                .addResourceToCollection(
+                                        (CollectionResource) res,
+                                        selectedResources);
+                        if (addedCount > 0) {
+
+                            status = "[" + addedCount + "/"
+                                    + selectedResources.size()
+                                    + "] resources added to the collection";
+
+                            UiListenerHandler.getInstance()
+                                    .resourceListUpdateUINotification(
+                                            ResourceType.COLLECTION);
+                        } else {
+                            status = "Failed to add resources to the collection";
+                        }
+                    }
+                }
+            } else {
+                // Checking whether the uri is used by any other resource.
+                if (Activator
+                        .getDefault()
+                        .getResourceManager()
+                        .isResourceExist(
+                                collectionResourceBasicDetailsPage.getResURI())) {
+                    MessageDialog
+                            .openError(getShell(), "Resource URI in use",
+                                    "Entered resource URI is in use. Please try a different one.");
+                    // TODO: Instead of MessageDialog, errors may be shown on
+                    // wizard
+                    // itself.
+                    return false;
+                }
+                try {
+                    getContainer().run(true, true, new IRunnableWithProgress() {
+
+                        @Override
+                        public void run(IProgressMonitor monitor)
+                                throws InvocationTargetException,
+                                InterruptedException {
+                            try {
+                                monitor.beginTask(
+                                        "Collection Resource Creation Without RAML",
+                                        3);
+                                monitor.worked(1);
+                                createCollectionResourceWithoutRAML((curPage == addResourcesToCollectionPage) ? true
+                                        : false);
+                                monitor.worked(1);
+                                if (curPage == addResourcesToCollectionPage) {
+                                    UiListenerHandler.getInstance()
+                                            .resourceListUpdateUINotification(
+                                                    ResourceType.COLLECTION);
+                                }
+                                monitor.worked(1);
+                            } finally {
+                                monitor.done();
+                            }
+                        }
+                    });
+                } catch (InvocationTargetException e) {
+                    Activator
+                            .getDefault()
+                            .getLogManager()
+                            .log(Level.ERROR.ordinal(), new Date(),
+                                    e.getMessage());
+                    e.printStackTrace();
+                } catch (InterruptedException e) {
+                    Activator
+                            .getDefault()
+                            .getLogManager()
+                            .log(Level.ERROR.ordinal(), new Date(),
+                                    e.getMessage());
+                    e.printStackTrace();
+                }
+            }
+        } else if (curPage == devicePage) {
+            final String devName = devicePage.getDeviceName();
+            final Set<Resource> resourceList = devicePage
+                    .getSelectedResourceList();
+            try {
+                getContainer().run(true, true, new IRunnableWithProgress() {
+
+                    @Override
+                    public void run(IProgressMonitor monitor)
+                            throws InvocationTargetException,
+                            InterruptedException {
+                        try {
+                            monitor.beginTask("Device Creation", 3);
+                            monitor.worked(1);
+                            createDevice(devName, resourceList);
+                            monitor.worked(1);
+                            UiListenerHandler.getInstance()
+                                    .resourceListUpdateUINotification(
+                                            ResourceType.DEVICE);
+                            status = "Device Created.";
+                            monitor.worked(1);
+                        } finally {
+                            monitor.done();
+                        }
+                    }
+                });
+            } catch (InvocationTargetException e) {
+                Activator.getDefault().getLogManager()
+                        .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
+                e.printStackTrace();
+            } catch (InterruptedException e) {
+                Activator.getDefault().getLogManager()
+                        .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
+                e.printStackTrace();
+            }
+        }
         return true;
     }
+
+    public MainPage getMainPage() {
+        return mainPage;
+    }
+
+    public SimpleResourceBasicDetailsPage getSimpleResourceBasicDetailsPage() {
+        return simpleResourceBasicDetailsPage;
+    }
+
+    public SimpleResourceAddAttributePage getSimpleResourceAddAttributePage() {
+        return simpleResourceAddAttributePage;
+    }
+
+    public CollectionResourceBasicDetailsPage getCollectionResourceBasicDetailsPage() {
+        return collectionResourceBasicDetailsPage;
+    }
+
+    public SimpleResourceOtherDetailsPage getSimpleResourceOtherDetailsPage() {
+        return simpleResourceOtherDetailsPage;
+    }
+
+    public AddResourcesToCollectionPage getAddResourcesToCollectionPage() {
+        return addResourcesToCollectionPage;
+    }
+
+    public LoadRamlPage getLoadRamlPage() {
+        return loadRamlPage;
+    }
+
+    public UpdatePropertiesPage getUpdatePropPage() {
+        return updatePropPage;
+    }
+
+    public DevicePage getDevicePage() {
+        return devicePage;
+    }
+
+    public StartStopResourcePage getStartStopPage() {
+        return startStopPage;
+    }
+
+    /*
+     * public SingleResource getSimResource() { return simResource; }
+     * 
+     * public void setSimResource(SingleResource simResource) { this.simResource
+     * = simResource; }
+     */
+
+    public void setStatus(String status) {
+        this.status = status;
+    }
+
+    public String getStatus() {
+        return status;
+    }
+
+    /*
+     * public SingleResource getCreatedResource() { return simResource; }
+     */
+
+    private void createSingleResourceWithoutRAML() {
+        SingleResource resource = new SingleResource();
+        // Basic resource details
+        resource.setResourceURI(simpleResourceBasicDetailsPage.getResURI());
+        resource.setResourceName(simpleResourceBasicDetailsPage.getResName());
+        resource.setResourceTypes(simpleResourceBasicDetailsPage.getResTypes());
+        resource.setObservable(simpleResourceBasicDetailsPage.isObservable());
+        // resource.setStarted(simpleResourceBasicDetailsPage.isStart());
+
+        // Resource Attributes
+        Map<String, LocalResourceAttribute> attributes = new HashMap<String, LocalResourceAttribute>();
+        Set<AttributeHelper> attributeSet = simpleResourceAddAttributePage
+                .getAttributes();
+        if (null != attributeSet && !attributeSet.isEmpty()) {
+            Iterator<AttributeHelper> itr = attributeSet.iterator();
+            AttributeHelper attHelper;
+            LocalResourceAttribute localResAtt;
+            // List<String> attValues;
+            while (itr.hasNext()) {
+                attHelper = itr.next();
+                if (null != attHelper) {
+                    localResAtt = attHelper.convertToLocalResourceAttribute();
+
+                    // Set the attribute value list.
+                    /*
+                     * attValues =
+                     * Activator.getDefault().getResourceManager().getValueList
+                     * (localResAtt); localResAtt.setAttValues(attValues);
+                     */
+                    attributes.put(
+                            localResAtt.getResourceAttributeRef().name(),
+                            localResAtt);
+                }
+            }
+            resource.setResourceAttributes(attributes);
+        }
+
+        // Request types
+        resource.setGetAllowed(simpleResourceOtherDetailsPage.isGetChecked());
+        resource.setPutAllowed(simpleResourceOtherDetailsPage.isPutChecked());
+        resource.setPostAllowed(simpleResourceOtherDetailsPage.isPostChecked());
+
+        // Call method of ResourceManager and update the response in the status
+        // string.
+        try {
+            boolean result = Activator.getDefault().getResourceManager()
+                    .createSingleResource(resource);
+            if (result) {
+                status = "Resource created.";
+                resource.printResourceInfo();
+            } else {
+                status = "Failed to create resource.";
+            }
+        } catch (SimulatorException e) {
+            status = "Failed to create resource.\n"
+                    + Utility.getSimulatorErrorString(e, null);
+        }
+    }
+
+    private void completeResourceCreationWithRAML() {
+        try {
+            boolean result;
+            Resource res = loadRamlPage.getResource();
+            if (res instanceof SingleResource) {
+                result = Activator
+                        .getDefault()
+                        .getResourceManager()
+                        .completeSingleResourceCreationByRAML(res,
+                                updatePropPage.getResURI(),
+                                updatePropPage.getResName(), false);
+            } else {
+                result = Activator
+                        .getDefault()
+                        .getResourceManager()
+                        .completeCollectionResourceCreationByRAML(res,
+                                updatePropPage.getResURI(),
+                                updatePropPage.getResName());
+            }
+
+            if (result) {
+                status = "Resource created.";
+                loadRamlPage.getResource().printResourceInfo();
+            } else {
+                status = "Failed to create resource.";
+            }
+        } catch (SimulatorException e) {
+            status = "Failed to create resource.\n"
+                    + Utility.getSimulatorErrorString(e, null);
+        }
+    }
+
+    private void createMultiInstanceSingleResourceWithoutRAML() {
+        try {
+            int toCreateCount = loadRamlPage.getResourceCount();
+            int resCreatedCount = Activator
+                    .getDefault()
+                    .getResourceManager()
+                    .createSingleResourceMultiInstances(
+                            loadRamlPage.getConfigFilePath(), toCreateCount);
+            if (resCreatedCount > 0) {
+                status = "[" + resCreatedCount + " out of " + toCreateCount
+                        + "]";
+                status += ((resCreatedCount == 1) ? "resource" : "resources")
+                        + " created successfully.";
+            } else {
+                status = "Failed to create resources.";
+            }
+        } catch (SimulatorException e) {
+            status = "Failed to create resource.\n"
+                    + Utility.getSimulatorErrorString(e, null);
+        }
+    }
+
+    private void createCollectionResourceWithoutRAML(boolean childResExist) {
+        CollectionResource resource = new CollectionResource();
+        // Basic resource details
+        resource.setResourceURI(collectionResourceBasicDetailsPage.getResURI());
+        resource.setResourceName(collectionResourceBasicDetailsPage
+                .getResName());
+        resource.setResourceTypes(collectionResourceBasicDetailsPage
+                .getResTypes());
+        resource.setObservable(collectionResourceBasicDetailsPage
+                .isObservable());
+        // resource.setStarted(simpleResourceBasicDetailsPage.isStart());
+
+        // Call method of ResourceManager and update the response in the status
+        // string.
+        try {
+            boolean result = Activator.getDefault().getResourceManager()
+                    .createCollectionResource(resource);
+            if (result) {
+                status = "Resource created.";
+                // Adding child resources.
+                if (childResExist) {
+                    Set<Resource> selectedResources = addResourcesToCollectionPage
+                            .getSelectedResourceList();
+                    if (!selectedResources.isEmpty()) {
+                        int addedCount = Activator
+                                .getDefault()
+                                .getResourceManager()
+                                .addResourceToCollection(resource,
+                                        selectedResources);
+                        if (addedCount > 0) {
+                            status = "[" + addedCount + "/"
+                                    + selectedResources.size()
+                                    + "] resources added to the collection";
+                        } else {
+                            status = "Failed to add resources to the collection.";
+                        }
+                    }
+                }
+            } else {
+                status = "Failed to create resource.";
+            }
+        } catch (SimulatorException e) {
+            status = "Failed to create resource.\n"
+                    + Utility.getSimulatorErrorString(e, null);
+        }
+    }
+
+    private void createDevice(String deviceName, Set<Resource> childs) {
+        Activator.getDefault().getResourceManager()
+                .createDevice(deviceName, childs);
+    }
+
 }
\ No newline at end of file
index be7dae8..9203c52 100644 (file)
 
 package oic.simulator.serviceprovider.view.dialogs;
 
-import java.util.Iterator;
+import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 import oic.simulator.serviceprovider.Activator;
-import oic.simulator.serviceprovider.resource.DeleteCategory;
+import oic.simulator.serviceprovider.model.CollectionResource;
+import oic.simulator.serviceprovider.model.Resource;
+import oic.simulator.serviceprovider.model.SingleResource;
 import oic.simulator.serviceprovider.utils.Constants;
 
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTreeViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.jface.wizard.WizardPage;
 import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.CCombo;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
 
 /**
  * This class shows UI for deleting resources.
  */
 public class DeleteResourcePage extends WizardPage {
 
-    private Button         allRbtn;
-    private Button         byTypeRbtn;
-    private Button         byUriRbtn;
+    private CheckboxTreeViewer       collectionTreeViewer;
+    private CheckboxTreeViewer       singleTreeViewer;
 
-    private CCombo         resourceTypeCmb;
-    private Text           resourceUriTxt;
+    private Button                   selectAllSingle;
+    private Button                   selectAllCollection;
+    private Button                   deselectAllSingle;
+    private Button                   deselectAllCollection;
 
-    private DeleteCategory deleteCategory;
+    private List<CollectionResource> collectionSourceList;
+    private List<SingleResource>     singleSourceList;
 
-    // It will hold either the resource type or resource uri
-    private String         deleteCandidate;
+    private Set<CollectionResource>  selectedCollections;
+    private Set<SingleResource>      selectedSingles;
 
     protected DeleteResourcePage() {
-        super("Delete Resource");
+        super("Delete Resources");
+
+        singleSourceList = Activator.getDefault().getResourceManager()
+                .getSingleResourceList();
+        collectionSourceList = Activator.getDefault().getResourceManager()
+                .getCollectionResourceList();
+
+        selectedCollections = new HashSet<CollectionResource>();
+        selectedSingles = new HashSet<SingleResource>();
     }
 
     @Override
     public void createControl(Composite parent) {
         setPageComplete(false);
-        setTitle(Constants.DELETE_PAGE_TITLE);
-        setMessage(Constants.DELETE_PAGE_MESSAGE);
+        setTitle("Delete Resources");
+        setMessage("Select one or more single and/or collection resources for deletion.");
 
-        Composite compContent = new Composite(parent, SWT.NONE);
-        compContent.setLayout(new GridLayout(1, false));
-        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
-        compContent.setLayoutData(gd);
-
-        Group group = new Group(compContent, SWT.NONE);
-        group.setText("Select Category");
-        GridLayout gridLayout = new GridLayout(2, false);
-        gridLayout.verticalSpacing = 15;
-        gridLayout.marginTop = 10;
-        gridLayout.marginLeft = 10;
-        group.setLayout(gridLayout);
-        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
-        group.setLayoutData(gd);
+        Composite container = new Composite(parent, SWT.NONE);
+        container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+        GridLayout layout = new GridLayout(5, true);
+        container.setLayout(layout);
 
-        allRbtn = new Button(group, SWT.RADIO);
-        allRbtn.setText("All resources");
-        gd = new GridData();
+        createSingleResourcesArea(container);
+
+        createCollectionResourcesArea(container);
+
+        createSelectionControls(container);
+
+        setControl(container);
+    }
+
+    private void createSingleResourcesArea(Composite container) {
+        Composite singleContainer = new Composite(container, SWT.NONE);
+        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
         gd.horizontalSpan = 2;
-        gd.widthHint = 200;
-        allRbtn.setLayoutData(gd);
+        singleContainer.setLayoutData(gd);
+        GridLayout layout = new GridLayout();
+        singleContainer.setLayout(layout);
 
-        byTypeRbtn = new Button(group, SWT.RADIO);
-        byTypeRbtn.setText("All (By resource type)");
-        gd = new GridData();
-        gd.widthHint = 200;
-        byTypeRbtn.setLayoutData(gd);
+        Label lbl = new Label(singleContainer, SWT.NONE);
+        lbl.setText("Single Resources:");
+        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        // gd.grabExcessHorizontalSpace = true;
+        // gd.horizontalAlignment = SWT.FILL;
+        lbl.setLayoutData(gd);
 
-        resourceTypeCmb = new CCombo(group, SWT.READ_ONLY | SWT.BORDER);
-        gd = new GridData();
-        gd.widthHint = 200;
-        resourceTypeCmb.setLayoutData(gd);
+        Group resourceGroup = new Group(singleContainer, SWT.NONE);
+
+        Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
 
-        byUriRbtn = new Button(group, SWT.RADIO);
-        byUriRbtn.setText("By Resource URI");
+        resourceGroup.setLayout(new GridLayout());
         gd = new GridData();
-        gd.widthHint = 200;
-        byUriRbtn.setLayoutData(gd);
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        gd.heightHint = 300;
+        gd.horizontalSpan = 2;
+        resourceGroup.setLayoutData(gd);
 
-        resourceUriTxt = new Text(group, SWT.BORDER);
+        singleTreeViewer = new CheckboxTreeViewer(resourceGroup);
+        singleTreeViewer.getTree().setBackground(color);
         gd = new GridData();
-        gd.widthHint = 300;
-        resourceUriTxt.setLayoutData(gd);
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        gd.grabExcessVerticalSpace = true;
+        gd.verticalAlignment = SWT.FILL;
+        // gd.heightHint = 300;
+        singleTreeViewer.getTree().setLayoutData(gd);
+        singleTreeViewer
+                .setContentProvider(new SingleResourceContentProvider());
+        singleTreeViewer.setLabelProvider(new TreeLabelProvider());
+        singleTreeViewer.setInput(new Object());
+        singleTreeViewer.addCheckStateListener(new ICheckStateListener() {
 
-        // Setting the initial visibility of controls
-        allRbtn.setSelection(false);
-        byTypeRbtn.setSelection(false);
-        byUriRbtn.setSelection(false);
+            @Override
+            public void checkStateChanged(CheckStateChangedEvent e) {
+                SingleResource res = (SingleResource) e.getElement();
+                if (null != res) {
+                    if (e.getChecked()) {
+                        selectedSingles.add(res);
+                        System.out.println("Checked" + res.getResourceName());
+                    } else {
+                        selectedSingles.remove(res);
+                        System.out.println("Unchecked:" + res.getResourceName());
+                    }
+                    setPageComplete(isSelectionDone());
+                }
+            }
+        });
+    }
 
-        resourceTypeCmb.setEnabled(false);
-        resourceUriTxt.setEnabled(false);
+    private void createCollectionResourcesArea(Composite container) {
+        Composite collectionContainer = new Composite(container, SWT.NONE);
+        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        gd.horizontalSpan = 2;
+        collectionContainer.setLayoutData(gd);
+        GridLayout layout = new GridLayout();
+        collectionContainer.setLayout(layout);
 
-        deleteCategory = DeleteCategory.NONE;
+        Label lbl = new Label(collectionContainer, SWT.NONE);
+        lbl.setText("Collection Resources:");
+        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        // gd.grabExcessHorizontalSpace = true;
+        // gd.horizontalAlignment = SWT.FILL;
+        lbl.setLayoutData(gd);
 
-        populateDataInUI();
+        Group resourceGroup = new Group(collectionContainer, SWT.NONE);
 
-        addUIListeners();
+        Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
 
-        setControl(compContent);
-    }
+        resourceGroup.setLayout(new GridLayout());
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        gd.heightHint = 300;
+        gd.horizontalSpan = 2;
+        resourceGroup.setLayoutData(gd);
 
-    private void populateDataInUI() {
-        // Populate Resourcetype in Combo
-        populateResourceTypeCombo();
-    }
+        collectionTreeViewer = new CheckboxTreeViewer(resourceGroup);
+        collectionTreeViewer.getTree().setBackground(color);
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        gd.grabExcessVerticalSpace = true;
+        gd.verticalAlignment = SWT.FILL;
+        // gd.heightHint = 300;
+        collectionTreeViewer.getTree().setLayoutData(gd);
+        collectionTreeViewer
+                .setContentProvider(new CollectionResourceContentProvider());
+        collectionTreeViewer.setLabelProvider(new TreeLabelProvider());
+        collectionTreeViewer.setInput(new Object());
+        collectionTreeViewer.addCheckStateListener(new ICheckStateListener() {
 
-    private void populateResourceTypeCombo() {
-        List<String> resourceTypeList;
-        resourceTypeList = Activator.getDefault().getResourceManager()
-                .getResourceTypeList();
-        if (null != resourceTypeList) {
-            Iterator<String> itr = resourceTypeList.iterator();
-            while (itr.hasNext()) {
-                resourceTypeCmb.add(itr.next());
+            @Override
+            public void checkStateChanged(CheckStateChangedEvent e) {
+                CollectionResource res = (CollectionResource) e.getElement();
+                if (null != res) {
+                    if (e.getChecked()) {
+                        selectedCollections.add(res);
+                        System.out.println("Checked" + res.getResourceName());
+                    } else {
+                        selectedCollections.remove(res);
+                        System.out.println("Unchecked:" + res.getResourceName());
+                    }
+                    setPageComplete(isSelectionDone());
+                }
             }
-        }
-
-        // By default, select the first item in the combo
-        if (resourceTypeCmb.getItemCount() > 0) {
-            resourceTypeCmb.select(0);
-            deleteCandidate = resourceTypeCmb.getText();
-        }
+        });
     }
 
-    public void addUIListeners() {
-        allRbtn.addSelectionListener(new SelectionAdapter() {
+    private void createSelectionControls(Composite container) {
+        Composite innerComp = new Composite(container, SWT.NULL);
+        GridLayout layout = new GridLayout();
+        // layout.verticalSpacing = 10;
+        layout.marginTop = 15;
+        innerComp.setLayout(layout);
+        GridData gd = new GridData();
+        gd.verticalAlignment = SWT.TOP;
+        innerComp.setLayoutData(gd);
+
+        selectAllSingle = new Button(innerComp, SWT.PUSH);
+        selectAllSingle.setText("Select All Single");
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        // gd.widthHint = 70;
+        selectAllSingle.setLayoutData(gd);
+        selectAllSingle.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
-                // Update the visibility of controls
-                resourceTypeCmb.setEnabled(false);
-                resourceUriTxt.setEnabled(false);
-
-                deleteCategory = DeleteCategory.ALL;
-                deleteCandidate = null;
-                setPageComplete(isSelectionDone());
+                check(singleTreeViewer, true);
             }
         });
 
-        byTypeRbtn.addSelectionListener(new SelectionAdapter() {
+        selectAllCollection = new Button(innerComp, SWT.PUSH);
+        selectAllCollection.setText("Select All Collection");
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        // gd.widthHint = 70;
+        selectAllCollection.setLayoutData(gd);
+        selectAllCollection.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
-                // Update the visibility of controls
-                resourceTypeCmb.setEnabled(true);
-                resourceUriTxt.setEnabled(false);
-
-                deleteCategory = DeleteCategory.BY_TYPE;
-                setPageComplete(isSelectionDone());
+                check(collectionTreeViewer, true);
             }
         });
 
-        byUriRbtn.addSelectionListener(new SelectionAdapter() {
+        deselectAllSingle = new Button(innerComp, SWT.PUSH);
+        deselectAllSingle.setText("Deselect All Single");
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        // gd.widthHint = 70;
+        deselectAllSingle.setLayoutData(gd);
+        deselectAllSingle.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
-                // Update the visibility of controls
-                resourceUriTxt.setEnabled(true);
-                resourceUriTxt.setFocus();
-                resourceTypeCmb.setEnabled(false);
-
-                deleteCategory = DeleteCategory.BY_URI;
-                setPageComplete(isSelectionDone());
+                check(singleTreeViewer, false);
             }
         });
 
-        resourceTypeCmb.addModifyListener(new ModifyListener() {
+        deselectAllCollection = new Button(innerComp, SWT.PUSH);
+        deselectAllCollection.setText("Deselect All Collection");
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        // gd.widthHint = 70;
+        deselectAllCollection.setLayoutData(gd);
+
+        deselectAllCollection.addSelectionListener(new SelectionAdapter() {
             @Override
-            public void modifyText(ModifyEvent arg0) {
-                setPageComplete(isSelectionDone());
+            public void widgetSelected(SelectionEvent e) {
+                check(collectionTreeViewer, false);
             }
         });
+    }
 
-        resourceUriTxt.addModifyListener(new ModifyListener() {
-            @Override
-            public void modifyText(ModifyEvent arg0) {
+    private void check(CheckboxTreeViewer viewer, boolean toCheck) {
+        Tree tree = viewer.getTree();
+        if (null != tree) {
+            TreeItem[] items = tree.getItems();
+            if (null != items && items.length > 0) {
+                Object obj;
+                for (TreeItem item : items) {
+                    obj = item.getData();
+                    if (null != obj) {
+                        viewer.setChecked(obj, toCheck);
+                        updateSelectionList((Resource) obj, toCheck);
+                    }
+                }
                 setPageComplete(isSelectionDone());
             }
-        });
+        }
     }
 
-    public boolean isSelectionDone() {
-        boolean done = false;
-        if (deleteCategory == DeleteCategory.ALL) {
-            done = true;
-        } else if (deleteCategory == DeleteCategory.BY_TYPE) {
-            deleteCandidate = resourceTypeCmb.getText();
-            if (null != deleteCandidate && deleteCandidate.length() > 0) {
-                done = true;
+    private void updateSelectionList(Resource res, boolean isChecked) {
+        if (res instanceof SingleResource) {
+            if (isChecked) {
+                selectedSingles.add((SingleResource) res);
+            } else {
+                selectedSingles.remove((SingleResource) res);
             }
-        } else if (deleteCategory == DeleteCategory.BY_URI) {
-            deleteCandidate = resourceUriTxt.getText();
-            if (null != deleteCandidate && deleteCandidate.length() > 0) {
-                done = true;
+        } else {
+            if (isChecked) {
+                selectedCollections.add((CollectionResource) res);
+            } else {
+                selectedCollections.remove((CollectionResource) res);
             }
         }
-        return done;
     }
 
-    public DeleteCategory getDeleteCategory() {
-        return deleteCategory;
+    public Set<SingleResource> getSelectedSingleResourcesList() {
+        return selectedSingles;
+    }
+
+    public Set<CollectionResource> getSelectedCollectionResourcesList() {
+        return selectedCollections;
+    }
+
+    class SingleResourceContentProvider implements ITreeContentProvider {
+
+        @Override
+        public void dispose() {
+        }
+
+        @Override
+        public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
+        }
+
+        @Override
+        public Object[] getChildren(Object parent) {
+            return null;
+        }
+
+        @Override
+        public Object[] getElements(Object parent) {
+            if (null == singleSourceList) {
+                singleSourceList = new ArrayList<SingleResource>();
+            }
+            return singleSourceList.toArray();
+        }
+
+        @Override
+        public Object getParent(Object child) {
+            return null;
+        }
+
+        @Override
+        public boolean hasChildren(Object parent) {
+            return false;
+        }
+    }
+
+    class CollectionResourceContentProvider implements ITreeContentProvider {
+
+        @Override
+        public void dispose() {
+        }
+
+        @Override
+        public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
+        }
+
+        @Override
+        public Object[] getChildren(Object parent) {
+            return null;
+        }
+
+        @Override
+        public Object[] getElements(Object parent) {
+            if (null == collectionSourceList) {
+                collectionSourceList = new ArrayList<CollectionResource>();
+            }
+            return collectionSourceList.toArray();
+        }
+
+        @Override
+        public Object getParent(Object child) {
+            return null;
+        }
+
+        @Override
+        public boolean hasChildren(Object parent) {
+            return false;
+        }
     }
 
-    public String getDeleteCandidate() {
-        return deleteCandidate;
+    class TreeLabelProvider extends LabelProvider {
+        @Override
+        public String getText(Object element) {
+            Resource res = (Resource) element;
+            return res.getResourceName();
+        }
+
+        @Override
+        public Image getImage(Object element) {
+            if (element instanceof CollectionResource) {
+                return Activator.getDefault().getImageRegistry()
+                        .get(Constants.COLLECTION_RESOURCE);
+            } else {
+                return Activator.getDefault().getImageRegistry()
+                        .get(Constants.SINGLE_RESOURCE);
+            }
+        }
     }
 
-    public void setFocusToTextBox() {
-        resourceUriTxt.setFocus();
+    public boolean isSelectionDone() {
+        boolean done = true;
+        Object obj[] = singleTreeViewer.getCheckedElements();
+        if (null == obj || obj.length < 1) {
+            obj = collectionTreeViewer.getCheckedElements();
+            if (null == obj || obj.length < 1) {
+                done = false;
+            }
+        }
+        return done;
     }
 }
\ No newline at end of file
index 4d079eb..4a2cc9e 100644 (file)
 
 package oic.simulator.serviceprovider.view.dialogs;
 
+import java.lang.reflect.InvocationTargetException;
 import java.net.URL;
+import java.util.Date;
+import java.util.Set;
 
 import oic.simulator.serviceprovider.Activator;
-import oic.simulator.serviceprovider.resource.DeleteCategory;
+import oic.simulator.serviceprovider.model.CollectionResource;
+import oic.simulator.serviceprovider.model.SingleResource;
 
 import org.eclipse.core.runtime.FileLocator;
 import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.Path;
-import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.jface.wizard.Wizard;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.PlatformUI;
+import org.oic.simulator.ILogger.Level;
+import org.oic.simulator.SimulatorException;
 
 /**
  * This class creates a UI wizard for delete resource operation.
@@ -37,6 +42,8 @@ public class DeleteResourceWizard extends Wizard {
 
     private DeleteResourcePage page;
 
+    private String             status;
+
     public DeleteResourceWizard() {
         setWindowTitle("Delete resources");
         IPath path = new Path("/icons/oic_logo_64x64.png");
@@ -56,45 +63,52 @@ public class DeleteResourceWizard extends Wizard {
         if (null == page) {
             return false;
         }
-        // Check the existence of the resource if the user has entered the uri
-        if (page.getDeleteCategory() == DeleteCategory.BY_URI) {
-            // Check whether the uri is in full form or short form
-            // If it is in short form, expand it to its full form.
-            String uri = page.getDeleteCandidate();
-            boolean dispName = Activator.getDefault().getResourceManager()
-                    .isDisplayName(uri);
-            if (dispName) {
-                uri = Activator.getDefault().getResourceManager()
-                        .getCompleteUriFromDisplayName(uri);
-            }
-            boolean exist = Activator.getDefault().getResourceManager()
-                    .isResourceExist(uri);
-            if (!exist) {
-                Shell activeShell = PlatformUI.getWorkbench().getDisplay()
-                        .getActiveShell();
-                MessageDialog dialog = new MessageDialog(activeShell,
-                        "Resource Not Found", null,
-                        "No resource exist with the given URI.",
-                        MessageDialog.INFORMATION, new String[] { "OK" }, 0);
-                dialog.open();
-                page.setFocusToTextBox();
-                return false;
-            }
-        }
-        return true;
-    }
+        try {
+            getContainer().run(true, true, new IRunnableWithProgress() {
 
-    public DeleteCategory getDeleteCategory() {
-        if (null == page) {
-            return DeleteCategory.NONE;
+                @Override
+                public void run(IProgressMonitor monitor)
+                        throws InvocationTargetException, InterruptedException {
+                    try {
+                        monitor.beginTask("Resource Deletion", 2);
+                        Set<CollectionResource> collectionResources = page
+                                .getSelectedCollectionResourcesList();
+                        if (null != collectionResources
+                                && collectionResources.size() > 0) {
+                            Activator
+                                    .getDefault()
+                                    .getResourceManager()
+                                    .removeCollectionResources(
+                                            collectionResources);
+                        }
+                        monitor.worked(1);
+                        Set<SingleResource> singleResources = page
+                                .getSelectedSingleResourcesList();
+                        if (null != singleResources
+                                && singleResources.size() > 0) {
+                            Activator.getDefault().getResourceManager()
+                                    .removeSingleResources(singleResources);
+                        }
+                        monitor.worked(1);
+                        status = "Resources deleted.";
+                    } catch (SimulatorException e) {
+                        status = "Failed to delete some of the resources. Please try again.";
+                    } finally {
+                        monitor.done();
+                    }
+                }
+            });
+        } catch (InvocationTargetException e) {
+            Activator.getDefault().getLogManager()
+                    .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
+        } catch (InterruptedException e) {
+            Activator.getDefault().getLogManager()
+                    .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
         }
-        return page.getDeleteCategory();
+        return true;
     }
 
-    public String getDeleteCandidate() {
-        if (null == page) {
-            return null;
-        }
-        return page.getDeleteCandidate();
+    public String getStatus() {
+        return status;
     }
 }
\ No newline at end of file
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DevicePage.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DevicePage.java
new file mode 100644 (file)
index 0000000..b6a194f
--- /dev/null
@@ -0,0 +1,207 @@
+package oic.simulator.serviceprovider.view.dialogs;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import oic.simulator.serviceprovider.Activator;
+import oic.simulator.serviceprovider.model.Resource;
+import oic.simulator.serviceprovider.model.SingleResource;
+import oic.simulator.serviceprovider.utils.Constants;
+
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTreeViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+public class DevicePage extends WizardPage {
+
+    private CheckboxTreeViewer treeViewer;
+
+    private Text               deviceNameTxt;
+
+    private String             deviceName;
+
+    Set<Resource>              selectedResourceList;
+
+    protected DevicePage() {
+        super("Devices");
+        selectedResourceList = new HashSet<Resource>();
+    }
+
+    @Override
+    public void createControl(Composite parent) {
+        setPageComplete(false);
+        setTitle(Constants.CREATE_DEVICE_PAGE_TITLE);
+        setMessage(Constants.CREATE_DEVICE_PAGE_MESSAGE);
+
+        Composite container = new Composite(parent, SWT.NONE);
+        GridLayout gridLayout = new GridLayout(2, false);
+        container.setLayout(gridLayout);
+        GridData gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        gd.heightHint = 300;
+        container.setLayoutData(gd);
+
+        Label deviceNameLbl = new Label(container, SWT.NULL);
+        deviceNameLbl.setText("Device Name");
+
+        deviceNameTxt = new Text(container, SWT.BORDER);
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        deviceNameTxt.setLayoutData(gd);
+
+        Group resourceGroup = new Group(container, SWT.NONE);
+
+        Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
+
+        resourceGroup.setLayout(new GridLayout());
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        gd.heightHint = 300;
+        gd.horizontalSpan = 2;
+        resourceGroup.setLayoutData(gd);
+
+        treeViewer = new CheckboxTreeViewer(resourceGroup);
+        treeViewer.getTree().setBackground(color);
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        gd.grabExcessVerticalSpace = true;
+        gd.verticalAlignment = SWT.FILL;
+        // gd.heightHint = 300;
+        treeViewer.getTree().setLayoutData(gd);
+        treeViewer.setContentProvider(new TreeContentProvider());
+        treeViewer.setLabelProvider(new TreeLabelProvider());
+        treeViewer.setInput(new Object());
+        treeViewer.addCheckStateListener(new ICheckStateListener() {
+
+            @Override
+            public void checkStateChanged(CheckStateChangedEvent e) {
+                Resource res = (Resource) e.getElement();
+                if (null != res) {
+                    if (e.getChecked()) {
+                        selectedResourceList.add(res);
+                        System.out.println("Checked" + res.getResourceName());
+                    } else {
+                        selectedResourceList.remove(res);
+                        System.out.println("Unchecked:" + res.getResourceName());
+                    }
+                }
+            }
+        });
+
+        setUiListeners();
+
+        setControl(container);
+    }
+
+    private void setUiListeners() {
+        deviceNameTxt.addModifyListener(new ModifyListener() {
+            @Override
+            public void modifyText(ModifyEvent e) {
+                deviceName = deviceNameTxt.getText();
+                setPageComplete(isSelectionDone());
+            }
+        });
+    }
+
+    private boolean isSelectionDone() {
+        if (null != deviceName) {
+            deviceName = deviceName.trim();
+        }
+        if (deviceName.isEmpty()) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public IWizardPage getNextPage() {
+        return null;
+    }
+
+    public String getDeviceName() {
+        return deviceName;
+    }
+
+    public Set<Resource> getSelectedResourceList() {
+        return selectedResourceList;
+    }
+
+}
+
+class TreeContentProvider implements ITreeContentProvider {
+
+    @Override
+    public void dispose() {
+    }
+
+    @Override
+    public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
+    }
+
+    @Override
+    public Object[] getChildren(Object parent) {
+        return null;
+    }
+
+    @Override
+    public Object[] getElements(Object parent) {
+        List<Resource> resList;
+        resList = Activator.getDefault().getResourceManager().getResourceList();
+        if (null == resList) {
+            resList = new ArrayList<Resource>();
+        }
+        return resList.toArray();
+    }
+
+    @Override
+    public Object getParent(Object child) {
+        return null;
+    }
+
+    @Override
+    public boolean hasChildren(Object parent) {
+        return false;
+    }
+}
+
+class TreeLabelProvider extends LabelProvider {
+    @Override
+    public String getText(Object element) {
+        Resource res = (Resource) element;
+        return res.getResourceName();
+    }
+
+    @Override
+    public Image getImage(Object element) {
+        if (element instanceof SingleResource) {
+            return Activator.getDefault().getImageRegistry()
+                    .get(Constants.SINGLE_RESOURCE);
+        } else {
+            return Activator.getDefault().getImageRegistry()
+                    .get(Constants.COLLECTION_RESOURCE);
+        }
+    }
+}
\ No newline at end of file
 
 package oic.simulator.serviceprovider.view.dialogs;
 
+import java.io.FileInputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Date;
+
+import oic.simulator.serviceprovider.Activator;
+import oic.simulator.serviceprovider.model.Resource;
 import oic.simulator.serviceprovider.utils.Constants;
+import oic.simulator.serviceprovider.utils.Utility;
 
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.wizard.IWizardPage;
 import org.eclipse.jface.wizard.WizardPage;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.KeyAdapter;
@@ -37,33 +48,51 @@ import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Listener;
 import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.PlatformUI;
+import org.oic.simulator.ILogger.Level;
+import org.oic.simulator.SimulatorException;
+import org.oic.simulator.server.SimulatorResource;
+import org.oic.simulator.server.SimulatorResource.Type;
 
 /**
  * This class shows UI for creating resources.
  */
-public class CreateResourcePage extends WizardPage {
+public class LoadRamlPage extends WizardPage {
+
+    private Text                   locationTxt;
+    private Button                 btnBrowse;
+    private Text                   noOfInstancesText;
+    private Label                  noOfInstancesLbl;
+    private Label                  locationLbl;
+
+    private String                 configFilePath = null;
+    private int                    resourceCount;
 
-    private Text   locationTxt;
-    private Button btnBrowse;
-    private Text   noOfInstancesText;
-    private Label  noOfInstancesLbl;
-    private Label  locationLbl;
+    private Resource               resource;
 
-    private String configFilePath = null;
-    private int    resourceCount;
+    private SimulatorResource.Type typeOfResource;
 
-    protected CreateResourcePage() {
+    protected LoadRamlPage() {
         super("Create Resource");
         resourceCount = -1;
     }
 
+    public void initialSetup(SimulatorResource.Type type) {
+        this.typeOfResource = type;
+        if (!noOfInstancesLbl.isDisposed()) {
+            noOfInstancesLbl.setVisible(type == Type.SINGLE);
+        }
+        if (!noOfInstancesText.isDisposed()) {
+            noOfInstancesText.setVisible(type == Type.SINGLE);
+        }
+    }
+
     @Override
     public void createControl(Composite parent) {
         setPageComplete(false);
         setTitle(Constants.CREATE_PAGE_TITLE);
         setMessage(Constants.CREATE_PAGE_MESSAGE);
         Composite compContent = new Composite(parent, SWT.NONE);
-        GridLayout gridLayout = new GridLayout(1, false);
+        GridLayout gridLayout = new GridLayout();
         compContent.setLayout(gridLayout);
         GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
         compContent.setLayoutData(gd);
@@ -129,7 +158,6 @@ public class CreateResourcePage extends WizardPage {
     }
 
     private void addUIListeners() {
-
         btnBrowse.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
@@ -138,9 +166,8 @@ public class CreateResourcePage extends WizardPage {
                 fileDialog
                         .setFilterExtensions(Constants.BROWSE_RAML_FILTER_EXTENSIONS);
                 String configFileAbsolutePath = fileDialog.open();
-                if (null != configFileAbsolutePath) {
+                if (null != configFileAbsolutePath)
                     locationTxt.setText(configFileAbsolutePath);
-                }
             }
         });
 
@@ -148,7 +175,7 @@ public class CreateResourcePage extends WizardPage {
             @Override
             public void modifyText(ModifyEvent e) {
                 configFilePath = locationTxt.getText();
-                setPageComplete(isSelectionDone());
+                getWizard().getContainer().updateButtons();
             }
         });
 
@@ -170,26 +197,111 @@ public class CreateResourcePage extends WizardPage {
         noOfInstancesText.addKeyListener(new KeyAdapter() {
             @Override
             public void keyReleased(KeyEvent e) {
-                setPageComplete(isSelectionDone());
+                getWizard().getContainer().updateButtons();
             }
         });
     }
 
-    private boolean isSelectionDone() {
+    @Override
+    public boolean canFlipToNextPage() {
         boolean done = false;
         try {
             resourceCount = Integer.parseInt(noOfInstancesText.getText());
         } catch (Exception e) {
             resourceCount = -1;
         }
+        if (null != configFilePath && configFilePath.trim().length() > 0) {
+            if (typeOfResource == Type.COLLECTION) {
+                done = true;
+            } else {
+                if (resourceCount == 1) {
+                    done = true;
+                }
+            }
+        }
+        return done;
+    }
 
-        if (null != configFilePath && configFilePath.length() > 0
-                && resourceCount >= 1) {
-            done = true;
+    public boolean isSelectionDone() {
+        boolean done = false;
+        try {
+            resourceCount = Integer.parseInt(noOfInstancesText.getText());
+        } catch (Exception e) {
+            resourceCount = -1;
+        }
+        if (null != configFilePath && configFilePath.trim().length() > 0) {
+            if (typeOfResource == Type.COLLECTION) {
+                done = true;
+            } else {
+                if (resourceCount >= 1) {
+                    done = true;
+                }
+            }
         }
         return done;
     }
 
+    public boolean isMultiResourceCreation() {
+        if (typeOfResource != Type.COLLECTION && resourceCount > 1) {
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    public IWizardPage getNextPage() {
+        // Validate the file path.
+        try {
+            new FileInputStream(configFilePath);
+        } catch (Exception e) {
+            MessageDialog
+                    .openError(getShell(), "Invalid File",
+                            "File doesn't exist. Either the file path or file name is invalid.");
+            // TODO: Instead of MessageDialog, errors may be shown on wizard
+            // itself.
+            return null;
+        }
+        final CreateResourceWizard wizard = ((CreateResourceWizard) getWizard());
+
+        try {
+            getContainer().run(true, true, new IRunnableWithProgress() {
+                @Override
+                public void run(IProgressMonitor monitor)
+                        throws InvocationTargetException, InterruptedException {
+                    try {
+                        monitor.beginTask("Resource Creation With RAML", 2);
+                        monitor.worked(1);
+                        resource = Activator.getDefault().getResourceManager()
+                                .createResourceByRAML(configFilePath);
+                        monitor.worked(1);
+                    } catch (SimulatorException e) {
+                        wizard.setStatus("Failed to create resource.\n"
+                                + Utility.getSimulatorErrorString(e, null));
+                    } finally {
+                        monitor.done();
+                    }
+                }
+            });
+        } catch (InvocationTargetException e) {
+            Activator.getDefault().getLogManager()
+                    .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
+            e.printStackTrace();
+        } catch (InterruptedException e) {
+            Activator.getDefault().getLogManager()
+                    .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
+            e.printStackTrace();
+        }
+        if (null == resource) {
+            wizard.setStatus("Failed to create Resource.");
+            wizard.getWizardDialog().close();
+            return null;
+        }
+        UpdatePropertiesPage updatePageRef = wizard.getUpdatePropPage();
+        updatePageRef.setResName(resource.getResourceName());
+        updatePageRef.setResURI(resource.getResourceURI());
+        return updatePageRef;
+    }
+
     public String getConfigFilePath() {
         return configFilePath;
     }
@@ -197,4 +309,12 @@ public class CreateResourcePage extends WizardPage {
     public int getResourceCount() {
         return resourceCount;
     }
+
+    public Resource getResource() {
+        return resource;
+    }
+
+    public void setResource(Resource resource) {
+        this.resource = resource;
+    }
 }
\ No newline at end of file
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/MainPage.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/MainPage.java
new file mode 100644 (file)
index 0000000..0e3937e
--- /dev/null
@@ -0,0 +1,191 @@
+package oic.simulator.serviceprovider.view.dialogs;
+
+import oic.simulator.serviceprovider.utils.Constants;
+
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.oic.simulator.server.SimulatorResource.Type;
+
+public class MainPage extends WizardPage {
+
+    private Button simpleBtn;
+    private Button collectionBtn;
+    private Button simpleFromRamlBtn;
+    private Button collectionFromRamlBtn;
+    private Button deviceBtn;
+    private Text   description;
+
+    public enum ResourceOption {
+        SIMPLE, SIMPLE_FROM_RAML, COLLECTION, COLLECTION_FROM_RAML, DEVICE, NONE
+    }
+
+    private ResourceOption resOption;
+
+    protected MainPage() {
+        super("Main Page");
+    }
+
+    @Override
+    public void createControl(Composite parent) {
+        setPageComplete(false);
+        setTitle(Constants.MAIN_PAGE_TITLE);
+        setMessage(Constants.MAIN_PAGE_MESSAGE);
+        Composite compContent = new Composite(parent, SWT.NONE);
+        GridLayout gridLayout = new GridLayout();
+        compContent.setLayout(gridLayout);
+        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        compContent.setLayoutData(gd);
+
+        simpleBtn = new Button(compContent, SWT.RADIO);
+        simpleBtn.setText("Simple resource");
+
+        simpleFromRamlBtn = new Button(compContent, SWT.RADIO);
+        simpleFromRamlBtn.setText("Simple resource(From RAML)");
+
+        collectionBtn = new Button(compContent, SWT.RADIO);
+        collectionBtn.setText("Collection resource");
+
+        collectionFromRamlBtn = new Button(compContent, SWT.RADIO);
+        collectionFromRamlBtn.setText("Collection resource(From RAML)");
+
+        deviceBtn = new Button(compContent, SWT.RADIO);
+        deviceBtn.setText("Device");
+
+        Label lbl = new Label(compContent, SWT.NULL);
+        lbl.setText("Details:");
+        gd = new GridData();
+        gd.verticalIndent = 20;
+        lbl.setLayoutData(gd);
+
+        description = new Text(compContent, SWT.MULTI | SWT.READ_ONLY
+                | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
+        description.setBackground(compContent.getBackground());
+        description.setText("[Select an option to view more details]");
+        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        description.setLayoutData(gd);
+
+        addUIListeners();
+
+        setControl(compContent);
+    }
+
+    private void addUIListeners() {
+        simpleBtn.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                description
+                        .setText("Create a simple resource by manually entering all the details given below.\n"
+                                + "\t1. Basic resource details: URI, Name, Resource Types, etc.\n"
+                                + "\t2. Options such as Observable, allowed request types, start/stop resource etc.\n"
+                                + "\t3. Adding attributes.");
+                resOption = ResourceOption.SIMPLE;
+                getWizard().getContainer().updateButtons();
+            }
+        });
+
+        simpleFromRamlBtn.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                description
+                        .setText("Create a simple resource from RAML configuration file.\n"
+                                + "\t1. Resource details, attributes, and other properties will be read from RAML.\n"
+                                + "\t2. Supports multi-instance creation.\n"
+                                + "\t3. For single instance creation, allows editing the URI and Name of the resource.\n"
+                                + "\t4. Allows to start or stop the resource(s).");
+                resOption = ResourceOption.SIMPLE_FROM_RAML;
+                getWizard().getContainer().updateButtons();
+            }
+        });
+
+        collectionBtn.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                description
+                        .setText("Create a collection resource by manually entering all the details given below.\n"
+                                + "\t1. Basic resource details: URI, Name, Resource Types, etc.\n"
+                                + "\t2. Start/stop the resource.\n"
+                                + "\t3. Adding existing simple resources to this collection.");
+                resOption = ResourceOption.COLLECTION;
+                getWizard().getContainer().updateButtons();
+            }
+        });
+
+        collectionFromRamlBtn.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                description
+                        .setText("Create a collection resource from RAML configuration file.\n"
+                                + "\t1. Resource details, attributes, and other properties will be read from RAML.\n"
+                                + "\t2. Supports multi-instance creation.\n"
+                                + "\t3. For single instance creation, allows editing the URI and Name of the resource.\n"
+                                + "\t4. Allows to start or stop the resource(s).");
+                resOption = ResourceOption.COLLECTION_FROM_RAML;
+                getWizard().getContainer().updateButtons();
+            }
+        });
+
+        deviceBtn.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                description
+                        .setText("Create a logical device that acts as a top-level logical classification.\n"
+                                + "\t1. Takes a device name for identication.\n"
+                                + "\t2. One or more single and collection resources can be added to it.");
+                resOption = ResourceOption.DEVICE;
+                getWizard().getContainer().updateButtons();
+            }
+        });
+    }
+
+    @Override
+    public boolean canFlipToNextPage() {
+        if (resOption != ResourceOption.NONE) {
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    public IWizardPage getPreviousPage() {
+        return null;
+    }
+
+    @Override
+    public IWizardPage getNextPage() {
+        CreateResourceWizard createWizard = (CreateResourceWizard) getWizard();
+        if (simpleBtn.getSelection()) {
+            return createWizard.getSimpleResourceBasicDetailsPage();
+        }
+        if (simpleFromRamlBtn.getSelection()) {
+            LoadRamlPage page = createWizard.getLoadRamlPage();
+            page.initialSetup(Type.SINGLE);
+            return page;
+        }
+        if (collectionBtn.getSelection()) {
+            return createWizard.getCollectionResourceBasicDetailsPage();
+        }
+        if (collectionFromRamlBtn.getSelection()) {
+            LoadRamlPage page = createWizard.getLoadRamlPage();
+            page.initialSetup(Type.COLLECTION);
+            return page;
+        }
+        if (deviceBtn.getSelection()) {
+            DevicePage page = createWizard.getDevicePage();
+            return page;
+        }
+        return null;
+    }
+
+    public ResourceOption getResourceOption() {
+        return resOption;
+    }
+}
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/RemoveResourceFromCollections.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/RemoveResourceFromCollections.java
new file mode 100644 (file)
index 0000000..0cf00e5
--- /dev/null
@@ -0,0 +1,206 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package oic.simulator.serviceprovider.view.dialogs;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import oic.simulator.serviceprovider.Activator;
+import oic.simulator.serviceprovider.model.CollectionResource;
+import oic.simulator.serviceprovider.utils.Constants;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTreeViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * This dialog is used for loading the RAML file.
+ */
+public class RemoveResourceFromCollections extends TitleAreaDialog {
+
+    private CheckboxTreeViewer treeViewer;
+
+    List<CollectionResource>   sourceList;
+
+    Set<CollectionResource>    selectedResourceList;
+
+    public RemoveResourceFromCollections(Shell parentShell,
+            List<CollectionResource> sourceList) {
+        super(parentShell);
+        this.sourceList = sourceList;
+        selectedResourceList = new HashSet<CollectionResource>();
+    }
+
+    @Override
+    public void create() {
+        super.create();
+        setTitle("Remove from Collections");
+        setMessage("Select one or more collection resources from which the single resource will be removed.");
+    }
+
+    @Override
+    protected Control createDialogArea(Composite parent) {
+        Composite compLayout = (Composite) super.createDialogArea(parent);
+        Composite container = new Composite(compLayout, SWT.NONE);
+        container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+        GridLayout layout = new GridLayout();
+        layout.verticalSpacing = 10;
+        layout.marginTop = 10;
+        container.setLayout(layout);
+
+        Label lbl = new Label(container, SWT.NONE);
+        lbl.setText("Select Resources from:");
+        GridData gd;
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        lbl.setLayoutData(gd);
+
+        Group resourceGroup = new Group(container, SWT.NONE);
+
+        Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
+
+        resourceGroup.setLayout(new GridLayout());
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        gd.heightHint = 300;
+        gd.horizontalSpan = 2;
+        resourceGroup.setLayoutData(gd);
+
+        treeViewer = new CheckboxTreeViewer(resourceGroup);
+        treeViewer.getTree().setBackground(color);
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        gd.grabExcessVerticalSpace = true;
+        gd.verticalAlignment = SWT.FILL;
+        // gd.heightHint = 300;
+        treeViewer.getTree().setLayoutData(gd);
+        treeViewer.setContentProvider(new TreeContentProvider());
+        treeViewer.setLabelProvider(new TreeLabelProvider());
+        treeViewer.setInput(new Object());
+        treeViewer.addCheckStateListener(new ICheckStateListener() {
+
+            @Override
+            public void checkStateChanged(CheckStateChangedEvent e) {
+                CollectionResource res = (CollectionResource) e.getElement();
+                if (null != res) {
+                    if (e.getChecked()) {
+                        selectedResourceList.add(res);
+                        System.out.println("Checked" + res.getResourceName());
+                    } else {
+                        selectedResourceList.remove(res);
+                        System.out.println("Unchecked:" + res.getResourceName());
+                    }
+                }
+            }
+        });
+
+        return compLayout;
+    }
+
+    public Set<CollectionResource> getSelectedResourceList() {
+        return selectedResourceList;
+    }
+
+    class TreeContentProvider implements ITreeContentProvider {
+
+        @Override
+        public void dispose() {
+        }
+
+        @Override
+        public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
+        }
+
+        @Override
+        public Object[] getChildren(Object parent) {
+            return null;
+        }
+
+        @Override
+        public Object[] getElements(Object parent) {
+            if (null == sourceList) {
+                sourceList = new ArrayList<CollectionResource>();
+            }
+            return sourceList.toArray();
+        }
+
+        @Override
+        public Object getParent(Object child) {
+            return null;
+        }
+
+        @Override
+        public boolean hasChildren(Object parent) {
+            return false;
+        }
+    }
+
+    class TreeLabelProvider extends LabelProvider {
+        @Override
+        public String getText(Object element) {
+            CollectionResource res = (CollectionResource) element;
+            return res.getResourceName();
+        }
+
+        @Override
+        public Image getImage(Object element) {
+            if (element instanceof CollectionResource) {
+                return Activator.getDefault().getImageRegistry()
+                        .get(Constants.COLLECTION_RESOURCE);
+            } else {
+                return null;
+            }
+        }
+    }
+
+    @Override
+    protected void okPressed() {
+        if (selectedResourceList.isEmpty()) {
+            MessageDialog.openInformation(
+                    Display.getDefault().getActiveShell(),
+                    "No selection done.", "No resources are selected.");
+            return;
+        }
+        close();
+    }
+
+    @Override
+    public boolean isHelpAvailable() {
+        return false;
+    }
+}
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/RemoveResourceFromDevices.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/RemoveResourceFromDevices.java
new file mode 100644 (file)
index 0000000..a875984
--- /dev/null
@@ -0,0 +1,205 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package oic.simulator.serviceprovider.view.dialogs;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import oic.simulator.serviceprovider.Activator;
+import oic.simulator.serviceprovider.model.Device;
+import oic.simulator.serviceprovider.utils.Constants;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTreeViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * This dialog is used for loading the RAML file.
+ */
+public class RemoveResourceFromDevices extends TitleAreaDialog {
+
+    private CheckboxTreeViewer treeViewer;
+
+    List<Device>               sourceList;
+
+    Set<Device>                selectedDeviceList;
+
+    public RemoveResourceFromDevices(Shell parentShell, List<Device> sourceList) {
+        super(parentShell);
+        this.sourceList = sourceList;
+        selectedDeviceList = new HashSet<Device>();
+    }
+
+    @Override
+    public void create() {
+        super.create();
+        setTitle("Remove from Device");
+        setMessage("Select one or more devices from which the single resource will be removed.");
+    }
+
+    @Override
+    protected Control createDialogArea(Composite parent) {
+        Composite compLayout = (Composite) super.createDialogArea(parent);
+        Composite container = new Composite(compLayout, SWT.NONE);
+        container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+        GridLayout layout = new GridLayout();
+        layout.verticalSpacing = 10;
+        layout.marginTop = 10;
+        container.setLayout(layout);
+
+        Label lbl = new Label(container, SWT.NONE);
+        lbl.setText("Select Resources from:");
+        GridData gd;
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        lbl.setLayoutData(gd);
+
+        Group resourceGroup = new Group(container, SWT.NONE);
+
+        Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
+
+        resourceGroup.setLayout(new GridLayout());
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        gd.heightHint = 300;
+        gd.horizontalSpan = 2;
+        resourceGroup.setLayoutData(gd);
+
+        treeViewer = new CheckboxTreeViewer(resourceGroup);
+        treeViewer.getTree().setBackground(color);
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        gd.grabExcessVerticalSpace = true;
+        gd.verticalAlignment = SWT.FILL;
+        // gd.heightHint = 300;
+        treeViewer.getTree().setLayoutData(gd);
+        treeViewer.setContentProvider(new TreeContentProvider());
+        treeViewer.setLabelProvider(new TreeLabelProvider());
+        treeViewer.setInput(new Object());
+        treeViewer.addCheckStateListener(new ICheckStateListener() {
+
+            @Override
+            public void checkStateChanged(CheckStateChangedEvent e) {
+                Device res = (Device) e.getElement();
+                if (null != res) {
+                    if (e.getChecked()) {
+                        selectedDeviceList.add(res);
+                        System.out.println("Checked" + res.getDeviceName());
+                    } else {
+                        selectedDeviceList.remove(res);
+                        System.out.println("Unchecked:" + res.getDeviceName());
+                    }
+                }
+            }
+        });
+
+        return compLayout;
+    }
+
+    public Set<Device> getSelectedDeviceList() {
+        return selectedDeviceList;
+    }
+
+    class TreeContentProvider implements ITreeContentProvider {
+
+        @Override
+        public void dispose() {
+        }
+
+        @Override
+        public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
+        }
+
+        @Override
+        public Object[] getChildren(Object parent) {
+            return null;
+        }
+
+        @Override
+        public Object[] getElements(Object parent) {
+            if (null == sourceList) {
+                sourceList = new ArrayList<Device>();
+            }
+            return sourceList.toArray();
+        }
+
+        @Override
+        public Object getParent(Object child) {
+            return null;
+        }
+
+        @Override
+        public boolean hasChildren(Object parent) {
+            return false;
+        }
+    }
+
+    class TreeLabelProvider extends LabelProvider {
+        @Override
+        public String getText(Object element) {
+            Device res = (Device) element;
+            return res.getDeviceName();
+        }
+
+        @Override
+        public Image getImage(Object element) {
+            if (element instanceof Device) {
+                return Activator.getDefault().getImageRegistry()
+                        .get(Constants.DEVICE);
+            } else {
+                return null;
+            }
+        }
+    }
+
+    @Override
+    protected void okPressed() {
+        if (selectedDeviceList.isEmpty()) {
+            MessageDialog.openInformation(
+                    Display.getDefault().getActiveShell(),
+                    "No selection done.", "No devices are selected.");
+            return;
+        }
+        close();
+    }
+
+    @Override
+    public boolean isHelpAvailable() {
+        return false;
+    }
+}
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/RemoveResources.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/RemoveResources.java
new file mode 100644 (file)
index 0000000..f76f8f9
--- /dev/null
@@ -0,0 +1,207 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package oic.simulator.serviceprovider.view.dialogs;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import oic.simulator.serviceprovider.Activator;
+import oic.simulator.serviceprovider.model.CollectionResource;
+import oic.simulator.serviceprovider.model.Resource;
+import oic.simulator.serviceprovider.utils.Constants;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTreeViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * This dialog is used for loading the RAML file.
+ */
+public class RemoveResources extends TitleAreaDialog {
+
+    private CheckboxTreeViewer treeViewer;
+
+    List<Resource>             sourceList;
+
+    Set<Resource>              selectedResourceList;
+
+    public RemoveResources(Shell parentShell, List<Resource> sourceList) {
+        super(parentShell);
+        this.sourceList = sourceList;
+        selectedResourceList = new HashSet<Resource>();
+    }
+
+    @Override
+    public void create() {
+        super.create();
+        setTitle("Remove Resources");
+        setMessage("Select one or more resources to be removed.");
+    }
+
+    @Override
+    protected Control createDialogArea(Composite parent) {
+        Composite compLayout = (Composite) super.createDialogArea(parent);
+        Composite container = new Composite(compLayout, SWT.NONE);
+        container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+        GridLayout layout = new GridLayout();
+        layout.verticalSpacing = 10;
+        layout.marginTop = 10;
+        container.setLayout(layout);
+
+        Label lbl = new Label(container, SWT.NONE);
+        lbl.setText("Select Resources from:");
+        GridData gd;
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        lbl.setLayoutData(gd);
+
+        Group resourceGroup = new Group(container, SWT.NONE);
+
+        Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
+
+        resourceGroup.setLayout(new GridLayout());
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        gd.heightHint = 300;
+        gd.horizontalSpan = 2;
+        resourceGroup.setLayoutData(gd);
+
+        treeViewer = new CheckboxTreeViewer(resourceGroup);
+        treeViewer.getTree().setBackground(color);
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        gd.grabExcessVerticalSpace = true;
+        gd.verticalAlignment = SWT.FILL;
+        // gd.heightHint = 300;
+        treeViewer.getTree().setLayoutData(gd);
+        treeViewer.setContentProvider(new TreeContentProvider());
+        treeViewer.setLabelProvider(new TreeLabelProvider());
+        treeViewer.setInput(new Object());
+        treeViewer.addCheckStateListener(new ICheckStateListener() {
+
+            @Override
+            public void checkStateChanged(CheckStateChangedEvent e) {
+                Resource res = (Resource) e.getElement();
+                if (null != res) {
+                    if (e.getChecked()) {
+                        selectedResourceList.add(res);
+                        System.out.println("Checked" + res.getResourceName());
+                    } else {
+                        selectedResourceList.remove(res);
+                        System.out.println("Unchecked:" + res.getResourceName());
+                    }
+                }
+            }
+        });
+
+        return compLayout;
+    }
+
+    public Set<Resource> getSelectedResourceList() {
+        return selectedResourceList;
+    }
+
+    class TreeContentProvider implements ITreeContentProvider {
+
+        @Override
+        public void dispose() {
+        }
+
+        @Override
+        public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
+        }
+
+        @Override
+        public Object[] getChildren(Object parent) {
+            return null;
+        }
+
+        @Override
+        public Object[] getElements(Object parent) {
+            if (null == sourceList) {
+                sourceList = new ArrayList<Resource>();
+            }
+            return sourceList.toArray();
+        }
+
+        @Override
+        public Object getParent(Object child) {
+            return null;
+        }
+
+        @Override
+        public boolean hasChildren(Object parent) {
+            return false;
+        }
+    }
+
+    class TreeLabelProvider extends LabelProvider {
+        @Override
+        public String getText(Object element) {
+            Resource res = (Resource) element;
+            return res.getResourceName();
+        }
+
+        @Override
+        public Image getImage(Object element) {
+            if (element instanceof CollectionResource) {
+                return Activator.getDefault().getImageRegistry()
+                        .get(Constants.COLLECTION_RESOURCE);
+            } else {
+                return Activator.getDefault().getImageRegistry()
+                        .get(Constants.SINGLE_RESOURCE);
+            }
+        }
+    }
+
+    @Override
+    protected void okPressed() {
+        if (selectedResourceList.isEmpty()) {
+            MessageDialog.openInformation(
+                    Display.getDefault().getActiveShell(),
+                    "No selection done.", "No resources are selected.");
+            return;
+        }
+        close();
+    }
+
+    @Override
+    public boolean isHelpAvailable() {
+        return false;
+    }
+}
index 09f95fe..5113712 100644 (file)
 
 package oic.simulator.serviceprovider.view.dialogs;
 
-import org.eclipse.jface.dialogs.IDialogConstants;
 import org.eclipse.jface.wizard.IWizard;
+import org.eclipse.jface.wizard.IWizardPage;
 import org.eclipse.jface.wizard.WizardDialog;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Shell;
 
 /**
@@ -28,8 +26,11 @@ import org.eclipse.swt.widgets.Shell;
  */
 public class ResourceWizardDialog extends WizardDialog {
 
+    private IWizard wizard;
+
     public ResourceWizardDialog(Shell parentShell, IWizard newWizard) {
         super(parentShell, newWizard);
+        wizard = newWizard;
     }
 
     @Override
@@ -43,11 +44,46 @@ public class ResourceWizardDialog extends WizardDialog {
     }
 
     @Override
-    protected void createButtonsForButtonBar(Composite parent) {
-        super.createButtonsForButtonBar(parent);
-        Button finishButton = getButton(IDialogConstants.FINISH_ID);
-        if (finishButton != null) {
-            finishButton.setText(IDialogConstants.OK_LABEL);
+    protected void backPressed() {
+        if (wizard.getClass() == CreateResourceWizard.class) {
+            CreateResourceWizard createWizard = (CreateResourceWizard) wizard;
+
+            MainPage mainPage = createWizard.getMainPage();
+            SimpleResourceBasicDetailsPage simpleResourceBasicDetailsPage = createWizard
+                    .getSimpleResourceBasicDetailsPage();
+            SimpleResourceOtherDetailsPage simpleResourceOtherDetailsPage = createWizard
+                    .getSimpleResourceOtherDetailsPage();
+            SimpleResourceAddAttributePage simpleResourceAddAttributesPage = createWizard
+                    .getSimpleResourceAddAttributePage();
+            CollectionResourceBasicDetailsPage collectionResourceBasicDetailsPage = createWizard
+                    .getCollectionResourceBasicDetailsPage();
+            AddResourcesToCollectionPage addResourcesToCollectionPage = createWizard
+                    .getAddResourcesToCollectionPage();
+            LoadRamlPage loadRamlPage = createWizard.getLoadRamlPage();
+            UpdatePropertiesPage updatePropPage = createWizard
+                    .getUpdatePropPage();
+            DevicePage devPage = createWizard.getDevicePage();
+
+            IWizardPage curPage = wizard.getContainer().getCurrentPage();
+            IWizardPage prevPage = null;
+
+            if (curPage == loadRamlPage
+                    || curPage == simpleResourceBasicDetailsPage
+                    || curPage == collectionResourceBasicDetailsPage
+                    || curPage == devPage) {
+                prevPage = mainPage;
+            } else if (curPage == updatePropPage) {
+                loadRamlPage.setResource(null);
+                prevPage = loadRamlPage;
+            } else if (curPage == addResourcesToCollectionPage) {
+                prevPage = collectionResourceBasicDetailsPage;
+            } else if (curPage == simpleResourceAddAttributesPage) {
+                prevPage = simpleResourceBasicDetailsPage;
+            } else if (curPage == simpleResourceOtherDetailsPage) {
+                prevPage = simpleResourceAddAttributesPage;
+            }
+            if (null != prevPage)
+                showPage(prevPage);
         }
     }
 }
\ No newline at end of file
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourceAddAttributePage.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourceAddAttributePage.java
new file mode 100644 (file)
index 0000000..0e664ca
--- /dev/null
@@ -0,0 +1,379 @@
+package oic.simulator.serviceprovider.view.dialogs;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import oic.simulator.serviceprovider.model.AttributeHelper;
+import oic.simulator.serviceprovider.utils.Constants;
+import oic.simulator.serviceprovider.utils.Utility;
+
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StyledCellLabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerCell;
+import org.eclipse.jface.window.Window;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Table;
+import org.oic.simulator.AttributeProperty.Type;
+
+public class SimpleResourceAddAttributePage extends WizardPage {
+
+    private TableViewer          attTblViewer;
+    private Button               addBtn;
+    private Button               remBtn;
+    private Button               editBtn;
+
+    private final String[]       attTblHeaders  = { "Name", "Type", "Range",
+            "Allowed Values", "Default Value"  };
+    private final Integer[]      attTblColWidth = { 90, 75, 75, 150, 75 };
+
+    private Set<AttributeHelper> attributes;
+
+    protected SimpleResourceAddAttributePage() {
+        super("Add Attributes");
+        attributes = new HashSet<AttributeHelper>();
+    }
+
+    @Override
+    public void createControl(Composite parent) {
+        setPageComplete(false);
+        setTitle(Constants.SIMPLE_RESOURCE_ADD_ATTRIBUTE_PAGE_TITLE);
+        setMessage(Constants.SIMPLE_RESOURCE_ADD_ATTRIBUTE_PAGE_MESSAGE);
+        Composite compContent = new Composite(parent, SWT.NONE);
+        GridLayout gridLayout = new GridLayout(2, false);
+        compContent.setLayout(gridLayout);
+        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        compContent.setLayoutData(gd);
+
+        Label lbl = new Label(compContent, SWT.NULL);
+        lbl.setText("Attributes:");
+        gd = new GridData();
+        gd.horizontalSpan = 2;
+        lbl.setLayoutData(gd);
+
+        setupAttributeTable(compContent);
+
+        setupAttributeControls(compContent);
+
+        setUiListeners(compContent);
+
+        setControl(compContent);
+    }
+
+    private void setupAttributeTable(Composite attComp) {
+        attTblViewer = new TableViewer(attComp, SWT.MULTI | SWT.H_SCROLL
+                | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
+
+        createAttributeColumns(attTblViewer);
+
+        // make lines and header visible
+        Table table = attTblViewer.getTable();
+        table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+        table.setHeaderVisible(true);
+        table.setLinesVisible(true);
+
+        attTblViewer.setContentProvider(new AttributeContentProvider());
+    }
+
+    public void createAttributeColumns(TableViewer tableViewer) {
+
+        TableViewerColumn attName = new TableViewerColumn(tableViewer, SWT.NONE);
+        attName.getColumn().setWidth(attTblColWidth[0]);
+        attName.getColumn().setText(attTblHeaders[0]);
+        attName.setLabelProvider(new StyledCellLabelProvider() {
+            @Override
+            public void update(ViewerCell cell) {
+                Object e = cell.getElement();
+                if (null == e) {
+                    return;
+                }
+                AttributeHelper att = (AttributeHelper) e;
+                cell.setText(att.getAttributeName());
+
+            }
+        });
+
+        TableViewerColumn attType = new TableViewerColumn(tableViewer, SWT.NONE);
+        attType.getColumn().setWidth(attTblColWidth[1]);
+        attType.getColumn().setText(attTblHeaders[1]);
+        attType.setLabelProvider(new StyledCellLabelProvider() {
+            @Override
+            public void update(ViewerCell cell) {
+                Object e = cell.getElement();
+                if (null == e) {
+                    return;
+                }
+                AttributeHelper att = (AttributeHelper) e;
+                cell.setText(att.getAttributeType());
+            }
+        });
+
+        TableViewerColumn attRange = new TableViewerColumn(tableViewer,
+                SWT.NONE);
+        attRange.getColumn().setWidth(attTblColWidth[2]);
+        attRange.getColumn().setText(attTblHeaders[2]);
+        attRange.setLabelProvider(new StyledCellLabelProvider() {
+            @Override
+            public void update(ViewerCell cell) {
+                Object e = cell.getElement();
+                if (null == e) {
+                    return;
+                }
+                AttributeHelper att = (AttributeHelper) e;
+                if (att.getValidValuesType() != Type.RANGE) {
+                    cell.setText("Nil");
+                } else {
+                    String min = att.getMin();
+                    String max = att.getMax();
+                    if (null != min && null != max) {
+                        cell.setText("[" + att.getMin() + " to " + att.getMax()
+                                + "]");
+                    } else {
+                        cell.setText("Nil");
+                    }
+                }
+            }
+        });
+
+        TableViewerColumn attAllwdValues = new TableViewerColumn(tableViewer,
+                SWT.NONE);
+        attAllwdValues.getColumn().setWidth(attTblColWidth[3]);
+        attAllwdValues.getColumn().setText(attTblHeaders[3]);
+        attAllwdValues.setLabelProvider(new StyledCellLabelProvider() {
+            @Override
+            public void update(ViewerCell cell) {
+                Object e = cell.getElement();
+                if (null == e) {
+                    return;
+                }
+                AttributeHelper att = (AttributeHelper) e;
+                if (att.getValidValuesType() != Type.VALUESET) {
+                    cell.setText("Nil");
+                } else {
+                    cell.setText(att.getAllowedValues().toString());
+                }
+            }
+        });
+
+        TableViewerColumn attDflValue = new TableViewerColumn(tableViewer,
+                SWT.NONE);
+        attDflValue.getColumn().setWidth(attTblColWidth[4]);
+        attDflValue.getColumn().setText(attTblHeaders[4]);
+        attDflValue.setLabelProvider(new StyledCellLabelProvider() {
+            @Override
+            public void update(ViewerCell cell) {
+                Object e = cell.getElement();
+                if (null == e) {
+                    return;
+                }
+                AttributeHelper att = (AttributeHelper) e;
+                cell.setText(att.getAttributeDflValue());
+            }
+        });
+    }
+
+    private void setupAttributeControls(Composite compContent) {
+
+        Composite innerComp = new Composite(compContent, SWT.NULL);
+        innerComp.setLayout(new GridLayout());
+        GridData gd = new GridData();
+        gd.verticalAlignment = SWT.TOP;
+        innerComp.setLayoutData(gd);
+
+        addBtn = new Button(innerComp, SWT.PUSH);
+        addBtn.setText("Add");
+        gd = new GridData();
+        gd.widthHint = 70;
+        addBtn.setLayoutData(gd);
+
+        editBtn = new Button(innerComp, SWT.PUSH);
+        editBtn.setText("Edit");
+        editBtn.setEnabled(false);
+        gd = new GridData();
+        gd.widthHint = 70;
+        editBtn.setLayoutData(gd);
+
+        remBtn = new Button(innerComp, SWT.PUSH);
+        remBtn.setText("Remove");
+        remBtn.setEnabled(false);
+        gd = new GridData();
+        gd.widthHint = 70;
+        remBtn.setLayoutData(gd);
+    }
+
+    private void setUiListeners(Composite compContent) {
+        addBtn.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                Set<String> rTypes = Utility.getAttributeTypes();
+                AddAttributeDialog dialog = new AddAttributeDialog(Display
+                        .getDefault().getActiveShell(), null, rTypes,
+                        attributes);
+                if (dialog.open() == Window.OK) {
+                    AttributeHelper att = dialog.getAttHelper();
+                    attributes.add(att);
+                    remBtn.setEnabled(true);
+                    AttributeContentProvider provider = (AttributeContentProvider) attTblViewer
+                            .getContentProvider();
+                    provider.addAttribute(att);
+                    attTblViewer.add(att);
+                    attTblViewer.getTable().deselectAll();
+                    attTblViewer.getTable().select(
+                            attTblViewer.getTable().getItemCount() - 1);
+                    editBtn.setEnabled(true);
+                }
+            }
+        });
+
+        editBtn.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                IStructuredSelection selection = (IStructuredSelection) attTblViewer
+                        .getSelection();
+                if (null == selection) {
+                    editBtn.setEnabled(false);
+                    return;
+                }
+                AttributeHelper att = (AttributeHelper) selection
+                        .getFirstElement();
+                if (null == att) {
+                    editBtn.setEnabled(false);
+                    return;
+                }
+                // Opening the dialog for edit operation.
+                // Passing the attribute to pre-fill the UI controls.
+                Set<String> rTypes = Utility.getAttributeTypes();
+                AddAttributeDialog dialog = new AddAttributeDialog(Display
+                        .getDefault().getActiveShell(), att, rTypes, attributes);
+                if (dialog.open() != Window.OK) {
+                    AttributeHelper newAtt = dialog.getAttClone();
+                    att.setAttributeName(newAtt.getAttributeName());
+                    att.setAttributeType(newAtt.getAttributeType());
+                    att.setAttributeDflValue(newAtt.getAttributeDflValue());
+                    att.setValidValuesType(newAtt.getValidValuesType());
+                    att.setMin(newAtt.getMin());
+                    att.setMax(newAtt.getMax());
+                    att.setAllowedValues(newAtt.getAllowedValues());
+                }
+                attTblViewer.update(att, null);
+                System.out.println("Attribute data after closing edit dialog: "
+                        + att);
+            }
+        });
+
+        remBtn.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                IStructuredSelection selection = (IStructuredSelection) attTblViewer
+                        .getSelection();
+                if (null != selection) {
+                    System.out.println(selection.size());
+                    Iterator<?> itr = selection.iterator();
+                    while (itr.hasNext()) {
+                        AttributeHelper att = (AttributeHelper) itr.next();
+                        System.out.println(att.getAttributeName());
+                        attTblViewer.remove(att);
+                        attributes.remove(att);
+                        AttributeContentProvider provider = (AttributeContentProvider) attTblViewer
+                                .getContentProvider();
+                        provider.removeAttribute(att);
+                    }
+                    if (attributes.size() < 1) {
+                        remBtn.setEnabled(false);
+                    }
+                    editBtn.setEnabled(false);
+                }
+            }
+        });
+
+        attTblViewer
+                .addSelectionChangedListener(new ISelectionChangedListener() {
+
+                    @Override
+                    public void selectionChanged(SelectionChangedEvent event) {
+                        System.out.println("table selection changed");
+                        remBtn.setEnabled(true);
+                        IStructuredSelection selection = (IStructuredSelection) event
+                                .getSelection();
+                        if (null == selection) {
+                            return;
+                        }
+                        if (selection.size() > 1) {
+                            editBtn.setEnabled(false);
+                        } else {
+                            editBtn.setEnabled(true);
+                        }
+                    }
+                });
+    }
+
+    class AttributeContentProvider implements ITreeContentProvider {
+
+        List<AttributeHelper> attList = new ArrayList<AttributeHelper>();
+
+        @SuppressWarnings("unchecked")
+        @Override
+        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+            attList = (List<AttributeHelper>) newInput;
+        }
+
+        @Override
+        public Object[] getChildren(Object element) {
+            return new Object[0];
+        }
+
+        @Override
+        public Object[] getElements(Object input) {
+            return attList.toArray();
+        }
+
+        @Override
+        public Object getParent(Object element) {
+            return null;
+        }
+
+        @Override
+        public boolean hasChildren(Object element) {
+            return false;
+        }
+
+        @Override
+        public void dispose() {
+        }
+
+        public synchronized void addAttribute(AttributeHelper newElement) {
+            attList.add(newElement);
+        }
+
+        public synchronized void removeAttribute(AttributeHelper element) {
+            attList.remove(element);
+        }
+    }
+
+    @Override
+    public boolean canFlipToNextPage() {
+        return false;
+    }
+
+    public Set<AttributeHelper> getAttributes() {
+        return attributes;
+    }
+}
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourceBasicDetailsPage.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourceBasicDetailsPage.java
new file mode 100644 (file)
index 0000000..f01939b
--- /dev/null
@@ -0,0 +1,303 @@
+package oic.simulator.serviceprovider.view.dialogs;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import oic.simulator.serviceprovider.Activator;
+import oic.simulator.serviceprovider.utils.Constants;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.window.Window;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.List;
+import org.eclipse.swt.widgets.Text;
+
+public class SimpleResourceBasicDetailsPage extends WizardPage {
+
+    private Text        resNameTxt;
+    private Text        resUriTxt;
+    private List        resTypeslist;
+    private Button      addToListBtn;
+    private Button      remFromListBtn;
+    private Button      observeBtn;
+    // private Button startBtn;
+
+    private String      resName;
+    private String      resURI;
+    private Set<String> resTypes;
+    private boolean     observable;
+
+    // private boolean start;
+
+    protected SimpleResourceBasicDetailsPage() {
+        super("Basic Details");
+        resTypes = new HashSet<String>();
+    }
+
+    @Override
+    public void createControl(Composite parent) {
+        setPageComplete(false);
+        setTitle(Constants.SIMPLE_RESOURCE_BASIC_DETAILS_PAGE_TITLE);
+        setMessage(Constants.SIMPLE_RESOURCE_BASIC_DETAILS_PAGE_MESSAGE);
+
+        Composite container = new Composite(parent, SWT.NONE);
+        GridLayout gridLayout = new GridLayout();
+        container.setLayout(gridLayout);
+        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        container.setLayoutData(gd);
+
+        Group resDetGrp = new Group(container, SWT.NONE);
+        resDetGrp.setText("Resource Details");
+        gridLayout = new GridLayout(4, false);
+        resDetGrp.setLayout(gridLayout);
+        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        resDetGrp.setLayoutData(gd);
+
+        Label resNameLbl = new Label(resDetGrp, SWT.NULL);
+        resNameLbl.setText(Constants.RESOURCE_NAME);
+        gd = new GridData();
+        resNameLbl.setLayoutData(gd);
+
+        resNameTxt = new Text(resDetGrp, SWT.BORDER);
+        gd = new GridData();
+        // gd.widthHint = 300;
+        gd.horizontalAlignment = SWT.FILL;
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalSpan = 3;
+        resNameTxt.setLayoutData(gd);
+        resNameTxt.setFocus();
+
+        Label resUriLbl = new Label(resDetGrp, SWT.NULL);
+        resUriLbl.setText(Constants.RESOURCE_URI);
+
+        resUriTxt = new Text(resDetGrp, SWT.BORDER);
+        gd = new GridData();
+        // gd.widthHint = 300;
+        gd.horizontalSpan = 3;
+        gd.horizontalAlignment = SWT.FILL;
+        gd.grabExcessHorizontalSpace = true;
+        resUriTxt.setLayoutData(gd);
+        /*
+         * Composite resTypesComp = new Composite(compContent, SWT.NONE);
+         * gridLayout = new GridLayout(3, false);
+         * resTypesComp.setLayout(gridLayout); gd = new GridData();
+         * gd.grabExcessHorizontalSpace = true; gd.horizontalAlignment =
+         * SWT.FILL; resTypesComp.setLayoutData(gd);
+         */
+
+        Label resTypesLbl = new Label(resDetGrp, SWT.NULL);
+        resTypesLbl.setText(Constants.RESOURCE_TYPES);
+
+        resTypeslist = new List(resDetGrp, SWT.BORDER | SWT.MULTI
+                | SWT.V_SCROLL);
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        gd.horizontalSpan = 2;
+        gd.heightHint = 100;
+        /* gd.widthHint = 200; */
+        resTypeslist.setLayoutData(gd);
+        // resTypeslist.setBackground(new Color());
+
+        Composite resTypesActionsComp = new Composite(resDetGrp, SWT.NONE);
+        gridLayout = new GridLayout();
+        resTypesActionsComp.setLayout(gridLayout);
+        gd = new GridData();
+        gd.verticalAlignment = SWT.TOP;
+        /*
+         * gd.grabExcessHorizontalSpace = true; gd.horizontalAlignment =
+         * SWT.FILL;
+         */
+        resTypesActionsComp.setLayoutData(gd);
+
+        addToListBtn = new Button(resTypesActionsComp, SWT.PUSH);
+        addToListBtn.setText("Add");
+        gd = new GridData();
+        gd.widthHint = 70;
+        addToListBtn.setLayoutData(gd);
+
+        remFromListBtn = new Button(resTypesActionsComp, SWT.PUSH);
+        remFromListBtn.setText("Remove");
+        gd = new GridData();
+        gd.widthHint = 70;
+        remFromListBtn.setLayoutData(gd);
+        remFromListBtn.setEnabled(false);
+
+        Group otherOptionsGrp = new Group(container, SWT.NONE);
+        otherOptionsGrp.setText("Other options");
+        gridLayout = new GridLayout();
+        otherOptionsGrp.setLayout(gridLayout);
+        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        otherOptionsGrp.setLayoutData(gd);
+
+        observeBtn = new Button(otherOptionsGrp, SWT.CHECK);
+        observeBtn.setText("Observable");
+        observeBtn.setSelection(true);
+        observable = true;
+
+        /*
+         * startBtn = new Button(otherOptionsGrp, SWT.CHECK);
+         * startBtn.setText("Start the resource immediately after creation");
+         * startBtn.setSelection(true);
+         */
+        addUiListeners();
+
+        setControl(container);
+    }
+
+    private void addUiListeners() {
+
+        resUriTxt.addModifyListener(new ModifyListener() {
+            @Override
+            public void modifyText(ModifyEvent arg0) {
+                resURI = resUriTxt.getText();
+                getWizard().getContainer().updateButtons();
+            }
+        });
+
+        resNameTxt.addModifyListener(new ModifyListener() {
+            @Override
+            public void modifyText(ModifyEvent arg0) {
+                resName = resNameTxt.getText();
+                getWizard().getContainer().updateButtons();
+            }
+        });
+
+        addToListBtn.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                SingleTextInputDialog dialog = new SingleTextInputDialog(
+                        getShell(), "Add Resource Type", "Resource Type");
+                if (dialog.open() == Window.OK) {
+                    System.out.println(dialog.getValue());
+                    String resType = dialog.getValue();
+                    // Duplicate check.
+                    if (resTypes.contains(resType)) {
+                        MessageDialog.openError(Display.getDefault()
+                                .getActiveShell(), "Duplicate value",
+                                "value already exist.");
+                        return;
+                    }
+                    resTypeslist.add(resType);
+                    resTypeslist.deselectAll();
+                    resTypeslist.select(resTypeslist.getItemCount() - 1);
+                    resTypeslist.showSelection();
+                    remFromListBtn.setEnabled(true);
+
+                    resTypes.add(resType);
+
+                    getWizard().getContainer().updateButtons();
+                }
+            }
+        });
+
+        remFromListBtn.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                int[] selection = resTypeslist.getSelectionIndices();
+                String[] selectionStr = resTypeslist.getSelection();
+                if (null != selection && selection.length > 0) {
+                    resTypeslist.remove(selection);
+                    for (String selected : selectionStr) {
+                        resTypes.remove(selected);
+                    }
+                }
+
+                changeVisibility();
+                getWizard().getContainer().updateButtons();
+            }
+        });
+
+        resTypeslist.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                changeVisibility();
+            }
+        });
+
+        observeBtn.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                observable = observeBtn.getSelection();
+            }
+        });
+
+        /*
+         * startBtn.addSelectionListener(new SelectionAdapter() {
+         * 
+         * @Override public void widgetSelected(SelectionEvent e) { start =
+         * startBtn.getSelection(); } });
+         */
+    }
+
+    private void changeVisibility() {
+        int[] selection = resTypeslist.getSelectionIndices();
+        if (null != selection && selection.length > 0) {
+            remFromListBtn.setEnabled(true);
+        } else {
+            remFromListBtn.setEnabled(false);
+        }
+    }
+
+    @Override
+    public boolean canFlipToNextPage() {
+        if (null == resName || null == resURI || resTypes.size() < 1) {
+            return false;
+        }
+        resName = resName.trim();
+        resURI = resURI.trim();
+        if (resName.length() < 1 || resURI.length() < 1) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public IWizardPage getNextPage() {
+        // Checking whether the uri is used by any other resource.
+        if (Activator.getDefault().getResourceManager().isResourceExist(resURI)) {
+            MessageDialog
+                    .openError(getShell(), "Resource URI in use",
+                            "Entered resource URI is in use. Please try a different one.");
+            // TODO: Instead of MessageDialog, errors may be shown on wizard
+            // itself.
+            return null;
+        }
+        return ((CreateResourceWizard) getWizard())
+                .getSimpleResourceAddAttributePage();
+    }
+
+    public String getResName() {
+        return resName;
+    }
+
+    public String getResURI() {
+        return resURI;
+    }
+
+    public Set<String> getResTypes() {
+        return resTypes;
+    }
+
+    public boolean isObservable() {
+        return observable;
+    }
+
+    /*
+     * public boolean isStart() { return start; }
+     */
+
+}
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourceOtherDetailsPage.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourceOtherDetailsPage.java
new file mode 100644 (file)
index 0000000..41cd07b
--- /dev/null
@@ -0,0 +1,119 @@
+package oic.simulator.serviceprovider.view.dialogs;
+
+import oic.simulator.serviceprovider.utils.Constants;
+
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+public class SimpleResourceOtherDetailsPage extends WizardPage {
+
+    private Button getBtn;
+    private Button putBtn;
+    private Button postBtn;
+
+    public boolean getChecked;
+    public boolean putChecked;
+    public boolean postChecked;
+
+    protected SimpleResourceOtherDetailsPage() {
+        super("Allowed Request Types");
+    }
+
+    @Override
+    public void createControl(Composite parent) {
+        setPageComplete(false);
+        setTitle(Constants.SIMPLE_RESOURCE_OTHER_DETAILS_PAGE_TITLE);
+        setMessage(Constants.SIMPLE_RESOURCE_OTHER_DETAILS_PAGE_MESSAGE);
+
+        Composite container = new Composite(parent, SWT.NONE);
+        GridLayout gridLayout = new GridLayout();
+        container.setLayout(gridLayout);
+        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        container.setLayoutData(gd);
+
+        Group resDetGrp = new Group(container, SWT.NONE);
+        resDetGrp.setText("Allowed Request Types");
+        gridLayout = new GridLayout();
+        resDetGrp.setLayout(gridLayout);
+        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        resDetGrp.setLayoutData(gd);
+
+        getBtn = new Button(resDetGrp, SWT.CHECK);
+        getBtn.setText("GET Request");
+
+        putBtn = new Button(resDetGrp, SWT.CHECK);
+        putBtn.setText("PUT Request");
+
+        postBtn = new Button(resDetGrp, SWT.CHECK);
+        postBtn.setText("POST Request");
+
+        Label lbl = new Label(container, SWT.NULL);
+        lbl.setText("Details:");
+        gd = new GridData();
+        gd.verticalIndent = 20;
+        lbl.setLayoutData(gd);
+
+        Text desc = new Text(container, SWT.MULTI | SWT.READ_ONLY | SWT.BORDER
+                | SWT.WRAP | SWT.V_SCROLL);
+        desc.setBackground(container.getBackground());
+        desc.setText("Shows the different types of request that can be used by the clients on the resource.\n"
+                + "Resource will handle only the request types which are selected here.");
+        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        desc.setLayoutData(gd);
+
+        addUiListeners();
+
+        setControl(container);
+    }
+
+    private void addUiListeners() {
+        getBtn.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                getChecked = getBtn.getSelection();
+            }
+        });
+
+        putBtn.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                putChecked = putBtn.getSelection();
+            }
+        });
+
+        postBtn.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                postChecked = postBtn.getSelection();
+            }
+        });
+    }
+
+    @Override
+    public IWizardPage getNextPage() {
+        return null;
+    }
+
+    public boolean isGetChecked() {
+        return getChecked;
+    }
+
+    public boolean isPutChecked() {
+        return putChecked;
+    }
+
+    public boolean isPostChecked() {
+        return postChecked;
+    }
+
+}
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourcePage.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourcePage.java
new file mode 100644 (file)
index 0000000..e743332
--- /dev/null
@@ -0,0 +1,96 @@
+package oic.simulator.serviceprovider.view.dialogs;
+
+import oic.simulator.serviceprovider.utils.Constants;
+
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+public class SimpleResourcePage extends WizardPage {
+
+    Button manualBtn;
+    Button ramlBtn;
+
+    protected SimpleResourcePage() {
+        super("Simle Page");
+    }
+
+    @Override
+    public void createControl(Composite parent) {
+        setPageComplete(false);
+        setTitle(Constants.SIMPLE_PAGE_TITLE);
+        setMessage(Constants.SIMPLE_PAGE_MESSAGE);
+        Composite compContent = new Composite(parent, SWT.NONE);
+        GridLayout gridLayout = new GridLayout();
+        compContent.setLayout(gridLayout);
+        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        compContent.setLayoutData(gd);
+
+        manualBtn = new Button(compContent, SWT.RADIO);
+        manualBtn.setText("Manually");
+
+        ramlBtn = new Button(compContent, SWT.RADIO);
+        ramlBtn.setText("From RAML file");
+
+        Label lbl = new Label(compContent, SWT.NULL);
+        lbl.setText("Details:");
+        gd = new GridData();
+        gd.verticalIndent = 20;
+        lbl.setLayoutData(gd);
+
+        Text desc = new Text(compContent, SWT.MULTI | SWT.READ_ONLY
+                | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
+        desc.setBackground(compContent.getBackground());
+        desc.setText("[Select an option to view more details]");
+        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        desc.setLayoutData(gd);
+
+        addUIListeners();
+
+        setControl(compContent);
+    }
+
+    private void addUIListeners() {
+        manualBtn.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                getWizard().getContainer().updateButtons();
+            }
+        });
+
+        ramlBtn.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                getWizard().getContainer().updateButtons();
+            }
+        });
+    }
+
+    @Override
+    public boolean canFlipToNextPage() {
+        if (manualBtn.getSelection() || ramlBtn.getSelection()) {
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    public IWizardPage getNextPage() {
+        CreateResourceWizard createWizard = (CreateResourceWizard) getWizard();
+        if (manualBtn.getSelection()) {
+            return createWizard.getSimpleResourceBasicDetailsPage();
+        }
+        if (ramlBtn.getSelection()) {
+            return createWizard.getLoadRamlPage();
+        }
+        return null;
+    }
+}
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SingleTextInputDialog.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SingleTextInputDialog.java
new file mode 100644 (file)
index 0000000..860d31d
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package oic.simulator.serviceprovider.view.dialogs;
+
+import org.eclipse.jface.dialogs.TrayDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * This class shows a dialog for filtering logs based on severity levels.
+ */
+public class SingleTextInputDialog extends TrayDialog {
+
+    private Text   txt;
+    private String value;
+    private String lblTxt;
+    private String shellTitle;
+
+    public SingleTextInputDialog(Shell shell, String title, String lblTxt) {
+        super(shell);
+        shellTitle = title;
+        this.lblTxt = lblTxt;
+    }
+
+    @Override
+    protected void configureShell(Shell shell) {
+        super.configureShell(shell);
+    }
+
+    @Override
+    protected Control createDialogArea(Composite parent) {
+        Composite composite = (Composite) super.createDialogArea(parent);
+        getShell().setText(shellTitle);
+
+        Composite content = new Composite(parent, SWT.NULL);
+        GridLayout gridLayout = new GridLayout();
+        content.setLayout(gridLayout);
+        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        content.setLayoutData(gd);
+
+        Label lbl = new Label(content, SWT.NONE);
+        lbl.setText(lblTxt);
+
+        txt = new Text(content, SWT.BORDER);
+        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        txt.setLayoutData(gd);
+        txt.addModifyListener(new ModifyListener() {
+
+            @Override
+            public void modifyText(ModifyEvent e) {
+                value = txt.getText();
+            }
+        });
+
+        return composite;
+    }
+
+    @Override
+    protected void okPressed() {
+        if (null != value) {
+            value = value.trim();
+            if (value.length() > 0) {
+                close();
+                return;
+            }
+        }
+        txt.setFocus();
+    }
+
+    @Override
+    public boolean isHelpAvailable() {
+        return false;
+    }
+
+    public String getValue() {
+        return value;
+    }
+}
\ No newline at end of file
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/StartStopResourcePage.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/StartStopResourcePage.java
new file mode 100644 (file)
index 0000000..4f2a3c8
--- /dev/null
@@ -0,0 +1,90 @@
+package oic.simulator.serviceprovider.view.dialogs;
+
+import oic.simulator.serviceprovider.utils.Constants;
+
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+public class StartStopResourcePage extends WizardPage {
+
+    private Button  startButton;
+
+    private boolean start;
+
+    protected StartStopResourcePage() {
+        super("Start/Stop Resource");
+        setStart(true);
+    }
+
+    @Override
+    public void createControl(Composite parent) {
+        setPageComplete(false);
+        setTitle(Constants.START_STOP_PAGE_TITLE);
+        setMessage(Constants.START_STOP_PAGE_MESSAGE);
+        Composite compContent = new Composite(parent, SWT.NONE);
+        GridLayout gridLayout = new GridLayout();
+        compContent.setLayout(gridLayout);
+        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        compContent.setLayoutData(gd);
+
+        startButton = new Button(compContent, SWT.CHECK);
+        startButton.setText("Start Resource(s)");
+        startButton.setSelection(true);
+        gd = new GridData();
+        gd.verticalIndent = 10;
+        startButton.setLayoutData(gd);
+
+        Label descLbl = new Label(compContent, SWT.NONE);
+        descLbl.setText("Description:");
+        gd = new GridData();
+        gd.verticalIndent = 50;
+        descLbl.setLayoutData(gd);
+
+        final Text text = new Text(compContent, SWT.MULTI | SWT.READ_ONLY
+                | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
+        text.setText("Starting the resource will register it with the platform and makes it visible on the network.\n"
+                + "Resources can be started or stopped later from 'Resource Manager' view.");
+        gd = new GridData();
+        gd.horizontalAlignment = SWT.FILL;
+        gd.grabExcessHorizontalSpace = true;
+        gd.heightHint = 100;
+        gd.verticalAlignment = SWT.BOTTOM;
+        text.setLayoutData(gd);
+
+        addUIListeners();
+
+        setControl(compContent);
+    }
+
+    private void addUIListeners() {
+        startButton.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                setStart(startButton.getSelection());
+            }
+        });
+    }
+
+    public boolean isStart() {
+        return start;
+    }
+
+    public void setStart(boolean start) {
+        this.start = start;
+    }
+
+    @Override
+    public IWizardPage getNextPage() {
+        System.out.println(this.getClass().getName() + ": getNextPage");
+        return null;
+    }
+}
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/UpdatePropertiesPage.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/UpdatePropertiesPage.java
new file mode 100644 (file)
index 0000000..e2faddb
--- /dev/null
@@ -0,0 +1,255 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package oic.simulator.serviceprovider.view.dialogs;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.Date;
+
+import oic.simulator.serviceprovider.Activator;
+import oic.simulator.serviceprovider.utils.Constants;
+import oic.simulator.serviceprovider.utils.Utility;
+import oic.simulator.serviceprovider.view.dialogs.MainPage.ResourceOption;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.oic.simulator.ILogger.Level;
+import org.oic.simulator.SimulatorException;
+
+public class UpdatePropertiesPage extends WizardPage {
+
+    private Text   resNameTxt;
+    private Text   resUriTxt;
+
+    private String resName;
+    private String resURI;
+
+    protected UpdatePropertiesPage() {
+        super("Update Properties");
+    }
+
+    @Override
+    public void createControl(Composite parent) {
+        setPageComplete(true);
+        setTitle(Constants.UPDATE_PROP_PAGE_TITLE);
+        setMessage(Constants.UPDATE_PROP_PAGE_MESSAGE);
+
+        Composite comp = new Composite(parent, SWT.NONE);
+        GridLayout gridLayout = new GridLayout();
+        comp.setLayout(gridLayout);
+        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        comp.setLayoutData(gd);
+
+        Group grp = new Group(comp, SWT.NONE);
+        gridLayout = new GridLayout(2, false);
+        grp.setLayout(gridLayout);
+        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        grp.setLayoutData(gd);
+
+        Label resNameLbl = new Label(grp, SWT.NULL);
+        resNameLbl.setText("Resource Name");
+        gd = new GridData();
+        gd.verticalIndent = 20;
+        resNameLbl.setLayoutData(gd);
+
+        resNameTxt = new Text(grp, SWT.BORDER);
+        resNameTxt.setFocus();
+        gd = new GridData();
+        gd.widthHint = 300;
+        gd.verticalIndent = 20;
+        resNameTxt.setLayoutData(gd);
+
+        Label resUriLbl = new Label(grp, SWT.NULL);
+        resUriLbl.setText("Resource URI");
+        gd = new GridData();
+        gd.verticalIndent = 10;
+        resUriLbl.setLayoutData(gd);
+
+        resUriTxt = new Text(grp, SWT.BORDER);
+        gd = new GridData();
+        gd.widthHint = 300;
+        gd.verticalIndent = 10;
+        resUriTxt.setLayoutData(gd);
+
+        Label descLbl = new Label(comp, SWT.NONE);
+        descLbl.setText("Description:");
+        gd = new GridData();
+        descLbl.setLayoutData(gd);
+
+        final Text text = new Text(comp, SWT.MULTI | SWT.READ_ONLY | SWT.BORDER
+                | SWT.WRAP | SWT.V_SCROLL);
+        text.setText("These properties can be changed later from properties view.");
+        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        text.setLayoutData(gd);
+
+        addUIListeners();
+
+        // Initialize data
+        if (resUriTxt.getText().length() < 1 && null != resURI) {
+            resUriTxt.setText(resURI);
+        }
+        if (resNameTxt.getText().length() < 1 && null != resName) {
+            resNameTxt.setText(resName);
+        }
+
+        setControl(comp);
+    }
+
+    private void addUIListeners() {
+        resNameTxt.addModifyListener(new ModifyListener() {
+            @Override
+            public void modifyText(ModifyEvent e) {
+                resName = resNameTxt.getText();
+                setPageComplete(isSelectionDone());
+                // getWizard().getContainer().updateButtons();
+            }
+        });
+
+        resUriTxt.addModifyListener(new ModifyListener() {
+            @Override
+            public void modifyText(ModifyEvent e) {
+                resURI = resUriTxt.getText();
+                setPageComplete(isSelectionDone());
+                // getWizard().getContainer().updateButtons();
+            }
+        });
+    }
+
+    @Override
+    public boolean canFlipToNextPage() {
+        CreateResourceWizard createWizard = (CreateResourceWizard) getWizard();
+        if (isSelectionDone()
+                && (createWizard.getMainPage().getResourceOption() == ResourceOption.COLLECTION_FROM_RAML)
+                && Activator.getDefault().getResourceManager()
+                        .isAnyResourceExist()) {
+            return true;
+        }
+        return false;
+    }
+
+    public boolean isSelectionDone() {
+        boolean done = false;
+        if (null != resName && resName.trim().length() > 0 && null != resURI
+                && resURI.trim().length() > 0) {
+            done = true;
+        }
+        return done;
+    }
+
+    @Override
+    public IWizardPage getNextPage() {
+        final boolean done[] = new boolean[1];
+        CreateResourceWizard createWizard = (CreateResourceWizard) getWizard();
+        // Checking whether the uri is used by any other resource.
+        if (Activator.getDefault().getResourceManager().isResourceExist(resURI)) {
+            MessageDialog
+                    .openError(getShell(), "Resource URI in use",
+                            "Entered resource URI is in use. Please try a different one.");
+            // TODO: Instead of MessageDialog, errors may be shown on wizard
+            // itself.
+            return null;
+        }
+        try {
+            getContainer().run(true, true, new IRunnableWithProgress() {
+
+                @Override
+                public void run(IProgressMonitor monitor)
+                        throws InvocationTargetException, InterruptedException {
+                    try {
+                        monitor.beginTask(
+                                "Completing Collection Resource Creation With RAML",
+                                2);
+                        monitor.worked(1);
+                        done[0] = completeCollectionResourceCreationWithRAML();
+                        monitor.worked(1);
+                    } finally {
+                        monitor.done();
+                    }
+                }
+            });
+        } catch (InvocationTargetException e) {
+            Activator.getDefault().getLogManager()
+                    .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
+            e.printStackTrace();
+            return null;
+        } catch (InterruptedException e) {
+            Activator.getDefault().getLogManager()
+                    .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
+            e.printStackTrace();
+            return null;
+        }
+        if (!done[0]) {
+            return null;
+        }
+        return createWizard.getAddResourcesToCollectionPage();
+    }
+
+    public void setResName(String resName) {
+        this.resName = resName;
+        if (!resNameTxt.isDisposed())
+            resNameTxt.setText(resName);
+    }
+
+    public void setResURI(String resURI) {
+        this.resURI = resURI;
+        if (!resUriTxt.isDisposed())
+            resUriTxt.setText(resURI);
+    }
+
+    public String getResName() {
+        return resName;
+    }
+
+    public String getResURI() {
+        return resURI;
+    }
+
+    private boolean completeCollectionResourceCreationWithRAML() {
+        boolean result = false;
+        String status;
+        CreateResourceWizard createWizard = (CreateResourceWizard) getWizard();
+        try {
+            result = Activator
+                    .getDefault()
+                    .getResourceManager()
+                    .completeCollectionResourceCreationByRAML(
+                            createWizard.getLoadRamlPage().getResource(),
+                            resURI, resName);
+            if (result)
+                status = "Resource created.";
+            else {
+                status = "Failed to create resource.";
+            }
+        } catch (SimulatorException e) {
+            status = "Failed to create resource.\n"
+                    + Utility.getSimulatorErrorString(e, null);
+        }
+        createWizard.setStatus(status);
+        return result;
+    }
+}
index e470596..334b5b5 100644 (file)
@@ -18,6 +18,7 @@
  *
  ******************************************************************/
 
+#include "simulator_resource_model_jni.h"
 #include "simulator_exceptions_jni.h"
 #include "simulator_utils_jni.h"
 #include "jni_sharedobject_holder.h"
@@ -90,7 +91,7 @@ static void onObserverChange(jobject listener, const std::string &uri,
                              ObservationStatus state, const ObserverInfo &observerInfo)
 {
     JNIEnv *env = getEnv();
-    if (env)
+    if (!env)
         return;
 
     jclass listenerCls = env->GetObjectClass(listener);
@@ -113,6 +114,23 @@ static void onObserverChange(jobject listener, const std::string &uri,
     releaseEnv();
 }
 
+static void onResourceModelChange(jobject listener, const std::string &uri,
+                                  SimulatorResourceModel &resModel)
+{
+    JNIEnv *env = getEnv();
+    if (!env)
+        return;
+
+    jclass listenerCls = env->GetObjectClass(listener);
+    jmethodID listenerMethod = env->GetMethodID(listenerCls, "onResourceModelChanged",
+                               "(Ljava/lang/String;Lorg/oic/simulator/SimulatorResourceModel;)V");
+
+    jobject jResModel = simulatorResourceModelToJava(env, resModel);
+    jstring jUri = env->NewStringUTF(uri.c_str());
+    env->CallVoidMethod(listener, listenerMethod, jUri, jResModel);
+    releaseEnv();
+}
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -168,6 +186,37 @@ Java_org_oic_simulator_server_SimulatorResource_getInterface
     return JniVector(env).toJava(interfaces);
 }
 
+JNIEXPORT jboolean JNICALL
+Java_org_oic_simulator_server_SimulatorResource_isObservable
+(JNIEnv *env, jobject object)
+{
+    SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
+    VALIDATE_OBJECT_RET(env, resource, false)
+
+    return resource->isObservable();
+}
+
+JNIEXPORT jboolean JNICALL
+Java_org_oic_simulator_server_SimulatorResource_isStarted
+(JNIEnv *env, jobject object)
+{
+    SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
+    VALIDATE_OBJECT_RET(env, resource, false)
+
+    return resource->isStarted();
+}
+
+JNIEXPORT jobject JNICALL
+Java_org_oic_simulator_server_SimulatorResource_getResourceModel
+(JNIEnv *env, jobject object)
+{
+    SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
+    VALIDATE_OBJECT_RET(env, resource, nullptr)
+
+    SimulatorResourceModel resModel = resource->getResourceModel();
+    return simulatorResourceModelToJava(env, resModel);
+}
+
 JNIEXPORT void JNICALL
 Java_org_oic_simulator_server_SimulatorResource_setName
 (JNIEnv *env, jobject object, jstring name)
@@ -312,24 +361,30 @@ Java_org_oic_simulator_server_SimulatorResource_setObserverListener
     }
 }
 
-JNIEXPORT jboolean JNICALL
-Java_org_oic_simulator_server_SimulatorResource_isObservable
-(JNIEnv *env, jobject object)
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_server_SimulatorResource_setResourceModelChangeListener
+(JNIEnv *env, jobject object, jobject listener)
 {
-    SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
-    VALIDATE_OBJECT_RET(env, resource, false)
-
-    return resource->isObservable();
-}
+    VALIDATE_CALLBACK(env, listener)
 
-JNIEXPORT jboolean JNICALL
-Java_org_oic_simulator_server_SimulatorResource_isStarted
-(JNIEnv *env, jobject object)
-{
     SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
-    VALIDATE_OBJECT_RET(env, resource, false)
+    VALIDATE_OBJECT(env, resource)
 
-    return resource->isStarted();
+    SimulatorResource::ResourceModelChangedCallback callback =  std::bind(
+                [](const std::string & uri, SimulatorResourceModel & resModel,
+                   const std::shared_ptr<JniListenerHolder> &listenerRef)
+    {
+        onResourceModelChange(listenerRef->get(), uri, resModel);
+    }, std::placeholders::_1, std::placeholders::_2, JniListenerHolder::create(env, listener));
+
+    try
+    {
+        resource->setModelChangeCallback(callback);
+    }
+    catch (InvalidArgsException &e)
+    {
+        throwInvalidArgsException(env, e.code(), e.what());
+    }
 }
 
 JNIEXPORT void JNICALL
index 3ed5a1b..d363d0b 100644 (file)
@@ -153,77 +153,77 @@ class ValueConverterJava : public boost::static_visitor<jobject>
     private:
         jclass getClass(const std::vector<int> &)
         {
-            return gSimulatorClassRefs.integer1DArrayCls;
+            return gSimulatorClassRefs.integerCls;
         }
 
         jclass getClass(const std::vector<std::vector<int>> &)
         {
-            return gSimulatorClassRefs.integer2DArrayCls;
+            return gSimulatorClassRefs.integer1DArrayCls;
         }
 
         jclass getClass(const std::vector<std::vector<std::vector<int>>> &)
         {
-            return gSimulatorClassRefs.integer3DArrayCls;
+            return gSimulatorClassRefs.integer2DArrayCls;
         }
 
         jclass getClass(const std::vector<double> &)
         {
-            return gSimulatorClassRefs.double1DArrayCls;
+            return gSimulatorClassRefs.doubleCls;
         }
 
         jclass getClass(const std::vector<std::vector<double>> &)
         {
-            return gSimulatorClassRefs.double2DArrayCls;
+            return gSimulatorClassRefs.double1DArrayCls;
         }
 
         jclass getClass(const std::vector<std::vector<std::vector<double>>> &)
         {
-            return gSimulatorClassRefs.double3DArrayCls;
+            return gSimulatorClassRefs.double2DArrayCls;
         }
 
         jclass getClass(const std::vector<bool> &)
         {
-            return gSimulatorClassRefs.boolean1DArrayCls;
+            return gSimulatorClassRefs.booleanCls;
         }
 
         jclass getClass(const std::vector<std::vector<bool>> &)
         {
-            return gSimulatorClassRefs.boolean2DArrayCls;
+            return gSimulatorClassRefs.boolean1DArrayCls;
         }
 
         jclass getClass(const std::vector<std::vector<std::vector<bool>>> &)
         {
-            return gSimulatorClassRefs.boolean3DArrayCls;
+            return gSimulatorClassRefs.boolean2DArrayCls;
         }
 
         jclass getClass(const std::vector<std::string> &)
         {
-            return gSimulatorClassRefs.string1DArrayCls;
+            return gSimulatorClassRefs.stringCls;
         }
 
         jclass getClass(const std::vector<std::vector<std::string>> &)
         {
-            return gSimulatorClassRefs.string2DArrayCls;
+            return gSimulatorClassRefs.string1DArrayCls;
         }
 
         jclass getClass(const std::vector<std::vector<std::vector<std::string>>> &)
         {
-            return gSimulatorClassRefs.string3DArrayCls;
+            return gSimulatorClassRefs.string2DArrayCls;
         }
 
         jclass getClass(const std::vector<SimulatorResourceModel> &)
         {
-            return gSimulatorClassRefs.simulatorResModel1DArrayCls;
+            return gSimulatorClassRefs.simulatorResourceModelCls;
         }
 
         jclass getClass(const std::vector<std::vector<SimulatorResourceModel>> &)
         {
-            return gSimulatorClassRefs.simulatorResModel2DArrayCls;
+            return gSimulatorClassRefs.simulatorResModel1DArrayCls;
         }
 
         jclass getClass(const std::vector<std::vector<std::vector<SimulatorResourceModel>>> &)
         {
-            return gSimulatorClassRefs.simulatorResModel3DArrayCls;
+            return gSimulatorClassRefs.simulatorResModel2DArrayCls;
         }
 
         JNIEnv *m_env;
@@ -552,13 +552,14 @@ class JniAttributeProperty
         static jobject toJava(JNIEnv *env,
                               SimulatorResourceModel::AttributeProperty &property)
         {
+            jobject jAttributeProperty = nullptr;
             if (SimulatorResourceModel::AttributeProperty::Type::RANGE == property.type())
             {
                 static jmethodID propertyCtor = env->GetMethodID(
                                                     gSimulatorClassRefs.attributePropertyCls, "<init>", "(DD)V");
 
-                return env->NewObject(gSimulatorClassRefs.attributePropertyCls, propertyCtor,
-                                      property.min(), property.max());
+                jAttributeProperty = env->NewObject(gSimulatorClassRefs.attributePropertyCls, propertyCtor,
+                                                    property.min(), property.max());
             }
             else
             {
@@ -574,11 +575,24 @@ class JniAttributeProperty
                     env->SetObjectArrayElement(jValueSet, index++, jValue);
                 }
 
-                return env->NewObject(gSimulatorClassRefs.attributePropertyCls, propertyCtor,
-                                      jValueSet);
+                jAttributeProperty = env->NewObject(gSimulatorClassRefs.attributePropertyCls, propertyCtor,
+                                                    jValueSet);
             }
 
-            return nullptr;
+            // Add child property
+            if (jAttributeProperty && property.getChildProperty())
+            {
+                SimulatorResourceModel::AttributeProperty childProperty = *(property.getChildProperty());
+                jobject jChildProperty = JniAttributeProperty::toJava(env,  property);
+                if (jChildProperty)
+                {
+                    static jfieldID childPropFID = env->GetFieldID(gSimulatorClassRefs.attributePropertyCls,
+                                                   "mChildProperty", "Lorg/oic/simulator/AttributeProperty;");
+                    env->SetObjectField(jAttributeProperty, childPropFID, jChildProperty);
+                }
+            }
+
+            return jAttributeProperty;
         }
 
         static SimulatorResourceModel::AttributeProperty toCpp(JNIEnv *env, jobject jAttributeProperty)
@@ -591,21 +605,26 @@ class JniAttributeProperty
                                      "mMax", "D");
             static jfieldID valueSetFID = env->GetFieldID(gSimulatorClassRefs.attributePropertyCls,
                                           "mValueSet", "[Lorg/oic/simulator/AttributeValue;");
+            static jfieldID childPropFID = env->GetFieldID(gSimulatorClassRefs.attributePropertyCls,
+                                           "mChildProperty", "Lorg/oic/simulator/AttributeProperty;");
             static jmethodID ordinalMID = env->GetMethodID(
                                               gSimulatorClassRefs.attributePropertyTypeCls, "ordinal", "()I");
 
+            SimulatorResourceModel::AttributeProperty attributeProperty;
             jobject jType = env->GetObjectField(jAttributeProperty, typeFID);
             jdouble jMin = env->GetDoubleField(jAttributeProperty, minFID);
             jdouble jMax = env->GetDoubleField(jAttributeProperty, maxFID);
             jobjectArray jValueSet = (jobjectArray) env->GetObjectField(jAttributeProperty, valueSetFID);
+            jobject jChildProperty = env->GetObjectField(jAttributeProperty, childPropFID);
 
             int ordinal = env->CallIntMethod(jType, ordinalMID);
             switch (SimulatorResourceModel::AttributeProperty::Type(ordinal))
             {
                 case SimulatorResourceModel::AttributeProperty::Type::RANGE:
                     {
-                        return SimulatorResourceModel::AttributeProperty(jMin, jMax);
+                        attributeProperty = SimulatorResourceModel::AttributeProperty(jMin, jMax);
                     }
+                    break;
 
                 case SimulatorResourceModel::AttributeProperty::Type::VALUE_SET:
                     {
@@ -617,11 +636,20 @@ class JniAttributeProperty
                             valueSet.push_back(JniAttributeValue::toCpp(env, jAttributeValue));
                         }
 
-                        return SimulatorResourceModel::AttributeProperty(valueSet);
+                        attributeProperty = SimulatorResourceModel::AttributeProperty(valueSet);
                     }
+                    break;
+            }
+
+            // Set child property
+            if (jChildProperty)
+            {
+                SimulatorResourceModel::AttributeProperty childProperty =
+                    JniAttributeProperty::toCpp(env, jAttributeProperty);
+                attributeProperty.setChildProperty(childProperty);
             }
 
-            return SimulatorResourceModel::AttributeProperty();
+            return attributeProperty;
         }
 };
 
index d1547ec..f64a73a 100644 (file)
@@ -40,23 +40,6 @@ SimulatorSingleResourceSP simulatorSingleResourceToCpp(JNIEnv *env, jobject obje
     return nullptr;
 }
 
-static void onResourceModelChange(jobject listener, const std::string &uri,
-                                  SimulatorResourceModel &resModel)
-{
-    JNIEnv *env = getEnv();
-    if (!env)
-        return;
-
-    jclass listenerCls = env->GetObjectClass(listener);
-    jmethodID listenerMethod = env->GetMethodID(listenerCls, "onResourceModelChanged",
-                               "(Ljava/lang/String;Lorg/oic/simulator/SimulatorResourceModel;)V");
-
-    jobject jResModel = simulatorResourceModelToJava(env, resModel);
-    jstring jUri = env->NewStringUTF(uri.c_str());
-    env->CallVoidMethod(listenerCls, listenerMethod, jUri, jResModel);
-    releaseEnv();
-}
-
 static void onAutoUpdationComplete(jobject listener, const std::string &uri, const int id)
 {
     JNIEnv *env = getEnv();
@@ -77,17 +60,6 @@ extern "C" {
 #endif
 
 JNIEXPORT jobject JNICALL
-Java_org_oic_simulator_server_SimulatorSingleResource_getResourceModel
-(JNIEnv *env, jobject object)
-{
-    SimulatorSingleResourceSP singleResource = simulatorSingleResourceToCpp(env, object);
-    VALIDATE_OBJECT_RET(env, singleResource, nullptr)
-
-    SimulatorResourceModel resModel = singleResource->getResourceModel();
-    return simulatorResourceModelToJava(env, resModel);
-}
-
-JNIEXPORT jobject JNICALL
 Java_org_oic_simulator_server_SimulatorSingleResource_getAttribute
 (JNIEnv *env, jobject object, jstring attrName)
 {
@@ -254,32 +226,6 @@ Java_org_oic_simulator_server_SimulatorSingleResource_stopUpdation
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_server_SimulatorSingleResource_setModelChangeListener
-(JNIEnv *env, jobject object, jobject listener)
-{
-    VALIDATE_CALLBACK(env, listener)
-
-    SimulatorSingleResourceSP singleResource = simulatorSingleResourceToCpp(env, object);
-    VALIDATE_OBJECT(env, singleResource)
-
-    SimulatorResource::ResourceModelChangedCallback callback =  std::bind(
-                [](const std::string & uri, SimulatorResourceModel & resModel,
-                   const std::shared_ptr<JniListenerHolder> &listenerRef)
-    {
-        onResourceModelChange(listenerRef->get(), uri, resModel);
-    }, std::placeholders::_1, std::placeholders::_2, JniListenerHolder::create(env, listener));
-
-    try
-    {
-        singleResource->setModelChangeCallback(callback);
-    }
-    catch (InvalidArgsException &e)
-    {
-        throwInvalidArgsException(env, e.code(), e.what());
-    }
-}
-
-JNIEXPORT void JNICALL
 Java_org_oic_simulator_server_SimulatorSingleResource_dispose
 (JNIEnv *env, jobject object)
 {
index d2705cd..b555f0e 100644 (file)
@@ -21,10 +21,11 @@ package org.oic.simulator;
  */
 public class AttributeProperty {
 
-    private Type mType = Type.UNKNOWN;
-    private double mMin = -1;
-    private double mMax = -1;
+    private Type             mType     = Type.UNKNOWN;
+    private double           mMin      = -1;
+    private double           mMax      = -1;
     private AttributeValue[] mValueSet = null;
+    private AttributeProperty mChildProperty = null;
 
     /**
      * Enum to represent propety type.
@@ -34,8 +35,9 @@ public class AttributeProperty {
     }
 
     /**
-     * Constructs {@AttributeProperty} of type {@AttributeProperty.Type.Range}
-     * with min and max values.
+     * Constructs {@AttributeProperty} of type
+     * {@AttributeProperty.Type.Range} with min
+     * and max values.
      *
      * @param min
      *            Minimun value the attribute can have.
@@ -49,11 +51,12 @@ public class AttributeProperty {
     }
 
     /**
-     * Constructs {@AttributeProperty} of type {@AttributeProperty.Type.VALUESET}
-     * with array of integers.
+     * Constructs {@AttributeProperty} of type
+     * {@AttributeProperty.Type.VALUESET} with
+     * array of integer.
      *
      * @param values
-     *            Attribute will be having one of the value from this array at any time.
+     *            Array of int type values.
      */
     public AttributeProperty(int[] values) {
         mType = Type.VALUESET;
@@ -63,11 +66,12 @@ public class AttributeProperty {
     }
 
     /**
-     * Constructs {@AttributeProperty} of type {@AttributeProperty.Type.VALUESET}
-     * with array of doubles.
+     * Constructs {@AttributeProperty} of type
+     * {@AttributeProperty.Type.VALUESET} with
+     * array of double.
      *
      * @param values
-     *            Attribute will be having one of the value from this array at any time.
+     *            Array of double type values.
      */
     public AttributeProperty(double[] values) {
         mType = Type.VALUESET;
@@ -77,11 +81,27 @@ public class AttributeProperty {
     }
 
     /**
-     * Constructs {@AttributeProperty} of type {@AttributeProperty.Type.VALUESET}
-     * with array of Strings.
+     * Constructs {@AttributeProperty} of type
+     * {@AttributeProperty.Type.VALUESET} with
+     * array of boolean.
      *
      * @param values
-     *            Attribute will be having one of the value from this array at any time.
+     *            Array of boolean type values.
+     */
+    public AttributeProperty(boolean[] values) {
+        mType = Type.VALUESET;
+        mValueSet = new AttributeValue[values.length];
+        for (int i = 0; i < values.length; i++)
+            mValueSet[i] = new AttributeValue(values[i]);
+    }
+
+    /**
+     * Constructs {@AttributeProperty} of type
+     * {@AttributeProperty.Type.VALUESET} with
+     * array of Strings.
+     *
+     * @param values
+     *            Array of strings.
      */
     public AttributeProperty(String[] values) {
         mType = Type.VALUESET;
@@ -122,6 +142,26 @@ public class AttributeProperty {
         return mValueSet;
     }
 
+    /**
+     * API to set child attribute propety.
+     *
+     * @param childProperty
+     *            Child element property this property used if the
+     *            Attribute value is of array type.
+     */
+    public void setChildProperty(AttributeProperty childProperty) {
+        mChildProperty = childProperty;
+    }
+
+    /**
+     * API to get child attribute propety.
+     *
+     * @return Child element property.
+     */
+    public AttributeProperty getChildProperty() {
+        return mChildProperty;
+    }
+
     private AttributeProperty(AttributeValue[] values) {
         mType = Type.VALUESET;
         mValueSet = values;
index 23e0fb3..76bc72c 100644 (file)
@@ -36,10 +36,11 @@ public class AttributeValue {
     public class TypeInfo {
         public ValueType mType;
         public ValueType mBaseType;
-        public int mDepth;
+        public int       mDepth;
 
         /**
-         * Constructs {@AttributeValue.TypeInfo} with default values.
+         * Constructs {@AttributeValue.TypeInfo} with
+         * default values.
          */
         TypeInfo() {
             mType = ValueType.UNKNOWN;
@@ -48,7 +49,8 @@ public class AttributeValue {
         }
 
         /**
-         * Constructs {@AttributeValue.TypeInfo} with given {AttributeValue.ValueType}.
+         * Constructs {@AttributeValue.TypeInfo} with
+         * given {AttributeValue.ValueType}.
          *
          * @param type
          *            Value type.
@@ -60,15 +62,17 @@ public class AttributeValue {
         }
 
         /**
-         * Constructs {@AttributeValue.TypeInfo} with given {AttributeValue.ValueType}s
-         * and depth information.
+         * Constructs {@AttributeValue.TypeInfo} with
+         * given {AttributeValue.ValueType}s and depth information.
          *
          * @param type
          *            Value type.
          * @param baseType
-         *            Value base type. This type is useful when vaule is of array type.
+         *            Value base type. This type is useful when vaule is of
+         *            array type.
          * @param depth
-         *            Depth of array type value. This type is useful when vaule is of array type.
+         *            Depth of array type value. This type is useful when vaule
+         *            is of array type.
          */
         TypeInfo(ValueType type, ValueType baseType, int depth) {
             mType = type;
@@ -118,7 +122,8 @@ public class AttributeValue {
     }
 
     /**
-     * Constructs {@AttributeValue} with SimulatorResourceModel type value.
+     * Constructs {@AttributeValue} with SimulatorResourceModel
+     * type value.
      *
      * @param value
      *            SimulatorResourceModel type value.
@@ -128,7 +133,8 @@ public class AttributeValue {
     }
 
     /**
-     * Constructs {@AttributeValue} with array of int type values.
+     * Constructs {@AttributeValue} with array of int type
+     * values.
      *
      * @param values
      *            Array of int type values.
@@ -141,7 +147,8 @@ public class AttributeValue {
     }
 
     /**
-     * Constructs {@AttributeValue} with array of Integer type values.
+     * Constructs {@AttributeValue} with array of Integer type
+     * values.
      *
      * @param values
      *            Array of Integer type values.
@@ -151,7 +158,8 @@ public class AttributeValue {
     }
 
     /**
-     * Constructs {@AttributeValue} with array of double type values.
+     * Constructs {@AttributeValue} with array of double type
+     * values.
      *
      * @param values
      *            Array of double type values.
@@ -164,7 +172,8 @@ public class AttributeValue {
     }
 
     /**
-     * Constructs {@AttributeValue} with array of Double type values.
+     * Constructs {@AttributeValue} with array of Double type
+     * values.
      *
      * @param values
      *            Array of Double type values.
@@ -174,7 +183,8 @@ public class AttributeValue {
     }
 
     /**
-     * Constructs {@AttributeValue} with array of boolean type values.
+     * Constructs {@AttributeValue} with array of boolean type
+     * values.
      *
      * @param values
      *            Array of boolean type values.
@@ -187,7 +197,8 @@ public class AttributeValue {
     }
 
     /**
-     * Constructs {@AttributeValue} with array of Boolean type values.
+     * Constructs {@AttributeValue} with array of Boolean type
+     * values.
      *
      * @param values
      *            Array of Boolean type values.
@@ -197,7 +208,8 @@ public class AttributeValue {
     }
 
     /**
-     * Constructs {@AttributeValue} with array of String type values.
+     * Constructs {@AttributeValue} with array of String type
+     * values.
      *
      * @param values
      *            Array of String type values.
@@ -207,7 +219,8 @@ public class AttributeValue {
     }
 
     /**
-     * Constructs {@AttributeValue} with array of SimulatorResourceModel type values.
+     * Constructs {@AttributeValue} with array of
+     * SimulatorResourceModel type values.
      *
      * @param values
      *            Array of SimulatorResourceModel type values.
@@ -217,7 +230,8 @@ public class AttributeValue {
     }
 
     /**
-     * Constructs {@AttributeValue} with 2 dimensional array of int type values.
+     * Constructs {@AttributeValue} with 2 dimensional array of
+     * int type values.
      *
      * @param values
      *            2 dimensional array of int type values.
@@ -234,7 +248,8 @@ public class AttributeValue {
     }
 
     /**
-     * Constructs {@AttributeValue} with 2 dimensional array of Integer type values.
+     * Constructs {@AttributeValue} with 2 dimensional array of
+     * Integer type values.
      *
      * @param values
      *            2 dimensional array of Integer type values.
@@ -244,7 +259,8 @@ public class AttributeValue {
     }
 
     /**
-     * Constructs {@AttributeValue} with 2 dimensional array of double type values.
+     * Constructs {@AttributeValue} with 2 dimensional array of
+     * double type values.
      *
      * @param values
      *            2 dimensional array of double type values.
@@ -261,7 +277,8 @@ public class AttributeValue {
     }
 
     /**
-     * Constructs {@AttributeValue} with 2 dimensional array of Double type values.
+     * Constructs {@AttributeValue} with 2 dimensional array of
+     * Double type values.
      *
      * @param values
      *            2 dimensional array of Double type values.
@@ -271,7 +288,8 @@ public class AttributeValue {
     }
 
     /**
-     * Constructs {@AttributeValue} with 2 dimensional array of boolean type values.
+     * Constructs {@AttributeValue} with 2 dimensional array of
+     * boolean type values.
      *
      * @param values
      *            2 dimensional array of boolean type values.
@@ -288,7 +306,8 @@ public class AttributeValue {
     }
 
     /**
-     * Constructs {@AttributeValue} with 2 dimensional array of Boolean type values.
+     * Constructs {@AttributeValue} with 2 dimensional array of
+     * Boolean type values.
      *
      * @param values
      *            2 dimensional array of Boolean type values.
@@ -298,7 +317,8 @@ public class AttributeValue {
     }
 
     /**
-     * Constructs {@AttributeValue} with 2 dimensional array of String type values.
+     * Constructs {@AttributeValue} with 2 dimensional array of
+     * String type values.
      *
      * @param values
      *            2 dimensional array of String type values.
@@ -459,25 +479,21 @@ public class AttributeValue {
     }
 
     private TypeInfo createTypeInfo(Object value) {
-        TypeInfo typeInfo  = new TypeInfo();
+        TypeInfo typeInfo = new TypeInfo();
         String className = value.getClass().getName();
         if (className.contains(Integer.class.getName())) {
             typeInfo.mBaseType = ValueType.INTEGER;
             typeInfo.mType = ValueType.INTEGER;
-        }
-        else if (className.contains(Double.class.getName())) {
+        } else if (className.contains(Double.class.getName())) {
             typeInfo.mBaseType = ValueType.DOUBLE;
             typeInfo.mType = ValueType.DOUBLE;
-        }
-        else if (className.contains(Boolean.class.getName())) {
+        } else if (className.contains(Boolean.class.getName())) {
             typeInfo.mBaseType = ValueType.BOOLEAN;
             typeInfo.mType = ValueType.BOOLEAN;
-        }
-        else if (className.contains(String.class.getName())) {
+        } else if (className.contains(String.class.getName())) {
             typeInfo.mBaseType = ValueType.STRING;
             typeInfo.mType = ValueType.STRING;
-        }
-        else if (className.contains(SimulatorResourceModel.class.getName())) {
+        } else if (className.contains(SimulatorResourceModel.class.getName())) {
             typeInfo.mBaseType = ValueType.RESOURCEMODEL;
             typeInfo.mType = ValueType.RESOURCEMODEL;
         }
@@ -486,7 +502,8 @@ public class AttributeValue {
         if (value.getClass().isArray()) {
             typeInfo.mType = ValueType.ARRAY;
             for (char ch : className.toCharArray()) {
-                if (ch == '[') typeInfo.mDepth++;
+                if (ch == '[')
+                    typeInfo.mDepth++;
             }
         }
 
diff --git a/service/simulator/java/sdk/src/org/oic/simulator/AttributeValueValidation.java b/service/simulator/java/sdk/src/org/oic/simulator/AttributeValueValidation.java
new file mode 100644 (file)
index 0000000..935588f
--- /dev/null
@@ -0,0 +1,323 @@
+package org.oic.simulator;
+
+public class AttributeValueValidation implements AttributeValueVisitor.VisitingMethods<Boolean> {
+    private AttributeProperty mProperty = null;
+
+    public AttributeValueValidation(AttributeProperty property) {
+        mProperty = property;
+    }
+
+    public boolean validate(AttributeValue value) {
+        AttributeValueVisitor visitor = new AttributeValueVisitor(value, this);
+        Boolean result = (Boolean) visitor.visit();
+        return result.booleanValue();
+    }
+
+    @Override
+    public Boolean visitingValue(Integer value) {
+        if (mProperty == null)
+            return false;
+
+        if (checkRange(value.doubleValue()) || checkValueSet(value))
+            return true;
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Double value) {
+        if (mProperty == null)
+            return false;
+
+        if (checkRange(value.doubleValue()) || checkValueSet(value))
+            return true;
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Boolean value) {
+        if (mProperty == null)
+            return false;
+
+        if (checkValueSet(value))
+            return true;
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(String value) {
+        if (mProperty == null)
+            return false;
+
+        if (checkRange(value.length()) || checkValueSet(value))
+            return true;
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(SimulatorResourceModel value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Integer[] values) {
+        if (mProperty == null)
+            return false;
+
+        if (!checkRange(values.length))
+            return false;
+
+        if (mProperty.getChildProperty() != null) {
+            AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty());
+            for (Integer value : values) {
+                if (rangeValidation.visitingValue(value) == false)
+                    return false;
+            }
+        }
+
+        return true;
+    }
+
+    @Override
+    public Boolean visitingValue(Double[] values) {
+        if (mProperty == null)
+            return false;
+
+        if (!checkRange(values.length))
+            return false;
+
+        if (mProperty.getChildProperty() != null) {
+            AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty());
+            for (Double value : values) {
+                if (rangeValidation.visitingValue(value) == false)
+                    return false;
+            }
+        }
+
+        return true;
+    }
+
+    @Override
+    public Boolean visitingValue(Boolean[] values) {
+        if (mProperty == null)
+            return false;
+
+        if (!checkRange(values.length))
+            return false;
+
+        if (mProperty.getChildProperty() != null) {
+            AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty());
+            for (Boolean value : values) {
+                if (rangeValidation.visitingValue(value) == false)
+                    return false;
+            }
+        }
+
+        return true;
+    }
+
+    @Override
+    public Boolean visitingValue(String[] values) {
+        if (mProperty == null)
+            return false;
+
+        if (!checkRange(values.length))
+            return false;
+
+        if (mProperty.getChildProperty() != null) {
+            AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty());
+            for (String value : values) {
+                if (rangeValidation.visitingValue(value) == false)
+                    return false;
+            }
+        }
+
+        return true;
+    }
+
+    @Override
+    public Boolean visitingValue(SimulatorResourceModel[] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Integer[][] values) {
+        if (mProperty == null)
+            return false;
+
+        if (!checkRange(values.length))
+            return false;
+
+        if (mProperty.getChildProperty() != null) {
+            AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty());
+            for (Integer[] value : values) {
+                if (rangeValidation.visitingValue(value) == false)
+                    return false;
+            }
+        }
+
+        return true;
+    }
+
+    @Override
+    public Boolean visitingValue(Double[][] values) {
+        if (mProperty == null)
+            return false;
+
+        if (!checkRange(values.length))
+            return false;
+
+        if (mProperty.getChildProperty() != null) {
+            AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty());
+            for (Double[] value : values) {
+                if (rangeValidation.visitingValue(value) == false)
+                    return false;
+            }
+        }
+
+        return true;
+    }
+
+    @Override
+    public Boolean visitingValue(Boolean[][] values) {
+        if (mProperty == null)
+            return false;
+
+        if (!checkRange(values.length))
+            return false;
+
+        if (mProperty.getChildProperty() != null) {
+            AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty());
+            for (Boolean[] value : values) {
+                if (rangeValidation.visitingValue(value) == false)
+                    return false;
+            }
+        }
+
+        return true;
+    }
+
+    @Override
+    public Boolean visitingValue(String[][] values) {
+        if (mProperty == null)
+            return false;
+
+        if (!checkRange(values.length))
+            return false;
+
+        if (mProperty.getChildProperty() != null) {
+            AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty());
+            for (String[] value : values) {
+                if (rangeValidation.visitingValue(value) == false)
+                    return false;
+            }
+        }
+
+        return true;
+    }
+
+    @Override
+    public Boolean visitingValue(SimulatorResourceModel[][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Integer[][][] values) {
+        if (mProperty == null)
+            return false;
+
+        if (!checkRange(values.length))
+            return false;
+
+        if (mProperty.getChildProperty() != null) {
+            AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty());
+            for (Integer[][] value : values) {
+                if (rangeValidation.visitingValue(value) == false)
+                    return false;
+            }
+        }
+
+        return true;
+    }
+
+    @Override
+    public Boolean visitingValue(Double[][][] values) {
+        if (mProperty == null)
+            return false;
+
+        if (!checkRange(values.length))
+            return false;
+
+        if (mProperty.getChildProperty() != null) {
+            AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty());
+            for (Double[][] value : values) {
+                if (rangeValidation.visitingValue(value) == false)
+                    return false;
+            }
+        }
+
+        return true;
+    }
+
+    @Override
+    public Boolean visitingValue(Boolean[][][] values) {
+        if (mProperty == null)
+            return false;
+
+        if (!checkRange(values.length))
+            return false;
+
+        if (mProperty.getChildProperty() != null) {
+            AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty());
+            for (Boolean[][] value : values) {
+                if (rangeValidation.visitingValue(value) == false)
+                    return false;
+            }
+        }
+
+        return true;
+    }
+
+    @Override
+    public Boolean visitingValue(String[][][] values) {
+        if (mProperty == null)
+            return false;
+
+        if (!checkRange(values.length))
+            return false;
+
+        if (mProperty.getChildProperty() != null) {
+            AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty());
+            for (String[][] value : values) {
+                if (rangeValidation.visitingValue(value) == false)
+                    return false;
+            }
+        }
+
+        return true;
+    }
+
+    @Override
+    public Boolean visitingValue(SimulatorResourceModel[][][] value) {
+        return false;
+    }
+
+    private boolean checkRange(double value) {
+        if (AttributeProperty.Type.RANGE == mProperty.type()
+                && (value >= mProperty.min() && value <= mProperty.max())) {
+            return true;
+        }
+
+        return false;
+    }
+
+    private <T> boolean checkValueSet(T value) {
+        if (AttributeProperty.Type.VALUESET == mProperty.type() && null != mProperty.valueSet()) {
+            for (AttributeValue allowedValue : mProperty.valueSet()) {
+                if (allowedValue.get().equals(value))
+                    return true;
+            }
+        }
+
+        return false;
+    }
+}
diff --git a/service/simulator/java/sdk/src/org/oic/simulator/AttributeValueVisitor.java b/service/simulator/java/sdk/src/org/oic/simulator/AttributeValueVisitor.java
new file mode 100644 (file)
index 0000000..28fc0fb
--- /dev/null
@@ -0,0 +1,118 @@
+package org.oic.simulator;
+
+public class AttributeValueVisitor {
+    private AttributeValue mValue;
+    private VisitingMethods mListener;
+
+    public interface VisitingMethods<T extends Object> {
+        public T visitingValue(Integer value);
+
+        public T visitingValue(Double value);
+
+        public T visitingValue(Boolean value);
+
+        public T visitingValue(String value);
+
+        public T visitingValue(SimulatorResourceModel value);
+
+        public T visitingValue(Integer[] value);
+
+        public T visitingValue(Double[] value);
+
+        public T visitingValue(Boolean[] value);
+
+        public T visitingValue(String[] value);
+
+        public T visitingValue(SimulatorResourceModel[] value);
+
+        public T visitingValue(Integer[][] value);
+
+        public T visitingValue(Double[][] value);
+
+        public T visitingValue(Boolean[][] value);
+
+        public T visitingValue(String[][] value);
+
+        public T visitingValue(SimulatorResourceModel[][] value);
+
+        public T visitingValue(Integer[][][] value);
+
+        public T visitingValue(Double[][][] value);
+
+        public T visitingValue(Boolean[][][] value);
+
+        public T visitingValue(String[][][] value);
+
+        public T visitingValue(SimulatorResourceModel[][][] value);
+    }
+
+    public AttributeValueVisitor(AttributeValue value, VisitingMethods listener) {
+        mValue = value;
+        mListener = listener;
+    }
+
+    public Object visit() {
+        if (null == mValue || null == mListener)
+            return null;
+
+        AttributeValue.TypeInfo typeInfo = mValue.typeInfo();
+        if (AttributeValue.ValueType.INTEGER == typeInfo.mBaseType) {
+            if (AttributeValue.ValueType.INTEGER == typeInfo.mType)
+                return mListener.visitingValue((Integer) mValue.get());
+            else if (AttributeValue.ValueType.ARRAY == typeInfo.mType) {
+                if (1 == typeInfo.mDepth)
+                    return mListener.visitingValue((Integer[]) mValue.get());
+                if (2 == typeInfo.mDepth)
+                    return mListener.visitingValue((Integer[][]) mValue.get());
+                if (3 == typeInfo.mDepth)
+                    return mListener.visitingValue((Integer[][][]) mValue.get());
+            }
+        } else if (AttributeValue.ValueType.DOUBLE == typeInfo.mBaseType) {
+            if (AttributeValue.ValueType.DOUBLE == typeInfo.mType)
+                return mListener.visitingValue((Double) mValue.get());
+            else if (AttributeValue.ValueType.ARRAY == typeInfo.mType) {
+                if (1 == typeInfo.mDepth)
+                    return mListener.visitingValue((Double[]) mValue.get());
+                if (2 == typeInfo.mDepth)
+                    return mListener.visitingValue((Double[][]) mValue.get());
+                if (3 == typeInfo.mDepth)
+                    return mListener.visitingValue((Double[][][]) mValue.get());
+            }
+        } else if (AttributeValue.ValueType.BOOLEAN == typeInfo.mBaseType) {
+            if (AttributeValue.ValueType.BOOLEAN == typeInfo.mType)
+                return mListener.visitingValue((Boolean) mValue.get());
+            else if (AttributeValue.ValueType.ARRAY == typeInfo.mType) {
+                if (1 == typeInfo.mDepth)
+                    return mListener.visitingValue((Boolean[]) mValue.get());
+                if (2 == typeInfo.mDepth)
+                    return mListener.visitingValue((Boolean[][]) mValue.get());
+                if (3 == typeInfo.mDepth)
+                    return mListener.visitingValue((Boolean[][][]) mValue.get());
+            }
+        } else if (AttributeValue.ValueType.STRING == typeInfo.mBaseType) {
+            if (AttributeValue.ValueType.STRING == typeInfo.mType)
+                return mListener.visitingValue((String) mValue.get());
+            else if (AttributeValue.ValueType.ARRAY == typeInfo.mType) {
+                if (1 == typeInfo.mDepth)
+                    return mListener.visitingValue((String[]) mValue.get());
+                if (2 == typeInfo.mDepth)
+                    return mListener.visitingValue((String[][]) mValue.get());
+                if (3 == typeInfo.mDepth)
+                    return mListener.visitingValue((String[][][]) mValue.get());
+            }
+        } else if (AttributeValue.ValueType.RESOURCEMODEL == typeInfo.mBaseType) {
+            if (AttributeValue.ValueType.RESOURCEMODEL == typeInfo.mType)
+                return mListener.visitingValue((SimulatorResourceModel) mValue.get());
+            else if (AttributeValue.ValueType.ARRAY == typeInfo.mType) {
+                if (1 == typeInfo.mDepth)
+                    return mListener.visitingValue((SimulatorResourceModel[]) mValue.get());
+                if (2 == typeInfo.mDepth)
+                    return mListener.visitingValue((SimulatorResourceModel[][]) mValue.get());
+                if (3 == typeInfo.mDepth)
+                    return mListener.visitingValue((SimulatorResourceModel[][][]) mValue.get());
+            }
+        }
+
+        return null;
+    }
+}
index 87bf84a..eedc935 100644 (file)
@@ -28,8 +28,7 @@ public interface ILogger {
     }
 
     /**
-     * This method will be used to deliver the log messages from
-     * native layer.
+     * This method will be used to deliver the log messages from native layer.
      *
      * @param time
      *            Local time information when action/event logged.
index 37984fd..4f4fb5e 100644 (file)
@@ -27,7 +27,8 @@ import org.oic.simulator.server.SimulatorResource;
  */
 public class SimulatorManager {
 
-    private SimulatorManager(){}
+    private SimulatorManager() {
+    }
 
     /**
      * API for creating a resource from a RAML configuration file.
@@ -180,8 +181,15 @@ public class SimulatorManager {
     public static native void setLogger(ILogger logger)
             throws SimulatorException;
 
-    private static native Vector<SimulatorResource> createResources(String configPath, int count);
-    private static native SimulatorResource createSingleResource(String name, String uri, String resourceType);
-    private static native SimulatorResource createCollectionResource(String name, String uri, String resourceType);
-    private static native void searchResource(String resourceType, FindResourceListener listener);
+    private static native Vector<SimulatorResource> createResources(
+            String configPath, int count);
+
+    private static native SimulatorResource createSingleResource(String name,
+            String uri, String resourceType);
+
+    private static native SimulatorResource createCollectionResource(
+            String name, String uri, String resourceType);
+
+    private static native void searchResource(String resourceType,
+            FindResourceListener listener);
 }
\ No newline at end of file
index 1c36904..e2db0f4 100644 (file)
 package org.oic.simulator;
 
 /**
- * This class represents the resource attribute which contains
- * attribute value and its property.
+ * This class represents the resource attribute which contains attribute value
+ * and its property.
  */
 public class SimulatorResourceAttribute {
 
-    private String mName = null;
-    private AttributeValue mValue = null;
+    private String            mName     = null;
+    private AttributeValue    mValue    = null;
     private AttributeProperty mProperty = null;
 
     /**
-     * Constructs {@SimulatorResourceAttribute} with attribute name, value and its property.
+     * Constructs {@SimulatorResourceAttribute}
+     * with attribute name, value and its property.
      *
      * @param name
      *            Name of the attribute.
@@ -36,14 +37,16 @@ public class SimulatorResourceAttribute {
      * @param property
      *            Property of attribute value.
      */
-    public SimulatorResourceAttribute(String name, AttributeValue value, AttributeProperty property) {
+    public SimulatorResourceAttribute(String name, AttributeValue value,
+            AttributeProperty property) {
         mName = new String(name);
         mValue = value;
         mProperty = property;
     }
 
     /**
-     * Constructs {@SimulatorResourceAttribute} with attribute name, value.
+     * Constructs {@SimulatorResourceAttribute}
+     * with attribute name, value.
      *
      * @param name
      *            Name of the attribute.
@@ -77,9 +80,20 @@ public class SimulatorResourceAttribute {
     /**
      * API to get propety of attribute's value.
      *
-     * @return Attribute's value property{@AttributeProperty}.
+     * @return Attribute's value property        {@AttributeProperty
+     * }.
      */
     public AttributeProperty property() {
         return mProperty;
     }
+
+    /**
+     * API to set the value of attribute.
+     * 
+     * @param value
+     *            Value of the attribute.
+     */
+    public void setValue(AttributeValue value) {
+        this.mValue = value;
+    }
 }
index b5fcdb5..04c2de5 100644 (file)
@@ -24,7 +24,7 @@ import java.util.Map;
  */
 public class SimulatorResourceModel {
 
-    private Map<String, AttributeValue> mValues = null;
+    private Map<String, AttributeValue>    mValues     = null;
     private Map<String, AttributeProperty> mProperties = null;
 
     /**
@@ -46,7 +46,8 @@ public class SimulatorResourceModel {
      * @throws InvalidArgsException
      *             This exception will be thrown on invalid input.
      */
-    public void addAttribute(String attrName, AttributeValue value) throws InvalidArgsException {
+    public void addAttribute(String attrName, AttributeValue value)
+            throws InvalidArgsException {
         if (null == attrName || attrName.isEmpty())
             throw new InvalidArgsException("Invalid attribute name!");
 
@@ -60,14 +61,16 @@ public class SimulatorResourceModel {
      * API to add an attribute to resource model.
      *
      * @param attribute
-     *            {@link SimulatorResourceAttribute} to be add to resource model.
+     *            {@link SimulatorResourceAttribute} to be add to resource
+     *            model.
      *
      * @throws InvalidArgsException
      *             This exception will be thrown on invalid input.
      */
-    public void addAttribute(SimulatorResourceAttribute attribute) throws InvalidArgsException {
-        if (null == attribute || null == attribute.name() || attribute.name().isEmpty()
-            || null == attribute.value())
+    public void addAttribute(SimulatorResourceAttribute attribute)
+            throws InvalidArgsException {
+        if (null == attribute || null == attribute.name()
+                || attribute.name().isEmpty() || null == attribute.value())
             throw new InvalidArgsException("Invalid attribute!");
 
         mValues.put(attribute.name(), attribute.value());
@@ -84,7 +87,8 @@ public class SimulatorResourceModel {
      * @throws InvalidArgsException
      *             This exception will be thrown on invalid input.
      */
-    public void setAttributeProperty(String attrName, AttributeProperty property) throws InvalidArgsException {
+    public void setAttributeProperty(String attrName, AttributeProperty property)
+            throws InvalidArgsException {
         if (null == attrName || attrName.isEmpty())
             throw new InvalidArgsException("Invalid attribute!");
 
@@ -95,6 +99,28 @@ public class SimulatorResourceModel {
     }
 
     /**
+     * API to set attribute's value.
+     *
+     * @param attrName
+     *            Name of the attribute.
+     * @param value
+     *            {@link AttributeValue} to be set for attribute.
+     *
+     * @throws InvalidArgsException
+     *             This exception will be thrown on invalid input.
+     */
+    public void setAttributeValue(String attrName, AttributeValue value)
+            throws InvalidArgsException {
+        if (null == attrName || attrName.isEmpty())
+            throw new InvalidArgsException("Invalid attribute name!");
+
+        if (null == value)
+            throw new InvalidArgsException("Attribute value is null!");
+
+        mValues.put(attrName, value);
+    }
+
+    /**
      * API to get all the attributes of resource model.
      *
      * @return Map of attributes with attribute name as key and its
@@ -107,7 +133,8 @@ public class SimulatorResourceModel {
         Map<String, SimulatorResourceAttribute> attributes = new HashMap<>();
         for (Map.Entry<String, AttributeValue> entry : mValues.entrySet()) {
             SimulatorResourceAttribute attribute = new SimulatorResourceAttribute(
-                    entry.getKey(), entry.getValue(), mProperties.get(entry.getKey()));
+                    entry.getKey(), entry.getValue(), mProperties.get(entry
+                            .getKey()));
             attributes.put(entry.getKey(), attribute);
         }
 
@@ -139,7 +166,7 @@ public class SimulatorResourceModel {
      *            Name of the attribute.
      *
      * @return true if resource model has an attribute with given name,
-     *               otherwise false.
+     *         otherwise false.
      */
     public boolean containsAttribute(String attrName) {
         if (mValues.containsKey(attrName))
@@ -153,7 +180,8 @@ public class SimulatorResourceModel {
      * @param attrName
      *            Name of the attribute.
      *
-     * @return Attribute value type information {@AttributeValue.TypeInfo}.
+     * @return Attribute value type information         {@AttributeValue.TypeInfo
+     * }.
      */
     public AttributeValue.TypeInfo getAttributeType(String attrName) {
         if (mValues.containsKey(attrName))
@@ -167,8 +195,8 @@ public class SimulatorResourceModel {
      * @param attrName
      *            Name of the attribute.
      *
-     * @return true if resource model has attribute it is removed,
-     *               otherwise false.
+     * @return true if resource model has attribute it is removed, otherwise
+     *         false.
      */
     public boolean removeAttribute(String attrName) {
         if (mValues.containsKey(attrName)) {
index 3268e45..f40eaca 100644 (file)
@@ -21,54 +21,15 @@ package org.oic.simulator;
  */
 public enum SimulatorResult {
     /** STACK error codes - START */
-    SIMULATOR_OK,
-    SIMULATOR_RESOURCE_CREATED,
-    SIMULATOR_RESOURCE_DELETED,
-    SIMULATOR_CONTINUE,
-    SIMULATOR_INVALID_URI,
-    SIMULATOR_INVALID_QUERY,
-    SIMULATOR_INVALID_IP,
-    SIMULATOR_INVALID_PORT,
-    SIMULATOR_INVALID_CALLBACK,
-    SIMULATOR_INVALID_METHOD,
-    SIMULATOR_INVALID_PARAM,
-    SIMULATOR_INVALID_OBSERVE_PARAM,
-    SIMULATOR_NO_MEMORY,
-    SIMULATOR_COMM_ERROR,
-    SIMULATOR_TIMEOUT,
-    SIMULATOR_ADAPTER_NOT_ENABLED,
-    SIMULATOR_NOTIMPL,
-    SIMULATOR_NO_RESOURCE,
-    SIMULATOR_RESOURCE_ERROR,
-    SIMULATOR_SLOW_RESOURCE,
-    SIMULATOR_DUPLICATE_REQUEST,
-    SIMULATOR_NO_OBSERVERS,
-    SIMULATOR_OBSERVER_NOT_FOUND,
-    SIMULATOR_VIRTUAL_DO_NOT_HANDLE,
-    SIMULATOR_INVALID_OPTION,
-    SIMULATOR_MALFORMED_RESPONSE,
-    SIMULATOR_PERSISTENT_BUFFER_REQUIRED,
-    SIMULATOR_INVALID_REQUEST_HANDLE,
-    SIMULATOR_INVALID_DEVICE_INFO,
-    SIMULATOR_INVALID_JSON,
-    SIMULATOR_UNAUTHORIZED_REQ,
+    SIMULATOR_OK, SIMULATOR_RESOURCE_CREATED, SIMULATOR_RESOURCE_DELETED, SIMULATOR_CONTINUE, SIMULATOR_INVALID_URI, SIMULATOR_INVALID_QUERY, SIMULATOR_INVALID_IP, SIMULATOR_INVALID_PORT, SIMULATOR_INVALID_CALLBACK, SIMULATOR_INVALID_METHOD, SIMULATOR_INVALID_PARAM, SIMULATOR_INVALID_OBSERVE_PARAM, SIMULATOR_NO_MEMORY, SIMULATOR_COMM_ERROR, SIMULATOR_TIMEOUT, SIMULATOR_ADAPTER_NOT_ENABLED, SIMULATOR_NOTIMPL, SIMULATOR_NO_RESOURCE, SIMULATOR_RESOURCE_ERROR, SIMULATOR_SLOW_RESOURCE, SIMULATOR_DUPLICATE_REQUEST, SIMULATOR_NO_OBSERVERS, SIMULATOR_OBSERVER_NOT_FOUND, SIMULATOR_VIRTUAL_DO_NOT_HANDLE, SIMULATOR_INVALID_OPTION, SIMULATOR_MALFORMED_RESPONSE, SIMULATOR_PERSISTENT_BUFFER_REQUIRED, SIMULATOR_INVALID_REQUEST_HANDLE, SIMULATOR_INVALID_DEVICE_INFO, SIMULATOR_INVALID_JSON, SIMULATOR_UNAUTHORIZED_REQ,
 
-    SIMULATOR_PRESENCE_STOPPED,
-    SIMULATOR_PRESENCE_TIMEOUT,
-    SIMULATOR_PRESENCE_DO_NOT_HANDLE,
+    SIMULATOR_PRESENCE_STOPPED, SIMULATOR_PRESENCE_TIMEOUT, SIMULATOR_PRESENCE_DO_NOT_HANDLE,
     /** STACK error codes - END */
 
     /** Simulator specific error codes - START */
-    SIMULATOR_INVALID_TYPE,
-    SIMULATOR_NOT_SUPPORTED,
-    SIMULATOR_OPERATION_NOT_ALLOWED,
-    SIMULATOR_OPERATION_IN_PROGRESS,
+    SIMULATOR_INVALID_TYPE, SIMULATOR_NOT_SUPPORTED, SIMULATOR_OPERATION_NOT_ALLOWED, SIMULATOR_OPERATION_IN_PROGRESS,
 
-    SIMULATOR_INVALID_RESPONSE_CODE,
-    SIMULATOR_UKNOWN_PROPERTY,
-    SIMULATOR_TYPE_MISMATCH,
-    SIMULATOR_BAD_VALUE,
-    SIMULATOR_BAD_OBJECT,
+    SIMULATOR_INVALID_RESPONSE_CODE, SIMULATOR_UKNOWN_PROPERTY, SIMULATOR_TYPE_MISMATCH, SIMULATOR_BAD_VALUE, SIMULATOR_BAD_OBJECT,
     /** Simulator specific error codes - END */
 
     SIMULATOR_ERROR;
index 29e7c2e..be935ae 100644 (file)
@@ -19,13 +19,11 @@ package org.oic.simulator.client;
 import org.oic.simulator.client.SimulatorRemoteResource;
 
 /**
- * Listener for getting notification when resources are discovered in
- * network.
+ * Listener for getting notification when resources are discovered in network.
  */
 public interface FindResourceListener {
     /**
-     * Method will be called when resource is discovered in the
-     * network.
+     * Method will be called when resource is discovered in the network.
      *
      * @param resource
      *            {@link SimulatorRemoteResource} object representing the
index 8b60405..3e8f8a1 100644 (file)
@@ -142,8 +142,9 @@ public final class SimulatorRemoteResource {
      * @throws SimulatorException
      *             This exception will be thrown for other errors.
      */
-    public void get(Map<String, String> queryParams, GetResponseListener onGetListener)
-            throws InvalidArgsException, SimulatorException {
+    public void get(Map<String, String> queryParams,
+            GetResponseListener onGetListener) throws InvalidArgsException,
+            SimulatorException {
         nativeGet(null, queryParams, onGetListener);
     }
 
@@ -166,9 +167,11 @@ public final class SimulatorRemoteResource {
      *             This exception will be thrown for other errors.
      */
     public void get(String resourceInterface, Map<String, String> queryParams,
-            GetResponseListener onGetListener) throws InvalidArgsException, SimulatorException {
+            GetResponseListener onGetListener) throws InvalidArgsException,
+            SimulatorException {
         if (null == resourceInterface || resourceInterface.isEmpty())
-            throw new InvalidArgsException(SimulatorResult.SIMULATOR_INVALID_PARAM,
+            throw new InvalidArgsException(
+                    SimulatorResult.SIMULATOR_INVALID_PARAM,
                     "Invalid resource interface!");
         nativeGet(resourceInterface, queryParams, onGetListener);
     }
@@ -192,8 +195,10 @@ public final class SimulatorRemoteResource {
      * @throws SimulatorException
      *             This exception will be thrown for other errors.
      */
-    public void put(Map<String, String> queryParams, SimulatorResourceModel representation,
-            PutResponseListener onPutListener) throws InvalidArgsException, SimulatorException {
+    public void put(Map<String, String> queryParams,
+            SimulatorResourceModel representation,
+            PutResponseListener onPutListener) throws InvalidArgsException,
+            SimulatorException {
         nativePut(null, queryParams, representation, onPutListener);
     }
 
@@ -219,10 +224,12 @@ public final class SimulatorRemoteResource {
      *             This exception will be thrown for other errors.
      */
     public void put(String resourceInterface, Map<String, String> queryParams,
-            SimulatorResourceModel representation, PutResponseListener onPutListener)
-            throws InvalidArgsException, SimulatorException {
+            SimulatorResourceModel representation,
+            PutResponseListener onPutListener) throws InvalidArgsException,
+            SimulatorException {
         if (null == resourceInterface || resourceInterface.isEmpty())
-            throw new InvalidArgsException(SimulatorResult.SIMULATOR_INVALID_PARAM,
+            throw new InvalidArgsException(
+                    SimulatorResult.SIMULATOR_INVALID_PARAM,
                     "Invalid resource interface!");
         nativePut(resourceInterface, queryParams, representation, onPutListener);
     }
@@ -246,8 +253,10 @@ public final class SimulatorRemoteResource {
      * @throws SimulatorException
      *             This exception will be thrown for other errors.
      */
-    public void post(Map<String, String> queryParams, SimulatorResourceModel representation,
-            PostResponseListener onPostListener) throws InvalidArgsException, SimulatorException {
+    public void post(Map<String, String> queryParams,
+            SimulatorResourceModel representation,
+            PostResponseListener onPostListener) throws InvalidArgsException,
+            SimulatorException {
         nativePost(null, queryParams, representation, onPostListener);
     }
 
@@ -273,12 +282,15 @@ public final class SimulatorRemoteResource {
      *             This exception will be thrown for other errors.
      */
     public void post(String resourceInterface, Map<String, String> queryParams,
-            SimulatorResourceModel representation, PostResponseListener onPostListener)
-            throws InvalidArgsException, SimulatorException {
+            SimulatorResourceModel representation,
+            PostResponseListener onPostListener) throws InvalidArgsException,
+            SimulatorException {
         if (null == resourceInterface || resourceInterface.isEmpty())
-            throw new InvalidArgsException(SimulatorResult.SIMULATOR_INVALID_PARAM,
+            throw new InvalidArgsException(
+                    SimulatorResult.SIMULATOR_INVALID_PARAM,
                     "Invalid resource interface!");
-        nativePost(resourceInterface, queryParams, representation, onPostListener);
+        nativePost(resourceInterface, queryParams, representation,
+                onPostListener);
     }
 
     /**
@@ -298,8 +310,8 @@ public final class SimulatorRemoteResource {
      *             This exception will be thrown for other errors.
      */
     public native void startObserve(Map<String, String> queryParams,
-            ObserveNotificationListener onObserveListener) throws InvalidArgsException,
-            SimulatorException;
+            ObserveNotificationListener onObserveListener)
+            throws InvalidArgsException, SimulatorException;
 
     /**
      * API to stop observing the resource.
@@ -310,7 +322,8 @@ public final class SimulatorRemoteResource {
      * @throws SimulatorException
      *             This exception will be thrown for other errors.
      */
-    public native void stopObserve() throws InvalidArgsException, SimulatorException;
+    public native void stopObserve() throws InvalidArgsException,
+            SimulatorException;
 
     /**
      * API to provide remote resource configure information, which is required
@@ -319,17 +332,16 @@ public final class SimulatorRemoteResource {
      * @param path
      *            Path to RAML file.
      *
-     * @return representation
-     *            {@link SimulatorResourceModel} holding the representation of
-     *            the remote resource.
+     * @return representation {@link SimulatorResourceModel} holding the
+     *         representation of the remote resource.
      *
      * @throws InvalidArgsException
      *             Thrown if the RAML configuration file path is invalid.
      * @throws SimulatorException
      *             Thrown for other errors.
      */
-    public native SimulatorResourceModel setConfigInfo(String path) throws InvalidArgsException,
-            SimulatorException;
+    public native SimulatorResourceModel setConfigInfo(String path)
+            throws InvalidArgsException, SimulatorException;
 
     /**
      * API to send multiple requests for the resource, based on the configure
@@ -357,9 +369,9 @@ public final class SimulatorRemoteResource {
      *             This exception will be thrown for other errors.
      */
     public int startVerification(VerificationType type,
-            VerificationListener onVerifyListener)
-            throws InvalidArgsException, NoSupportException,
-            OperationInProgressException, SimulatorException {
+            VerificationListener onVerifyListener) throws InvalidArgsException,
+            NoSupportException, OperationInProgressException,
+            SimulatorException {
         return startVerification(type.ordinal(), onVerifyListener);
     }
 
@@ -375,8 +387,8 @@ public final class SimulatorRemoteResource {
      * @throws SimulatorException
      *             Thrown for other errors.
      */
-    public native void stopVerification(int id)
-            throws InvalidArgsException, SimulatorException;
+    public native void stopVerification(int id) throws InvalidArgsException,
+            SimulatorException;
 
     /**
      * Listener for receiving asynchronous response for GET request.
@@ -438,15 +450,16 @@ public final class SimulatorRemoteResource {
      */
     public interface ObserveNotificationListener {
         /**
-         * This method will be called when there is a change in the resource model
-         * of the remote resource.
+         * This method will be called when there is a change in the resource
+         * model of the remote resource.
          *
          * @param uid
          *            Unique Id of the resource.
          * @param resourceModel
          *            {@link SimulatorResourceModel}.
          * @param sequenceNumber
-         *            Sequential number for ordering the model change notifications.
+         *            Sequential number for ordering the model change
+         *            notifications.
          */
         public void onObserveNotification(String uid,
                 SimulatorResourceModel resourceModel, int sequenceNumber);
@@ -487,15 +500,20 @@ public final class SimulatorRemoteResource {
         public void onVerificationCompleted(String uid, int id);
     }
 
-
     private native void nativeGet(String resourceInterface,
-            Map<String, String> queryParamsMap, GetResponseListener onGetListener);
+            Map<String, String> queryParamsMap,
+            GetResponseListener onGetListener);
 
-    private native void nativePut(String resourceInterface, Map<String, String> queryParams,
-            SimulatorResourceModel representation, PutResponseListener onPutListener);
+    private native void nativePut(String resourceInterface,
+            Map<String, String> queryParams,
+            SimulatorResourceModel representation,
+            PutResponseListener onPutListener);
 
-    private native void nativePost(String resourceInterface, Map<String, String> queryParams,
-            SimulatorResourceModel representation, PostResponseListener onPostListener);
+    private native void nativePost(String resourceInterface,
+            Map<String, String> queryParams,
+            SimulatorResourceModel representation,
+            PostResponseListener onPostListener);
 
-    private native int startVerification(int type, VerificationListener onVerifyListener);
+    private native int startVerification(int type,
+            VerificationListener onVerifyListener);
 }
index 39a3269..42c7b79 100644 (file)
@@ -28,55 +28,59 @@ public final class SimulatorCollectionResource extends SimulatorResource {
     }
 
     /**
-    * API to add child resource to collection.
-    *
-    * @param resource
-    *            Child resource to be added to collection.
-    *
-    * @throws InvalidArgsException
-    *              This exception will be thrown on invalid input.
-    * @throws SimulatorException
-    *             This exception will be thrown on occurrence of error in native.
-    */
+     * API to add child resource to collection.
+     *
+     * @param resource
+     *            Child resource to be added to collection.
+     *
+     * @throws InvalidArgsException
+     *             This exception will be thrown on invalid input.
+     * @throws SimulatorException
+     *             This exception will be thrown on occurrence of error in
+     *             native.
+     */
     public native void addChildResource(SimulatorResource resource)
             throws InvalidArgsException, SimulatorException;
 
     /**
-    * API to remove child resource from collection.
-    *
-    * @param resource
-    *            Child resource to be removed from collection.
-    *
-    * @throws InvalidArgsException
-    *              This exception will be thrown on invalid input.
-    * @throws SimulatorException
-    *             This exception will be thrown on occurrence of error in native.
-    */
+     * API to remove child resource from collection.
+     *
+     * @param resource
+     *            Child resource to be removed from collection.
+     *
+     * @throws InvalidArgsException
+     *             This exception will be thrown on invalid input.
+     * @throws SimulatorException
+     *             This exception will be thrown on occurrence of error in
+     *             native.
+     */
     public native void removeChildResource(SimulatorResource resource)
             throws InvalidArgsException, SimulatorException;
 
     /**
-    * API to remove child resource from collection.
-    *
-    * @param uri
-    *            URI of child resource to be removed from collection.
-    *
-    * @throws InvalidArgsException
-    *              This exception will be thrown on invalid input.
-    * @throws SimulatorException
-    *             This exception will be thrown on occurrence of error in native.
-    */
+     * API to remove child resource from collection.
+     *
+     * @param uri
+     *            URI of child resource to be removed from collection.
+     *
+     * @throws InvalidArgsException
+     *             This exception will be thrown on invalid input.
+     * @throws SimulatorException
+     *             This exception will be thrown on occurrence of error in
+     *             native.
+     */
     public native void removeChildResourceByUri(String uri)
             throws InvalidArgsException, SimulatorException;
 
     /**
-    * API to get list of child resources.
-    *
-    * @return Vector of child resources {@link SimulatorResource}.
-    *
-    * @throws SimulatorException
-    *             This exception will be thrown on occurrence of error in native.
-    */
+     * API to get list of child resources.
+     *
+     * @return Vector of child resources {@link SimulatorResource}.
+     *
+     * @throws SimulatorException
+     *             This exception will be thrown on occurrence of error in
+     *             native.
+     */
     public native Vector<SimulatorResource> getChildResource()
             throws SimulatorException;
 }
index 0211955..5120fd8 100644 (file)
@@ -28,7 +28,8 @@ public class SimulatorResource {
 
     protected long mNativeHandle;
 
-    protected SimulatorResource(){}
+    protected SimulatorResource() {
+    }
 
     @Override
     protected void finalize() throws Throwable {
@@ -55,20 +56,20 @@ public class SimulatorResource {
      * @return Name of the resource.
      *
      * @throws SimulatorException
-     *             This exception will be thrown if the native resource object does
-     *             not exist or for some general errors.
+     *             This exception will be thrown if the native resource object
+     *             does not exist or for some general errors.
      */
     public native String getName() throws SimulatorException;
 
     /**
-     * API to get the type which indicates whether resource is
-     * single or collection resource.
+     * API to get the type which indicates whether resource is single or
+     * collection resource.
      *
      * @return Type of resource.
      *
      * @throws SimulatorException
-     *             This exception will be thrown if the native resource object does
-     *             not exist or for some general errors.
+     *             This exception will be thrown if the native resource object
+     *             does not exist or for some general errors.
      */
     public native Type getType() throws SimulatorException;
 
@@ -78,8 +79,8 @@ public class SimulatorResource {
      * @return Resource URI.
      *
      * @throws SimulatorException
-     *             This exception will be thrown if the native resource object does
-     *             not exist or for some general errors.
+     *             This exception will be thrown if the native resource object
+     *             does not exist or for some general errors.
      */
     public native String getURI() throws SimulatorException;
 
@@ -89,8 +90,8 @@ public class SimulatorResource {
      * @return Resource type.
      *
      * @throws SimulatorException
-     *             This exception will be thrown if the native resource object does
-     *             not exist or for some general errors.
+     *             This exception will be thrown if the native resource object
+     *             does not exist or for some general errors.
      */
     public native String getResourceType() throws SimulatorException;
 
@@ -100,121 +101,159 @@ public class SimulatorResource {
      * @return Interface type.
      *
      * @throws SimulatorException
-     *             This exception will be thrown if the native resource object does
-     *             not exist or for some general errors.
+     *             This exception will be thrown if the native resource object
+     *             does not exist or for some general errors.
      */
     public native Vector<String> getInterface() throws SimulatorException;
 
     /**
+     * API to get the observable state of resource.
+     *
+     * @return Observable state - true if resource is observable, otherwise
+     *         false.
+     *
+     * @throws SimulatorException
+     *             This exception will be thrown if the native resource object
+     *             does not exist or for some general errors.
+     */
+    public native boolean isObservable() throws SimulatorException;
+
+    /**
+     * API to get the start state of resource.
+     *
+     * @return Start state - true if resource is started, otherwise false.
+     *
+     * @throws SimulatorException
+     *             This exception will be thrown if the native resource object
+     *             does not exist or for some general errors.
+     */
+    public native boolean isStarted() throws SimulatorException;
+
+    /**
+     * API to get the {@link SimulatorResourceModel} of the simulated resource.
+     *
+     * @return {@link SimulatorResourceModel} object on success, otherwise null.
+     *
+     * @throws SimulatorException
+     *             This exception will be thrown if simulated resource is not
+     *             proper.
+     */
+    public native SimulatorResourceModel getResourceModel()
+            throws SimulatorException;
+
+    /**
      * API to set the name of the resource.
      *
-     * @param name - Name to be set.
+     * @param name
+     *            - Name to be set.
      *
      * @throws InvalidArgsException
-     *              This exception will be thrown if the resource name is
-     *              invalid.
+     *             This exception will be thrown if the resource name is
+     *             invalid.
      * @throws SimulatorException
-     *             This exception will be thrown if the native resource object does
-     *             not exist or for some general errors.
+     *             This exception will be thrown if the native resource object
+     *             does not exist or for some general errors.
      */
-    public native void setName(String name) throws InvalidArgsException, SimulatorException;
+    public native void setName(String name) throws InvalidArgsException,
+            SimulatorException;
 
     /**
      * API to set the resource URI.
      *
-     * @param uri - URI to be set.
+     * @param uri
+     *            - URI to be set.
      *
      * @throws InvalidArgsException
-     *              This exception will be thrown if the resource URI is
-     *              invalid.
+     *             This exception will be thrown if the resource URI is invalid.
      * @throws SimulatorException
-     *             This exception will be thrown if the native resource object does
-     *             not exist or for some general errors.
+     *             This exception will be thrown if the native resource object
+     *             does not exist or for some general errors.
      */
-    public native void setURI(String uri) throws InvalidArgsException, SimulatorException;
+    public native void setURI(String uri) throws InvalidArgsException,
+            SimulatorException;
 
     /**
      * API to set the resource type.
      *
-     * @param resourceType - resource type string.
+     * @param resourceType
+     *            - resource type string.
      *
      * @throws InvalidArgsException
-     *              This exception will be thrown if the resource type is
-     *              invalid.
+     *             This exception will be thrown if the resource type is
+     *             invalid.
      * @throws SimulatorException
-     *             This exception will be thrown if the native resource object does
-     *             not exist or for some general errors.
+     *             This exception will be thrown if the native resource object
+     *             does not exist or for some general errors.
      */
-    public native void setResourceType(String resourceType) throws InvalidArgsException, SimulatorException;
+    public native void setResourceType(String resourceType)
+            throws InvalidArgsException, SimulatorException;
 
     /**
      * API to add interface type for resource.
      *
-     * @param interfaceType - interface to be added for resource.
+     * @param interfaceType
+     *            - interface to be added for resource.
      *
      * @throws InvalidArgsException
-     *              This exception will be thrown if the interface type is
-     *              invalid.
+     *             This exception will be thrown if the interface type is
+     *             invalid.
      * @throws SimulatorException
-     *             This exception will be thrown if the native resource object does
-     *             not exist or for some general errors.
+     *             This exception will be thrown if the native resource object
+     *             does not exist or for some general errors.
      */
-    public native void addInterface(String interfaceType) throws InvalidArgsException, SimulatorException;
+    public native void addInterface(String interfaceType)
+            throws InvalidArgsException, SimulatorException;
 
     /**
      * API to make the resource observable or not.
      *
-     * @param state - true make the resource observable, otherwise non-observable.
+     * @param state
+     *            - true make the resource observable, otherwise non-observable.
      *
      * @throws SimulatorException
-     *             This exception will be thrown if the native resource object does
-     *             not exist or for some general errors.
+     *             This exception will be thrown if the native resource object
+     *             does not exist or for some general errors.
      */
     public native void setObservable(boolean state) throws SimulatorException;
 
     /**
-     * API to set the listener for receiving the notifications when
-     * observer is registered or unregistered with resource.
+     * API to set the listener for receiving the notifications when observer is
+     * registered or unregistered with resource.
      *
-     * @param listener - Callback to be set for receiving the notifications.
+     * @param listener
+     *            - Callback to be set for receiving the notifications.
      *
      * @throws InvalidArgsException
-     *              This exception will be thrown if the listener is
-     *              invalid.
-     * @throws SimulatorException
-     *             This exception will be thrown if the native resource object does
-     *             not exist or for some general errors.
-     */
-    public native void setObserverListener(ObserverListener listener) throws InvalidArgsException, SimulatorException;
-
-    /**
-     * API to get the observable state of resource.
-     *
-     * @return Observable state - true if resource is observable, otherwise false.
-     *
+     *             This exception will be thrown if the listener is invalid.
      * @throws SimulatorException
-     *             This exception will be thrown if the native resource object does
-     *             not exist or for some general errors.
+     *             This exception will be thrown if the native resource object
+     *             does not exist or for some general errors.
      */
-    public native boolean isObservable() throws SimulatorException;
+    public native void setObserverListener(ObserverListener listener)
+            throws InvalidArgsException, SimulatorException;
 
     /**
-     * API to get the start state of resource.
+     * API to set listener for receiving notifications when resource's model
+     * gets changed.
      *
-     * @return Start state - true if resource is started, otherwise false.
+     * @param listener
+     *            {@link ResourceModelChangeListener}.
      *
+     * @throws InvalidArgsException
+     *             This exception will be thrown on invalid input.
      * @throws SimulatorException
-     *             This exception will be thrown if the native resource object does
-     *             not exist or for some general errors.
+     *             This exception will be thrown for other errors.
      */
-    public native boolean isStarted() throws SimulatorException;
+    public native void setResourceModelChangeListener(
+            ResourceModelChangeListener listener) throws InvalidArgsException,
+            SimulatorException;
 
     /**
      * API to start the resource.
      *
      * @throws SimulatorException
-     *             This exception will be thrown if the native resource object does
-     *             not exist or for some general errors.
+     *             This exception will be thrown if the native resource object
+     *             does not exist or for some general errors.
      */
     public native void start() throws SimulatorException;
 
@@ -222,8 +261,8 @@ public class SimulatorResource {
      * API to stop the resource.
      *
      * @throws SimulatorException
-     *             This exception will be thrown if the native resource object does
-     *             not exist or for some general errors.
+     *             This exception will be thrown if the native resource object
+     *             does not exist or for some general errors.
      */
     public native void stop() throws SimulatorException;
 
@@ -233,19 +272,20 @@ public class SimulatorResource {
      * @return observers as an array of {@link Observer}.
      *
      * @throws SimulatorException
-     *             This exception will be thrown if the native resource object does
-     *             not exist or for some general errors.
+     *             This exception will be thrown if the native resource object
+     *             does not exist or for some general errors.
      */
     public native Vector<Observer> getObservers() throws SimulatorException;
 
     /**
      * API to notify current resource model to specific observer.
      *
-     * @param observerId - Observer ID to notify.
+     * @param observerId
+     *            - Observer ID to notify.
      *
      * @throws SimulatorException
-     *             This exception will be thrown if the native resource object does
-     *             not exist or for some general errors.
+     *             This exception will be thrown if the native resource object
+     *             does not exist or for some general errors.
      */
     public native void notifyObserver(int observerId) throws SimulatorException;
 
@@ -253,14 +293,14 @@ public class SimulatorResource {
      * API to notify all registered observers.
      *
      * @throws SimulatorException
-     *             This exception will be thrown if the native resource object does
-     *             not exist or for some general errors.
+     *             This exception will be thrown if the native resource object
+     *             does not exist or for some general errors.
      */
     public native void notifyAllObservers() throws SimulatorException;
 
     /**
-     * Listener for receiving notification when observer is registered or unregistered
-     * with the resource.
+     * Listener for receiving notification when observer is registered or
+     * unregistered with the resource.
      */
     public interface ObserverListener {
         /**
@@ -287,9 +327,8 @@ public class SimulatorResource {
     }
 
     /**
-     * Listener for receiving notification on completion of
-     * automatically updating attribute value from its range or
-     * value set property.
+     * Listener for receiving notification on completion of automatically
+     * updating attribute value from its range or value set property.
      */
     public interface AutoUpdateListener {
         /**
@@ -309,14 +348,15 @@ public class SimulatorResource {
      */
     public interface ResourceModelChangeListener {
         /**
-         * Method will be invoked to notify about the changes in the
-         * resource model.
+         * Method will be invoked to notify about the changes in the resource
+         * model.
          *
          * @param uri
          *            URI of resource.
          * @param resourceModel
          *            {@link SimulatorResourceModel} of the resource.
          */
-        public void onResourceModelChanged(String uri, SimulatorResourceModel resourceModel);
+        public void onResourceModelChanged(String uri,
+                SimulatorResourceModel resourceModel);
     }
 }
index 0ac7715..7a1d8ab 100644 (file)
@@ -29,24 +29,13 @@ public final class SimulatorSingleResource extends SimulatorResource {
     }
 
     /**
-     * API to get the {@link SimulatorResourceModel} of the simulated resource.
-     *
-     * @return {@link SimulatorResourceModel} object on success, otherwise null.
-     *
-     * @throws SimulatorException
-     *             This exception will be thrown if simulated resource is not
-     *             proper.
-     */
-    public native SimulatorResourceModel getResourceModel() throws SimulatorException;
-
-    /**
      * API to get attribute of resource.
      *
      * @param attrName
      *            Name of the attribute
      *
-     * @return An object of {@link SimulatorResourceAttribute},
-     *             or null if resource doest not have attribute of this name.
+     * @return An object of {@link SimulatorResourceAttribute}, or null if
+     *         resource doest not have attribute of this name.
      *
      * @throws InvalidArgsException
      *             This exception will be thrown if the attribute name is
@@ -124,9 +113,9 @@ public final class SimulatorSingleResource extends SimulatorResource {
      * @throws SimulatorException
      *             This exception will be thrown for other errors.
      */
-    public native int startResourceUpdation(AutoUpdateType type,
-            int interval, AutoUpdateListener listener)
-            throws InvalidArgsException, SimulatorException;
+    public native int startResourceUpdation(AutoUpdateType type, int interval,
+            AutoUpdateListener listener) throws InvalidArgsException,
+            SimulatorException;
 
     /**
      * API to start the attribute level automation. This automation involves
@@ -163,21 +152,5 @@ public final class SimulatorSingleResource extends SimulatorResource {
      * @throws SimulatorException
      *             This exception will be thrown for general errors.
      */
-    public native void stopUpdation(int id)
-            throws SimulatorException;
-
-    /**
-     * API to set listener for receiving notifications when resource's model
-     * gets changed.
-     *
-     * @param listener
-     *            {@link ResourceModelChangeListener}.
-     *
-     * @throws InvalidArgsException
-     *             This exception will be thrown on invalid input.
-     * @throws SimulatorException
-     *             This exception will be thrown for other errors.
-     */
-    public native void setResourceModelChangeListener(ResourceModelChangeListener listener)
-            throws InvalidArgsException, SimulatorException;
+    public native void stopUpdation(int id) throws SimulatorException;
 }
index 38fe308..efaa23c 100755 (executable)
@@ -47,4 +47,3 @@ ramlsdk = raml_env.SharedLibrary('RamlParser', raml_src)
 raml_env.InstallTarget(ramlsdk, 'libRaml')\r
 \r
 SConscript('../../../extlibs/yaml/SConscript')\r
-SConscript('example/SConscript')\r
diff --git a/service/simulator/ramlparser/example/SConscript b/service/simulator/ramlparser/example/SConscript
deleted file mode 100755 (executable)
index 41ee9a0..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-#******************************************************************\r
-#\r
-# Copyright 2015 Samsung Electronics All Rights Reserved.\r
-#\r
-#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
-#\r
-# Licensed under the Apache License, Version 2.0 (the "License");\r
-# you may not use this file except in compliance with the License.\r
-# You may obtain a copy of the License at\r
-#\r
-#      http://www.apache.org/licenses/LICENSE-2.0\r
-#\r
-# Unless required by applicable law or agreed to in writing, software\r
-# distributed under the License is distributed on an "AS IS" BASIS,\r
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-# See the License for the specific language governing permissions and\r
-# limitations under the License.\r
-#\r
-#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
-import os\r
-Import('env')\r
-lib_env = env.Clone()\r
-SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')\r
-raml_env = lib_env.Clone()\r
-\r
-######################################################################\r
-# Build flags\r
-######################################################################\r
-raml_env.AppendUnique(CPPPATH = ['../../../../extlibs/timer'])\r
-raml_env.AppendUnique(CPPPATH = ['../raml/model','../raml/jsonSchemaParser', '../raml' , '../../../../extlibs/yaml/yaml/src' , '../../../../extlibs/yaml/yaml/include'])\r
-raml_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread'])\r
-raml_env.AppendUnique(CPPDEFINES = ['LINUX'])\r
-\r
-raml_env.AppendUnique(CPPPATH = ['../../../../extlibs/cjson/'])\r
-raml_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'connectivity_abstraction', 'libcoap'])\r
-raml_env.AppendUnique(LIBS = ['pthread'])\r
-raml_env.PrependUnique(LIBS = ['RamlParser','YamlParser'])\r
-\r
-raml_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])\r
-raml_env.AppendUnique(RPATH = [env.get('BUILD_DIR')])\r
-\r
-if raml_env.get('SECURED') == '1':\r
-    raml_env.AppendUnique(LIBS = ['tinydtls'])\r
-######################################################################\r
-# Source files and Targets\r
-######################################################################\r
-raml_parser = raml_env.Program('raml-parser', 'raml_parser.cpp')\r
-\r
-env.AppendTarget('raml_parser')\r
diff --git a/service/simulator/ramlparser/example/raml_parser.cpp b/service/simulator/ramlparser/example/raml_parser.cpp
deleted file mode 100755 (executable)
index f8525ff..0000000
+++ /dev/null
@@ -1,532 +0,0 @@
-/******************************************************************\r
- *\r
- * Copyright 2015 Samsung Electronics All Rights Reserved.\r
- *\r
- *\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *      http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- ******************************************************************/\r
-\r
-#include "RamlParser.h"\r
-#include "Helpers.h"\r
-#include <iostream>\r
-#include <string>\r
-#include <memory>\r
-\r
-//#define PRINT_PARAMS\r
-//#define PRINT_PROTOCOLS\r
-//#define PRINT_BASEURI\r
-//#define PRINT_DOCUMENTATION\r
-//#define PRINT_TYPES\r
-//#define PRINT_TRAITS\r
-//#define PRINT_RESOURCE_URI_BASEURI\r
-//#define PRINT_ACTION_QUERY_PARAM\r
-//#define PRINT_RESPONSE_HEADER\r
-#define PRINT_REQUEST_RESPONSE_BODY_PARAMS\r
-//#define PRINT_ACTION_HEADERS\r
-//#define PRINT_SCHEMAS\r
-#define PRINT_RAML\r
-#define PRINT_JSON\r
-//#define PRINT_JSON_DEFINITION\r
-#define PRINT_JSON_PROPERTIES\r
-\r
-using namespace RAML;\r
-\r
-void printProperties(const PropertiesPtr &prop);\r
-\r
-#ifdef PRINT_PARAMS\r
-void printParameters(AbstractParam abstractParam)\r
-{\r
-    std::cout << "Description : "  << abstractParam.getDescription()  << std::endl;\r
-    std::cout << "DefaultValue : "  << abstractParam.getDefaultValue()  << std::endl;\r
-    std::cout << "Example : " << abstractParam.getExample()  << std::endl;\r
-    std::cout << "displayName : "  << abstractParam.getDisplayName()  << std::endl;\r
-    std::cout << "Maxlength : "  << abstractParam.getMaxLength()  << std::endl;\r
-    std::cout << "Max : "  << abstractParam.getMaximum()  << std::endl;\r
-    std::cout << "Minlength : "  << abstractParam.getMinLength()  << std::endl;\r
-    std::cout << "Min : "  << abstractParam.getMinimum()  << std::endl;\r
-    std::cout << "Pattern : "  << abstractParam.getPattern()  << std::endl;\r
-    std::cout << "Type : "  << abstractParam.getType()  << std::endl;\r
-    std::cout << "Repeat : "  << abstractParam.isRepeat()  << std::endl;\r
-    std::cout << "Required : "  << abstractParam.isRequired()  << std::endl;\r
-    std::cout << "Enum : "   ;\r
-    for (auto elem : abstractParam.getEnumeration())\r
-        std::cout << elem   << "       ";\r
-    std::cout << std::endl;\r
-}\r
-#endif\r
-\r
-void printRequestResponseBody(const RequestResponseBodyPtr &body)\r
-{\r
-    std::cout << "Body : Type : " << body->getType() << std::endl;\r
-    if ( body->getSchema() == NULL ) return;\r
-#ifdef PRINT_SCHEMAS\r
-    std::cout << "Body : Schema : " << body->getSchema()->getSchema() << std::endl;\r
-#endif\r
-    std::cout << "Body : Schema : PROPERTIES :" << std::endl;\r
-\r
-    for ( auto pro : body->getSchema()->getProperties()->getProperties() )\r
-    {\r
-        printProperties(pro.second);\r
-    }\r
-\r
-    std::cout << "Body : Schema : ITEMS :" << std::endl;\r
-    for (auto it : body->getSchema()->getProperties()->getItems())\r
-    {\r
-        for (auto  tt : it->getProperties())\r
-        {\r
-            printProperties(tt.second);\r
-        }\r
-    }\r
-#ifdef PRINT_SCHEMAS\r
-    std::cout << "-----------------------------" << std::endl;\r
-    std::cout << "Body : example : " << body->getExample() << std::endl;\r
-#endif\r
-\r
-#ifdef PRINT_REQUEST_RESPONSE_BODY_PARAMS\r
-    std::cout << "Body : FormParameters        "  << std::endl;\r
-    for (auto  tw : body->getFormParameters())\r
-    {\r
-        std::cout << "-----------------------------" << std::endl;\r
-        std::cout << tw.first << " : "  << std::endl;\r
-        std::cout << "-----------------------------" << std::endl;\r
-        FormParameter formParameter = *tw.second;\r
-#ifdef PRINT_PARAMS\r
-        printParameters((AbstractParam)formParameter);\r
-#endif\r
-    }\r
-#endif\r
-}\r
-\r
-\r
-void printResponse(const ResponsePtr &response)\r
-{\r
-    std::cout << "#############################################" << std::endl;\r
-    std::cout << "Response : Description : " << response->getDescription() << std::endl;\r
-\r
-    for (auto  tv :  response->getResponseBody())\r
-        printRequestResponseBody(tv.second);\r
-#ifdef PRINT_RESPONSE_HEADER\r
-    std::cout << "Header" << std::endl;\r
-    for (auto  tw :  response->getHeaders())\r
-    {\r
-        std::cout << "-----------------------------" << std::endl;\r
-        std::cout << tw.first << " : "  << std::endl;\r
-        std::cout << "-----------------------------" << std::endl;\r
-\r
-        Header header = *tw.second;\r
-#ifdef PRINT_PARAMS\r
-        printParameters((AbstractParam)header);\r
-#endif\r
-    }\r
-#endif\r
-}\r
-\r
-void printAction(const ActionPtr &action)\r
-{\r
-    std::cout << "Description : " << action->getDescription() << std::endl;\r
-    std::cout << "----Action Body--------------" << std::endl;\r
-    for (auto  tv :  action->getRequestBody())\r
-        printRequestResponseBody(tv.second);\r
-    std::cout << "-----------------------------" << std::endl;\r
-    std::cout << "Responses    " << std::endl;\r
-    for (auto  tu :  action->getResponses())\r
-    {\r
-        std::cout << "Response : " << tu.first << std::endl;\r
-        printResponse(tu.second);\r
-    }\r
-#ifdef PRINT_ACTION_QUERY_PARAM\r
-    std::cout << "QueryParameter" << std::endl;\r
-    for (auto  tw :  action->getQueryParameters())\r
-    {\r
-        std::cout << "-----------------------------" << std::endl;\r
-        std::cout << tw.first << " : "  << std::endl;\r
-        std::cout << "-----------------------------" << std::endl;\r
-        QueryParameter queryParam = *tw.second;\r
-#ifdef PRINT_PARAMS\r
-        printParameters((AbstractParam)queryParam);\r
-#endif\r
-    }\r
-#endif\r
-#ifdef PRINT_ACTION_HEADERS\r
-    std::cout << "Headers" << std::endl;\r
-    for (auto  tw :  action->getHeaders())\r
-    {\r
-        std::cout << "-----------------------------" << std::endl;\r
-        std::cout << tw.first << " : "  << std::endl;\r
-        std::cout << "-----------------------------" << std::endl;\r
-        Header header = *tw.second;\r
-#ifdef PRINT_PARAMS\r
-        printParameters((AbstractParam)header);\r
-#endif\r
-    }\r
-#endif\r
-\r
-#ifdef PRINT_TRAITS\r
-\r
-    std::cout << "Traits  " << std::endl;\r
-    std::cout << "-----------------------------" << std::endl;\r
-    for (auto  tt :  action->getTraits())\r
-    {\r
-        std::cout << tt  << "     ";\r
-    }\r
-    std::cout << std::endl << "-----------------------------" << std::endl;\r
-#endif\r
-}\r
-\r
-void printResource(const RamlResourcePtr &resource)\r
-{\r
-    std::cout << "Displayname : " << resource->getDisplayName()   << std::endl;\r
-    std::cout << "Description : " << resource->getDescription()   << std::endl;\r
-#ifdef PRINT_RESOURCE_URI_BASEURI\r
-    std::cout << "#############################################" << std::endl;\r
-    std::cout << "ResourceURI  "   << resource->getResourceUri() << std::endl;\r
-    std::cout << "UriParameters        "    << std::endl;\r
-    for (auto  tt :  resource->getUriParameters())\r
-    {\r
-        std::cout << "-----------------------------" << std::endl;\r
-        std::cout << tt.first << " : "  << std::endl;\r
-        std::cout << "-----------------------------" << std::endl;\r
-        UriParameter uriParameter = *tt.second;\r
-#ifdef PRINT_PARAMS\r
-        printParameters((AbstractParam)uriParameter);\r
-#endif\r
-    }\r
-    std::cout << "#############################################" << std::endl;\r
-    std::cout << "BaseUriParameters    "    << std::endl;\r
-    for (auto  tt :  resource->getBaseUriParameters())\r
-    {\r
-        std::cout << "-----------------------------" << std::endl;\r
-        std::cout << tt.first << " : "  << std::endl;\r
-        std::cout << "-----------------------------" << std::endl;\r
-\r
-        UriParameter uriParameter = *tt.second;\r
-#ifdef PRINT_PARAMS\r
-        printParameters((AbstractParam)uriParameter);\r
-#endif\r
-    }\r
-#endif\r
-    std::cout << "Actions  " << std::endl;\r
-    for (auto  tt :  resource->getActions())\r
-    {\r
-        std::cout << "#############################################" << std::endl;\r
-        std::cout << "ActionsType  " << std::endl;\r
-        printAction(tt.second);\r
-    }\r
-#ifdef PRINT_TRAITS\r
-    std::cout << "Traits  " << std::endl;\r
-    std::cout << "-----------------------------" << std::endl;\r
-    for (auto  tt :  resource->getTraits())\r
-    {\r
-        std::cout << tt  << "     ";\r
-    }\r
-    std::cout << std::endl << "-----------------------------" << std::endl;\r
-#endif\r
-    std::cout << "Number of Child Resource for " << resource->getDisplayName() << " : " <<\r
-              resource->getResources().size() << std::endl;\r
-\r
-    for (auto  tt :  resource->getResources())\r
-    {\r
-        std::cout << "Child Resource" << std::endl;\r
-        std::cout << "-----------------------------" << std::endl;\r
-        std::cout << "ResourceName :" << tt.first << std::endl;\r
-        printResource(tt.second);\r
-    }\r
-\r
-}\r
-void printProperties(const PropertiesPtr &prop)\r
-{\r
-#ifdef PRINT_JSON_PROPERTIES\r
-    std::cout << "-------------------------------" << std::endl;\r
-#endif\r
-    std::cout << "Name: " << prop->getName() << std::endl;\r
-#ifdef PRINT_JSON_PROPERTIES\r
-    std::cout << "-------------------------------" << std::endl;\r
-    std::cout << "Type: " << prop->getType() << std::endl;\r
-    std::cout << "Description: " << prop->getDescription() << std::endl;\r
-    try\r
-    {\r
-        switch (prop->getVariantType())\r
-        {\r
-            case VariantType::INT : // Integer\r
-                std::cout << "Defaut: " << prop->getValueInt() << std::endl;\r
-                for (auto tt : prop->getAllowedValuesInt())\r
-                {\r
-                    std::cout << "enum value : " << tt << std::endl;\r
-                }\r
-                {\r
-                    double min = 0, max = 0;\r
-                    int mul = 0;\r
-                    prop->getRange(min, max, mul);\r
-                    std::cout << "Minimum: " << min << std::endl;\r
-                    std::cout << "Maximum: " << max << std::endl;\r
-                }\r
-                break;\r
-\r
-            case VariantType::DOUBLE : // Double\r
-                std::cout << "Defaut: " << prop->getValueDouble() << std::endl;\r
-                for (auto tt : prop->getAllowedValuesDouble())\r
-                {\r
-                    std::cout << "enum value : " << tt << std::endl;\r
-                }\r
-                {\r
-                    double min = 0, max = 0;\r
-                    int mul = 0;\r
-                    prop->getRange(min, max, mul);\r
-                    std::cout << "MinimumDouble: " << min << std::endl;\r
-                    std::cout << "MaximumDouble: " << max << std::endl;\r
-                }\r
-                break;\r
-\r
-            case VariantType::BOOL : // Boolean\r
-                std::cout << "Defaut: " << std::boolalpha << prop->getValueBool() << std::noboolalpha << std::endl;\r
-                for (auto tt : prop->getAllowedValuesBool())\r
-                {\r
-                    std::cout << std::boolalpha << "enum value : " << tt << std::noboolalpha << std::endl;\r
-                }\r
-                break;\r
-\r
-            case VariantType::STRING : // String\r
-                std::cout << "Defaut: " << prop->getValueString() << std::endl;\r
-                for (auto tt : prop->getAllowedValuesString())\r
-                {\r
-                    std::cout << "enum value : " << tt << std::endl;\r
-                }\r
-                {\r
-                    double min = 0, max = 0;\r
-                    int mul = 0;\r
-                    prop->getRange(min, max, mul);\r
-                    std::cout << "MinimumLength: " << min << std::endl;\r
-                    std::cout << "MaximumLength: " << max << std::endl;\r
-                }\r
-                break;\r
-            default:\r
-                break;\r
-\r
-        }\r
-    }\r
-    catch (const boost::bad_lexical_cast &e)\r
-    {\r
-        std::cout << e.what() << std::endl;\r
-    }\r
-    catch ( ... )\r
-    {\r
-        std::cout << "Unknown exception caught!" << std::endl;\r
-    }\r
-\r
-    if (prop->getType() == "array")\r
-    {\r
-        for (auto it : prop->getItems())\r
-        {\r
-            std::cout << "items Type : " << it->getType() << std::endl;\r
-            if (it->getType() == "string")\r
-                for (auto tt : it->getAllowedValuesString())\r
-                {\r
-                    std::cout << "enum value : " << tt << std::endl;\r
-                }\r
-            for (auto tt : it->getProperties())\r
-            {\r
-                printProperties(tt.second);\r
-            }\r
-            std::cout << "Item Required Values : " << std::endl;\r
-            for (auto tt : it->getRequiredValues())\r
-            {\r
-                std::cout << tt << std::endl;\r
-            }\r
-        }\r
-    }\r
-#endif\r
-\r
-}\r
-void printJsonSchema(JsonSchemaPtr js)\r
-{\r
-    std::cout << "##############################" << std::endl;\r
-    std::cout << "------JSON Schema Parser------" << std::endl;\r
-    std::cout << "##############################" << std::endl;\r
-\r
-    std::cout << "Id: " << js->getId() << std::endl;\r
-    std::cout << "Schema: " << js->getSchema() << std::endl;\r
-    std::cout << "Title: " << js->getTitle() << std::endl;\r
-    std::cout << "Type: " << js->getType() << std::endl;\r
-    std::cout << "Description: " << js->getDescription() << std::endl;\r
-    std::cout << "AdditionalProperties: " << js->getAdditionalProperties() << std::endl;\r
-#ifdef PRINT_JSON_DEFINITION\r
-    std::cout << "-------------------------------" << std::endl;\r
-    std::cout << "Definitions." << std::endl;\r
-    for (auto  tt : js->getDefinitions())\r
-    {\r
-        std::cout << "-------------------------------" << std::endl;\r
-        std::cout << tt.first << std::endl;\r
-        for (auto  it : tt.second->getProperties())\r
-        {\r
-            printProperties(it.second);\r
-        }\r
-    }\r
-#endif\r
-    std::cout << "##############################" << std::endl;\r
-    std::cout << "Properties." << std::endl;\r
-    for (auto  it : js->getProperties())\r
-    {\r
-        printProperties(it.second);\r
-    }\r
-    std::cout << "-------------------------------" << std::endl;\r
-    std::cout << "Required." << std::endl;\r
-    std::cout << "-------------------------------" << std::endl;\r
-    for (auto it : js->getRequiredValues())\r
-    {\r
-        std::cout << it << std::endl;\r
-    }\r
-    std::cout << "-------------------------------" << std::endl;\r
-    std::cout << "Items." << std::endl;\r
-    std::cout << "-------------------------------" << std::endl;\r
-    for (auto it : js->getItems())\r
-    {\r
-        for (auto  tt : it->getProperties())\r
-        {\r
-            printProperties(tt.second);\r
-        }\r
-        std::cout << "-------------------------------" << std::endl;\r
-        std::cout << "Required." << std::endl;\r
-        std::cout << "-------------------------------" << std::endl;\r
-        for (auto tt : it->getRequiredValues())\r
-        {\r
-            std::cout << tt << std::endl;\r
-        }\r
-    }\r
-    std::cout << "-------------------------------" << std::endl;\r
-}\r
-\r
-int main(int argc, char *argv[])\r
-{\r
-    if (argc == 1)\r
-    {\r
-        return 0;\r
-    }\r
-    char *value = argv[1];\r
-    std::string s(value);\r
-\r
-    try\r
-    {\r
-        std::shared_ptr<RamlParser> ramlParser = std::make_shared<RamlParser>(s);\r
-        RamlPtr m_raml = ramlParser->getRamlPtr();\r
-#ifdef PRINT_RAML\r
-\r
-        std::cout << "#############################################" << std::endl;\r
-        std::cout << "Test Raml Parser" << std::endl;\r
-        std::cout << "#############################################" << std::endl;\r
-\r
-        std::cout << "Title : " << m_raml->getTitle() << std::endl;\r
-        std::cout << "Version : " <<  m_raml->getVersion() << std::endl;\r
-#ifdef PRINT_PROTOCOLS\r
-        std::cout << "Protocols : "   ;\r
-        for (auto  it : m_raml->getProtocols())\r
-        {\r
-            std::cout << it  << "     ";\r
-        }\r
-\r
-        std::cout << std::endl;\r
-#endif\r
-#ifdef PRINT_BASEURI\r
-        std::cout << "BaseUri : " <<  m_raml->getBaseUri() << std::endl;\r
-\r
-        std::cout << "BaseUriParameters : " << std::endl;\r
-        for (auto  it : m_raml->getBaseUriParameters())\r
-        {\r
-            std::cout << "-----------------------------" << std::endl;\r
-            std::cout << it.first << " : "  << std::endl;\r
-            std::cout << "-----------------------------" << std::endl;\r
-            UriParameter uriParameter = *it.second;\r
-#ifdef PRINT_PARAMS\r
-            printParameters((AbstractParam)uriParameter);\r
-#endif\r
-        }\r
-#endif\r
-#ifdef PRINT_SCHEMAS\r
-        std::cout << "#############################################" << std::endl;\r
-        std::cout << "Schemas" << std::endl;\r
-        std::cout << "-----------------------------" << std::endl;\r
-        for (auto  it : m_raml->getSchemas())\r
-        {\r
-            std::cout << it.first   << " : " << it.second->getSchema() << std::endl;\r
-        }\r
-#endif\r
-        std::cout << "MediaType : " <<  m_raml->getMediaType() << std::endl;\r
-        std::cout << "#############################################" << std::endl;\r
-#ifdef PRINT_DOCUMENTATION\r
-        std::cout << "#############################################" << std::endl;\r
-\r
-        std::cout << "Documentation" << std::endl;\r
-        std::cout << "-----------------------------" << std::endl;\r
-        for (auto  it : m_raml->getDocumentation())\r
-        {\r
-            std::cout << it->getTitle() << " : " << it->getContent() << std::endl;\r
-        }\r
-        std::cout << "#############################################" << std::endl;\r
-#endif\r
-\r
-        std::cout << "Resources" << std::endl;\r
-        for (auto  it : m_raml->getResources())\r
-        {\r
-            std::cout << "-----------------------------" << std::endl;\r
-            std::cout << "ResourceName :" << it.first << std::endl;\r
-            printResource(it.second);\r
-        }\r
-#ifdef PRINT_TYPES\r
-\r
-        std::cout << "#############################################" << std::endl;\r
-\r
-        std::cout << "ResourceTypes " << std::endl;\r
-        for (auto  it : m_raml->getResourceTypes())\r
-        {\r
-            std::cout << "------------" << it.first << "-----------------" << std::endl;\r
-            printResource(it.second);\r
-        }\r
-#endif\r
-#ifdef PRINT_TRAITS\r
-\r
-        std::cout << "#############################################" << std::endl;\r
-\r
-        std::cout << "Traits " << std::endl;\r
-        for (auto  it : m_raml->getTraits())\r
-        {\r
-            std::cout << "-------------" << it.first << "----------------" << std::endl;\r
-            printAction(it.second);\r
-        }\r
-#endif\r
-#endif\r
-#ifdef PRINT_JSON\r
-        for (auto  it : m_raml->getResources())\r
-        {\r
-            for (auto  tt :  it.second->getActions())\r
-            {\r
-                for (auto  tu :  tt.second->getResponses())\r
-                {\r
-                    for (auto  tv :  tu.second->getResponseBody())\r
-                    {\r
-                        auto pro = tv.second->getSchema()->getProperties();\r
-                        printJsonSchema(pro);\r
-                        break;\r
-                    }\r
-                }\r
-            }\r
-        }\r
-#endif\r
-    }\r
-    catch (RamlException &e)\r
-    {\r
-        std::cout << e.what() << std::endl;\r
-    }\r
-\r
-}\r
-\r
index a7adee2..c4dda1d 100755 (executable)
@@ -200,7 +200,7 @@ namespace RAML
                  *\r
                  * @param min - Minimum value of Properties.\r
                  */\r
-            inline void setMin(const double &min)\r
+            inline void setMin(double min)\r
             {\r
                 m_min = min;\r
             }\r
@@ -210,7 +210,7 @@ namespace RAML
                  *\r
                  * @param max - Maximum value of Properties.\r
                  */\r
-            inline void setMax(const double &max)\r
+            inline void setMax(double max)\r
             {\r
                 m_max = max;\r
             }\r
index 14ce23f..7a1e140 100644 (file)
 
 AttributeGenerator::AttributeGenerator(const SimulatorResourceModel::Attribute &attribute)
     :   m_attribute(attribute),
-        m_curIntValue(INT_MIN),
+        m_curValue(INT_MIN),
         m_valueSetIndex(0)
 {
     if (m_attribute.getProperty().type() == SimulatorResourceModel::AttributeProperty::Type::RANGE)
     {
-        m_curIntValue = m_attribute.getProperty().min();
+        m_curValue = m_attribute.getProperty().min();
     }
     else if (m_attribute.getProperty().type() ==
              SimulatorResourceModel::AttributeProperty::Type::VALUE_SET)
@@ -39,7 +39,7 @@ AttributeGenerator::AttributeGenerator(const SimulatorResourceModel::Attribute &
 bool AttributeGenerator::hasNext()
 {
     if (m_attribute.getProperty().type() == SimulatorResourceModel::AttributeProperty::Type::RANGE
-        && m_curIntValue <= m_attribute.getProperty().max())
+        && m_curValue <= m_attribute.getProperty().max())
     {
         return true;
     }
@@ -60,9 +60,12 @@ bool AttributeGenerator::next(SimulatorResourceModel::Attribute &attribute)
 
     attribute.setName(m_attribute.getName());
     if (m_attribute.getProperty().type() == SimulatorResourceModel::AttributeProperty::Type::RANGE
-        && m_curIntValue <= m_attribute.getProperty().max())
+        && m_curValue <= m_attribute.getProperty().max())
     {
-        attribute.setValue(m_curIntValue++);
+        if (SimulatorResourceModel::ValueType::INTEGER == m_attribute.getType().type())
+            attribute.setValue(static_cast<int>(m_curValue++));
+        else
+            attribute.setValue(m_curValue++);
     }
     else if (m_attribute.getProperty().type() ==
              SimulatorResourceModel::AttributeProperty::Type::VALUE_SET
@@ -80,9 +83,12 @@ SimulatorResourceModel::Attribute AttributeGenerator::current()
     attribute.setName(m_attribute.getName());
 
     if (m_attribute.getProperty().type() == SimulatorResourceModel::AttributeProperty::Type::RANGE
-        && m_curIntValue <= m_attribute.getProperty().max())
+        && m_curValue <= m_attribute.getProperty().max())
     {
-        attribute.setValue(m_curIntValue);
+        if (SimulatorResourceModel::ValueType::INTEGER == m_attribute.getType().type())
+            attribute.setValue(static_cast<int>(m_curValue));
+        else
+            attribute.setValue(m_curValue);
     }
     else if (m_attribute.getProperty().type() ==
              SimulatorResourceModel::AttributeProperty::Type::VALUE_SET
@@ -96,7 +102,7 @@ SimulatorResourceModel::Attribute AttributeGenerator::current()
 
 void AttributeGenerator::reset()
 {
-    m_curIntValue = m_attribute.getProperty().min();
+    m_curValue = m_attribute.getProperty().min();
     m_valueSetIndex = 0;
 }
 
index 7743bad..ca0439c 100644 (file)
@@ -36,7 +36,7 @@ class AttributeGenerator
 
     private:
         SimulatorResourceModel::Attribute m_attribute;
-        int m_curIntValue;
+        double m_curValue;
         size_t m_valueSetIndex;
         std::vector<SimulatorResourceModel::ValueVariant> m_supportedValues;
 };
index 91349f0..9cae27a 100644 (file)
@@ -33,4 +33,4 @@ SimulatorResult ResponseModel::verifyResponse(const OC::OCRepresentation &ocRep)
     if (m_repSchema->match(resModel))
         return SIMULATOR_OK;
     return SIMULATOR_ERROR;
-}
\ No newline at end of file
+}
index 02df295..f790824 100644 (file)
@@ -403,35 +403,109 @@ class SimulatorResourceModelBuilder
         }
 };
 
-class RangeValidater : public boost::static_visitor<bool>
+class RangeValidator : public boost::static_visitor<bool>
 {
     public:
-        RangeValidater(SimulatorResourceModel::AttributeProperty &property) :
+        RangeValidator(SimulatorResourceModel::AttributeProperty &property) :
             m_property(property) {}
 
         bool operator ()(const int &value)
         {
-            if (checkIntRange(value) || checkSupportedValueSet(value))
+            if (checkRange(value) || checkSupportedValueSet(value))
                 return true;
             return false;
         }
 
         bool operator ()(const double &value)
         {
-            return checkSupportedValueSet(value);
+            if (checkRange(value) || checkSupportedValueSet(value))
+                return true;
+            return false;
+        }
+
+        bool operator ()(const bool &value)
+        {
+            if (checkSupportedValueSet(value))
+                return true;
+            return false;
         }
 
         bool operator ()(const std::string &value)
         {
             int len = value.length();
-            if (checkIntRange(len) || checkSupportedValueSet(value))
+            if (checkRange(len) || checkSupportedValueSet(value))
                 return true;
             return false;
         }
 
+        bool operator ()(const SimulatorResourceModel &)
+        {
+            return true;
+        }
+
+        template <typename T>
+        bool operator ()(const std::vector<T> &values)
+        {
+            // Verify array property
+            int length = values.size();
+            if (!checkRange(length))
+                return false;
+
+            // Verify array element property
+            if (!m_property.getChildProperty())
+                return true;
+
+            m_property = *(m_property.getChildProperty());
+            for (int index = 0; index < length; index++)
+            {
+                if (!operator ()(values[index]))
+                    return false;
+            }
+
+            return true;
+        }
+
         template <typename T>
-        bool operator ()(const T &)
+        bool operator ()(const std::vector<std::vector<T>> &values)
         {
+            // Verify array property
+            int length = values.size();
+            if (!checkRange(length))
+                return false;
+
+            // Verify array element property
+            if (!m_property.getChildProperty())
+                return true;
+
+            m_property = *(m_property.getChildProperty());
+            for (int index = 0; index < length; index++)
+            {
+                if (!operator ()(values[index]))
+                    return false;
+            }
+
+            return true;
+        }
+
+        template <typename T>
+        bool operator ()(const std::vector<std::vector<std::vector<T>>> &values)
+        {
+            // Verify array property
+            int length = values.size();
+            if (!checkRange(length))
+                return false;
+
+            // Verify array element property
+            if (!m_property.getChildProperty())
+                return true;
+
+            m_property = *(m_property.getChildProperty());
+            for (int index = 0; index < length; index++)
+            {
+                if (!operator ()(values[index]))
+                    return false;
+            }
+
             return true;
         }
 
@@ -444,7 +518,7 @@ class RangeValidater : public boost::static_visitor<bool>
             return false;
         }
 
-        bool checkIntRange(const int &value)
+        bool checkRange(const double &value)
         {
             if (SimulatorResourceModel::AttributeProperty::Type::RANGE ==
                 m_property.type())
@@ -473,7 +547,7 @@ class RangeValidater : public boost::static_visitor<bool>
             return false;
         }
 
-        SimulatorResourceModel::AttributeProperty &m_property;
+        SimulatorResourceModel::AttributeProperty m_property;
 };
 
 class ToStringConverter
@@ -617,25 +691,12 @@ bool SimulatorResourceModel::TypeInfo::operator!=(
     return false;
 }
 
-std::string SimulatorResourceModel::AttributeProperty::valueSetToString() const
-{
-    std::ostringstream out;
-    out << "[ ";
-    for (auto &value : m_valueSet)
-    {
-        out << ToStringConverter().getStringRepresentation(value);
-        out << ", ";
-    }
-    out << "]";
-    return out.str();
-}
-
 SimulatorResourceModel::AttributeProperty::AttributeProperty()
     :   m_type(SimulatorResourceModel::AttributeProperty::Type::UNKNOWN),
         m_min(INT_MIN),
         m_max(INT_MAX) {}
 
-SimulatorResourceModel::AttributeProperty::AttributeProperty(int min, int max)
+SimulatorResourceModel::AttributeProperty::AttributeProperty(double min, double max)
     :   m_type(SimulatorResourceModel::AttributeProperty::Type::RANGE),
         m_min(min),
         m_max(max) {}
@@ -681,12 +742,12 @@ SimulatorResourceModel::AttributeProperty::type() const
     return m_type;
 }
 
-int SimulatorResourceModel::AttributeProperty::min() const
+double SimulatorResourceModel::AttributeProperty::min() const
 {
     return m_min;
 }
 
-int SimulatorResourceModel::AttributeProperty::max() const
+double SimulatorResourceModel::AttributeProperty::max() const
 {
     return m_max;
 }
@@ -702,6 +763,30 @@ SimulatorResourceModel::AttributeProperty::valueSet() const
     return m_valueSet;
 }
 
+std::string SimulatorResourceModel::AttributeProperty::valueSetToString() const
+{
+    std::ostringstream out;
+    out << "[ ";
+    for (auto &value : m_valueSet)
+    {
+        out << ToStringConverter().getStringRepresentation(value);
+        out << ", ";
+    }
+    out << "]";
+    return out.str();
+}
+
+void SimulatorResourceModel::AttributeProperty::setChildProperty(AttributeProperty &childProperty)
+{
+    m_childProperty.reset(new SimulatorResourceModel::AttributeProperty(childProperty));
+}
+
+std::shared_ptr<SimulatorResourceModel::AttributeProperty>
+SimulatorResourceModel::AttributeProperty::getChildProperty()
+{
+    return m_childProperty;
+}
+
 std::string SimulatorResourceModel::Attribute::getName() const
 {
     return m_name;
@@ -921,8 +1006,8 @@ bool SimulatorResourceModel::setAttributeValue(const std::string &key,
 {
     if (key.empty())
     {
-        OC_LOG(ERROR, TAG, "Invalid key!");
-        throw InvalidArgsException(SIMULATOR_INVALID_PARAM, "Attribute name is empty!");
+        OC_LOG(ERROR, TAG, "key is empty!");
+        return false;
     }
 
     /*
@@ -969,8 +1054,8 @@ bool SimulatorResourceModel::match(const std::string &key,
         if (getAttributeProperty(key, prop)
             && SimulatorResourceModel::AttributeProperty::Type::UNKNOWN != prop.type())
         {
-            RangeValidater rangeValidater(prop);
-            return boost::apply_visitor(rangeValidater, newValue);
+            RangeValidator rangeValidator(prop);
+            return boost::apply_visitor(rangeValidator, newValue);
         }
 
         return true;
@@ -1000,13 +1085,11 @@ bool SimulatorResourceModel::match(const SimulatorResourceModel &resModel, bool
         }
 
         SimulatorResourceModel::AttributeProperty prop;
-        if (getAttributeProperty(element.first, prop))
+        if (getAttributeProperty(element.first, prop)
+            && SimulatorResourceModel::AttributeProperty::Type::UNKNOWN != prop.type())
         {
-            RangeValidater rangeValidater(prop);
-            if (false == boost::apply_visitor(rangeValidater, element.second))
-            {
-                return false;
-            }
+            RangeValidator rangeValidator(prop);
+            return boost::apply_visitor(rangeValidator, element.second);
         }
     }
 
index d8cfe90..042f156 100644 (file)
@@ -168,4 +168,4 @@ std::string getRequestString(const std::map<std::string, std::string> &queryPara
     }
     data << "Payload:  No payload";
     return data.str();
-}
\ No newline at end of file
+}
index d3a3ff7..e99b16e 100755 (executable)
@@ -147,6 +147,12 @@ void SimulatorCollectionResourceImpl::setObserverCallback(ObserverCallback callb
     m_observeCallback = callback;
 }
 
+void SimulatorCollectionResourceImpl::setModelChangeCallback(ResourceModelChangedCallback callback)
+{
+    VALIDATE_CALLBACK(callback)
+    m_modelCallback = callback;
+}
+
 bool SimulatorCollectionResourceImpl::isObservable()
 {
     return (m_property & OC_OBSERVABLE);
@@ -513,4 +519,4 @@ OC::OCRepresentation SimulatorCollectionResourceImpl::prepareRepresentation()
     ocRep.setValue("links", links);
 
     return ocRep;
-}
\ No newline at end of file
+}
index 97d09cd..d75c33d 100755 (executable)
@@ -34,6 +34,9 @@ class SimulatorCollectionResourceImpl : public SimulatorCollectionResource
         std::string getURI() const;
         std::string getResourceType() const;
         std::vector<std::string> getInterface() const;
+        bool isObservable();
+        bool isStarted();
+        SimulatorResourceModel getResourceModel();
         void setInterface(const std::vector<std::string> &interfaces);
         void setName(const std::string &name);
         void setURI(const std::string &uri);
@@ -41,12 +44,9 @@ class SimulatorCollectionResourceImpl : public SimulatorCollectionResource
         void addInterface(std::string interfaceType);
         void setObservable(bool state);
         void setObserverCallback(ObserverCallback callback);
-        bool isObservable();
-        bool isStarted();
+        void setModelChangeCallback(ResourceModelChangedCallback callback);
         void start();
         void stop();
-        SimulatorResourceModel getResourceModel();
-        void setResourceModel(const SimulatorResourceModel &resModel);
         std::vector<ObserverInfo> getObserversList();
         void notify(int id);
         void notifyAll();
@@ -57,6 +57,8 @@ class SimulatorCollectionResourceImpl : public SimulatorCollectionResource
         void removeChildResource(const std::string &uri);
         std::vector<SimulatorResourceSP> getChildResources();
 
+        void setResourceModel(const SimulatorResourceModel &resModel);
+
     private:
         SimulatorCollectionResourceImpl();
 
@@ -84,6 +86,7 @@ class SimulatorCollectionResourceImpl : public SimulatorCollectionResource
         std::vector<std::string> m_supportedTypes;
         std::vector<ObserverInfo> m_observersList;
         ObserverCallback m_observeCallback;
+        ResourceModelChangedCallback m_modelCallback;
 
         OCResourceProperty m_property;
         OCResourceHandle m_resourceHandle;
index 19bc538..174d669 100644 (file)
@@ -189,8 +189,7 @@ SimulatorResourceModel SimulatorResourceFactory::buildResourceModel(
             continue;\r
 \r
         std::string propName = propElement.second->getName();\r
-        if ("rt" == propName || "resourceType" == propName || "if" == propName ||\r
-            "p" == propName || "n" == propName || "id" == propName )\r
+        if ("p" == propName || "n" == propName || "id" == propName)\r
         {\r
             continue;\r
         }\r
@@ -314,6 +313,7 @@ std::shared_ptr<SimulatorResource> SimulatorResourceFactory::buildResource(
         }\r
         resModel.add("links", arrayResModel);\r
     }\r
+\r
     // Create simple/collection resource\r
     std::shared_ptr<SimulatorResource> simResource;\r
     if (resModel.containsAttribute("links"))\r
@@ -326,10 +326,7 @@ std::shared_ptr<SimulatorResource> SimulatorResourceFactory::buildResource(
             collectionRes->setName(name);\r
             collectionRes->setResourceType(resourceType);\r
             collectionRes->setInterface(interfaceType);\r
-            if (ResourceURIFactory::getInstance()->isUnique(uri))\r
-                collectionRes->setURI(uri);\r
-            else\r
-                collectionRes->setURI(ResourceURIFactory::getInstance()->constructURI(uri));\r
+            collectionRes->setURI(ResourceURIFactory::getInstance()->constructURI(uri));\r
 \r
             collectionRes->setResourceModel(resModel);\r
             simResource = std::dynamic_pointer_cast<SimulatorResource>(collectionRes);\r
@@ -346,10 +343,7 @@ std::shared_ptr<SimulatorResource> SimulatorResourceFactory::buildResource(
             singleRes->setName(name);\r
             singleRes->setResourceType(resourceType);\r
             singleRes->setInterface(interfaceType);\r
-            if (ResourceURIFactory::getInstance()->isUnique(uri))\r
-                singleRes->setURI(uri);\r
-            else\r
-                singleRes->setURI(ResourceURIFactory::getInstance()->constructURI(uri));\r
+            singleRes->setURI(ResourceURIFactory::getInstance()->constructURI(uri));\r
 \r
             singleRes->setResourceModel(resModel);\r
             simResource = std::dynamic_pointer_cast<SimulatorResource>(singleRes);\r
@@ -371,14 +365,26 @@ ResourceURIFactory::ResourceURIFactory()
 \r
 std::string ResourceURIFactory::constructURI(const std::string &uri)\r
 {\r
+    std::lock_guard<std::mutex> lock(m_lock);\r
+    if (isUnique(uri))\r
+    {\r
+        updateUri(uri);\r
+        return uri;\r
+    }\r
     std::ostringstream os;\r
     os << uri;\r
     if (!uri.empty() && '/' != uri[uri.length() - 1])\r
         os << '/';\r
     os << m_id++;\r
+    updateUri(os.str());\r
     return os.str();\r
 }\r
 \r
+void ResourceURIFactory::updateUri(const std::string &uri)\r
+{\r
+    m_uriList.insert(std::pair<std::string, bool>(uri, true));\r
+}\r
+\r
 bool ResourceURIFactory::isUnique(const std::string &uri)\r
 {\r
     if (m_uriList.end() == m_uriList.find(uri))\r
index 153eadc..64e7514 100755 (executable)
@@ -119,15 +119,6 @@ class ResourceURIFactory
          */
         std::string constructURI(const std::string &uri);
 
-        /**
-         * API to check the uri is unique or not.
-         *
-         * @param uri - uri to be checked for its uniqueness.
-         *
-         * @return true if uri is unique, otherwise false.
-         */
-        bool isUnique(const std::string &uri);
-
     private:
         ResourceURIFactory();
         ResourceURIFactory(const ResourceURIFactory &) = delete;
@@ -135,7 +126,11 @@ class ResourceURIFactory
         ResourceURIFactory(ResourceURIFactory &&) = delete;
         ResourceURIFactory &operator=(ResourceURIFactory && ) = delete;
 
+        bool isUnique(const std::string &uri);
+        void updateUri(const std::string &uri);
+
         unsigned int m_id;
+        std::mutex m_lock;
         std::map<std::string, bool> m_uriList;
 };
 
index 3c07f78..e424b7a 100755 (executable)
@@ -164,7 +164,7 @@ void SimulatorSingleResourceImpl::start()
     std::lock_guard<std::recursive_mutex> lock(m_objectLock);
     if (m_resourceHandle)
     {
-        throw SimulatorException(SIMULATOR_ERROR, "Resource already registered!");
+        SIM_LOG(ILogger::INFO, "[" << m_name << "] " << "Resource already registered!")
     }
 
     if (m_uri.empty() || m_resourceType.empty())
@@ -218,7 +218,7 @@ std::vector<ObserverInfo> SimulatorSingleResourceImpl::getObserversList()
     return m_observersList;
 }
 
-void SimulatorSingleResourceImpl::notify(int id)
+void SimulatorSingleResourceImpl::notify(int id, SimulatorResourceModel &resModel)
 {
     std::lock_guard<std::recursive_mutex> lock(m_objectLock);
     if (!m_resourceHandle)
@@ -229,7 +229,7 @@ void SimulatorSingleResourceImpl::notify(int id)
 
     resourceResponse->setErrorCode(200);
     resourceResponse->setResponseResult(OC_EH_OK);
-    resourceResponse->setResourceRepresentation(m_resModel.getOCRepresentation(),
+    resourceResponse->setResourceRepresentation(resModel.getOCRepresentation(),
             OC::DEFAULT_INTERFACE);
 
     OC::ObservationIds observers;
@@ -242,7 +242,7 @@ void SimulatorSingleResourceImpl::notify(int id)
                      m_resourceHandle, observers, resourceResponse);
 }
 
-void SimulatorSingleResourceImpl::notifyAll()
+void SimulatorSingleResourceImpl::notifyAll(SimulatorResourceModel &resModel)
 {
     std::lock_guard<std::recursive_mutex> lock(m_objectLock);
     if (!m_resourceHandle)
@@ -256,7 +256,7 @@ void SimulatorSingleResourceImpl::notifyAll()
 
     resourceResponse->setErrorCode(200);
     resourceResponse->setResponseResult(OC_EH_OK);
-    resourceResponse->setResourceRepresentation(m_resModel.getOCRepresentation(),
+    resourceResponse->setResourceRepresentation(resModel.getOCRepresentation(),
             OC::DEFAULT_INTERFACE);
 
     OC::ObservationIds observers;
@@ -270,6 +270,16 @@ void SimulatorSingleResourceImpl::notifyAll()
                      m_resourceHandle, observers, resourceResponse);
 }
 
+void SimulatorSingleResourceImpl::notify(int id)
+{
+    notify(id, m_resModel);
+}
+
+void SimulatorSingleResourceImpl::notifyAll()
+{
+    notifyAll(m_resModel);
+}
+
 bool SimulatorSingleResourceImpl::getAttribute(const std::string &attrName,
         SimulatorResourceModel::Attribute &attribute)
 {
@@ -399,15 +409,31 @@ void SimulatorSingleResourceImpl::setResourceModel(const SimulatorResourceModel
     m_resModel = resModel;
 }
 
-void SimulatorSingleResourceImpl::notifyApp()
+void SimulatorSingleResourceImpl::notifyApp(SimulatorResourceModel &resModel)
 {
     if (m_modelCallback)
     {
-        SimulatorResourceModel resModel = m_resModel;
         m_modelCallback(m_uri, resModel);
     }
 }
 
+void SimulatorSingleResourceImpl::notifyApp()
+{
+    notifyApp(m_resModel);
+}
+
+bool SimulatorSingleResourceImpl::updateResourceModel(OC::OCRepresentation &ocRep,
+        SimulatorResourceModel &resModel)
+{
+    std::lock_guard<std::mutex> lock(m_modelLock);
+    if (m_resModel.update(ocRep))
+    {
+        resModel = m_resModel;
+        return true;
+    }
+    return false;
+}
+
 OCEntityHandlerResult SimulatorSingleResourceImpl::handleRequests(
     std::shared_ptr<OC::OCResourceRequest> request)
 {
@@ -510,16 +536,17 @@ std::shared_ptr<OC::OCResourceResponse> SimulatorSingleResourceImpl::requestOnBa
              || "POST" == request->getRequestType())
     {
         OC::OCRepresentation requestRep = request->getResourceRepresentation();
-        if (true == m_resModel.update(requestRep))
+        SimulatorResourceModel resModel;
+        if (true == updateResourceModel(requestRep, resModel))
         {
-            notifyAll();
-            notifyApp();
+            notifyAll(resModel);
+            notifyApp(resModel);
 
             response = std::make_shared<OC::OCResourceResponse>();
             response->setErrorCode(200);
             response->setResponseResult(OC_EH_OK);
-            response->setResourceRepresentation(m_resModel.getOCRepresentation());
-            std::string resPayload = getPayloadString(m_resModel.getOCRepresentation());
+            response->setResourceRepresentation(resModel.getOCRepresentation());
+            std::string resPayload = getPayloadString(resModel.getOCRepresentation());
             SIM_LOG(ILogger::INFO, "[" << m_uri <<
                     "] Sending response for " << request->getRequestType() << " request. \n**Payload details**" <<
                     resPayload)
index c54cac9..f1b7593 100755 (executable)
@@ -49,6 +49,8 @@ class SimulatorSingleResourceImpl : public SimulatorSingleResource
         std::vector<ObserverInfo> getObserversList();
         void notify(int id);
         void notifyAll();
+        void notify(int id, SimulatorResourceModel &resModel);
+        void notifyAll(SimulatorResourceModel &resModel);
 
         bool getAttribute(const std::string &attrName,
                           SimulatorResourceModel::Attribute &attribute);
@@ -71,6 +73,7 @@ class SimulatorSingleResourceImpl : public SimulatorSingleResource
         void stopUpdation(const int id);
         void setResourceModel(const SimulatorResourceModel &resModel);
         void notifyApp();
+        void notifyApp(SimulatorResourceModel &resModel);
 
     private:
         SimulatorSingleResourceImpl();
@@ -78,6 +81,7 @@ class SimulatorSingleResourceImpl : public SimulatorSingleResource
         std::shared_ptr<OC::OCResourceResponse> requestOnBaseLineInterface(
             std::shared_ptr<OC::OCResourceRequest> request);
         void resourceModified();
+        bool updateResourceModel(OC::OCRepresentation &ocRep, SimulatorResourceModel &resModel);
 
         SimulatorResource::Type m_type;
         std::string m_name;
index 18ca709..100a90a 100644 (file)
@@ -48,7 +48,11 @@ std::shared_ptr<SimulatorResource> SimulatorManager::createResource(
 {
     VALIDATE_INPUT(configPath.empty(), "Empty path!")
 
-    return SimulatorResourceFactory::getInstance()->createResource(configPath);
+    std::shared_ptr<SimulatorResource> resource =
+        SimulatorResourceFactory::getInstance()->createResource(configPath);
+    if (!resource)
+        throw SimulatorException(SIMULATOR_ERROR, "Failed to create resource!");
+    return resource;
 }
 
 std::vector<std::shared_ptr<SimulatorResource>> SimulatorManager::createResource(
@@ -57,7 +61,11 @@ std::vector<std::shared_ptr<SimulatorResource>> SimulatorManager::createResource
     VALIDATE_INPUT(configPath.empty(), "Empty path!")
     VALIDATE_INPUT(!count, "Count is zero!")
 
-    return SimulatorResourceFactory::getInstance()->createResource(configPath, count);
+    std::vector<std::shared_ptr<SimulatorResource>> resources =
+                SimulatorResourceFactory::getInstance()->createResource(configPath, count);
+    if (!resources.size())
+        throw SimulatorException(SIMULATOR_ERROR, "Failed to create resource!");
+    return resources;
 }
 
 std::shared_ptr<SimulatorSingleResource> SimulatorManager::createSingleResource(
diff --git a/service/simulator/unittests/SimulatorTest/.gitignore b/service/simulator/unittests/SimulatorTest/.gitignore
new file mode 100644 (file)
index 0000000..ae3c172
--- /dev/null
@@ -0,0 +1 @@
+/bin/
diff --git a/service/simulator/unittests/SimulatorTest/ramls/oic.r.light-error.json b/service/simulator/unittests/SimulatorTest/ramls/oic.r.light-error.json
deleted file mode 100644 (file)
index a6d1ce8..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-{
-  "id": "http://openinterconnect.org/schemas/oic.r.light-error#",
-  "$schema": "http://json-schema.org/draft-04/schema#",
-  "title": "OIC Light",
-  "$ref": "#/definitions/oic.r.light",
-  "definitions": {
-    "oic.r.light": {
-      "type": "object",
-      "properties": {
-               "rt": {
-          "type": "string",
-          "description": "Description about resource type",
-          "default": "oic.r.light"
-        },
-               "if": {
-          "type": "string",
-          "description": "Interface supported",
-          "default": "oic.if.baseline"
-        },
-        "n": {
-          "type": "string",
-          "description": "Readonly, Human friendly name",
-                 "default": "OIC Light Error"
-        },
-        "intensity":  {
-          "type": "integer",
-          "description": "ReadOnly, Comma separated min,max values for intensity on this device",
-          "default": "10,20"
-        }
-      }
-    }
-  },
-   "required": ["rt","if"]
-}
diff --git a/service/simulator/unittests/SimulatorTest/ramls/oic.r.light.json b/service/simulator/unittests/SimulatorTest/ramls/oic.r.light.json
deleted file mode 100644 (file)
index f6aad80..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-{
-  "id": "http://openinterconnect.org/schemas/oic.r.light#",
-  "$schema": "http://json-schema.org/schema#",
-  "title": "OIC Light",
-  "$ref": "#/definitions/oic.r.light",
-  "definitions": {
-    "oic.r.light": {
-      "type": "object",
-      "properties": {
-               "rt": {
-          "type": "string",
-          "description": "Description about resource type",
-          "default": "oic.r.light"
-        },
-               "if": {
-          "type": "string",
-          "description": "Interface supported",
-          "default": "oic.if.baseline"
-        },
-        "n": {
-          "type": "string",
-          "description": "Readonly, Human friendly name",
-                 "default": "OIC Light"
-        },
-               "power": {
-                 "type": "boolean",
-                 "description": "Light status",
-                 "default": false,
-                 "enum": [true,false]
-               },
-               "intensity": {
-                 "type": "integer",
-                 "description": "brightness of the light",
-                 "default": 10,
-                 "minimum": 10,
-          "maximum": 20
-               }
-               }
-         }
-       },      
-  "required": [ "rt","if","power" ]
-}
\ No newline at end of file
diff --git a/service/simulator/unittests/SimulatorTest/ramls/oic.r.light.raml b/service/simulator/unittests/SimulatorTest/ramls/oic.r.light.raml
deleted file mode 100644 (file)
index 1988343..0000000
+++ /dev/null
@@ -1,133 +0,0 @@
-#%RAML 0.8
-title: OICLight
-version: v1.0-20150910
-schemas:
-  - OICLight:         !include oic.r.light.json
-    OICLightError:    !include oic.r.light-error.json
-traits:
-  - interface:
-      queryParameters:
-        if:
-          enum: ["oic.if.a"]
-
-/oic/r/light:
-  description: |
-    Resource to be exposed by any OIC Device that can act as Light.
-  displayName: OIC Light
-  is: [ interface ] # valid for all methods
-
-  get:
-    responses:
-      200:
-        body:
-          application/json:
-            schema:  |
-              {
-                  "id": "http://openinterconnect.org/schemas/oic.r.light#",
-                  "$schema": "http://json-schema.org/schema#",
-                  "title": "OIC Light",
-                  "$ref": "#/definitions/oic.r.light",
-                  "definitions": {
-                  "oic.r.light": {
-                  "type": "object",
-                  "properties": {
-                      "rt": {
-                      "type": "string",
-                      "description": "Description about resource type",
-                      "default": "oic.r.light"
-                  },
-                  "if": {
-                      "type": "string",
-                      "description": "Interface supported",
-                      "default": "oic.if.baseline"
-                  },
-                  "n": {
-                      "type": "string",
-                      "description": "Readonly, Human friendly name",
-                      "default": "OIC Light"
-                  },
-                  "power": {
-                      "type": "boolean",
-                      "description": "Light status",
-                      "default": false,
-                      "enum": [true,false]
-                  },
-                  "intensity": {
-                      "type": "integer",
-                      "description": "brightness of the light",
-                      "default": 10,
-                      "minimum": 10,
-                      "maximum": 20
-                  }
-                  }
-                  }
-                },     
-                "required": [ "rt","if","power" ]
-              }
-  post:
-    body:
-      application/json:
-        schema: OICLight
-    responses:
-      200:
-        body:
-          application/json:
-            schema: OICLight
-      403:
-        description: |
-          This response is generated by the OIC Server when the client sends:
-            An update with an out of range property value for intensity.
-          The server responds with the range property illustrating the error.
-        body:
-          application/json:
-            schema: OICLightError
-  put:
-    body:
-      application/json:
-        schema: OICLight
-    responses:
-      200:
-        body:
-          application/json:
-            schema: OICLight
-      403:
-        description: |
-          This response is generated by the OIC Server when the client sends:
-            An update with an out of range property value for intensity.
-          The server responds with the range property illustrating the error.
-        body:
-          application/json:
-            schema:  |
-              {
-                  "id": "http://openinterconnect.org/schemas/oic.r.light-error#",
-                  "$schema": "http://json-schema.org/draft-04/schema#",
-                  "title": "OIC Light",
-                  "$ref": "#/definitions/oic.r.light",
-                  "definitions": {
-                  "oic.r.light": {
-                  "type": "object",
-                  "properties": {
-                      "rt": {
-                          "type": "string",
-                          "description": "Description about resource type",
-                          "default": "oic.r.light"
-                      },
-                      "if": {
-                          "type": "string",
-                          "description": "Interface supported",
-                          "default": "oic.if.baseline"
-                      },
-                      "n": {
-                          "type": "string",
-                          "description": "Readonly, Human friendly name",
-                          "default": "OIC Light Error"
-                      },
-                      "intensity":  {
-                          "type": "integer",
-                          "description": "ReadOnly, Comma separated min,max values for intensity on this device",
-                          "default": "10,20"
-                      }
-                    }
-                  }
-                }
-              }
\ No newline at end of file
index 5dd5dc4..475b708 100644 (file)
@@ -21,6 +21,7 @@ import java.util.Vector;
 import org.oic.simulator.InvalidArgsException;
 import org.oic.simulator.SimulatorException;
 import org.oic.simulator.SimulatorManager;
+import org.oic.simulator.SimulatorResourceModel;
 import org.oic.simulator.server.SimulatorCollectionResource;
 import org.oic.simulator.server.SimulatorResource;
 import org.oic.simulator.test.ExceptionType;
@@ -41,13 +42,8 @@ public class SimulatorCollectionResourceTest extends TestCase {
 
     protected void setUp() throws Exception {
         super.setUp();
-        // collectionResource = (SimulatorCollectionResource)
-        // SimulatorManager.createResource(
-        // COLLECTION_RES_RAML);
         collectionResource = (SimulatorCollectionResource) SimulatorManager
-                .createResource(SimulatorResource.Type.COLLECTION,
-                        "test-collection", "/test/collection",
-                        "test.collection");
+                .createResource(COLLECTION_RES_RAML);
     }
 
     protected void tearDown() throws Exception {
@@ -287,4 +283,19 @@ public class SimulatorCollectionResourceTest extends TestCase {
 
         assertTrue(exType == ExceptionType.INVALID_ARGS);
     }
+
+    public void testGetResourceModel_P01() {
+        SimulatorResourceModel result = null;
+
+        try {
+            result = collectionResource.getResourceModel();
+        } catch (InvalidArgsException e) {
+            e.printStackTrace();
+        } catch (SimulatorException e) {
+            e.printStackTrace();
+        }
+
+        assertNotNull(result);
+        assertTrue(result.size() > 0);
+    }
 }
diff --git a/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/test/AttributeValueValidationTest.java b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/test/AttributeValueValidationTest.java
new file mode 100644 (file)
index 0000000..96618f4
--- /dev/null
@@ -0,0 +1,253 @@
+package org.oic.simulator.test;
+
+import org.oic.simulator.AttributeProperty;
+import org.oic.simulator.AttributeValue;
+import org.oic.simulator.AttributeValueValidation;
+
+import junit.framework.TestCase;
+
+public class AttributeValueValidationTest extends TestCase {
+    protected void setUp() throws Exception {
+        super.setUp();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    public void testValidateInt_P01() {
+        AttributeProperty property = new AttributeProperty(1, 10);
+        AttributeValueValidation validation = new AttributeValueValidation(
+                property);
+        assertTrue(validation.validate(new AttributeValue(5)));
+    }
+
+    public void testValidateInt_P02() {
+        int[] valueSet = { 1, 5, 7 };
+        AttributeProperty property = new AttributeProperty(valueSet);
+        AttributeValueValidation validation = new AttributeValueValidation(
+                property);
+        assertTrue(validation.validate(new AttributeValue(5)));
+    }
+
+    public void testValidateInt_N01() {
+        AttributeProperty property = new AttributeProperty(1, 10);
+        AttributeValueValidation validation = new AttributeValueValidation(
+                property);
+        assertFalse(validation.validate(new AttributeValue(15)));
+    }
+
+    public void testValidateInt_N02() {
+        int[] valueSet = { 1, 5, 7 };
+        AttributeProperty property = new AttributeProperty(valueSet);
+        AttributeValueValidation validation = new AttributeValueValidation(
+                property);
+        assertFalse(validation.validate(new AttributeValue(6)));
+    }
+
+    public void testValidateInt_N03() {
+        AttributeValueValidation validation = new AttributeValueValidation(
+                null);
+        assertFalse(validation.validate(new AttributeValue(6)));
+    }
+
+    public void testValidateInt1DArray_P01() {
+        AttributeProperty arrayProp = new AttributeProperty(1, 2);
+        arrayProp.setChildProperty(new AttributeProperty(1, 10));
+
+        int[] value = { 1, 5 };
+        AttributeValueValidation validation = new AttributeValueValidation(
+                arrayProp);
+        assertTrue(validation.validate(new AttributeValue(value)));
+    }
+
+    public void testValidateInt1DArray_N01() {
+        AttributeProperty arrayProp = new AttributeProperty(1, 2);
+        arrayProp.setChildProperty(new AttributeProperty(1, 10));
+
+        int[] value = { 1, 5, 7 };
+        AttributeValueValidation validation = new AttributeValueValidation(
+                arrayProp);
+        assertFalse(validation.validate(new AttributeValue(value)));
+    }
+
+    public void testValidateInt1DArray_N02() {
+        AttributeProperty arrayProp = new AttributeProperty(1, 2);
+        arrayProp.setChildProperty(new AttributeProperty(1, 10));
+
+        int[] value = { 1, 15 };
+        AttributeValueValidation validation = new AttributeValueValidation(
+                arrayProp);
+        assertFalse(validation.validate(new AttributeValue(value)));
+    }
+
+    public void testValidateInt2DArray_P01() {
+        AttributeProperty array1Prop = new AttributeProperty(1, 1);
+        AttributeProperty array2Prop = new AttributeProperty(1, 1);
+        AttributeProperty valueProp = new AttributeProperty(1, 10);
+        array1Prop.setChildProperty(array2Prop);
+        array2Prop.setChildProperty(valueProp);
+
+        int[][] value = { { 1 } };
+        AttributeValueValidation validation = new AttributeValueValidation(
+                array1Prop);
+        assertTrue(validation.validate(new AttributeValue(value)));
+    }
+
+    public void testValidateInt2DArray_N01() {
+        AttributeProperty array1Prop = new AttributeProperty(1, 1);
+        AttributeProperty array2Prop = new AttributeProperty(1, 1);
+        AttributeProperty valueProp = new AttributeProperty(1, 10);
+        array1Prop.setChildProperty(array2Prop);
+        array2Prop.setChildProperty(valueProp);
+
+        int[][] value = { { 1 }, { 2 } };
+        AttributeValueValidation validation = new AttributeValueValidation(
+                array1Prop);
+        assertFalse(validation.validate(new AttributeValue(value)));
+    }
+
+    public void testValidateInt2DArray_N02() {
+        AttributeProperty array1Prop = new AttributeProperty(1, 1);
+        AttributeProperty array2Prop = new AttributeProperty(1, 1);
+        AttributeProperty valueProp = new AttributeProperty(1, 10);
+        array1Prop.setChildProperty(array2Prop);
+        array2Prop.setChildProperty(valueProp);
+
+        int[][] value = { { 1, 2 } };
+        AttributeValueValidation validation = new AttributeValueValidation(
+                array1Prop);
+        assertFalse(validation.validate(new AttributeValue(value)));
+    }
+
+    public void testValidateInt2DArray_N03() {
+        AttributeProperty array1Prop = new AttributeProperty(1, 1);
+        AttributeProperty array2Prop = new AttributeProperty(1, 1);
+        AttributeProperty valueProp = new AttributeProperty(1, 10);
+        array1Prop.setChildProperty(array2Prop);
+        array2Prop.setChildProperty(valueProp);
+
+        int[][] value = { { 15 } };
+        AttributeValueValidation validation = new AttributeValueValidation(
+                array1Prop);
+        assertFalse(validation.validate(new AttributeValue(value)));
+    }
+
+    public void testValidateDouble_P01() {
+        AttributeProperty property = new AttributeProperty(1, 10);
+        AttributeValueValidation validation = new AttributeValueValidation(
+                property);
+        assertTrue(validation.validate(new AttributeValue(5.12)));
+    }
+
+    public void testValidateDouble_P02() {
+        double[] valueSet = { 1.0, 5.12, 7.0 };
+        AttributeProperty property = new AttributeProperty(valueSet);
+        AttributeValueValidation validation = new AttributeValueValidation(
+                property);
+        assertTrue(validation.validate(new AttributeValue(5.12)));
+    }
+
+    public void testValidateDouble_N01() {
+        AttributeProperty property = new AttributeProperty(1, 10);
+        AttributeValueValidation validation = new AttributeValueValidation(
+                property);
+        assertFalse(validation.validate(new AttributeValue(15.23)));
+    }
+
+    public void testValidateDouble_N02() {
+        double[] valueSet = { 1.0, 5.12, 7.0 };
+        AttributeProperty property = new AttributeProperty(valueSet);
+        AttributeValueValidation validation = new AttributeValueValidation(
+                property);
+        assertFalse(validation.validate(new AttributeValue(6.0)));
+    }
+
+    public void testValidateDouble_N03() {
+        AttributeValueValidation validation = new AttributeValueValidation(
+                null);
+        assertFalse(validation.validate(new AttributeValue(6.0)));
+    }
+
+    public void testValidateDouble1DArray_P01() {
+        AttributeProperty arrayProp = new AttributeProperty(1, 2);
+        arrayProp.setChildProperty(new AttributeProperty(1, 10));
+
+        double[] value = { 1.2, 5.2 };
+        AttributeValueValidation validation = new AttributeValueValidation(
+                arrayProp);
+        assertTrue(validation.validate(new AttributeValue(value)));
+    }
+
+    public void testValidateDouble1DArray_N01() {
+        AttributeProperty arrayProp = new AttributeProperty(1, 2);
+        arrayProp.setChildProperty(new AttributeProperty(1, 10));
+
+        double[] value = { 1.2, 5.2, 7.2 };
+        AttributeValueValidation validation = new AttributeValueValidation(
+                arrayProp);
+        assertFalse(validation.validate(new AttributeValue(value)));
+    }
+
+    public void testValidateDouble1DArray_N02() {
+        AttributeProperty arrayProp = new AttributeProperty(1, 2);
+        arrayProp.setChildProperty(new AttributeProperty(1, 10));
+
+        double[] value = { 1.2, 15.2 };
+        AttributeValueValidation validation = new AttributeValueValidation(
+                arrayProp);
+        assertFalse(validation.validate(new AttributeValue(value)));
+    }
+
+    public void testValidateDouble2DArray_P01() {
+        AttributeProperty array1Prop = new AttributeProperty(1, 1);
+        AttributeProperty array2Prop = new AttributeProperty(1, 1);
+        AttributeProperty valueProp = new AttributeProperty(1, 10);
+        array1Prop.setChildProperty(array2Prop);
+        array2Prop.setChildProperty(valueProp);
+
+        double[][] value = { { 1.2 } };
+        AttributeValueValidation validation = new AttributeValueValidation(
+                array1Prop);
+        assertTrue(validation.validate(new AttributeValue(value)));
+    }
+
+    public void testValidateDouble2DArray_N01() {
+        AttributeProperty array1Prop = new AttributeProperty(1, 1);
+        AttributeProperty array2Prop = new AttributeProperty(1, 1);
+        AttributeProperty valueProp = new AttributeProperty(1, 10);
+        array1Prop.setChildProperty(array2Prop);
+        array2Prop.setChildProperty(valueProp);
+
+        double[][] value = { { 1.2 }, { 2.2 } };
+        AttributeValueValidation validation = new AttributeValueValidation(
+                array1Prop);
+        assertFalse(validation.validate(new AttributeValue(value)));
+    }
+
+    public void testValidateDouble2DArray_N02() {
+        AttributeProperty array1Prop = new AttributeProperty(1, 1);
+        AttributeProperty array2Prop = new AttributeProperty(1, 1);
+        AttributeProperty valueProp = new AttributeProperty(1, 10);
+        array1Prop.setChildProperty(array2Prop);
+        array2Prop.setChildProperty(valueProp);
+
+        double[][] value = { { 1.2, 2.2 } };
+        AttributeValueValidation validation = new AttributeValueValidation(
+                array1Prop);
+        assertFalse(validation.validate(new AttributeValue(value)));
+    }
+
+    public void testValidateDouble2DArray_N03() {
+        AttributeProperty array1Prop = new AttributeProperty(1, 1);
+        AttributeProperty array2Prop = new AttributeProperty(1, 1);
+        AttributeProperty valueProp = new AttributeProperty(1, 10);
+        array1Prop.setChildProperty(array2Prop);
+        array2Prop.setChildProperty(valueProp);
+
+        double[][] value = { { 15.2 } };
+        AttributeValueValidation validation = new AttributeValueValidation(
+                array1Prop);
+        assertFalse(validation.validate(new AttributeValue(value)));
+    }
+}