Java and JNI support for collection resource.
authorHarish Kumara Marappa <h.marappa@samsung.com>
Thu, 29 Oct 2015 17:12:35 +0000 (22:42 +0530)
committerMadan Lanka <lanka.madan@samsung.com>
Fri, 30 Oct 2015 02:32:04 +0000 (02:32 +0000)
Implementation of collection resource in Java and JNI layer. Implementation of
SimulatorResourceModel java class to maintain all the attributes in java layer
itself.

Change-Id: Idb2ec54a2f599749f8155bbf1d9df7cc92a7d981
Signed-off-by: Harish Kumara Marappa <h.marappa@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/3979
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
70 files changed:
service/simulator/java/jni/jni_listener_holder.h [new file with mode: 0644]
service/simulator/java/jni/jni_queryparam.cpp [new file with mode: 0644]
service/simulator/java/jni/jni_queryparam.h [moved from service/simulator/java/sdk/src/org/oic/simulator/clientcontroller/SimulatorObserveType.java with 58% similarity]
service/simulator/java/jni/jni_sharedobject_holder.h [new file with mode: 0644]
service/simulator/java/jni/jni_string.cpp [new file with mode: 0644]
service/simulator/java/jni/jni_string.h [moved from service/simulator/java/sdk/src/org/oic/simulator/serviceprovider/AutomationType.java with 57% similarity]
service/simulator/java/jni/jni_vector.cpp [new file with mode: 0644]
service/simulator/java/jni/jni_vector.h [new file with mode: 0644]
service/simulator/java/jni/resource_attributes_jni.cpp [deleted file]
service/simulator/java/jni/resource_attributes_jni.h [deleted file]
service/simulator/java/jni/simulator_collection_resource_jni.cpp [new file with mode: 0644]
service/simulator/java/jni/simulator_common_jni.h [deleted file]
service/simulator/java/jni/simulator_device_info_jni.cpp
service/simulator/java/jni/simulator_device_info_jni.h
service/simulator/java/jni/simulator_exceptions_jni.cpp [new file with mode: 0644]
service/simulator/java/jni/simulator_exceptions_jni.h [moved from service/simulator/java/jni/simulator_jni_utils.h with 65% similarity]
service/simulator/java/jni/simulator_init_jni.cpp [new file with mode: 0644]
service/simulator/java/jni/simulator_jni_utils.cpp [deleted file]
service/simulator/java/jni/simulator_manager_jni.cpp
service/simulator/java/jni/simulator_manager_jni.h [deleted file]
service/simulator/java/jni/simulator_platform_info_jni.cpp
service/simulator/java/jni/simulator_platform_info_jni.h
service/simulator/java/jni/simulator_remote_resource_jni.cpp
service/simulator/java/jni/simulator_remote_resource_jni.h [deleted file]
service/simulator/java/jni/simulator_resource_jni.cpp [new file with mode: 0644]
service/simulator/java/jni/simulator_resource_jni_util.cpp [deleted file]
service/simulator/java/jni/simulator_resource_jni_util.h [deleted file]
service/simulator/java/jni/simulator_resource_model_jni.cpp
service/simulator/java/jni/simulator_resource_model_jni.h
service/simulator/java/jni/simulator_resource_server_jni.cpp [deleted file]
service/simulator/java/jni/simulator_resource_server_jni.h [deleted file]
service/simulator/java/jni/simulator_resource_utils_jni.cpp [new file with mode: 0644]
service/simulator/java/jni/simulator_resource_utils_jni.h [new file with mode: 0644]
service/simulator/java/jni/simulator_single_resource_jni.cpp [new file with mode: 0644]
service/simulator/java/jni/simulator_utils_jni.cpp [new file with mode: 0644]
service/simulator/java/jni/simulator_utils_jni.h [new file with mode: 0644]
service/simulator/java/sdk/src/org/oic/simulator/AttributeProperty.java [new file with mode: 0644]
service/simulator/java/sdk/src/org/oic/simulator/AttributeValue.java [new file with mode: 0644]
service/simulator/java/sdk/src/org/oic/simulator/DeviceInfo.java
service/simulator/java/sdk/src/org/oic/simulator/DeviceListener.java [moved from service/simulator/java/sdk/src/org/oic/simulator/IDeviceInfo.java with 85% similarity]
service/simulator/java/sdk/src/org/oic/simulator/IAutomation.java [deleted file]
service/simulator/java/sdk/src/org/oic/simulator/ILogger.java
service/simulator/java/sdk/src/org/oic/simulator/InvalidArgsException.java
service/simulator/java/sdk/src/org/oic/simulator/NoSupportException.java
service/simulator/java/sdk/src/org/oic/simulator/OperationInProgressException.java
service/simulator/java/sdk/src/org/oic/simulator/PlatformInfo.java
service/simulator/java/sdk/src/org/oic/simulator/PlatformListener.java [moved from service/simulator/java/sdk/src/org/oic/simulator/IPlatformInfo.java with 84% similarity]
service/simulator/java/sdk/src/org/oic/simulator/ResourceAttribute.java [deleted file]
service/simulator/java/sdk/src/org/oic/simulator/SimulatorException.java
service/simulator/java/sdk/src/org/oic/simulator/SimulatorManager.java
service/simulator/java/sdk/src/org/oic/simulator/SimulatorManagerNativeInterface.java [deleted file]
service/simulator/java/sdk/src/org/oic/simulator/SimulatorResourceAttribute.java [new file with mode: 0644]
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 [moved from service/simulator/java/sdk/src/org/oic/simulator/clientcontroller/IFindResourceListener.java with 68% similarity]
service/simulator/java/sdk/src/org/oic/simulator/client/SimulatorConnectivityType.java [moved from service/simulator/java/sdk/src/org/oic/simulator/clientcontroller/SimulatorConnectivityType.java with 98% similarity]
service/simulator/java/sdk/src/org/oic/simulator/client/SimulatorRemoteResource.java [moved from service/simulator/java/sdk/src/org/oic/simulator/clientcontroller/SimulatorRemoteResource.java with 55% similarity]
service/simulator/java/sdk/src/org/oic/simulator/clientcontroller/IGetListener.java [deleted file]
service/simulator/java/sdk/src/org/oic/simulator/clientcontroller/IObserveListener.java [deleted file]
service/simulator/java/sdk/src/org/oic/simulator/clientcontroller/IPostListener.java [deleted file]
service/simulator/java/sdk/src/org/oic/simulator/clientcontroller/IPutListener.java [deleted file]
service/simulator/java/sdk/src/org/oic/simulator/clientcontroller/IVerificationListener.java [deleted file]
service/simulator/java/sdk/src/org/oic/simulator/clientcontroller/SimulatorVerificationType.java [deleted file]
service/simulator/java/sdk/src/org/oic/simulator/server/Observer.java [moved from service/simulator/java/sdk/src/org/oic/simulator/serviceprovider/ObserverInfo.java with 76% similarity]
service/simulator/java/sdk/src/org/oic/simulator/server/SimulatorCollectionResource.java [new file with mode: 0644]
service/simulator/java/sdk/src/org/oic/simulator/server/SimulatorResource.java [new file with mode: 0644]
service/simulator/java/sdk/src/org/oic/simulator/server/SimulatorSingleResource.java [new file with mode: 0644]
service/simulator/java/sdk/src/org/oic/simulator/serviceprovider/IObserver.java [deleted file]
service/simulator/java/sdk/src/org/oic/simulator/serviceprovider/IResourceModelChangedListener.java [deleted file]
service/simulator/java/sdk/src/org/oic/simulator/serviceprovider/SimulatorResourceServer.java [deleted file]

diff --git a/service/simulator/java/jni/jni_listener_holder.h b/service/simulator/java/jni/jni_listener_holder.h
new file mode 100644 (file)
index 0000000..254aa68
--- /dev/null
@@ -0,0 +1,54 @@
+/******************************************************************
+ *
+ * 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.
+ *
+ ******************************************************************/
+
+#ifndef JNI_LISTENER_HOLDER_H_
+#define JNI_LISTENER_HOLDER_H_
+
+class JniListenerHolder
+{
+    public:
+        ~JniListenerHolder()
+        {
+            JNIEnv *env = getEnv();
+            if (!env)
+                return;
+            env->DeleteGlobalRef(m_listener);
+            releaseEnv();
+        }
+
+        jobject get()
+        {
+            return m_listener;
+        }
+
+        static std::shared_ptr<JniListenerHolder> create(JNIEnv *env, jobject &listener)
+        {
+            return std::shared_ptr<JniListenerHolder>(new JniListenerHolder(env, listener));
+        }
+
+    private:
+        JniListenerHolder(JNIEnv *env, jobject &listener)
+            : m_listener(env->NewGlobalRef(listener)) {}
+
+        jobject m_listener;
+};
+
+#endif
+
diff --git a/service/simulator/java/jni/jni_queryparam.cpp b/service/simulator/java/jni/jni_queryparam.cpp
new file mode 100644 (file)
index 0000000..fd59abf
--- /dev/null
@@ -0,0 +1,68 @@
+/******************************************************************
+ *
+ * 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.
+ *
+ ******************************************************************/
+
+#include "jni_queryparam.h"
+#include "jni_string.h"
+#include "simulator_utils_jni.h"
+
+JniQueryParameter::JniQueryParameter(JNIEnv *env) : m_env(env) {}
+
+std::map<std::string, std::string> JniQueryParameter::toCpp(jobject jQueryParams)
+{
+    std::map<std::string, std::string> result;
+    if (!jQueryParams)
+        return result;
+
+    static jmethodID entrySetMethodID = m_env->GetMethodID(gSimulatorClassRefs.mapCls, "entrySet",
+                                        "()Ljava/util/Set;");
+    static jmethodID iteratorMethodID = m_env->GetMethodID(gSimulatorClassRefs.setCls, "iterator",
+                                        "()Ljava/util/Iterator;");
+    static jmethodID hasNextMethodID = m_env->GetMethodID(gSimulatorClassRefs.iteratorCls, "hasNext",
+                                       "()Z");
+    static jmethodID nextMethodID = m_env->GetMethodID(gSimulatorClassRefs.iteratorCls, "next",
+                                    "()Ljava/lang/Object;");
+    static jmethodID getKeyMethodID = m_env->GetMethodID(gSimulatorClassRefs.mapEntryCls, "getKey",
+                                      "()Ljava/lang/Object;");
+    static jmethodID getValueMethodID = m_env->GetMethodID(gSimulatorClassRefs.mapEntryCls, "getValue",
+                                        "()Ljava/lang/Object;");
+
+    jobject entrySet = m_env->CallObjectMethod(jQueryParams, entrySetMethodID);
+    jobject iterator = m_env->CallObjectMethod(entrySet, iteratorMethodID);
+    if (!entrySet || !iterator || m_env->ExceptionCheck())
+        return result;
+
+    while (m_env->CallBooleanMethod(iterator, hasNextMethodID))
+    {
+        jobject entry = m_env->CallObjectMethod(iterator, nextMethodID);
+        jstring key = (jstring) m_env->CallObjectMethod(entry, getKeyMethodID);
+        jstring value = (jstring) m_env->CallObjectMethod(entry, getValueMethodID);
+
+        JniString jniKey(m_env, key);
+        JniString jniValue(m_env, key);
+
+        result[jniKey.get()] = jniValue.get();
+
+        m_env->DeleteLocalRef(entry);
+        m_env->DeleteLocalRef(key);
+        m_env->DeleteLocalRef(value);
+    }
+
+    return result;
+}
@@ -1,6 +1,9 @@
-/*
+/******************************************************************
+ *
  * 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
  * 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 org.oic.simulator.clientcontroller;
+#ifndef JNI_QUERY_PARAM_H_
+#define JNI_QUERY_PARAM_H_
 
-/**
- * Enum for observe types.
- */
-public enum SimulatorObserveType {
-    OBSERVE(0), OBSERVE_ALL(1);
+#include <jni.h>
+#include <map>
+#include <string>
 
-    private int value;
+class JniQueryParameter
+{
+    public:
+        JniQueryParameter(JNIEnv *env);
+        std::map<std::string, std::string> toCpp(jobject queryParams);
 
-    private SimulatorObserveType(int value) {
-        this.value = value;
-    }
+    private:
+        JNIEnv *m_env;
+};
 
-    public int getValue() {
-        return this.value;
-    }
-}
+#endif
\ No newline at end of file
diff --git a/service/simulator/java/jni/jni_sharedobject_holder.h b/service/simulator/java/jni/jni_sharedobject_holder.h
new file mode 100644 (file)
index 0000000..46756fd
--- /dev/null
@@ -0,0 +1,49 @@
+/******************************************************************
+ *
+ * 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.
+ *
+ ******************************************************************/
+
+#ifndef JNI_SHARED_OBJECT_HOLDER_H_
+#define JNI_SHARED_OBJECT_HOLDER_H_
+
+#include <memory>
+
+template <typename T>
+class JniSharedObjectHolder
+{
+    public:
+        std::shared_ptr<T> get()
+        {
+            return m_sharedObject;
+        }
+
+        static JniSharedObjectHolder *create(std::shared_ptr<T> &sharedObject)
+        {
+            return new JniSharedObjectHolder(sharedObject);
+        }
+
+    private:
+        JniSharedObjectHolder(std::shared_ptr<T> &sharedObject)
+        {
+            m_sharedObject = sharedObject;
+        }
+
+        std::shared_ptr<T> m_sharedObject;
+};
+
+#endif
diff --git a/service/simulator/java/jni/jni_string.cpp b/service/simulator/java/jni/jni_string.cpp
new file mode 100644 (file)
index 0000000..95e77de
--- /dev/null
@@ -0,0 +1,46 @@
+/******************************************************************
+ *
+ * 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.
+ *
+ ******************************************************************/
+
+#include "jni_string.h"
+
+JniString::JniString(JNIEnv *env, jstring &string)
+    :   m_env(nullptr), m_string(nullptr), m_cStr("")
+{
+    m_env = env;
+    m_string = string;
+    if (m_string)
+    {
+        m_cStr = env->GetStringUTFChars(m_string, nullptr);
+    }
+}
+
+JniString::~JniString()
+{
+    if (m_string && m_cStr)
+    {
+        m_env->ReleaseStringUTFChars(m_string, m_cStr);
+    }
+}
+
+std::string JniString::get()
+{
+    return std::string(m_cStr);
+}
+
@@ -1,6 +1,9 @@
-/*
+/******************************************************************
+ *
  * 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
  * 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 org.oic.simulator.serviceprovider;
+#ifndef JNI_STRING_H_
+#define JNI_STRING_H_
 
-/**
- * This enum contains the different levels of server side automation which are
- * supported by the simulator.
- */
-public enum AutomationType {
-    NORMAL(0), RECURRENT(1);
+#include <jni.h>
+#include <string>
 
-    private int value;
+class JniString
+{
+    public:
+        JniString(JNIEnv *env, jstring &string);
+        ~JniString();
+        std::string get();
 
-    private AutomationType(int value) {
-        this.value = value;
-    }
+    private:
+        JNIEnv *m_env;
+        jstring m_string;
+        const char *m_cStr;
+};
 
-    public int getValue() {
-        return this.value;
-    }
-}
+#endif
diff --git a/service/simulator/java/jni/jni_vector.cpp b/service/simulator/java/jni/jni_vector.cpp
new file mode 100644 (file)
index 0000000..5f2135f
--- /dev/null
@@ -0,0 +1,92 @@
+/******************************************************************
+ *
+ * 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.
+ *
+ ******************************************************************/
+
+#include "jni_vector.h"
+#include "jni_string.h"
+#include "simulator_utils_jni.h"
+
+JniVector::JniVector(JNIEnv *env) : m_env(env)
+{
+    m_vectorCls = gSimulatorClassRefs.vectorCls;
+}
+
+jobject JniVector::toJava()
+{
+    static jmethodID vectorCtor = m_env->GetMethodID(m_vectorCls, "<init>", "()V");
+    return m_env->NewObject(m_vectorCls, vectorCtor);
+}
+
+jobject JniVector::toJava(std::vector<std::string> &cppVector)
+{
+    static jmethodID addMethod = m_env->GetMethodID(m_vectorCls, "add", "(Ljava/lang/Object;)Z");
+
+    jobject vectorObject = toJava();
+    if (!vectorObject)
+        return nullptr;
+
+    for (size_t index = 0; index < cppVector.size(); index++)
+    {
+        jstring element = m_env->NewStringUTF(cppVector[index].c_str());
+        m_env->CallBooleanMethod(vectorObject, addMethod, element);
+        m_env->DeleteLocalRef(element);
+    }
+
+    return vectorObject;
+}
+
+void JniVector::addElementsCpp(jobject vector, int size, std::vector<int> &result)
+{
+    static jmethodID getMethod = m_env->GetMethodID(m_vectorCls, "get", "(I)Ljava/lang/Object;");
+    static jmethodID intValueMethod = m_env->GetMethodID(gSimulatorClassRefs.integerCls, "intValue",
+                                      "()I");
+
+    for (int index = 0; index < size; index++)
+    {
+        jobject intObject = m_env->CallObjectMethod(vector, getMethod, index);
+        int value = m_env->CallIntMethod(intObject, intValueMethod);
+        result.push_back(value);
+    }
+}
+
+void JniVector::addElementsCpp(jobject vector, int size, std::vector<double> &result)
+{
+    static jmethodID getMethod = m_env->GetMethodID(m_vectorCls, "get", "(I)Ljava/lang/Object;");
+    static jmethodID doubleValueMethod = m_env->GetMethodID(gSimulatorClassRefs.doubleCls,
+                                         "doubleValue", "()D");
+
+    for (int index = 0; index < size; index++)
+    {
+        jobject doubleObject = m_env->CallObjectMethod(vector, getMethod, index);
+        double value = m_env->CallDoubleMethod(doubleObject, doubleValueMethod);
+        result.push_back(value);
+    }
+}
+
+void JniVector::addElementsCpp(jobject vector, int size, std::vector<std::string> &result)
+{
+    static jmethodID getMethodID = m_env->GetMethodID(m_vectorCls, "get", "(I)Ljava/lang/Object;");
+
+    for (int index = 0; index < size; index++)
+    {
+        jstring stringObject = (jstring) m_env->CallObjectMethod(vector, getMethodID, index);
+        JniString value(m_env, stringObject);
+        result.push_back(value.get());
+    }
+}
\ No newline at end of file
diff --git a/service/simulator/java/jni/jni_vector.h b/service/simulator/java/jni/jni_vector.h
new file mode 100644 (file)
index 0000000..860c082
--- /dev/null
@@ -0,0 +1,56 @@
+/******************************************************************
+ *
+ * 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.
+ *
+ ******************************************************************/
+
+#ifndef JNI_VECTOR_H_
+#define JNI_VECTOR_H_
+
+#include <jni.h>
+#include <vector>
+#include <string>
+
+class JniVector
+{
+    public:
+        JniVector(JNIEnv *env);
+
+        template <typename TYPE>
+        std::vector<TYPE> toCpp(jobject vector)
+        {
+            std::vector<TYPE> result;
+            jmethodID sizeMethodID = m_env->GetMethodID(m_vectorCls, "size", "()I");
+
+            int size = m_env->CallIntMethod(vector, sizeMethodID);
+            addElementsCpp(vector, size, result);
+            return result;
+        }
+
+        jobject toJava(std::vector<std::string> &cppVector);
+        jobject toJava();
+
+    private:
+        void addElementsCpp(jobject vector, int size, std::vector<int> &result);
+        void addElementsCpp(jobject vector, int size, std::vector<double> &result);
+        void addElementsCpp(jobject vector, int size, std::vector<std::string> &result);
+
+        JNIEnv *m_env;
+        jclass m_vectorCls;
+};
+
+#endif
diff --git a/service/simulator/java/jni/resource_attributes_jni.cpp b/service/simulator/java/jni/resource_attributes_jni.cpp
deleted file mode 100644 (file)
index 5732eff..0000000
+++ /dev/null
@@ -1,246 +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.
- *
- ******************************************************************/
-
-#include "resource_attributes_jni.h"
-#include "simulator_resource_model.h"
-#include "simulator_common_jni.h"
-#include "simulator_error_codes.h"
-#include <climits>
-
-extern SimulatorClassRefs gSimulatorClassRefs;
-
-class attribute_value_visitor : public boost::static_visitor<jobject>
-{
-    public:
-        attribute_value_visitor(JNIEnv *env) : m_Env(env) {}
-
-        // Integer type value conversion
-        jobject operator ()(const int &value) const
-        {
-            jobject result = m_Env->NewObject(gSimulatorClassRefs.classInteger,
-                                              gSimulatorClassRefs.classIntegerCtor, value);
-            return result;
-        }
-
-        // Double type value conversion
-        jobject operator ()(const double &value) const
-        {
-            jobject result = m_Env->NewObject(gSimulatorClassRefs.classDouble,
-                                              gSimulatorClassRefs.classDoubleCtor, value);
-            return result;
-        }
-
-        // String type value conversion
-        jobject operator ()(const std::string &value) const
-        {
-            jstring str = m_Env->NewStringUTF(value.c_str());
-            return static_cast<jobject>(str);
-        }
-
-        // Boolean type value conversion
-        jobject operator ()(const bool &value) const
-        {
-            jobject result = m_Env->NewObject(gSimulatorClassRefs.classBoolean,
-                                              gSimulatorClassRefs.classBooleanCtor, value);
-            return result;
-        }
-#if 0
-        // SimulatorResourceModel::Attribute type value conversion
-        jobject operator ()(const SimulatorResourceModel::Attribute &value) const
-        {
-            JResourceAttributeConverter converter(value);
-            return converter.toJava();
-        }
-#endif
-
-    private:
-        JNIEnv *m_Env;
-};
-
-jobject JResourceAttributeConverter::toJava(JNIEnv *env)
-{
-    // Create an object of ResourceAttribute java class
-    jobject jattributeObj = (jobject) env->NewObject(gSimulatorClassRefs.classResourceAttribute,
-                            gSimulatorClassRefs.classResourceAttributeCtor);
-    if (env->ExceptionCheck() || !jattributeObj)
-    {
-        return nullptr;
-    }
-
-    // Set attribute name
-    if (!setName(env, jattributeObj))
-    {
-        return nullptr;
-    }
-
-    // Set types
-    if (!setType(env, jattributeObj))
-    {
-        return nullptr;
-    }
-
-    // Set value
-    if (!setValue(env, jattributeObj))
-    {
-        return nullptr;
-    }
-
-    // Set Range
-    if (!setRange(env, jattributeObj))
-    {
-        return nullptr;
-    }
-
-    // Set Allowed values
-    if (!setAllowedValues(env, jattributeObj))
-    {
-        return nullptr;
-    }
-
-    return jattributeObj;
-}
-
-bool JResourceAttributeConverter::setName(JNIEnv *env, jobject &jattributeObj)
-{
-    // Get field reference to "ResourceAttribute::m_name"
-    static jfieldID fidName = env->GetFieldID(gSimulatorClassRefs.classResourceAttribute, "m_name",
-                              "Ljava/lang/String;");
-    if (!fidName)
-    {
-        return false;
-    }
-
-    // Set the attribute name
-    std::string name = m_attribute.getName();
-    jstring jname = env->NewStringUTF(name.c_str());
-    env->SetObjectField(jattributeObj, fidName, jname);
-    if (env->ExceptionCheck())
-    {
-        return false;
-    }
-
-    return true;
-}
-
-bool JResourceAttributeConverter::setType(JNIEnv *env, jobject &jattributeObj)
-{
-    // Get class refs to ResourceAttribute::Type class
-    static jclass clsType = env->FindClass("org/oic/simulator/ResourceAttribute$Type");
-    if (!clsType)
-    {
-        return false;
-    }
-
-    // Get method ref to static method to ResourceAttribute::Type::getType
-    static jmethodID midGetType = env->GetStaticMethodID(clsType, "getType",
-                                  "(I)Lorg/oic/simulator/ResourceAttribute$Type;");
-    if (!midGetType)
-    {
-        return false;
-    }
-
-    // Get field reference to "ResourceAttribute::m_type"
-    static jfieldID fidType = env->GetFieldID(gSimulatorClassRefs.classResourceAttribute,
-                              "m_type", "Lorg/oic/simulator/ResourceAttribute$Type;");
-    if (!fidType)
-    {
-        return false;
-    }
-
-    int type = static_cast<int>(m_attribute.getValueType());
-    jobject jtype = env->CallStaticObjectMethod(clsType, midGetType, type);
-    if (env->ExceptionCheck())
-    {
-        return false;
-    }
-
-    env->SetObjectField(jattributeObj, fidType, jtype);
-    if (env->ExceptionCheck())
-    {
-        return false;
-    }
-
-    return true;
-}
-
-bool JResourceAttributeConverter::setValue(JNIEnv *env, jobject &jattributeObj)
-{
-    // Get field reference to "ResourceAttribute::m_value"
-    static jfieldID fidValue = env->GetFieldID(gSimulatorClassRefs.classResourceAttribute,
-                               "m_value", "Ljava/lang/Object;");
-    if (!fidValue)
-    {
-        return false;
-    }
-    jobject jvalue = boost::apply_visitor(attribute_value_visitor(env), m_attribute.getValue());
-    env->SetObjectField(jattributeObj, fidValue, jvalue);
-    return true;
-}
-
-bool JResourceAttributeConverter::setRange(JNIEnv *env, jobject &jattributeObj)
-{
-    int min = INT_MIN;
-    int max = INT_MAX;
-    m_attribute.getRange(min, max);
-    if (INT_MIN == min || INT_MAX == max)
-    {
-        return true;
-    }
-    env->CallVoidMethod(jattributeObj, gSimulatorClassRefs.classResourceAttributeSetRange, min, max);
-    if (env->ExceptionCheck())
-    {
-        return false;
-    }
-
-    return true;
-}
-
-bool JResourceAttributeConverter::setAllowedValues(JNIEnv *env, jobject &jattributeObj)
-{
-    // Get field reference to "ResourceAttribute::m_AllowedValues"
-    static jfieldID fidAllowedValues = env->GetFieldID(gSimulatorClassRefs.classResourceAttribute,
-                                       "m_AllowedValues", "Ljava/lang/Object;");
-    if (!fidAllowedValues)
-    {
-        return false;
-    }
-
-    jobjectArray jallowedValues = env->NewObjectArray(m_attribute.getAllowedValuesSize(),
-                                  gSimulatorClassRefs.classObject, NULL);
-    if (!jallowedValues)
-    {
-        return false;
-    }
-
-    int index = 0;
-    for (auto & value : m_attribute.getAllowedValues())
-    {
-        jobject jvalue = boost::apply_visitor(attribute_value_visitor(env), value);
-        env->SetObjectArrayElement(jallowedValues, index++, jvalue);
-    }
-
-    env->SetObjectField(jattributeObj, fidAllowedValues, jallowedValues);
-    if (env->ExceptionCheck())
-    {
-        return false;
-    }
-
-    return true;
-}
\ No newline at end of file
diff --git a/service/simulator/java/jni/resource_attributes_jni.h b/service/simulator/java/jni/resource_attributes_jni.h
deleted file mode 100644 (file)
index 3c34cf1..0000000
+++ /dev/null
@@ -1,47 +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.
- *
- ******************************************************************/
-
-#ifndef RESOURCE_ATTRIBUTE_JNI_H_
-#define RESOURCE_ATTRIBUTE_JNI_H_
-
-#include <jni.h>
-#include "simulator_resource_model.h"
-
-class JResourceAttributeConverter
-{
-    public:
-        JResourceAttributeConverter(SimulatorResourceModel::Attribute &attribute) {m_attribute = attribute;}
-        JResourceAttributeConverter(const JResourceAttributeConverter &) = delete;
-        JResourceAttributeConverter &operator=(const JResourceAttributeConverter &) = delete;
-        JResourceAttributeConverter(const JResourceAttributeConverter &&) = delete;
-        JResourceAttributeConverter &operator=(const JResourceAttributeConverter && ) = delete;
-        jobject toJava(JNIEnv *env);
-
-    private:
-        bool setName(JNIEnv *env, jobject &jaAttributeObj);
-        bool setType(JNIEnv *env, jobject &jaAttributeObj);
-        bool setValue(JNIEnv *env, jobject &jaAttributeObj);
-        bool setRange(JNIEnv *env, jobject &jaAttributeObj);
-        bool setAllowedValues(JNIEnv *env, jobject &jaAttributeObj);
-
-        SimulatorResourceModel::Attribute m_attribute;
-};
-
-#endif //SIMULATOR_RESOURCE_ATTRIBUTE_JNI_H_
diff --git a/service/simulator/java/jni/simulator_collection_resource_jni.cpp b/service/simulator/java/jni/simulator_collection_resource_jni.cpp
new file mode 100644 (file)
index 0000000..1b9c2dc
--- /dev/null
@@ -0,0 +1,154 @@
+/******************************************************************
+ *
+ * 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.
+ *
+ ******************************************************************/
+
+#include "simulator_exceptions_jni.h"
+#include "simulator_resource_utils_jni.h"
+#include "simulator_utils_jni.h"
+#include "jni_sharedobject_holder.h"
+#include "jni_string.h"
+#include "jni_vector.h"
+
+#include "simulator_collection_resource.h"
+
+#define VALIDATE_OBJECT(ENV, OBJECT) if (!OBJECT){throwBadObjectException(ENV, "No corresponsing native object!"); return;}
+#define VALIDATE_OBJECT_RET(ENV, OBJECT, RET) if (!OBJECT){throwBadObjectException(ENV, "No corresponsing native object!"); return RET;}
+
+extern SimulatorResourceSP SimulatorResourceToCpp(JNIEnv *env, jobject object);
+
+SimulatorCollectionResourceSP SimulatorCollectionResourceToCpp(JNIEnv *env, jobject object)
+{
+    JniSharedObjectHolder<SimulatorCollectionResource> *jniResource =
+        GetHandle<JniSharedObjectHolder<SimulatorCollectionResource>>(env, object);
+    if (jniResource)
+        return jniResource->get();
+    return nullptr;
+}
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+JNIEXPORT jobject JNICALL
+Java_org_oic_simulator_server_SimulatorCollectionResource_getSupportedResources
+(JNIEnv *env, jobject object)
+{
+    SimulatorCollectionResourceSP collectionResource = SimulatorCollectionResourceToCpp(env, object);
+    VALIDATE_OBJECT_RET(env, collectionResource, nullptr)
+
+    std::vector<std::string> supportedTypes = collectionResource->getSupportedResources();
+    return JniVector(env).toJava(supportedTypes);
+}
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_server_SimulatorCollectionResource_addChildResource
+(JNIEnv *env, jobject object, jobject resource)
+{
+    VALIDATE_INPUT(env, !resource, "Child resource is null!")
+
+    SimulatorResourceSP childResource = SimulatorResourceToCpp(env, resource);
+    VALIDATE_INPUT(env, !childResource, "No corresponding native object of child resource!")
+
+    SimulatorCollectionResourceSP collectionResource = SimulatorCollectionResourceToCpp(env, object);
+    VALIDATE_OBJECT(env, collectionResource)
+
+    try
+    {
+        collectionResource->addChildResource(childResource);
+    }
+    catch (InvalidArgsException &e)
+    {
+        throwInvalidArgsException(env, e.code(), e.what());
+    }
+    catch (SimulatorException &e)
+    {
+        throwSimulatorException(env, e.code(), e.what());
+    }
+}
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_server_SimulatorCollectionResource_removeChildResource
+(JNIEnv *env, jobject object, jobject resource)
+{
+    VALIDATE_INPUT(env, !resource, "Child resource is null!")
+
+    SimulatorResourceSP childResource = SimulatorResourceToCpp(env, resource);
+    VALIDATE_INPUT(env, !childResource, "No corresponding native object of child resource!")
+
+    SimulatorCollectionResourceSP collectionResource = SimulatorCollectionResourceToCpp(env, object);
+    VALIDATE_OBJECT(env, collectionResource)
+
+    try
+    {
+        collectionResource->removeChildResource(childResource);
+    }
+    catch (InvalidArgsException &e)
+    {
+        throwInvalidArgsException(env, e.code(), e.what());
+    }
+    catch (SimulatorException &e)
+    {
+        throwSimulatorException(env, e.code(), e.what());
+    }
+}
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_server_SimulatorCollectionResource_removeChildResourceByUri
+(JNIEnv *env, jobject object, jstring uri)
+{
+    SimulatorCollectionResourceSP collectionResource = SimulatorCollectionResourceToCpp(env, object);
+    VALIDATE_OBJECT(env, collectionResource)
+
+    try
+    {
+        JniString jniUri(env, uri);
+        collectionResource->removeChildResource(jniUri.get());
+    }
+    catch (InvalidArgsException &e)
+    {
+        throwInvalidArgsException(env, e.code(), e.what());
+    }
+    catch (SimulatorException &e)
+    {
+        throwSimulatorException(env, e.code(), e.what());
+    }
+}
+
+JNIEXPORT jobject JNICALL
+Java_org_oic_simulator_server_SimulatorCollectionResource_getChildResource
+(JNIEnv *env, jobject object)
+{
+    SimulatorCollectionResourceSP collectionResource = SimulatorCollectionResourceToCpp(env, object);
+    VALIDATE_OBJECT_RET(env, collectionResource, nullptr)
+
+    std::vector<SimulatorResourceSP> childResources = collectionResource->getChildResources();
+    return createSimulatorResourceVector(env,  childResources);
+}
+
+JNIEXPORT void JNICALL Java_org_oic_simulator_server_SimulatorCollectionResource_dispose
+(JNIEnv *env, jobject object)
+{
+    JniSharedObjectHolder<SimulatorCollectionResource> *resource =
+        GetHandle<JniSharedObjectHolder<SimulatorCollectionResource>>(env, object);
+    delete resource;
+}
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/service/simulator/java/jni/simulator_common_jni.h b/service/simulator/java/jni/simulator_common_jni.h
deleted file mode 100644 (file)
index b0fd74b..0000000
+++ /dev/null
@@ -1,107 +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.
- *
- ******************************************************************/
-
-#ifndef SIMULATOR_COMMON_JNI_H_
-#define SIMULATOR_COMMON_JNI_H_
-
-#include <jni.h>
-
-typedef struct
-{
-    jclass classObject;
-    jclass classInteger;
-    jclass classDouble;
-    jclass classBoolean;
-    jclass classString;
-    jclass classHashMap;
-    jclass classVector;
-    jclass classMap;
-    jclass classMapEntry;
-    jclass classSet;
-    jclass classIterator;
-    jclass classLinkedList;
-
-    jclass classSimulatorResource;
-    jclass classSimulatorResourceModel;
-    jclass classResourceAttribute;
-    jclass classSimulatorRemoteResource;
-    jclass classSimulatorCallback;
-    jclass classObserverInfo;
-    jclass classDeviceInfo;
-    jclass classPlatformInfo;
-    jclass classSimulatorException;
-    jclass classInvalidArgsException;
-    jclass classNoSupportException;
-    jclass classOperationInProgressException;
-
-    jmethodID classIntegerCtor;
-    jmethodID classDoubleCtor;
-    jmethodID classBooleanCtor;
-    jmethodID classHashMapCtor;
-    jmethodID classHashMapPut;
-    jmethodID classVectorCtor;
-    jmethodID classVectorAddElement;
-    jmethodID classMapEntrySet;
-    jmethodID classMapGetKey;
-    jmethodID classMapGetValue;
-    jmethodID classIteratorId;
-    jmethodID classHasNextId;
-    jmethodID classNextId;
-    jmethodID classLinkedListCtor;
-    jmethodID classLinkedListAddObject;
-
-    jmethodID classSimulatorResourceCtor;
-    jmethodID classSimulatorResourceModelCtor;
-    jmethodID classResourceAttributeCtor;
-    jmethodID classResourceAttributeSetRange;
-    jmethodID classSimulatorResourceModelId;
-    jmethodID classObserverInfoCtor;
-    jmethodID classSimulatorExceptionCtor;
-    jmethodID classInvalidArgsExceptionCtor;
-    jmethodID classNoSupportExceptionCtor;
-    jmethodID classOperationInProgressExceptionCtor;
-
-} SimulatorClassRefs;
-
-static jfieldID GetHandleField(JNIEnv *env, jobject jobj)
-{
-    jclass cls = env->GetObjectClass(jobj);
-    return env->GetFieldID(cls, "nativeHandle", "J");
-}
-
-template <typename T>
-static T *GetHandle(JNIEnv *env, jobject jobj)
-{
-    jlong handle = env->GetLongField(jobj, GetHandleField(env, jobj));
-    return reinterpret_cast<T *>(handle);
-}
-
-template <typename T>
-static void SetHandle(JNIEnv *env, jobject jobj, T *type)
-{
-    jlong handle = reinterpret_cast<jlong>(type);
-
-    env->SetLongField(jobj, GetHandleField(env, jobj), handle);
-}
-
-JNIEnv *getEnv();
-void releaseEnv();
-
-#endif
index c954a97..a2f17ed 100644 (file)
  ******************************************************************/
 
 #include "simulator_device_info_jni.h"
-#include "simulator_common_jni.h"
+#include "simulator_utils_jni.h"
 
 extern SimulatorClassRefs gSimulatorClassRefs;
-jobject JDeviceInfo::toJava(DeviceInfo &deviceInfo)
+
+jobject JniDeviceInfo::toJava(DeviceInfo &deviceInfo)
 {
     if (!m_env)
         return nullptr;
 
-    jmethodID deviceInfoMId = m_env->GetMethodID(gSimulatorClassRefs.classDeviceInfo, "<init>", "(V)V");
-    if (!deviceInfoMId)
-        return nullptr;
-
-    jobject jDeviceInfo = (jobject) m_env->NewObject(gSimulatorClassRefs.classDeviceInfo, deviceInfoMId);
-    if (!jDeviceInfo)
-        return nullptr;
-
+    static jmethodID deviceInfoCtor = m_env->GetMethodID(gSimulatorClassRefs.deviceInfoCls, "<init>",
+                                      "()V");
+    jobject jDeviceInfo = m_env->NewObject(gSimulatorClassRefs.deviceInfoCls, deviceInfoCtor);
     setFieldValue(jDeviceInfo, "mName", deviceInfo.getName());
     setFieldValue(jDeviceInfo, "mID", deviceInfo.getID());
     setFieldValue(jDeviceInfo, "mSpecVersion", deviceInfo.getSpecVersion());
@@ -43,54 +39,33 @@ jobject JDeviceInfo::toJava(DeviceInfo &deviceInfo)
     return jDeviceInfo;
 }
 
-void JDeviceInfo::setFieldValue(jobject jDeviceInfo, const std::string &fieldName,
-                                const std::string &value)
+void JniDeviceInfo::setFieldValue(jobject jDeviceInfo, const std::string &fieldName,
+                                  const std::string &value)
 {
-    jfieldID fieldID = m_env->GetFieldID(gSimulatorClassRefs.classDeviceInfo, fieldName.c_str(),
+    jfieldID fieldID = m_env->GetFieldID(m_env->GetObjectClass(jDeviceInfo), fieldName.c_str(),
                                          "Ljava/lang/String;");
     jstring valueStr = m_env->NewStringUTF(value.c_str());
     m_env->SetObjectField(jDeviceInfo, fieldID, valueStr);
 }
 
-void JniDeviceInfoListener::onDeviceInfoReceived(DeviceInfo &deviceInfo)
+void onDeviceInfoReceived(jobject listener, DeviceInfo &deviceInfo)
 {
-    // Get the environment
     JNIEnv *env = getEnv();
     if (!env)
         return;
 
-    jobject listener = env->NewLocalRef(m_listener);
-    if (!listener)
-    {
-        releaseEnv();
-        return;
-    }
-
     jclass listenerCls = env->GetObjectClass(listener);
-    if (!listenerCls)
-    {
-        releaseEnv();
-        return;
-    }
-
-    jmethodID listenerMId = env->GetMethodID(listenerCls, "onDeviceFound",
-                            "(Lorg/oic/simulator/DeviceInfo;)V");
-    if (!listenerMId)
-    {
-        releaseEnv();
-        return;
-    }
+    jmethodID listenerMethodId = env->GetMethodID(listenerCls, "onDeviceFound",
+                                 "(Lorg/oic/simulator/DeviceInfo;)V");
 
-    // Convert CPP to Java DeviceInfo object
-    jobject jDeviceInfo = JDeviceInfo(env).toJava(deviceInfo);
+    jobject jDeviceInfo = JniDeviceInfo(env).toJava(deviceInfo);
     if (!jDeviceInfo)
     {
         releaseEnv();
         return;
     }
 
-    // Invoke java listener with DeviceInfo
-    env->CallVoidMethod(listener, listenerMId, jDeviceInfo);
+    env->CallVoidMethod(listener, listenerMethodId, jDeviceInfo);
     if (env->ExceptionCheck())
     {
         releaseEnv();
index ac53867..27e845d 100644 (file)
 #include "simulator_device_info.h"
 #include <jni.h>
 
-class JDeviceInfo
+class JniDeviceInfo
 {
     public:
-        JDeviceInfo(JNIEnv *env) : m_env(env) {}
-        JDeviceInfo(const JDeviceInfo &) = delete;
-        JDeviceInfo &operator=(const JDeviceInfo &) = delete;
-        JDeviceInfo(const JDeviceInfo &&) = delete;
-        JDeviceInfo &operator=(const JDeviceInfo && ) = delete;
+        JniDeviceInfo(JNIEnv *env) : m_env(env) {}
+        JniDeviceInfo(const JniDeviceInfo &) = delete;
+        JniDeviceInfo &operator=(const JniDeviceInfo &) = delete;
+        JniDeviceInfo(const JniDeviceInfo &&) = delete;
+        JniDeviceInfo &operator=(const JniDeviceInfo && ) = delete;
         jobject toJava(DeviceInfo &deviceInfo);
 
     private:
@@ -41,18 +41,6 @@ class JDeviceInfo
         JNIEnv *m_env;
 };
 
-class JniDeviceInfoListener
-{
-    public:
-        JniDeviceInfoListener(JNIEnv *env, jobject listener)
-        {
-            m_listener = env->NewWeakGlobalRef(listener);
-        }
-
-        void onDeviceInfoReceived(DeviceInfo &deviceInfo);
-
-    private:
-        jweak m_listener;
-};
+void onDeviceInfoReceived(jobject listener, DeviceInfo &deviceInfo);
 
 #endif
diff --git a/service/simulator/java/jni/simulator_exceptions_jni.cpp b/service/simulator/java/jni/simulator_exceptions_jni.cpp
new file mode 100644 (file)
index 0000000..041b844
--- /dev/null
@@ -0,0 +1,89 @@
+/******************************************************************
+ *
+ * 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.
+ *
+ ******************************************************************/
+
+#include "simulator_exceptions_jni.h"
+#include "simulator_utils_jni.h"
+
+extern SimulatorClassRefs gSimulatorClassRefs;
+
+void throwSimulatorException(JNIEnv *env, SimulatorResult code, const char *message)
+{
+    static jmethodID simulatorExceptionCtor = env->GetMethodID(
+                gSimulatorClassRefs.simulatorExceptionCls, "<init>", "(ILjava/lang/String;)V");
+
+    jobject exceptionObject = env->NewObject(gSimulatorClassRefs.simulatorExceptionCls,
+                              simulatorExceptionCtor, code, env->NewStringUTF(message));
+    if (exceptionObject)
+    {
+        env->Throw((jthrowable) exceptionObject);
+    }
+}
+
+void throwInvalidArgsException(JNIEnv *env, SimulatorResult code, const char *message)
+{
+    static jmethodID invalidArgsExceptionCtor = env->GetMethodID(
+                gSimulatorClassRefs.invalidArgsExceptionCls, "<init>", "(ILjava/lang/String;)V");
+
+    jobject exceptionObject = env->NewObject(gSimulatorClassRefs.invalidArgsExceptionCls,
+                              invalidArgsExceptionCtor, code, env->NewStringUTF(message));
+    if (exceptionObject)
+    {
+        env->Throw((jthrowable) exceptionObject);
+    }
+}
+
+void throwNoSupportException(JNIEnv *env, const char *message)
+{
+    static jmethodID noSupportExceptionCtor = env->GetMethodID(
+                gSimulatorClassRefs.noSupportExceptionCls, "<init>", "(Ljava/lang/String;)V");
+
+    jobject exceptionObject = env->NewObject(gSimulatorClassRefs.noSupportExceptionCls,
+                              noSupportExceptionCtor, env->NewStringUTF(message));
+    if (exceptionObject)
+    {
+        env->Throw((jthrowable) exceptionObject);
+    }
+}
+
+void throwOperationInProgressException(JNIEnv *env, const char *message)
+{
+    static jmethodID operationInProgressExceptionCtor = env->GetMethodID(
+                gSimulatorClassRefs.operationInProgressExceptionCls, "<init>", "(Ljava/lang/String;)V");
+
+    jobject exceptionObject = env->NewObject(gSimulatorClassRefs.operationInProgressExceptionCls,
+                              operationInProgressExceptionCtor, env->NewStringUTF(message));
+    if (exceptionObject)
+    {
+        env->Throw((jthrowable) exceptionObject);
+    }
+}
+
+void throwBadObjectException(JNIEnv *env, const char *message)
+{
+    static jmethodID simulatorExceptionCtor = env->GetMethodID(
+                gSimulatorClassRefs.simulatorExceptionCls, "<init>", "(ILjava/lang/String;)V");
+
+    jobject exceptionObject = env->NewObject(gSimulatorClassRefs.simulatorExceptionCls,
+                              simulatorExceptionCtor, SIMULATOR_BAD_OBJECT, env->NewStringUTF(message));
+    if (exceptionObject)
+    {
+        env->Throw((jthrowable) exceptionObject);
+    }
+}
\ No newline at end of file
  * and viceversa
  */
 
-#ifndef __SIMULATOR_JNI_UTILS_H_
-#define __SIMULATOR_JNI_UTILS_H_
+#ifndef SIMULATOR_EXCEPTIONS_JNI_H_
+#define SIMULATOR_EXCEPTIONS_JNI_H_
 
 #include <jni.h>
 #include "simulator_error_codes.h"
 
-void throwSimulatorException(JNIEnv *env, SimulatorResult errCode, const char *errMessage);
+void throwSimulatorException(JNIEnv *env, SimulatorResult code, const char *message);
 
-void throwInvalidArgsException(JNIEnv *env, SimulatorResult errCode, const char *errMessage);
+void throwInvalidArgsException(JNIEnv *env, SimulatorResult code, const char *message);
 
-void throwNoSupportException(JNIEnv *env, SimulatorResult errCode, const char *errMessage);
+void throwNoSupportException(JNIEnv *env, const char *message);
 
-void throwOperationInProgressException(JNIEnv *env, SimulatorResult errCode,
-                                       const char *errMessage);
+void throwOperationInProgressException(JNIEnv *env, const char *message);
 
-#endif //__SIMULATOR_JNI_UTILS_H_
+void throwBadObjectException(JNIEnv *env, const char *message);
+
+#endif
diff --git a/service/simulator/java/jni/simulator_init_jni.cpp b/service/simulator/java/jni/simulator_init_jni.cpp
new file mode 100644 (file)
index 0000000..6fe500c
--- /dev/null
@@ -0,0 +1,231 @@
+/******************************************************************
+ *
+ * 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.
+ *
+ ******************************************************************/
+
+#include "simulator_utils_jni.h"
+#include <mutex>
+
+#define OBJECT_CLS "java/lang/Object"
+#define INTEGER_CLS "java/lang/Integer"
+#define DOUBLE_CLS "java/lang/Double"
+#define BOOLEAN_CLS "java/lang/Boolean"
+#define STRING_CLS "java/lang/String"
+#define VECTOR_CLS "java/util/Vector"
+#define HASHMAP_CLS "java/util/HashMap"
+#define MAP_CLS "java/util/Map"
+#define MAP_ENTRY_CLS "java/util/Map$Entry"
+#define SET_CLS "java/util/Set"
+#define ITERATOR_CLS "java/util/Iterator"
+
+#define SIMULATOR_RESOURCE_CLS "org/oic/simulator/server/SimulatorResource"
+#define SIMULATOR_RESOURCE_TYPE_CLS "org/oic/simulator/server/SimulatorResource$Type"
+#define SIMULATOR_SINGLE_RESOURCE_CLS "org/oic/simulator/server/SimulatorSingleResource"
+#define SIMULATOR_COLLECTION_RESOURCE_CLS "org/oic/simulator/server/SimulatorCollectionResource"
+#define SIMULATOR_RESOURCE_MODEL_CLS "org/oic/simulator/SimulatorResourceModel"
+#define SIMULATOR_RESOURCE_ATTRIBUTE_CLS "org/oic/simulator/SimulatorResourceAttribute"
+#define ATTRIBUTE_VALUE_CLS "org/oic/simulator/AttributeValue"
+#define ATTRIBUTE_VALUE_TYPE_CLS "org/oic/simulator/AttributeValue$ValueType"
+#define ATTRIBUTE_TYPE_INFO_CLS "org/oic/simulator/AttributeValue$TypeInfo"
+#define ATTRIBUTE_PROPERTY_CLS "org/oic/simulator/AttributeProperty"
+#define ATTRIBUTE_PROPERTY_TYPE_CLS "org/oic/simulator/AttributeProperty$Type"
+
+#define SIMULATOR_REMOTE_RESOURCE_CLS "org/oic/simulator/client/SimulatorRemoteResource"
+#define OBSERVER_CLS "org/oic/simulator/server/Observer"
+#define DEVICE_INFO_CLS "org/oic/simulator/DeviceInfo"
+#define PLATFORM_INFO_CLS "org/oic/simulator/PlatformInfo"
+#define SIMULATOR_EXCEPTION_CLS "org/oic/simulator/SimulatorException"
+#define INVALID_ARGS_EXCEPTION_CLS "org/oic/simulator/InvalidArgsException"
+#define NO_SUPPORT_EXCEPTION_CLS "org/oic/simulator/NoSupportException"
+#define OPERATION_IN_PROGRESS_EXCEPTION_CLS "org/oic/simulator/OperationInProgressException"
+#define SIMULATOR_RESULT_CLS "org/oic/simulator/SimulatorResult"
+
+#define INTEGER_1D_ARRAY "[Ljava/lang/Integer;"
+#define INTEGER_2D_ARRAY "[[Ljava/lang/Integer;"
+#define INTEGER_3D_ARRAY "[[Ljava/lang/Integer;"
+#define DOUBLE_1D_ARRAY "[Ljava/lang/Double;"
+#define DOUBLE_2D_ARRAY "[[Ljava/lang/Double;"
+#define DOUBLE_3D_ARRAY "[[Ljava/lang/Double;"
+#define BOOLEAN_1D_ARRAY "[Ljava/lang/Boolean;"
+#define BOOLEAN_2D_ARRAY "[[Ljava/lang/Boolean;"
+#define BOOLEAN_3D_ARRAY "[[Ljava/lang/Boolean;"
+#define STRING_1D_ARRAY "[Ljava/lang/String;"
+#define STRING_2D_ARRAY "[[Ljava/lang/String;"
+#define STRING_3D_ARRAY "[[Ljava/lang/String;"
+#define SIMULATOR_RESOURCE_MODEL_1D_ARRAY "[Lorg/oic/simulator/SimulatorResourceModel;"
+#define SIMULATOR_RESOURCE_MODEL_2D_ARRAY "[[Lorg/oic/simulator/SimulatorResourceModel;"
+#define SIMULATOR_RESOURCE_MODEL_3D_ARRAY "[[Lorg/oic/simulator/SimulatorResourceModel;"
+
+SimulatorClassRefs gSimulatorClassRefs;
+static std::mutex gJvmMutex;
+static JavaVM *gJavaVM;
+
+JNIEnv *getEnv()
+{
+    std::unique_lock<std::mutex> lock(gJvmMutex);
+    if (!gJavaVM)
+        return nullptr;
+
+    JNIEnv *env = nullptr;
+    jint ret = gJavaVM->GetEnv((void **)&env, JNI_VERSION_1_6);
+    switch (ret)
+    {
+        case JNI_OK:
+            return env;
+        case JNI_EDETACHED:
+            if (!gJavaVM->AttachCurrentThread((void **)&env, NULL))
+                return env;
+    }
+
+    return nullptr;
+}
+
+void releaseEnv()
+{
+    std::unique_lock<std::mutex> lock(gJvmMutex);
+    if (!gJavaVM)
+        return;
+    gJavaVM->DetachCurrentThread();
+}
+
+static void getClassRef(JNIEnv *env, const char *className, jclass &classRef)
+{
+    jclass localRef = env->FindClass(className);
+    if (localRef)
+    {
+        classRef = (jclass) env->NewGlobalRef(localRef);
+        env->DeleteLocalRef(localRef);
+    }
+}
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
+{
+    if (!vm)
+        return JNI_ERR;
+
+    JNIEnv *env = nullptr;
+    if (JNI_OK != vm->GetEnv((void **) &env, JNI_VERSION_1_6))
+        return JNI_ERR;
+
+    // Get the class references
+    getClassRef(env, OBJECT_CLS, gSimulatorClassRefs.objectCls);
+    getClassRef(env, INTEGER_CLS, gSimulatorClassRefs.integerCls);
+    getClassRef(env, DOUBLE_CLS, gSimulatorClassRefs.doubleCls);
+    getClassRef(env, BOOLEAN_CLS, gSimulatorClassRefs.booleanCls);
+    getClassRef(env, STRING_CLS, gSimulatorClassRefs.stringCls);
+    getClassRef(env, VECTOR_CLS, gSimulatorClassRefs.vectorCls);
+    getClassRef(env, HASHMAP_CLS, gSimulatorClassRefs.hashMapCls);
+    getClassRef(env, MAP_CLS, gSimulatorClassRefs.mapCls);
+    getClassRef(env, MAP_ENTRY_CLS, gSimulatorClassRefs.mapEntryCls);
+    getClassRef(env, SET_CLS, gSimulatorClassRefs.setCls);
+    getClassRef(env, ITERATOR_CLS, gSimulatorClassRefs.iteratorCls);
+    getClassRef(env, SIMULATOR_RESOURCE_CLS, gSimulatorClassRefs.simulatorResourceCls);
+    getClassRef(env, SIMULATOR_RESOURCE_TYPE_CLS, gSimulatorClassRefs.simulatorResourceTypeCls);
+    getClassRef(env, SIMULATOR_SINGLE_RESOURCE_CLS, gSimulatorClassRefs.simulatorSingleResourceCls);
+    getClassRef(env, SIMULATOR_COLLECTION_RESOURCE_CLS,
+                gSimulatorClassRefs.simulatorCollectionResourceCls);
+    getClassRef(env, SIMULATOR_REMOTE_RESOURCE_CLS, gSimulatorClassRefs.simulatorRemoteResourceCls);
+    getClassRef(env, SIMULATOR_RESOURCE_MODEL_CLS, gSimulatorClassRefs.simulatorResourceModelCls);
+    getClassRef(env, SIMULATOR_RESOURCE_ATTRIBUTE_CLS,
+                gSimulatorClassRefs.simulatorResourceAttributeCls);
+    getClassRef(env, ATTRIBUTE_VALUE_CLS, gSimulatorClassRefs.attributeValueCls);
+    getClassRef(env, ATTRIBUTE_VALUE_TYPE_CLS, gSimulatorClassRefs.attributeValueTypeCls);
+    getClassRef(env, ATTRIBUTE_TYPE_INFO_CLS, gSimulatorClassRefs.attributeTypeInfoCls);
+    getClassRef(env, ATTRIBUTE_PROPERTY_CLS, gSimulatorClassRefs.attributePropertyCls);
+    getClassRef(env, ATTRIBUTE_PROPERTY_TYPE_CLS, gSimulatorClassRefs.attributePropertyTypeCls);
+    getClassRef(env, OBSERVER_CLS, gSimulatorClassRefs.observerCls);
+    getClassRef(env, DEVICE_INFO_CLS, gSimulatorClassRefs.deviceInfoCls);
+    getClassRef(env, PLATFORM_INFO_CLS, gSimulatorClassRefs.platformInfoCls);
+    getClassRef(env, SIMULATOR_EXCEPTION_CLS, gSimulatorClassRefs.simulatorExceptionCls);
+    getClassRef(env, INVALID_ARGS_EXCEPTION_CLS, gSimulatorClassRefs.invalidArgsExceptionCls);
+    getClassRef(env, NO_SUPPORT_EXCEPTION_CLS, gSimulatorClassRefs.noSupportExceptionCls);
+    getClassRef(env, OPERATION_IN_PROGRESS_EXCEPTION_CLS,
+                gSimulatorClassRefs.operationInProgressExceptionCls);
+    getClassRef(env, SIMULATOR_RESULT_CLS, gSimulatorClassRefs.simulatorResultCls);
+    getClassRef(env, INTEGER_1D_ARRAY, gSimulatorClassRefs.integer1DArrayCls);
+    getClassRef(env, INTEGER_2D_ARRAY, gSimulatorClassRefs.integer2DArrayCls);
+    getClassRef(env, INTEGER_3D_ARRAY, gSimulatorClassRefs.integer3DArrayCls);
+    getClassRef(env, DOUBLE_1D_ARRAY, gSimulatorClassRefs.double1DArrayCls);
+    getClassRef(env, DOUBLE_2D_ARRAY, gSimulatorClassRefs.double2DArrayCls);
+    getClassRef(env, DOUBLE_3D_ARRAY, gSimulatorClassRefs.double3DArrayCls);
+    getClassRef(env, BOOLEAN_1D_ARRAY, gSimulatorClassRefs.boolean1DArrayCls);
+    getClassRef(env, BOOLEAN_2D_ARRAY, gSimulatorClassRefs.boolean2DArrayCls);
+    getClassRef(env, BOOLEAN_3D_ARRAY, gSimulatorClassRefs.boolean3DArrayCls);
+    getClassRef(env, STRING_1D_ARRAY, gSimulatorClassRefs.string1DArrayCls);
+    getClassRef(env, STRING_2D_ARRAY, gSimulatorClassRefs.string2DArrayCls);
+    getClassRef(env, STRING_3D_ARRAY, gSimulatorClassRefs.string3DArrayCls);
+    getClassRef(env, SIMULATOR_RESOURCE_MODEL_1D_ARRAY,
+                gSimulatorClassRefs.simulatorResModel1DArrayCls);
+    getClassRef(env, SIMULATOR_RESOURCE_MODEL_2D_ARRAY,
+                gSimulatorClassRefs.simulatorResModel2DArrayCls);
+    getClassRef(env, SIMULATOR_RESOURCE_MODEL_3D_ARRAY,
+                gSimulatorClassRefs.simulatorResModel3DArrayCls);
+
+    gJavaVM = vm;
+    return JNI_VERSION_1_6;
+}
+
+JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved)
+{
+    if (!vm)
+        return;
+
+    JNIEnv *env = nullptr;
+    if (JNI_OK != vm->GetEnv((void **) &env, JNI_VERSION_1_6))
+        return;
+
+    // Release the class global references
+    env->DeleteGlobalRef(gSimulatorClassRefs.objectCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.integerCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.doubleCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.booleanCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.stringCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.hashMapCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.vectorCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.mapCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.mapEntryCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.setCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.iteratorCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.simulatorResourceCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.simulatorSingleResourceCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.simulatorCollectionResourceCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.simulatorResourceModelCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.simulatorResourceAttributeCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.attributeValueCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.attributeValueTypeCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.attributeTypeInfoCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.attributePropertyCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.attributePropertyTypeCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.simulatorRemoteResourceCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.observerCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.deviceInfoCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.platformInfoCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.simulatorExceptionCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.invalidArgsExceptionCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.noSupportExceptionCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.operationInProgressExceptionCls);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
diff --git a/service/simulator/java/jni/simulator_jni_utils.cpp b/service/simulator/java/jni/simulator_jni_utils.cpp
deleted file mode 100644 (file)
index 0274d63..0000000
+++ /dev/null
@@ -1,71 +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.
- *
- ******************************************************************/
-#include "simulator_jni_utils.h"
-#include "simulator_common_jni.h"
-
-extern SimulatorClassRefs gSimulatorClassRefs;
-
-void throwSimulatorException(JNIEnv *env, SimulatorResult errCode, const char *errMessage)
-{
-    jobject ex = env->NewObject(gSimulatorClassRefs.classSimulatorException,
-                                gSimulatorClassRefs.classSimulatorExceptionCtor, errCode,
-                                env->NewStringUTF(errMessage));
-    if (!ex)
-    {
-        return;
-    }
-    env->Throw((jthrowable)ex);
-}
-
-void throwInvalidArgsException(JNIEnv *env, SimulatorResult errCode, const char *errMessage)
-{
-    jobject ex = env->NewObject(gSimulatorClassRefs.classInvalidArgsException,
-                                gSimulatorClassRefs.classInvalidArgsExceptionCtor, errCode,
-                                env->NewStringUTF(errMessage));
-    if (!ex)
-    {
-        return;
-    }
-    env->Throw((jthrowable)ex);
-}
-
-void throwNoSupportException(JNIEnv *env, SimulatorResult errCode, const char *errMessage)
-{
-    jobject ex = env->NewObject(gSimulatorClassRefs.classNoSupportException,
-                                gSimulatorClassRefs.classNoSupportExceptionCtor, errCode,
-                                env->NewStringUTF(errMessage));
-    if (!ex)
-    {
-        return;
-    }
-    env->Throw((jthrowable)ex);
-}
-
-void throwOperationInProgressException(JNIEnv *env, SimulatorResult errCode, const char *errMessage)
-{
-    jobject ex = env->NewObject(gSimulatorClassRefs.classOperationInProgressException,
-                                gSimulatorClassRefs.classOperationInProgressExceptionCtor, errCode,
-                                env->NewStringUTF(errMessage));
-    if (!ex)
-    {
-        return;
-    }
-    env->Throw((jthrowable)ex);
-}
index 0fc5796..3391685 100644 (file)
  *
  ******************************************************************/
 
-#include "simulator_manager_jni.h"
-#include "simulator_resource_server_jni.h"
-#include "simulator_common_jni.h"
-#include "simulator_manager.h"
-#include "simulator_remote_resource_jni.h"
 #include "simulator_resource_model_jni.h"
 #include "simulator_device_info_jni.h"
 #include "simulator_platform_info_jni.h"
-#include "simulator_resource_jni_util.h"
-#include "simulator_jni_utils.h"
-
-SimulatorClassRefs gSimulatorClassRefs;
-std::mutex gEnvMutex;
-JavaVM *gvm;
-
-JNIEnv *getEnv()
-{
-    std::unique_lock<std::mutex> lock(gEnvMutex);
-    if (nullptr == gvm)
-        return NULL;
-
-    JNIEnv *env = NULL;
-    jint ret = gvm->GetEnv((void **)&env, JNI_VERSION_1_6);
-    switch (ret)
-    {
-        case JNI_OK:
-            return env;
-        case JNI_EDETACHED:
-            if (0 == gvm->AttachCurrentThread((void **)&env, NULL))
-                return env;
-    }
-
-    return NULL;
-}
+#include "simulator_exceptions_jni.h"
+#include "simulator_resource_utils_jni.h"
+#include "simulator_utils_jni.h"
+#include "jni_sharedobject_holder.h"
+#include "jni_listener_holder.h"
+#include "jni_string.h"
 
-void releaseEnv()
-{
-    std::unique_lock<std::mutex> lock(gEnvMutex);
-    if (nullptr == gvm)
-        return;
-    gvm->DetachCurrentThread();
-}
+#include "simulator_manager.h"
 
 class JNILogger : public ILogger
 {
@@ -109,448 +78,185 @@ class JNILogger : public ILogger
         jweak m_logger;
 };
 
-
-jobject SimulatorRemoteResourceToJava(JNIEnv *env, jlong resource)
-{
-    jmethodID constructor = env->GetMethodID(gSimulatorClassRefs.classSimulatorRemoteResource, "<init>",
-                            "(J)V");
-    if (NULL == constructor)
-    {
-        return NULL;
-    }
-
-    jobject resourceObj = (jobject) env->NewObject(gSimulatorClassRefs.classSimulatorRemoteResource,
-                          constructor, resource);
-    if (NULL == resourceObj)
-    {
-        return NULL;
-    }
-
-    return resourceObj;
-}
-
-class JNIFoundResourceListener
-{
-    public:
-        void setJavaFoundResourceListener(JNIEnv *env, jobject listener)
-        {
-            m_listener = env->NewWeakGlobalRef(listener);
-        }
-
-        void onFoundResource(std::shared_ptr<SimulatorRemoteResource> resource)
-        {
-            JNIEnv *env = getEnv();
-            if (nullptr == env)
-                return;
-
-            jobject foundResourceListener = env->NewLocalRef(m_listener);
-            if (!foundResourceListener)
-            {
-                releaseEnv();
-                return;
-            }
-
-            jclass foundResourceCls = env->GetObjectClass(foundResourceListener);
-            if (!foundResourceCls)
-            {
-                releaseEnv();
-                return;
-            }
-
-            jmethodID foundResourceMId = env->GetMethodID(foundResourceCls, "onResourceCallback",
-                                         "(Lorg/oic/simulator/clientcontroller/SimulatorRemoteResource;)V");
-            if (!foundResourceMId)
-            {
-                releaseEnv();
-                return;
-            }
-
-            JniSimulatorRemoteResource *jniSimulatorResource = new JniSimulatorRemoteResource(resource);
-            if (!jniSimulatorResource)
-            {
-                releaseEnv();
-                return;
-            }
-
-            jobject simulatorResource = SimulatorRemoteResourceToJava(env,
-                                        reinterpret_cast<jlong>(jniSimulatorResource));
-
-            jfieldID fieldID = env->GetFieldID(gSimulatorClassRefs.classSimulatorRemoteResource, "mUri",
-                                               "Ljava/lang/String;");
-            jstring jUri = env->NewStringUTF(resource->getURI().c_str());
-            env->SetObjectField(simulatorResource, fieldID, jUri);
-
-            fieldID = env->GetFieldID(gSimulatorClassRefs.classSimulatorRemoteResource, "mConnType", "I");
-            jint jConnType = resource->getConnectivityType();
-            env->SetIntField(simulatorResource, fieldID, jConnType);
-
-            fieldID = env->GetFieldID(gSimulatorClassRefs.classSimulatorRemoteResource, "mHost",
-                                      "Ljava/lang/String;");
-            jstring jHost = env->NewStringUTF(resource->getHost().c_str());
-            env->SetObjectField(simulatorResource, fieldID, jHost);
-
-            fieldID = env->GetFieldID(gSimulatorClassRefs.classSimulatorRemoteResource, "mId",
-                                      "Ljava/lang/String;");
-            jstring jUid = env->NewStringUTF(resource->getID().c_str());
-            env->SetObjectField(simulatorResource, fieldID, jUid);
-
-            fieldID = env->GetFieldID(gSimulatorClassRefs.classSimulatorRemoteResource, "mResTypes",
-                                      "Ljava/util/LinkedList;");
-            std::vector<std::string> resourceTypes = resource->getResourceTypes();
-            jobject jResTypes = convertStringVectorToJavaList(env, resourceTypes);
-            env->SetObjectField(simulatorResource, fieldID, jResTypes);
-
-            fieldID = env->GetFieldID(gSimulatorClassRefs.classSimulatorRemoteResource, "mResInterfaces",
-                                      "Ljava/util/LinkedList;");
-            std::vector<std::string> interfaceTypes = resource->getResourceInterfaces();
-            jobject jResInterfaces = convertStringVectorToJavaList(env, interfaceTypes);
-            env->SetObjectField(simulatorResource, fieldID, jResInterfaces);
-
-            fieldID = env->GetFieldID(gSimulatorClassRefs.classSimulatorRemoteResource, "mIsObservable", "Z");
-            env->SetBooleanField(simulatorResource, fieldID, resource->isObservable());
-
-            env->CallVoidMethod(foundResourceListener, foundResourceMId, simulatorResource);
-            if ((env)->ExceptionCheck())
-            {
-                delete jniSimulatorResource;
-                releaseEnv();
-                return;
-            }
-
-            releaseEnv();
-        }
-
-    private:
-        jweak m_listener;
-
-};
-
-void onResourceModelChange(jweak jlistenerRef, const std::string &uri,
-                           const SimulatorResourceModel &resModel)
+void onResourceFound(jobject listener, std::shared_ptr<SimulatorRemoteResource> remoteResource)
 {
     JNIEnv *env = getEnv();
-    if (nullptr == env)
-        return;
-
-    jobject modelChangeListener = env->NewLocalRef(jlistenerRef);
-    if (!modelChangeListener)
-    {
-        releaseEnv();
-        return;
-    }
-
-    jclass modelChangeCls = env->GetObjectClass(modelChangeListener);
-    if (!modelChangeCls)
-    {
-        releaseEnv();
+    if (!env)
         return;
-    }
 
-    jmethodID foundModelChangeMId = env->GetMethodID(modelChangeCls, "onResourceModelChanged",
-                                    "(Ljava/lang/String;Lorg/oic/simulator/SimulatorResourceModel;)V");
-    if (!foundModelChangeMId)
-    {
-        releaseEnv();
-        return;
-    }
-
-    JSimulatorResourceModel *jniModel = new JSimulatorResourceModel(resModel);
-    if (!jniModel)
-    {
-        releaseEnv();
-        return;
-    }
+    jclass listenerCls = env->GetObjectClass(listener);
+    jmethodID callbackMethod = env->GetMethodID(listenerCls, "onResourceFound",
+                               "(Lorg/oic/simulator/client/SimulatorRemoteResource;)V");
 
-    jobject jModel = JSimulatorResourceModel::toJava(env, reinterpret_cast<jlong>(jniModel));
-    jstring jUri = env->NewStringUTF(uri.c_str());
-    env->CallVoidMethod(modelChangeListener, foundModelChangeMId, jUri, jModel);
-    if ((env)->ExceptionCheck())
-    {
-        delete jniModel;
-        releaseEnv();
+    jobject resource = createSimulatorRemoteResource(env, remoteResource);
+    if (!resource)
         return;
-    }
-
-    env->DeleteLocalRef(jUri);
 
+    env->CallVoidMethod(listener, callbackMethod, resource);
     releaseEnv();
 }
 
+#ifdef __cplusplus
+extern "C" {
+#endif
 
 JNIEXPORT jobject JNICALL
-Java_org_oic_simulator_SimulatorManagerNativeInterface_createResource
-(JNIEnv *env, jclass object, jstring configPath, jobject listener)
+Java_org_oic_simulator_SimulatorManager_createResource
+(JNIEnv *env, jclass object, jstring configPath)
 {
-    if (!configPath)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM,
-                                  "Configuration file path is empty!");
-        return nullptr;
-    }
-
-    if (!listener)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_CALLBACK,
-                                  "Resource model change callback not set!");
-        return nullptr;
-    }
+    VALIDATE_INPUT_RET(env, !configPath, "Path is null!", nullptr)
 
-    jweak jlistenerRef = env->NewWeakGlobalRef(listener);
-    SimulatorResourceServer::ResourceModelChangedCB callback =  [jlistenerRef](const std::string & uri,
-            const SimulatorResourceModel & resModel)
-    {
-        onResourceModelChange(jlistenerRef, uri, resModel);
-    };
-
-    const char *configPathCStr = env->GetStringUTFChars(configPath, NULL);
-    SimulatorResourceServerSP resource = NULL;
     try
     {
-        resource = SimulatorManager::getInstance()->createResource(
-                       configPathCStr, callback);
-        if (nullptr == resource)
-        {
-            if (configPathCStr)
-                env->ReleaseStringUTFChars(configPath, configPathCStr);
-            return NULL;
-        }
+        JniString jniPath(env, configPath);
+        SimulatorResourceSP resource = SimulatorManager::getInstance()->createResource(
+                                           jniPath.get());
+        return createSimulatorResource(env, resource);
     }
     catch (InvalidArgsException &e)
     {
         throwInvalidArgsException(env, e.code(), e.what());
-        return nullptr;
     }
     catch (SimulatorException &e)
     {
         throwSimulatorException(env, e.code(), e.what());
-        return nullptr;
     }
-    catch (...)
-    {
-        throwSimulatorException(env, SIMULATOR_ERROR, "Unknown Exception");
-        return nullptr;
-    }
-
-    JniSimulatorResource *jniSimResource = new JniSimulatorResource(resource);
-    jobject jSimulatorResource = JniSimulatorResource::toJava(env,
-                                 reinterpret_cast<jlong>(jniSimResource));
-
-    jniSimResource->setResourceInfo(env, jSimulatorResource);
 
-    if (configPathCStr)
-        env->ReleaseStringUTFChars(configPath, configPathCStr);
-    return jSimulatorResource;
+    return nullptr;
 }
 
-JNIEXPORT jobjectArray JNICALL
-Java_org_oic_simulator_SimulatorManagerNativeInterface_createResources
-(JNIEnv *env, jclass object, jstring configPath, jint count, jobject listener)
+JNIEXPORT jobject JNICALL
+Java_org_oic_simulator_SimulatorManager_createResources
+(JNIEnv *env, jclass object, jstring configPath, jint count)
 {
-    if (!configPath)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM,
-                                  "Configuration file path is empty!");
-        return nullptr;
-    }
+    VALIDATE_INPUT_RET(env, !configPath, "Path is null!", nullptr)
+    VALIDATE_INPUT_RET(env, !count || count < 0, "Invalid count value!", nullptr)
 
-    if (!listener)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_CALLBACK,
-                                  "Resource model change callback not set!");
-        return nullptr;
-    }
-
-    jweak jlistenerRef = env->NewWeakGlobalRef(listener);
-    SimulatorResourceServer::ResourceModelChangedCB callback =  [jlistenerRef](const std::string & uri,
-            const SimulatorResourceModel & resModel)
-    {
-        onResourceModelChange(jlistenerRef, uri, resModel);
-    };
-
-    const char *configPathCStr = env->GetStringUTFChars(configPath, NULL);
-    std::vector<SimulatorResourceServerSP> resources;
     try
     {
-        resources = SimulatorManager::getInstance()->createResource(configPathCStr, count, callback);
+        JniString jniPath(env, configPath);
+        std::vector<SimulatorResourceSP> resources =
+            SimulatorManager::getInstance()->createResource(jniPath.get(), count);
+        return createSimulatorResourceVector(env, resources);
     }
     catch (InvalidArgsException &e)
     {
         throwInvalidArgsException(env, e.code(), e.what());
-        return nullptr;
     }
     catch (SimulatorException &e)
     {
         throwSimulatorException(env, e.code(), e.what());
-        return nullptr;
-    }
-    catch (...)
-    {
-        throwSimulatorException(env, SIMULATOR_ERROR, "Unknown Exception");
-        return nullptr;
     }
 
-    // Construct the object array and send it java layer
-    jobjectArray resourceArray = env->NewObjectArray(resources.size(),
-                                 gSimulatorClassRefs.classSimulatorResource, NULL);
-    if (resourceArray)
-    {
-        for (size_t i = 0; i < resources.size(); i++)
-        {
-            JniSimulatorResource *jniSimResource = new JniSimulatorResource(resources[i]);
-            jobject jSimulatorResource = JniSimulatorResource::toJava(env,
-                                         reinterpret_cast<jlong>(jniSimResource));
-            jniSimResource->setResourceInfo(env, jSimulatorResource);
-            env->SetObjectArrayElement(resourceArray, i, jSimulatorResource);
-        }
-    }
-
-    if (configPathCStr)
-        env->ReleaseStringUTFChars(configPath, configPathCStr);
-    return resourceArray;
+    return nullptr;
 }
 
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_SimulatorManagerNativeInterface_deleteResource
-(JNIEnv *env, jclass object, jobject jResource)
+JNIEXPORT jobject JNICALL
+Java_org_oic_simulator_SimulatorManager_createSingleResource
+(JNIEnv *env, jclass object, jstring name, jstring uri, jstring resourceType)
 {
-    if (!jResource)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM,
-                                  "No resource has been passed!");
-        return;
-    }
-
-    SimulatorResourceServerSP resource =
-        JniSimulatorResource::getJniSimulatorResourceSP(env, jResource);
-    if (!resource)
-    {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT,
-                                "Simulator resource not found!");
-        return;
-    }
+    VALIDATE_INPUT_RET(env, !name, "Name is null!", nullptr)
+    VALIDATE_INPUT_RET(env, !uri, "URI is null!", nullptr)
+    VALIDATE_INPUT_RET(env, !resourceType, "Resource type is null!", nullptr)
 
     try
     {
-        SimulatorManager::getInstance()->deleteResource(resource);
+        JniString jniName(env, name);
+        JniString jniUri(env, uri);
+        JniString jniResourceType(env, resourceType);
+
+        SimulatorSingleResourceSP resource = SimulatorManager::getInstance()->createSingleResource(
+                jniName.get(), jniUri.get(), jniResourceType.get());
+        return createSimulatorResource(env, std::dynamic_pointer_cast<SimulatorResource>(resource));
     }
     catch (InvalidArgsException &e)
     {
         throwInvalidArgsException(env, e.code(), e.what());
     }
-    catch (...)
+    catch (SimulatorException &e)
     {
-        throwSimulatorException(env, SIMULATOR_ERROR, "Unknown Exception");
+        throwSimulatorException(env, e.code(), e.what());
     }
+
+    return nullptr;
 }
 
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_SimulatorManagerNativeInterface_deleteResources
-(JNIEnv *env, jclass object, jstring resourceType)
+JNIEXPORT jobject JNICALL
+Java_org_oic_simulator_SimulatorManager_createCollectionResource
+(JNIEnv *env, jclass object, jstring name, jstring uri, jstring resourceType)
 {
-    std::string type;
-    const char *typeCStr = NULL;
-    if (resourceType)
-    {
-        typeCStr = env->GetStringUTFChars(resourceType, NULL);
-        type = typeCStr;
-    }
+    VALIDATE_INPUT_RET(env, !name, "Name is null!", nullptr)
+    VALIDATE_INPUT_RET(env, !uri, "URI is null!", nullptr)
+    VALIDATE_INPUT_RET(env, !resourceType, "Resource type is null!", nullptr)
 
     try
     {
-        SimulatorManager::getInstance()->deleteResource(type);
+        JniString jniName(env, name);
+        JniString jniUri(env, uri);
+        JniString jniResourceType(env, resourceType);
+
+        SimulatorCollectionResourceSP resource = SimulatorManager::getInstance()->createCollectionResource(
+                    jniName.get(), jniUri.get(), jniResourceType.get());
+        return createSimulatorResource(env, std::dynamic_pointer_cast<SimulatorResource>(resource));
     }
-    catch (...)
+    catch (InvalidArgsException &e)
     {
-        throwSimulatorException(env, SIMULATOR_ERROR, "Unknown Exception");
-        return;
+        throwInvalidArgsException(env, e.code(), e.what());
+    }
+    catch (SimulatorException &e)
+    {
+        throwSimulatorException(env, e.code(), e.what());
     }
 
-    if (typeCStr)
-        env->ReleaseStringUTFChars(resourceType, typeCStr);
+    return nullptr;
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_SimulatorManagerNativeInterface_findResource
-(JNIEnv *env, jobject object, jstring jResourceType, jobject jListener)
+Java_org_oic_simulator_SimulatorManager_searchResource
+(JNIEnv *env, jobject object, jstring resourceType, jobject listener)
 {
-    if (!jListener)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_CALLBACK, "Invalid callback!");
-        return;
-    }
+    VALIDATE_CALLBACK(env, listener)
 
-    const char *typeCStr = NULL;
-    std::string resourceType;
-    if (jResourceType)
+    ResourceFindCallback callback =  std::bind([](
+                                         std::shared_ptr<SimulatorRemoteResource> resource,
+                                         const std::shared_ptr<JniListenerHolder> &listenerRef)
     {
-        typeCStr = env->GetStringUTFChars(jResourceType, NULL);
-        resourceType = typeCStr;
-    }
-
-    JNIFoundResourceListener *resourceListener = new JNIFoundResourceListener();
-    resourceListener->setJavaFoundResourceListener(env, jListener);
+        onResourceFound(listenerRef->get(), resource);
+    }, std::placeholders::_1, JniListenerHolder::create(env, listener));
 
     try
     {
-        if (!jResourceType)
+        if (!resourceType)
         {
-            SimulatorManager::getInstance()->findResource(
-                std::bind(&JNIFoundResourceListener::onFoundResource,
-                          resourceListener, std::placeholders::_1));
+            SimulatorManager::getInstance()->findResource(callback);
         }
         else
         {
-            SimulatorManager::getInstance()->findResource(resourceType,
-                    std::bind(&JNIFoundResourceListener::onFoundResource,
-                              resourceListener, std::placeholders::_1));
+            JniString type(env, resourceType);
+            SimulatorManager::getInstance()->findResource(type.get(), callback);
         }
 
     }
     catch (InvalidArgsException &e)
     {
         throwInvalidArgsException(env, e.code(), e.what());
-        return;
     }
     catch (SimulatorException &e)
     {
         throwSimulatorException(env, e.code(), e.what());
-        return;
     }
-    catch (...)
-    {
-        throwSimulatorException(env, SIMULATOR_ERROR, "Unknown Exception");
-        return;
-    }
-
-    if (typeCStr)
-        env->ReleaseStringUTFChars(jResourceType, typeCStr);
 }
 
-
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_SimulatorManagerNativeInterface_setLogger
-(JNIEnv *env, jclass object, jobject logger)
+Java_org_oic_simulator_SimulatorManager_setDeviceInfo
+(JNIEnv *env, jobject object, jstring deviceName)
 {
-    static std::shared_ptr<JNILogger> target(new JNILogger());
-    target->setJavaLogger(env, logger);
-    SimulatorManager::getInstance()->setLogger(target);
-}
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_SimulatorManagerNativeInterface_setDeviceInfo
-(JNIEnv *env, jobject interfaceObject, jstring deviceInfo)
-{
-    if (!deviceInfo)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM, "Invalid device info!");
-        return;
-    }
-
-    const char *deviceName = env->GetStringUTFChars(deviceInfo, NULL);
+    VALIDATE_INPUT(env, !deviceName, "Device name is null!")
 
     try
     {
-        SimulatorManager::getInstance()->setDeviceInfo(deviceName);
+        JniString jniDeviceName(env, deviceName);
+        SimulatorManager::getInstance()->setDeviceInfo(jniDeviceName.get());
     }
     catch (InvalidArgsException &e)
     {
@@ -560,31 +266,19 @@ Java_org_oic_simulator_SimulatorManagerNativeInterface_setDeviceInfo
     {
         throwSimulatorException(env, e.code(), e.what());
     }
-    catch (...)
-    {
-        throwSimulatorException(env, SIMULATOR_ERROR, "Unknown Exception");
-        return;
-    }
-
-    env->ReleaseStringUTFChars(deviceInfo, deviceName);
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_SimulatorManagerNativeInterface_getDeviceInfo
-(JNIEnv *env, jobject interfaceObject, jobject jListener)
+Java_org_oic_simulator_SimulatorManager_findDevices
+(JNIEnv *env, jobject object, jobject listener)
 {
-    if (!jListener)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_CALLBACK, "Invalid callback!");
-        return;
-    }
+    VALIDATE_CALLBACK(env, listener)
 
-    JniDeviceInfoListener *deviceInfoListener = new JniDeviceInfoListener(env, jListener);
-    DeviceInfoCallback callback = std::bind([deviceInfoListener](DeviceInfo & deviceInfo)
+    DeviceInfoCallback callback =  std::bind([](DeviceInfo & deviceInfo,
+                                   const std::shared_ptr<JniListenerHolder> &listenerRef)
     {
-        deviceInfoListener->onDeviceInfoReceived(deviceInfo);
-        delete deviceInfoListener;
-    }, std::placeholders::_1);
+        onDeviceInfoReceived(listenerRef->get(), deviceInfo);
+    }, std::placeholders::_1, JniListenerHolder::create(env, listener));
 
     try
     {
@@ -598,56 +292,37 @@ Java_org_oic_simulator_SimulatorManagerNativeInterface_getDeviceInfo
     {
         throwSimulatorException(env, e.code(), e.what());
     }
-    catch (...)
-    {
-        throwSimulatorException(env, SIMULATOR_ERROR, "Unknown Exception");
-        return;
-    }
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_SimulatorManagerNativeInterface_setPlatformInfo
-(JNIEnv *env, jobject interfaceObject, jobject jPlatformInfo)
+Java_org_oic_simulator_SimulatorManager_setPlatformInfo
+(JNIEnv *env, jobject object, jobject platformInfo)
 {
-    if (!jPlatformInfo)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM, "Invalid platform info!");
-        return;
-    }
+    VALIDATE_INPUT(env, !platformInfo, "Platform info is null!")
 
-    JPlatformInfo jniPlatformInfo(env);
     try
     {
-        PlatformInfo platformInfo = jniPlatformInfo.toCPP(jPlatformInfo);
-        SimulatorManager::getInstance()->setPlatformInfo(platformInfo);
+        JniPlatformInfo jniPlatformInfo(env);
+        PlatformInfo info = jniPlatformInfo.toCpp(platformInfo);
+        SimulatorManager::getInstance()->setPlatformInfo(info);
     }
     catch (SimulatorException &e)
     {
         throwSimulatorException(env, e.code(), e.what());
     }
-    catch (...)
-    {
-        throwSimulatorException(env, SIMULATOR_ERROR, "Unknown Exception");
-        return;
-    }
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_SimulatorManagerNativeInterface_getPlatformInfo
-(JNIEnv *env, jobject interfaceObject, jobject jListener)
+Java_org_oic_simulator_SimulatorManager_getPlatformInformation
+(JNIEnv *env, jobject object, jobject listener)
 {
-    if (!jListener)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_CALLBACK, "Invalid callback!");
-        return;
-    }
+    VALIDATE_CALLBACK(env, listener)
 
-    JniPlatformInfoListener *platformInfoListener = new JniPlatformInfoListener(env, jListener);
-    PlatformInfoCallback callback = std::bind([platformInfoListener](PlatformInfo & platformInfo)
+    PlatformInfoCallback callback =  std::bind([](PlatformInfo & platformInfo,
+                                     const std::shared_ptr<JniListenerHolder> &listenerRef)
     {
-        platformInfoListener->onPlatformInfoReceived(platformInfo);
-        delete platformInfoListener;
-    }, std::placeholders::_1);
+        onPlatformInfoReceived(listenerRef->get(), platformInfo);
+    }, std::placeholders::_1, JniListenerHolder::create(env, listener));
 
     try
     {
@@ -661,308 +336,17 @@ Java_org_oic_simulator_SimulatorManagerNativeInterface_getPlatformInfo
     {
         throwSimulatorException(env, e.code(), e.what());
     }
-    catch (...)
-    {
-        throwSimulatorException(env, SIMULATOR_ERROR, "Unknown Exception");
-        return;
-    }
 }
 
-static bool getClassRef(JNIEnv *env, const char *className, jclass &classRef)
-{
-    jclass localClassRef = nullptr;
-    localClassRef = env->FindClass(className);
-    if (!localClassRef)
-        return false;
-
-    classRef = (jclass)env->NewGlobalRef(localClassRef);
-    env->DeleteLocalRef(localClassRef);
-    return true;
-}
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
-{
-    if (!vm)
-    {
-        return JNI_ERR;
-    }
-
-    JNIEnv *env = NULL;
-    if (JNI_OK != vm->GetEnv((void **) &env, JNI_VERSION_1_6))
-    {
-        return JNI_ERR;
-    }
-
-    // Get the class references
-    if (false == getClassRef(env, "java/lang/Object", gSimulatorClassRefs.classObject))
-    {
-        return JNI_ERR;
-    }
-
-    if (false == getClassRef(env, "java/lang/Integer", gSimulatorClassRefs.classInteger))
-    {
-        return JNI_ERR;
-    }
-
-    if (false == getClassRef(env, "java/lang/Double", gSimulatorClassRefs.classDouble))
-    {
-        return JNI_ERR;
-    }
-
-    if (false == getClassRef(env, "java/lang/Boolean", gSimulatorClassRefs.classBoolean))
-    {
-        return JNI_ERR;
-    }
-
-    if (false == getClassRef(env, "java/lang/String", gSimulatorClassRefs.classString))
-    {
-        return JNI_ERR;
-    }
-
-    if (false == getClassRef(env, "java/util/HashMap", gSimulatorClassRefs.classHashMap))
-    {
-        return JNI_ERR;
-    }
-
-    if (false == getClassRef(env, "java/util/Vector", gSimulatorClassRefs.classVector))
-    {
-        return JNI_ERR;
-    }
-
-    if (false == getClassRef(env, "java/util/Map", gSimulatorClassRefs.classMap))
-    {
-        return JNI_ERR;
-    }
-
-    if (false == getClassRef(env, "java/util/Map$Entry", gSimulatorClassRefs.classMapEntry))
-    {
-        return JNI_ERR;
-    }
-
-    if (false == getClassRef(env, "java/util/Set", gSimulatorClassRefs.classSet))
-    {
-        return JNI_ERR;
-    }
-
-    if (false == getClassRef(env, "java/util/Iterator", gSimulatorClassRefs.classIterator))
-    {
-        return JNI_ERR;
-    }
-
-    if (false == getClassRef(env, "java/util/LinkedList", gSimulatorClassRefs.classLinkedList))
-    {
-        return JNI_ERR;
-    }
-
-    if (false == getClassRef(env, "org/oic/simulator/serviceprovider/SimulatorResourceServer",
-                             gSimulatorClassRefs.classSimulatorResource))
-    {
-        return JNI_ERR;
-    }
-
-    if (false == getClassRef(env, "org/oic/simulator/SimulatorResourceModel",
-                             gSimulatorClassRefs.classSimulatorResourceModel))
-    {
-        return JNI_ERR;
-    }
-
-    if (false == getClassRef(env, "org/oic/simulator/ResourceAttribute",
-                             gSimulatorClassRefs.classResourceAttribute))
-    {
-        return JNI_ERR;
-    }
-
-    if (false == getClassRef(env, "org/oic/simulator/clientcontroller/SimulatorRemoteResource",
-                             gSimulatorClassRefs.classSimulatorRemoteResource))
-    {
-        return JNI_ERR;
-    }
-
-    if (false == getClassRef(env, "org/oic/simulator/serviceprovider/ObserverInfo",
-                             gSimulatorClassRefs.classObserverInfo))
-    {
-        return JNI_ERR;
-    }
-
-    if (false == getClassRef(env, "org/oic/simulator/DeviceInfo",
-                             gSimulatorClassRefs.classDeviceInfo))
-    {
-        return JNI_ERR;
-    }
-
-    if (false == getClassRef(env, "org/oic/simulator/PlatformInfo",
-                             gSimulatorClassRefs.classPlatformInfo))
-    {
-        return JNI_ERR;
-    }
-
-    if (false == getClassRef(env, "org/oic/simulator/SimulatorException",
-                             gSimulatorClassRefs.classSimulatorException))
-    {
-        return JNI_ERR;
-    }
-
-    if (false == getClassRef(env, "org/oic/simulator/InvalidArgsException",
-                             gSimulatorClassRefs.classInvalidArgsException))
-    {
-        return JNI_ERR;
-    }
-
-    if (false == getClassRef(env, "org/oic/simulator/NoSupportException",
-                             gSimulatorClassRefs.classNoSupportException))
-    {
-        return JNI_ERR;
-    }
-
-    if (false == getClassRef(env, "org/oic/simulator/OperationInProgressException",
-                             gSimulatorClassRefs.classOperationInProgressException))
-    {
-        return JNI_ERR;
-    }
-
-    // Get the reference to methods
-    gSimulatorClassRefs.classIntegerCtor = env->GetMethodID(gSimulatorClassRefs.classInteger, "<init>",
-                                           "(I)V");
-    if (!gSimulatorClassRefs.classIntegerCtor)
-        return JNI_ERR;
-
-    gSimulatorClassRefs.classDoubleCtor = env->GetMethodID(gSimulatorClassRefs.classDouble, "<init>",
-                                          "(D)V");
-    if (!gSimulatorClassRefs.classDoubleCtor)
-        return JNI_ERR;
-
-    gSimulatorClassRefs.classBooleanCtor= env->GetMethodID(gSimulatorClassRefs.classBoolean, "<init>",
-                                          "(Z)V");
-    if (!gSimulatorClassRefs.classBooleanCtor)
-        return JNI_ERR;
-
-    gSimulatorClassRefs.classHashMapCtor = env->GetMethodID(gSimulatorClassRefs.classHashMap, "<init>",
-                                           "()V");
-    if (!gSimulatorClassRefs.classHashMapCtor)
-        return JNI_ERR;
-
-    gSimulatorClassRefs.classHashMapPut = env->GetMethodID(gSimulatorClassRefs.classHashMap, "put",
-                                          "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
-    if (!gSimulatorClassRefs.classHashMapPut)
-        return JNI_ERR;
-
-    gSimulatorClassRefs.classVectorCtor = env->GetMethodID(gSimulatorClassRefs.classVector, "<init>",
-                                          "()V");
-    if (!gSimulatorClassRefs.classVectorCtor)
-        return JNI_ERR;
-
-    gSimulatorClassRefs.classVectorAddElement = env->GetMethodID(gSimulatorClassRefs.classVector,
-            "addElement",
-            "(Ljava/lang/Object;)V");
-    if (!gSimulatorClassRefs.classVectorAddElement)
-        return JNI_ERR;
-
-    gSimulatorClassRefs.classMapEntrySet = env->GetMethodID(
-            gSimulatorClassRefs.classMap, "entrySet", "()Ljava/util/Set;");
-    if (!gSimulatorClassRefs.classMapEntrySet)
-        return JNI_ERR;
-
-    gSimulatorClassRefs.classMapGetKey = env->GetMethodID(
-            gSimulatorClassRefs.classMapEntry, "getKey", "()Ljava/lang/Object;");
-    if (!gSimulatorClassRefs.classMapGetKey)
-        return JNI_ERR;
-
-    gSimulatorClassRefs.classMapGetValue = env->GetMethodID(
-            gSimulatorClassRefs.classMapEntry, "getValue", "()Ljava/lang/Object;");
-    if (!gSimulatorClassRefs.classMapGetValue)
-        return JNI_ERR;
-
-    gSimulatorClassRefs.classIteratorId = env->GetMethodID(
-            gSimulatorClassRefs.classSet, "iterator", "()Ljava/util/Iterator;");
-    if (!gSimulatorClassRefs.classIteratorId)
-        return JNI_ERR;
-
-    gSimulatorClassRefs.classHasNextId = env->GetMethodID(
-            gSimulatorClassRefs.classIterator, "hasNext", "()Z");
-    if (!gSimulatorClassRefs.classHasNextId)
-        return JNI_ERR;
-
-    gSimulatorClassRefs.classNextId = env->GetMethodID(
-                                          gSimulatorClassRefs.classIterator, "next", "()Ljava/lang/Object;");
-    if (!gSimulatorClassRefs.classNextId)
-        return JNI_ERR;
-
-    gSimulatorClassRefs.classLinkedListCtor = env->GetMethodID(gSimulatorClassRefs.classLinkedList,
-            "<init>", "()V");
-    if (!gSimulatorClassRefs.classLinkedListCtor)
-        return JNI_ERR;
-
-    gSimulatorClassRefs.classLinkedListAddObject = env->GetMethodID(gSimulatorClassRefs.classLinkedList,
-            "add", "(Ljava/lang/Object;)Z");
-    if (!gSimulatorClassRefs.classLinkedListAddObject)
-        return JNI_ERR;
-
-    gSimulatorClassRefs.classSimulatorResourceCtor = env->GetMethodID(
-                gSimulatorClassRefs.classSimulatorResource, "<init>", "(J)V");
-    if (!gSimulatorClassRefs.classSimulatorResourceCtor)
-        return JNI_ERR;
-
-    gSimulatorClassRefs.classSimulatorResourceModelCtor = env->GetMethodID(
-                gSimulatorClassRefs.classSimulatorResourceModel, "<init>", "(J)V");
-    if (!gSimulatorClassRefs.classSimulatorResourceModelCtor)
-        return JNI_ERR;
-
-    gSimulatorClassRefs.classResourceAttributeCtor = env->GetMethodID(
-                gSimulatorClassRefs.classResourceAttribute, "<init>", "()V");
-    if (!gSimulatorClassRefs.classResourceAttributeCtor)
-        return JNI_ERR;
-
-    gSimulatorClassRefs.classResourceAttributeSetRange = env->GetMethodID(
-                gSimulatorClassRefs.classResourceAttribute, "setRange", "(II)V");
-    if (!gSimulatorClassRefs.classResourceAttributeSetRange)
-        return JNI_ERR;
-
-    gSimulatorClassRefs.classSimulatorResourceModelId = env->GetMethodID(
-                gSimulatorClassRefs.classSimulatorResourceModel, "<init>", "(J)V");
-    if (!gSimulatorClassRefs.classSimulatorResourceModelId)
-        return JNI_ERR;
-
-    gSimulatorClassRefs.classObserverInfoCtor = env->GetMethodID(
-                gSimulatorClassRefs.classObserverInfo, "<init>",
-                "(ILjava/lang/String;I)V");
-    if (!gSimulatorClassRefs.classObserverInfoCtor)
-        return JNI_ERR;
-
-    gSimulatorClassRefs.classSimulatorExceptionCtor = env->GetMethodID(
-                gSimulatorClassRefs.classSimulatorException, "<init>",
-                "(ILjava/lang/String;)V");
-    if (!gSimulatorClassRefs.classSimulatorExceptionCtor)
-        return JNI_ERR;
-
-    gSimulatorClassRefs.classInvalidArgsExceptionCtor = env->GetMethodID(
-                gSimulatorClassRefs.classInvalidArgsException, "<init>",
-                "(ILjava/lang/String;)V");
-    if (!gSimulatorClassRefs.classInvalidArgsExceptionCtor)
-        return JNI_ERR;
-
-    gSimulatorClassRefs.classNoSupportExceptionCtor = env->GetMethodID(
-                gSimulatorClassRefs.classNoSupportException, "<init>",
-                "(ILjava/lang/String;)V");
-    if (!gSimulatorClassRefs.classNoSupportExceptionCtor)
-        return JNI_ERR;
-
-    gSimulatorClassRefs.classOperationInProgressExceptionCtor = env->GetMethodID(
-                gSimulatorClassRefs.classOperationInProgressException, "<init>",
-                "(ILjava/lang/String;)V");
-    if (!gSimulatorClassRefs.classOperationInProgressExceptionCtor)
-        return JNI_ERR;
-
-    gvm = vm;
-    return JNI_VERSION_1_6;
-}
-
-JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved)
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_SimulatorManager_setLogger
+(JNIEnv *env, jobject object, jobject logger)
 {
+    static std::shared_ptr<JNILogger> target(new JNILogger());
+    target->setJavaLogger(env, logger);
+    SimulatorManager::getInstance()->setLogger(target);
 }
 
 #ifdef __cplusplus
 }
-#endif
+#endif
\ No newline at end of file
diff --git a/service/simulator/java/jni/simulator_manager_jni.h b/service/simulator/java/jni/simulator_manager_jni.h
deleted file mode 100644 (file)
index 2a71031..0000000
+++ /dev/null
@@ -1,74 +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.
- *
- ******************************************************************/
-
-#ifndef SIMULATOR_MANAGER_JNI_H_
-#define SIMULATOR_MANAGER_JNI_H_
-
-#include <jni.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-JNIEXPORT jobject JNICALL
-Java_org_oic_simulator_SimulatorManagerNativeInterface_createResource
-(JNIEnv *env, jclass object, jstring jConfigPath, jobject jListener);
-
-JNIEXPORT jobjectArray JNICALL
-Java_org_oic_simulator_SimulatorManagerNativeInterface_createResources
-(JNIEnv *env, jclass object, jstring jConfigPath, jint count, jobject jListener);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_SimulatorManagerNativeInterface_deleteResource
-(JNIEnv *env, jclass object, jobject jResource);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_SimulatorManagerNativeInterface_deleteResources
-(JNIEnv *env, jclass object, jstring resourceType);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_SimulatorManagerNativeInterface_findResource
-(JNIEnv *env, jobject interfaceObject, jstring jResourceType, jobject jListener);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_SimulatorManagerNativeInterface_setDeviceInfo
-(JNIEnv *env, jobject interfaceObject, jstring deviceInfo);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_SimulatorManagerNativeInterface_getDeviceInfo
-(JNIEnv *env, jobject interfaceObject, jobject jListener);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_SimulatorManagerNativeInterface_setPlatformInfo
-(JNIEnv *env, jobject interfaceObject, jobject platformInfo);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_SimulatorManagerNativeInterface_getPlatformInfo
-(JNIEnv *env, jobject interfaceObject, jobject jListener);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_SimulatorManagerNativeInterface_setLogger
-(JNIEnv *env, jclass object, jobject logger);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif //SIMULATOR_MANAGER_JNI_H_
index f3be763..4fb7702 100644 (file)
  ******************************************************************/
 
 #include "simulator_platform_info_jni.h"
-#include "simulator_common_jni.h"
+#include "simulator_utils_jni.h"
+#include "jni_string.h"
 
 extern SimulatorClassRefs gSimulatorClassRefs;
-jobject JPlatformInfo::toJava(PlatformInfo &platformInfo)
+
+jobject JniPlatformInfo::toJava(PlatformInfo &platformInfo)
 {
     if (!m_env)
         return nullptr;
 
-    jmethodID constr = m_env->GetMethodID(gSimulatorClassRefs.classPlatformInfo, "<init>", "(V)V");
-    if (constr)
-        return nullptr;
-
-    jobject jPlatformInfo = (jobject) m_env->NewObject(gSimulatorClassRefs.classPlatformInfo, constr);
-    if (jPlatformInfo)
-        return nullptr;
-
+    static jmethodID platformInfoCtor = m_env->GetMethodID(gSimulatorClassRefs.platformInfoCls,
+                                        "<init>", "()V");
+    jobject jPlatformInfo = (jobject) m_env->NewObject(gSimulatorClassRefs.platformInfoCls,
+                            platformInfoCtor);
     setFieldValue(jPlatformInfo, "mPlatformId", platformInfo.getPlatformID());
-    setFieldValue(jPlatformInfo, "m_manufacturerName", platformInfo.getManufacturerName());
-    setFieldValue(jPlatformInfo, "m_manufacturerUrl", platformInfo.getManufacturerUrl());
-    setFieldValue(jPlatformInfo, "m_modelNumber", platformInfo.getModelNumber());
-    setFieldValue(jPlatformInfo, "m_dateOfManufacture", platformInfo.getDateOfManfacture());
-    setFieldValue(jPlatformInfo, "m_platformVersion", platformInfo.getPlatformVersion());
-    setFieldValue(jPlatformInfo, "m_operationSystemVersion", platformInfo.getOSVersion());
-    setFieldValue(jPlatformInfo, "m_hardwareVersion", platformInfo.getHardwareVersion());
-    setFieldValue(jPlatformInfo, "m_firmwareVersion", platformInfo.getFirmwareVersion());
-    setFieldValue(jPlatformInfo, "m_supportUrl", platformInfo.getSupportUrl());
-    setFieldValue(jPlatformInfo, "m_systemTime", platformInfo.getSystemTime());
+    setFieldValue(jPlatformInfo, "mManufacturerName", platformInfo.getManufacturerName());
+    setFieldValue(jPlatformInfo, "mManufacturerUrl", platformInfo.getManufacturerUrl());
+    setFieldValue(jPlatformInfo, "mModelNumber", platformInfo.getModelNumber());
+    setFieldValue(jPlatformInfo, "mDateOfManufacture", platformInfo.getDateOfManfacture());
+    setFieldValue(jPlatformInfo, "mPlatformVersion", platformInfo.getPlatformVersion());
+    setFieldValue(jPlatformInfo, "mOperationSystemVersion", platformInfo.getOSVersion());
+    setFieldValue(jPlatformInfo, "mHardwareVersion", platformInfo.getHardwareVersion());
+    setFieldValue(jPlatformInfo, "mFirmwareVersion", platformInfo.getFirmwareVersion());
+    setFieldValue(jPlatformInfo, "mSupportUrl", platformInfo.getSupportUrl());
+    setFieldValue(jPlatformInfo, "mSystemTime", platformInfo.getSystemTime());
 
     return jPlatformInfo;
 }
 
-PlatformInfo JPlatformInfo::toCPP(jobject jPlatformInfo)
+PlatformInfo JniPlatformInfo::toCpp(jobject jPlatformInfo)
 {
     PlatformInfo platformInfo;
     if (!m_env || !jPlatformInfo)
         return platformInfo;
 
     platformInfo.setPlatformID(getFieldValue(jPlatformInfo, "mPlatformId"));
-    platformInfo.setManufacturerName(getFieldValue(jPlatformInfo, "m_manufacturerName"));
-    platformInfo.setManufacturerUrl(getFieldValue(jPlatformInfo, "m_manufacturerUrl"));
-    platformInfo.setModelNumber(getFieldValue(jPlatformInfo, "m_modelNumber"));
-    platformInfo.setDateOfManfacture(getFieldValue(jPlatformInfo, "m_dateOfManufacture"));
-    platformInfo.setPlatformVersion(getFieldValue(jPlatformInfo, "m_platformVersion"));
-    platformInfo.setOSVersion(getFieldValue(jPlatformInfo, "m_operationSystemVersion"));
-    platformInfo.setHardwareVersion(getFieldValue(jPlatformInfo, "m_hardwareVersion"));
-    platformInfo.setFirmwareVersion(getFieldValue(jPlatformInfo, "m_firmwareVersion"));
-    platformInfo.setSupportUrl(getFieldValue(jPlatformInfo, "m_supportUrl"));
-    platformInfo.setSystemTime(getFieldValue(jPlatformInfo, "m_systemTime"));
+    platformInfo.setManufacturerName(getFieldValue(jPlatformInfo, "mManufacturerName"));
+    platformInfo.setManufacturerUrl(getFieldValue(jPlatformInfo, "mManufacturerUrl"));
+    platformInfo.setModelNumber(getFieldValue(jPlatformInfo, "mModelNumber"));
+    platformInfo.setDateOfManfacture(getFieldValue(jPlatformInfo, "mDateOfManufacture"));
+    platformInfo.setPlatformVersion(getFieldValue(jPlatformInfo, "mPlatformVersion"));
+    platformInfo.setOSVersion(getFieldValue(jPlatformInfo, "mOperationSystemVersion"));
+    platformInfo.setHardwareVersion(getFieldValue(jPlatformInfo, "mHardwareVersion"));
+    platformInfo.setFirmwareVersion(getFieldValue(jPlatformInfo, "mFirmwareVersion"));
+    platformInfo.setSupportUrl(getFieldValue(jPlatformInfo, "mSupportUrl"));
+    platformInfo.setSystemTime(getFieldValue(jPlatformInfo, "mSystemTime"));
 
     return std::move(platformInfo);
 }
 
-void JPlatformInfo::setFieldValue(jobject jPlatformInfo, const std::string &fieldName,
-                                  const std::string &value)
+void JniPlatformInfo::setFieldValue(jobject jPlatformInfo, const std::string &fieldName,
+                                    const std::string &value)
 {
-    jfieldID fieldID = m_env->GetFieldID(gSimulatorClassRefs.classPlatformInfo, fieldName.c_str(),
+    jfieldID fieldID = m_env->GetFieldID(m_env->GetObjectClass(jPlatformInfo), fieldName.c_str(),
                                          "Ljava/lang/String;");
     jstring valueStr = m_env->NewStringUTF(value.c_str());
     m_env->SetObjectField(jPlatformInfo, fieldID, valueStr);
 }
 
-std::string JPlatformInfo::getFieldValue(jobject jPlatformInfo, const std::string &fieldName)
+std::string JniPlatformInfo::getFieldValue(jobject jPlatformInfo, const std::string &fieldName)
 {
-    jfieldID fieldID = m_env->GetFieldID(gSimulatorClassRefs.classPlatformInfo, fieldName.c_str(),
+    jfieldID fieldID = m_env->GetFieldID(m_env->GetObjectClass(jPlatformInfo), fieldName.c_str(),
                                          "Ljava/lang/String;");
     jstring jvalue = (jstring) m_env->GetObjectField(jPlatformInfo, fieldID);
-    const char *valueCStr = m_env->GetStringUTFChars(jvalue, NULL);
-    if (valueCStr)
-        return std::string(valueCStr);
-    return std::string();
+    JniString value(m_env, jvalue);
+    return value.get();
 }
 
-void JniPlatformInfoListener::onPlatformInfoReceived(PlatformInfo &platformInfo)
+void onPlatformInfoReceived(jobject listener, PlatformInfo &platformInfo)
 {
-    // Get the environment
     JNIEnv *env = getEnv();
     if (!env)
         return;
 
-    jobject listener = env->NewLocalRef(m_listener);
-    if (!listener)
-    {
-        releaseEnv();
-        return;
-    }
-
     jclass listenerCls = env->GetObjectClass(listener);
-    if (!listenerCls)
-    {
-        releaseEnv();
-        return;
-    }
-
-    jmethodID listenerMId = env->GetMethodID(listenerCls, "onPlatformFound",
-                            "(Lorg/oic/simulator/PlatformInfo;)V");
-    if (!listenerMId)
-    {
-        releaseEnv();
-        return;
-    }
+    jmethodID listenerMethodId = env->GetMethodID(listenerCls, "onPlatformFound",
+                                 "(Lorg/oic/simulator/PlatformInfo;)V");
 
-    // Convert CPP to Java DeviceInfo object
-    jobject jPlatformInfo = JPlatformInfo(env).toJava(platformInfo);
+    jobject jPlatformInfo = JniPlatformInfo(env).toJava(platformInfo);
     if (!jPlatformInfo)
     {
         releaseEnv();
         return;
     }
 
-    // Invoke java listener with DeviceInfo
-    env->CallVoidMethod(listener, listenerMId, jPlatformInfo);
+    env->CallVoidMethod(listener, listenerMethodId, jPlatformInfo);
     if (env->ExceptionCheck())
     {
         releaseEnv();
index e623b81..ba75df7 100644 (file)
 #include "simulator_platform_info.h"
 #include <jni.h>
 
-class JPlatformInfo
+class JniPlatformInfo
 {
     public:
-        JPlatformInfo(JNIEnv *env) : m_env(env) {}
-        JPlatformInfo(const JPlatformInfo &) = delete;
-        JPlatformInfo &operator=(const JPlatformInfo &) = delete;
-        JPlatformInfo(const JPlatformInfo &&) = delete;
-        JPlatformInfo &operator=(const JPlatformInfo && ) = delete;
+        JniPlatformInfo(JNIEnv *env) : m_env(env) {}
+        JniPlatformInfo(const JniPlatformInfo &) = delete;
+        JniPlatformInfo &operator=(const JniPlatformInfo &) = delete;
+        JniPlatformInfo(const JniPlatformInfo &&) = delete;
+        JniPlatformInfo &operator=(const JniPlatformInfo && ) = delete;
         jobject toJava(PlatformInfo &platformInfo);
-        PlatformInfo toCPP(jobject jPlatformInfo);
+        PlatformInfo toCpp(jobject jPlatformInfo);
 
     private:
         void setFieldValue(jobject jPlatformInfo, const std::string &fieldName,
@@ -43,18 +43,6 @@ class JPlatformInfo
         JNIEnv *m_env;
 };
 
-class JniPlatformInfoListener
-{
-    public:
-        JniPlatformInfoListener(JNIEnv *env, jobject listener)
-        {
-            m_listener = env->NewWeakGlobalRef(listener);
-        }
-
-        void onPlatformInfoReceived(PlatformInfo &platformInfo);
-
-    private:
-        jweak m_listener;
-};
+void onPlatformInfoReceived(jobject listener, PlatformInfo &platformInfo);
 
 #endif
index 63215b6..f413696 100644 (file)
  *
  ******************************************************************/
 
-#include "simulator_remote_resource_jni.h"
-#include "simulator_common_jni.h"
-#include "simulator_error_codes.h"
-#include "simulator_resource_jni_util.h"
 #include "simulator_resource_model_jni.h"
-#include "simulator_client_types.h"
-#include "simulator_exceptions.h"
-#include "simulator_jni_utils.h"
+#include "simulator_exceptions_jni.h"
+#include "simulator_utils_jni.h"
+#include "jni_sharedobject_holder.h"
+#include "jni_listener_holder.h"
+#include "jni_queryparam.h"
+#include "jni_string.h"
+#include "jni_vector.h"
 
-extern SimulatorClassRefs gSimulatorClassRefs;
+#include "simulator_remote_resource.h"
 
-SimulatorRemoteResourceSP JniSimulatorRemoteResource::getResourceHandle
-(JNIEnv *env, jobject object)
-{
-    JniSimulatorRemoteResource *jniResource = GetHandle<JniSimulatorRemoteResource>(env, object);
-    if (env->ExceptionCheck() || !jniResource)
-    {
-        return nullptr;
-    }
+#define VALIDATE_OBJECT(ENV, OBJECT) if (!OBJECT){throwBadObjectException(ENV, "No corresponsing native object!"); return;}
+#define VALIDATE_OBJECT_RET(ENV, OBJECT, RET) if (!OBJECT){throwBadObjectException(ENV, "No corresponsing native object!"); return RET;}
 
-    return jniResource->m_resource;
+SimulatorRemoteResourceSP SimulatorRemoteResourceToCpp(JNIEnv *env, jobject object)
+{
+    JniSharedObjectHolder<SimulatorRemoteResource> *jniResource =
+        GetHandle<JniSharedObjectHolder<SimulatorRemoteResource>>(env, object);
+    if (jniResource)
+        return jniResource->get();
+    return nullptr;
 }
 
-class JNIOnObserveListener
+void onObserveCallback(jobject listener, const std::string &uid, const int errorCode,
+                       SimulatorResourceModelSP representation, const int seq)
 {
-    public:
-        void setJavaOnObserveListener(JNIEnv *env, jobject listener)
-        {
-            m_listener = env->NewWeakGlobalRef(listener);
-        }
+    JNIEnv *env = getEnv();
+    if (!env)
+        return;
 
-        void onObserveCallback(const std::string &uId, const int errorCode,
-                               SimulatorResourceModelSP representation,
-                               const int seqNumber)
-        {
-            JNIEnv *env = getEnv();
-            if (nullptr == env)
-                return;
-
-            jobject onObserveListener = env->NewLocalRef(m_listener);
-            if (!onObserveListener)
-            {
-                releaseEnv();
-                return;
-            }
-
-            jclass onObserveCls = env->GetObjectClass(onObserveListener);
-            if (!onObserveCls)
-            {
-                releaseEnv();
-                return;
-            }
-
-            if (OC_STACK_OK != errorCode && OC_STACK_RESOURCE_CREATED != errorCode
-                && OC_STACK_RESOURCE_DELETED != errorCode)
-            {
-                jmethodID midL = env->GetMethodID(onObserveCls, "onObserveFailed", "(Ljava/lang/Throwable;)V");
-                if (!midL)
-                {
-                    releaseEnv();
-                    return;
-                }
-                env->CallVoidMethod(onObserveListener, midL);
-            }
-            else
-            {
-                JSimulatorResourceModel *jniModel = new JSimulatorResourceModel(representation);
-                if (!jniModel)
-                {
-                    releaseEnv();
-                    return;
-                }
-
-                jobject jRepresentation = JSimulatorResourceModel::toJava(env,
-                        reinterpret_cast<jlong>(jniModel));
-                if (!jRepresentation)
-                {
-                    delete jniModel;
-                    releaseEnv();
-                    return;
-                }
-
-                jmethodID midL = env->GetMethodID(onObserveCls, "onObserveCompleted",
-                        "(Ljava/lang/String;Lorg/oic/simulator/SimulatorResourceModel;I)V");
-                if (!midL)
-                {
-                    delete jniModel;
-                    releaseEnv();
-                    return;
-                }
-
-                jstring jUid = env->NewStringUTF(uId.c_str());
-
-                env->CallVoidMethod(onObserveListener, midL, jUid, jRepresentation,
-                                    static_cast<jint>(seqNumber));
-                if (env->ExceptionCheck())
-                {
-                    delete jniModel;
-                    releaseEnv();
-                }
-            }
-        }
-
-    private:
-        jweak m_listener;
-};
-
-class JNIOnGetListener
-{
-    public:
-        void setJavaOnGetListener(JNIEnv *env, jobject listener)
-        {
-            m_listener = env->NewWeakGlobalRef(listener);
-        }
+    jclass listenerCls = env->GetObjectClass(listener);
+    jmethodID listenerMethodId = env->GetMethodID(listenerCls, "onObserveNotification",
+                                 "(Ljava/lang/String;Lorg/oic/simulator/SimulatorResourceModel;I)V");
 
-        void onGetCallback(const std::string &uId, int errorCode,
-                           SimulatorResourceModelSP representation)
-        {
-            JNIEnv *env = getEnv();
-            if (nullptr == env)
-                return;
-
-            jobject onGetListener = env->NewLocalRef(m_listener);
-            if (!onGetListener)
-            {
-                releaseEnv();
-                return;
-            }
-
-            jclass onGetCls = env->GetObjectClass(onGetListener);
-            if (!onGetCls)
-            {
-                releaseEnv();
-                return;
-            }
-
-            // TODO: Revisit is it required?
-            if (OC_STACK_OK != errorCode && OC_STACK_RESOURCE_CREATED != errorCode
-                && OC_STACK_RESOURCE_DELETED != errorCode)
-            {
-                jmethodID midL = env->GetMethodID(onGetCls, "onGetFailed", "(Ljava/lang/Throwable;)V");
-                if (!midL)
-                {
-                    releaseEnv();
-                    return;
-                }
-                env->CallVoidMethod(onGetListener, midL);
-            }
-            else
-            {
-                JSimulatorResourceModel *jniModel = new JSimulatorResourceModel(representation);
-                if (!jniModel)
-                {
-                    releaseEnv();
-                    return;
-                }
-
-                jobject jRepresentation = JSimulatorResourceModel::toJava(env, reinterpret_cast<jlong>(jniModel));
-                if (!jRepresentation)
-                {
-                    delete jniModel;
-                    releaseEnv();
-                    return;
-                }
-
-                jmethodID midL = env->GetMethodID(onGetCls, "onGetCompleted",
-                                                  "(Ljava/lang/String;Lorg/oic/simulator/SimulatorResourceModel;)V");
-                if (!midL)
-                {
-                    delete jniModel;
-                    releaseEnv();
-                    return;
-                }
-
-                jstring jUid = env->NewStringUTF(uId.c_str());
-                env->CallVoidMethod(onGetListener, midL, jUid, jRepresentation);
-                if (env->ExceptionCheck())
-                {
-                    delete jniModel;
-                    releaseEnv();
-                }
-            }
-        }
-
-    private:
-        jweak m_listener;
-};
-
-class JNIOnPutListener
-{
-    public:
-        void setJavaOnPutListener(JNIEnv *env, jobject listener)
-        {
-            m_listener = env->NewWeakGlobalRef(listener);
-        }
+    SimulatorResourceModel *resModel = representation.get();
+    jobject jResModel = simulatorResourceModelToJava(env, *resModel);
+    jstring jUid = env->NewStringUTF(uid.c_str());
+    env->CallVoidMethod(listener, listenerMethodId, jUid, jResModel, seq);
+    releaseEnv();
+}
 
-        void onPutCallback(const std::string &uId, int errorCode,
-                           SimulatorResourceModelSP representation)
-        {
-            JNIEnv *env = getEnv();
-            if (nullptr == env)
-                return;
-
-            jobject onPutListener = env->NewLocalRef(m_listener);
-            if (!onPutListener)
-            {
-                releaseEnv();
-                return;
-            }
-
-            jclass onGetCls = env->GetObjectClass(onPutListener);
-            if (!onGetCls)
-            {
-                releaseEnv();
-                return;
-            }
-
-            // TODO: Revisit is it required?
-            if (OC_STACK_OK != errorCode && OC_STACK_RESOURCE_CREATED != errorCode
-                && OC_STACK_RESOURCE_DELETED != errorCode)
-            {
-                jmethodID midL = env->GetMethodID(onGetCls, "onPutFailed", "(Ljava/lang/Throwable;)V");
-                if (!midL)
-                {
-                    releaseEnv();
-                    return;
-                }
-                env->CallVoidMethod(onPutListener, midL);
-            }
-            else
-            {
-                JSimulatorResourceModel *jniModel = new JSimulatorResourceModel(representation);
-                if (!jniModel)
-                {
-                    releaseEnv();
-                    return;
-                }
-
-                jobject jRepresentation = JSimulatorResourceModel::toJava(env,
-                        reinterpret_cast<jlong>(jniModel));
-                if (!jRepresentation)
-                {
-                    delete jniModel;
-                    releaseEnv();
-                    return;
-                }
-
-                jmethodID midL = env->GetMethodID(onGetCls, "onPutCompleted",
-                            "(Ljava/lang/String;Lorg/oic/simulator/SimulatorResourceModel;)V");
-                if (!midL)
-                {
-                    delete jniModel;
-                    releaseEnv();
-                    return;
-                }
-
-                jstring jUid = env->NewStringUTF(uId.c_str());
-                env->CallVoidMethod(onPutListener, midL, jUid, jRepresentation);
-                if (env->ExceptionCheck())
-                {
-                    delete jniModel;
-                    releaseEnv();
-                }
-            }
-        }
-
-    private:
-        jweak m_listener;
-};
-
-class JNIOnPostListener
+void onGetCallback(jobject listener, const std::string &uid, int errorCode,
+                   SimulatorResourceModelSP representation)
 {
-    public:
-        void setJavaOnPostListener(JNIEnv *env, jobject listener)
-        {
-            m_listener = env->NewWeakGlobalRef(listener);
-        }
+    JNIEnv *env = getEnv();
+    if (!env)
+        return;
 
-        void onPostCallback(const std::string &uId, int errorCode,
-                            SimulatorResourceModelSP representation)
-        {
-            JNIEnv *env = getEnv();
-            if (nullptr == env)
-                return;
-
-            jobject onPostListener = env->NewLocalRef(m_listener);
-            if (!onPostListener)
-            {
-                releaseEnv();
-                return;
-            }
-
-            jclass onGetCls = env->GetObjectClass(onPostListener);
-            if (!onGetCls)
-            {
-                releaseEnv();
-                return;
-            }
-
-            // TODO: Revisit is it required?
-            if (OC_STACK_OK != errorCode && OC_STACK_RESOURCE_CREATED != errorCode
-                && OC_STACK_RESOURCE_DELETED != errorCode)
-            {
-                jmethodID midL = env->GetMethodID(onGetCls, "onPostFailed", "(Ljava/lang/Throwable;)V");
-                if (!midL)
-                {
-                    releaseEnv();
-                    return;
-                }
-                env->CallVoidMethod(onPostListener, midL);
-            }
-            else
-            {
-                JSimulatorResourceModel *jniModel = new JSimulatorResourceModel(representation);
-                if (!jniModel)
-                {
-                    releaseEnv();
-                    return;
-                }
-
-                jobject jRepresentation = JSimulatorResourceModel::toJava(env,
-                        reinterpret_cast<jlong>(jniModel));
-                if (!jRepresentation)
-                {
-                    delete jniModel;
-                    releaseEnv();
-                    return;
-                }
-
-                jmethodID midL = env->GetMethodID(onGetCls, "onPostCompleted",
-                        "(Ljava/lang/String;Lorg/oic/simulator/SimulatorResourceModel;)V");
-                if (!midL)
-                {
-                    delete jniModel;
-                    releaseEnv();
-                    return;
-                }
-
-                jstring jUid = env->NewStringUTF(uId.c_str());
-
-                env->CallVoidMethod(onPostListener, midL, jUid, jRepresentation);
-                if (env->ExceptionCheck())
-                {
-                    delete jniModel;
-                    releaseEnv();
-                }
-            }
-        }
-
-    private:
-        jweak m_listener;
-
-};
-
-class JNIOnVerificationListener
-{
-    public:
-        void setJavaOnVerificationListener(JNIEnv *env, jobject listener)
-        {
-            m_listener = env->NewWeakGlobalRef(listener);
-        }
+    jclass listenerCls = env->GetObjectClass(listener);
+    jmethodID listenerMethodId = env->GetMethodID(listenerCls, "onGetResponse",
+                                 "(Ljava/lang/String;Lorg/oic/simulator/SimulatorResult;Lorg/oic/simulator/SimulatorResourceModel;)V");
 
-        void onVerificationCallback(const std::string &uId, int id, OperationState opState)
-        {
-            JNIEnv *env = getEnv();
-            if (nullptr == env)
-                return;
-
-            jobject onVerificationListener = env->NewLocalRef(m_listener);
-            if (!onVerificationListener)
-            {
-                releaseEnv();
-                return;
-            }
-
-            jclass onVerificationCls = env->GetObjectClass(onVerificationListener);
-            if (!onVerificationCls)
-            {
-                releaseEnv();
-                return;
-            }
-
-            jmethodID midL;
-
-            if (OP_START == opState)
-            {
-                midL = env->GetMethodID(onVerificationCls, "onVerificationStarted", "(Ljava/lang/String;I)V");
-            }
-            else if (OP_COMPLETE == opState)
-            {
-                midL = env->GetMethodID(onVerificationCls, "onVerificationCompleted", "(Ljava/lang/String;I)V");
-            }
-            else
-            {
-                midL = env->GetMethodID(onVerificationCls, "onVerificationAborted", "(Ljava/lang/String;I)V");
-            }
-
-            if (!midL)
-            {
-                releaseEnv();
-                return;
-            }
-
-            jstring jUid = env->NewStringUTF(uId.c_str());
-
-            env->CallVoidMethod(onVerificationListener, midL, jUid, (jint)id);
-
-            if (env->ExceptionCheck())
-            {
-                releaseEnv();
-            }
-        }
-
-    private:
-        jweak m_listener;
-
-};
+    SimulatorResourceModel *resModel = representation.get();
+    jobject jResModel = simulatorResourceModelToJava(env, *resModel);
+    jstring jUid = env->NewStringUTF(uid.c_str());
+    env->CallVoidMethod(listener, listenerMethodId, jUid,
+                        simulatorResultToJava(env, static_cast<SimulatorResult>(errorCode)), jResModel);
 
+    releaseEnv();
+}
 
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_startObserve
-(JNIEnv *env, jobject thiz, jint observeType, jobject jQueryParamsMap, jobject jListener)
+void onPutCallback(jobject listener, const std::string &uid, int errorCode,
+                   SimulatorResourceModelSP representation)
 {
-    if (!jListener)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_CALLBACK, "Invalid callback!");
+    JNIEnv *env = getEnv();
+    if (!env)
         return;
-    }
 
-    SimulatorRemoteResourceSP resource = JniSimulatorRemoteResource::getResourceHandle(env,
-                                         thiz);
-    if (!resource)
-    {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
-        return;
-    }
+    jclass listenerCls = env->GetObjectClass(listener);
+    jmethodID listenerMethodId = env->GetMethodID(listenerCls, "onPutResponse",
+                                 "(Ljava/lang/String;Lorg/oic/simulator/SimulatorResult;Lorg/oic/simulator/SimulatorResourceModel;)V");
 
-    std::map<std::string, std::string> queryParams;
-    if (jQueryParamsMap)
-        convertJavaMapToQueryParamsMap(env, jQueryParamsMap, queryParams);
+    SimulatorResourceModel *resModel = representation.get();
+    jobject jResModel = simulatorResourceModelToJava(env, *resModel);
+    jstring jUid = env->NewStringUTF(uid.c_str());
+    env->CallVoidMethod(listener, listenerMethodId, jUid,
+                        simulatorResultToJava(env, static_cast<SimulatorResult>(errorCode)), jResModel);
 
-    ObserveType type = ObserveType::OBSERVE;
-    if (1 == observeType)
-        type = ObserveType::OBSERVE_ALL;
+    releaseEnv();
+}
 
-    JNIOnObserveListener *onObserveListener = new JNIOnObserveListener();
-    onObserveListener->setJavaOnObserveListener(env, jListener);
+void onPostCallback(jobject listener, const std::string &uid, int errorCode,
+                    SimulatorResourceModelSP representation)
+{
+    JNIEnv *env = getEnv();
+    if (!env)
+        return;
 
-    try
-    {
-        resource->observe(type,
-                          std::bind(&JNIOnObserveListener::onObserveCallback,
-                                    onObserveListener, std::placeholders::_1,
-                                    std::placeholders::_2, std::placeholders::_3,
-                                    std::placeholders::_4));
-    }
-    catch (InvalidArgsException &e)
-    {
-        throwInvalidArgsException(env, e.code(), e.what());
-    }
-    catch (SimulatorException &e)
-    {
-        throwSimulatorException(env, e.code(), e.what());
-    }
-    catch (...)
-    {
-        throwSimulatorException(env, SIMULATOR_ERROR, "Unknown Exception");
-    }
+    jclass listenerCls = env->GetObjectClass(listener);
+    jmethodID listenerMethodId = env->GetMethodID(listenerCls, "onPostResponse",
+                                 "(Ljava/lang/String;Lorg/oic/simulator/SimulatorResult;Lorg/oic/simulator/SimulatorResourceModel;)V");
+
+    SimulatorResourceModel *resModel = representation.get();
+    jobject jResModel = simulatorResourceModelToJava(env, *resModel);
+    jstring jUid = env->NewStringUTF(uid.c_str());
+    env->CallVoidMethod(listener, listenerMethodId, jUid,
+                        simulatorResultToJava(env, static_cast<SimulatorResult>(errorCode)), jResModel);
+
+    releaseEnv();
 }
 
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_stopObserve
-(JNIEnv *env, jobject thiz)
+void onVerificationCallback(jobject listener, const std::string &uid, int id,
+                            OperationState opState)
 {
-    SimulatorRemoteResourceSP resource = JniSimulatorRemoteResource::getResourceHandle(env,
-                                         thiz);
-    if (!resource)
-    {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
+    JNIEnv *env = getEnv();
+    if (!env)
         return;
-    }
 
-    try
+    jclass listenerCls = env->GetObjectClass(listener);
+    jmethodID listenerMethodId;
+    if (OP_START == opState)
     {
-        resource->cancelObserve();
+        listenerMethodId = env->GetMethodID(listenerCls, "onVerificationStarted", "(Ljava/lang/String;I)V");
     }
-    catch (SimulatorException &e)
+    else if (OP_COMPLETE == opState)
     {
-        throwSimulatorException(env, e.code(), e.what());
+        listenerMethodId = env->GetMethodID(listenerCls, "onVerificationCompleted",
+                                            "(Ljava/lang/String;I)V");
     }
-    catch (...)
+    else if (OP_ABORT == opState)
     {
-        throwSimulatorException(env, SIMULATOR_ERROR, "Unknown Exception");
+        listenerMethodId = env->GetMethodID(listenerCls, "onVerificationAborted", "(Ljava/lang/String;I)V");
     }
+
+    jstring jUid = env->NewStringUTF(uid.c_str());
+    env->CallVoidMethod(listener, listenerMethodId, jUid, id);
+
+    if (OP_COMPLETE == opState || OP_ABORT == opState)
+        env->DeleteGlobalRef(listener);
+    releaseEnv();
 }
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_nativeGet
-(JNIEnv *env, jobject thiz, jstring jResourceInterface,
- jobject jQueryParamsMap, jobject jListener)
+Java_org_oic_simulator_client_SimulatorRemoteResource_nativeGet
+(JNIEnv *env, jobject object, jstring resInterface, jobject queryParamsMap, jobject listener)
 {
-    if (!jListener)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_CALLBACK, "Invalid callback!");
-        return;
-    }
+    VALIDATE_CALLBACK(env, listener)
 
-    SimulatorRemoteResourceSP resource = JniSimulatorRemoteResource::getResourceHandle(env,
-                                         thiz);
-    if (!resource)
-    {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
-        return;
-    }
+    SimulatorRemoteResourceSP resource = SimulatorRemoteResourceToCpp(env, object);
+    VALIDATE_OBJECT(env, resource)
 
-    // Interface type
-    const char *interfaceCStr = NULL;
-    std::string interfaceType;
-    if (jResourceInterface)
+    try
     {
-        interfaceCStr = env->GetStringUTFChars(jResourceInterface, NULL);
-        interfaceType = interfaceCStr;
-    }
-
-    // Query parameters
-    std::map<std::string, std::string> queryParams;
-    if (jQueryParamsMap)
-        convertJavaMapToQueryParamsMap(env, jQueryParamsMap, queryParams);
+        JniString jniInterface(env, resInterface);
+        std::map<std::string, std::string> queryParams =
+            JniQueryParameter(env).toCpp(queryParamsMap);
 
-    // Create listener
-    JNIOnGetListener *onGetListener = new JNIOnGetListener();
-    onGetListener->setJavaOnGetListener(env, jListener);
+        SimulatorRemoteResource::ResponseCallback callback =  std::bind([](
+                    const std::string & uid, int errorCode, SimulatorResourceModelSP representation,
+                    const std::shared_ptr<JniListenerHolder> &listenerRef)
+        {
+            onGetCallback(listenerRef->get(), uid, errorCode, representation);
+        }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
+        JniListenerHolder::create(env, listener));
 
-    try
-    {
-        resource->get(interfaceType,
-                      queryParams,
-                      std::bind(&JNIOnGetListener::onGetCallback,
-                                onGetListener, std::placeholders::_1,
-                                std::placeholders::_2, std::placeholders::_3));
+        resource->get(jniInterface.get(), queryParams, callback);
     }
     catch (InvalidArgsException &e)
     {
         throwInvalidArgsException(env, e.code(), e.what());
-        return;
     }
     catch (NoSupportException &e)
     {
-        throwNoSupportException(env, e.code(), e.what());
-        return;
+        throwNoSupportException(env, e.what());
     }
     catch (SimulatorException &e)
     {
         throwSimulatorException(env, e.code(), e.what());
-        return;
     }
-    catch (...)
-    {
-        throwSimulatorException(env, SIMULATOR_ERROR, "Unknown Exception");
-        return;
-    }
-
-    if (interfaceCStr)
-        env->ReleaseStringUTFChars(jResourceInterface, interfaceCStr);
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_nativePut
-(JNIEnv *env, jobject thiz, jstring jResourceInterface,
- jobject jRepresentation, jobject jQueryParamsMap, jobject jListener)
+Java_org_oic_simulator_client_SimulatorRemoteResource_nativePut
+(JNIEnv *env, jobject object, jstring resInterface, jobject queryParamsMap,
+ jobject representation, jobject listener)
 {
-    if (!jListener)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_CALLBACK, "Invalid callback!");
-        return;
-    }
+    VALIDATE_CALLBACK(env, listener)
 
-    SimulatorRemoteResourceSP resource = JniSimulatorRemoteResource::getResourceHandle(env,
-                                         thiz);
-    if (!resource)
-    {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
-        return;
-    }
+    SimulatorRemoteResourceSP resource = SimulatorRemoteResourceToCpp(env, object);
+    VALIDATE_OBJECT(env, resource)
 
-    // Interface type
-    const char *interfaceCStr = NULL;
-    std::string interfaceType;
-    if (jResourceInterface)
+    try
     {
-        interfaceCStr = env->GetStringUTFChars(jResourceInterface, NULL);
-        interfaceType = interfaceCStr;
-    }
-
-    // Query parameters
-    std::map<std::string, std::string> queryParams;
-    if (jQueryParamsMap)
-        convertJavaMapToQueryParamsMap(env, jQueryParamsMap, queryParams);
+        JniString jniInterface(env, resInterface);
+        std::map<std::string, std::string> queryParams =
+            JniQueryParameter(env).toCpp(queryParamsMap);
 
-    SimulatorResourceModelSP resourceModel =
-        JSimulatorResourceModel::getResourceModelPtr(env, jRepresentation);
+        SimulatorResourceModel resModel;
+        simulatorResourceModelToCpp(env, representation, resModel);
+        SimulatorResourceModelSP resModelSP(new SimulatorResourceModel(resModel));
 
-    // Create listener
-    JNIOnPutListener *onPutListener = new JNIOnPutListener();
-    onPutListener->setJavaOnPutListener(env, jListener);
+        SimulatorRemoteResource::ResponseCallback callback =  std::bind([](
+                    const std::string & uid, int errorCode, SimulatorResourceModelSP representation,
+                    const std::shared_ptr<JniListenerHolder> &listenerRef)
+        {
+            onPutCallback(listenerRef->get(), uid, errorCode, representation);
+        }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
+        JniListenerHolder::create(env, listener));
 
-    try
-    {
-        resource->put(interfaceType,
-                      queryParams,
-                      resourceModel,
-                      std::bind(&JNIOnPutListener::onPutCallback,
-                                onPutListener, std::placeholders::_1,
-                                std::placeholders::_2, std::placeholders::_3));
+        resource->put(jniInterface.get(), queryParams, resModelSP, callback);
     }
     catch (InvalidArgsException &e)
     {
         throwInvalidArgsException(env, e.code(), e.what());
-        return;
     }
     catch (NoSupportException &e)
     {
-        throwNoSupportException(env, e.code(), e.what());
-        return;
+        throwNoSupportException(env, e.what());
     }
     catch (SimulatorException &e)
     {
         throwSimulatorException(env, e.code(), e.what());
-        return;
     }
-    catch (...)
-    {
-        throwSimulatorException(env, SIMULATOR_ERROR, "Unknown Exception");
-        return;
-    }
-
-    if (interfaceCStr)
-        env->ReleaseStringUTFChars(jResourceInterface, interfaceCStr);
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_nativePost
-(JNIEnv *env, jobject thiz, jstring jResourceInterface,
- jobject jRepresentation, jobject jQueryParamsMap, jobject jListener)
+Java_org_oic_simulator_client_SimulatorRemoteResource_nativePost
+(JNIEnv *env, jobject object, jstring resInterface, jobject queryParamsMap,
+ jobject representation, jobject listener)
 {
-    if (!jListener)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_CALLBACK, "Invalid callback!");
-        return;
-    }
+    VALIDATE_CALLBACK(env, listener)
 
-    SimulatorRemoteResourceSP resource = JniSimulatorRemoteResource::getResourceHandle(env,
-                                         thiz);
-    if (!resource)
-    {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
-        return;
-    }
+    SimulatorRemoteResourceSP resource = SimulatorRemoteResourceToCpp(env, object);
+    VALIDATE_OBJECT(env, resource)
 
-    // Interface type
-    const char *interfaceCStr = NULL;
-    std::string interfaceType;
-    if (jResourceInterface)
+    try
     {
-        interfaceCStr = env->GetStringUTFChars(jResourceInterface, NULL);
-        interfaceType = interfaceCStr;
-    }
-
-    // Query parameters
-    std::map<std::string, std::string> queryParams;
-    if (jQueryParamsMap)
-        convertJavaMapToQueryParamsMap(env, jQueryParamsMap, queryParams);
+        JniString jniInterface(env, resInterface);
+        std::map<std::string, std::string> queryParams =
+            JniQueryParameter(env).toCpp(queryParamsMap);
 
-    SimulatorResourceModelSP resourceModel =
-        JSimulatorResourceModel::getResourceModelPtr(env, jRepresentation);
+        SimulatorResourceModel resModel;
+        simulatorResourceModelToCpp(env, representation, resModel);
+        SimulatorResourceModelSP resModelSP(new SimulatorResourceModel(resModel));
 
-    // Create listener
-    JNIOnPostListener *onPostListener = new JNIOnPostListener();
-    onPostListener->setJavaOnPostListener(env, jListener);
+        SimulatorRemoteResource::ResponseCallback callback =  std::bind([](
+                    const std::string & uid, int errorCode, SimulatorResourceModelSP representation,
+                    const std::shared_ptr<JniListenerHolder> &listenerRef)
+        {
+            onPostCallback(listenerRef->get(), uid, errorCode, representation);
+        }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
+        JniListenerHolder::create(env, listener));
 
-    try
-    {
-        resource->post(interfaceType,
-                       queryParams,
-                       resourceModel,
-                       std::bind(&JNIOnPostListener::onPostCallback,
-                                 onPostListener, std::placeholders::_1,
-                                 std::placeholders::_2, std::placeholders::_3));
+        resource->post(jniInterface.get(), queryParams, resModelSP, callback);
     }
     catch (InvalidArgsException &e)
     {
         throwInvalidArgsException(env, e.code(), e.what());
-        return;
     }
     catch (NoSupportException &e)
     {
-        throwNoSupportException(env, e.code(), e.what());
-        return;
+        throwNoSupportException(env, e.what());
     }
     catch (SimulatorException &e)
     {
         throwSimulatorException(env, e.code(), e.what());
-        return;
-    }
-    catch (...)
-    {
-        throwSimulatorException(env, SIMULATOR_ERROR, "Unknown Exception");
-        return;
     }
-
-    if (interfaceCStr)
-        env->ReleaseStringUTFChars(jResourceInterface, interfaceCStr);
 }
 
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_setConfigInfo
-(JNIEnv *env, jobject thiz, jstring jConfigPath)
+JNIEXPORT jobject JNICALL
+Java_org_oic_simulator_client_SimulatorRemoteResource_setConfigInfo
+(JNIEnv *env, jobject object, jstring configPath)
 {
-    if (!jConfigPath)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM,
-                                  "Configuration file path is null!");
-        return;
-    }
+    VALIDATE_INPUT_RET(env, !configPath, "Path is null!", nullptr)
 
-    SimulatorRemoteResourceSP resource = JniSimulatorRemoteResource::getResourceHandle(env,
-                                         thiz);
-    if (!resource)
+    SimulatorRemoteResourceSP resource = SimulatorRemoteResourceToCpp(env, object);
+    VALIDATE_OBJECT_RET(env, resource, nullptr)
+
+    try
     {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
-        return;
+        JniString jniConfigPath(env, configPath);
+        SimulatorResourceModelSP repSchema = resource->configure(jniConfigPath.get());
+        return simulatorResourceModelToJava(env, *(repSchema.get()));
     }
-
-    // Interface type
-    const char *configCStr = NULL;
-    std::string configPath;
-    if (jConfigPath)
+    catch (InvalidArgsException &e)
     {
-        configCStr = env->GetStringUTFChars(jConfigPath, NULL);
-        configPath = configCStr;
+        throwInvalidArgsException(env, e.code(), e.what());
     }
 
+    return nullptr;
+}
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_client_SimulatorRemoteResource_startObserve
+(JNIEnv *env, jobject object, jobject queryParamsMap, jobject listener)
+{
+    VALIDATE_CALLBACK(env, listener)
+
+    SimulatorRemoteResourceSP resource = SimulatorRemoteResourceToCpp(env, object);
+    VALIDATE_OBJECT(env, resource)
+
     try
     {
-        resource->configure(configPath);
+        std::map<std::string, std::string> queryParams =
+            JniQueryParameter(env).toCpp(queryParamsMap);
+
+        SimulatorRemoteResource::ObserveNotificationCallback callback =  std::bind([](
+                    const std::string & uid, const int errorCode,
+                    SimulatorResourceModelSP representation, const int seq,
+                    const std::shared_ptr<JniListenerHolder> &listenerRef)
+        {
+            onObserveCallback(listenerRef->get(), uid, errorCode, representation, seq);
+        }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
+        std::placeholders::_4, JniListenerHolder::create(env, listener));
+
+        resource->observe(ObserveType::OBSERVE, callback);
     }
     catch (InvalidArgsException &e)
     {
         throwInvalidArgsException(env, e.code(), e.what());
-        return;
     }
-    catch (...)
+    catch (SimulatorException &e)
     {
-        throwSimulatorException(env, SIMULATOR_ERROR, "Unknown Exception");
-        return;
+        throwSimulatorException(env, e.code(), e.what());
     }
-
-    if (configCStr)
-        env->ReleaseStringUTFChars(jConfigPath, configCStr);
 }
 
-JNIEXPORT jint JNICALL
-Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_startVerification
-(JNIEnv *env, jobject thiz, jint jReqType, jobject jListener)
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_client_SimulatorRemoteResource_stopObserve
+(JNIEnv *env, jobject object)
 {
-    if (!jListener)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_CALLBACK, "Invalid callback!");
-        return SIMULATOR_INVALID_CALLBACK;
-    }
+    SimulatorRemoteResourceSP resource = SimulatorRemoteResourceToCpp(env, object);
+    VALIDATE_OBJECT(env, resource)
 
-    SimulatorRemoteResourceSP resource = JniSimulatorRemoteResource::getResourceHandle(env,
-                                         thiz);
-    if (!resource)
+    try
     {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
-        return SIMULATOR_BAD_OBJECT;
+        resource->cancelObserve();
     }
-
-    // Convert RequestType
-    RequestType reqType;
-
-    switch (jReqType)
+    catch (SimulatorException &e)
     {
-        case 0:
-            reqType = RequestType::RQ_TYPE_GET;
-            break;
-
-        case 1:
-            reqType = RequestType::RQ_TYPE_PUT;
-            break;
+        throwSimulatorException(env, e.code(), e.what());
+    }
+}
 
-        case 2:
-            reqType = RequestType::RQ_TYPE_POST;
-            break;
+JNIEXPORT jint JNICALL
+Java_org_oic_simulator_client_SimulatorRemoteResource_startVerification
+(JNIEnv *env, jobject object, jint reqType, jobject listener)
+{
+    VALIDATE_CALLBACK_RET(env, listener, -1)
 
-        case 3:
-            reqType = RequestType::RQ_TYPE_DELETE;
-            break;
+    SimulatorRemoteResourceSP resource = SimulatorRemoteResourceToCpp(env, object);
+    VALIDATE_OBJECT_RET(env, resource, -1)
 
-        default:
-            return -1;
+    // Convert RequestType
+    RequestType type;
+    switch (reqType)
+    {
+        case 0: type = RequestType::RQ_TYPE_GET; break;
+        case 1: type = RequestType::RQ_TYPE_PUT; break;
+        case 2: type = RequestType::RQ_TYPE_POST; break;
+        case 3: type = RequestType::RQ_TYPE_DELETE; break;
+        default: return -1;
     }
 
-    // Create listener
-    JNIOnVerificationListener *onVerificationListener = new JNIOnVerificationListener();
-    onVerificationListener->setJavaOnVerificationListener(env, jListener);
-
-    int automationId = -1;
-
     try
     {
-        automationId = resource->startVerification(reqType,
-                       std::bind(&JNIOnVerificationListener::onVerificationCallback,
-                                 onVerificationListener, std::placeholders::_1,
-                                 std::placeholders::_2, std::placeholders::_3));
+        SimulatorRemoteResource::StateCallback callback =  std::bind([](
+                    const std::string & uid, int id, OperationState opState,
+                    const std::shared_ptr<JniListenerHolder> &listenerRef)
+        {
+            onVerificationCallback(listenerRef->get(), uid, id, opState);
+        }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
+        JniListenerHolder::create(env, listener));
+
+        return resource->startVerification(type, callback);
     }
     catch (InvalidArgsException &e)
     {
@@ -841,39 +394,30 @@ Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_startVerificatio
     }
     catch (NoSupportException &e)
     {
-        throwNoSupportException(env, e.code(), e.what());
+        throwNoSupportException(env, e.what());
     }
     catch (OperationInProgressException &e)
     {
-        throwOperationInProgressException(env, e.code(), e.what());
+        throwOperationInProgressException(env, e.what());
     }
     catch (SimulatorException &e)
     {
         throwSimulatorException(env, e.code(), e.what());
     }
-    catch (...)
-    {
-        throwSimulatorException(env, SIMULATOR_ERROR, "Unknown Exception");
-    }
 
-    return automationId;
+    return -1;
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_stopVerification
-(JNIEnv *env, jobject thiz, jint jId)
+Java_org_oic_simulator_client_SimulatorRemoteResource_stopVerification
+(JNIEnv *env, jobject object, jint id)
 {
-    SimulatorRemoteResourceSP resource = JniSimulatorRemoteResource::getResourceHandle(env,
-                                         thiz);
-    if (!resource)
-    {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
-        return;
-    }
+    SimulatorRemoteResourceSP resource = SimulatorRemoteResourceToCpp(env, object);
+    VALIDATE_OBJECT(env, resource)
 
     try
     {
-        resource->stopVerification((int)jId);
+        resource->stopVerification(id);
     }
     catch (InvalidArgsException &e)
     {
@@ -881,17 +425,19 @@ Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_stopVerification
     }
     catch (NoSupportException &e)
     {
-        throwNoSupportException(env, e.code(), e.what());
-    }
-    catch (...)
-    {
-        throwSimulatorException(env, SIMULATOR_ERROR, "Unknown Exception");
+        throwNoSupportException(env, e.what());
     }
 }
 
-JNIEXPORT void JNICALL Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_dispose
-(JNIEnv *env, jobject thiz)
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_client_SimulatorRemoteResource_dispose
+(JNIEnv *env, jobject object)
 {
-    JniSimulatorRemoteResource *resource = GetHandle<JniSimulatorRemoteResource>(env, thiz);
+    JniSharedObjectHolder<SimulatorRemoteResource> *resource =
+        GetHandle<JniSharedObjectHolder<SimulatorRemoteResource>>(env, object);
     delete resource;
-}
\ No newline at end of file
+}
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/service/simulator/java/jni/simulator_remote_resource_jni.h b/service/simulator/java/jni/simulator_remote_resource_jni.h
deleted file mode 100644 (file)
index b1fbecd..0000000
+++ /dev/null
@@ -1,85 +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.
- *
- ******************************************************************/
-
-#ifndef SIMULATOR_REMOTE_RESOURCE_JNI_H_
-#define SIMULATOR_REMOTE_RESOURCE_JNI_H_
-
-#include <jni.h>
-#include "simulator_remote_resource.h"
-
-class JniSimulatorRemoteResource
-{
-    public:
-        JniSimulatorRemoteResource(SimulatorRemoteResourceSP &resource)
-            : m_resource(resource) {};
-        static SimulatorRemoteResourceSP getResourceHandle(JNIEnv *env, jobject object);
-    private:
-        SimulatorRemoteResourceSP m_resource;
-};
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_startObserve
-(JNIEnv *env, jobject thiz, jint observeType, jobject jQueryParamsMap, jobject jListener);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_stopObserve
-(JNIEnv *env, jobject thiz);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_nativeGet
-(JNIEnv *env, jobject thiz, jstring jResourceInterface,
- jobject jQueryParamsMap, jobject jListener);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_nativePut
-(JNIEnv *env, jobject thiz, jstring jResourceInterface,
- jobject jRepresentation, jobject jQueryParamsMap, jobject jListener);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_nativePost
-(JNIEnv *env, jobject thiz, jstring jResourceInterface,
- jobject jRepresentation, jobject jQueryParamsMap, jobject jListener);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_setConfigInfo
-(JNIEnv *env, jobject thiz, jstring jConfigPath);
-
-JNIEXPORT jint JNICALL
-Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_startVerification
-(JNIEnv *env, jobject thiz, jint jReqType, jobject jListener);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_stopVerification
-(JNIEnv *env, jobject thiz, jint jId);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_dispose
-(JNIEnv *, jobject);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
diff --git a/service/simulator/java/jni/simulator_resource_jni.cpp b/service/simulator/java/jni/simulator_resource_jni.cpp
new file mode 100644 (file)
index 0000000..e470596
--- /dev/null
@@ -0,0 +1,415 @@
+/******************************************************************
+ *
+ * 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.
+ *
+ ******************************************************************/
+
+#include "simulator_exceptions_jni.h"
+#include "simulator_utils_jni.h"
+#include "jni_sharedobject_holder.h"
+#include "jni_listener_holder.h"
+#include "jni_string.h"
+#include "jni_vector.h"
+
+#include "simulator_resource.h"
+
+#define VALIDATE_OBJECT(ENV, OBJECT) if (!OBJECT){throwBadObjectException(ENV, "No corresponsing native object!"); return;}
+#define VALIDATE_OBJECT_RET(ENV, OBJECT, RET) if (!OBJECT){throwBadObjectException(ENV, "No corresponsing native object!"); return RET;}
+
+SimulatorResourceSP SimulatorResourceToCpp(JNIEnv *env, jobject object)
+{
+    JniSharedObjectHolder<SimulatorResource> *jniResource =
+        GetHandle<JniSharedObjectHolder<SimulatorResource>>(env, object);
+    if (jniResource)
+        return jniResource->get();
+    return nullptr;
+}
+
+static jobject resourceTypeToJava(JNIEnv *env, SimulatorResource::Type type)
+{
+    static jfieldID single = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResourceTypeCls,
+                             "SINGLE", "Lorg/oic/simulator/server/SimulatorResource$Type;");
+    static jfieldID collection = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResourceTypeCls,
+                                 "COLLECTION", "Lorg/oic/simulator/server/SimulatorResource$Type;");
+
+    switch (type)
+    {
+        case SimulatorResource::Type::SINGLE_RESOURCE:
+            return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResourceTypeCls, single);
+        case SimulatorResource::Type::COLLECTION_RESOURCE:
+            return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResourceTypeCls, collection);
+    }
+
+    return nullptr;
+}
+
+static jobject createObserverInfo(JNIEnv *env, const ObserverInfo &observerInfo)
+{
+    static jmethodID observerInfoCtor = env->GetMethodID(gSimulatorClassRefs.observerCls,
+                                        "<init>", "(ILjava/lang/String;I)V");
+
+    jstring address = env->NewStringUTF(observerInfo.address.c_str());
+    jobject observer = (jobject) env->NewObject(gSimulatorClassRefs.observerCls,
+                       observerInfoCtor, observerInfo.id, address, observerInfo.port);
+    env->DeleteLocalRef(address);
+
+    return observer;
+}
+
+static jobject createObserverInfoVector(JNIEnv *env,
+                                        const std::vector<ObserverInfo> observersList)
+{
+    jobject vectorObject = JniVector(env).toJava();
+    if (!vectorObject)
+        return nullptr;
+
+    static jmethodID addMethod = env->GetMethodID(gSimulatorClassRefs.vectorCls,
+                                 "add", "(Ljava/lang/Object;)Z");
+
+    for (auto &observer : observersList)
+        env->CallBooleanMethod(vectorObject, addMethod, createObserverInfo(env, observer));
+
+    return vectorObject;
+}
+
+static void onObserverChange(jobject listener, const std::string &uri,
+                             ObservationStatus state, const ObserverInfo &observerInfo)
+{
+    JNIEnv *env = getEnv();
+    if (env)
+        return;
+
+    jclass listenerCls = env->GetObjectClass(listener);
+    jmethodID listenerMethod = nullptr;
+    if (ObservationStatus::REGISTER == state)
+    {
+        listenerMethod = env->GetMethodID(listenerCls, "onObserverAdded",
+                                          "(Ljava/lang/String;Lorg/oic/simulator/server/Observer;)V");
+    }
+    else
+    {
+        listenerMethod = env->GetMethodID(listenerCls, "onObserverRemoved",
+                                          "(Ljava/lang/String;Lorg/oic/simulator/server/Observer;)V");
+    }
+
+    jstring jUri = env->NewStringUTF(uri.c_str());
+    jobject jobserver = createObserverInfo(env, observerInfo);
+
+    env->CallVoidMethod(listener, listenerMethod, jUri, jobserver);
+    releaseEnv();
+}
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+JNIEXPORT jstring JNICALL
+Java_org_oic_simulator_server_SimulatorResource_getName
+(JNIEnv *env, jobject object)
+{
+    SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
+    VALIDATE_OBJECT_RET(env, resource, nullptr)
+
+    return env->NewStringUTF(resource->getName().c_str());
+}
+
+JNIEXPORT jobject JNICALL
+Java_org_oic_simulator_server_SimulatorResource_getType
+(JNIEnv *env, jobject object)
+{
+    SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
+    VALIDATE_OBJECT_RET(env, resource, nullptr)
+
+    return resourceTypeToJava(env, resource->getType());
+}
+
+JNIEXPORT jstring JNICALL
+Java_org_oic_simulator_server_SimulatorResource_getURI
+(JNIEnv *env, jobject object)
+{
+    SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
+    VALIDATE_OBJECT_RET(env, resource, nullptr)
+
+    return env->NewStringUTF(resource->getURI().c_str());
+}
+
+JNIEXPORT jstring JNICALL
+Java_org_oic_simulator_server_SimulatorResource_getResourceType
+(JNIEnv *env, jobject object)
+{
+    SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
+    VALIDATE_OBJECT_RET(env, resource, nullptr)
+
+    return env->NewStringUTF(resource->getResourceType().c_str());
+}
+
+JNIEXPORT jobject JNICALL
+Java_org_oic_simulator_server_SimulatorResource_getInterface
+(JNIEnv *env, jobject object)
+{
+    SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
+    VALIDATE_OBJECT_RET(env, resource, nullptr)
+
+    std::vector<std::string> interfaces = resource->getInterface();
+    return JniVector(env).toJava(interfaces);
+}
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_server_SimulatorResource_setName
+(JNIEnv *env, jobject object, jstring name)
+{
+    VALIDATE_INPUT(env, !name, "Name is null!")
+
+    SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
+    VALIDATE_OBJECT(env, resource)
+
+    try
+    {
+        JniString jniName(env, name);
+        resource->setName(jniName.get());
+    }
+    catch (InvalidArgsException &e)
+    {
+        throwInvalidArgsException(env, e.code(), e.what());
+    }
+    catch (SimulatorException &e)
+    {
+        throwInvalidArgsException(env, e.code(), e.what());
+    }
+}
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_server_SimulatorResource_setURI
+(JNIEnv *env, jobject object, jstring uri)
+{
+    VALIDATE_INPUT(env, !uri, "Uri is null!")
+
+    SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
+    VALIDATE_OBJECT(env, resource)
+
+    try
+    {
+        JniString jniUri(env, uri);
+        resource->setURI(jniUri.get());
+    }
+    catch (InvalidArgsException &e)
+    {
+        throwInvalidArgsException(env, e.code(), e.what());
+    }
+    catch (SimulatorException &e)
+    {
+        throwInvalidArgsException(env, e.code(), e.what());
+    }
+}
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_server_SimulatorResource_setResourceType
+(JNIEnv *env, jobject object, jstring resourceType)
+{
+    VALIDATE_INPUT(env, !resourceType, "Resource type is null!")
+
+    SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
+    VALIDATE_OBJECT(env, resource)
+
+    try
+    {
+        JniString jniType(env, resourceType);
+        resource->setResourceType(jniType.get());
+    }
+    catch (InvalidArgsException &e)
+    {
+        throwInvalidArgsException(env, e.code(), e.what());
+    }
+    catch (SimulatorException &e)
+    {
+        throwInvalidArgsException(env, e.code(), e.what());
+    }
+}
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_server_SimulatorResource_addInterface
+(JNIEnv *env, jobject object, jstring interfaceType)
+{
+    VALIDATE_INPUT(env, !interfaceType, "Interface type is null!")
+
+    SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
+    VALIDATE_OBJECT(env, resource)
+
+    try
+    {
+        JniString jniInterfaceType(env, interfaceType);
+        resource->addInterface(jniInterfaceType.get());
+    }
+    catch (InvalidArgsException &e)
+    {
+        throwInvalidArgsException(env, e.code(), e.what());
+    }
+    catch (NoSupportException &e)
+    {
+        throwNoSupportException(env, e.what());
+    }
+    catch (SimulatorException &e)
+    {
+        throwInvalidArgsException(env, e.code(), e.what());
+    }
+}
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_server_SimulatorResource_setObservable
+(JNIEnv *env, jobject object, jboolean state)
+{
+    SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
+    VALIDATE_OBJECT(env, resource)
+
+    try
+    {
+        resource->setObservable(static_cast<bool>(state));
+    }
+    catch (SimulatorException &e)
+    {
+        throwInvalidArgsException(env, e.code(), e.what());
+    }
+}
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_server_SimulatorResource_setObserverListener
+(JNIEnv *env, jobject object, jobject listener)
+{
+    VALIDATE_CALLBACK(env, listener)
+
+    SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
+    VALIDATE_OBJECT(env, resource)
+
+    SimulatorResource::ObserverCallback callback =  std::bind([](const std::string & uri,
+            ObservationStatus state, const ObserverInfo & observerInfo,
+            const std::shared_ptr<JniListenerHolder> &listenerRef)
+    {
+        onObserverChange(listenerRef->get(), uri, state, observerInfo);
+    }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
+    JniListenerHolder::create(env, listener));
+
+    try
+    {
+        resource->setObserverCallback(callback);
+    }
+    catch (InvalidArgsException &e)
+    {
+        throwInvalidArgsException(env, e.code(), e.what());
+    }
+}
+
+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 void JNICALL
+Java_org_oic_simulator_server_SimulatorResource_start
+(JNIEnv *env, jobject object)
+{
+    SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
+    VALIDATE_OBJECT(env, resource)
+
+    try
+    {
+        resource->start();
+    }
+    catch (SimulatorException &e)
+    {
+        throwSimulatorException(env, e.code(), e.what());
+    }
+}
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_server_SimulatorResource_stop
+(JNIEnv *env, jobject object)
+{
+    SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
+    VALIDATE_OBJECT(env, resource)
+
+    try
+    {
+        resource->stop();
+    }
+    catch (SimulatorException &e)
+    {
+        throwSimulatorException(env, e.code(), e.what());
+    }
+}
+
+JNIEXPORT jobject JNICALL
+Java_org_oic_simulator_server_SimulatorResource_getObservers
+(JNIEnv *env, jobject object)
+{
+    SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
+    VALIDATE_OBJECT_RET(env, resource, nullptr)
+
+    return createObserverInfoVector(env, resource->getObserversList());
+}
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_server_SimulatorResource_notifyObserver
+(JNIEnv *env, jobject object, jint id)
+{
+    SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
+    VALIDATE_OBJECT(env, resource)
+
+    try
+    {
+        resource->notify(id);
+    }
+    catch (SimulatorException &e)
+    {
+        throwSimulatorException(env, e.code(), e.what());
+    }
+}
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_server_SimulatorResource_notifyAllObservers
+(JNIEnv *env, jobject object)
+{
+    SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
+    VALIDATE_OBJECT(env, resource)
+
+    try
+    {
+        resource->notifyAll();
+    }
+    catch (SimulatorException &e)
+    {
+        throwSimulatorException(env, e.code(), e.what());
+    }
+}
+
+#ifdef __cplusplus
+}
+#endif
\ No newline at end of file
diff --git a/service/simulator/java/jni/simulator_resource_jni_util.cpp b/service/simulator/java/jni/simulator_resource_jni_util.cpp
deleted file mode 100644 (file)
index de2952b..0000000
+++ /dev/null
@@ -1,206 +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.
- *
- ******************************************************************/
-#include "simulator_resource_jni_util.h"
-#include "simulator_common_jni.h"
-
-extern SimulatorClassRefs gSimulatorClassRefs;
-
-std::vector<int> convertIntegerVector(JNIEnv *env, jobject jVectorInt)
-{
-    std::vector<int> vectorInt;
-
-    jclass vectorClass = env->FindClass("java/util/Vector");
-    if (!vectorClass)
-    {
-        return vectorInt;
-    }
-
-    jmethodID size = env->GetMethodID(vectorClass, "size", "()I");
-    if (NULL == size)
-    {
-        return vectorInt;
-    }
-
-    jmethodID get = env->GetMethodID(vectorClass, "get", "(I)""Ljava/lang/Object;");
-    if (NULL == get)
-    {
-        return vectorInt;
-    }
-
-    jint jSize = env->CallIntMethod(jVectorInt, size);
-    int sizeOfVector = jSize;
-
-    for (int index = 0; index < sizeOfVector; index++)
-    {
-        jint jIndex = index;
-        jint jValue = env->CallIntMethod(jVectorInt, get, jIndex);
-        vectorInt.push_back((int)jValue);
-    }
-
-    return vectorInt;
-}
-
-std::vector<double> convertDoubleVector(JNIEnv *env, jobject jVectorDouble)
-{
-    std::vector<double> vectorDouble;
-
-    jclass vectorClass = env->FindClass("java/util/Vector");
-    if (!vectorClass)
-    {
-        return vectorDouble;
-    }
-
-    jmethodID size = env->GetMethodID(vectorClass, "size", "()I");
-    if (NULL == size)
-    {
-        return vectorDouble;
-    }
-
-    jmethodID get = env->GetMethodID(vectorClass, "get", "(I)""Ljava/lang/Object;");
-    if (NULL == get)
-    {
-        return vectorDouble;
-    }
-
-    jint jSize = env->CallIntMethod(jVectorDouble, size);
-    int sizeOfVector = jSize;
-
-    for (int index = 0; index < sizeOfVector; index++)
-    {
-        jint jIndex = index;
-        jdouble jValue = env->CallDoubleMethod(jVectorDouble, get, jIndex);
-        vectorDouble.push_back((double)jValue);
-    }
-
-    return vectorDouble;
-}
-
-std::vector<std::string> convertStringVector(JNIEnv *env, jobject jVectorString)
-{
-    std::vector<std::string> vectorString;
-
-    jclass vectorClass = env->FindClass("java/util/Vector");
-    if (!vectorClass)
-    {
-        return vectorString;
-    }
-
-    jmethodID size = env->GetMethodID(vectorClass, "size", "()I");
-    if (NULL == size)
-    {
-        return vectorString;
-    }
-
-    jmethodID get = env->GetMethodID(vectorClass, "get", "(I)""Ljava/lang/Object;");
-    if (NULL == get)
-    {
-        return vectorString;
-    }
-
-    jint jSize = env->CallIntMethod(jVectorString, size);
-    int sizeOfVector = jSize;
-
-    for (int index = 0; index < sizeOfVector; index++)
-    {
-        jint jIndex = index;
-        jstring jContactInfoObj = (jstring)env->CallObjectMethod(jVectorString, get, jIndex);
-        if (jContactInfoObj == NULL)
-        {
-            return vectorString;
-        }
-        const char *buff = env->GetStringUTFChars(jContactInfoObj, 0);
-        if (NULL != buff)
-        {
-            std::string tempString = buff;
-            vectorString.push_back(tempString);
-        }
-
-        env->ReleaseStringUTFChars(jContactInfoObj, buff);
-    }
-
-    return vectorString;
-}
-
-void convertJavaMapToQueryParamsMap(JNIEnv *env, jobject hashMap,
-                                    std::map<std::string, std::string> &queryParams)
-{
-    if (!hashMap) return;
-
-    jobject jEntrySet = env->CallObjectMethod(hashMap, gSimulatorClassRefs.classMapEntrySet);
-    jobject jIterator = env->CallObjectMethod(jEntrySet, gSimulatorClassRefs.classIteratorId);
-    if (!jEntrySet || !jIterator || env->ExceptionCheck()) return;
-
-    while (env->CallBooleanMethod(jIterator, gSimulatorClassRefs.classHasNextId))
-    {
-        jobject jEntry = env->CallObjectMethod(jIterator, gSimulatorClassRefs.classNextId);
-        if (!jEntry) return;
-        jstring jKey = (jstring)env->CallObjectMethod(jEntry, gSimulatorClassRefs.classMapGetKey);
-        if (!jKey) return;
-        jstring jValue = (jstring)env->CallObjectMethod(jEntry, gSimulatorClassRefs.classMapGetValue);
-        if (!jValue) return;
-
-        queryParams.insert(std::make_pair(env->GetStringUTFChars(jKey, NULL),
-                                          env->GetStringUTFChars(jValue, NULL)));
-
-        if (env->ExceptionCheck()) return;
-        env->DeleteLocalRef(jEntry);
-        env->DeleteLocalRef(jKey);
-        env->DeleteLocalRef(jValue);
-    }
-}
-
-jobject convertHashMapToJavaMap(JNIEnv *env,
-                                const std::map<std::string, uint8_t> &observersList)
-{
-    if (observersList.empty())
-    {
-        return NULL;
-    }
-
-    jobject jObserverListMap = env->NewObject(gSimulatorClassRefs.classHashMap,
-                               gSimulatorClassRefs.classHashMapCtor);
-
-    for (auto it = observersList.begin(); it != observersList.end(); ++it)
-    {
-        jstring key = (*env).NewStringUTF( (*it).first.c_str() );
-        jint value = (*it).second;
-        env->CallObjectMethod(jObserverListMap, gSimulatorClassRefs.classHashMapPut, key, value);
-    }
-
-    return jObserverListMap;
-}
-
-jobject convertStringVectorToJavaList(JNIEnv *env, std::vector<std::string> &vector)
-{
-    jobject jList = env->NewObject(gSimulatorClassRefs.classLinkedList,
-                                   gSimulatorClassRefs.classLinkedListCtor);
-    if (!jList) return nullptr;
-    for (size_t i = 0; i < vector.size(); ++i)
-    {
-        jstring jStr = env->NewStringUTF(vector[i].c_str());
-        if (!jStr) return nullptr;
-        env->CallBooleanMethod(jList, gSimulatorClassRefs.classLinkedListAddObject, jStr);
-        if (env->ExceptionCheck()) return nullptr;
-        env->DeleteLocalRef(jStr);
-    }
-    return jList;
-}
-
-
diff --git a/service/simulator/java/jni/simulator_resource_jni_util.h b/service/simulator/java/jni/simulator_resource_jni_util.h
deleted file mode 100644 (file)
index d3c7e70..0000000
+++ /dev/null
@@ -1,77 +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.
- *
- ******************************************************************/
-
-/**
- * @file   simulator_resource_jni_util.h
- *
- * @brief  This file contains the utility functions for conversions from java to CPP
- * and viceversa
- */
-
-#ifndef __SIMULATOR_RESOURCE_JNI_UTIL_H_
-#define __SIMULATOR_RESOURCE_JNI_UTIL_H_
-
-#include <jni.h>
-#include <iostream>
-#include <vector>
-#include <map>
-
-#include "simulator_remote_resource.h"
-
-/**
-  * Utility function for converting a Java Vector of Strings to CPP Vector of Strings
-  *
-  * @param env - Default JNI Environment pointer
-  * @param jVectorString - Java Vector of Strings
-  *
-  * @return void
-  */
-std::vector<int> convertIntegerVector(JNIEnv *env, jobject jVectorInt);
-
-/**
-  * Utility function for converting a Java Vector of Strings to CPP Vector of Strings
-  *
-  * @param env - Default JNI Environment pointer
-  * @param jVectorString - Java Vector of Strings
-  *
-  * @return void
-  */
-std::vector<double> convertDoubleVector(JNIEnv *env, jobject jVectorDouble);
-
-/**
-  * Utility function for converting a Java Vector of Strings to CPP Vector of Strings
-  *
-  * @param env - Default JNI Environment pointer
-  * @param jVectorString - Java Vector of Strings
-  *
-  * @return void
-  */
-std::vector<std::string> convertStringVector(JNIEnv *env, jobject jVectorString);
-
-void convertJavaMapToQueryParamsMap(JNIEnv *env, jobject hashMap,
-                                    std::map<std::string, std::string> &map);
-
-jobject convertHashMapToJavaMap(JNIEnv *env,
-                                const std::map<std::string, uint8_t> &observersList);
-
-jobject convertStringVectorToJavaList(JNIEnv *env, std::vector<std::string> &vector);
-
-#endif //__SIMULATOR_RESOURCE_JNI_UTIL_H_
-
index 65b9d9d..3ed5a1b 100644 (file)
  ******************************************************************/
 
 #include "simulator_resource_model_jni.h"
-#include "simulator_common_jni.h"
-#include "resource_attributes_jni.h"
 #include "simulator_error_codes.h"
-#include "simulator_jni_utils.h"
+#include "simulator_exceptions_jni.h"
+#include "simulator_utils_jni.h"
+#include "jni_string.h"
 
-using namespace std;
-
-extern SimulatorClassRefs gSimulatorClassRefs;
-
-JSimulatorResourceModel::JSimulatorResourceModel(SimulatorResourceModel resModel)
-    : m_resourceModel(resModel)
-{}
-
-JSimulatorResourceModel::JSimulatorResourceModel(SimulatorResourceModelSP resModel)
-    : m_resModelPtr(resModel)
-{}
-
-bool JSimulatorResourceModel::getResourceModel(JNIEnv *env, jobject thiz,
-        SimulatorResourceModel &resModel)
+class JniTypeInfo
 {
-    JSimulatorResourceModel *resource = GetHandle<JSimulatorResourceModel>(env, thiz);
-    if (env->ExceptionCheck())
-    {
-        return false;
-    }
-
-    if (nullptr != resource->m_resModelPtr)
-        resModel = *(resource->m_resModelPtr.get());
-    else
-        resModel = resource->m_resourceModel;
-    return true;
-}
-
-SimulatorResourceModelSP JSimulatorResourceModel::getResourceModelPtr(JNIEnv *env, jobject thiz)
+    public:
+        JniTypeInfo(JNIEnv *env) : m_env(env) {}
+
+        SimulatorResourceModel::TypeInfo toCpp(jobject jAttributeValue)
+        {
+            static jmethodID typeInfoMID = m_env->GetMethodID(gSimulatorClassRefs.attributeValueCls,
+                                           "typeInfo", "()Lorg/oic/simulator/AttributeValue$TypeInfo;");
+            static jfieldID typeFID = m_env->GetFieldID(gSimulatorClassRefs.attributeTypeInfoCls,
+                                      "mType", "Lorg/oic/simulator/AttributeValue$ValueType;");
+            static jfieldID baseTypeFID = m_env->GetFieldID(gSimulatorClassRefs.attributeTypeInfoCls,
+                                          "mBaseType", "Lorg/oic/simulator/AttributeValue$ValueType;");
+            static jfieldID depthFID = m_env->GetFieldID(gSimulatorClassRefs.attributeTypeInfoCls,
+                                       "mDepth", "I");
+
+            jobject jTypeInfo = m_env->CallObjectMethod(jAttributeValue, typeInfoMID);
+            jobject jType = m_env->GetObjectField(jTypeInfo, typeFID);
+            jobject jBaseType = m_env->GetObjectField(jTypeInfo, baseTypeFID);
+            jint jDepth = m_env->GetIntField(jTypeInfo, depthFID);
+
+            return SimulatorResourceModel::TypeInfo(getValueType(jType),
+                                                    getValueType(jBaseType), jDepth);
+        }
+
+    private:
+        SimulatorResourceModel::ValueType getValueType(jobject jValueType)
+        {
+            static jmethodID ordinalMID = m_env->GetMethodID(
+                                              gSimulatorClassRefs.attributeValueTypeCls, "ordinal", "()I");
+
+            int ordinal = m_env->CallIntMethod(jValueType, ordinalMID);
+            return SimulatorResourceModel::ValueType(ordinal);
+        }
+
+        JNIEnv *m_env;
+};
+
+class ValueConverterJava : public boost::static_visitor<jobject>
 {
-    JSimulatorResourceModel *resource = GetHandle<JSimulatorResourceModel>(env, thiz);
-    if (env->ExceptionCheck())
-    {
-        return nullptr;
-    }
-
-    if (nullptr != resource->m_resModelPtr)
-        return resource->m_resModelPtr;
-    return nullptr;
-}
-
-jobject JSimulatorResourceModel::toJava(JNIEnv *env, jlong nativeHandle)
+    public:
+        ValueConverterJava(JNIEnv *env) : m_env(env) {}
+
+        jobject operator ()(const int &value)
+        {
+            static jmethodID integerCtor =
+                m_env->GetMethodID(gSimulatorClassRefs.integerCls, "<init>", "(I)V");
+            return m_env->NewObject(gSimulatorClassRefs.integerCls,
+                                    integerCtor, value);
+        }
+
+        jobject operator ()(const double &value)
+        {
+            static jmethodID doubleCtor =
+                m_env->GetMethodID(gSimulatorClassRefs.doubleCls, "<init>", "(D)V");
+            return m_env->NewObject(gSimulatorClassRefs.doubleCls,
+                                    doubleCtor, value);
+        }
+
+        jobject operator ()(const bool &value)
+        {
+            static jmethodID booleanCtor =
+                m_env->GetMethodID(gSimulatorClassRefs.booleanCls, "<init>", "(Z)V");
+            return m_env->NewObject(gSimulatorClassRefs.booleanCls,
+                                    booleanCtor, value);
+        }
+
+        jobject operator ()(const std::string &value)
+        {
+            jstring stringValue = m_env->NewStringUTF(value.c_str());
+            return static_cast<jobject>(stringValue);
+        }
+
+        jobject operator ()(const SimulatorResourceModel &value)
+        {
+            return simulatorResourceModelToJava(m_env, const_cast<SimulatorResourceModel &>(value));
+        }
+
+        template <typename T>
+        jobject operator ()(const std::vector<T> &values)
+        {
+            jobjectArray jArray = m_env->NewObjectArray(values.size(), getClass(values), nullptr);
+            if (!jArray)
+                return nullptr;
+
+            for (size_t index = 0; index < values.size(); index++)
+            {
+                jobject element = operator()(values[index]);
+                m_env->SetObjectArrayElement(jArray, index, element);
+            }
+
+            return jArray;
+        }
+
+        template <typename T>
+        jobject operator ()(const std::vector<std::vector<T>> &values)
+        {
+            jobjectArray jArray = m_env->NewObjectArray(values.size(), getClass(values), nullptr);
+            if (!jArray)
+                return nullptr;
+
+            for (size_t index = 0; index < values.size(); index++)
+            {
+                jobject element = operator()(values[index]);
+                m_env->SetObjectArrayElement(jArray, index, element);
+            }
+
+            return jArray;
+        }
+
+        template <typename T>
+        jobject operator ()(const std::vector<std::vector<std::vector<T>>> &values)
+        {
+            jobjectArray jArray = m_env->NewObjectArray(values.size(), getClass(values), nullptr);
+            if (!jArray)
+                return nullptr;
+
+            for (size_t index = 0; index < values.size(); index++)
+            {
+                jobject element = operator()(values[index]);
+                m_env->SetObjectArrayElement(jArray, index, element);
+            }
+
+            return jArray;
+        }
+
+    private:
+        jclass getClass(const std::vector<int> &)
+        {
+            return gSimulatorClassRefs.integer1DArrayCls;
+        }
+
+        jclass getClass(const std::vector<std::vector<int>> &)
+        {
+            return gSimulatorClassRefs.integer2DArrayCls;
+        }
+
+        jclass getClass(const std::vector<std::vector<std::vector<int>>> &)
+        {
+            return gSimulatorClassRefs.integer3DArrayCls;
+        }
+
+        jclass getClass(const std::vector<double> &)
+        {
+            return gSimulatorClassRefs.double1DArrayCls;
+        }
+
+        jclass getClass(const std::vector<std::vector<double>> &)
+        {
+            return gSimulatorClassRefs.double2DArrayCls;
+        }
+
+        jclass getClass(const std::vector<std::vector<std::vector<double>>> &)
+        {
+            return gSimulatorClassRefs.double3DArrayCls;
+        }
+
+        jclass getClass(const std::vector<bool> &)
+        {
+            return gSimulatorClassRefs.boolean1DArrayCls;
+        }
+
+        jclass getClass(const std::vector<std::vector<bool>> &)
+        {
+            return gSimulatorClassRefs.boolean2DArrayCls;
+        }
+
+        jclass getClass(const std::vector<std::vector<std::vector<bool>>> &)
+        {
+            return gSimulatorClassRefs.boolean3DArrayCls;
+        }
+
+        jclass getClass(const std::vector<std::string> &)
+        {
+            return gSimulatorClassRefs.string1DArrayCls;
+        }
+
+        jclass getClass(const std::vector<std::vector<std::string>> &)
+        {
+            return gSimulatorClassRefs.string2DArrayCls;
+        }
+
+        jclass getClass(const std::vector<std::vector<std::vector<std::string>>> &)
+        {
+            return gSimulatorClassRefs.string3DArrayCls;
+        }
+
+        jclass getClass(const std::vector<SimulatorResourceModel> &)
+        {
+            return gSimulatorClassRefs.simulatorResModel1DArrayCls;
+        }
+
+        jclass getClass(const std::vector<std::vector<SimulatorResourceModel>> &)
+        {
+            return gSimulatorClassRefs.simulatorResModel2DArrayCls;
+        }
+
+        jclass getClass(const std::vector<std::vector<std::vector<SimulatorResourceModel>>> &)
+        {
+            return gSimulatorClassRefs.simulatorResModel3DArrayCls;
+        }
+
+        JNIEnv *m_env;
+};
+
+class ValueConverterCpp
 {
-    jobject resourceObj = (jobject) env->NewObject(gSimulatorClassRefs.classSimulatorResourceModel,
-                          gSimulatorClassRefs.classSimulatorResourceModelCtor, nativeHandle);
-    if (!resourceObj)
-    {
-        return NULL;
-    }
-    return resourceObj;
-}
-
-void JSimulatorResourceModel::toJava(JNIEnv *env, jobject thiz, jlong nativeHandle)
+    public:
+        ValueConverterCpp(JNIEnv *env, SimulatorResourceModel::TypeInfo &typeInfo,
+                          jobject &value) : m_env(env), m_typeInfo(typeInfo), m_value(value) {}
+
+        void convert()
+        {
+            switch (m_typeInfo.baseType())
+            {
+                case SimulatorResourceModel::ValueType::INTEGER:
+                    return handleByDepth<int>();
+                case SimulatorResourceModel::ValueType::DOUBLE:
+                    return handleByDepth<double>();
+                case SimulatorResourceModel::ValueType::BOOLEAN:
+                    return handleByDepth<bool>();
+                case SimulatorResourceModel::ValueType::STRING:
+                    return handleByDepth<std::string>();
+                case SimulatorResourceModel::ValueType::RESOURCE_MODEL:
+                    return handleByDepth<SimulatorResourceModel>();
+                case SimulatorResourceModel::ValueType::VECTOR:
+                case SimulatorResourceModel::ValueType::UNKNOWN:
+                    break;
+            }
+        }
+
+        SimulatorResourceModel::ValueVariant get()
+        {
+            return std::move(m_result);
+        }
+
+    private:
+        template <typename T>
+        void handleByDepth()
+        {
+            if (0 == m_typeInfo.depth())
+            {
+                T value;
+                getValue(m_value, value);
+                m_result = value;
+            }
+            else if (1 == m_typeInfo.depth())
+            {
+                std::vector<T> value;
+                getValue(m_value, value);
+                m_result = value;
+            }
+            else if (2 == m_typeInfo.depth())
+            {
+                std::vector<std::vector<T>> value;
+                getValue(m_value, value);
+                m_result = value;
+            }
+            else if (3 == m_typeInfo.depth())
+            {
+                std::vector<std::vector<std::vector<T>>> value;
+                getValue(m_value, value);
+                m_result = value;
+            }
+        }
+
+        void getValue(jobject &jValue, int &value)
+        {
+            static jmethodID intValueMID = m_env->GetMethodID(
+                                               gSimulatorClassRefs.integerCls, "intValue", "()I");
+
+            jint temp = m_env->CallIntMethod(jValue, intValueMID);
+            value = temp;
+        }
+
+        void getValue(jobject &jValue, std::vector<int> &value)
+        {
+            jobjectArray array = (jobjectArray) jValue;
+            size_t length = m_env->GetArrayLength(array);
+            for (size_t i = 0; i < length; i++)
+            {
+                jobject jElement = m_env->GetObjectArrayElement(array, i);
+
+                int element;
+                getValue(jElement, element);
+                value.push_back(element);
+            }
+        }
+
+        void getValue(jobject &jValue, std::vector<std::vector<int>> &value)
+        {
+            jobjectArray array = (jobjectArray) jValue;
+            size_t length = m_env->GetArrayLength(array);
+            for (size_t i = 0; i < length; i++)
+            {
+                jobject jElement = m_env->GetObjectArrayElement(array, i);
+
+                std::vector<int> element;
+                getValue(jElement, element);
+                value.push_back(element);
+            }
+        }
+
+        void getValue(jobject &jValue, std::vector<std::vector<std::vector<int>>> &value)
+        {
+            jobjectArray array = (jobjectArray) jValue;
+            size_t length = m_env->GetArrayLength(array);
+            for (size_t i = 0; i < length; i++)
+            {
+                jobject jElement = m_env->GetObjectArrayElement(array, i);
+
+                std::vector<std::vector<int>> element;
+                getValue(jElement, element);
+                value.push_back(element);
+            }
+        }
+
+        void getValue(jobject &jValue, double &value)
+        {
+            static jmethodID doubleValueMID = m_env->GetMethodID(
+                                                  gSimulatorClassRefs.doubleCls, "doubleValue", "()D");
+
+            value = m_env->CallDoubleMethod(jValue, doubleValueMID);
+        }
+
+        void getValue(jobject &jValue, std::vector<double> &value)
+        {
+            jobjectArray array = (jobjectArray) jValue;
+            size_t length = m_env->GetArrayLength(array);
+            for (size_t i = 0; i < length; i++)
+            {
+                jobject jElement = m_env->GetObjectArrayElement(array, i);
+
+                double element;
+                getValue(jElement, element);
+                value.push_back(element);
+            }
+        }
+
+        void getValue(jobject &jValue, std::vector<std::vector<double>> &value)
+        {
+            jobjectArray array = (jobjectArray) jValue;
+            size_t length = m_env->GetArrayLength(array);
+            for (size_t i = 0; i < length; i++)
+            {
+                jobject jElement = m_env->GetObjectArrayElement(array, i);
+
+                std::vector<double> element;
+                getValue(jElement, element);
+                value.push_back(element);
+            }
+        }
+
+        void getValue(jobject &jValue, std::vector<std::vector<std::vector<double>>> &value)
+        {
+            jobjectArray array = (jobjectArray) jValue;
+            size_t length = m_env->GetArrayLength(array);
+            for (size_t i = 0; i < length; i++)
+            {
+                jobject jElement = m_env->GetObjectArrayElement(array, i);
+
+                std::vector<std::vector<double>> element;
+                getValue(jElement, element);
+                value.push_back(element);
+            }
+        }
+
+        void getValue(jobject &jValue, bool &value)
+        {
+            static jmethodID boolValueMID = m_env->GetMethodID(
+                                                gSimulatorClassRefs.booleanCls, "booleanValue", "()Z");
+
+            value = m_env->CallBooleanMethod(jValue, boolValueMID);
+        }
+
+        void getValue(jobject &jValue, std::vector<bool> &value)
+        {
+            jobjectArray array = (jobjectArray) jValue;
+            size_t length = m_env->GetArrayLength(array);
+            for (size_t i = 0; i < length; i++)
+            {
+                jobject jElement = m_env->GetObjectArrayElement(array, i);
+
+                bool element;
+                getValue(jElement, element);
+                value.push_back(element);
+            }
+        }
+
+        void getValue(jobject &jValue, std::vector<std::vector<bool>> &value)
+        {
+            jobjectArray array = (jobjectArray) jValue;
+            size_t length = m_env->GetArrayLength(array);
+            for (size_t i = 0; i < length; i++)
+            {
+                jobject jElement = m_env->GetObjectArrayElement(array, i);
+
+                std::vector<bool> element;
+                getValue(jElement, element);
+                value.push_back(element);
+            }
+        }
+
+        void getValue(jobject &jValue, std::vector<std::vector<std::vector<bool>>> &value)
+        {
+            jobjectArray array = (jobjectArray) jValue;
+            size_t length = m_env->GetArrayLength(array);
+            for (size_t i = 0; i < length; i++)
+            {
+                jobject jElement = m_env->GetObjectArrayElement(array, i);
+
+                std::vector<std::vector<bool>> element;
+                getValue(jElement, element);
+                value.push_back(element);
+            }
+        }
+
+        void getValue(jobject &jValue, std::string &value)
+        {
+            jstring stringValue = (jstring) jValue;
+            JniString jniValue(m_env, stringValue);
+            value = jniValue.get();
+        }
+
+        void getValue(jobject jValue, std::vector<std::string> &value)
+        {
+            jobjectArray array = (jobjectArray) jValue;
+            size_t length = m_env->GetArrayLength(array);
+            for (size_t i = 0; i < length; i++)
+            {
+                jobject jElement = m_env->GetObjectArrayElement(array, i);
+
+                std::string element;
+                getValue(jElement, element);
+                value.push_back(element);
+            }
+        }
+
+        void getValue(jobject &jValue, std::vector<std::vector<std::string>> &value)
+        {
+            jobjectArray array = (jobjectArray) jValue;
+            size_t length = m_env->GetArrayLength(array);
+            for (size_t i = 0; i < length; i++)
+            {
+                jobject jElement = m_env->GetObjectArrayElement(array, i);
+
+                std::vector<std::string> element;
+                getValue(jElement, element);
+                value.push_back(element);
+            }
+        }
+
+        void getValue(jobject &jValue, std::vector<std::vector<std::vector<std::string>>> &value)
+        {
+            jobjectArray array = (jobjectArray) jValue;
+            size_t length = m_env->GetArrayLength(array);
+            for (size_t i = 0; i < length; i++)
+            {
+                jobject jElement = m_env->GetObjectArrayElement(array, i);
+
+                std::vector<std::vector<std::string>> element;
+                getValue(jElement, element);
+                value.push_back(element);
+            }
+        }
+
+        void getValue(jobject &jValue, SimulatorResourceModel &value)
+        {
+        }
+
+        void getValue(jobject &jValue, std::vector<SimulatorResourceModel> &value)
+        {
+        }
+
+        void getValue(jobject &jValue, std::vector<std::vector<SimulatorResourceModel>> &value)
+        {
+        }
+
+        void getValue(jobject &jValue, std::vector<std::vector<std::vector<SimulatorResourceModel>>> &value)
+        {
+        }
+
+        JNIEnv *m_env;
+        SimulatorResourceModel::TypeInfo &m_typeInfo;
+        jobject &m_value;
+        SimulatorResourceModel::ValueVariant m_result;
+};
+
+class JniAttributeValue
 {
-    if (env && thiz && nativeHandle)
-    {
-        env->SetLongField(thiz, GetHandleField(env, thiz), nativeHandle);
-    }
-}
+    public:
+        static jobject toJava(JNIEnv *env, SimulatorResourceModel::Attribute &attribute)
+        {
+            auto value = attribute.getValue();
+            return toJava(env, value);
+        }
+
+        static jobject toJava(JNIEnv *env, SimulatorResourceModel::ValueVariant &value)
+        {
+            ValueConverterJava converter(env);
+            jobject jValue =  boost::apply_visitor(converter, value);
+
+            static jmethodID attrValueCtor = env->GetMethodID(
+                                                 gSimulatorClassRefs.attributeValueCls, "<init>", "(Ljava/lang/Object;)V");
+
+            return env->NewObject(gSimulatorClassRefs.attributeValueCls, attrValueCtor, jValue);
+        }
+
+        static SimulatorResourceModel::ValueVariant toCpp(JNIEnv *env, jobject &jAttributeValue)
+        {
+            static jmethodID getMID = env->GetMethodID(gSimulatorClassRefs.attributeValueCls,
+                                      "get", "()Ljava/lang/Object;");
+
+            SimulatorResourceModel::TypeInfo typeInfo = JniTypeInfo(env).toCpp(jAttributeValue);
+            jobject jValue = env->CallObjectMethod(jAttributeValue, getMID);
+
+            ValueConverterCpp converter(env, typeInfo, jValue);
+            converter.convert();
+            return converter.get();
+        }
+};
+
+class JniAttributeProperty
+{
+    public:
+        static jobject toJava(JNIEnv *env,
+                              SimulatorResourceModel::AttributeProperty &property)
+        {
+            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());
+            }
+            else
+            {
+                static jmethodID propertyCtor = env->GetMethodID(
+                                                    gSimulatorClassRefs.attributePropertyCls, "<init>", "([Lorg/oic/simulator/AttributeValue;)V");
+
+                jobjectArray jValueSet = env->NewObjectArray(property.valueSetSize(),
+                                         gSimulatorClassRefs.attributeValueCls, nullptr);
+                int index = 0;
+                for (auto &value : property.valueSet())
+                {
+                    jobject jValue = JniAttributeValue::toJava(env, value);
+                    env->SetObjectArrayElement(jValueSet, index++, jValue);
+                }
+
+                return env->NewObject(gSimulatorClassRefs.attributePropertyCls, propertyCtor,
+                                      jValueSet);
+            }
+
+            return nullptr;
+        }
+
+        static SimulatorResourceModel::AttributeProperty toCpp(JNIEnv *env, jobject jAttributeProperty)
+        {
+            static jfieldID typeFID = env->GetFieldID(gSimulatorClassRefs.attributePropertyCls,
+                                      "mType", "Lorg/oic/simulator/AttributeProperty$Type;");
+            static jfieldID minFID = env->GetFieldID(gSimulatorClassRefs.attributePropertyCls,
+                                     "mMin", "D");
+            static jfieldID maxFID = env->GetFieldID(gSimulatorClassRefs.attributePropertyCls,
+                                     "mMax", "D");
+            static jfieldID valueSetFID = env->GetFieldID(gSimulatorClassRefs.attributePropertyCls,
+                                          "mValueSet", "[Lorg/oic/simulator/AttributeValue;");
+            static jmethodID ordinalMID = env->GetMethodID(
+                                              gSimulatorClassRefs.attributePropertyTypeCls, "ordinal", "()I");
+
+            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);
+
+            int ordinal = env->CallIntMethod(jType, ordinalMID);
+            switch (SimulatorResourceModel::AttributeProperty::Type(ordinal))
+            {
+                case SimulatorResourceModel::AttributeProperty::Type::RANGE:
+                    {
+                        return SimulatorResourceModel::AttributeProperty(jMin, jMax);
+                    }
+
+                case SimulatorResourceModel::AttributeProperty::Type::VALUE_SET:
+                    {
+                        std::vector<SimulatorResourceModel::ValueVariant> valueSet;
+                        size_t length = env->GetArrayLength(jValueSet);
+                        for (size_t i = 0; i < length; i++)
+                        {
+                            jobject jAttributeValue = env->GetObjectArrayElement(jValueSet, i);
+                            valueSet.push_back(JniAttributeValue::toCpp(env, jAttributeValue));
+                        }
+
+                        return SimulatorResourceModel::AttributeProperty(valueSet);
+                    }
+            }
+
+            return SimulatorResourceModel::AttributeProperty();
+        }
+};
 
 static jobject createHashMap(JNIEnv *env)
 {
-    jobject mapobj = env->NewObject(gSimulatorClassRefs.classHashMap,
-                                    gSimulatorClassRefs.classHashMapCtor);
-    return mapobj;
+    static jmethodID hashMapCtor = env->GetMethodID(
+                                       gSimulatorClassRefs.hashMapCls, "<init>", "()V");
+    return env->NewObject(gSimulatorClassRefs.hashMapCls, hashMapCtor);
 }
 
 static void addEntryToHashMap(JNIEnv *env, jobject mapobj, jobject key, jobject value)
 {
     if (!mapobj || !key || !value)
-    {
         return;
-    }
 
-    env->CallObjectMethod(mapobj, gSimulatorClassRefs.classHashMapPut, key, value);
-}
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_SimulatorResourceModel_create
-(JNIEnv *env, jobject thiz)
-{
-    SimulatorResourceModelSP resModel = std::make_shared<SimulatorResourceModel>();
-    JSimulatorResourceModel *jresModel = new JSimulatorResourceModel(resModel);
-    JSimulatorResourceModel::toJava(env, thiz, reinterpret_cast<jlong>(jresModel));
+    static jmethodID hashMapPutMethod = env->GetMethodID(gSimulatorClassRefs.hashMapCls,
+                                        "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
+    env->CallObjectMethod(mapobj, hashMapPutMethod, key, value);
 }
 
-JNIEXPORT jint JNICALL
-Java_org_oic_simulator_SimulatorResourceModel_size
-(JNIEnv *env, jobject thiz)
+jobject simulatorResourceModelToJava(JNIEnv *env, SimulatorResourceModel &resModel)
 {
-    SimulatorResourceModel resourceModel;
-    bool result = JSimulatorResourceModel::getResourceModel(env, thiz, resourceModel);
-    if (!result)
-    {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "Resource model not found!");
-        return SIMULATOR_BAD_OBJECT;
-    }
-
-    return resourceModel.size();
-}
-
-JNIEXPORT jobject JNICALL
-Java_org_oic_simulator_SimulatorResourceModel_getAttributes
-(JNIEnv *env, jobject thiz)
-{
-    SimulatorResourceModel resourceModel;
-    bool result = JSimulatorResourceModel::getResourceModel(env, thiz, resourceModel);
-    if (!result)
-    {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "Resource model not found!");
+    jobject attributesMap = createHashMap(env);
+    jobject propertiesMap = createHashMap(env);
+    if (!attributesMap || !propertiesMap)
         return nullptr;
-    }
 
-    map<string, SimulatorResourceModel::Attribute> attributesMap = resourceModel.getAttributes();
-
-    // Create Java HashMap object
-    jobject jHashMap = NULL;
-    jHashMap = createHashMap(env);
-    if (!jHashMap)
+    for (auto &attributeEntry : resModel.getAttributes())
     {
-        throwSimulatorException(env, SIMULATOR_ERROR, "Java map creation failed!");
-        return nullptr;
-    }
-
-    for (auto & attributeEntry : attributesMap)
-    {
-        SimulatorResourceModel::Attribute attribute(attributeEntry.second);
-
-        // Create a object of ResourceAttribute java class
-        JResourceAttributeConverter converter(attribute);
-        jobject jAttribute = converter.toJava(env);
-
-        // Add an entry with attribute.first and javaSimualatorResourceAttribute to the HashMap
         jstring jAttrName = env->NewStringUTF((attributeEntry.first).c_str());
-        addEntryToHashMap(env, jHashMap, static_cast<jobject>(jAttrName), jAttribute);
-        env->DeleteLocalRef(jAttrName);
-    }
-
-    return jHashMap;
-}
-
-JNIEXPORT jobject JNICALL
-Java_org_oic_simulator_SimulatorResourceModel_getAttribute
-(JNIEnv *env, jobject thiz, jstring jAttrName)
-{
-    if (!jAttrName)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM, "Invalid attribute name!");
-        return nullptr;
-    }
-
-    const char *attrName = env->GetStringUTFChars(jAttrName, NULL);
-    if (!attrName)
-    {
-        throwSimulatorException(env, SIMULATOR_ERROR, "String error!");
-        return nullptr;
-    }
-
-    SimulatorResourceModel resourceModel;
-    bool result = JSimulatorResourceModel::getResourceModel(env, thiz, resourceModel);
-    if (!result)
-    {
-        env->ReleaseStringUTFChars(jAttrName, attrName);
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "Resource model not found!");
-        return nullptr;
-    }
+        jobject jAttributeValue = JniAttributeValue::toJava(env, attributeEntry.second);
+        addEntryToHashMap(env, attributesMap, jAttrName, jAttributeValue);
 
-    SimulatorResourceModel::Attribute attribute;
-    bool found = resourceModel.getAttribute(attrName, attribute);
-    if (!found)
-    {
-        env->ReleaseStringUTFChars(jAttrName, attrName);
-        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM, "Attribute does not exist!");
-        return nullptr;
+        jobject jAttributeProperty = JniAttributeProperty::toJava(env, attributeEntry.second.getProperty());
+        addEntryToHashMap(env, propertiesMap, jAttrName, jAttributeProperty);
     }
 
-    env->ReleaseStringUTFChars(jAttrName, attrName);
+    static jmethodID simulatorResourceModelCtor = env->GetMethodID(
+                gSimulatorClassRefs.simulatorResourceModelCls, "<init>", "(Ljava/util/Map;Ljava/util/Map;)V");
 
-    // Create a object of ResourceAttribute java class
-    JResourceAttributeConverter converter(attribute);
-    return converter.toJava(env);
+    return env->NewObject(gSimulatorClassRefs.simulatorResourceModelCls,
+                          simulatorResourceModelCtor, attributesMap, propertiesMap);
 }
 
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_SimulatorResourceModel_addAttributeInt
-(JNIEnv *env, jobject thiz, jstring jname, jint jvalue)
+jobject simulatorResourceAttributeToJava(JNIEnv *env, SimulatorResourceModel::Attribute &attribute)
 {
-    if (!jname)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM, "Invalid attribute name!");
-        return;
-    }
-
-    SimulatorResourceModelSP resModelPtr;
-    resModelPtr = JSimulatorResourceModel::getResourceModelPtr(env, thiz);
-    if (!resModelPtr)
-    {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "Resource model not found!");
-        return;
-    }
-
-    const char *nameCstr = env->GetStringUTFChars(jname, NULL);
-    if (!nameCstr)
-    {
-        throwSimulatorException(env, SIMULATOR_ERROR, "String error!");
-        return;
-    }
+    static jmethodID simulatorResAttributeCtor = env->GetMethodID(
+                gSimulatorClassRefs.simulatorResourceAttributeCls, "<init>",
+                "(Ljava/lang/String;Lorg/oic/simulator/AttributeValue;Lorg/oic/simulator/AttributeProperty;)V");
 
-    std::string attrName(nameCstr);
-    int value = static_cast<int>(jvalue);
-    resModelPtr->addAttribute(attrName, value);
+    jstring jAttrName = env->NewStringUTF(attribute.getName().c_str());
+    jobject jAttributeValue = JniAttributeValue::toJava(env, attribute);
+    jobject jAttributeProperty = JniAttributeProperty::toJava(env, attribute.getProperty());
 
-    // Release created c string
-    env->ReleaseStringUTFChars(jname, nameCstr);
+    return env->NewObject(gSimulatorClassRefs.simulatorResourceAttributeCls,
+                          simulatorResAttributeCtor, jAttrName, jAttributeValue, jAttributeProperty);
 }
 
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_SimulatorResourceModel_addAttributeDouble
-(JNIEnv *env, jobject thiz, jstring jname, jdouble jvalue)
+bool simulatorResourceModelToCpp(JNIEnv *env, jobject jResModel, SimulatorResourceModel &resModel)
 {
-    if (!jname)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM, "Invalid attribute name!");
-        return;
-    }
+    if (!jResModel)
+        return false;
 
-    SimulatorResourceModelSP resModelPtr;
-    resModelPtr = JSimulatorResourceModel::getResourceModelPtr(env, thiz);
-    if (!resModelPtr)
+    static jfieldID valuesFID = env->GetFieldID(gSimulatorClassRefs.simulatorResourceModelCls,
+                                "mValues", "Ljava/util/Map;");
+    static jfieldID propertiesFID = env->GetFieldID(gSimulatorClassRefs.simulatorResourceModelCls,
+                                    "mProperties", "Ljava/util/Map;");
+    static jmethodID entrySetMID = env->GetMethodID(gSimulatorClassRefs.mapCls, "entrySet",
+                                   "()Ljava/util/Set;");
+    static jmethodID iteratorMID = env->GetMethodID(gSimulatorClassRefs.setCls, "iterator",
+                                   "()Ljava/util/Iterator;");
+    static jmethodID hasNextMID = env->GetMethodID(gSimulatorClassRefs.iteratorCls, "hasNext",
+                                  "()Z");
+    static jmethodID nextMID = env->GetMethodID(gSimulatorClassRefs.iteratorCls, "next",
+                               "()Ljava/lang/Object;");
+    static jmethodID getKeyMID = env->GetMethodID(gSimulatorClassRefs.mapEntryCls, "getKey",
+                                 "()Ljava/lang/Object;");
+    static jmethodID getValueMID = env->GetMethodID(gSimulatorClassRefs.mapEntryCls, "getValue",
+                                   "()Ljava/lang/Object;");
+
+    jobject jValues = env->GetObjectField(jResModel, valuesFID);
+    jobject jProperties = env->GetObjectField(jResModel, propertiesFID);
+
+    if (jValues)
     {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "Resource model not found!");
-        return;
+        jobject entrySet = env->CallObjectMethod(jValues, entrySetMID);
+        jobject iterator = env->CallObjectMethod(entrySet, iteratorMID);
+        if (entrySet && iterator)
+        {
+            while (env->CallBooleanMethod(iterator, hasNextMID))
+            {
+                jobject entry = env->CallObjectMethod(iterator, nextMID);
+                jstring key = (jstring) env->CallObjectMethod(entry, getKeyMID);
+                jobject value = env->CallObjectMethod(entry, getValueMID);
+                resModel.add(JniString(env, key).get(), JniAttributeValue::toCpp(env, value));
+
+                env->DeleteLocalRef(entry);
+                env->DeleteLocalRef(key);
+                env->DeleteLocalRef(value);
+            }
+        }
     }
 
-    const char *nameCstr = env->GetStringUTFChars(jname, NULL);
-    if (!nameCstr)
+    if (jProperties)
     {
-        throwSimulatorException(env, SIMULATOR_ERROR, "String error!");
-        return;
+        jobject entrySet = env->CallObjectMethod(jProperties, entrySetMID);
+        jobject iterator = env->CallObjectMethod(entrySet, iteratorMID);
+        if (entrySet && iterator)
+        {
+            while (env->CallBooleanMethod(iterator, hasNextMID))
+            {
+                jobject entry = env->CallObjectMethod(iterator, nextMID);
+                jstring key = (jstring) env->CallObjectMethod(entry, getKeyMID);
+                jobject value = env->CallObjectMethod(entry, getValueMID);
+                resModel.setAttributeProperty(JniString(env, key).get(),
+                                              JniAttributeProperty::toCpp(env, value));
+
+                env->DeleteLocalRef(entry);
+                env->DeleteLocalRef(key);
+                env->DeleteLocalRef(value);
+            }
+        }
     }
 
-    std::string attrName(nameCstr);
-    double value = static_cast<double>(jvalue);
-    resModelPtr->addAttribute(attrName, value);
-
-    // Release created c string
-    env->ReleaseStringUTFChars(jname, nameCstr);
+    return true;
 }
 
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_SimulatorResourceModel_addAttributeBoolean
-(JNIEnv *env, jobject thiz, jstring jname, jboolean jvalue)
+bool simulatorResourceAttributeToCpp(JNIEnv *env, jobject jAttribute,
+                                     SimulatorResourceModel::Attribute &attribute)
 {
-    if (!jname)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM, "Invalid attribute name!");
-        return;
-    }
-
-    SimulatorResourceModelSP resModelPtr;
-    resModelPtr = JSimulatorResourceModel::getResourceModelPtr(env, thiz);
-    if (!resModelPtr)
-    {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "Resource model not found!");
-        return;
-    }
-
-    const char *nameCstr = env->GetStringUTFChars(jname, NULL);
-    if (!nameCstr)
-    {
-        throwSimulatorException(env, SIMULATOR_ERROR, "String error!");
-        return;
-    }
-
-    std::string attrName(nameCstr);
-    bool value = static_cast<bool>(jvalue);
-    resModelPtr->addAttribute(attrName, value);
+    if (!jAttribute)
+        return false;
 
-    // Release created c string
-    env->ReleaseStringUTFChars(jname, nameCstr);
-}
+    static jfieldID nameFID = env->GetFieldID(gSimulatorClassRefs.simulatorResourceAttributeCls,
+                              "mName", "Ljava/lang/String;");
+    static jfieldID valueFID = env->GetFieldID(gSimulatorClassRefs.simulatorResourceAttributeCls,
+                               "mValue", "Lorg/oic/simulator/AttributeValue;");
+    static jfieldID propertyFID = env->GetFieldID(gSimulatorClassRefs.simulatorResourceAttributeCls,
+                                  "mProperty", "Lorg/oic/simulator/AttributeProperty;");
 
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_SimulatorResourceModel_addAttributeString
-(JNIEnv *env, jobject thiz, jstring jname, jstring jvalue)
-{
-    if (!jname)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM, "Invalid attribute name!");
-        return;
-    }
-
-    if (!jvalue)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM, "Attribute value cannot be null!");
-        return;
-    }
+    jstring jAttributeName = (jstring) env->GetObjectField(jAttribute, nameFID);
+    jobject jAttributeValue = env->GetObjectField(jAttribute, valueFID);
+    jobject jAttributeProperty = env->GetObjectField(jAttribute, propertyFID);
 
-    SimulatorResourceModelSP resModelPtr;
-    resModelPtr = JSimulatorResourceModel::getResourceModelPtr(env, thiz);
-    if (!resModelPtr)
-    {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "Resource model not found!");
-        return;
-    }
+    if (!jAttributeName || !jAttributeValue)
+        return false;
 
-    const char *nameCstr = env->GetStringUTFChars(jname, NULL);
-    if (!nameCstr)
-    {
-        throwSimulatorException(env, SIMULATOR_ERROR, "String error!");
-        return;
-    }
+    JniString attrName(env, jAttributeName);
+    SimulatorResourceModel::ValueVariant value = JniAttributeValue::toCpp(env, jAttributeValue);
 
-    const char *valueCstr = env->GetStringUTFChars(jvalue, NULL);
-    if (!valueCstr)
+    attribute.setName(attrName.get());
+    attribute.setValue(value);
+    if (jAttributeProperty)
     {
-        env->ReleaseStringUTFChars(jname, nameCstr);
-        throwSimulatorException(env, SIMULATOR_ERROR, "String error!");
-        return;
+        SimulatorResourceModel::AttributeProperty property = JniAttributeProperty::toCpp(env,
+                jAttributeProperty);
+        attribute.setProperty(property);
     }
 
-    std::string attrName(nameCstr);
-    std::string value(valueCstr);
-    resModelPtr->addAttribute(attrName, value);
-
-    // Release created c string
-    env->ReleaseStringUTFChars(jname, nameCstr);
-    env->ReleaseStringUTFChars(jvalue, valueCstr);
+    return true;
 }
 
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_SimulatorResourceModel_dispose
-(JNIEnv *env, jobject thiz)
+bool AttributeValueToCpp(JNIEnv *env, jobject jAttributeValue,
+                         SimulatorResourceModel::ValueVariant &value)
 {
-    JSimulatorResourceModel *resourceModel = GetHandle<JSimulatorResourceModel>(env, thiz);
-    delete resourceModel;
+    if (!jAttributeValue)
+        return false;
+
+    value = JniAttributeValue::toCpp(env, jAttributeValue);
+    return true;
 }
+
index 2e4d35d..ca23b3b 100644 (file)
 #include <jni.h>
 #include "simulator_resource_model.h"
 
-class JSimulatorResourceModel
-{
-    public:
-        JSimulatorResourceModel(SimulatorResourceModel resModel);
-        JSimulatorResourceModel(SimulatorResourceModelSP resModel);
-
-        static jobject toJava(JNIEnv *env, jlong nativeHandle);
-        static void toJava(JNIEnv *env, jobject thiz, jlong nativeHandle);
-        static bool getResourceModel(JNIEnv *env, jobject thiz, SimulatorResourceModel &resModel);
-        static SimulatorResourceModelSP getResourceModelPtr(JNIEnv *env, jobject thiz);
-
-    private:
-        SimulatorResourceModel m_resourceModel;
-        SimulatorResourceModelSP m_resModelPtr;
-};
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_SimulatorResourceModel_create
-(JNIEnv *, jobject);
-
-JNIEXPORT jint JNICALL
-Java_org_oic_simulator_SimulatorResourceModel_size
-(JNIEnv *, jobject);
-
-JNIEXPORT jobject JNICALL
-Java_org_oic_simulator_SimulatorResourceModel_getAttributes
-(JNIEnv *, jobject);
-
-JNIEXPORT jobject JNICALL
-Java_org_oic_simulator_SimulatorResourceModel_getAttribute
-(JNIEnv *, jobject, jstring);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_SimulatorResourceModel_addAttributeInt
-(JNIEnv *, jobject, jstring, jint);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_SimulatorResourceModel_addAttributeDouble
-(JNIEnv *, jobject, jstring, jdouble);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_SimulatorResourceModel_addAttributeBoolean
-(JNIEnv *, jobject, jstring, jboolean);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_SimulatorResourceModel_addAttributeString
-(JNIEnv *, jobject, jstring, jstring);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_SimulatorResourceModel_dispose
-(JNIEnv *, jobject);
-
-
-#ifdef __cplusplus
-}
-#endif
+jobject simulatorResourceModelToJava(JNIEnv *env, SimulatorResourceModel &resModel);
+jobject simulatorResourceAttributeToJava(JNIEnv *env, SimulatorResourceModel::Attribute &attribute);
+bool simulatorResourceModelToCpp(JNIEnv *env, jobject jResModel, SimulatorResourceModel &resModel);
+bool simulatorResourceAttributeToCpp(JNIEnv *env, jobject jAttribute,
+                                     SimulatorResourceModel::Attribute &attribute);
+bool AttributeValueToCpp(JNIEnv *env, jobject jAttributeValue,
+                         SimulatorResourceModel::ValueVariant &value);
 
 #endif
diff --git a/service/simulator/java/jni/simulator_resource_server_jni.cpp b/service/simulator/java/jni/simulator_resource_server_jni.cpp
deleted file mode 100644 (file)
index 209ef47..0000000
+++ /dev/null
@@ -1,840 +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.
- *
- ******************************************************************/
-
-#include "simulator_resource_server_jni.h"
-#include "simulator_resource_jni_util.h"
-#include "simulator_common_jni.h"
-#include "simulator_resource_model_jni.h"
-#include "simulator_jni_utils.h"
-#include "simulator_logger.h"
-#include "simulator_jni_utils.h"
-
-extern SimulatorClassRefs gSimulatorClassRefs;
-
-JniSimulatorResource::JniSimulatorResource(SimulatorResourceServerSP &resource)
-    : m_sharedResource(resource) {}
-
-SimulatorResourceServerSP JniSimulatorResource::getJniSimulatorResourceSP(JNIEnv *env,
-        jobject thiz)
-{
-    JniSimulatorResource *resource = GetHandle<JniSimulatorResource>(env, thiz);
-    if (env->ExceptionCheck())
-    {
-        return NULL;
-    }
-    return resource->m_sharedResource;
-}
-
-jobject JniSimulatorResource::toJava(JNIEnv *env, jlong resource)
-{
-    jobject resourceObj = (jobject) env->NewObject(gSimulatorClassRefs.classSimulatorResource,
-                          gSimulatorClassRefs.classSimulatorResourceCtor, resource);
-    if (NULL == resourceObj)
-    {
-        return NULL;
-    }
-    return resourceObj;
-}
-
-void JniSimulatorResource::setResourceInfo(JNIEnv *env, jobject jobj)
-{
-    if (!env || !jobj)
-        return;
-
-    std::string uri = m_sharedResource->getURI();
-    std::string resourceType = m_sharedResource->getResourceType();
-    std::string name = m_sharedResource->getName();
-    std::string interfaceType = m_sharedResource->getInterfaceType();
-
-    jfieldID fieldID = env->GetFieldID(gSimulatorClassRefs.classSimulatorResource, "resourceURI",
-                                       "Ljava/lang/String;");
-    jstring jUri = env->NewStringUTF(uri.c_str());
-    env->SetObjectField(jobj, fieldID, jUri);
-
-    fieldID = env->GetFieldID(gSimulatorClassRefs.classSimulatorResource, "resourceName",
-                              "Ljava/lang/String;");
-    jstring jName = env->NewStringUTF(name.c_str());
-    env->SetObjectField(jobj, fieldID, jName);
-
-    fieldID = env->GetFieldID(gSimulatorClassRefs.classSimulatorResource, "resourceType",
-                              "Ljava/lang/String;");
-    jstring jResourceType = env->NewStringUTF(resourceType.c_str());
-    env->SetObjectField(jobj, fieldID, jResourceType);
-
-    fieldID = env->GetFieldID(gSimulatorClassRefs.classSimulatorResource, "interfaceType",
-                              "Ljava/lang/String;");
-    jstring jInterfaceType = env->NewStringUTF(interfaceType.c_str());
-    env->SetObjectField(jobj, fieldID, jInterfaceType);
-
-    env->DeleteLocalRef(jUri);
-    env->DeleteLocalRef(jName);
-    env->DeleteLocalRef(jResourceType);
-    env->DeleteLocalRef(jInterfaceType);
-}
-
-void onAutomationComplete(jweak jlistenerRef, const std::string &uri,
-                          const int automationID)
-{
-    JNIEnv *env = getEnv();
-    if (nullptr == env)
-        return;
-
-    jobject autoCompleteListener = env->NewLocalRef(jlistenerRef);
-    if (!autoCompleteListener)
-    {
-        releaseEnv();
-        return;
-    }
-
-    jclass autoCompleteCls = env->GetObjectClass(autoCompleteListener);
-    if (!autoCompleteCls)
-    {
-        releaseEnv();
-        return;
-    }
-
-    jmethodID autoCompleteMId = env->GetMethodID(autoCompleteCls, "onAutomationComplete",
-                                "(Ljava/lang/String;I)V");
-    if (!autoCompleteMId)
-    {
-        releaseEnv();
-        return;
-    }
-
-    jstring jUri = env->NewStringUTF(uri.c_str());
-
-    env->CallVoidMethod(autoCompleteListener, autoCompleteMId, jUri, automationID);
-    if ((env)->ExceptionCheck())
-    {
-        releaseEnv();
-        return;
-    }
-
-    env->DeleteLocalRef(jUri);
-
-    releaseEnv();
-}
-
-JNIEXPORT jobject JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_getModel
-(JNIEnv *env, jobject object)
-{
-    SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env, object);
-    if (!resource)
-    {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
-        return nullptr;
-    }
-
-    SimulatorResourceModel resModel = resource->getModel();
-    JSimulatorResourceModel *model = new JSimulatorResourceModel(resModel);
-    jobject jModel = JSimulatorResourceModel::toJava(env, reinterpret_cast<jlong>(model));
-    return jModel;
-}
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_addAttributeInteger
-(JNIEnv *env, jobject jobject, jstring jKey, jint jValue)
-{
-    if (!jKey)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM, "Invalid Attribute name!");
-        return;
-    }
-
-    SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env,
-                                         jobject);
-    if (!resource)
-    {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
-        return;
-    }
-
-    std::string str = env->GetStringUTFChars(jKey, NULL);
-    SimulatorResourceModel::Attribute att;
-    att.setName(str);
-    att.setValue(static_cast<int>(jValue));
-    resource->addAttribute(att);
-}
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_addAttributeDouble
-(JNIEnv *env, jobject jobject, jstring jKey, jdouble jValue)
-{
-    if (!jKey)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM, "Invalid Attribute name!");
-        return;
-    }
-
-    SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env,
-                                         jobject);
-    if (!resource)
-    {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
-        return;
-    }
-
-    std::string str = env->GetStringUTFChars(jKey, NULL);
-    SimulatorResourceModel::Attribute att;
-    att.setName(str);
-    att.setValue(static_cast<double>(jValue));
-    resource->addAttribute(att);
-}
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_addAttributeBoolean
-(JNIEnv *env, jobject jobject, jstring jKey, jboolean jValue)
-{
-    if (!jKey)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM, "Invalid Attribute name!");
-        return;
-    }
-
-    SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env,
-                                         jobject);
-    if (!resource)
-    {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
-        return;
-    }
-
-    std::string str = env->GetStringUTFChars(jKey, NULL);
-    SimulatorResourceModel::Attribute att;
-    att.setName(str);
-    att.setValue(static_cast<bool>(jValue));
-    resource->addAttribute(att);
-}
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_addAttributeString
-(JNIEnv *env, jobject jobject, jstring jKey, jstring jValue)
-{
-    if (!jKey)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM, "Invalid Attribute name!");
-        return;
-    }
-
-    if (!jValue)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM, "Attribute value cannot be null!");
-        return;
-    }
-
-    SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env,
-                                         jobject);
-    if (!resource)
-    {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
-        return;
-    }
-
-    std::string key = env->GetStringUTFChars(jKey, NULL);
-    std::string value = env->GetStringUTFChars(jValue, NULL);
-    SimulatorResourceModel::Attribute att;
-    att.setName(key);
-    att.setValue(value);
-    resource->addAttribute(att);
-}
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_updateAttributeInteger
-(JNIEnv *env, jobject jobject, jstring jKey, jint jValue)
-{
-    if (!jKey)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM, "Invalid Attribute name!");
-        return;
-    }
-
-    SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env,
-                                         jobject);
-    if (!resource)
-    {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
-        return;
-    }
-
-    std::string str = env->GetStringUTFChars(jKey, NULL);
-    resource->updateAttributeValue(str, static_cast<int>(jValue));
-}
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_updateAttributeDouble
-(JNIEnv *env, jobject jobject, jstring jKey, jdouble jValue)
-{
-    if (!jKey)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM, "Invalid Attribute name!");
-        return;
-    }
-
-    SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env,
-                                         jobject);
-    if (!resource)
-    {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
-        return;
-    }
-
-    std::string str = env->GetStringUTFChars(jKey, NULL);
-    resource->updateAttributeValue(str, static_cast<double>(jValue));
-}
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_updateAttributeBoolean
-(JNIEnv *env, jobject jobject, jstring jKey, jboolean jValue)
-{
-    if (!jKey)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM, "Invalid Attribute name!");
-        return;
-    }
-
-    SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env,
-                                         jobject);
-    if (!resource)
-    {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
-        return;
-    }
-
-    std::string str = env->GetStringUTFChars(jKey, NULL);
-    resource->updateAttributeValue(str, static_cast<bool>(jValue));
-}
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_updateAttributeString
-(JNIEnv *env, jobject jobject, jstring jKey, jstring jValue)
-{
-    if (!jKey)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM, "Invalid Attribute name!");
-        return;
-    }
-
-    SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env,
-                                         jobject);
-    if (!resource)
-    {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
-        return;
-    }
-
-    std::string key = env->GetStringUTFChars(jKey, NULL);
-    std::string value = env->GetStringUTFChars(jValue, NULL);
-
-    resource->updateAttributeValue(key, value);
-}
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_updateAttributeFromAllowedValues
-(JNIEnv *env, jobject object, jstring attrName, jint index)
-{
-    if (!attrName || index < 0)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM, "Invalid parameter!");
-        return;
-    }
-
-    SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env, object);
-    if (!resource)
-    {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
-        return;
-    }
-
-    const char *attrNameCStr = env->GetStringUTFChars(attrName, NULL);
-    if (!attrNameCStr)
-    {
-        throwSimulatorException(env, SIMULATOR_ERROR, "String error!");
-        return;
-    }
-
-    resource->updateAttributeValue(attrNameCStr, static_cast<int>(index));
-    env->ReleaseStringUTFChars(attrName, attrNameCStr);
-}
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_setRange
-(JNIEnv *env, jobject object, jstring attrName, jint min, jint max)
-{
-    if (!attrName)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM, "Invalid parameter!");
-        return;
-    }
-
-    SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env, object);
-    if (!resource)
-    {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
-        return;
-    }
-
-    const char *attrNameCStr = env->GetStringUTFChars(attrName, NULL);
-    if (!attrNameCStr)
-    {
-        throwSimulatorException(env, SIMULATOR_ERROR, "String error!");
-        return;
-    }
-
-    resource->setRange(attrNameCStr, static_cast<int>(min), static_cast<int>(max));
-    env->ReleaseStringUTFChars(attrName, attrNameCStr);
-}
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_setAllowedValuesInteger
-(JNIEnv *env, jobject object, jstring jKey, jobject jAllowedValues)
-{
-    if (!jKey || !jAllowedValues)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM, "Invalid parameter!");
-        return;
-    }
-
-    SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env, object);
-    if (!resource)
-    {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
-        return;
-    }
-
-    const char *keyCStr = env->GetStringUTFChars(jKey, NULL);
-    if (!keyCStr)
-    {
-        throwSimulatorException(env, SIMULATOR_ERROR, "String error!");
-        return;
-    }
-
-    resource->setAllowedValues(keyCStr, convertIntegerVector(env, jAllowedValues));
-    env->ReleaseStringUTFChars(jKey, keyCStr);
-}
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_setAllowedValuesDouble
-(JNIEnv *env, jobject object, jstring jKey, jobject jAllowedValues)
-{
-    if (!jKey || !jAllowedValues)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM, "Invalid parameter!");
-        return;
-    }
-
-    SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env, object);
-    if (!resource)
-    {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
-        return;
-    }
-
-    const char *keyCStr = env->GetStringUTFChars(jKey, NULL);
-    if (!keyCStr)
-    {
-        throwSimulatorException(env, SIMULATOR_ERROR, "String error!");
-        return;
-    }
-
-    resource->setAllowedValues(keyCStr, convertDoubleVector(env, jAllowedValues));
-    env->ReleaseStringUTFChars(jKey, keyCStr);
-}
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_setAllowedValuesString
-(JNIEnv *env, jobject object, jstring jKey, jobject jAllowedValues)
-{
-    if (!jKey || !jAllowedValues)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM, "Invalid parameter!");
-        return;
-    }
-
-    SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env, object);
-    if (!resource)
-    {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
-        return;
-    }
-
-    const char *keyCStr = env->GetStringUTFChars(jKey, NULL);
-    if (!keyCStr)
-    {
-        throwSimulatorException(env, SIMULATOR_ERROR, "String error!");
-        return;
-    }
-
-    resource->setAllowedValues(keyCStr, convertStringVector(env, jAllowedValues));
-    env->ReleaseStringUTFChars(jKey, keyCStr);
-}
-
-JNIEXPORT jint JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_startResourceAutomation
-(JNIEnv *env, jobject object, jint automationType, jint updateInterval, jobject listener)
-{
-    SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env, object);
-    if (!resource)
-    {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
-        return SIMULATOR_BAD_OBJECT;
-    }
-
-    if (!listener)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_CALLBACK,
-                                  "Start Resource Automation failed! Callback not set");
-        return SIMULATOR_INVALID_CALLBACK;
-    }
-
-    jweak jlistenerRef = env->NewWeakGlobalRef(listener);
-    updateCompleteCallback callback =  [jlistenerRef](const std::string & uri, const int automationID)
-    {
-        onAutomationComplete(jlistenerRef, uri, automationID);
-    };
-
-    AutomationType type = AutomationType::NORMAL;
-    if (1 == automationType)
-    {
-        type = AutomationType::RECURRENT;
-    }
-
-    int automationId = -1;
-
-    try
-    {
-        automationId = resource->startUpdateAutomation(type, updateInterval, callback);
-    }
-    catch (InvalidArgsException &e)
-    {
-        throwInvalidArgsException(env, e.code(), e.what());
-    }
-    catch (SimulatorException &e)
-    {
-        throwSimulatorException(env, e.code(), e.what());
-    }
-    catch (...)
-    {
-        throwSimulatorException(env, SIMULATOR_ERROR, "Unknown Exception");
-    }
-    return automationId;
-}
-
-JNIEXPORT jint JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_startAttributeAutomation
-(JNIEnv *env, jobject object, jstring attrName, jint automationType, jint updateInterval, jobject listener)
-{
-    SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env, object);
-    if (!resource)
-    {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
-        return SIMULATOR_BAD_OBJECT;
-    }
-
-    if (!attrName)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM, "Invalid Attribute name!");
-        return SIMULATOR_INVALID_PARAM;
-    }
-
-    if (!listener)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_CALLBACK,
-                                  "Start Attribute Automation failed! Callback not set");
-        return SIMULATOR_INVALID_CALLBACK;
-    }
-
-    jweak jlistenerRef = env->NewWeakGlobalRef(listener);
-    updateCompleteCallback callback =  [jlistenerRef](const std::string & uri, const int automationID)
-    {
-        onAutomationComplete(jlistenerRef, uri, automationID);
-    };
-
-    const char *attrNamePtr = env->GetStringUTFChars(attrName, NULL);
-
-    AutomationType type = AutomationType::NORMAL;
-    if (1 == automationType)
-    {
-        type = AutomationType::RECURRENT;
-    }
-
-    int automationId = -1;
-    try
-    {
-        automationId = resource->startUpdateAutomation(attrNamePtr, type, updateInterval, callback);
-    }
-    catch (InvalidArgsException &e)
-    {
-        throwInvalidArgsException(env, e.code(), e.what());
-        return -1;
-    }
-    catch (SimulatorException &e)
-    {
-        throwSimulatorException(env, e.code(), e.what());
-        return -1;
-    }
-    catch (...)
-    {
-        throwSimulatorException(env, SIMULATOR_ERROR, "Unknown Exception");
-        return -1;
-    }
-    env->ReleaseStringUTFChars(attrName, attrNamePtr);
-    return automationId;
-}
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_stopAutomation
-(JNIEnv *env, jobject object, jint automationId)
-{
-    SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env, object);
-    if (!resource)
-    {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
-        return;
-    }
-
-    try
-    {
-        resource->stopUpdateAutomation(automationId);
-    }
-    catch (SimulatorException &e)
-    {
-        throwSimulatorException(env, e.code(), e.what());
-    }
-    catch (...)
-    {
-        throwSimulatorException(env, SIMULATOR_ERROR, "Unknown Exception");
-    }
-
-    SIM_LOG(ILogger::INFO, "Automation has been forcibly stopped.")
-}
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_removeAttribute
-(JNIEnv *env, jobject jobject, jstring jKey)
-{
-    if (!jKey)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM, "Invalid Attribute name!");
-        return;
-    }
-
-    SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env,
-                                         jobject);
-    if (!resource)
-    {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
-        return;
-    }
-
-    std::string str = env->GetStringUTFChars(jKey, NULL);
-    try
-    {
-        resource->removeAttribute(str);
-    }
-    catch (InvalidArgsException &e)
-    {
-        throwInvalidArgsException(env, e.code(), e.what());
-        return;
-    }
-    catch (SimulatorException &e)
-    {
-        throwSimulatorException(env, e.code(), e.what());
-        return;
-    }
-    catch (...)
-    {
-        throwSimulatorException(env, SIMULATOR_ERROR, "Unknown Exception");
-        return;
-    }
-}
-
-JNIEXPORT jobjectArray JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_getObserversList
-(JNIEnv *env, jobject object)
-{
-    SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env, object);
-    if (!resource)
-    {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
-        return nullptr;
-    }
-
-    std::vector<ObserverInfo> observersList;
-    observersList = resource->getObserversList();
-
-    // Construct the object array and send it java layer
-    jobjectArray jobserversArray = env->NewObjectArray(observersList.size(),
-                                   gSimulatorClassRefs.classObserverInfo, NULL);
-    if (jobserversArray)
-    {
-        for (size_t i = 0; i < observersList.size(); i++)
-        {
-            jstring jaddress = env->NewStringUTF(observersList[i].address.c_str());
-            jobject jobserver = (jobject) env->NewObject(gSimulatorClassRefs.classObserverInfo,
-                                gSimulatorClassRefs.classObserverInfoCtor, observersList[i].id,
-                                jaddress, observersList[i].port);
-
-            env->SetObjectArrayElement(jobserversArray, i, jobserver);
-            env->DeleteLocalRef(jaddress);
-        }
-    }
-
-    return jobserversArray;
-}
-
-void onObserverChange(jweak jlistenerRef, const std::string &uri,
-                      ObservationStatus state, const ObserverInfo &observerInfo)
-{
-    JNIEnv *env = getEnv();
-    if (nullptr == env)
-        return;
-
-    jobject observerChangeListener = env->NewLocalRef(jlistenerRef);
-    if (!observerChangeListener)
-    {
-        releaseEnv();
-        return;
-    }
-
-    jclass observerChangeCls = env->GetObjectClass(observerChangeListener);
-    if (!observerChangeCls)
-    {
-        releaseEnv();
-        return;
-    }
-
-    jmethodID observerChangeMId = env->GetMethodID(observerChangeCls, "onObserverChanged",
-                                  "(Ljava/lang/String;ILorg/oic/simulator/serviceprovider/ObserverInfo;)V");
-    if (!observerChangeMId)
-    {
-        releaseEnv();
-        return;
-    }
-
-    // Convert URI
-    jstring jUri = env->NewStringUTF(uri.c_str());
-
-    // Convert state
-    jint jstate = (state == ObservationStatus::OBSERVE_REGISTER) ? 0 : 1;
-
-    // Construct the java object of observerinfo
-    jstring jaddress = env->NewStringUTF(observerInfo.address.c_str());
-    jobject jobserver = (jobject) env->NewObject(gSimulatorClassRefs.classObserverInfo,
-                        gSimulatorClassRefs.classObserverInfoCtor, observerInfo.id,
-                        jaddress, observerInfo.port);
-
-    env->CallVoidMethod(observerChangeListener, observerChangeMId, jUri, jstate, jobserver);
-    env->DeleteLocalRef(jaddress);
-    if ((env)->ExceptionCheck())
-    {
-        releaseEnv();
-        return;
-    }
-
-    env->DeleteLocalRef(jUri);
-
-    releaseEnv();
-}
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_setObserverCallback
-(JNIEnv *env, jobject object, jobject jcallback)
-{
-    if (!jcallback)
-    {
-        throwInvalidArgsException(env, SIMULATOR_INVALID_CALLBACK, "Callback not set");
-        return;
-    }
-
-    jweak jlistenerRef = env->NewWeakGlobalRef(jcallback);
-    SimulatorResourceServer::ObserverCB callback =  [jlistenerRef](const std::string & uri,
-            ObservationStatus state, const ObserverInfo & observerInfo)
-    {
-        onObserverChange(jlistenerRef, uri, state, observerInfo);
-    };
-
-    SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env, object);
-    if (!resource)
-    {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
-        return;
-    }
-
-    resource->setObserverCallback(callback);
-}
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_notifyObserver
-(JNIEnv *env, jobject object, jint jId)
-{
-    SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env, object);
-    if (!resource)
-    {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
-        return;
-    }
-
-    try
-    {
-        resource->notify(jId);
-    }
-    catch (SimulatorException &e)
-    {
-        throwSimulatorException(env, e.code(), e.what());
-    }
-    catch (...)
-    {
-        throwSimulatorException(env, SIMULATOR_ERROR, "Unknown Exception");
-    }
-}
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_notifyAllObservers
-(JNIEnv *env, jobject object)
-{
-    SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env, object);
-    if (!resource)
-    {
-        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
-        return;
-    }
-
-    try
-    {
-        resource->notifyAll();
-    }
-    catch (SimulatorException &e)
-    {
-        throwSimulatorException(env, e.code(), e.what());
-    }
-    catch (...)
-    {
-        throwSimulatorException(env, SIMULATOR_ERROR, "Unknown Exception");
-    }
-}
-
-JNIEXPORT void JNICALL Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_dispose
-(JNIEnv *env, jobject thiz)
-{
-    JniSimulatorResource *resource = GetHandle<JniSimulatorResource>(env, thiz);
-    delete resource;
-}
-
diff --git a/service/simulator/java/jni/simulator_resource_server_jni.h b/service/simulator/java/jni/simulator_resource_server_jni.h
deleted file mode 100644 (file)
index 298071a..0000000
+++ /dev/null
@@ -1,137 +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.
- *
- ******************************************************************/
-
-#ifndef SIMULATOR_RESOURCE_JNI_H_
-#define SIMULATOR_RESOURCE_JNI_H_
-
-#include <jni.h>
-#include "simulator_resource_server.h"
-
-class JniSimulatorResource
-{
-    public:
-        JniSimulatorResource(SimulatorResourceServerSP &resource);
-
-        static jobject toJava(JNIEnv *env, jlong resource);
-        void setResourceInfo(JNIEnv *env, jobject jobj);
-        static SimulatorResourceServerSP getJniSimulatorResourceSP(JNIEnv *env, jobject thiz);
-    private:
-        SimulatorResourceServerSP m_sharedResource;
-};
-
-
-#ifdef __cplusplus
-extern "C" {
-
-JNIEXPORT jobject JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_getModel
-(JNIEnv *, jobject);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_addAttributeInteger
-(JNIEnv *, jobject, jstring, jint);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_addAttributeDouble
-(JNIEnv *, jobject, jstring, jdouble);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_addAttributeBoolean
-(JNIEnv *, jobject, jstring, jboolean);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_addAttributeString
-(JNIEnv *, jobject, jstring, jstring);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_updateAttributeInteger
-(JNIEnv *, jobject, jstring, jint);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_updateAttributeDouble
-(JNIEnv *, jobject, jstring, jdouble);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_updateAttributeBoolean
-(JNIEnv *, jobject, jstring, jboolean);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_updateAttributeString
-(JNIEnv *, jobject, jstring, jstring);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_updateAttributeFromAllowedValues
-(JNIEnv *, jobject, jstring, jint);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_setRange
-(JNIEnv *, jobject, jstring, jint, jint);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_setAllowedValuesInteger
-(JNIEnv *, jobject, jstring, jobject);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_setAllowedValuesDouble
-(JNIEnv *, jobject, jstring, jobject);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_setAllowedValuesString
-(JNIEnv *, jobject, jstring, jobject);
-
-JNIEXPORT jint JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_startResourceAutomation
-(JNIEnv *, jobject, jint, jint, jobject);
-
-JNIEXPORT jint JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_startAttributeAutomation
-(JNIEnv *, jobject, jstring, jint, jint, jobject);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_stopAutomation
-(JNIEnv *, jobject, jint);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_removeAttribute
-(JNIEnv *, jobject, jstring);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_setObserverCallback
-(JNIEnv *env, jobject object, jobject observer);
-
-JNIEXPORT jobjectArray JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_getObserversList
-(JNIEnv *env, jobject object);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_notifyObserver
-(JNIEnv *env, jobject object, jint jId);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_notifyAllObservers
-(JNIEnv *env, jobject object);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_dispose
-(JNIEnv *, jobject);
-
-}
-#endif
-#endif //SIMULATOR_RESOURCE_JNI_H_
diff --git a/service/simulator/java/jni/simulator_resource_utils_jni.cpp b/service/simulator/java/jni/simulator_resource_utils_jni.cpp
new file mode 100644 (file)
index 0000000..8a23727
--- /dev/null
@@ -0,0 +1,158 @@
+/******************************************************************
+ *
+ * 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.
+ *
+ ******************************************************************/
+
+#include "simulator_resource_utils_jni.h"
+#include "simulator_utils_jni.h"
+#include "jni_sharedobject_holder.h"
+#include "jni_vector.h"
+
+jobject createSingleResource(JNIEnv *env, SimulatorResourceSP singleResource)
+{
+    if (!singleResource)
+        return nullptr;
+
+    auto *objectHolder = JniSharedObjectHolder<SimulatorResource>::create(singleResource);
+    if (!objectHolder)
+        return nullptr;
+
+    static jmethodID simulatorSingleResourceCtor = env->GetMethodID(
+                gSimulatorClassRefs.simulatorSingleResourceCls, "<init>", "(J)V");
+
+    jobject resource = (jobject) env->NewObject(gSimulatorClassRefs.simulatorSingleResourceCls,
+                       simulatorSingleResourceCtor, reinterpret_cast<jlong>(objectHolder));
+    if (!resource)
+    {
+        delete objectHolder;
+        return nullptr;
+    }
+
+    return resource;
+}
+
+jobject createCollectionResource(JNIEnv *env, SimulatorResourceSP collectionResource)
+{
+    if (!collectionResource)
+        return nullptr;
+
+    auto *objectHolder = JniSharedObjectHolder<SimulatorResource>::create(collectionResource);
+    if (!objectHolder)
+        return nullptr;
+
+    static jmethodID simulatorCollectionResourceCtor = env->GetMethodID(
+                gSimulatorClassRefs.simulatorCollectionResourceCls, "<init>", "(J)V");
+    jobject resource = (jobject) env->NewObject(gSimulatorClassRefs.simulatorCollectionResourceCls,
+                       simulatorCollectionResourceCtor, reinterpret_cast<jlong>(objectHolder));
+    if (!resource)
+    {
+        delete objectHolder;
+        return nullptr;
+    }
+
+    return resource;
+}
+
+jobject createSimulatorResource(JNIEnv *env, SimulatorResourceSP resource)
+{
+    if (!resource)
+        return nullptr;
+
+    if (SimulatorResource::Type::COLLECTION_RESOURCE == resource->getType())
+        return createCollectionResource(env, resource);
+    return createSingleResource(env, resource);
+}
+
+jobject createSimulatorResourceVector(JNIEnv *env, std::vector<SimulatorResourceSP> &resources)
+{
+    if (!resources.size())
+        return nullptr;
+
+    jobject vectorObject = JniVector(env).toJava();
+    if (!vectorObject)
+        return nullptr;
+
+    static jmethodID addMethod = env->GetMethodID(gSimulatorClassRefs.vectorCls,
+                                 "add", "(Ljava/lang/Object;)Z");
+
+    for (auto &resource : resources)
+        env->CallBooleanMethod(vectorObject, addMethod, createSimulatorResource(env, resource));
+
+    return vectorObject;
+}
+
+jobject createSimulatorRemoteResource(JNIEnv *env, SimulatorRemoteResourceSP &remoteResource)
+{
+    if (!remoteResource)
+        return nullptr;
+
+    auto *objectHolder = JniSharedObjectHolder<SimulatorRemoteResource>::create(remoteResource);
+    if (!objectHolder)
+        return nullptr;
+
+    static jmethodID simulatorRemoteResourceCtor = env->GetMethodID(
+                gSimulatorClassRefs.simulatorRemoteResourceCls, "<init>", "(J)V");
+
+    jobject resource = (jobject) env->NewObject(gSimulatorClassRefs.simulatorRemoteResourceCls,
+                       simulatorRemoteResourceCtor, reinterpret_cast<jlong>(objectHolder));
+    if (!resource)
+    {
+        delete objectHolder;
+        return nullptr;
+    }
+
+    // Setting all required fields
+    static jfieldID uriID = env->GetFieldID(gSimulatorClassRefs.simulatorRemoteResourceCls,
+                                            "mUri", "Ljava/lang/String;");
+    static jfieldID connTypeID = env->GetFieldID(gSimulatorClassRefs.simulatorRemoteResourceCls,
+                                 "mConnType", "I");
+    static jfieldID hostID = env->GetFieldID(gSimulatorClassRefs.simulatorRemoteResourceCls,
+                             "mHost", "Ljava/lang/String;");
+    static jfieldID uidID = env->GetFieldID(gSimulatorClassRefs.simulatorRemoteResourceCls,
+                                            "mId", "Ljava/lang/String;");
+    static jfieldID resTypesID = env->GetFieldID(gSimulatorClassRefs.simulatorRemoteResourceCls,
+                                 "mResTypes", "Ljava/util/Vector;");
+    static jfieldID interfacesID = env->GetFieldID(gSimulatorClassRefs.simulatorRemoteResourceCls,
+                                   "mResInterfaces", "Ljava/util/Vector;");
+    static jfieldID isObservableID = env->GetFieldID(gSimulatorClassRefs.simulatorRemoteResourceCls,
+                                     "mIsObservable", "Z");
+
+    jstring uri = env->NewStringUTF(remoteResource->getURI().c_str());
+    env->SetObjectField(resource, uriID, uri);
+
+    jint connType = remoteResource->getConnectivityType();
+    env->SetIntField(resource, connTypeID, connType);
+
+    jstring host = env->NewStringUTF(remoteResource->getHost().c_str());
+    env->SetObjectField(resource, hostID, host);
+
+    jstring uid = env->NewStringUTF(remoteResource->getID().c_str());
+    env->SetObjectField(resource, uidID, uid);
+
+    std::vector<std::string> resourceTypes = remoteResource->getResourceTypes();
+    jobject ResTypes = JniVector(env).toJava(resourceTypes);
+    env->SetObjectField(resource, resTypesID, ResTypes);
+
+    std::vector<std::string> interfaceTypes = remoteResource->getResourceInterfaces();
+    jobject resInterfaces = JniVector(env).toJava(interfaceTypes);
+    env->SetObjectField(resource, interfacesID, resInterfaces);
+
+    env->SetBooleanField(resource, isObservableID, remoteResource->isObservable());
+
+    return resource;
+}
\ No newline at end of file
diff --git a/service/simulator/java/jni/simulator_resource_utils_jni.h b/service/simulator/java/jni/simulator_resource_utils_jni.h
new file mode 100644 (file)
index 0000000..bfcb1d6
--- /dev/null
@@ -0,0 +1,35 @@
+/******************************************************************
+ *
+ * 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.
+ *
+ ******************************************************************/
+
+#ifndef SIMULATOR_RESOURCE_UTILS_JNI_H_
+#define SIMULATOR_RESOURCE_UTILS_JNI_H_
+
+#include <jni.h>
+#include "simulator_single_resource.h"
+#include "simulator_collection_resource.h"
+#include "simulator_remote_resource.h"
+
+jobject createSingleResource(JNIEnv *env, SimulatorResourceSP singleResource);
+jobject createCollectionResource(JNIEnv *env, SimulatorResourceSP collectionResource);
+jobject createSimulatorResource(JNIEnv *env, SimulatorResourceSP resource);
+jobject createSimulatorResourceVector(JNIEnv *env, std::vector<SimulatorResourceSP> &resources);
+jobject createSimulatorRemoteResource(JNIEnv *env, SimulatorRemoteResourceSP &remoteResource);
+
+#endif
diff --git a/service/simulator/java/jni/simulator_single_resource_jni.cpp b/service/simulator/java/jni/simulator_single_resource_jni.cpp
new file mode 100644 (file)
index 0000000..d1547ec
--- /dev/null
@@ -0,0 +1,293 @@
+/******************************************************************
+ *
+ * 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.
+ *
+ ******************************************************************/
+
+#include "simulator_resource_model_jni.h"
+#include "simulator_exceptions_jni.h"
+#include "simulator_utils_jni.h"
+#include "jni_sharedobject_holder.h"
+#include "jni_listener_holder.h"
+#include "jni_string.h"
+#include "jni_vector.h"
+
+#include "simulator_single_resource.h"
+
+#define VALIDATE_OBJECT(ENV, OBJECT) if (!OBJECT){throwBadObjectException(ENV, "No corresponsing native object!"); return;}
+#define VALIDATE_OBJECT_RET(ENV, OBJECT, RET) if (!OBJECT){throwBadObjectException(ENV, "No corresponsing native object!"); return RET;}
+
+SimulatorSingleResourceSP simulatorSingleResourceToCpp(JNIEnv *env, jobject object)
+{
+    JniSharedObjectHolder<SimulatorSingleResource> *jniResource =
+        GetHandle<JniSharedObjectHolder<SimulatorSingleResource>>(env, object);
+    if (jniResource)
+        return jniResource->get();
+    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();
+    if (!env)
+        return;
+
+    jclass listenerCls = env->GetObjectClass(listener);
+    jmethodID listenerMethod = env->GetMethodID(listenerCls, "onUpdateComplete",
+                               "(Ljava/lang/String;I)V");
+
+    jstring jUri = env->NewStringUTF(uri.c_str());
+    env->CallVoidMethod(listener, listenerMethod, jUri, id);
+    releaseEnv();
+}
+
+#ifdef __cplusplus
+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)
+{
+    VALIDATE_INPUT_RET(env, !attrName, "Attribute name is null!", nullptr)
+
+    SimulatorSingleResourceSP singleResource = simulatorSingleResourceToCpp(env, object);
+    VALIDATE_OBJECT_RET(env, singleResource, nullptr)
+
+    JniString jniAttrName(env, attrName);
+    SimulatorResourceModel::Attribute attribute;
+    if (singleResource->getAttribute(jniAttrName.get(), attribute))
+        return simulatorResourceAttributeToJava(env, attribute);
+    return nullptr;
+}
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_server_SimulatorSingleResource_addAttribute
+(JNIEnv *env, jobject object, jobject resAttribute)
+{
+    VALIDATE_INPUT(env, !resAttribute, "Resource attribute is null!")
+
+    SimulatorSingleResourceSP singleResource = simulatorSingleResourceToCpp(env, object);
+    VALIDATE_OBJECT(env, singleResource)
+
+    try
+    {
+        SimulatorResourceModel::Attribute attribute;
+        if (!simulatorResourceAttributeToCpp(env, resAttribute, attribute))
+        {
+            throwSimulatorException(env, SIMULATOR_ERROR,
+                                    "Failed to covnert SimulatorResourceAttribute java object!");
+            return;
+        }
+
+        singleResource->addAttribute(attribute);
+    }
+    catch (SimulatorException &e)
+    {
+        throwSimulatorException(env, e.code(), e.what());
+    }
+}
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_server_SimulatorSingleResource_updateAttribute
+(JNIEnv *env, jobject object, jstring attrName, jobject attrValue)
+{
+    VALIDATE_INPUT(env, !attrName, "Attribute name is null!")
+    VALIDATE_INPUT(env, !attrValue, "Attribute value is null!")
+
+    SimulatorSingleResourceSP singleResource = simulatorSingleResourceToCpp(env, object);
+    VALIDATE_OBJECT(env, singleResource)
+
+    SimulatorResourceModel::ValueVariant value;
+    if (!AttributeValueToCpp(env, attrValue, value))
+    {
+        throwSimulatorException(env, SIMULATOR_ERROR,
+                                "Failed to covnert AttributeValue java object!");
+        return;
+    }
+
+    SimulatorResourceModel::Attribute attribute(JniString(env, attrName).get());
+    attribute.setValue(value);
+    singleResource->updateAttributeValue(attribute);
+}
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_server_SimulatorSingleResource_removeAttribute
+(JNIEnv *env, jobject object, jstring attrName)
+{
+    VALIDATE_INPUT(env, !attrName, "Attribute name is null!")
+
+    SimulatorSingleResourceSP singleResource = simulatorSingleResourceToCpp(env, object);
+    VALIDATE_OBJECT(env, singleResource)
+
+    try
+    {
+        JniString jniAttrName(env, attrName);
+        singleResource->removeAttribute(jniAttrName.get());
+    }
+    catch (InvalidArgsException &e)
+    {
+        throwInvalidArgsException(env, e.code(), e.what());
+    }
+}
+
+JNIEXPORT jint JNICALL
+Java_org_oic_simulator_server_SimulatorSingleResource_startResourceUpdation
+(JNIEnv *env, jobject object, jint type, jint interval, jobject listener)
+{
+    VALIDATE_CALLBACK_RET(env, listener, -1)
+
+    SimulatorSingleResourceSP singleResource = simulatorSingleResourceToCpp(env, object);
+    VALIDATE_OBJECT_RET(env, singleResource, -1)
+
+    jobject listenerRef = env->NewGlobalRef(listener);
+    updateCompleteCallback callback =  [listenerRef](const std::string & uri, const int id)
+    {
+        onAutoUpdationComplete(listenerRef, uri, id);
+    };
+
+    try
+    {
+        int id = singleResource->startResourceUpdation((1 == type) ? AutomationType::RECURRENT :
+                 AutomationType::NORMAL, interval, callback);
+        return id;
+    }
+    catch (InvalidArgsException &e)
+    {
+        throwInvalidArgsException(env, e.code(), e.what());
+    }
+    catch (SimulatorException &e)
+    {
+        throwSimulatorException(env, e.code(), e.what());
+    }
+
+    return -1;
+}
+
+JNIEXPORT jint JNICALL
+Java_org_oic_simulator_server_SimulatorSingleResource_startAttributeUpdation
+(JNIEnv *env, jobject object, jstring attrName, jint type, jint interval, jobject listener)
+{
+    VALIDATE_INPUT_RET(env, !attrName, "Attribute name is null!", -1)
+    VALIDATE_CALLBACK_RET(env, listener, -1)
+
+    SimulatorSingleResourceSP singleResource = simulatorSingleResourceToCpp(env, object);
+    VALIDATE_OBJECT_RET(env, singleResource, -1)
+
+    jobject listenerRef = env->NewGlobalRef(listener);
+    updateCompleteCallback callback =  [listenerRef](const std::string & uri, const int id)
+    {
+        onAutoUpdationComplete(listenerRef, uri, id);
+    };
+
+    JniString jniAttrName(env, attrName);
+
+    try
+    {
+        int id = singleResource->startAttributeUpdation(jniAttrName.get(),
+                 (1 == type) ? AutomationType::RECURRENT : AutomationType::NORMAL,
+                 interval, callback);
+        return id;
+    }
+    catch (InvalidArgsException &e)
+    {
+        throwInvalidArgsException(env, e.code(), e.what());
+    }
+    catch (SimulatorException &e)
+    {
+        throwSimulatorException(env, e.code(), e.what());
+    }
+
+    return -1;
+}
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_server_SimulatorSingleResource_stopUpdation
+(JNIEnv *env, jobject object, jint id)
+{
+    SimulatorSingleResourceSP singleResource = simulatorSingleResourceToCpp(env, object);
+    VALIDATE_OBJECT(env, singleResource)
+
+    singleResource->stopUpdation(id);
+}
+
+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)
+{
+    JniSharedObjectHolder<SimulatorSingleResource> *resource =
+        GetHandle<JniSharedObjectHolder<SimulatorSingleResource>>(env, object);
+    delete resource;
+}
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/service/simulator/java/jni/simulator_utils_jni.cpp b/service/simulator/java/jni/simulator_utils_jni.cpp
new file mode 100644 (file)
index 0000000..1f971ce
--- /dev/null
@@ -0,0 +1,293 @@
+/******************************************************************
+ *
+ * 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.
+ *
+ ******************************************************************/
+
+#include "simulator_utils_jni.h"
+
+jobject simulatorResultToJava(JNIEnv *env, SimulatorResult errorCode)
+{
+    switch (errorCode)
+    {
+        case SIMULATOR_OK:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_OK", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_RESOURCE_CREATED:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_RESOURCE_CREATED", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_RESOURCE_DELETED:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_RESOURCE_DELETED", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_CONTINUE:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_CONTINUE", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_INVALID_URI:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_INVALID_URI", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_INVALID_QUERY:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_INVALID_QUERY", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_INVALID_IP:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_INVALID_IP", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_INVALID_PORT:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_INVALID_PORT", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_INVALID_CALLBACK:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_INVALID_CALLBACK", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_INVALID_METHOD:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_INVALID_METHOD", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_INVALID_PARAM:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_INVALID_PARAM", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_INVALID_OBSERVE_PARAM:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_INVALID_OBSERVE_PARAM", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_NO_MEMORY:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_NO_MEMORY", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_COMM_ERROR:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_COMM_ERROR", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_TIMEOUT:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_TIMEOUT", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_ADAPTER_NOT_ENABLED:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_ADAPTER_NOT_ENABLED", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_NOTIMPL:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_NOTIMPL", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_NO_RESOURCE:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_NO_RESOURCE", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_RESOURCE_ERROR:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_RESOURCE_ERROR", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_SLOW_RESOURCE:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_SLOW_RESOURCE", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_DUPLICATE_REQUEST:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_DUPLICATE_REQUEST", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_NO_OBSERVERS:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_NO_OBSERVERS", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_OBSERVER_NOT_FOUND:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_OBSERVER_NOT_FOUND", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_VIRTUAL_DO_NOT_HANDLE:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_VIRTUAL_DO_NOT_HANDLE", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_INVALID_OPTION:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_INVALID_OPTION", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_MALFORMED_RESPONSE:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_MALFORMED_RESPONSE", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_PERSISTENT_BUFFER_REQUIRED:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_PERSISTENT_BUFFER_REQUIRED", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_INVALID_REQUEST_HANDLE:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_INVALID_REQUEST_HANDLE", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_INVALID_DEVICE_INFO:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_INVALID_DEVICE_INFO", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_INVALID_JSON:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_INVALID_JSON", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_UNAUTHORIZED_REQ:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_UNAUTHORIZED_REQ", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+#ifdef WITH_PRESENCE
+        case SIMULATOR_PRESENCE_STOPPED:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_PRESENCE_STOPPED", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_PRESENCE_TIMEOUT:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_PRESENCE_TIMEOUT", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_PRESENCE_DO_NOT_HANDLE:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_PRESENCE_DO_NOT_HANDLE", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+#endif
+        case SIMULATOR_INVALID_TYPE:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_INVALID_TYPE", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_NOT_SUPPORTED:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_NOT_SUPPORTED", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_OPERATION_NOT_ALLOWED:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_OPERATION_NOT_ALLOWED", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_OPERATION_IN_PROGRESS:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_OPERATION_IN_PROGRESS", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_INVALID_RESPONSE_CODE:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_INVALID_RESPONSE_CODE", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_UKNOWN_PROPERTY:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_UKNOWN_PROPERTY", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_TYPE_MISMATCH:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_TYPE_MISMATCH", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_BAD_VALUE:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_BAD_VALUE", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        case SIMULATOR_BAD_OBJECT:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_BAD_OBJECT", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+    }
+
+    static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                              "SIMULATOR_ERROR", "Lorg/oic/simulator/SimulatorResult;");
+    return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+}
+
diff --git a/service/simulator/java/jni/simulator_utils_jni.h b/service/simulator/java/jni/simulator_utils_jni.h
new file mode 100644 (file)
index 0000000..9ed427f
--- /dev/null
@@ -0,0 +1,112 @@
+/******************************************************************
+ *
+ * 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.
+ *
+ ******************************************************************/
+
+#ifndef SIMULATOR_UTILS_JNI_H_
+#define SIMULATOR_UTILS_JNI_H_
+
+#include <jni.h>
+#include "simulator_error_codes.h"
+
+typedef struct
+{
+    jclass objectCls;
+    jclass integerCls;
+    jclass doubleCls;
+    jclass booleanCls;
+    jclass stringCls;
+    jclass hashMapCls;
+    jclass vectorCls;
+    jclass mapCls;
+    jclass mapEntryCls;
+    jclass setCls;
+    jclass iteratorCls;
+
+    jclass interfaceTypeCls;
+    jclass simulatorResourceCls;
+    jclass simulatorResourceTypeCls;
+    jclass simulatorSingleResourceCls;
+    jclass simulatorCollectionResourceCls;
+    jclass simulatorResourceModelCls;
+    jclass simulatorResourceAttributeCls;
+    jclass attributeValueCls;
+    jclass attributeValueTypeCls;
+    jclass attributeTypeInfoCls;
+    jclass attributePropertyCls;
+    jclass attributePropertyTypeCls;
+    jclass simulatorRemoteResourceCls;
+    jclass observerCls;
+    jclass deviceInfoCls;
+    jclass platformInfoCls;
+    jclass simulatorExceptionCls;
+    jclass invalidArgsExceptionCls;
+    jclass noSupportExceptionCls;
+    jclass operationInProgressExceptionCls;
+    jclass simulatorResultCls;
+
+    jclass integer1DArrayCls;
+    jclass integer2DArrayCls;
+    jclass integer3DArrayCls;
+    jclass double1DArrayCls;
+    jclass double2DArrayCls;
+    jclass double3DArrayCls;
+    jclass boolean1DArrayCls;
+    jclass boolean2DArrayCls;
+    jclass boolean3DArrayCls;
+    jclass string1DArrayCls;
+    jclass string2DArrayCls;
+    jclass string3DArrayCls;
+    jclass simulatorResModel1DArrayCls;
+    jclass simulatorResModel2DArrayCls;
+    jclass simulatorResModel3DArrayCls;
+} SimulatorClassRefs;
+
+#define VALIDATE_INPUT(ENV, CONDITION, MSG) if (CONDITION) {throwInvalidArgsException(ENV, SIMULATOR_INVALID_PARAM, MSG); return;}
+#define VALIDATE_INPUT_RET(ENV, CONDITION, MSG, RET) if (CONDITION) {throwInvalidArgsException(ENV, SIMULATOR_INVALID_PARAM, MSG); return RET;}
+
+#define VALIDATE_CALLBACK(ENV, CALLBACK) if (!CALLBACK){throwInvalidArgsException(env, SIMULATOR_INVALID_CALLBACK, "Invalid callback!"); return;}
+#define VALIDATE_CALLBACK_RET(ENV, CALLBACK, RET) if (!CALLBACK){throwInvalidArgsException(env, SIMULATOR_INVALID_CALLBACK, "Invalid callback!"); return RET;}
+
+static jfieldID GetHandleField(JNIEnv *env, jobject jobj)
+{
+    jclass cls = env->GetObjectClass(jobj);
+    return env->GetFieldID(cls, "mNativeHandle", "J");
+}
+
+template <typename T>
+static T *GetHandle(JNIEnv *env, jobject jobj)
+{
+    jlong handle = env->GetLongField(jobj, GetHandleField(env, jobj));
+    return reinterpret_cast<T *>(handle);
+}
+
+template <typename T>
+static void SetHandle(JNIEnv *env, jobject jobj, T *type)
+{
+    jlong handle = reinterpret_cast<jlong>(type);
+    env->SetLongField(jobj, GetHandleField(env, jobj), handle);
+}
+
+extern JNIEnv *getEnv();
+extern void releaseEnv();
+extern SimulatorClassRefs gSimulatorClassRefs;
+
+jobject simulatorResultToJava(JNIEnv *env, SimulatorResult errorCode);
+
+#endif
diff --git a/service/simulator/java/sdk/src/org/oic/simulator/AttributeProperty.java b/service/simulator/java/sdk/src/org/oic/simulator/AttributeProperty.java
new file mode 100644 (file)
index 0000000..d2705cd
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ * 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 org.oic.simulator;
+
+/**
+ * This class represents the resource attribute's vaule property.
+ */
+public class AttributeProperty {
+
+    private Type mType = Type.UNKNOWN;
+    private double mMin = -1;
+    private double mMax = -1;
+    private AttributeValue[] mValueSet = null;
+
+    /**
+     * Enum to represent propety type.
+     */
+    public enum Type {
+        UNKNOWN, RANGE, VALUESET
+    }
+
+    /**
+     * Constructs {@AttributeProperty} of type {@AttributeProperty.Type.Range}
+     * with min and max values.
+     *
+     * @param min
+     *            Minimun value the attribute can have.
+     * @param max
+     *            Maximum value the attribute can have.
+     */
+    public AttributeProperty(double min, double max) {
+        mType = Type.RANGE;
+        mMin = min;
+        mMax = max;
+    }
+
+    /**
+     * Constructs {@AttributeProperty} of type {@AttributeProperty.Type.VALUESET}
+     * with array of integers.
+     *
+     * @param values
+     *            Attribute will be having one of the value from this array at any time.
+     */
+    public AttributeProperty(int[] 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 doubles.
+     *
+     * @param values
+     *            Attribute will be having one of the value from this array at any time.
+     */
+    public AttributeProperty(double[] 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
+     *            Attribute will be having one of the value from this array at any time.
+     */
+    public AttributeProperty(String[] values) {
+        mType = Type.VALUESET;
+        mValueSet = new AttributeValue[values.length];
+        for (int i = 0; i < values.length; i++)
+            mValueSet[i] = new AttributeValue(values[i]);
+    }
+
+    /**
+     * API to get type of property.
+     *
+     * @return {@AttributeProperty.Type}.
+     */
+    public Type type() {
+        return mType;
+    }
+
+    /**
+     * API to get minimum value which was set as property.
+     */
+    public double min() {
+        return mMin;
+    }
+
+    /**
+     * API to get maximum value which was set as property.
+     */
+    public double max() {
+        return mMax;
+    }
+
+    /**
+     * API to get array of values which was set as property.
+     *
+     * @return array of {@AttributeValue}.
+     */
+    public AttributeValue[] valueSet() {
+        return mValueSet;
+    }
+
+    private AttributeProperty(AttributeValue[] values) {
+        mType = Type.VALUESET;
+        mValueSet = values;
+    }
+}
diff --git a/service/simulator/java/sdk/src/org/oic/simulator/AttributeValue.java b/service/simulator/java/sdk/src/org/oic/simulator/AttributeValue.java
new file mode 100644 (file)
index 0000000..23e0fb3
--- /dev/null
@@ -0,0 +1,495 @@
+/*
+ * 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 org.oic.simulator;
+
+/**
+ * This class accommodate different type of values as Object.
+ */
+public class AttributeValue {
+
+    private Object mValue = null;
+
+    /**
+     * Enum to represent value type.
+     */
+    public enum ValueType {
+        UNKNOWN, INTEGER, DOUBLE, BOOLEAN, STRING, RESOURCEMODEL, ARRAY
+    }
+
+    /**
+     * Class provides the value type information in detail.
+     */
+    public class TypeInfo {
+        public ValueType mType;
+        public ValueType mBaseType;
+        public int mDepth;
+
+        /**
+         * Constructs {@AttributeValue.TypeInfo} with default values.
+         */
+        TypeInfo() {
+            mType = ValueType.UNKNOWN;
+            mBaseType = ValueType.UNKNOWN;
+            mDepth = 0;
+        }
+
+        /**
+         * Constructs {@AttributeValue.TypeInfo} with given {AttributeValue.ValueType}.
+         *
+         * @param type
+         *            Value type.
+         */
+        TypeInfo(ValueType type) {
+            mType = type;
+            mBaseType = type;
+            mDepth = 0;
+        }
+
+        /**
+         * 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.
+         * @param depth
+         *            Depth of array type value. This type is useful when vaule is of array type.
+         */
+        TypeInfo(ValueType type, ValueType baseType, int depth) {
+            mType = type;
+            mBaseType = baseType;
+            mDepth = depth;
+        }
+    }
+
+    /**
+     * Constructs {@AttributeValue} with int type value.
+     *
+     * @param value
+     *            int type value.
+     */
+    public AttributeValue(int value) {
+        mValue = new Integer(value);
+    }
+
+    /**
+     * Constructs {@AttributeValue} with double type value.
+     *
+     * @param value
+     *            double type value.
+     */
+    public AttributeValue(double value) {
+        mValue = new Double(value);
+    }
+
+    /**
+     * Constructs {@AttributeValue} with boolean type value.
+     *
+     * @param value
+     *            boolean type value.
+     */
+    public AttributeValue(boolean value) {
+        mValue = new Boolean(value);
+    }
+
+    /**
+     * Constructs {@AttributeValue} with String type value.
+     *
+     * @param value
+     *            String type value.
+     */
+    public AttributeValue(String value) {
+        mValue = value;
+    }
+
+    /**
+     * Constructs {@AttributeValue} with SimulatorResourceModel type value.
+     *
+     * @param value
+     *            SimulatorResourceModel type value.
+     */
+    public AttributeValue(SimulatorResourceModel value) {
+        mValue = value;
+    }
+
+    /**
+     * Constructs {@AttributeValue} with array of int type values.
+     *
+     * @param values
+     *            Array of int type values.
+     */
+    public AttributeValue(int[] values) {
+        Integer[] newValues = new Integer[values.length];
+        for (int i = 0; i < values.length; i++)
+            newValues[i] = Integer.valueOf(values[i]);
+        mValue = newValues;
+    }
+
+    /**
+     * Constructs {@AttributeValue} with array of Integer type values.
+     *
+     * @param values
+     *            Array of Integer type values.
+     */
+    public AttributeValue(Integer[] values) {
+        mValue = values;
+    }
+
+    /**
+     * Constructs {@AttributeValue} with array of double type values.
+     *
+     * @param values
+     *            Array of double type values.
+     */
+    public AttributeValue(double[] values) {
+        Double[] newValues = new Double[values.length];
+        for (int i = 0; i < values.length; i++)
+            newValues[i] = Double.valueOf(values[i]);
+        mValue = newValues;
+    }
+
+    /**
+     * Constructs {@AttributeValue} with array of Double type values.
+     *
+     * @param values
+     *            Array of Double type values.
+     */
+    public AttributeValue(Double[] values) {
+        mValue = values;
+    }
+
+    /**
+     * Constructs {@AttributeValue} with array of boolean type values.
+     *
+     * @param values
+     *            Array of boolean type values.
+     */
+    public AttributeValue(boolean[] values) {
+        Boolean[] newValues = new Boolean[values.length];
+        for (int i = 0; i < values.length; i++)
+            newValues[i] = Boolean.valueOf(values[i]);
+        mValue = newValues;
+    }
+
+    /**
+     * Constructs {@AttributeValue} with array of Boolean type values.
+     *
+     * @param values
+     *            Array of Boolean type values.
+     */
+    public AttributeValue(Boolean[] values) {
+        mValue = values;
+    }
+
+    /**
+     * Constructs {@AttributeValue} with array of String type values.
+     *
+     * @param values
+     *            Array of String type values.
+     */
+    public AttributeValue(String[] values) {
+        mValue = values;
+    }
+
+    /**
+     * Constructs {@AttributeValue} with array of SimulatorResourceModel type values.
+     *
+     * @param values
+     *            Array of SimulatorResourceModel type values.
+     */
+    public AttributeValue(SimulatorResourceModel[] values) {
+        mValue = values;
+    }
+
+    /**
+     * Constructs {@AttributeValue} with 2 dimensional array of int type values.
+     *
+     * @param values
+     *            2 dimensional array of int type values.
+     */
+    public AttributeValue(int[][] values) {
+        Integer[][] newValues = new Integer[values.length][];
+        for (int i = 0; i < values.length; i++) {
+            newValues[i] = new Integer[values[i].length];
+            for (int j = 0; j < values[i].length; j++) {
+                newValues[i][j] = Integer.valueOf(values[i][j]);
+            }
+        }
+        mValue = newValues;
+    }
+
+    /**
+     * Constructs {@AttributeValue} with 2 dimensional array of Integer type values.
+     *
+     * @param values
+     *            2 dimensional array of Integer type values.
+     */
+    public AttributeValue(Integer[][] values) {
+        mValue = values;
+    }
+
+    /**
+     * Constructs {@AttributeValue} with 2 dimensional array of double type values.
+     *
+     * @param values
+     *            2 dimensional array of double type values.
+     */
+    public AttributeValue(double[][] values) {
+        Double[][] newValues = new Double[values.length][];
+        for (int i = 0; i < values.length; i++) {
+            newValues[i] = new Double[values[i].length];
+            for (int j = 0; j < values[i].length; j++) {
+                newValues[i][j] = Double.valueOf(values[i][j]);
+            }
+        }
+        mValue = newValues;
+    }
+
+    /**
+     * Constructs {@AttributeValue} with 2 dimensional array of Double type values.
+     *
+     * @param values
+     *            2 dimensional array of Double type values.
+     */
+    public AttributeValue(Double[][] values) {
+        mValue = values;
+    }
+
+    /**
+     * Constructs {@AttributeValue} with 2 dimensional array of boolean type values.
+     *
+     * @param values
+     *            2 dimensional array of boolean type values.
+     */
+    public AttributeValue(boolean[][] values) {
+        Boolean[][] newValues = new Boolean[values.length][];
+        for (int i = 0; i < values.length; i++) {
+            newValues[i] = new Boolean[values[i].length];
+            for (int j = 0; j < values[i].length; j++) {
+                newValues[i][j] = Boolean.valueOf(values[i][j]);
+            }
+        }
+        mValue = newValues;
+    }
+
+    /**
+     * Constructs {@AttributeValue} with 2 dimensional array of Boolean type values.
+     *
+     * @param values
+     *            2 dimensional array of Boolean type values.
+     */
+    public AttributeValue(Boolean[][] values) {
+        mValue = values;
+    }
+
+    /**
+     * Constructs {@AttributeValue} with 2 dimensional array of String type values.
+     *
+     * @param values
+     *            2 dimensional array of String type values.
+     */
+    public AttributeValue(String[][] values) {
+        mValue = values;
+    }
+
+    /**
+     * Constructs {@AttributeValue} with 2 dimensional array of
+     * SimulatorResourceModel type values.
+     *
+     * @param values
+     *            2 dimensional array of SimulatorResourceModel type values.
+     */
+    public AttributeValue(SimulatorResourceModel[][] values) {
+        mValue = values;
+    }
+
+    /**
+     * Constructs {@AttributeValue} with 3 dimensional array of
+     * int type values.
+     *
+     * @param values
+     *            3 dimensional array of int type values.
+     */
+    public AttributeValue(int[][][] values) {
+        Integer[][][] newValues = new Integer[values.length][][];
+        for (int i = 0; i < values.length; i++) {
+            newValues[i] = new Integer[values[i].length][];
+            for (int j = 0; j < values[i].length; j++) {
+                newValues[i][j] = new Integer[values[i][j].length];
+                for (int k = 0; k < values[j].length; k++) {
+                    newValues[i][j][k] = Integer.valueOf(values[i][j][k]);
+                }
+            }
+        }
+        mValue = newValues;
+    }
+
+    /**
+     * Constructs {@AttributeValue} with 3 dimensional array of
+     * Integer type values.
+     *
+     * @param values
+     *            3 dimensional array of Integer type values.
+     */
+    public AttributeValue(Integer[][][] values) {
+        mValue = values;
+    }
+
+    /**
+     * Constructs {@AttributeValue} with 3 dimensional array of
+     * double type values.
+     *
+     * @param values
+     *            3 dimensional array of double type values.
+     */
+    public AttributeValue(double[][][] values) {
+        Double[][][] newValues = new Double[values.length][][];
+        for (int i = 0; i < values.length; i++) {
+            newValues[i] = new Double[values[i].length][];
+            for (int j = 0; j < values[i].length; j++) {
+                newValues[i][j] = new Double[values[i][j].length];
+                for (int k = 0; k < values[j].length; k++) {
+                    newValues[i][j][k] = Double.valueOf(values[i][j][k]);
+                }
+            }
+        }
+        mValue = newValues;
+    }
+
+    /**
+     * Constructs {@AttributeValue} with 3 dimensional array of
+     * Double type values.
+     *
+     * @param values
+     *            3 dimensional array of Double type values.
+     */
+    public AttributeValue(Double[][][] values) {
+        mValue = values;
+    }
+
+    /**
+     * Constructs {@AttributeValue} with 3 dimensional array of
+     * boolean type values.
+     *
+     * @param values
+     *            3 dimensional array of boolean type values.
+     */
+    public AttributeValue(boolean[][][] values) {
+        Boolean[][][] newValues = new Boolean[values.length][][];
+        for (int i = 0; i < values.length; i++) {
+            newValues[i] = new Boolean[values[i].length][];
+            for (int j = 0; j < values[i].length; j++) {
+                newValues[i][j] = new Boolean[values[i][j].length];
+                for (int k = 0; k < values[j].length; k++) {
+                    newValues[i][j][k] = Boolean.valueOf(values[i][j][k]);
+                }
+            }
+        }
+        mValue = newValues;
+    }
+
+    /**
+     * Constructs {@AttributeValue} with 3 dimensional array of
+     * Boolean type values.
+     *
+     * @param values
+     *            3 dimensional array of Boolean type values.
+     */
+    public AttributeValue(Boolean[][][] values) {
+        mValue = values;
+    }
+
+    /**
+     * Constructs {@AttributeValue} with 3 dimensional array of
+     * String type values.
+     *
+     * @param values
+     *            3 dimensional array of String type values.
+     */
+    public AttributeValue(String[][][] values) {
+        mValue = values;
+    }
+
+    /**
+     * Constructs {@AttributeValue} with 3 dimensional array of
+     * SimulatorResourceModel type values.
+     *
+     * @param values
+     *            3 dimensional array of SimulatorResourceModel type values.
+     */
+    public AttributeValue(SimulatorResourceModel[][][] values) {
+        mValue = values;
+    }
+
+    /**
+     * API to get value type information.
+     *
+     * @return {@AttributeValue.TypeInfo}.
+     */
+    public TypeInfo typeInfo() {
+        return createTypeInfo(mValue);
+    }
+
+    /**
+     * API to get value as Object.
+     *
+     * @return Value as Object.
+     */
+    public Object get() {
+        return mValue;
+    }
+
+    private AttributeValue(Object value) {
+        mValue = value;
+    }
+
+    private TypeInfo createTypeInfo(Object value) {
+        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())) {
+            typeInfo.mBaseType = ValueType.DOUBLE;
+            typeInfo.mType = ValueType.DOUBLE;
+        }
+        else if (className.contains(Boolean.class.getName())) {
+            typeInfo.mBaseType = ValueType.BOOLEAN;
+            typeInfo.mType = ValueType.BOOLEAN;
+        }
+        else if (className.contains(String.class.getName())) {
+            typeInfo.mBaseType = ValueType.STRING;
+            typeInfo.mType = ValueType.STRING;
+        }
+        else if (className.contains(SimulatorResourceModel.class.getName())) {
+            typeInfo.mBaseType = ValueType.RESOURCEMODEL;
+            typeInfo.mType = ValueType.RESOURCEMODEL;
+        }
+
+        // For array types
+        if (value.getClass().isArray()) {
+            typeInfo.mType = ValueType.ARRAY;
+            for (char ch : className.toCharArray()) {
+                if (ch == '[') typeInfo.mDepth++;
+            }
+        }
+
+        return typeInfo;
+    }
+}
index 49e8e39..66a45ce 100644 (file)
@@ -17,7 +17,7 @@
 package org.oic.simulator;
 
 /**
- * This class contains remote device information and provides APIs to access it.
+ * This class contains remote device information.
  */
 public class DeviceInfo {
     private String mName;
 package org.oic.simulator;
 
 /**
- * Interface for getting device information.
+ * Listener for getting device information.
  */
-public interface IDeviceInfo {
+public interface DeviceListener {
     /**
-     * Callback method which provides remote device information.
+     * Method which provides remote device information.
      *
      * @param devInfo
      *            {@link DeviceInfo} object holding the device information.
diff --git a/service/simulator/java/sdk/src/org/oic/simulator/IAutomation.java b/service/simulator/java/sdk/src/org/oic/simulator/IAutomation.java
deleted file mode 100644 (file)
index 1338fd5..0000000
+++ /dev/null
@@ -1,32 +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 org.oic.simulator;
-
-/**
- * Interface for receiving notifications on completion of automation.
- */
-public interface IAutomation {
-    /**
-     * Callback method for receiving automation complete notifications.
-     *
-     * @param resourceURI
-     *            URI of the resource on which the automation has occurred.
-     * @param automationId
-     *            Unique Id of the automation.
-     */
-    public void onAutomationComplete(String resourceURI, int automationId);
-}
index 082e59e..87bf84a 100644 (file)
@@ -28,8 +28,8 @@ public interface ILogger {
     }
 
     /**
-     * This callback method will be called to notify the application about the
-     * status or problems along with their severity.
+     * This method will be used to deliver the log messages from
+     * native layer.
      *
      * @param time
      *            Local time information when action/event logged.
index d62fbdd..256e3eb 100644 (file)
@@ -21,7 +21,16 @@ package org.oic.simulator;
  */
 @SuppressWarnings("serial")
 public class InvalidArgsException extends SimulatorException {
-    public InvalidArgsException(int errorCode, String errMessage) {
-        super(errorCode, errMessage);
+
+    public InvalidArgsException(int code, String message) {
+        super(code, message);
+    }
+
+    public InvalidArgsException(SimulatorResult code, String message) {
+        super(code, message);
+    }
+
+    public InvalidArgsException(String message) {
+        super(SimulatorResult.SIMULATOR_INVALID_PARAM, message);
     }
 }
index 914641f..7e6348a 100644 (file)
@@ -21,7 +21,12 @@ package org.oic.simulator;
  */
 @SuppressWarnings("serial")
 public class NoSupportException extends SimulatorException {
-    public NoSupportException(int errorCode, String errMessage) {
-        super(errorCode, errMessage);
+
+    public NoSupportException(String message) {
+        super(SimulatorResult.SIMULATOR_NOT_SUPPORTED, message);
+    }
+
+    public NoSupportException(SimulatorResult code, String message) {
+        super(code, message);
     }
 }
\ No newline at end of file
index c9127b5..e0c259c 100644 (file)
@@ -22,7 +22,12 @@ package org.oic.simulator;
  */
 @SuppressWarnings("serial")
 public class OperationInProgressException extends SimulatorException {
-    public OperationInProgressException(int errorCode, String errMessage) {
-        super(errorCode, errMessage);
+
+    public OperationInProgressException(String message) {
+        super(SimulatorResult.SIMULATOR_OPERATION_IN_PROGRESS, message);
+    }
+
+    public OperationInProgressException(SimulatorResult code, String message) {
+        super(code, message);
     }
 }
index 7956e92..8ff3a60 100644 (file)
@@ -22,16 +22,16 @@ package org.oic.simulator;
  */
 public class PlatformInfo {
     private String mPlatformId;
-    private String m_manufacturerName;
-    private String m_manufacturerUrl;
-    private String m_modelNumber;
-    private String m_dateOfManufacture;
-    private String m_platformVersion;
-    private String m_operationSystemVersion;
-    private String m_hardwareVersion;
-    private String m_firmwareVersion;
-    private String m_supportUrl;
-    private String m_systemTime;
+    private String mManufacturerName;
+    private String mManufacturerUrl;
+    private String mModelNumber;
+    private String mDateOfManufacture;
+    private String mPlatformVersion;
+    private String mOperationSystemVersion;
+    private String mHardwareVersion;
+    private String mFirmwareVersion;
+    private String mSupportUrl;
+    private String mSystemTime;
 
     /**
      * This method is for getting platform id.
@@ -58,7 +58,7 @@ public class PlatformInfo {
      * @return Manufacturer name.
      */
     public String getManufacturerName() {
-        return m_manufacturerName;
+        return mManufacturerName;
     }
 
     /**
@@ -68,7 +68,7 @@ public class PlatformInfo {
      *            Manufacturer name.
      */
     public void setManufacturerName(String m_manufacturerName) {
-        this.m_manufacturerName = m_manufacturerName;
+        this.mManufacturerName = m_manufacturerName;
     }
 
     /**
@@ -77,7 +77,7 @@ public class PlatformInfo {
      * @return Manufacturer URL.
      */
     public String getManufacturerUrl() {
-        return m_manufacturerUrl;
+        return mManufacturerUrl;
     }
 
     /**
@@ -87,7 +87,7 @@ public class PlatformInfo {
      *            Manufacturer URL.
      */
     public void setManufacturerUrl(String m_manufacturerUrl) {
-        this.m_manufacturerUrl = m_manufacturerUrl;
+        this.mManufacturerUrl = m_manufacturerUrl;
     }
 
     /**
@@ -96,7 +96,7 @@ public class PlatformInfo {
      * @return Model number.
      */
     public String getModelNumber() {
-        return m_modelNumber;
+        return mModelNumber;
     }
 
     /**
@@ -106,7 +106,7 @@ public class PlatformInfo {
      *            Model number.
      */
     public void setModelNumber(String m_modelNumber) {
-        this.m_modelNumber = m_modelNumber;
+        this.mModelNumber = m_modelNumber;
     }
 
     /**
@@ -115,7 +115,7 @@ public class PlatformInfo {
      * @return Date of manufacture.
      */
     public String getDateOfManufacture() {
-        return m_dateOfManufacture;
+        return mDateOfManufacture;
     }
 
     /**
@@ -125,7 +125,7 @@ public class PlatformInfo {
      *            Date of manufacture.
      */
     public void setDateOfManufacture(String m_dateOfManufacture) {
-        this.m_dateOfManufacture = m_dateOfManufacture;
+        this.mDateOfManufacture = m_dateOfManufacture;
     }
 
     /**
@@ -134,7 +134,7 @@ public class PlatformInfo {
      * @return Platform version.
      */
     public String getPlatformVersion() {
-        return m_platformVersion;
+        return mPlatformVersion;
     }
 
     /**
@@ -144,7 +144,7 @@ public class PlatformInfo {
      *            Platform version.
      */
     public void setPlatformVersion(String m_platformVersion) {
-        this.m_platformVersion = m_platformVersion;
+        this.mPlatformVersion = m_platformVersion;
     }
 
     /**
@@ -153,7 +153,7 @@ public class PlatformInfo {
      * @return Operation system version.
      */
     public String getOperationSystemVersion() {
-        return m_operationSystemVersion;
+        return mOperationSystemVersion;
     }
 
     /**
@@ -163,7 +163,7 @@ public class PlatformInfo {
      *            Operation system version.
      */
     public void setOperationSystemVersion(String m_operationSystemVersion) {
-        this.m_operationSystemVersion = m_operationSystemVersion;
+        this.mOperationSystemVersion = m_operationSystemVersion;
     }
 
     /**
@@ -172,7 +172,7 @@ public class PlatformInfo {
      * @return Hardware version.
      */
     public String getHardwareVersion() {
-        return m_hardwareVersion;
+        return mHardwareVersion;
     }
 
     /**
@@ -182,7 +182,7 @@ public class PlatformInfo {
      *            Hardware version.
      */
     public void setHardwareVersion(String m_hardwareVersion) {
-        this.m_hardwareVersion = m_hardwareVersion;
+        this.mHardwareVersion = m_hardwareVersion;
     }
 
     /**
@@ -191,7 +191,7 @@ public class PlatformInfo {
      * @return Firmware version.
      */
     public String getFirmwareVersion() {
-        return m_firmwareVersion;
+        return mFirmwareVersion;
     }
 
     /**
@@ -201,7 +201,7 @@ public class PlatformInfo {
      *            Firmware version.
      */
     public void setFirmwareVersion(String m_firmwareVersion) {
-        this.m_firmwareVersion = m_firmwareVersion;
+        this.mFirmwareVersion = m_firmwareVersion;
     }
 
     /**
@@ -210,7 +210,7 @@ public class PlatformInfo {
      * @return URL of support link.
      */
     public String getSupportUrl() {
-        return m_supportUrl;
+        return mSupportUrl;
     }
 
     /**
@@ -220,7 +220,7 @@ public class PlatformInfo {
      *            URL of support link.
      */
     public void setSupportUrl(String m_supportUrl) {
-        this.m_supportUrl = m_supportUrl;
+        this.mSupportUrl = m_supportUrl;
     }
 
     /**
@@ -229,7 +229,7 @@ public class PlatformInfo {
      * @return System time.
      */
     public String getSystemTime() {
-        return m_systemTime;
+        return mSystemTime;
     }
 
     /**
@@ -239,6 +239,6 @@ public class PlatformInfo {
      *            System time.
      */
     public void setSystemTime(String m_systemTime) {
-        this.m_systemTime = m_systemTime;
+        this.mSystemTime = m_systemTime;
     }
 }
 package org.oic.simulator;
 
 /**
- * Interface for getting platform information.
+ * Listener for getting platform information.
  */
-public interface IPlatformInfo {
+public interface PlatformListener {
     /**
-     * Callback method which provides remote device platform information.
+     * Method which provides remote device platform information.
      *
      * @param platformInfo
      *            {@link PlatformInfo} object holding the platform information.
diff --git a/service/simulator/java/sdk/src/org/oic/simulator/ResourceAttribute.java b/service/simulator/java/sdk/src/org/oic/simulator/ResourceAttribute.java
deleted file mode 100644 (file)
index 0822e76..0000000
+++ /dev/null
@@ -1,139 +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 org.oic.simulator;
-
-/**
- * This class represents an attribute of a resource. It has a set of native
- * methods for getting the attribute's information.
- */
-public class ResourceAttribute {
-    /**
-     * Type of attribute value.
-     */
-    public enum Type {
-        UNKNOWN, INT, DOUBLE, BOOL, STRING;
-
-        private static Type[] m_cvalues = Type.values();
-
-        @SuppressWarnings("unused")
-        private static Type getType(int x) {
-            return m_cvalues[x];
-        }
-    };
-
-    /**
-     * Class contains range property in min and max value.
-     */
-    public class Range {
-        public int getMin() {
-            return m_min;
-        }
-
-        public int getMax() {
-            return m_max;
-        }
-
-        private Range(int min, int max) {
-            m_min = min;
-            m_max = max;
-        }
-
-        private int m_min;
-        private int m_max;
-    }
-
-    @SuppressWarnings("unused")
-    private void setRange(int min, int max) {
-        m_range = new Range(min, max);
-    }
-
-    /**
-     * This generic API is used to get the value of an attribute whose type is
-     * given by the caller of the method.
-     *
-     * @param <T>
-     *            This specifies the type in which the value has to be returned.
-     *
-     * @return The attribute's value in a specified type.
-     */
-    public <T> T getValue() {
-        @SuppressWarnings("unchecked")
-        T t = (T) m_value;
-        return t;
-    }
-
-    /**
-     * Method for getting the attribute's name.
-     *
-     * @return Attribute's name
-     */
-    public String getName() {
-        return m_name;
-    }
-
-    /**
-     * Method for getting the attribute's value type.
-     *
-     * @return Attribute's value type as {@link Type}
-     */
-    public Type getType() {
-        return m_type;
-    }
-
-    /**
-     * Method for getting the attribute's value base type. For example If the
-     * attribute value object is of type Vector of {@link Integer} then its type
-     * is Vector and base type is INT.
-     *
-     * @return Attribute's value type as {@link Type}
-     */
-    public Type getBaseType() {
-        return m_type;
-    }
-
-    /**
-     * Method for getting the attribute's range property. Range will be valid
-     * only for Integer type.
-     *
-     * @return Attribute's value range as {@link Range}.
-     */
-    public Range getRange() {
-        return m_range;
-    }
-
-    /**
-     * Method for getting the attribute's allowed values property. Allowed
-     * values property will be valid only for Integer, Double, String types.
-     *
-     * @param <T>
-     *            Attribute's allowed values whose type is given by the caller
-     *            of the method.
-     *
-     * @return Attribute's value range as {@link Range}.
-     */
-    public <T> T getAllowedValues() {
-        @SuppressWarnings("unchecked")
-        T t = (T) m_AllowedValues;
-        return t;
-    }
-
-    private String m_name          = null;
-    private Object m_value         = null;
-    private Type   m_type          = Type.STRING;
-    private Range  m_range         = null;
-    private Object m_AllowedValues = null;
-}
\ No newline at end of file
index 7b4c5c8..95e22fa 100644 (file)
@@ -23,19 +23,24 @@ package org.oic.simulator;
 @SuppressWarnings("serial")
 public class SimulatorException extends Exception {
 
-    private SimulatorResult errorCode;
-    private String          errorMessage;
+    private SimulatorResult code;
+    private String          message;
 
-    public SimulatorException(int errorCode, String errMessage) {
-        this.errorCode = SimulatorResult.get(errorCode);
-        this.errorMessage = errMessage;
+    public SimulatorException(int code, String message) {
+        this.code = SimulatorResult.get(code);
+        this.message = message;
+    }
+
+    public SimulatorException(SimulatorResult code, String message) {
+        this.code = code;
+        this.message = new String(message);
     }
 
     public SimulatorResult code() {
-        return errorCode;
+        return code;
     }
 
     public String message() {
-        return errorMessage;
+        return message;
     }
 }
\ No newline at end of file
index a16ce67..37984fd 100644 (file)
 
 package org.oic.simulator;
 
-import org.oic.simulator.clientcontroller.IFindResourceListener;
-import org.oic.simulator.serviceprovider.IResourceModelChangedListener;
-import org.oic.simulator.serviceprovider.SimulatorResourceServer;
+import java.util.Vector;
+
+import org.oic.simulator.client.FindResourceListener;
+import org.oic.simulator.server.SimulatorResource;
 
 /**
  * This class provides a set of methods for creation, discovery and deletion of
@@ -26,15 +27,13 @@ import org.oic.simulator.serviceprovider.SimulatorResourceServer;
  */
 public class SimulatorManager {
 
+    private SimulatorManager(){}
+
     /**
-     * API for creating a resource from a RAML configuration file whose path is
-     * given as a parameter.
+     * API for creating a resource from a RAML configuration file.
      *
      * @param configPath
      *            Path to RAML configuration file.
-     * @param listener
-     *            Listener for receiving notifications whenever there is a
-     *            change in the resource model.
      *
      * @return {@link SimulatorResourceServer} - Created resource on success,
      *         otherwise null.
@@ -44,30 +43,16 @@ public class SimulatorManager {
      * @throws SimulatorException
      *             Thrown for other errors.
      */
-    public static SimulatorResourceServer createResource(String configPath,
-            IResourceModelChangedListener listener)
-            throws InvalidArgsException, SimulatorException {
-        if (configPath.isEmpty() || null == listener)
-            throw new InvalidArgsException(
-                    SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
-                    "Parameter passed in invalid");
-        SimulatorResourceServer simulatorResourceServerObj;
-        simulatorResourceServerObj = SimulatorManagerNativeInterface
-                .createResource(configPath, listener);
-        return simulatorResourceServerObj;
-    }
+    public static native SimulatorResource createResource(String configPath)
+            throws InvalidArgsException, SimulatorException;
 
     /**
-     * API for creating a set of resources from a RAML configuration file whose
-     * path is given as a parameter.
+     * API for creating a set of resources from a RAML configuration file.
      *
      * @param configPath
      *            Path to RAML configuration file.
      * @param count
      *            Number of resources to be created.
-     * @param listener
-     *            Listener for receiving notifications whenever there is a
-     *            change in the resource model.
      *
      * @return Returns an array of {@link SimulatorResourceServer} objects one
      *         for each created resource on success, otherwise null.
@@ -77,51 +62,34 @@ public class SimulatorManager {
      * @throws SimulatorException
      *             Thrown for other errors.
      */
-    public static SimulatorResourceServer[] createResource(String configPath,
-            int count, IResourceModelChangedListener listener)
-            throws InvalidArgsException, SimulatorException {
-        if (configPath.isEmpty() || count < 0 || null == listener)
-            throw new InvalidArgsException(
-                    SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
-                    "Parameter passed in invalid");
-        SimulatorResourceServer[] simulatorResourceServers;
-        simulatorResourceServers = SimulatorManagerNativeInterface
-                .createResources(configPath, count, listener);
-        return simulatorResourceServers;
-    }
+    public static Vector<SimulatorResource> createResource(String configPath,
+            int count) throws InvalidArgsException, SimulatorException {
+        return createResources(configPath, count);
+    };
 
     /**
-     * API for deleting a specific resource.
+     * API for creating a resource either single or collection type.
      *
-     * @param resource
-     *            {@link SimulatorResourceServer} object of the resource to be
-     *            deleted.
+     * @param configPath
+     *            Path to RAML configuration file.
+     *
+     * @return {@link SimulatorResourceServer} - Created resource on success,
+     *         otherwise null.
      *
      * @throws InvalidArgsException
-     *             Thrown if the input parameter is empty.
+     *             Thrown if the input parameters are empty.
      * @throws SimulatorException
      *             Thrown for other errors.
      */
-    public static void deleteResource(SimulatorResourceServer resource)
+    public static SimulatorResource createResource(SimulatorResource.Type type,
+            String name, String uri, String resourceType)
             throws InvalidArgsException, SimulatorException {
-        SimulatorManagerNativeInterface.deleteResource(resource);
-    }
-
-    /**
-     * API for deleting either all the resources or resources of a specific
-     * type. Ex: If resourceType is oic.light, all resources of oic.light type
-     * will be deleted. If resourceType is null, then all of the resources will
-     * be deleted.
-     *
-     * @param resourceType
-     *            Type of resource to be deleted.
-     *
-     * @throws SimulatorException
-     *             Thrown for other errors.
-     */
-    public static void deleteResources(String resourceType)
-            throws SimulatorException {
-        SimulatorManagerNativeInterface.deleteResources(resourceType);
+        SimulatorResource resource = null;
+        if (type == SimulatorResource.Type.SINGLE)
+            resource = createSingleResource(name, uri, resourceType);
+        else
+            resource = createCollectionResource(name, uri, resourceType);
+        return resource;
     }
 
     /**
@@ -136,9 +104,9 @@ public class SimulatorManager {
      * @throws SimulatorException
      *             Thrown for other errors.
      */
-    public static void findResource(IFindResourceListener listener)
+    public static void findResource(FindResourceListener listener)
             throws InvalidArgsException, SimulatorException {
-        SimulatorManagerNativeInterface.findResource(null, listener);
+        searchResource(null, listener);
     }
 
     /**
@@ -156,24 +124,15 @@ public class SimulatorManager {
      *             Thrown for other errors.
      */
     public static void findResource(String resourceType,
-            IFindResourceListener listener) throws InvalidArgsException,
+            FindResourceListener listener) throws InvalidArgsException,
             SimulatorException {
         if (null == resourceType || resourceType.isEmpty()) {
             throw new InvalidArgsException(
-                    SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
-                    "Resource type is empty");
+                    SimulatorResult.SIMULATOR_INVALID_PARAM,
+                    "Invalid resource type!");
         }
-        SimulatorManagerNativeInterface.findResource(resourceType, listener);
-    }
 
-    /**
-     * API to set the listener for receiving log messages.
-     *
-     * @param logger
-     *            {@link ILogger} to receive the log messages.
-     */
-    public static void setLogger(ILogger logger) {
-        SimulatorManagerNativeInterface.setLogger(logger);
+        searchResource(resourceType, listener);
     }
 
     /**
@@ -182,20 +141,17 @@ public class SimulatorManager {
      * @param deviceInfo
      *            Device information.
      */
-    public static void setDeviceInfo(String deviceInfo) {
-        SimulatorManagerNativeInterface.setDeviceInfo(deviceInfo);
-    }
+    public static native void setDeviceInfo(String deviceInfo)
+            throws InvalidArgsException, SimulatorException;
 
     /**
-     * API to get the device information asynchronously via callback
-     * using {@link IDeviceInfo}.
+     * API to search for devices in the network.
      *
      * @param listener
-     *            Interface for receiving the device information.
+     *            Listener for receiving the device information.
      */
-    public static void getDeviceInfo(IDeviceInfo listener) {
-        SimulatorManagerNativeInterface.getDeviceInfo(listener);
-    }
+    public static native void findDevices(DeviceListener listener)
+            throws InvalidArgsException, SimulatorException;
 
     /**
      * API to set the platform information.
@@ -203,18 +159,29 @@ public class SimulatorManager {
      * @param platformInfo
      *            {@link PlatformInfo} - Platform information.
      */
-    public static void setPlatformInfo(PlatformInfo platformInfo) {
-        SimulatorManagerNativeInterface.setPlatformInfo(platformInfo);
-    }
+    public static native void setPlatformInfo(PlatformInfo platformInfo)
+            throws InvalidArgsException, SimulatorException;
 
     /**
-     * API to get the platform information asynchronously via callback
-     * using {@link IPlatformInfo}..
+     * API to find all devices' platform information in the network.
      *
      * @param listener
-     *            Interface for receiving the platform information.
+     *            Listener for receiving the platform information.
      */
-    public static void getPlatformInfo(IPlatformInfo listener) {
-        SimulatorManagerNativeInterface.getPlatformInfo(listener);
-    }
+    public static native void getPlatformInformation(PlatformListener listener)
+            throws InvalidArgsException, SimulatorException;
+
+    /**
+     * API to set the listener for receiving log messages.
+     *
+     * @param logger
+     *            {@link ILogger} to receive the log messages.
+     */
+    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);
 }
\ No newline at end of file
diff --git a/service/simulator/java/sdk/src/org/oic/simulator/SimulatorManagerNativeInterface.java b/service/simulator/java/sdk/src/org/oic/simulator/SimulatorManagerNativeInterface.java
deleted file mode 100644 (file)
index 5fd2185..0000000
+++ /dev/null
@@ -1,161 +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 org.oic.simulator;
-
-import org.oic.simulator.clientcontroller.IFindResourceListener;
-import org.oic.simulator.serviceprovider.IResourceModelChangedListener;
-import org.oic.simulator.serviceprovider.SimulatorResourceServer;
-
-/**
- * This class provides a set of native functions for creation, discovery and
- * deletion of resources.
- */
-class SimulatorManagerNativeInterface {
-
-    /**
-     * Native function for creating a resource.
-     *
-     * @param configPath
-     *            Path to RAML configuration file.
-     * @param listener
-     *            Listener for receiving notifications whenever there is a
-     *            change in the resource model.
-     *
-     * @return {@link SimulatorResourceServer} object on success, otherwise
-     *         null.
-     *
-     * @throws InvalidArgsException
-     *             Thrown if the input parameters are empty.
-     * @throws SimulatorException
-     *             Thrown for other errors.
-     */
-    public static native SimulatorResourceServer createResource(
-            String configPath, IResourceModelChangedListener listener)
-            throws InvalidArgsException, SimulatorException;
-
-    /**
-     * Native function for creating several resources.
-     *
-     * @param configPath
-     *            Path to RAML configuration file.
-     * @param count
-     *            Number of instances.
-     * @param listener
-     *            Listener for receiving notifications whenever there is a
-     *            change in the resource model.
-     *
-     * @return An array of {@link SimulatorResourceServer} objects on success,
-     *         otherwise null.
-     *
-     * @throws InvalidArgsException
-     *             Thrown if the input parameters are empty.
-     * @throws SimulatorException
-     *             Thrown for other errors.
-     */
-    public static native SimulatorResourceServer[] createResources(
-            String configPath, int count, IResourceModelChangedListener listener)
-            throws InvalidArgsException, SimulatorException;
-
-    /**
-     * Native function to delete a specific resource.
-     *
-     * @param resource
-     *            {@link SimulatorResourceServer} object of the resource to be
-     *            deleted.
-     *
-     * @throws InvalidArgsException
-     *             Thrown if the input parameter is empty.
-     * @throws SimulatorException
-     *             Thrown for other errors.
-     */
-    public static native void deleteResource(SimulatorResourceServer resource)
-            throws InvalidArgsException, SimulatorException;
-
-    /**
-     * Native function to delete all resources or resources of a specific type.
-     *
-     * @param resourceType
-     *            Type of the resource.
-     *
-     * @throws InvalidArgsException
-     *             Thrown if the input parameter is empty.
-     * @throws SimulatorException
-     *             Thrown for other errors.
-     */
-    public static native void deleteResources(String resourceType)
-            throws SimulatorException;
-
-    /**
-     * Native function for discovering resources.
-     *
-     * @param resourceType
-     *            required resource type
-     * @param listener
-     *            Interface to receive the discovered remote resources.
-     *
-     * @throws InvalidArgsException
-     *             Thrown if the input parameter is empty.
-     * @throws SimulatorException
-     *             Thrown for other errors.
-     */
-    public static native void findResource(String resourceType,
-            IFindResourceListener listener) throws InvalidArgsException,
-            SimulatorException;
-
-    /**
-     * Native function to set the logger listener for receiving the log messages
-     * from native layer.
-     *
-     * @param logger
-     *            Interface to receive log.
-     */
-    public static native void setLogger(ILogger logger);
-
-    /**
-     * Native function to set the device information.
-     *
-     * @param deviceInfo
-     *            Device information.
-     */
-    public static native void setDeviceInfo(String deviceInfo);
-
-    /**
-     * Native function to get the device information asynchronously via the
-     * listener.
-     *
-     * @param listener
-     *            Interface for receiving the device information.
-     */
-    public static native void getDeviceInfo(IDeviceInfo listener);
-
-    /**
-     * Native function to set the platform information.
-     *
-     * @param platformInfo
-     *            Platform information.
-     */
-    public static native void setPlatformInfo(PlatformInfo platformInfo);
-
-    /**
-     * Native function to get the platform information asynchronously via the
-     * listener.
-     *
-     * @param listener
-     *            Interface for receiving the platform information.
-     */
-    public static native void getPlatformInfo(IPlatformInfo listener);
-}
\ No newline at end of file
diff --git a/service/simulator/java/sdk/src/org/oic/simulator/SimulatorResourceAttribute.java b/service/simulator/java/sdk/src/org/oic/simulator/SimulatorResourceAttribute.java
new file mode 100644 (file)
index 0000000..1c36904
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * 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 org.oic.simulator;
+
+/**
+ * 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 AttributeProperty mProperty = null;
+
+    /**
+     * Constructs {@SimulatorResourceAttribute} with attribute name, value and its property.
+     *
+     * @param name
+     *            Name of the attribute.
+     * @param value
+     *            Value of the attribute.
+     * @param property
+     *            Property of attribute value.
+     */
+    public SimulatorResourceAttribute(String name, AttributeValue value, AttributeProperty property) {
+        mName = new String(name);
+        mValue = value;
+        mProperty = property;
+    }
+
+    /**
+     * Constructs {@SimulatorResourceAttribute} with attribute name, value.
+     *
+     * @param name
+     *            Name of the attribute.
+     * @param value
+     *            Value of the attribute.
+     */
+    public SimulatorResourceAttribute(String name, AttributeValue value) {
+        mName = new String(name);
+        mValue = value;
+        mProperty = null;
+    }
+
+    /**
+     * API to get name of attribute.
+     *
+     * @return Attribute's name.
+     */
+    public String name() {
+        return mName;
+    }
+
+    /**
+     * API to get value of attribute.
+     *
+     * @return Attribute's value {@AttributeValue}.
+     */
+    public AttributeValue value() {
+        return mValue;
+    }
+
+    /**
+     * API to get propety of attribute's value.
+     *
+     * @return Attribute's value property{@AttributeProperty}.
+     */
+    public AttributeProperty property() {
+        return mProperty;
+    }
+}
index 63961e9..b5fcdb5 100644 (file)
 
 package org.oic.simulator;
 
-import org.oic.simulator.ResourceAttribute;
+import java.util.HashMap;
 import java.util.Map;
 
 /**
- * This class represents the resource model of a resource and it provides a set
- * of native methods for accessing the resource model.
+ * This class represents the resource model of a resource.
  */
 public class SimulatorResourceModel {
 
+    private Map<String, AttributeValue> mValues = null;
+    private Map<String, AttributeProperty> mProperties = null;
+
     /**
-     * Constructor for creating a native resource model object. Client requests
-     * such as PUT and POST uses this method for passing the new/updated
-     * resource model.
+     * Constructs new {@SimulatorResourceModel} object.
      */
     public SimulatorResourceModel() {
-        create();
+        mValues = new HashMap<>();
+        mProperties = new HashMap<>();
     }
 
     /**
-     * API to add an attribute of type integer.
+     * API to add an attribute to resource model.
      *
-     * @param name
-     *            Name of the attribute
+     * @param attrName
+     *            Name of the attribute.
      * @param value
-     *            Value of the attribute
+     *            Value of the attribute.
      *
      * @throws InvalidArgsException
-     *             This exception will be thrown if the attribute name is
-     *             invalid.
-     * @throws SimulatorException
-     *             This exception will be thrown either if the resource model is
-     *             not found or for some general errors.
+     *             This exception will be thrown on invalid input.
      */
-    public native void addAttributeInt(String name, int value)
-            throws InvalidArgsException, SimulatorException;
+    public void addAttribute(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 add an attribute of type double.
+     * API to add an attribute to resource model.
      *
-     * @param name
-     *            Name of the attribute
-     * @param value
-     *            Value of the attribute
+     * @param attribute
+     *            {@link SimulatorResourceAttribute} to be add to resource model.
      *
      * @throws InvalidArgsException
-     *             This exception will be thrown if the attribute name is
-     *             invalid.
-     * @throws SimulatorException
-     *             This exception will be thrown either if the resource model is
-     *             not found or for some general errors.
+     *             This exception will be thrown on invalid input.
      */
-    public native void addAttributeDouble(String name, double value)
-            throws InvalidArgsException, SimulatorException;
+    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());
+    }
 
     /**
-     * API to add an attribute of type boolean.
+     * API to set attribute's property.
      *
-     * @param name
-     *            Name of the attribute
-     * @param value
-     *            Value of the attribute
+     * @param attrName
+     *            Name of the attribute.
+     * @param property
+     *            {@link AttributeProperty} to be set for attribute.
      *
      * @throws InvalidArgsException
-     *             This exception will be thrown if the attribute name is
-     *             invalid.
-     * @throws SimulatorException
-     *             This exception will be thrown either if the resource model is
-     *             not found or for some general errors.
+     *             This exception will be thrown on invalid input.
      */
-    public native void addAttributeBoolean(String name, boolean value)
-            throws InvalidArgsException, SimulatorException;
+    public void setAttributeProperty(String attrName, AttributeProperty property) throws InvalidArgsException {
+        if (null == attrName || attrName.isEmpty())
+            throw new InvalidArgsException("Invalid attribute!");
+
+        if (null == property)
+            throw new InvalidArgsException("Invalid attribute property!");
+
+        mProperties.put(attrName, property);
+    }
 
     /**
-     * API to add an attribute of type string.
-     *
-     * @param name
-     *            Name of the attribute
-     * @param value
-     *            Value of the attribute
+     * API to get all the attributes of resource model.
      *
-     * @throws InvalidArgsException
-     *             This exception will be thrown if the attribute name is
-     *             invalid.
-     * @throws SimulatorException
-     *             This exception will be thrown either if the resource model is
-     *             not found or for some general errors.
+     * @return Map of attributes with attribute name as key and its
+     *         corresponding {@link SimulatorResourceAttribute} as value.
      */
-    public native void addAttributeString(String name, String value)
-            throws InvalidArgsException, SimulatorException;
+    public Map<String, SimulatorResourceAttribute> getAttributes() {
+        if (mValues.size() == 0)
+            return null;
+
+        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()));
+            attributes.put(entry.getKey(), attribute);
+        }
+
+        return attributes;
+    }
 
     /**
-     * API to get number of attributes for this model.
+     * API to get attribute by name.
      *
-     * @return Number of attributes.
+     * @param attrName
+     *            Name of the attribute.
      *
-     * @throws SimulatorException
-     *             This exception will be thrown either if the resource model is
-     *             not found or for some general errors.
+     * @return {@link SimulatorResourceAttribute}.
      */
-    public native int size() throws SimulatorException;
+    public SimulatorResourceAttribute getAttribute(String attrName) {
+        if (mValues.containsKey(attrName)) {
+            SimulatorResourceAttribute attribute = new SimulatorResourceAttribute(
+                    attrName, mValues.get(attrName), mProperties.get(attrName));
+            return attribute;
+        }
+
+        return null;
+    }
 
     /**
-     * API for getting all attributes.
+     * API to check whether resource model has attribute.
      *
-     * @return Map of attributes with attribute name as the key and its
-     *         corresponding {@link ResourceAttribute} object as the value.
+     * @param attrName
+     *            Name of the attribute.
      *
-     * @throws SimulatorException
-     *             This exception will be thrown either if the resource model is
-     *             not found or for some general errors.
+     * @return true if resource model has an attribute with given name,
+     *               otherwise false.
      */
-    public native Map<String, ResourceAttribute> getAttributes()
-            throws SimulatorException;
+    public boolean containsAttribute(String attrName) {
+        if (mValues.containsKey(attrName))
+            return true;
+        return false;
+    }
 
     /**
-     * API to get attribute by its name.
+     * API to get value type information of attribute.
      *
-     * @param name
-     *            Name of the attribute
+     * @param attrName
+     *            Name of the attribute.
      *
-     * @return An object of {@link ResourceAttribute}.
+     * @return Attribute value type information {@AttributeValue.TypeInfo}.
+     */
+    public AttributeValue.TypeInfo getAttributeType(String attrName) {
+        if (mValues.containsKey(attrName))
+            return mValues.get(attrName).typeInfo();
+        return null;
+    }
+
+    /**
+     * API to remove attribute from resource model.
      *
-     * @throws InvalidArgsException
-     *             This exception will be thrown if the attribute does not
-     *             exist.
+     * @param attrName
+     *            Name of the attribute.
      *
-     * @throws SimulatorException
-     *             This exception will be thrown either if the resource model is
-     *             not found or for some general errors.
+     * @return true if resource model has attribute it is removed,
+     *               otherwise false.
      */
-    public native ResourceAttribute getAttribute(String name)
-            throws InvalidArgsException, SimulatorException;
+    public boolean removeAttribute(String attrName) {
+        if (mValues.containsKey(attrName)) {
+            mValues.remove(attrName);
+            if (mProperties.containsKey(attrName))
+                mProperties.remove(attrName);
+            return true;
+        }
 
-    private SimulatorResourceModel(long nativeHandle) {
-        this.nativeHandle = nativeHandle;
+        return false;
     }
 
-    @Override
-    protected void finalize() throws Throwable {
-        try {
-            dispose();
-        } finally {
-            super.finalize();
-        }
+    /**
+     * API to get number of attributes present in resource model.
+     *
+     * @return Number of attributes present in resource model.
+     */
+    public int size() {
+        return mValues.size();
     }
 
-    private native void create();
-
-    private native void dispose();
-
-    private long nativeHandle;
-}
\ No newline at end of file
+    // Methods used in native code
+    private SimulatorResourceModel(Map<String, AttributeValue> values,
+            Map<String, AttributeProperty> properties) {
+        mValues = values;
+        mProperties = properties;
+    }
+}
index 8e4b9eb..3268e45 100644 (file)
@@ -68,6 +68,7 @@ public enum SimulatorResult {
     SIMULATOR_UKNOWN_PROPERTY,
     SIMULATOR_TYPE_MISMATCH,
     SIMULATOR_BAD_VALUE,
+    SIMULATOR_BAD_OBJECT,
     /** Simulator specific error codes - END */
 
     SIMULATOR_ERROR;
  * limitations under the License.
  */
 
-package org.oic.simulator.clientcontroller;
+package org.oic.simulator.client;
 
-import org.oic.simulator.clientcontroller.SimulatorRemoteResource;
+import org.oic.simulator.client.SimulatorRemoteResource;
 
 /**
- * Provides interface for getting notification when resources are discovered in
+ * Listener for getting notification when resources are discovered in
  * network.
  */
-public interface IFindResourceListener {
+public interface FindResourceListener {
     /**
-     * This callback method will be called when resource is discovered in the
+     * Method will be called when resource is discovered in the
      * network.
      *
      * @param resource
      *            {@link SimulatorRemoteResource} object representing the
      *            resource discovered in the network.
      */
-    public void onResourceCallback(SimulatorRemoteResource resource);
+    public void onResourceFound(SimulatorRemoteResource resource);
 }
  * limitations under the License.
  */
 
-package org.oic.simulator.clientcontroller;
+package org.oic.simulator.client;
 
-import java.util.LinkedList;
 import java.util.Map;
+import java.util.Vector;
 
 import org.oic.simulator.InvalidArgsException;
 import org.oic.simulator.NoSupportException;
@@ -31,10 +31,36 @@ import org.oic.simulator.SimulatorResult;
  * Server. It comes with a well-defined contract or interface onto which you can
  * perform different operations or subscribe for event notifications.
  */
-public class SimulatorRemoteResource {
+public final class SimulatorRemoteResource {
+
+    private long           mNativeHandle;
+    private String         mUri;
+    private int            mConnType;
+    private String         mHost;
+    private String         mId;
+    private Vector<String> mResTypes;
+    private Vector<String> mResInterfaces;
+    private boolean        mIsObservable;
+
+    private native void dispose();
 
     private SimulatorRemoteResource(long nativeHandle) {
-        this.nativeHandle = nativeHandle;
+        mNativeHandle = nativeHandle;
+    }
+
+    @Override
+    protected void finalize() throws Throwable {
+        try {
+            dispose();
+        } catch (Throwable t) {
+            throw t;
+        } finally {
+            super.finalize();
+        }
+    }
+
+    public enum VerificationType {
+        GET, PUT, POST, DELETE;
     }
 
     /**
@@ -42,20 +68,11 @@ public class SimulatorRemoteResource {
      *
      * @return Resource URI
      */
-    public String getUri() {
+    public String getURI() {
         return mUri;
     }
 
     /**
-     * API to get the observe policy of this resource.
-     *
-     * @return True if the resource is observable, otherwise false.
-     */
-    public boolean getIsObservable() {
-        return mIsObservable;
-    }
-
-    /**
      * API to get the connectivity type for this resource.
      *
      * @return Connectivity type.
@@ -67,18 +84,18 @@ public class SimulatorRemoteResource {
     /**
      * API to get the list of resource types.
      *
-     * @return List of resource types.
+     * @return Array of resource types.
      */
-    public LinkedList<String> getResourceTypes() {
+    public Vector<String> getResourceTypes() {
         return mResTypes;
     }
 
     /**
      * API to get the list of resource interfaces.
      *
-     * @return List of resource interfaces.
+     * @return Array of resource interfaces.
      */
-    public LinkedList<String> getResourceInterfaces() {
+    public Vector<String> getResourceInterfaces() {
         return mResInterfaces;
     }
 
@@ -101,45 +118,19 @@ public class SimulatorRemoteResource {
     }
 
     /**
-     * API to start observing the resource.
-     *
-     * @param observeType
-     *            Allows the client to specify how it wants to observe.
-     * @param queryParamsMap
-     *            Map which can have the query parameter names and values.
-     * @param onObserveListener
-     *            The handler method which will be invoked with a map of
-     *            attribute names and values whenever there is a change in
-     *            resource model of the remote resource.
-     *
-     * @throws InvalidArgsException
-     *             This exception will be thrown if any parameter has invalid
-     *             values.
-     * @throws SimulatorException
-     *             This exception will be thrown for other errors.
-     */
-    public native void startObserve(SimulatorObserveType observeType,
-            Map<String, String> queryParamsMap,
-            IObserveListener onObserveListener) throws InvalidArgsException,
-            SimulatorException;
-
-    /**
-     * API to stop observing the resource.
+     * API to get the observe policy of this resource.
      *
-     * @throws InvalidArgsException
-     *             This exception will be thrown if the native remote resource
-     *             object is unavailable.
-     * @throws SimulatorException
-     *             This exception will be thrown for other errors.
+     * @return True if the resource is observable, otherwise false.
      */
-    public native void stopObserve() throws InvalidArgsException,
-            SimulatorException;
+    public boolean isObservable() {
+        return mIsObservable;
+    }
 
     /**
      * API to send GET request to the resource. Response will be notified
      * asynchronously via callback set for {@link IGetListener}.
      *
-     * @param queryParamsMap
+     * @param queryParams
      *            Map which can have the query parameter name and value.
      * @param onGetListener
      *            Event handler which will be invoked with the response for GET
@@ -148,20 +139,12 @@ public class SimulatorRemoteResource {
      * @throws InvalidArgsException
      *             This exception will be thrown if any parameter has invalid
      *             values.
-     * @throws NoSupportException
-     *             This exception will be thrown if we cannot send GET request
-     *             to the remote resource.
      * @throws SimulatorException
      *             This exception will be thrown for other errors.
      */
-    public void get(Map<String, String> queryParamsMap,
-            IGetListener onGetListener) throws InvalidArgsException,
-            NoSupportException, SimulatorException {
-        if (null == onGetListener)
-            throw new InvalidArgsException(
-                    SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
-                    "Parameter passed in invalid");
-        this.nativeGet(null, queryParamsMap, onGetListener);
+    public void get(Map<String, String> queryParams, GetResponseListener onGetListener)
+            throws InvalidArgsException, SimulatorException {
+        nativeGet(null, queryParams, onGetListener);
     }
 
     /**
@@ -170,7 +153,7 @@ public class SimulatorRemoteResource {
      *
      * @param resourceInterface
      *            Interface type of the resource to operate on.
-     * @param queryParamsMap
+     * @param queryParams
      *            Map which can have the query parameter name and value.
      * @param onGetListener
      *            Event handler which will be invoked with the response for GET
@@ -179,35 +162,26 @@ public class SimulatorRemoteResource {
      * @throws InvalidArgsException
      *             This exception will be thrown if any parameter has invalid
      *             values.
-     * @throws NoSupportException
-     *             This exception will be thrown if we cannot send GET request
-     *             to the remote resource.
      * @throws SimulatorException
      *             This exception will be thrown for other errors.
      */
-    public void get(String resourceInterface,
-            Map<String, String> queryParamsMap, IGetListener onGetListener)
-            throws InvalidArgsException, NoSupportException, SimulatorException {
-        if (null == resourceInterface || resourceInterface.isEmpty() || null == onGetListener)
-            throw new InvalidArgsException(
-                    SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
-                    "Parameter passed in invalid");
-        this.nativeGet(resourceInterface, queryParamsMap, onGetListener);
+    public void get(String resourceInterface, Map<String, String> queryParams,
+            GetResponseListener onGetListener) throws InvalidArgsException, SimulatorException {
+        if (null == resourceInterface || resourceInterface.isEmpty())
+            throw new InvalidArgsException(SimulatorResult.SIMULATOR_INVALID_PARAM,
+                    "Invalid resource interface!");
+        nativeGet(resourceInterface, queryParams, onGetListener);
     }
 
-    private native void nativeGet(String resourceInterface,
-            Map<String, String> queryParamsMap, IGetListener onGetListener)
-            throws InvalidArgsException, NoSupportException, SimulatorException;
-
     /**
      * API to send PUT request to the resource. Response will be notified
      * asynchronously via callback set for {@link IPutListener}.
      *
+     * @param queryParams
+     *            Map which can have the query parameter name and value.
      * @param representation
      *            {@link SimulatorResourceModel} holding the representation of
      *            the resource.
-     * @param queryParamsMap
-     *            Map which can have the query parameter name and value.
      * @param onPutListener
      *            Event handler which will be invoked with the response for PUT
      *            request with a map of attribute name and values.
@@ -215,20 +189,12 @@ public class SimulatorRemoteResource {
      * @throws InvalidArgsException
      *             This exception will be thrown if any parameter has invalid
      *             value.
-     * @throws NoSupportException
-     *             This exception will be thrown if we cannot send PUT request
-     *             to the remote resource.
      * @throws SimulatorException
      *             This exception will be thrown for other errors.
      */
-    public void put(SimulatorResourceModel representation,
-            Map<String, String> queryParamsMap, IPutListener onPutListener)
-            throws InvalidArgsException, NoSupportException, SimulatorException {
-        if (null == representation || null == onPutListener)
-            throw new InvalidArgsException(
-                    SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
-                    "Parameter passed in invalid");
-        this.nativePut(null, representation, queryParamsMap, onPutListener);
+    public void put(Map<String, String> queryParams, SimulatorResourceModel representation,
+            PutResponseListener onPutListener) throws InvalidArgsException, SimulatorException {
+        nativePut(null, queryParams, representation, onPutListener);
     }
 
     /**
@@ -237,11 +203,11 @@ public class SimulatorRemoteResource {
      *
      * @param resourceInterface
      *            Interface type of the resource to operate on.
+     * @param queryParams
+     *            Map which can have the query parameter name and value.
      * @param representation
      *            {@link SimulatorResourceModel} holding the representation of
      *            the resource.
-     * @param queryParamsMap
-     *            Map which can have the query parameter name and value.
      * @param onPutListener
      *            Event handler which will be invoked with the response for PUT
      *            request with a map of attribute name and values.
@@ -249,38 +215,27 @@ public class SimulatorRemoteResource {
      * @throws InvalidArgsException
      *             This exception will be thrown if any parameter has invalid
      *             value.
-     * @throws NoSupportException
-     *             This exception will be thrown if we cannot send PUT request
-     *             to the remote resource.
      * @throws SimulatorException
      *             This exception will be thrown for other errors.
      */
-    public void put(String resourceInterface,
-            SimulatorResourceModel representation,
-            Map<String, String> queryParamsMap, IPutListener onPutListener)
-            throws InvalidArgsException, NoSupportException, SimulatorException {
-        if (null == resourceInterface || resourceInterface.isEmpty() ||
-            null == representation || null == onPutListener)
-            throw new InvalidArgsException(
-                    SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
-                    "Parameter passed in invalid");
-        this.nativePut(resourceInterface, representation, queryParamsMap, onPutListener);
+    public void put(String resourceInterface, Map<String, String> queryParams,
+            SimulatorResourceModel representation, PutResponseListener onPutListener)
+            throws InvalidArgsException, SimulatorException {
+        if (null == resourceInterface || resourceInterface.isEmpty())
+            throw new InvalidArgsException(SimulatorResult.SIMULATOR_INVALID_PARAM,
+                    "Invalid resource interface!");
+        nativePut(resourceInterface, queryParams, representation, onPutListener);
     }
 
-    private native void nativePut(String resourceInterface,
-            SimulatorResourceModel representation,
-            Map<String, String> queryParamsMap, IPutListener onPutListener)
-            throws InvalidArgsException, NoSupportException, SimulatorException;
-
     /**
      * API to send POST request to the resource. Response will be notified
      * asynchronously via callback set for {@link IPostListener}.
      *
+     * @param queryParams
+     *            Map which can have the query parameter name and value.
      * @param representation
      *            {@link SimulatorResourceModel} holding the representation of
-     *            the resource
-     * @param queryParamsMap
-     *            Map which can have the query parameter name and value
+     *            the resource.
      * @param onPostListener
      *            Event handler which will be invoked with the response for POST
      *            request with a map of attribute name and values.
@@ -288,20 +243,12 @@ public class SimulatorRemoteResource {
      * @throws InvalidArgsException
      *             This exception will be thrown if any parameter has invalid
      *             value.
-     * @throws NoSupportException
-     *             This exception will be thrown if we cannot send POST request
-     *             on the remote resource.
      * @throws SimulatorException
      *             This exception will be thrown for other errors.
      */
-    public void post(SimulatorResourceModel representation,
-            Map<String, String> queryParamsMap, IPostListener onPostListener)
-            throws InvalidArgsException, NoSupportException, SimulatorException {
-        if (null == representation || null == onPostListener)
-            throw new InvalidArgsException(
-                    SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
-                    "Parameter passed in invalid");
-        this.nativePost(null, representation, queryParamsMap, onPostListener);
+    public void post(Map<String, String> queryParams, SimulatorResourceModel representation,
+            PostResponseListener onPostListener) throws InvalidArgsException, SimulatorException {
+        nativePost(null, queryParams, representation, onPostListener);
     }
 
     /**
@@ -310,11 +257,11 @@ public class SimulatorRemoteResource {
      *
      * @param resourceInterface
      *            Interface type of the resource to operate on.
+     * @param queryParams
+     *            Map which can have the query parameter name and value.
      * @param representation
      *            {@link SimulatorResourceModel} holding the representation of
      *            the resource.
-     * @param queryParamsMap
-     *            Map which can have the query parameter name and value.
      * @param onPostListener
      *            Event handler which will be invoked with the response for POST
      *            request with a map of attribute name and values.
@@ -322,50 +269,74 @@ public class SimulatorRemoteResource {
      * @throws InvalidArgsException
      *             This exception will be thrown if any parameter has invalid
      *             value.
-     * @throws NoSupportException
-     *             This exception will be thrown if we cannot send POST request
-     *             on the remote resource.
      * @throws SimulatorException
      *             This exception will be thrown for other errors.
      */
-    public void post(String resourceInterface,
-            SimulatorResourceModel representation,
-            Map<String, String> queryParamsMap, IPostListener onPostListener)
-            throws InvalidArgsException, NoSupportException, SimulatorException {
-        if (null == resourceInterface || resourceInterface.isEmpty() ||
-            null == representation || null == onPostListener)
-            throw new InvalidArgsException(
-                SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
-                "Parameter passed in invalid");
-        this.nativePost(resourceInterface, representation, queryParamsMap, onPostListener);
+    public void post(String resourceInterface, Map<String, String> queryParams,
+            SimulatorResourceModel representation, PostResponseListener onPostListener)
+            throws InvalidArgsException, SimulatorException {
+        if (null == resourceInterface || resourceInterface.isEmpty())
+            throw new InvalidArgsException(SimulatorResult.SIMULATOR_INVALID_PARAM,
+                    "Invalid resource interface!");
+        nativePost(resourceInterface, queryParams, representation, onPostListener);
     }
 
-    private native void nativePost(String resourceInterface,
-            SimulatorResourceModel representation,
-            Map<String, String> queryParamsMap, IPostListener onPostListener)
-            throws InvalidArgsException, NoSupportException, SimulatorException;
+    /**
+     * API to start observing the resource.
+     *
+     * @param queryParams
+     *            Map which can have the query parameter names and values.
+     * @param onObserveListener
+     *            The handler method which will be invoked with a map of
+     *            attribute names and values whenever there is a change in
+     *            resource model of the remote resource.
+     *
+     * @throws InvalidArgsException
+     *             This exception will be thrown if any parameter has invalid
+     *             values.
+     * @throws SimulatorException
+     *             This exception will be thrown for other errors.
+     */
+    public native void startObserve(Map<String, String> queryParams,
+            ObserveNotificationListener onObserveListener) throws InvalidArgsException,
+            SimulatorException;
 
     /**
-     * API to provide remote resource configure information,
-     * which is required for using automation feature.
+     * API to stop observing the resource.
+     *
+     * @throws InvalidArgsException
+     *             This exception will be thrown if the native remote resource
+     *             object is unavailable.
+     * @throws SimulatorException
+     *             This exception will be thrown for other errors.
+     */
+    public native void stopObserve() throws InvalidArgsException, SimulatorException;
+
+    /**
+     * API to provide remote resource configure information, which is required
+     * for using automation feature.
      *
      * @param path
      *            Path to RAML file.
      *
+     * @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 void 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 file provided from {@link setConfigInfo}.
-     * This verifies response received as well.
+     * API to send multiple requests for the resource, based on the configure
+     * file provided from {@link setConfigInfo}. This verifies response received
+     * as well.
      *
-     * @param requestType
+     * @param type
      *            Request type to verify.
      * @param onVerifyListener
      *            This event handler will be invoked with the current status of
@@ -385,51 +356,146 @@ public class SimulatorRemoteResource {
      * @throws SimulatorException
      *             This exception will be thrown for other errors.
      */
-    public int startVerification(SimulatorVerificationType requestType,
-            IVerificationListener onVerifyListener)
+    public int startVerification(VerificationType type,
+            VerificationListener onVerifyListener)
             throws InvalidArgsException, NoSupportException,
             OperationInProgressException, SimulatorException {
-        return startVerification(requestType.ordinal(), onVerifyListener);
+        return startVerification(type.ordinal(), onVerifyListener);
     }
 
     /**
-     * API to stop sending requests which has been started using {@link setConfigInfo}.
+     * API to stop sending requests which has been started using
+     * {@link setConfigInfo}.
      *
      * @param id
      *            Automation ID.
      *
      * @throws InvalidArgsException
      *             Thrown if the automation ID is invalid.
-     * @throws NoSupportException
-     *             Thrown if the resource is not configured with RAML.
      * @throws SimulatorException
      *             Thrown for other errors.
      */
-    public native void stopVerification(int id) throws InvalidArgsException,
-            NoSupportException, SimulatorException;
+    public native void stopVerification(int id)
+            throws InvalidArgsException, SimulatorException;
 
-    private native int startVerification(int requestType,
-            IVerificationListener onVerifyListener)
-            throws InvalidArgsException, NoSupportException,
-            OperationInProgressException, SimulatorException;
+    /**
+     * Listener for receiving asynchronous response for GET request.
+     */
+    public interface GetResponseListener {
+        /**
+         * Method will be called when response for GET request arrives.
+         *
+         * @param uid
+         *            Unique Id of the resource.
+         * @param result
+         *            Error code {@link SimulatorResult}.
+         * @param resourceModel
+         *            {@link SimulatorResourceModel}.
+         */
+        public void onGetResponse(String uid, SimulatorResult result,
+                SimulatorResourceModel resourceModel);
+    }
 
-    @Override
-    protected void finalize() throws Throwable {
-        try {
-            dispose();
-        } finally {
-            super.finalize();
-        }
+    /**
+     * Listener for receiving asynchronous response for PUT request.
+     */
+    public interface PutResponseListener {
+        /**
+         * Method will be called when response for PUT request arrives.
+         *
+         * @param uid
+         *            Unique Id of the resource.
+         * @param result
+         *            Error code {@link SimulatorResult}.
+         * @param resourceModel
+         *            {@link SimulatorResourceModel}.
+         */
+        public void onPutResponse(String uid, SimulatorResult result,
+                SimulatorResourceModel resourceModel);
     }
 
-    private native void dispose();
+    /**
+     * Listener for receiving asynchronous response for POST request.
+     */
+    public interface PostResponseListener {
+        /**
+         * Method will be called when response for POST request arrives.
+         *
+         * @param uid
+         *            Unique Id of the resource.
+         * @param result
+         *            Error code {@link SimulatorResult}.
+         * @param resourceModel
+         *            {@link SimulatorResourceModel}.
+         */
+        public void onPostResponse(String uid, SimulatorResult result,
+                SimulatorResourceModel resourceModel);
+    }
+
+    /**
+     * Listener for getting asynchronous notification whenever remote resource's
+     * representation gets changed.
+     */
+    public interface ObserveNotificationListener {
+        /**
+         * 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.
+         */
+        public void onObserveNotification(String uid,
+                SimulatorResourceModel resourceModel, int sequenceNumber);
+    }
+
+    /**
+     * Listener for receiving the verification session status.
+     */
+    public interface VerificationListener {
+        /**
+         * Called when the verification request is accepted and started.
+         *
+         * @param uid
+         *            Unique Id of the resource.
+         * @param id
+         *            Verification Id.
+         */
+        public void onVerificationStarted(String uid, int id);
+
+        /**
+         * Called when the verification is stopped before its completion.
+         *
+         * @param uid
+         *            Unique Id of the resource.
+         * @param id
+         *            Verification Id.
+         */
+        public void onVerificationAborted(String uid, int id);
+
+        /**
+         * Called when the verification is done.
+         *
+         * @param uid
+         *            Unique Id of the resource.
+         * @param id
+         *            Verification Id.
+         */
+        public void onVerificationCompleted(String uid, int id);
+    }
+
+
+    private native void nativeGet(String resourceInterface,
+            Map<String, String> queryParamsMap, GetResponseListener onGetListener);
+
+    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 long               nativeHandle;
-    private String             mUri;
-    private int                mConnType;
-    private String             mHost;
-    private String             mId;
-    private LinkedList<String> mResTypes;
-    private LinkedList<String> mResInterfaces;
-    private boolean            mIsObservable;
+    private native int startVerification(int type, VerificationListener onVerifyListener);
 }
diff --git a/service/simulator/java/sdk/src/org/oic/simulator/clientcontroller/IGetListener.java b/service/simulator/java/sdk/src/org/oic/simulator/clientcontroller/IGetListener.java
deleted file mode 100644 (file)
index db3e63c..0000000
+++ /dev/null
@@ -1,45 +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 org.oic.simulator.clientcontroller;
-
-import org.oic.simulator.SimulatorResourceModel;
-
-/**
- * Interface for receiving response for GET request. An IGetListener can be
- * registered via the resource get call. Event listeners are notified
- * asynchronously.
- */
-public interface IGetListener {
-    /**
-     * This method will be called when response from the remote resource for GET
-     * request arrives.
-     *
-     * @param uId
-     *            Unique Id of the resource.
-     * @param representation
-     *            {@link SimulatorResourceModel}.
-     */
-    public void onGetCompleted(String uId, SimulatorResourceModel representation);
-
-    /**
-     * Called when there is an error in GET request.
-     *
-     * @param ex
-     *            Error information.
-     */
-    public void onGetFailed(Throwable ex);
-}
diff --git a/service/simulator/java/sdk/src/org/oic/simulator/clientcontroller/IObserveListener.java b/service/simulator/java/sdk/src/org/oic/simulator/clientcontroller/IObserveListener.java
deleted file mode 100644 (file)
index 30ed0fb..0000000
+++ /dev/null
@@ -1,49 +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 org.oic.simulator.clientcontroller;
-
-import org.oic.simulator.SimulatorResourceModel;
-
-/**
- * Provides interface for getting notification when resource model of an
- * observed resource gets changed. An IObserveListener can be registered via the
- * SimulatorRemoteResource observe call. Event listeners are notified
- * asynchronously.
- */
-public interface IObserveListener {
-    /**
-     * 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 representation
-     *            {@link SimulatorResourceModel}.
-     * @param sequenceNumber
-     *            Sequential number for ordering the model change notifications.
-     */
-    public void onObserveCompleted(String uId,
-            SimulatorResourceModel representation, int sequenceNumber);
-
-    /**
-     * Called when there is an error in observe request.
-     *
-     * @param ex
-     *            Error information.
-     */
-    public void onObserveFailed(Throwable ex);
-}
diff --git a/service/simulator/java/sdk/src/org/oic/simulator/clientcontroller/IPostListener.java b/service/simulator/java/sdk/src/org/oic/simulator/clientcontroller/IPostListener.java
deleted file mode 100644 (file)
index 9949ac9..0000000
+++ /dev/null
@@ -1,46 +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 org.oic.simulator.clientcontroller;
-
-import org.oic.simulator.SimulatorResourceModel;
-
-/**
- * Interface for receiving response for POST request. An IPostListener can be
- * registered via the resource post call. Event listeners are notified
- * asynchronously.
- */
-public interface IPostListener {
-    /**
-     * This method will be called when response from the remote resource for
-     * POST request arrives.
-     *
-     * @param uId
-     *            Unique Id of the resource.
-     * @param representation
-     *            {@link SimulatorResourceModel}.
-     */
-    public void onPostCompleted(String uId,
-            SimulatorResourceModel representation);
-
-    /**
-     * Called when there is an error in POST request.
-     *
-     * @param ex
-     *            Error information.
-     */
-    public void onPostFailed(Throwable ex);
-}
diff --git a/service/simulator/java/sdk/src/org/oic/simulator/clientcontroller/IPutListener.java b/service/simulator/java/sdk/src/org/oic/simulator/clientcontroller/IPutListener.java
deleted file mode 100644 (file)
index 91a44d9..0000000
+++ /dev/null
@@ -1,46 +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 org.oic.simulator.clientcontroller;
-
-import org.oic.simulator.SimulatorResourceModel;
-
-/**
- * Interface for receiving response for PUT request. An IPutListener can be
- * registered via the resource put call. Event listeners are notified
- * asynchronously.
- */
-public interface IPutListener {
-    /**
-     * This method will be called when response from the remote resource for PUT
-     * request arrives.
-     *
-     * @param uId
-     *            Unique Id of the resource.
-     * @param representation
-     *            {@link SimulatorResourceModel}.
-     */
-    public void onPutCompleted(String uId, SimulatorResourceModel representation);
-
-    /**
-     * Called when there is an error in PUT request.
-     *
-     * @param ex
-     *            Error information.
-     */
-    public void onPutFailed(Throwable ex);
-}
-
diff --git a/service/simulator/java/sdk/src/org/oic/simulator/clientcontroller/IVerificationListener.java b/service/simulator/java/sdk/src/org/oic/simulator/clientcontroller/IVerificationListener.java
deleted file mode 100644 (file)
index e69cdd6..0000000
+++ /dev/null
@@ -1,54 +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 org.oic.simulator.clientcontroller;
-
-/**
- * Interface for receiving the verification status via callback. An
- * IVerificationListener can be registered via the resource startVerification
- * call. Event listeners are notified asynchronously.
- */
-public interface IVerificationListener {
-    /**
-     * Called when the verification request is accepted and started.
-     *
-     * @param uId
-     *            Unique Id of the resource.
-     * @param id
-     *            Verification Id.
-     */
-    public void onVerificationStarted(String uId, int id);
-
-    /**
-     * Called when the verification is stopped before its completion.
-     *
-     * @param uId
-     *            Unique Id of the resource.
-     * @param id
-     *            Verification Id.
-     */
-    public void onVerificationAborted(String uId, int id);
-
-    /**
-     * Called when the verification is done.
-     *
-     * @param uId
-     *            Unique Id of the resource.
-     * @param id
-     *            Verification Id.
-     */
-    public void onVerificationCompleted(String uId, int id);
-}
diff --git a/service/simulator/java/sdk/src/org/oic/simulator/clientcontroller/SimulatorVerificationType.java b/service/simulator/java/sdk/src/org/oic/simulator/clientcontroller/SimulatorVerificationType.java
deleted file mode 100644 (file)
index ccb0c36..0000000
+++ /dev/null
@@ -1,55 +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 org.oic.simulator.clientcontroller;
-
-/**
- * Types of automatic verification.
- */
-public enum SimulatorVerificationType {
-    RQ_TYPE_GET(0), RQ_TYPE_PUT(1), RQ_TYPE_POST(2), RQ_TYPE_DELETE(3);
-
-    private int value;
-
-    private SimulatorVerificationType(int value) {
-        this.value = value;
-    }
-
-    public int getValue() {
-        return this.value;
-    }
-
-    /**
-     * Method to get the {@link SimulatorVerificationType} from an integer
-     * value.
-     *
-     * @param value
-     *            Integral value of {@link SimulatorVerificationType}.
-     * @return {@link SimulatorVerificationType} corresponding to the given
-     *         value.
-     */
-    public static SimulatorVerificationType getVerificationType(int value) {
-        SimulatorVerificationType result = null;
-        SimulatorVerificationType[] types = SimulatorVerificationType.values();
-        for (SimulatorVerificationType type : types) {
-            if (type.getValue() == value) {
-                result = type;
-                break;
-            }
-        }
-        return result;
-    }
-}
  * limitations under the License.
  */
 
-package org.oic.simulator.serviceprovider;
+package org.oic.simulator.server;
 
 /**
  * Class which represents the details of an observer.
  */
-public class ObserverInfo {
+public class Observer {
 
-    private int    id;
-    private String address;
-    private int    port;
+    private int    mId;
+    private String mAddress;
+    private int    mPort;
 
-    private ObserverInfo(int id, String address, int port) {
-        this.id = id;
-        this.address = address;
-        this.port = port;
+    private Observer(int id, String address, int port) {
+        mId = id;
+        mAddress = address;
+        mPort = port;
     }
 
     /**
@@ -37,7 +37,7 @@ public class ObserverInfo {
      * @return Observer's Id.
      */
     public int getId() {
-        return id;
+        return mId;
     }
 
     /**
@@ -46,7 +46,7 @@ public class ObserverInfo {
      * @return Observer's device address.
      */
     public String getAddress() {
-        return address;
+        return mAddress;
     }
 
     /**
@@ -55,6 +55,6 @@ public class ObserverInfo {
      * @return Observer's port number.
      */
     public int getPort() {
-        return port;
+        return mPort;
     }
 }
diff --git a/service/simulator/java/sdk/src/org/oic/simulator/server/SimulatorCollectionResource.java b/service/simulator/java/sdk/src/org/oic/simulator/server/SimulatorCollectionResource.java
new file mode 100644 (file)
index 0000000..39a3269
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * 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 org.oic.simulator.server;
+
+import java.util.Vector;
+
+import org.oic.simulator.InvalidArgsException;
+import org.oic.simulator.SimulatorException;
+
+public final class SimulatorCollectionResource extends SimulatorResource {
+
+    private SimulatorCollectionResource(long nativeHandle) {
+        mNativeHandle = nativeHandle;
+    }
+
+    /**
+    * 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.
+    */
+    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.
+    */
+    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.
+    */
+    public native Vector<SimulatorResource> getChildResource()
+            throws SimulatorException;
+}
diff --git a/service/simulator/java/sdk/src/org/oic/simulator/server/SimulatorResource.java b/service/simulator/java/sdk/src/org/oic/simulator/server/SimulatorResource.java
new file mode 100644 (file)
index 0000000..0211955
--- /dev/null
@@ -0,0 +1,322 @@
+/*
+ * 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 org.oic.simulator.server;
+
+import java.util.Vector;
+
+import org.oic.simulator.InvalidArgsException;
+import org.oic.simulator.SimulatorException;
+import org.oic.simulator.SimulatorResourceModel;
+
+public class SimulatorResource {
+
+    private native void dispose();
+
+    protected long mNativeHandle;
+
+    protected SimulatorResource(){}
+
+    @Override
+    protected void finalize() throws Throwable {
+        try {
+            dispose();
+        } catch (Throwable t) {
+            throw t;
+        } finally {
+            super.finalize();
+        }
+    }
+
+    public enum Type {
+        SINGLE, COLLECTION
+    }
+
+    public enum AutoUpdateType {
+        ONE_TIME, REPEAT
+    }
+
+    /**
+     * API to get the name of the resource.
+     *
+     * @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.
+     */
+    public native String getName() throws SimulatorException;
+
+    /**
+     * 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.
+     */
+    public native Type getType() throws SimulatorException;
+
+    /**
+     * API to get the resource URI.
+     *
+     * @return Resource URI.
+     *
+     * @throws SimulatorException
+     *             This exception will be thrown if the native resource object does
+     *             not exist or for some general errors.
+     */
+    public native String getURI() throws SimulatorException;
+
+    /**
+     * API to get the resource type.
+     *
+     * @return Resource type.
+     *
+     * @throws SimulatorException
+     *             This exception will be thrown if the native resource object does
+     *             not exist or for some general errors.
+     */
+    public native String getResourceType() throws SimulatorException;
+
+    /**
+     * API to get the interfaces resource is bound with.
+     *
+     * @return Interface type.
+     *
+     * @throws SimulatorException
+     *             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 set the name of the resource.
+     *
+     * @param name - Name to be set.
+     *
+     * @throws InvalidArgsException
+     *              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.
+     */
+    public native void setName(String name) throws InvalidArgsException, SimulatorException;
+
+    /**
+     * API to set the resource URI.
+     *
+     * @param uri - URI to be set.
+     *
+     * @throws InvalidArgsException
+     *              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.
+     */
+    public native void setURI(String uri) throws InvalidArgsException, SimulatorException;
+
+    /**
+     * API to set the resource type.
+     *
+     * @param resourceType - resource type string.
+     *
+     * @throws InvalidArgsException
+     *              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.
+     */
+    public native void setResourceType(String resourceType) throws InvalidArgsException, SimulatorException;
+
+    /**
+     * API to add interface type for resource.
+     *
+     * @param interfaceType - interface to be added for resource.
+     *
+     * @throws InvalidArgsException
+     *              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.
+     */
+    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.
+     *
+     * @throws SimulatorException
+     *             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.
+     *
+     * @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.
+     *
+     * @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 start the resource.
+     *
+     * @throws SimulatorException
+     *             This exception will be thrown if the native resource object does
+     *             not exist or for some general errors.
+     */
+    public native void start() throws SimulatorException;
+
+    /**
+     * 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.
+     */
+    public native void stop() throws SimulatorException;
+
+    /**
+     * API to get observers which are registered with resource.
+     *
+     * @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.
+     */
+    public native Vector<Observer> getObservers() throws SimulatorException;
+
+    /**
+     * API to notify current resource model to specific observer.
+     *
+     * @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.
+     */
+    public native void notifyObserver(int observerId) throws SimulatorException;
+
+    /**
+     * 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.
+     */
+    public native void notifyAllObservers() throws SimulatorException;
+
+    /**
+     * Listener for receiving notification when observer is registered or unregistered
+     * with the resource.
+     */
+    public interface ObserverListener {
+        /**
+         * Method will be invoked when a observer is registered with resource.
+         *
+         * @param uri
+         *            URI of the resource.
+         * @param observer
+         *            {@link ObserverInfo} object containing the details of
+         *            observer.
+         */
+        public void onObserverAdded(String resourceURI, Observer observer);
+
+        /**
+         * Method will be invoked when a observer is Unregistered with resource.
+         *
+         * @param resourceURI
+         *            URI of the resource.
+         * @param observer
+         *            {@link ObserverInfo} object containing the details of
+         *            observer.
+         */
+        public void onObserverRemoved(String resourceURI, Observer observer);
+    }
+
+    /**
+     * Listener for receiving notification on completion of
+     * automatically updating attribute value from its range or
+     * value set property.
+     */
+    public interface AutoUpdateListener {
+        /**
+         * Method for receiving automation complete notifications.
+         *
+         * @param uri
+         *            URI of resource.
+         * @param id
+         *            Identifier for auto resource/attribute update session.
+         */
+        public void onUpdateComplete(String uri, int id);
+    }
+
+    /**
+     * Listener for receiving notifications whenever there is a change in the
+     * resource model.
+     */
+    public interface ResourceModelChangeListener {
+        /**
+         * 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);
+    }
+}
diff --git a/service/simulator/java/sdk/src/org/oic/simulator/server/SimulatorSingleResource.java b/service/simulator/java/sdk/src/org/oic/simulator/server/SimulatorSingleResource.java
new file mode 100644 (file)
index 0000000..0ac7715
--- /dev/null
@@ -0,0 +1,183 @@
+/*
+ * 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 org.oic.simulator.server;
+
+import org.oic.simulator.AttributeValue;
+import org.oic.simulator.InvalidArgsException;
+import org.oic.simulator.SimulatorException;
+import org.oic.simulator.SimulatorResourceAttribute;
+import org.oic.simulator.SimulatorResourceModel;
+
+public final class SimulatorSingleResource extends SimulatorResource {
+
+    private SimulatorSingleResource(long nativeHandle) {
+        mNativeHandle = nativeHandle;
+    }
+
+    /**
+     * 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.
+     *
+     * @throws InvalidArgsException
+     *             This exception will be thrown if the attribute name is
+     *             invalid.
+     * @throws SimulatorException
+     *             This exception will be thrown either if the resource model is
+     *             not found or for some general errors.
+     */
+    public native SimulatorResourceAttribute getAttribute(String attrName)
+            throws InvalidArgsException, SimulatorException;
+
+    /**
+     * API to add an attribute to resource's representation model.
+     *
+     * @param attrName
+     *            Name of the attribute.
+     * @param attribute
+     *            Attribute to be added to resource's representation model.
+     *
+     * @throws InvalidArgsException
+     *             This exception will be thrown on invalid input.
+     * @throws SimulatorException
+     *             This exception will be thrown for other errors.
+     */
+    public native void addAttribute(SimulatorResourceAttribute attribute)
+            throws InvalidArgsException, SimulatorException;
+
+    /**
+     * API to update the value of an attribute.
+     *
+     * @param attrName
+     *            Name of the attribute.
+     * @param value
+     *            New value of the attribute.
+     *
+     * @throws InvalidArgsException
+     *             This exception will be thrown on invalid input.
+     * @throws SimulatorException
+     *             This exception will be thrown for other errors.
+     */
+    public native void updateAttribute(String attrName, AttributeValue value)
+            throws InvalidArgsException, SimulatorException;
+
+    /**
+     * API to remove an attribute from the simulated resource.
+     *
+     * @param attrName
+     *            Name of the attribute to be deleted.
+     *
+     * @throws InvalidArgsException
+     *             This exception will be thrown on invalid input.
+     * @throws SimulatorException
+     *             This exception will be thrown for other errors.
+     */
+    public native void removeAttribute(String attrName)
+            throws InvalidArgsException, SimulatorException;
+
+    /**
+     * API to start the resource level automation. This automation involves
+     * automatically updating all the possible values for all the attributes
+     * sequentially.
+     *
+     * @param type
+     *            {@link AutomationType} indicating whether the automation is
+     *            one-time or recursive.
+     * @param interval
+     *            Interval time in milliseconds.
+     * @param listener
+     *            Listener to be notified when value updation ends.
+     *
+     * @return Automation ID using which the automation can be stopped.
+     *
+     * @throws InvalidArgsException
+     *             This exception will be thrown on invalid input.
+     * @throws SimulatorException
+     *             This exception will be thrown for other errors.
+     */
+    public native int startResourceUpdation(AutoUpdateType type,
+            int interval, AutoUpdateListener listener)
+            throws InvalidArgsException, SimulatorException;
+
+    /**
+     * API to start the attribute level automation. This automation involves
+     * automatically updating all the possible values for a given attribute
+     * sequentially.
+     *
+     * @param attrName
+     *            Name of the attribute to be automated.
+     * @param type
+     *            {@link AutomationType} indicating whether the automation is
+     *            one-time or recursive.
+     * @param interval
+     *            Interval time in milliseconds.
+     * @param listener
+     *            Listener to be notified when automation ends.
+     *
+     * @return Automation ID using which the automation can be stopped.
+     *
+     * @throws InvalidArgsException
+     *             This exception will be thrown on invalid input.
+     * @throws SimulatorException
+     *             This exception will be thrown for other errors.
+     */
+    public native int startAttributeUpdation(String attrName,
+            AutoUpdateType type, int interval, AutoUpdateListener listener)
+            throws InvalidArgsException, SimulatorException;
+
+    /**
+     * API to stop the automation based on automation id.
+     *
+     * @param id
+     *            Using which a specific automation can be stopped.
+     *
+     * @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;
+}
diff --git a/service/simulator/java/sdk/src/org/oic/simulator/serviceprovider/IObserver.java b/service/simulator/java/sdk/src/org/oic/simulator/serviceprovider/IObserver.java
deleted file mode 100644 (file)
index 0dceda2..0000000
+++ /dev/null
@@ -1,37 +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 org.oic.simulator.serviceprovider;
-
-/**
- * Interface for receiving the observe notifications.
- */
-public interface IObserver {
-    /**
-     * This callback method will be called when a new observer is added or an
-     * existing observer is removed.
-     *
-     * @param resourceURI
-     *            URI of the resource.
-     * @param state
-     *            Indicates whether an observer is added or removed.
-     * @param observer
-     *            {@link ObserverInfo} object containing the details of
-     *            observer.
-     */
-    public void onObserverChanged(String resourceURI, int state,
-            ObserverInfo observer);
-}
diff --git a/service/simulator/java/sdk/src/org/oic/simulator/serviceprovider/IResourceModelChangedListener.java b/service/simulator/java/sdk/src/org/oic/simulator/serviceprovider/IResourceModelChangedListener.java
deleted file mode 100644 (file)
index 744116b..0000000
+++ /dev/null
@@ -1,37 +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 org.oic.simulator.serviceprovider;
-
-import org.oic.simulator.SimulatorResourceModel;
-
-/**
- * Interface for receiving notifications whenever there is a change in the
- * resource model.
- */
-public interface IResourceModelChangedListener {
-    /**
-     * This callback method will be called to notify about the changes in the
-     * resource model.
-     *
-     * @param resourceURI
-     *            URI of resource.
-     * @param resourceModel
-     *            {@link SimulatorResourceModel} of the resource.
-     */
-    public void onResourceModelChanged(String resourceURI,
-            SimulatorResourceModel resourceModel);
-}
\ No newline at end of file
diff --git a/service/simulator/java/sdk/src/org/oic/simulator/serviceprovider/SimulatorResourceServer.java b/service/simulator/java/sdk/src/org/oic/simulator/serviceprovider/SimulatorResourceServer.java
deleted file mode 100644 (file)
index d601b53..0000000
+++ /dev/null
@@ -1,488 +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 org.oic.simulator.serviceprovider;
-
-import java.util.Vector;
-
-import org.oic.simulator.IAutomation;
-import org.oic.simulator.InvalidArgsException;
-import org.oic.simulator.SimulatorException;
-import org.oic.simulator.SimulatorResourceModel;
-
-/**
- * This class represents a resource in the simulator. It provides a set of
- * native methods for manipulating the simulated resource by adding and removing
- * attributes to its model, automating the attribute value updates, and changing
- * the range of acceptable values of the attributes.
- */
-public class SimulatorResourceServer {
-
-    private String resourceName;
-    private String resourceURI;
-    private String resourceType;
-    private String interfaceType;
-
-    private long   nativeHandle;
-
-    private SimulatorResourceServer(long nativeHandle) {
-        this.nativeHandle = nativeHandle;
-    }
-
-    /**
-     * API to get the resource name. Example: Light, Fan, etc.
-     *
-     * @return Resource name.
-     */
-    public String getName() {
-        return resourceName;
-    }
-
-    /**
-     * API to get the resource URI. Example: /oic/light, /oic/fan, etc.
-     *
-     * @return Resource URI.
-     */
-    public String getURI() {
-        return resourceURI;
-    }
-
-    /**
-     * API to get the resource Type. Example: oic.light, oic.fan, etc.
-     *
-     * @return Resource type.
-     */
-    public String getResourceType() {
-        return resourceType;
-    }
-
-    /**
-     * API to get the interface type of the resource. Example: oic.if.baseline,
-     * oic.if.b, etc.
-     *
-     * @return Interface type of the resource.
-     */
-    public String getInterfaceType() {
-        return interfaceType;
-    }
-
-   /**
-     * 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 getModel()
-            throws SimulatorException;
-
-    /**
-     * API to add an attribute whose value is of type int.
-     *
-     * @param key
-     *            Name of the attribute.
-     * @param value
-     *            Initial value of the attribute.
-     *
-     * @throws InvalidArgsException
-     *             This exception will be thrown if any parameter has invalid
-     *             values.
-     * @throws SimulatorException
-     *             This exception will be thrown for other errors.
-     */
-    public native void addAttributeInteger(String key, int value)
-            throws InvalidArgsException, SimulatorException;
-
-    /**
-     * API to  add an attribute whose value is of type double.
-     *
-     * @param key
-     *            Name of the attribute.
-     * @param value
-     *            Initial value of the attribute.
-     *
-     * @throws InvalidArgsException
-     *             This exception will be thrown if any parameter has invalid
-     *             values.
-     * @throws SimulatorException
-     *             This exception will be thrown for other errors.
-     */
-    public native void addAttributeDouble(String key, double value)
-            throws InvalidArgsException, SimulatorException;
-
-    /**
-     * API to  add an attribute whose value is of type boolean.
-     *
-     * @param key
-     *            Name of the attribute.
-     * @param value
-     *            Initial value of the attribute.
-     *
-     * @throws InvalidArgsException
-     *             This exception will be thrown if any parameter has invalid
-     *             values.
-     * @throws SimulatorException
-     *             This exception will be thrown for other errors.
-     */
-    public native void addAttributeBoolean(String key, boolean value)
-            throws InvalidArgsException, SimulatorException;
-
-    /**
-     * API to  add an attribute whose value is of type String.
-     *
-     * @param key
-     *            Name of the attribute.
-     * @param value
-     *            Initial value of the attribute.
-     *
-     * @throws InvalidArgsException
-     *             This exception will be thrown if any parameter has invalid
-     *             values.
-     * @throws SimulatorException
-     *             This exception will be thrown for other errors.
-     */
-    public native void addAttributeString(String key, String value)
-            throws InvalidArgsException, SimulatorException;
-
-    /**
-     * API to  update the value of an attribute whose value is of
-     * type int.
-     *
-     * @param key
-     *            Name of the attribute.
-     * @param value
-     *            New value of the attribute.
-     *
-     * @throws InvalidArgsException
-     *             This exception will be thrown if any parameter has invalid
-     *             values.
-     * @throws SimulatorException
-     *             This exception will be thrown for other errors.
-     */
-    public native void updateAttributeInteger(String key, int value)
-            throws InvalidArgsException, SimulatorException;
-
-    /**
-     * API to  update the value of an attribute whose value is of
-     * type double.
-     *
-     * @param key
-     *            Name of the attribute.
-     * @param value
-     *            New value of the attribute.
-     *
-     * @throws InvalidArgsException
-     *             This exception will be thrown if any parameter has invalid
-     *             values.
-     * @throws SimulatorException
-     *             This exception will be thrown for other errors.
-     */
-    public native void updateAttributeDouble(String key, double value)
-            throws InvalidArgsException, SimulatorException;
-
-    /**
-     * API to  update the value of an attribute whose value is of
-     * type boolean.
-     *
-     * @param key
-     *            Name of the attribute.
-     * @param value
-     *            New value of the attribute.
-     *
-     * @throws InvalidArgsException
-     *             This exception will be thrown if any parameter has invalid
-     *             values.
-     * @throws SimulatorException
-     *             This exception will be thrown for other errors.
-     */
-    public native void updateAttributeBoolean(String key, boolean value)
-            throws InvalidArgsException, SimulatorException;
-
-    /**
-     * API to  update the value of an attribute whose value is of
-     * type String.
-     *
-     * @param key
-     *            Name of the attribute.
-     * @param value
-     *            New value of the attribute.
-     *
-     * @throws InvalidArgsException
-     *             This exception will be thrown if any parameter has invalid
-     *             values.
-     * @throws SimulatorException
-     *             This exception will be thrown for other errors.
-     */
-    public native void updateAttributeString(String key, String value)
-            throws InvalidArgsException, SimulatorException;
-
-    /**
-     * API to update the value of an attribute from
-     * its allowed values.
-     *
-     * @param key
-     *            Name of the attribute.
-     * @param index
-     *            Index of the value in the allowed values.
-     *
-     * @throws InvalidArgsException
-     *             This exception will be thrown if any parameter has invalid
-     *             values.
-     * @throws SimulatorException
-     *             This exception will be thrown for other errors.
-     */
-    public native void updateAttributeFromAllowedValues(String key,
-            int index) throws InvalidArgsException, SimulatorException;
-
-    /**
-     * API to  set the range of allowed values. This function is
-     * intended to be used for integer type attributes.
-     *
-     * @param key
-     *            Name of the attribute.
-     * @param min
-     *            Minimum value in the range.
-     * @param max
-     *            Maximum value in the range.
-     *
-     * @throws InvalidArgsException
-     *             This exception will be thrown if any parameter has invalid
-     *             values.
-     * @throws SimulatorException
-     *             This exception will be thrown for other errors.
-     */
-    public native void setRange(String key, int min, int max)
-            throws InvalidArgsException, SimulatorException;
-
-    /**
-     * API to  set the allowed values of attribute whose value is of
-     * type int.
-     *
-     * @param key
-     *            Name of the attribute.
-     * @param allowedValues
-     *            Allowed values of the attribute.
-     *
-     * @throws InvalidArgsException
-     *             This exception will be thrown if any parameter has invalid
-     *             values.
-     * @throws SimulatorException
-     *             This exception will be thrown for other errors.
-     */
-    public native void setAllowedValuesInteger(String key,
-            Vector<Integer> allowedValues) throws InvalidArgsException,
-            SimulatorException;
-
-    /**
-     * API to  set the allowed values of attribute whose value is of
-     * type double.
-     *
-     * @param key
-     *            Name of the attribute.
-     * @param allowedValues
-     *            Allowed values of the attribute.
-     *
-     * @throws InvalidArgsException
-     *             This exception will be thrown if any parameter has invalid
-     *             values.
-     * @throws SimulatorException
-     *             This exception will be thrown for other errors.
-     */
-    public native void setAllowedValuesDouble(String key,
-            Vector<Double> allowedValues) throws InvalidArgsException,
-            SimulatorException;
-
-    /**
-     * API to  set the allowed values of attribute whose value is of
-     * type String.
-     *
-     * @param key
-     *            Name of the attribute.
-     * @param allowedValues
-     *            Allowed values of the attribute.
-     *
-     * @throws InvalidArgsException
-     *             This exception will be thrown if any parameter has invalid
-     *             values.
-     * @throws SimulatorException
-     *             This exception will be thrown for other errors.
-     */
-    public native void setAllowedValuesString(String key,
-            Vector<String> allowedValues) throws InvalidArgsException,
-            SimulatorException;
-
-    /**
-     * API to  start the resource level automation. This automation
-     * involves automatically updating all the possible values for all the
-     * attributes sequentially.
-     *
-     * @param typeOfAutomation
-     *            {@link AutomationType} indicating whether the automation is
-     *            one-time or recursive.
-     * @param updateInterval
-     *            Interval time in milliseconds for attribute value update automation.
-     * @param listener
-     *            Listener to be notified when automation ends.
-     *
-     * @return Automation ID using which the automation can be stopped.
-     *
-     * @throws InvalidArgsException
-     *             This exception will be thrown if any parameter has invalid
-     *             values.
-     * @throws SimulatorException
-     *             This exception will be thrown for other errors.
-     */
-    public int startResourceAutomation(AutomationType typeOfAutomation,
-            int updateInterval, IAutomation listener) throws InvalidArgsException,
-            SimulatorException {
-        return startResourceAutomation(typeOfAutomation.getValue(), updateInterval, listener);
-    }
-
-    /**
-     * API to  start the attribute level automation. This automation
-     * involves automatically updating all the possible values for a given
-     * attribute sequentially.
-     *
-     * @param attrName
-     *            Name of the attribute to be automated.
-     * @param typeOfAutomation
-     *            {@link AutomationType} indicating whether the automation is
-     *            one-time or recursive.
-     * @param updateInterval
-     *            Interval time in milliseconds for attribute value update automation.
-     * @param listener
-     *            Listener to be notified when automation ends.
-     *
-     * @return Automation ID using which the automation can be stopped.
-     *
-     * @throws InvalidArgsException
-     *             This exception will be thrown if any parameter has invalid
-     *             values.
-     * @throws SimulatorException
-     *             This exception will be thrown for other errors.
-     */
-    public int startAttributeAutomation(String attrName,
-            AutomationType typeOfAutomation, int updateInterval,
-            IAutomation listener)
-            throws InvalidArgsException, SimulatorException {
-        return startAttributeAutomation(attrName, typeOfAutomation.getValue(),
-                updateInterval, listener);
-    }
-
-    /**
-     * API to  stop the automation based on automation id.
-     *
-     * @param automationId
-     *            Using which a specific automation can be stopped.
-     *
-     * @throws SimulatorException
-     *             This exception will be thrown for other errors.
-     */
-    public native void stopAutomation(int automationId)
-            throws SimulatorException;
-
-    /**
-     * API to remove an attribute from the simulated resource.
-     *
-     * @param key
-     *            Name of the attribute to be deleted.
-     *
-     * @throws InvalidArgsException
-     *             This exception will be thrown either if the parameter has
-     *             invalid value or the native resource object does not exist.
-     * @throws SimulatorException
-     *             This exception will be thrown for other errors.
-     */
-    public native void removeAttribute(String key) throws InvalidArgsException,
-            SimulatorException;
-
-    /**
-     * API to get observers  information.
-     *
-     * @return An array of {@link ObserverInfo} objects.
-     *
-     * @throws InvalidArgsException
-     *             This exception will be thrown if the native resource object
-     *             does not exist.
-     * @throws SimulatorException
-     *             This exception will be thrown for other errors.
-     */
-    public native ObserverInfo[] getObserversList()
-            throws InvalidArgsException, SimulatorException;
-
-    /**
-     * API to set callback to receive notifications when observer is added/removed.
-     *
-     * @param observer
-     *            Listener to be notified when clients start/stop observing.
-     *
-     * @throws InvalidArgsException
-     *             This exception will be thrown either if the parameter has
-     *             invalid value or the native resource object does not exist.
-     * @throws SimulatorException
-     *             This exception will be thrown for other errors.
-     */
-    public native void setObserverCallback(IObserver observer)
-            throws InvalidArgsException, SimulatorException;
-
-    /**
-     * API to notify simulated resource's state to a specific observer.
-     *
-     * @param id
-     *            Observer's Id.
-     *
-     * @throws InvalidArgsException
-     *             This exception will be thrown if the native resource object
-     *             does not exist.
-     * @throws SimulatorException
-     *             This exception will be thrown for other errors.
-     */
-    public native void notifyObserver(int id) throws InvalidArgsException,
-            SimulatorException;
-
-    /**
-     * API to notify simualted resource's state to all observers.
-     *
-     * @throws InvalidArgsException
-     *             This exception will be thrown if the native resource object
-     *             does not exist.
-     * @throws SimulatorException
-     *             This exception will be thrown for other errors.
-     */
-    public native void notifyAllObservers() throws InvalidArgsException,
-            SimulatorException;
-
-    private native int startResourceAutomation(int typeOfAutomation,
-            int updateInterval, IAutomation listener) throws InvalidArgsException,
-            SimulatorException;
-
-    private native int startAttributeAutomation(String attrName,
-        int typeOfAutomation, int updateInterval, IAutomation listener)
-        throws InvalidArgsException, SimulatorException;
-
-    @Override
-    protected void finalize() throws Throwable {
-        try {
-            dispose();
-        } finally {
-            super.finalize();
-        }
-    }
-
-    private native void dispose();
-}