Resource container can be built without Java support.
authorMarkus Jung <markus.jung@samsung.com>
Mon, 20 Jul 2015 00:48:58 +0000 (09:48 +0900)
committerUze Choi <uzchoi@samsung.com>
Mon, 20 Jul 2015 02:09:12 +0000 (02:09 +0000)
SConscript checks for the presence of a Java build environment and configures a CPP Macro variable that includes/excludes Java related code
in the resource container.

Change-Id: I33cc32e45eb28b554512841ff92a0a078966598a
Signed-off-by: Markus Jung <markus.jung@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1741
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/resource-manipulation/src/resourceContainer/SConscript
service/resource-manipulation/src/resourceContainer/include/BundleInfoInternal.h
service/resource-manipulation/src/resourceContainer/include/ResourceContainerImpl.h
service/resource-manipulation/src/resourceContainer/include/org_iotivity_resourcecontainer_bundle_api_BaseActivator.h
service/resource-manipulation/src/resourceContainer/src/BaseActivator.cpp
service/resource-manipulation/src/resourceContainer/src/BundleInfoInternal.cpp
service/resource-manipulation/src/resourceContainer/src/JavaBundleResource.cpp
service/resource-manipulation/src/resourceContainer/src/ResourceContainerImpl.cpp
service/resource-manipulation/src/resourceContainer/unittests/ResourceContainerTest.cpp
service/resource-manipulation/src/resourceContainer/unittests/SConscript

index bc345c7..f8c6014 100644 (file)
@@ -46,17 +46,18 @@ target_os = env.get('TARGET_OS')
 try:
        print 'Java Home: ', os.environ['JAVA_HOME']
        print 'Java Lib: ', os.environ['JAVA_LIB']
+       resource_container_env.Append(CPPDEFINES={'JAVA_SUPPORT':1})
 except KeyError:
        print '''
 *********************************** Error *************************************
-* Cannot build resource container. JAVA_HOME or JAVA_LIB are not set properly 
+* Building resource container without Java support. JAVA_HOME or JAVA_LIB are not set properly 
 * Please configure JAVA_HOME to point to your Java 7 JDK and 
 * JAVA_LIB to your folder containing libjvm
 * Example: export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386
 *          export JAVA_LIB=/usr/lib/jvm/java-7-openjdk-i386/jre/lib/i386/server
 *******************************************************************************        
        '''
-       Return()
+       resource_container_env.Append(CPPDEFINES={'JAVA_SUPPORT':0})
        
 
 resource_container_env.AppendUnique(
@@ -65,10 +66,19 @@ resource_container_env.AppendUnique(
                '../../include',
                'include',
                'bundle-api/include',
-               'src',
+               'src'           
+       ])
+
+try:
+       resource_container_env.AppendUnique(
+       CPPPATH = [
                os.environ['JAVA_HOME']+'/include',
-               os.environ['JAVA_HOME']+'/include/linux'
+               os.environ['JAVA_HOME']+'/include/linux'                
        ])
+except KeyError:
+       print ''
+       
+
 
 if target_os not in ['windows', 'winrt']:
     resource_container_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall'])
@@ -79,25 +89,20 @@ if target_os == 'android':
     resource_container_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
     resource_container_env.PrependUnique(LIBS = ['gnustl_shared', 'compatibility', 'log'])
        
-
-resource_container_env.AppendUnique(LIBPATH = [os.environ['JAVA_LIB']])
+try:
+       resource_container_env.AppendUnique(LIBPATH = [os.environ['JAVA_LIB']])
+except KeyError:
+       print ''
        
-conf = Configure(resource_container_env)
-if not conf.CheckLib('jvm'):
-       print '''
-*********************************** Error *************************************
-* Cannot locate libjvm for resource container.
-* Please check your JAVA_LIB to point to your folder containing libjvm.
-* Example: export JAVA_LIB=/usr/lib/jvm/java-7-openjdk-i386/jre/lib/i386/server/
-*******************************************************************************        
-       '''
-       resource_container_env = conf.Finish()
-       Return()
-resource_container_env = conf.Finish()
 
 resource_container_env.PrependUnique(LIBS = ['server_builder', 'service_common', 'oc','octbstack', 'oc_logger', 'oc_logger_core', 'connectivity_abstraction'])
-resource_container_env.AppendUnique(LIBS = ['dl', 'jvm'])      
+resource_container_env.AppendUnique(LIBS = ['dl'])     
 
+try:   
+       print 'Java Lib: ', os.environ['JAVA_LIB']
+       resource_container_env.AppendUnique(LIBS = ['jvm'])             
+except KeyError:
+       print ''
 
 ######################################################################
 # Source files and Targets
@@ -106,6 +111,7 @@ res_container_src = ['src/BaseActivator.cpp','src/BundleActivator.cpp','src/Bund
        'src/BundleInfoInternal.cpp', 'src/BundleResource.cpp', 'src/Configuration.cpp', 'src/JavaBundleResource.cpp', 'src/ProtocolBridgeResource.cpp',
        'src/ProtocolBridgeConnector.cpp', 'src/ResourceContainer.cpp', 'src/ResourceContainerBundleAPI.cpp', 'src/ResourceContainerImpl.cpp', 
        'src/SoftSensorResource.cpp']
+       
 res_container_static = resource_container_env.StaticLibrary('ResContainerLib', res_container_src)
 res_container_shared = resource_container_env.SharedLibrary('ResContainerLib', res_container_src)
 
@@ -181,7 +187,9 @@ containersample_env.AppendUnique(LINKFLAGS=["-rdynamic"])
 Command("examples/ResourceContainerConfig.xml","examples/ResourceContainerConfig.xml", Copy("$TARGET", "$SOURCE"))
 Ignore("examples/ResourceContainerConfig.xml", "examples/ResourceContainerConfig.xml")
 
-containersampleapp_src =  [res_container_src , 'src/ContainerSample.cpp']
+containersample_env.AppendUnique(LIBS = ['ResContainerLib'])
+
+containersampleapp_src =  ['src/ContainerSample.cpp']
 containersampleapp = containersample_env.Program('ContainerSample',containersampleapp_src)
 Alias("containersample", containersampleapp)
 env.AppendTarget('containersample')
@@ -190,8 +198,9 @@ env.AppendTarget('containersample')
 # Build Container Sample Client
 ######################################################################
 containersampleclient_env = resource_container_env.Clone();
-containersampleclient_env.AppendUnique(LINKFLAGS=["-rdynamic"])
-containersampleclient_src =  [res_container_src , 'src/ContainerSampleClient.cpp']
+
+containersample_env.AppendUnique(LIBS = ['ResContainerLib'])
+containersampleclient_src =  ['src/ContainerSampleClient.cpp']
 containersampleclientapp = containersample_env.Program('ContainerSampleClient',containersampleclient_src)
 Alias("containersampleclient", containersampleclientapp)
 env.AppendTarget('containersampleclient')
index 078ad43..6bad441 100644 (file)
 #include <string>
 #include "BundleInfo.h"
 #include "ResourceContainerBundleAPI.h"
-#include "jni.h"
+
+#if (JAVA_SUPPORT)
+    #include "jni.h"
+#endif
 
 using namespace std;
 using namespace OIC::Service;
@@ -62,14 +65,6 @@ namespace OIC
                 void setActivatorName(string activatorName);
                 string getActivatorName();
 
-                void setJavaBundleActivatorMethod(jmethodID activator);
-                jmethodID getJavaBundleActivatorMethod();
-                void setJavaBundleDeactivatorMethod(jmethodID deactivator);
-                jmethodID getJavaBundleDeactivatorMethod();
-
-                void setJavaBundleActivatorObject(jobject);
-                jobject getJavaBundleActivatorObject();
-
                 void setBundleActivator(activator_t *);
                 activator_t *getBundleActivator();
 
@@ -82,13 +77,23 @@ namespace OIC
                 void setResourceDestroyer(resourceDestroyer_t *);
                 resourceDestroyer_t *getResourceDestroyer();
 
+                void setBundleInfo(BundleInfo *bundleInfo);
+
                 void setBundleHandle(void *);
                 void *getBundleHandle();
 
                 void setJavaBundle(bool javaBundle);
                 bool getJavaBundle();
 
-                void setBundleInfo(BundleInfo *bundleInfo);
+#if (JAVA_SUPPORT)
+                void setJavaBundleActivatorMethod(jmethodID activator);
+                jmethodID getJavaBundleActivatorMethod();
+                void setJavaBundleDeactivatorMethod(jmethodID deactivator);
+                jmethodID getJavaBundleDeactivatorMethod();
+
+                void setJavaBundleActivatorObject(jobject);
+                jobject getJavaBundleActivatorObject();
+#endif
 
             private:
                 bool m_loaded, m_activated, m_java_bundle;
@@ -99,9 +104,12 @@ namespace OIC
                 resourceDestroyer_t *m_resourceDestroyer;
                 void *m_bundleHandle;
                 string m_activator_name;
+                string m_library_path;
+#if (JAVA_SUPPORT)
                 jmethodID m_java_activator, m_java_deactivator;
                 jobject m_java_activator_object;
-                string m_library_path;
+#endif
+
         };
     }
 }
index 30fe8b2..bd2b81e 100644 (file)
@@ -21,6 +21,8 @@
 #ifndef RESOURCECONTAINERIMPL_H_
 #define RESOURCECONTAINERIMPL_H_
 
+
+
 #include "ResourceContainer.h"
 #include "ResourceContainerBundleAPI.h"
 #include "BundleInfoInternal.h"
 #include "RCSResponse.h"
 #include "ResourceObject.h"
 
-#include "jni.h"
+#if(JAVA_SUPPORT)
+    #include <jni.h>
+#endif
+
 #include <map>
 
 using namespace OIC::Service;
@@ -55,7 +60,7 @@ namespace OIC
                 void registerBundle(BundleInfo *bundleinfo);
                 void unregisterBundle(BundleInfo *bundleinfo);
                 void unregisterBundleSo(string id);
-                void unregisterBundleJava(string id);
+
 
                 // methods from ResourceContainerBundleAPI
                 void registerResource(BundleResource *resource);
@@ -89,7 +94,10 @@ namespace OIC
 
                 std::list<string> listBundleResources(string bundleId);
 
+#if(JAVA_SUPPORT)
                 JavaVM *getJavaVM(string bundleId);
+                void unregisterBundleJava(string id);
+#endif
 
 
             private:
@@ -99,16 +107,23 @@ namespace OIC
                 map< std::string, list<string> > m_mapBundleResources; //<bundleID, vector<uri>>
                 string m_configFile;
                 Configuration *m_config = NULL;
-                map<string, JavaVM *> m_bundleVM;
 
-                void registerJavaBundle(BundleInfo *bundleInfo);
-                void registerSoBundle(BundleInfo *bundleInfo);
-                void activateJavaBundle(string bundleId);
+
                 void activateSoBundle(string bundleId);
-                void deactivateJavaBundle(string bundleId);
                 void deactivateSoBundle(string bundleId);
                 void addSoBundleResource(string bundleId, resourceInfo newResourceInfo);
                 void removeSoBundleResource(string bundleId, string resourceUri);
+                void registerSoBundle(BundleInfo *bundleInfo);
+
+#if(JAVA_SUPPORT)
+                map<string, JavaVM *> m_bundleVM;
+
+                void registerJavaBundle(BundleInfo *bundleInfo);
+                void activateJavaBundle(string bundleId);
+                void deactivateJavaBundle(string bundleId);
+
+#endif
+
         };
     }
 }
index ca33ba6..b83c4b9 100644 (file)
@@ -1,4 +1,6 @@
 /* DO NOT EDIT THIS FILE - it is machine generated */
+
+#if(JAVA_SUPPORT)
 #include <jni.h>
 /* Header for class org_iotivity_resourcecontainer_bundle_api_BaseActivator */
 
@@ -43,3 +45,4 @@ JNIEXPORT jobjectArray JNICALL Java_org_iotivity_resourcecontainer_bundle_api_Ba
 }
 #endif
 #endif
+#endif
index fb71bc5..992b673 100644 (file)
 // limitations under the License.
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-#include <jni.h>
-#include "org_iotivity_resourcecontainer_bundle_api_BaseActivator.h"
-#include "JavaBundleResource.h"
 #include "ResourceContainerImpl.h"
+#if(JAVA_SUPPORT)
+    #include <jni.h>
+    #include "org_iotivity_resourcecontainer_bundle_api_BaseActivator.h"
+    #include "JavaBundleResource.h"
+    #include "ResourceContainerImpl.h"
+
+    using namespace OIC::Service;
+
+    std::map< string, JavaBundleResource* > java_resources;
+
+    /*
+     * Class:     org_iotivity_resourcecontainer_bundle_api_BaseActivator
+     * Method:    registerJavaResource
+     * Signature: (Lorg/iotivity/resourcecontainer/bundle/api/BundleResource;[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
+     */
+    JNIEXPORT void JNICALL Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_registerJavaResource
+    (JNIEnv *env, jobject obj, jobject bundleResource, jobjectArray attributes, jstring bundleId, jstring uri, jstring resourceType, jstring res_name)
+    {
+        //return;
+        //static std::map<jobject, JavaBundleResource > javaBundles;
+        const char *str_bundleId = env->GetStringUTFChars(bundleId, 0);
+        const char *str_uri = env->GetStringUTFChars(uri, 0);
+        const char *str_resourceType = env->GetStringUTFChars(resourceType, 0);
+        const char *str_res_name = env->GetStringUTFChars(res_name, 0);
+
+        JavaBundleResource *javaBundleResource = new JavaBundleResource(env, obj, bundleResource, str_bundleId, attributes);
+        ResourceContainerImpl *container = ResourceContainerImpl::getImplInstance();
+
+        javaBundleResource->m_uri = string(str_uri, strlen(str_uri));
+        javaBundleResource->m_resourceType = string(str_resourceType, strlen(str_resourceType));
+        javaBundleResource->m_name = string(str_res_name, strlen(str_res_name));
+        container->registerResource(javaBundleResource);
+
+        java_resources[str_uri] = javaBundleResource;
+
+    }
+
+    /*
+     * Class:     org_iotivity_resourcecontainer_bundle_api_BaseActivator
+     * Method:    unregisterJavaResource
+     * Signature: (Lorg/iotivity/resourcecontainer/bundle/api/BundleResource;)V
+     */
+    JNIEXPORT void JNICALL Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_unregisterJavaResource
+    (JNIEnv *env, jobject obj, jobject bundleResource, jstring uri)
+    {
+        const char *str_uri = env->GetStringUTFChars(uri, 0);
+
+        if(java_resources[str_uri] != NULL)
+        {
+            ResourceContainerImpl *container = ResourceContainerImpl::getImplInstance();
+            container->unregisterResource(java_resources[str_uri]);
+            java_resources.erase(str_uri);
+        }
+    }
 
-using namespace OIC::Service;
-
-std::map< string, JavaBundleResource* > java_resources;
-
-/*
- * Class:     org_iotivity_resourcecontainer_bundle_api_BaseActivator
- * Method:    registerJavaResource
- * Signature: (Lorg/iotivity/resourcecontainer/bundle/api/BundleResource;[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
- */
-JNIEXPORT void JNICALL Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_registerJavaResource
-(JNIEnv *env, jobject obj, jobject bundleResource, jobjectArray attributes, jstring bundleId, jstring uri, jstring resourceType, jstring res_name)
-{
-    //return;
-    //static std::map<jobject, JavaBundleResource > javaBundles;
-    const char *str_bundleId = env->GetStringUTFChars(bundleId, 0);
-    const char *str_uri = env->GetStringUTFChars(uri, 0);
-    const char *str_resourceType = env->GetStringUTFChars(resourceType, 0);
-    const char *str_res_name = env->GetStringUTFChars(res_name, 0);
-
-    JavaBundleResource *javaBundleResource = new JavaBundleResource(env, obj, bundleResource, str_bundleId, attributes);
-    ResourceContainerImpl *container = ResourceContainerImpl::getImplInstance();
-
-    javaBundleResource->m_uri = string(str_uri, strlen(str_uri));
-    javaBundleResource->m_resourceType = string(str_resourceType, strlen(str_resourceType));
-    javaBundleResource->m_name = string(str_res_name, strlen(str_res_name));
-    container->registerResource(javaBundleResource);
-
-    java_resources[str_uri] = javaBundleResource;
-
-}
-
-/*
- * Class:     org_iotivity_resourcecontainer_bundle_api_BaseActivator
- * Method:    unregisterJavaResource
- * Signature: (Lorg/iotivity/resourcecontainer/bundle/api/BundleResource;)V
- */
-JNIEXPORT void JNICALL Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_unregisterJavaResource
-(JNIEnv *env, jobject obj, jobject bundleResource, jstring uri)
-{
-    const char *str_uri = env->GetStringUTFChars(uri, 0);
-
-    if(java_resources[str_uri] != NULL)
+    /*
+     * Class:     org_iotivity_resourcecontainer_bundle_api_BaseActivator
+     * Method:    getNumberOfConfiguredResources
+     * Signature: (Ljava/lang/String;)I
+     */
+    JNIEXPORT jint JNICALL Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_getNumberOfConfiguredResources(
+            JNIEnv *env, jobject obj, jstring bundleId)
     {
+
+        const char *str_bundleId = env->GetStringUTFChars(bundleId, 0);
+
+        ResourceContainerImpl *container = ResourceContainerImpl::getImplInstance();
+        vector< resourceInfo > resourceConfig;
+        container->getResourceConfiguration(str_bundleId, &resourceConfig);
+
+        return resourceConfig.size();
+    }
+
+    /*
+     * Class:     org_iotivity_resourcecontainer_bundle_api_BaseActivator
+     * Method:    getConfiguredResourceParams
+     * Signature: (Ljava/lang/String;I)[Ljava/lang/String;
+     */
+    JNIEXPORT jobjectArray JNICALL Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_getConfiguredResourceParams(
+            JNIEnv *env, jobject obj, jstring bundleId, jint resourceId)
+    {
+
+        jobjectArray ret;
+        const char *str_bundleId = env->GetStringUTFChars(bundleId, 0);
+
         ResourceContainerImpl *container = ResourceContainerImpl::getImplInstance();
-        container->unregisterResource(java_resources[str_uri]);
-        java_resources.erase(str_uri);
+        vector< resourceInfo > resourceConfig;
+        container->getResourceConfiguration(str_bundleId, &resourceConfig);
+        resourceInfo conf = resourceConfig[resourceId];
+        ret = (jobjectArray) env->NewObjectArray(4, env->FindClass("java/lang/String"),
+                env->NewStringUTF(""));
+
+        env->SetObjectArrayElement(ret, 0, env->NewStringUTF(conf.name.c_str()));
+        env->SetObjectArrayElement(ret, 1, env->NewStringUTF(conf.uri.c_str()));
+        env->SetObjectArrayElement(ret, 2, env->NewStringUTF(conf.resourceType.c_str()));
+        env->SetObjectArrayElement(ret, 3, env->NewStringUTF(conf.address.c_str()));
+        return ret;
     }
-}
-
-/*
- * Class:     org_iotivity_resourcecontainer_bundle_api_BaseActivator
- * Method:    getNumberOfConfiguredResources
- * Signature: (Ljava/lang/String;)I
- */
-JNIEXPORT jint JNICALL Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_getNumberOfConfiguredResources(
-        JNIEnv *env, jobject obj, jstring bundleId)
-{
-
-    const char *str_bundleId = env->GetStringUTFChars(bundleId, 0);
-
-    ResourceContainerImpl *container = ResourceContainerImpl::getImplInstance();
-    vector< resourceInfo > resourceConfig;
-    container->getResourceConfiguration(str_bundleId, &resourceConfig);
-
-    return resourceConfig.size();
-}
-
-/*
- * Class:     org_iotivity_resourcecontainer_bundle_api_BaseActivator
- * Method:    getConfiguredResourceParams
- * Signature: (Ljava/lang/String;I)[Ljava/lang/String;
- */
-JNIEXPORT jobjectArray JNICALL Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_getConfiguredResourceParams(
-        JNIEnv *env, jobject obj, jstring bundleId, jint resourceId)
-{
-
-    jobjectArray ret;
-    const char *str_bundleId = env->GetStringUTFChars(bundleId, 0);
-
-    ResourceContainerImpl *container = ResourceContainerImpl::getImplInstance();
-    vector< resourceInfo > resourceConfig;
-    container->getResourceConfiguration(str_bundleId, &resourceConfig);
-    resourceInfo conf = resourceConfig[resourceId];
-    ret = (jobjectArray) env->NewObjectArray(4, env->FindClass("java/lang/String"),
-            env->NewStringUTF(""));
-
-    env->SetObjectArrayElement(ret, 0, env->NewStringUTF(conf.name.c_str()));
-    env->SetObjectArrayElement(ret, 1, env->NewStringUTF(conf.uri.c_str()));
-    env->SetObjectArrayElement(ret, 2, env->NewStringUTF(conf.resourceType.c_str()));
-    env->SetObjectArrayElement(ret, 3, env->NewStringUTF(conf.address.c_str()));
-    return ret;
-}
+#endif
index 2727ddf..9a14ef2 100644 (file)
@@ -171,6 +171,7 @@ namespace OIC
             return m_library_path;
         }
 
+#if (JAVA_SUPPORT)
         void BundleInfoInternal::setJavaBundleActivatorMethod(jmethodID javaBundleActivator)
         {
             m_java_activator = javaBundleActivator;
@@ -191,16 +192,6 @@ namespace OIC
             return m_java_deactivator;
         }
 
-        /*void BundleInfoInternal::setJavaBundleActivatorClass(jclass activator_class)
-        {
-            m_java_activator_class = activator_class;
-        }
-
-        jclass BundleInfoInternal::getJavaBundleActivatorClass()
-        {
-            return m_java_activator_class;
-        }*/
-
         void BundleInfoInternal::setJavaBundleActivatorObject(jobject activator_object)
         {
             m_java_activator_object = activator_object;
@@ -210,6 +201,7 @@ namespace OIC
         {
             return m_java_activator_object;
         }
+#endif
 
         void BundleInfoInternal::setBundleInfo(BundleInfo *bundleInfo)
         {
index 5400550..96b5015 100644 (file)
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
-#include "JavaBundleResource.h"
-#include <jni.h>
-#include <string.h>
 
-#include <iostream>
+#if(JAVA_SUPPORT)
+    #include "JavaBundleResource.h"
+    #include <jni.h>
+    #include <string.h>
 
-using namespace OIC::Service;
-using namespace std;
+    #include <iostream>
 
-#include "oc_logger.hpp"
+    using namespace OIC::Service;
+    using namespace std;
 
-using OC::oc_log_stream;
-using namespace OIC::Service;
+    #include "oc_logger.hpp"
 
-auto info_logger = []() -> boost::iostreams::stream<OC::oc_log_stream> &
-{
-    static OC::oc_log_stream ols(oc_make_ostream_logger);
-    static boost::iostreams::stream<OC::oc_log_stream> os(ols);
-    os->set_level(OC_LOG_INFO);
-    os->set_module("JavaBundleResource");
-    return os;
-};
+    using OC::oc_log_stream;
+    using namespace OIC::Service;
 
-auto error_logger = []() -> boost::iostreams::stream<OC::oc_log_stream> &
-{
-    static OC::oc_log_stream ols(oc_make_ostream_logger);
-    static boost::iostreams::stream<OC::oc_log_stream> os(ols);
-    os->set_level(OC_LOG_ERROR);
-    os->set_module("JavaBundleResource");
-    return os;
-};
-
-JavaBundleResource::JavaBundleResource()
-{
-
-}
-
-void JavaBundleResource::initAttributes()
-{
-
-}
+    auto info_logger = []() -> boost::iostreams::stream<OC::oc_log_stream> &
+    {
+        static OC::oc_log_stream ols(oc_make_ostream_logger);
+        static boost::iostreams::stream<OC::oc_log_stream> os(ols);
+        os->set_level(OC_LOG_INFO);
+        os->set_module("JavaBundleResource");
+        return os;
+    };
+
+    auto error_logger = []() -> boost::iostreams::stream<OC::oc_log_stream> &
+    {
+        static OC::oc_log_stream ols(oc_make_ostream_logger);
+        static boost::iostreams::stream<OC::oc_log_stream> os(ols);
+        os->set_level(OC_LOG_ERROR);
+        os->set_module("JavaBundleResource");
+        return os;
+    };
+
+    JavaBundleResource::JavaBundleResource()
+    {
 
-JavaBundleResource::JavaBundleResource(JNIEnv *env, jobject obj, jobject bundleResource,
-        string bundleId, jobjectArray attributes)
-{
-    int stringCount = env->GetArrayLength(attributes);
+    }
 
-    for (int i = 0; i < stringCount; i++)
+    void JavaBundleResource::initAttributes()
     {
-        jstring str = (jstring) env->GetObjectArrayElement(attributes, i);
-        const char *rawString = env->GetStringUTFChars(str, 0);
-        string s(rawString, strlen(rawString));
-        BundleResource::setAttribute(s, "");
+
     }
 
-    m_bundleId = bundleId;
+    JavaBundleResource::JavaBundleResource(JNIEnv *env, jobject obj, jobject bundleResource,
+            string bundleId, jobjectArray attributes)
+    {
+        int stringCount = env->GetArrayLength(attributes);
 
-    this->bundleResource = env->NewGlobalRef(bundleResource);
+        for (int i = 0; i < stringCount; i++)
+        {
+            jstring str = (jstring) env->GetObjectArrayElement(attributes, i);
+            const char *rawString = env->GetStringUTFChars(str, 0);
+            string s(rawString, strlen(rawString));
+            BundleResource::setAttribute(s, "");
+        }
 
-    bundleResourceClass = env->GetObjectClass(bundleResource);
+        m_bundleId = bundleId;
 
-    attributeSetter = env->GetMethodID(bundleResourceClass, "setAttribute",
-            "(Ljava/lang/String;Ljava/lang/String;)V");
+        this->bundleResource = env->NewGlobalRef(bundleResource);
 
-    attributeGetter = env->GetMethodID(bundleResourceClass, "getAttribute",
-            "(Ljava/lang/String;)Ljava/lang/String;");
+        bundleResourceClass = env->GetObjectClass(bundleResource);
 
-}
+        attributeSetter = env->GetMethodID(bundleResourceClass, "setAttribute",
+                "(Ljava/lang/String;Ljava/lang/String;)V");
 
-JavaBundleResource::~JavaBundleResource()
-{
+        attributeGetter = env->GetMethodID(bundleResourceClass, "getAttribute",
+                "(Ljava/lang/String;)Ljava/lang/String;");
 
-}
+    }
 
-ResourceAttributes& JavaBundleResource::getAttributes(){
-    return BundleResource::getAttributes();
-}
+    JavaBundleResource::~JavaBundleResource()
+    {
 
-ResourceAttributes::Value JavaBundleResource::getAttribute(const std::string& attributeName)
-{
-    JavaVM* vm = ResourceContainerImpl::getImplInstance()->getJavaVM(m_bundleId);
+    }
 
-    JNIEnv * env;
-    int envStat = vm->GetEnv((void **) &env, JNI_VERSION_1_4);
+    ResourceAttributes& JavaBundleResource::getAttributes(){
+        return BundleResource::getAttributes();
+    }
 
-    if (envStat == JNI_EDETACHED)
+    ResourceAttributes::Value JavaBundleResource::getAttribute(const std::string& attributeName)
     {
-        if (vm->AttachCurrentThread((void**) &env, NULL) != 0)
+        JavaVM* vm = ResourceContainerImpl::getImplInstance()->getJavaVM(m_bundleId);
+
+        JNIEnv * env;
+        int envStat = vm->GetEnv((void **) &env, JNI_VERSION_1_4);
+
+        if (envStat == JNI_EDETACHED)
         {
-            error_logger() << "Failed to attach " << endl;
+            if (vm->AttachCurrentThread((void**) &env, NULL) != 0)
+            {
+                error_logger() << "Failed to attach " << endl;
+            }
+        }
+        else if (envStat == JNI_EVERSION)
+        {
+            error_logger() << "Env: version not supported " << endl;
         }
-    }
-    else if (envStat == JNI_EVERSION)
-    {
-        error_logger() << "Env: version not supported " << endl;
-    }
 
-    jstring attrName = env->NewStringUTF(attributeName.c_str());
+        jstring attrName = env->NewStringUTF(attributeName.c_str());
 
-    jstring returnString = (jstring) env->CallObjectMethod(bundleResource, attributeGetter,
-            attrName);
+        jstring returnString = (jstring) env->CallObjectMethod(bundleResource, attributeGetter,
+                attrName);
 
-    const char *js = env->GetStringUTFChars(returnString, NULL);
-    std::string val(js);
-    ResourceAttributes::Value newVal = val;
-    env->ReleaseStringUTFChars(returnString, js);
-    BundleResource::setAttribute(attributeName, newVal.toString());
-    return BundleResource::getAttribute(attributeName);
-}
+        const char *js = env->GetStringUTFChars(returnString, NULL);
+        std::string val(js);
+        ResourceAttributes::Value newVal = val;
+        env->ReleaseStringUTFChars(returnString, js);
+        BundleResource::setAttribute(attributeName, newVal.toString());
+        return BundleResource::getAttribute(attributeName);
+    }
 
-void JavaBundleResource::setAttribute(std::string attributeName, ResourceAttributes::Value&& value)
-{
-    JavaVM* vm = ResourceContainerImpl::getImplInstance()->getJavaVM(m_bundleId);
+    void JavaBundleResource::setAttribute(std::string attributeName, ResourceAttributes::Value&& value)
+    {
+        JavaVM* vm = ResourceContainerImpl::getImplInstance()->getJavaVM(m_bundleId);
 
-    JNIEnv * env;
-    int envStat = vm->GetEnv((void **) &env, JNI_VERSION_1_4);
+        JNIEnv * env;
+        int envStat = vm->GetEnv((void **) &env, JNI_VERSION_1_4);
 
-    if (envStat == JNI_EDETACHED)
-    {
-        if (vm->AttachCurrentThread((void**) &env, NULL) != 0)
+        if (envStat == JNI_EDETACHED)
         {
-            error_logger() << "Failed to attach " << endl;
+            if (vm->AttachCurrentThread((void**) &env, NULL) != 0)
+            {
+                error_logger() << "Failed to attach " << endl;
+            }
+        }
+        else if (envStat == JNI_EVERSION)
+        {
+            error_logger() << "Env: version not supported " << endl;
         }
-    }
-    else if (envStat == JNI_EVERSION)
-    {
-        error_logger() << "Env: version not supported " << endl;
-    }
 
-    jstring attrName = env->NewStringUTF(attributeName.c_str());
-    jstring val = env->NewStringUTF(value.toString().c_str());
+        jstring attrName = env->NewStringUTF(attributeName.c_str());
+        jstring val = env->NewStringUTF(value.toString().c_str());
 
 
-    env->CallObjectMethod(bundleResource, attributeSetter, attrName, val);
-    BundleResource::setAttribute(attributeName, std::move(value));
-}
+        env->CallObjectMethod(bundleResource, attributeSetter, attrName, val);
+        BundleResource::setAttribute(attributeName, std::move(value));
+    }
+#endif
index eaa16a7..80a0742 100644 (file)
@@ -23,7 +23,6 @@
 #include <string.h>
 #include <iostream>
 #include <fstream>
-#include <jni.h>
 #include <iostream>
 #include <fstream>
 #include <stdio.h>
@@ -66,24 +65,28 @@ namespace OIC
 
         ResourceContainerImpl::ResourceContainerImpl()
         {
-            // TODO Auto-generated constructor stub
 
         }
 
         ResourceContainerImpl::~ResourceContainerImpl()
         {
-            // TODO Auto-generated destructor stub
+
         }
 
         bool has_suffix(const std::string &str, const std::string &suffix)
         {
             return str.size() >= suffix.size()
-                   && str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0;
+                    && str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0;
         }
 
         void ResourceContainerImpl::startContainer(string configFile)
         {
-            info_logger() << "Starting resource container" << endl;
+            info_logger() << "Starting resource container " << endl;
+#if (JAVA_SUPPORT)
+            info_logger() << "Resource container has Java support" << endl;
+#else
+            info_logger() << "Resource container without Java support" << endl;
+#endif
 
             m_config = new Configuration(configFile);
 
@@ -103,11 +106,12 @@ namespace OIC
                         string activatorName = bundles[i]["activator"];
                         std::replace(activatorName.begin(), activatorName.end(), '.', '/');
                         ((BundleInfoInternal *) bundleInfo)->setActivatorName(activatorName);
-                        ((BundleInfoInternal *) bundleInfo)->setLibraryPath(bundles[i]["libraryPath"]);
+                        ((BundleInfoInternal *) bundleInfo)->setLibraryPath(
+                                bundles[i]["libraryPath"]);
 
                     }
                     info_logger() << "Init Bundle:" << bundles[i]["id"] << ";" << bundles[i]["path"]
-                                  << endl;
+                            << endl;
                     registerBundle(bundleInfo);
                     activateBundle(bundleInfo);
                 }
@@ -122,7 +126,7 @@ namespace OIC
         {
             info_logger() << "Stopping resource container.";
             for (std::map< std::string, BundleInfoInternal * >::iterator it = m_bundles.begin();
-                 it != m_bundles.end(); ++it)
+                    it != m_bundles.end(); ++it)
             {
                 BundleInfoInternal *bundleInfo = it->second;
                 deactivateBundle(bundleInfo);
@@ -157,7 +161,9 @@ namespace OIC
 
             if (m_bundles[id]->getJavaBundle())
             {
+#if(JAVA_SUPPORT)
                 activateJavaBundle(id);
+#endif
             }
             else
             {
@@ -173,7 +179,9 @@ namespace OIC
 
             if (m_bundles[id]->getJavaBundle())
             {
+#if(JAVA_SUPPORT)
                 deactivateJavaBundle(id);
+#endif
             }
             else
             {
@@ -188,8 +196,10 @@ namespace OIC
 
             if (has_suffix(bundleInfo->getPath(), ".jar"))
             {
+#if(JAVA_SUPPORT)
                 ((BundleInfoInternal *) bundleInfo)->setJavaBundle(true);
                 registerJavaBundle(bundleInfo);
+#endif
             }
             else
             {
@@ -209,7 +219,9 @@ namespace OIC
                 }
                 else
                 {
+#if(JAVA_SUPPORT)
                     unregisterBundleJava(bundleInfo->getID());
+#endif
                 }
             }
         }
@@ -218,7 +230,7 @@ namespace OIC
         {
             void *bundleHandle = m_bundles[id]->getBundleHandle();
             info_logger() << "Unregister bundle: " << m_bundles[id]->getID() << ", "
-                          << m_bundles[id]->getID() << endl;
+                    << m_bundles[id]->getID() << endl;
             char *error;
             dlclose(bundleHandle);
             if ((error = dlerror()) != NULL)
@@ -232,18 +244,6 @@ namespace OIC
             }
         }
 
-        void ResourceContainerImpl::unregisterBundleJava(string id)
-        {
-            info_logger() << "Unregister Java bundle: " << m_bundles[id]->getID() << ", "
-                          << m_bundles[id]->getID() << endl;
-
-            info_logger() << "Destroying JVM" << endl;
-            m_bundleVM[id]->DestroyJavaVM();
-
-            delete m_bundles[id];
-            m_bundles.erase(id);
-        }
-
         void ResourceContainerImpl::registerResource(BundleResource *resource)
         {
             string strUri = resource->m_uri;
@@ -251,7 +251,7 @@ namespace OIC
             ResourceObject::Ptr server = nullptr;
 
             info_logger() << "Registration of resource " << strUri << "," << strResourceType
-                          << endl;
+                    << endl;
 
             server = buildResourceObject(strUri, strResourceType);
 
@@ -264,15 +264,15 @@ namespace OIC
                 resource->registerObserver(this);
 
                 server->setGetRequestHandler(
-                    std::bind(&ResourceContainerImpl::getRequestHandler, this,
-                              std::placeholders::_1, std::placeholders::_2));
+                        std::bind(&ResourceContainerImpl::getRequestHandler, this,
+                                std::placeholders::_1, std::placeholders::_2));
 
                 server->setSetRequestHandler(
-                    std::bind(&ResourceContainerImpl::setRequestHandler, this,
-                              std::placeholders::_1, std::placeholders::_2));
+                        std::bind(&ResourceContainerImpl::setRequestHandler, this,
+                                std::placeholders::_1, std::placeholders::_2));
 
                 info_logger() << "Registration finished " << strUri << "," << strResourceType
-                              << endl;
+                        << endl;
             }
         }
 
@@ -281,8 +281,8 @@ namespace OIC
             string strUri = resource->m_uri;
             string strResourceType = resource->m_resourceType;
 
-            info_logger() << "Unregistration of resource " << resource->m_uri << "," << resource->m_resourceType
-                          << endl;
+            info_logger() << "Unregistration of resource " << resource->m_uri << ","
+                    << resource->m_resourceType << endl;
 
             if (m_mapServers.find(strUri) != m_mapServers.end())
             {
@@ -311,31 +311,31 @@ namespace OIC
             }
         }
 
-        RCSGetResponse ResourceContainerImpl::getRequestHandler(
-            const RCSRequest &request, const ResourceAttributes &attributes)
+        RCSGetResponse ResourceContainerImpl::getRequestHandler(const RCSRequest &request,
+                const ResourceAttributes &attributes)
         {
             ResourceAttributes attr;
 
             if (m_mapServers.find(request.getResourceUri()) != m_mapServers.end()
-                && m_mapResources.find(request.getResourceUri()) != m_mapResources.end())
+                    && m_mapResources.find(request.getResourceUri()) != m_mapResources.end())
             {
                 for (string attrName : m_mapResources[request.getResourceUri()]->getAttributeNames())
                 {
                     attr[attrName] = m_mapResources[request.getResourceUri()]->getAttribute(
-                                         attrName);
+                            attrName);
                 }
             }
 
             return RCSGetResponse::create(attr);
         }
 
-        RCSSetResponse ResourceContainerImpl::setRequestHandler(
-            const RCSRequest &request, const ResourceAttributes &attributes)
+        RCSSetResponse ResourceContainerImpl::setRequestHandler(const RCSRequest &request,
+                const ResourceAttributes &attributes)
         {
             ResourceAttributes attr = attributes;
 
             if (m_mapServers.find(request.getResourceUri()) != m_mapServers.end()
-                && m_mapResources.find(request.getResourceUri()) != m_mapResources.end())
+                    && m_mapResources.find(request.getResourceUri()) != m_mapResources.end())
             {
                 for (string attrName : m_mapResources[request.getResourceUri()]->getAttributeNames())
                 {
@@ -353,7 +353,7 @@ namespace OIC
         void ResourceContainerImpl::onNotificationReceived(std::string strResourceUri)
         {
             info_logger() << "ResourceContainerImpl::onNotificationReceived\n\tnotification from "
-                          << strResourceUri << ".\n";
+                    << strResourceUri << ".\n";
 
             if (m_mapServers.find(strResourceUri) != m_mapServers.end())
             {
@@ -371,7 +371,7 @@ namespace OIC
                 string strResourceType)
         {
             return ResourceObject::Builder(strUri, strResourceType, "DEFAULT_INTERFACE").setObservable(
-                       true).setDiscoverable(true).build();
+                    true).setDiscoverable(true).build();
         }
 
         void ResourceContainerImpl::startBundle(string bundleId)
@@ -387,7 +387,7 @@ namespace OIC
         }
 
         void ResourceContainerImpl::addBundle(string bundleId, string bundleUri, string bundlePath,
-                                              std::map< string, string > params)
+                std::map< string, string > params)
         {
             if (m_bundles.find(bundleId) != m_bundles.end())
                 error_logger() << "BundleId already exist" << endl;
@@ -401,20 +401,19 @@ namespace OIC
                 {
                     string activatorName = params["activator"];
                     std::replace(activatorName.begin(), activatorName.end(), '.', '/');
-                    ((BundleInfoInternal *)bundleInfo)->setActivatorName(activatorName);
-                    ((BundleInfoInternal *)bundleInfo)->setLibraryPath(params["libraryPath"]);
+                    ((BundleInfoInternal *) bundleInfo)->setActivatorName(activatorName);
+                    ((BundleInfoInternal *) bundleInfo)->setLibraryPath(params["libraryPath"]);
                 }
                 if (params.find("activator") != params.end())
                 {
                     string activatorName = params["activator"];
                     std::replace(activatorName.begin(), activatorName.end(), '.', '/');
-                    ((BundleInfoInternal *)bundleInfo)->setActivatorName(activatorName);
-                    ((BundleInfoInternal *)bundleInfo)->setLibraryPath(params["libraryPath"]);
+                    ((BundleInfoInternal *) bundleInfo)->setActivatorName(activatorName);
+                    ((BundleInfoInternal *) bundleInfo)->setLibraryPath(params["libraryPath"]);
                 }
 
-                info_logger() << "Add Bundle:" << bundleInfo->getID().c_str() << ";" <<
-                              bundleInfo->getPath().c_str() <<
-                              endl;
+                info_logger() << "Add Bundle:" << bundleInfo->getID().c_str() << ";"
+                        << bundleInfo->getPath().c_str() << endl;
 
                 registerBundle(bundleInfo);
             }
@@ -433,7 +432,8 @@ namespace OIC
             }
             else
             {
-                error_logger() << "Bundle with ID \'" << bundleId << "\' is not registered." << endl;
+                error_logger() << "Bundle with ID \'" << bundleId << "\' is not registered."
+                        << endl;
             }
         }
 
@@ -441,7 +441,7 @@ namespace OIC
         {
             std::list< BundleInfo * > ret;
             for (std::map< std::string, BundleInfoInternal * >::iterator it = m_bundles.begin();
-                 it != m_bundles.end(); ++it)
+                    it != m_bundles.end(); ++it)
             {
                 {
                     BundleInfo *bundleInfo = BundleInfo::build();
@@ -474,7 +474,8 @@ namespace OIC
             }
             else
             {
-                error_logger() << "Bundle with ID \'" << bundleId << "\' is not registered." << endl;
+                error_logger() << "Bundle with ID \'" << bundleId << "\' is not registered."
+                        << endl;
             }
         }
 
@@ -489,7 +490,8 @@ namespace OIC
             }
             else
             {
-                error_logger() << "Bundle with ID \'" << bundleId << "\' is not registered." << endl;
+                error_logger() << "Bundle with ID \'" << bundleId << "\' is not registered."
+                        << endl;
             }
         }
 
@@ -506,125 +508,6 @@ namespace OIC
 
         }
 
-        JavaVM *ResourceContainerImpl::getJavaVM(string bundleId)
-        {
-            return m_bundleVM[bundleId];
-        }
-
-        void ResourceContainerImpl::registerJavaBundle(BundleInfo *bundleInfo)
-        {
-            info_logger() << "Registering Java bundle " << bundleInfo->getID() << endl;
-            JavaVM *jvm;
-            JNIEnv *env;
-            JavaVMInitArgs vm_args;
-            JavaVMOption options[3];
-
-            BundleInfoInternal *bundleInfoInternal = (BundleInfoInternal *) bundleInfo;
-
-            if (FILE *file = fopen(bundleInfo->getPath().c_str(), "r"))
-            {
-                fclose(file);
-                info_logger() << "Resource bundle " << bundleInfo->getPath().c_str() << " available." << endl;
-                //return true;
-            }
-            else
-            {
-                error_logger() << "Resource bundle " << bundleInfo->getPath().c_str() << " not available" << endl;
-                return;
-            }
-
-            char optionString[] = "-Djava.compiler=NONE";
-            options[0].optionString = optionString;
-            char classpath[1000];
-            strcpy(classpath, "-Djava.class.path=");
-            strcat(classpath, bundleInfo->getPath().c_str());
-
-
-            info_logger() << "Configured classpath: " << classpath << "|" << endl;
-
-            options[1].optionString = classpath;
-
-            char libraryPath[1000];
-            strcpy(libraryPath, "-Djava.library.path=");
-            strcat(libraryPath, bundleInfo->getLibraryPath().c_str());
-            options[2].optionString = libraryPath;
-
-            info_logger() << "Configured library path: " << libraryPath << "|" << endl;
-
-            vm_args.version = JNI_VERSION_1_4;
-            vm_args.options = options;
-            vm_args.nOptions = 3;
-            vm_args.ignoreUnrecognized = 1;
-
-            int res;
-            res = JNI_CreateJavaVM(&jvm, (void **) &env, &vm_args);
-
-            if (res < 0)
-            {
-                error_logger() << " cannot create JavaVM." << endl;
-                return;
-            }
-            else
-            {
-                info_logger() << "JVM successfully created " << endl;
-            }
-
-            m_bundleVM.insert(std::pair< string, JavaVM * >(bundleInfo->getID(), jvm));
-
-            const char *className = bundleInfoInternal->getActivatorName().c_str();
-
-            info_logger() << "Looking up class: " << bundleInfoInternal->getActivatorName() << "|" << endl;
-
-            jclass bundleActivatorClass = env->FindClass(className);
-
-            if (bundleActivatorClass == NULL)
-            {
-                error_logger() << "Cannot register bundle " << bundleInfoInternal->getID()
-                               << " bundle activator(" << bundleInfoInternal->getActivatorName()
-                               << ") not found " << endl;
-                return;
-            }
-
-            jmethodID activateMethod = env->GetMethodID(bundleActivatorClass, "activateBundle",
-                                       "()V");
-
-            if (activateMethod == NULL)
-            {
-                error_logger() << "Cannot register bundle " << bundleInfoInternal->getID()
-                               << " activate bundle method not found " << endl;
-                return;
-            }
-            bundleInfoInternal->setJavaBundleActivatorMethod(activateMethod);
-
-            jmethodID deactivateMethod = env->GetMethodID(bundleActivatorClass, "deactivateBundle",
-                                         "()V");
-
-            if (deactivateMethod == NULL)
-            {
-                error_logger() << "Cannot register bundle " << bundleInfoInternal->getID()
-                               << " deactivate bundle method not found " << endl;
-                return;
-            }
-
-            bundleInfoInternal->setJavaBundleDeactivatorMethod(deactivateMethod);
-
-            jmethodID constructor;
-
-            constructor = env->GetMethodID(bundleActivatorClass, "<init>", "(Ljava/lang/String;)V");
-
-            jstring bundleID = env->NewStringUTF(bundleInfoInternal->getID().c_str());
-
-            jobject bundleActivator = env->NewObject(bundleActivatorClass, constructor, bundleID);
-
-            bundleInfoInternal->setJavaBundleActivatorObject(bundleActivator);
-
-            bundleInfoInternal->setLoaded(true);
-
-            m_bundles[bundleInfo->getID()] = ((BundleInfoInternal *)bundleInfo);
-
-            info_logger() << "Bundle registered" << endl;
-        }
-
         void ResourceContainerImpl::registerSoBundle(BundleInfo *bundleInfo)
         {
             char *error;
@@ -643,9 +526,11 @@ namespace OIC
             {
                 bundleActivator = (activator_t *) dlsym(bundleHandle, "externalActivateBundle");
                 bundleDeactivator = (deactivator_t *) dlsym(bundleHandle,
-                                    "externalDeactivateBundle");
-                resourceCreator = (resourceCreator_t *)dlsym(bundleHandle, "externalCreateResource");
-                resourceDestroyer = (resourceDestroyer_t *)dlsym(bundleHandle, "externalDestroyResource");
+                        "externalDeactivateBundle");
+                resourceCreator = (resourceCreator_t *) dlsym(bundleHandle,
+                        "externalCreateResource");
+                resourceDestroyer = (resourceDestroyer_t *) dlsym(bundleHandle,
+                        "externalDestroyResource");
 
                 if ((error = dlerror()) != NULL)
                 {
@@ -660,7 +545,7 @@ namespace OIC
                     ((BundleInfoInternal *) bundleInfo)->setLoaded(true);
                     ((BundleInfoInternal *) bundleInfo)->setBundleHandle(bundleHandle);
 
-                    m_bundles[bundleInfo->getID()] = ((BundleInfoInternal *)bundleInfo);
+                    m_bundles[bundleInfo->getID()] = ((BundleInfoInternal *) bundleInfo);
                 }
             }
             else
@@ -672,32 +557,6 @@ namespace OIC
             }
         }
 
-        void ResourceContainerImpl::activateJavaBundle(string bundleId)
-        {
-            info_logger() << "Activating java bundle" << endl;
-            JavaVM *vm = getJavaVM(bundleId);
-            BundleInfoInternal *bundleInfoInternal = (BundleInfoInternal *) m_bundles[bundleId];
-            JNIEnv *env;
-            int envStat = vm->GetEnv((void **) &env, JNI_VERSION_1_4);
-
-            if (envStat == JNI_EDETACHED)
-            {
-                if (vm->AttachCurrentThread((void **) &env, NULL) != 0)
-                {
-                    error_logger() << "Failed to attach " << endl;
-                }
-            }
-            else if (envStat == JNI_EVERSION)
-            {
-                error_logger() << "Env: version not supported " << endl;
-            }
-
-            env->CallVoidMethod(bundleInfoInternal->getJavaBundleActivatorObject(),
-                                bundleInfoInternal->getJavaBundleActivatorMethod());
-
-            m_bundles[bundleId]->setActivated(true);
-        }
-
         void ResourceContainerImpl::activateSoBundle(string bundleId)
         {
             activator_t *bundleActivator = m_bundles[bundleId]->getBundleActivator();
@@ -717,32 +576,6 @@ namespace OIC
             bundleInfoInternal->setActivated(true);
         }
 
-        void ResourceContainerImpl::deactivateJavaBundle(string bundleId)
-        {
-            info_logger() << "Deactivating java bundle" << endl;
-            JavaVM *vm = getJavaVM(bundleId);
-            BundleInfoInternal *bundleInfoInternal = (BundleInfoInternal *) m_bundles[bundleId];
-            JNIEnv *env;
-            int envStat = vm->GetEnv((void **) &env, JNI_VERSION_1_4);
-
-            if (envStat == JNI_EDETACHED)
-            {
-                if (vm->AttachCurrentThread((void **) &env, NULL) != 0)
-                {
-                    error_logger() << "Failed to attach " << endl;
-                }
-            }
-            else if (envStat == JNI_EVERSION)
-            {
-                error_logger() << "Env: version not supported " << endl;
-            }
-
-            env->CallVoidMethod(bundleInfoInternal->getJavaBundleActivatorObject(),
-                                bundleInfoInternal->getJavaBundleDeactivatorMethod());
-
-            m_bundles[bundleId]->setActivated(false);
-        }
-
         void ResourceContainerImpl::deactivateSoBundle(string id)
         {
             deactivator_t *bundleDeactivator = m_bundles[id]->getBundleDeactivator();
@@ -760,7 +593,8 @@ namespace OIC
             }
         }
 
-        void ResourceContainerImpl::addSoBundleResource(string bundleId, resourceInfo newResourceInfo)
+        void ResourceContainerImpl::addSoBundleResource(string bundleId,
+                resourceInfo newResourceInfo)
         {
             resourceCreator_t *resourceCreator;
 
@@ -780,7 +614,8 @@ namespace OIC
         {
             if (m_mapResources.find(resourceUri) != m_mapResources.end())
             {
-                resourceDestroyer_t *resourceDestroyer = m_bundles[bundleId]->getResourceDestroyer();
+                resourceDestroyer_t *resourceDestroyer =
+                        m_bundles[bundleId]->getResourceDestroyer();
 
                 if (resourceDestroyer != NULL)
                 {
@@ -792,6 +627,191 @@ namespace OIC
                 }
             }
         }
+
+#if(JAVA_SUPPORT)
+    JavaVM *ResourceContainerImpl::getJavaVM(string bundleId)
+    {
+        return m_bundleVM[bundleId];
     }
+
+    void ResourceContainerImpl::registerJavaBundle(BundleInfo *bundleInfo)
+    {
+        info_logger() << "Registering Java bundle " << bundleInfo->getID() << endl;
+        JavaVM *jvm;
+        JNIEnv *env;
+        JavaVMInitArgs vm_args;
+        JavaVMOption options[3];
+
+        BundleInfoInternal *bundleInfoInternal = (BundleInfoInternal *) bundleInfo;
+
+        if (FILE *file = fopen(bundleInfo->getPath().c_str(), "r"))
+        {
+            fclose(file);
+            info_logger() << "Resource bundle " << bundleInfo->getPath().c_str() << " available." << endl;
+            //return true;
+        }
+        else
+        {
+            error_logger() << "Resource bundle " << bundleInfo->getPath().c_str() << " not available" << endl;
+            return;
+        }
+
+        char optionString[] = "-Djava.compiler=NONE";
+        options[0].optionString = optionString;
+        char classpath[1000];
+        strcpy(classpath, "-Djava.class.path=");
+        strcat(classpath, bundleInfo->getPath().c_str());
+
+        info_logger() << "Configured classpath: " << classpath << "|" << endl;
+
+        options[1].optionString = classpath;
+
+        char libraryPath[1000];
+        strcpy(libraryPath, "-Djava.library.path=");
+        strcat(libraryPath, bundleInfo->getLibraryPath().c_str());
+        options[2].optionString = libraryPath;
+
+        info_logger() << "Configured library path: " << libraryPath << "|" << endl;
+
+        vm_args.version = JNI_VERSION_1_4;
+        vm_args.options = options;
+        vm_args.nOptions = 3;
+        vm_args.ignoreUnrecognized = 1;
+
+        int res;
+        res = JNI_CreateJavaVM(&jvm, (void **) &env, &vm_args);
+
+        if (res < 0)
+        {
+            error_logger() << " cannot create JavaVM." << endl;
+            return;
+        }
+        else
+        {
+            info_logger() << "JVM successfully created " << endl;
+        }
+
+        m_bundleVM.insert(std::pair< string, JavaVM * >(bundleInfo->getID(), jvm));
+
+        const char *className = bundleInfoInternal->getActivatorName().c_str();
+
+        info_logger() << "Looking up class: " << bundleInfoInternal->getActivatorName() << "|" << endl;
+
+        jclass bundleActivatorClass = env->FindClass(className);
+
+        if (bundleActivatorClass == NULL)
+        {
+            error_logger() << "Cannot register bundle " << bundleInfoInternal->getID()
+            << " bundle activator(" << bundleInfoInternal->getActivatorName()
+            << ") not found " << endl;
+            return;
+        }
+
+        jmethodID activateMethod = env->GetMethodID(bundleActivatorClass, "activateBundle",
+                "()V");
+
+        if (activateMethod == NULL)
+        {
+            error_logger() << "Cannot register bundle " << bundleInfoInternal->getID()
+            << " activate bundle method not found " << endl;
+            return;
+        }
+        bundleInfoInternal->setJavaBundleActivatorMethod(activateMethod);
+
+        jmethodID deactivateMethod = env->GetMethodID(bundleActivatorClass, "deactivateBundle",
+                "()V");
+
+        if (deactivateMethod == NULL)
+        {
+            error_logger() << "Cannot register bundle " << bundleInfoInternal->getID()
+            << " deactivate bundle method not found " << endl;
+            return;
+        }
+
+        bundleInfoInternal->setJavaBundleDeactivatorMethod(deactivateMethod);
+
+        jmethodID constructor;
+
+        constructor = env->GetMethodID(bundleActivatorClass, "<init>", "(Ljava/lang/String;)V");
+
+        jstring bundleID = env->NewStringUTF(bundleInfoInternal->getID().c_str());
+
+        jobject bundleActivator = env->NewObject(bundleActivatorClass, constructor, bundleID);
+
+        bundleInfoInternal->setJavaBundleActivatorObject(bundleActivator);
+
+        bundleInfoInternal->setLoaded(true);
+
+        m_bundles[bundleInfo->getID()] = ((BundleInfoInternal *)bundleInfo);
+
+        info_logger() << "Bundle registered" << endl;
+    }
+
+    void ResourceContainerImpl::activateJavaBundle(string bundleId)
+    {
+        info_logger() << "Activating java bundle" << endl;
+        JavaVM *vm = getJavaVM(bundleId);
+        BundleInfoInternal *bundleInfoInternal = (BundleInfoInternal *) m_bundles[bundleId];
+        JNIEnv *env;
+        int envStat = vm->GetEnv((void **) &env, JNI_VERSION_1_4);
+
+        if (envStat == JNI_EDETACHED)
+        {
+            if (vm->AttachCurrentThread((void **) &env, NULL) != 0)
+            {
+                error_logger() << "Failed to attach " << endl;
+            }
+        }
+        else if (envStat == JNI_EVERSION)
+        {
+            error_logger() << "Env: version not supported " << endl;
+        }
+
+        env->CallVoidMethod(bundleInfoInternal->getJavaBundleActivatorObject(),
+                bundleInfoInternal->getJavaBundleActivatorMethod());
+
+        m_bundles[bundleId]->setActivated(true);
+    }
+
+    void ResourceContainerImpl::deactivateJavaBundle(string bundleId)
+    {
+        info_logger() << "Deactivating java bundle" << endl;
+        JavaVM *vm = getJavaVM(bundleId);
+        BundleInfoInternal *bundleInfoInternal = (BundleInfoInternal *) m_bundles[bundleId];
+        JNIEnv *env;
+        int envStat = vm->GetEnv((void **) &env, JNI_VERSION_1_4);
+
+        if (envStat == JNI_EDETACHED)
+        {
+            if (vm->AttachCurrentThread((void **) &env, NULL) != 0)
+            {
+                error_logger() << "Failed to attach " << endl;
+            }
+        }
+        else if (envStat == JNI_EVERSION)
+        {
+            error_logger() << "Env: version not supported " << endl;
+        }
+
+        env->CallVoidMethod(bundleInfoInternal->getJavaBundleActivatorObject(),
+                bundleInfoInternal->getJavaBundleDeactivatorMethod());
+
+        m_bundles[bundleId]->setActivated(false);
+    }
+
+    void ResourceContainerImpl::unregisterBundleJava(string id)
+    {
+        info_logger() << "Unregister Java bundle: " << m_bundles[id]->getID() << ", "
+        << m_bundles[id]->getID() << endl;
+
+        info_logger() << "Destroying JVM" << endl;
+        m_bundleVM[id]->DestroyJavaVM();
+
+        delete m_bundles[id];
+        m_bundles.erase(id);
+    }
+#endif
+    }
+
 }
 
index d13c4b4..92e1178 100644 (file)
@@ -290,6 +290,7 @@ TEST_F(ResourceContainerImplTest, SoBundleLoadedWhenRegisteredWithRegisterBundle
     EXPECT_NE(nullptr, ((BundleInfoInternal *)m_pBundleInfo)->getBundleHandle());
 }
 
+#if (JAVA_SUPPORT_TEST)
 TEST_F(ResourceContainerImplTest, JavaBundleLoadedWhenRegisteredWithRegisterBundleAPIWrongPath)
 {
     m_pBundleInfo->setPath("wrong_path.jar");
@@ -319,6 +320,7 @@ TEST_F(ResourceContainerImplTest, JavaBundleTest)
     m_pResourceContainer->deactivateBundle(m_pBundleInfo);
     EXPECT_FALSE(((BundleInfoInternal *) m_pBundleInfo)->isActivated());
 }
+#endif
 
 TEST_F(ResourceContainerImplTest, BundleNotRegisteredIfBundlePathIsInvalid)
 {
index daebaad..abe6add 100644 (file)
@@ -34,23 +34,6 @@ def filtered_glob(env, pattern, omit=[],
 
 env.AddMethod(filtered_glob, "FilteredGlob");
 
-try:
-       print 'Java Home: ', os.environ['JAVA_HOME']
-       print 'Java Lib: ', os.environ['JAVA_LIB']
-except KeyError:
-       print '''
-*********************************** Error *************************************
-* Cannot build resource container. JAVA_HOME or JAVA_LIB are not set properly 
-* Please configure JAVA_HOME to point to your Java 7 JDK and 
-* JAVA_LIB to your folder containing libjvm
-* Example: export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386
-*          export JAVA_LIB=/usr/lib/jvm/java-7-openjdk-i386/jre/lib/i386/server/
-*******************************************************************************        
-       '''
-       Return()
-       
-
-
 if env.get('RELEASE'):
        env.AppendUnique(CCFLAGS = ['-Os'])
        env.AppendUnique(CPPDEFINES = ['NDEBUG'])
@@ -68,6 +51,24 @@ lib_env = env.Clone()
 SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
 
 container_gtest_env = lib_env.Clone()
+
+try:
+       print 'Java Home: ', os.environ['JAVA_HOME']
+       print 'Java Lib: ', os.environ['JAVA_LIB']
+       container_gtest_env.Append(CPPDEFINES={'JAVA_SUPPORT_TEST':1})
+except KeyError:
+       print '''
+*********************************** Error *************************************
+* Building resource container without Java support. JAVA_HOME or JAVA_LIB are not set properly 
+* Please configure JAVA_HOME to point to your Java 7 JDK and 
+* JAVA_LIB to your folder containing libjvm
+* Example: export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386
+*          export JAVA_LIB=/usr/lib/jvm/java-7-openjdk-i386/jre/lib/i386/server/
+*******************************************************************************        
+       '''
+       container_gtest_env.Append(CPPDEFINES={'JAVA_SUPPORT_TEST':0})
+       
+
 target_os = env.get('TARGET_OS')
 
 ######################### unit test setting ##########################
@@ -88,10 +89,17 @@ container_gtest_env.AppendUnique(
                '../include',
                '../../../include',
                '../include/internal',
-               '../bundle-api/include',
+               '../bundle-api/include'         
+       ])
+       
+try:
+       container_gtest_env.AppendUnique(
+       CPPPATH = [
                os.environ['JAVA_HOME']+'/include',
-               os.environ['JAVA_HOME']+'/include/linux'
+               os.environ['JAVA_HOME']+'/include/linux'                
        ])
+except KeyError:
+       print ''
 
 if target_os not in ['windows', 'winrt']:
        container_gtest_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall'])
@@ -106,26 +114,25 @@ if target_os == 'android':
 container_gtest_env.PrependUnique(CPPPATH = [env.get('SRC_DIR')+'/extlibs/hippomocks-master',
                              gtest_dir + '/include'])
                                                                         
-container_gtest_env.AppendUnique(LIBPATH = [os.environ['JAVA_LIB']])
+try:
+       container_gtest_env.AppendUnique(LIBPATH = [os.environ['JAVA_LIB']])
+except KeyError:
+       print ''
 
 container_gtest_env.AppendUnique(CCFLAGS = ['-Wnoexcept'])     
 
-conf = Configure(container_gtest_env)
-if not conf.CheckLib('jvm'):
-       print '''
-*********************************** Error *************************************
-* Cannot locate libjvm for resourc container test. Please check your JAVA_HOME 
-* and configure JAVA_LIB to point to your folder containing libjvm.
-* Example: export JAVA_LIB=/usr/lib/jvm/java-7-openjdk-i386/jre/lib/i386/server
-*******************************************************************************        
-       '''
-       container_gtest_env = conf.Finish()
-       Return()
-container_gtest_env = conf.Finish()
+
 
 container_gtest_env.PrependUnique(LIBS = ['ResContainerLib', 'server_builder', 'service_common', 'oc','octbstack', 'oc_logger', 'oc_logger_core', 'connectivity_abstraction', gtest, gtest_main])
-container_gtest_env.AppendUnique(LIBS = ['dl', 'jvm']) 
 
+container_gtest_env.AppendUnique(LIBS = ['dl'])
+
+
+try:   
+       print 'Java Lib: ', os.environ['JAVA_LIB']
+       container_gtest_env.AppendUnique(LIBS = ['jvm'])                
+except KeyError:
+       print ''
 
 ######################################################################
 # build test bundle