From 5b54af95d00b24371b7c323090808b092034c770 Mon Sep 17 00:00:00 2001 From: Oliver Bolte Date: Thu, 7 Jul 2005 09:57:52 +0000 Subject: INTEGRATION: CWS sb33 (1.7.58); FILE MERGED 2005/06/30 16:50:13 sb 1.7.58.1: #120220# Adapted to changed uno_getEnvironment(..., java, pContext). --- javaunohelper/source/bootstrap.cxx | 91 +++++----------------------------- javaunohelper/source/javaunohelper.cxx | 42 +++++++--------- 2 files changed, 29 insertions(+), 104 deletions(-) (limited to 'javaunohelper/source') diff --git a/javaunohelper/source/bootstrap.cxx b/javaunohelper/source/bootstrap.cxx index 147889f83136..bfd152dd3e4a 100644 --- a/javaunohelper/source/bootstrap.cxx +++ b/javaunohelper/source/bootstrap.cxx @@ -2,9 +2,9 @@ * * $RCSfile: bootstrap.cxx,v $ * - * $Revision: 1.7 $ + * $Revision: 1.8 $ * - * last change: $Author: hr $ $Date: 2003-08-07 14:36:26 $ + * last change: $Author: obo $ $Date: 2005-07-07 10:57:39 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -60,7 +60,6 @@ ************************************************************************/ #include "osl/diagnose.h" -#include "osl/mutex.hxx" #include "rtl/alloc.h" #include "rtl/bootstrap.hxx" @@ -70,13 +69,15 @@ #include "uno/environment.hxx" #include "cppuhelper/bootstrap.hxx" -#include "cppuhelper/compbase1.hxx" -#include "cppuhelper/component_context.hxx" +#include "com/sun/star/lang/XComponent.hpp" #include "com/sun/star/lang/XSingleComponentFactory.hpp" #include "jni.h" #include "jvmaccess/virtualmachine.hxx" +#include "jvmaccess/unovirtualmachine.hxx" + +#include "vm.hxx" #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) ) @@ -88,77 +89,7 @@ using ::rtl::OUString; namespace javaunohelper { -struct MutexHolder -{ - ::osl::Mutex m_mutex; -}; -typedef ::cppu::WeakComponentImplHelper1< lang::XSingleComponentFactory > t_impl; - -//================================================================================================== -class SingletonFactory : public MutexHolder, public t_impl -{ - ::rtl::Reference< ::jvmaccess::VirtualMachine > m_vm_access; - -protected: - virtual void SAL_CALL disposing(); - -public: - inline SingletonFactory( ::rtl::Reference< ::jvmaccess::VirtualMachine > const & vm_access ) - : t_impl( m_mutex ), - m_vm_access( vm_access ) - {} - - // XSingleComponentFactory impl - virtual Reference< XInterface > SAL_CALL createInstanceWithContext( - Reference< XComponentContext > const & xContext ) - throw (Exception); - virtual Reference< XInterface > SAL_CALL createInstanceWithArgumentsAndContext( - Sequence< Any > const & args, Reference< XComponentContext > const & xContext ) - throw (Exception); -}; -//__________________________________________________________________________________________________ -void SingletonFactory::disposing() -{ - m_vm_access.clear(); -} -//__________________________________________________________________________________________________ -Reference< XInterface > SingletonFactory::createInstanceWithContext( - Reference< XComponentContext > const & xContext ) - throw (Exception) -{ - sal_Int64 handle = reinterpret_cast< sal_Int64 >( m_vm_access.get() ); - Any arg( makeAny( handle ) ); - return xContext->getServiceManager()->createInstanceWithArgumentsAndContext( - OUSTR("com.sun.star.java.JavaVirtualMachine"), Sequence< Any >( &arg, 1 ), xContext ); -} -//__________________________________________________________________________________________________ -Reference< XInterface > SingletonFactory::createInstanceWithArgumentsAndContext( - Sequence< Any > const & args, Reference< XComponentContext > const & xContext ) - throw (Exception) -{ - return xContext->getServiceManager()->createInstanceWithArgumentsAndContext( - OUSTR("com.sun.star.java.JavaVirtualMachine"), args, xContext ); -} -//================================================================================================== -Reference< XComponentContext > install_vm_singleton( - Reference< XComponentContext > const & xContext, - ::rtl::Reference< ::jvmaccess::VirtualMachine > const & vm_access ) -{ - Reference< lang::XSingleComponentFactory > xFac( new SingletonFactory( vm_access ) ); - ::cppu::ContextEntry_Init entry( - OUSTR("/singletons/com.sun.star.java.theJavaVirtualMachine"), makeAny( xFac ), true ); - return ::cppu::createComponentContext( &entry, 1, xContext ); -} -//================================================================================================== -::rtl::Reference< ::jvmaccess::VirtualMachine > create_vm_access( JNIEnv * jni_env ) -{ - JavaVM * vm; - jni_env->GetJavaVM( &vm ); - return new ::jvmaccess::VirtualMachine( vm, JNI_VERSION_1_2, false, jni_env ); -} - -//================================================================================================== inline ::rtl::OUString jstring_to_oustring( jstring jstr, JNIEnv * jni_env ) { OSL_ASSERT( sizeof (sal_Unicode) == sizeof (jchar) ); @@ -177,7 +108,8 @@ inline ::rtl::OUString jstring_to_oustring( jstring jstr, JNIEnv * jni_env ) //================================================================================================== extern "C" JNIEXPORT jobject JNICALL Java_com_sun_star_comp_helper_Bootstrap_cppuhelper_1bootstrap( - JNIEnv * jni_env, jclass jClass, jstring juno_rc, jobjectArray jpairs ) + JNIEnv * jni_env, jclass jClass, jstring juno_rc, jobjectArray jpairs, + jobject loader ) { try { @@ -230,10 +162,11 @@ extern "C" JNIEXPORT jobject JNICALL Java_com_sun_star_comp_helper_Bootstrap_cpp } // create vm access - ::rtl::Reference< ::jvmaccess::VirtualMachine > vm_access( - ::javaunohelper::create_vm_access( jni_env ) ); + ::rtl::Reference< ::jvmaccess::UnoVirtualMachine > vm_access( + ::javaunohelper::create_vm_access( jni_env, loader ) ); // wrap vm singleton entry - xContext = ::javaunohelper::install_vm_singleton( xContext, vm_access ); + xContext = ::javaunohelper::install_vm_singleton( + xContext, vm_access->getVirtualMachine() ); // get uno envs OUString cpp_env_name = OUSTR(CPPU_CURRENT_LANGUAGE_BINDING_NAME); diff --git a/javaunohelper/source/javaunohelper.cxx b/javaunohelper/source/javaunohelper.cxx index e9a63804cf9f..e2bdcc7af536 100644 --- a/javaunohelper/source/javaunohelper.cxx +++ b/javaunohelper/source/javaunohelper.cxx @@ -2,9 +2,9 @@ * * $RCSfile: javaunohelper.cxx,v $ * - * $Revision: 1.7 $ + * $Revision: 1.8 $ * - * last change: $Author: hr $ $Date: 2003-08-07 14:36:35 $ + * last change: $Author: obo $ $Date: 2005-07-07 10:57:52 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -76,6 +76,9 @@ #include "jni.h" #include "jvmaccess/virtualmachine.hxx" +#include "jvmaccess/unovirtualmachine.hxx" + +#include "vm.hxx" #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) ) @@ -85,19 +88,6 @@ using namespace ::com::sun::star::uno; using ::rtl::OString; using ::rtl::OUString; -namespace javaunohelper -{ - -//================================================================================================== -Reference< XComponentContext > install_vm_singleton( - Reference< XComponentContext > const & xContext, - ::rtl::Reference< ::jvmaccess::VirtualMachine > const & vm_access ); -//================================================================================================== -::rtl::Reference< ::jvmaccess::VirtualMachine > create_vm_access( JNIEnv * jni_env ); - -} - - /* * Class: com_sun_star_comp_helper_SharedLibraryLoader * Method: component_writeInfo @@ -105,7 +95,8 @@ Reference< XComponentContext > install_vm_singleton( */ extern "C" JNIEXPORT jboolean JNICALL Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1writeInfo( - JNIEnv * pJEnv, jclass jClass, jstring jLibName, jobject jSMgr, jobject jRegKey ) + JNIEnv * pJEnv, jclass jClass, jstring jLibName, jobject jSMgr, + jobject jRegKey, jobject loader ) { sal_Bool bRet = sal_False; @@ -134,8 +125,8 @@ Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1writeInfo( } // create vm access - ::rtl::Reference< ::jvmaccess::VirtualMachine > vm_access( - ::javaunohelper::create_vm_access( pJEnv ) ); + ::rtl::Reference< ::jvmaccess::UnoVirtualMachine > vm_access( + ::javaunohelper::create_vm_access( pJEnv, loader ) ); OUString java_env_name = OUSTR(UNO_LB_JAVA); uno_getEnvironment( (uno_Environment **)&java_env, java_env_name.pData, vm_access.get() ); @@ -184,7 +175,7 @@ Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1writeInfo( extern "C" JNIEXPORT jobject JNICALL Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1getFactory( JNIEnv * pJEnv, jclass jClass, jstring jLibName, jstring jImplName, - jobject jSMgr, jobject jRegKey ) + jobject jSMgr, jobject jRegKey, jobject loader ) { const jchar* pJLibName = pJEnv->GetStringChars(jLibName, NULL); OUString aLibName( pJLibName ); @@ -216,8 +207,8 @@ Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1getFactory( } // create vm access - ::rtl::Reference< ::jvmaccess::VirtualMachine > vm_access( - ::javaunohelper::create_vm_access( pJEnv ) ); + ::rtl::Reference< ::jvmaccess::UnoVirtualMachine > vm_access( + ::javaunohelper::create_vm_access( pJEnv, loader ) ); OUString java_env_name = OUSTR(UNO_LB_JAVA); uno_getEnvironment( (uno_Environment **)&java_env, java_env_name.pData, vm_access.get() ); @@ -279,7 +270,7 @@ Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1getFactory( extern "C" JNIEXPORT jobject JNICALL Java_com_sun_star_comp_helper_RegistryServiceFactory_createRegistryServiceFactory( JNIEnv * pJEnv, jclass jClass, jstring jWriteRegFile, - jstring jReadRegFile, jboolean jbReadOnly ) + jstring jReadRegFile, jboolean jbReadOnly, jobject loader ) { jobject joRegServiceFac = 0; @@ -315,10 +306,11 @@ Java_com_sun_star_comp_helper_RegistryServiceFactory_createRegistryServiceFactor xProps->getPropertyValue( OUSTR("DefaultContext") ), UNO_QUERY_THROW ); // create vm access - ::rtl::Reference< ::jvmaccess::VirtualMachine > vm_access( - ::javaunohelper::create_vm_access( pJEnv ) ); + ::rtl::Reference< ::jvmaccess::UnoVirtualMachine > vm_access( + ::javaunohelper::create_vm_access( pJEnv, loader ) ); // wrap vm singleton entry - xContext = ::javaunohelper::install_vm_singleton( xContext, vm_access ); + xContext = ::javaunohelper::install_vm_singleton( + xContext, vm_access->getVirtualMachine() ); rMSFac.set( xContext->getServiceManager(), UNO_QUERY_THROW ); // get uno envs -- cgit