summaryrefslogtreecommitdiff
path: root/javaunohelper/source
diff options
context:
space:
mode:
Diffstat (limited to 'javaunohelper/source')
-rw-r--r--javaunohelper/source/bootstrap.cxx192
-rw-r--r--javaunohelper/source/javaunohelper.cxx326
-rw-r--r--javaunohelper/source/javaunohelper.map9
-rw-r--r--javaunohelper/source/makefile.mk138
-rw-r--r--javaunohelper/source/preload.cxx161
-rw-r--r--javaunohelper/source/vm.cxx150
-rw-r--r--javaunohelper/source/vm.hxx58
7 files changed, 1034 insertions, 0 deletions
diff --git a/javaunohelper/source/bootstrap.cxx b/javaunohelper/source/bootstrap.cxx
new file mode 100644
index 000000000000..98219d4f4f67
--- /dev/null
+++ b/javaunohelper/source/bootstrap.cxx
@@ -0,0 +1,192 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: bootstrap.cxx,v $
+ * $Revision: 1.13 $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_javaunohelper.hxx"
+
+#include "osl/diagnose.h"
+
+#include "rtl/alloc.h"
+#include "rtl/bootstrap.hxx"
+#include "rtl/string.hxx"
+
+#include "uno/mapping.hxx"
+#include "uno/environment.hxx"
+
+#include "cppuhelper/bootstrap.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) )
+
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
+using ::rtl::OString;
+using ::rtl::OUString;
+
+namespace javaunohelper
+{
+
+inline ::rtl::OUString jstring_to_oustring( jstring jstr, JNIEnv * jni_env )
+{
+ OSL_ASSERT( sizeof (sal_Unicode) == sizeof (jchar) );
+ jsize len = jni_env->GetStringLength( jstr );
+ rtl_uString * ustr =
+ (rtl_uString *)rtl_allocateMemory( sizeof (rtl_uString) + (len * sizeof (sal_Unicode)) );
+ jni_env->GetStringRegion( jstr, 0, len, ustr->buffer );
+ OSL_ASSERT( JNI_FALSE == jni_env->ExceptionCheck() );
+ ustr->refCount = 1;
+ ustr->length = len;
+ ustr->buffer[ len ] = '\0';
+ return ::rtl::OUString( ustr, SAL_NO_ACQUIRE );
+}
+
+}
+
+//==================================================================================================
+extern "C" JNIEXPORT jobject JNICALL Java_com_sun_star_comp_helper_Bootstrap_cppuhelper_1bootstrap(
+ JNIEnv * jni_env, jclass, jstring juno_rc, jobjectArray jpairs,
+ jobject loader )
+{
+ try
+ {
+ if (0 != jpairs)
+ {
+ jsize nPos = 0, len = jni_env->GetArrayLength( jpairs );
+ while (nPos < len)
+ {
+ // name
+ jstring jstr = (jstring)jni_env->GetObjectArrayElement( jpairs, nPos );
+ if (JNI_FALSE != jni_env->ExceptionCheck())
+ {
+ jni_env->ExceptionClear();
+ throw RuntimeException(
+ OUSTR("index out of bounds?!"), Reference< XInterface >() );
+ }
+ if (0 != jstr)
+ {
+ OUString name( ::javaunohelper::jstring_to_oustring( jstr, jni_env ) );
+ // value
+ jstr = (jstring)jni_env->GetObjectArrayElement( jpairs, nPos +1 );
+ if (JNI_FALSE != jni_env->ExceptionCheck())
+ {
+ jni_env->ExceptionClear();
+ throw RuntimeException(
+ OUSTR("index out of bounds?!"), Reference< XInterface >() );
+ }
+ if (0 != jstr)
+ {
+ OUString value( ::javaunohelper::jstring_to_oustring( jstr, jni_env ) );
+
+ // set bootstrap parameter
+ ::rtl::Bootstrap::set( name, value );
+ }
+ }
+ nPos += 2;
+ }
+ }
+
+ // bootstrap uno
+ Reference< XComponentContext > xContext;
+ if (0 == juno_rc)
+ {
+ xContext = ::cppu::defaultBootstrap_InitialComponentContext();
+ }
+ else
+ {
+ OUString uno_rc( ::javaunohelper::jstring_to_oustring( juno_rc, jni_env ) );
+ xContext = ::cppu::defaultBootstrap_InitialComponentContext( uno_rc );
+ }
+
+ // create vm access
+ ::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 );
+
+ // get uno envs
+ OUString cpp_env_name = OUSTR(CPPU_CURRENT_LANGUAGE_BINDING_NAME);
+ OUString java_env_name = OUSTR(UNO_LB_JAVA);
+ Environment java_env, cpp_env;
+ uno_getEnvironment((uno_Environment **)&cpp_env, cpp_env_name.pData, NULL);
+ uno_getEnvironment( (uno_Environment **)&java_env, java_env_name.pData, vm_access.get() );
+
+ // map to java
+ Mapping mapping( cpp_env.get(), java_env.get() );
+ if (! mapping.is())
+ {
+ Reference< lang::XComponent > xComp( xContext, UNO_QUERY );
+ if (xComp.is())
+ xComp->dispose();
+ throw RuntimeException(
+ OUSTR("cannot get mapping C++ <-> Java!"),
+ Reference< XInterface >() );
+ }
+
+ jobject jret = (jobject)mapping.mapInterface( xContext.get(), ::getCppuType( &xContext ) );
+ jobject jlocal = jni_env->NewLocalRef( jret );
+ jni_env->DeleteGlobalRef( jret );
+
+ return jlocal;
+ }
+ catch (RuntimeException & exc)
+ {
+ jclass c = jni_env->FindClass( "com/sun/star/uno/RuntimeException" );
+ if (0 != c)
+ {
+ OString cstr( ::rtl::OUStringToOString(
+ exc.Message, RTL_TEXTENCODING_JAVA_UTF8 ) );
+ OSL_TRACE( __FILE__": forwarding RuntimeException: %s", cstr.getStr() );
+ jni_env->ThrowNew( c, cstr.getStr() );
+ }
+ }
+ catch (Exception & exc)
+ {
+ jclass c = jni_env->FindClass( "com/sun/star/uno/Exception" );
+ if (0 != c)
+ {
+ OString cstr( ::rtl::OUStringToOString(
+ exc.Message, RTL_TEXTENCODING_JAVA_UTF8 ) );
+ OSL_TRACE( __FILE__": forwarding Exception: %s", cstr.getStr() );
+ jni_env->ThrowNew( c, cstr.getStr() );
+ }
+ }
+
+ return 0;
+}
+
diff --git a/javaunohelper/source/javaunohelper.cxx b/javaunohelper/source/javaunohelper.cxx
new file mode 100644
index 000000000000..1ba29dc8d640
--- /dev/null
+++ b/javaunohelper/source/javaunohelper.cxx
@@ -0,0 +1,326 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: javaunohelper.cxx,v $
+ * $Revision: 1.13 $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_javaunohelper.hxx"
+
+#include <osl/diagnose.h>
+#include <osl/module.h>
+
+#include <uno/environment.hxx>
+#include <uno/mapping.hxx>
+
+#include <cppuhelper/factory.hxx>
+#include <cppuhelper/servicefactory.hxx>
+#include <cppuhelper/component_context.hxx>
+
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/registry/XRegistryKey.hpp>
+
+#include "jni.h"
+#include "jvmaccess/virtualmachine.hxx"
+#include "jvmaccess/unovirtualmachine.hxx"
+
+#include "vm.hxx"
+
+#define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
+
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
+using ::rtl::OString;
+using ::rtl::OUString;
+
+/*
+ * Class: com_sun_star_comp_helper_SharedLibraryLoader
+ * Method: component_writeInfo
+ * Signature: (Ljava/lang/String;Lcom/sun/star/lang/XMultiServiceFactory;Lcom/sun/star/registry/XRegistryKey;)Z
+ */
+extern "C" JNIEXPORT jboolean JNICALL
+Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1writeInfo(
+ JNIEnv * pJEnv, jclass, jstring jLibName, jobject jSMgr,
+ jobject jRegKey, jobject loader )
+{
+ sal_Bool bRet = sal_False;
+
+ const jchar* pJLibName = pJEnv->GetStringChars( jLibName, NULL );
+ OUString aLibName( pJLibName );
+ pJEnv->ReleaseStringChars( jLibName, pJLibName);
+
+ oslModule lib = osl_loadModule( aLibName.pData, SAL_LOADMODULE_LAZY | SAL_LOADMODULE_GLOBAL );
+ if (lib)
+ {
+ // ========================= LATEST VERSION =========================
+ OUString aGetEnvName( RTL_CONSTASCII_USTRINGPARAM(COMPONENT_GETENV) );
+ oslGenericFunction pSym =
+ osl_getFunctionSymbol( lib, aGetEnvName.pData );
+ if (pSym)
+ {
+ Environment java_env, loader_env;
+
+ const sal_Char * pEnvTypeName = 0;
+ (*((component_getImplementationEnvironmentFunc)pSym))(
+ &pEnvTypeName, (uno_Environment **)&loader_env );
+ if (! loader_env.is())
+ {
+ OUString aEnvTypeName( OUString::createFromAscii( pEnvTypeName ) );
+ uno_getEnvironment( (uno_Environment **)&loader_env, aEnvTypeName.pData, 0 );
+ }
+
+ // create vm access
+ ::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() );
+
+ OUString aWriteInfoName( RTL_CONSTASCII_USTRINGPARAM(COMPONENT_WRITEINFO) );
+ pSym = osl_getFunctionSymbol( lib, aWriteInfoName.pData );
+ if (pSym)
+ {
+ if (loader_env.is() && java_env.is())
+ {
+ Mapping java2dest(java_env.get(), loader_env.get());
+
+ if ( java2dest.is() )
+ {
+ void * pSMgr =
+ java2dest.mapInterface(
+ jSMgr, getCppuType((Reference< lang::XMultiServiceFactory > *) 0) );
+ void * pKey =
+ java2dest.mapInterface(
+ jRegKey, getCppuType((Reference< registry::XRegistryKey > *) 0) );
+
+ uno_ExtEnvironment * env = loader_env.get()->pExtEnv;
+ if (pKey)
+ {
+ bRet = (*((component_writeInfoFunc)pSym))( pSMgr, pKey );
+
+ if (env)
+ (*env->releaseInterface)( env, pKey );
+ }
+
+ if (pSMgr && env)
+ (*env->releaseInterface)( env, pSMgr );
+ }
+ }
+ }
+ }
+ }
+
+ return bRet == sal_False? JNI_FALSE : JNI_TRUE;
+}
+
+/*
+ * Class: com_sun_star_comp_helper_SharedLibraryLoader
+ * Method: component_getFactory
+ * Signature: (Ljava/lang/String;Ljava/lang/String;Lcom/sun/star/lang/XMultiServiceFactory;Lcom/sun/star/registry/XRegistryKey;)Ljava/lang/Object;
+ */
+extern "C" JNIEXPORT jobject JNICALL
+Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1getFactory(
+ JNIEnv * pJEnv, jclass, jstring jLibName, jstring jImplName,
+ jobject jSMgr, jobject jRegKey, jobject loader )
+{
+ const jchar* pJLibName = pJEnv->GetStringChars(jLibName, NULL);
+ OUString aLibName( pJLibName );
+ pJEnv->ReleaseStringChars( jLibName, pJLibName);
+
+ aLibName += OUString( RTL_CONSTASCII_USTRINGPARAM(SAL_DLLEXTENSION) );
+
+ jobject joSLL_cpp = 0;
+
+ oslModule lib = osl_loadModule( aLibName.pData, SAL_LOADMODULE_LAZY | SAL_LOADMODULE_GLOBAL );
+ if (lib)
+ {
+ // ========================= LATEST VERSION =========================
+ OUString aGetEnvName( RTL_CONSTASCII_USTRINGPARAM(COMPONENT_GETENV) );
+ oslGenericFunction pSym =
+ osl_getFunctionSymbol( lib, aGetEnvName.pData );
+ if (pSym)
+ {
+ Environment java_env, loader_env;
+
+ const sal_Char * pEnvTypeName = 0;
+ (*((component_getImplementationEnvironmentFunc)pSym))(
+ &pEnvTypeName, (uno_Environment **)&loader_env );
+
+ if (! loader_env.is())
+ {
+ OUString aEnvTypeName( OUString::createFromAscii( pEnvTypeName ) );
+ uno_getEnvironment( (uno_Environment **)&loader_env, aEnvTypeName.pData, 0 );
+ }
+
+ // create vm access
+ ::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() );
+
+ OUString aGetFactoryName( RTL_CONSTASCII_USTRINGPARAM(COMPONENT_GETFACTORY) );
+ pSym = osl_getFunctionSymbol( lib, aGetFactoryName.pData );
+ if (pSym)
+ {
+ if (loader_env.is() && java_env.is())
+ {
+ Mapping java2dest( java_env.get(), loader_env.get() );
+ Mapping dest2java( loader_env.get(), java_env.get() );
+
+ if (dest2java.is() && java2dest.is())
+ {
+ void * pSMgr =
+ java2dest.mapInterface(
+ jSMgr, ::getCppuType((Reference< lang::XMultiServiceFactory > *) 0) );
+ void * pKey =
+ java2dest.mapInterface(
+ jRegKey, ::getCppuType((Reference< registry::XRegistryKey > *) 0) );
+
+ const char* pImplName = pJEnv->GetStringUTFChars( jImplName, NULL );
+
+ void * pSSF = (*((component_getFactoryFunc)pSym))(
+ pImplName, pSMgr, pKey );
+
+ pJEnv->ReleaseStringUTFChars( jImplName, pImplName );
+
+ uno_ExtEnvironment * env = loader_env.get()->pExtEnv;
+
+ if (pKey && env)
+ (*env->releaseInterface)( env, pKey );
+ if (pSMgr && env)
+ (*env->releaseInterface)( env, pSMgr );
+
+ if (pSSF)
+ {
+ jobject jglobal = (jobject) dest2java.mapInterface(
+ pSSF, getCppuType((Reference< XInterface > *) 0) );
+ joSLL_cpp = pJEnv->NewLocalRef( jglobal );
+ pJEnv->DeleteGlobalRef( jglobal );
+ if (env)
+ (*env->releaseInterface)( env, pSSF );
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return joSLL_cpp;
+}
+
+/*
+ * Class: com_sun_star_comp_helper_RegistryServiceFactory
+ * Method: createRegistryServiceFactory
+ * Signature: (Ljava/lang/String;Ljava/lang/String;Z)Ljava/lang/Object;
+ */
+extern "C" JNIEXPORT jobject JNICALL
+Java_com_sun_star_comp_helper_RegistryServiceFactory_createRegistryServiceFactory(
+ JNIEnv * pJEnv, jclass, jstring jWriteRegFile,
+ jstring jReadRegFile, jboolean jbReadOnly, jobject loader )
+{
+ jobject joRegServiceFac = 0;
+
+ try
+ {
+ OUString aWriteRegFile;
+ OUString aReadRegFile;
+
+ sal_Bool bReadOnly = jbReadOnly == JNI_FALSE ? sal_False : sal_True;
+
+ if (jReadRegFile) {
+ const jchar* pjReadRegFile = pJEnv->GetStringChars(jReadRegFile, NULL);
+ aReadRegFile = OUString(pjReadRegFile);
+ pJEnv->ReleaseStringChars(jReadRegFile, pjReadRegFile);
+ }
+
+ if (jWriteRegFile) {
+ const jchar * pjWriteRegFile = pJEnv->GetStringChars(jWriteRegFile, NULL);
+ aWriteRegFile = OUString(pjWriteRegFile);
+ pJEnv->ReleaseStringChars(jWriteRegFile, pjWriteRegFile);
+ }
+
+ // bootstrap
+ Reference< lang::XMultiServiceFactory > rMSFac;
+ if (aReadRegFile.getLength() == 0)
+ rMSFac = ::cppu::createRegistryServiceFactory( aWriteRegFile, bReadOnly);
+ else
+ rMSFac = ::cppu::createRegistryServiceFactory(aWriteRegFile, aReadRegFile, bReadOnly);
+
+ Reference< beans::XPropertySet > xProps(
+ rMSFac, UNO_QUERY_THROW );
+ Reference< XComponentContext > xContext(
+ xProps->getPropertyValue( OUSTR("DefaultContext") ), UNO_QUERY_THROW );
+
+ // create vm access
+ ::rtl::Reference< ::jvmaccess::UnoVirtualMachine > vm_access(
+ ::javaunohelper::create_vm_access( pJEnv, loader ) );
+ // wrap vm singleton entry
+ xContext = ::javaunohelper::install_vm_singleton( xContext, vm_access );
+ rMSFac.set( xContext->getServiceManager(), UNO_QUERY_THROW );
+
+ // get uno envs
+ OUString aCurrentEnv(RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME));
+ OUString java_env_name = OUSTR(UNO_LB_JAVA);
+ Environment java_env, curr_env;
+ uno_getEnvironment((uno_Environment **)&curr_env, aCurrentEnv.pData, NULL);
+ uno_getEnvironment( (uno_Environment **)&java_env, java_env_name.pData, vm_access.get() );
+
+ Mapping curr_java(curr_env.get(), java_env.get());
+ if (! curr_java.is())
+ {
+ throw RuntimeException(
+ OUSTR("no C++ <-> Java mapping available!"), Reference< XInterface >() );
+ }
+
+ jobject joGlobalRegServiceFac =
+ (jobject)curr_java.mapInterface(
+ rMSFac.get(),
+ getCppuType((Reference< lang::XMultiServiceFactory > *)0) );
+ joRegServiceFac = pJEnv->NewLocalRef( joGlobalRegServiceFac );
+ pJEnv->DeleteGlobalRef(joGlobalRegServiceFac);
+ }
+ catch (Exception & exc)
+ {
+ jclass c = pJEnv->FindClass( "com/sun/star/uno/RuntimeException" );
+ if (0 != c)
+ {
+ OString cstr( ::rtl::OUStringToOString(
+ exc.Message, RTL_TEXTENCODING_JAVA_UTF8 ) );
+ OSL_TRACE( __FILE__": forwarding Exception: %s", cstr.getStr() );
+ pJEnv->ThrowNew( c, cstr.getStr() );
+ }
+ return 0;
+ }
+
+ OSL_TRACE("javaunohelper.cxx: object %i", joRegServiceFac);
+
+ return joRegServiceFac;
+}
diff --git a/javaunohelper/source/javaunohelper.map b/javaunohelper/source/javaunohelper.map
new file mode 100644
index 000000000000..a7bf6b0721af
--- /dev/null
+++ b/javaunohelper/source/javaunohelper.map
@@ -0,0 +1,9 @@
+UDK_3.1 {
+ global:
+ Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1writeInfo;
+ Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1getFactory;
+ Java_com_sun_star_comp_helper_RegistryServiceFactory_createRegistryServiceFactory;
+ Java_com_sun_star_comp_helper_Bootstrap_cppuhelper_1bootstrap;
+ local:
+ *;
+};
diff --git a/javaunohelper/source/makefile.mk b/javaunohelper/source/makefile.mk
new file mode 100644
index 000000000000..4898c6a1179b
--- /dev/null
+++ b/javaunohelper/source/makefile.mk
@@ -0,0 +1,138 @@
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2008 by Sun Microsystems, Inc.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# $RCSfile: makefile.mk,v $
+#
+# $Revision: 1.18 $
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+PRJ=..
+
+PRJNAME=javaunohelper
+TARGET=juh
+USE_DEFFILE=TRUE
+ENABLE_EXCEPTIONS=TRUE
+LIBTARGET=NO
+
+# --- Settings -----------------------------------------------------
+
+.INCLUDE : settings.mk
+
+.IF "$(SOLAR_JAVA)"==""
+nojava:
+ @echo "Not building javaunohelper because Java is disabled"
+.ENDIF
+
+# ------------------------------------------------------------------
+
+UNOUCRDEP=$(SOLARBINDIR)$/udkapi.rdb
+UNOUCRRDB=$(SOLARBINDIR)$/udkapi.rdb
+
+UNOUCROUT=$(OUT)$/inc$/comprehensive
+INCPRE+=$(OUT)$/inc$/comprehensive
+NO_OFFUH=TRUE
+CPPUMAKERFLAGS+=-C
+
+UNOTYPES= \
+ com.sun.star.beans.NamedValue \
+ com.sun.star.container.XHierarchicalNameAccess \
+ com.sun.star.loader.XImplementationLoader \
+ com.sun.star.registry.XRegistryKey \
+ com.sun.star.registry.XSimpleRegistry \
+ com.sun.star.beans.XPropertySet \
+ com.sun.star.lang.DisposedException \
+ com.sun.star.lang.IllegalArgumentException \
+ com.sun.star.lang.XTypeProvider \
+ com.sun.star.lang.XServiceInfo \
+ com.sun.star.lang.XMultiServiceFactory \
+ com.sun.star.lang.XMultiComponentFactory \
+ com.sun.star.lang.XSingleServiceFactory \
+ com.sun.star.lang.XSingleComponentFactory \
+ com.sun.star.uno.TypeClass \
+ com.sun.star.uno.XWeak \
+ com.sun.star.uno.XAggregation \
+ com.sun.star.uno.XComponentContext \
+ com.sun.star.lang.XInitialization \
+ com.sun.star.lang.XComponent
+
+SLOFILES= \
+ $(SLO)$/javaunohelper.obj \
+ $(SLO)$/bootstrap.obj \
+ $(SLO)$/preload.obj \
+ $(SLO)$/vm.obj
+
+# ------------------------------------------------------------------
+
+LIB1TARGET=$(SLB)$/$(SHL1TARGET).lib
+LIB1OBJFILES=\
+ $(SLO)$/javaunohelper.obj \
+ $(SLO)$/bootstrap.obj \
+ $(SLO)$/vm.obj
+
+SHL1TARGET=juhx
+
+SHL1STDLIBS= \
+ $(JVMACCESSLIB) \
+ $(SALHELPERLIB) \
+ $(SALLIB) \
+ $(CPPULIB) \
+ $(CPPUHELPERLIB)
+
+SHL1VERSIONMAP = javaunohelper.map
+
+SHL1DEPN=
+SHL1IMPLIB=i$(SHL1TARGET)
+SHL1LIBS=$(LIB1TARGET)
+SHL1DEF=$(MISC)$/$(SHL1TARGET).def
+SHL1RPATH=URELIB
+
+DEF1NAME=$(SHL1TARGET)
+
+# ------------------------------------------------------------------
+
+LIB2TARGET=$(SLB)$/$(SHL2TARGET).lib
+LIB2OBJFILES=\
+ $(SLO)$/preload.obj
+
+SHL2TARGET=juh
+
+SHL2STDLIBS= \
+ $(SALLIB)
+
+SHL2VERSIONMAP = javaunohelper.map
+
+SHL2DEPN=
+SHL2IMPLIB=i$(SHL2TARGET)
+SHL2LIBS=$(LIB2TARGET)
+SHL2DEF=$(MISC)$/$(SHL2TARGET).def
+SHL2RPATH=URELIB
+
+DEF2NAME=$(SHL2TARGET)
+
+# --- Targets ------------------------------------------------------
+
+.INCLUDE : target.mk
+
diff --git a/javaunohelper/source/preload.cxx b/javaunohelper/source/preload.cxx
new file mode 100644
index 000000000000..9d2d8a5eeeaf
--- /dev/null
+++ b/javaunohelper/source/preload.cxx
@@ -0,0 +1,161 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: preload.cxx,v $
+ * $Revision: 1.8 $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_javaunohelper.hxx"
+
+#include "jni.h"
+
+#include "rtl/ustring.hxx"
+#include "osl/module.h"
+
+#define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
+
+#if ! defined SAL_DLLPREFIX
+#define SAL_DLLPREFIX ""
+#endif
+
+using ::rtl::OUString;
+
+extern "C"
+{
+typedef jboolean (JNICALL * fptr_writeInfo)(
+ JNIEnv *, jclass, jstring, jobject, jobject, jobject );
+typedef jobject (JNICALL * fptr_getFactory)(
+ JNIEnv *, jclass, jstring, jstring, jobject, jobject, jobject );
+typedef jobject (JNICALL * fptr_createRegistryServiceFactory)(
+ JNIEnv *, jclass, jstring, jstring, jboolean, jobject );
+typedef jobject (JNICALL * fptr_bootstrap)(
+ JNIEnv *_env, jclass, jstring, jobjectArray, jobject );
+
+static fptr_writeInfo s_writeInfo;
+static fptr_getFactory s_getFactory;
+static fptr_createRegistryServiceFactory s_createRegistryServiceFactory;
+static fptr_bootstrap s_bootstrap;
+static bool s_inited = false;
+
+extern "C" { static void SAL_CALL thisModule() {} }
+
+//--------------------------------------------------------------------------------------------------
+static bool inited_juhx( JNIEnv * jni_env )
+{
+ if (s_inited)
+ return true;
+ OUString lib_name = OUSTR(SAL_DLLPREFIX "juhx" SAL_DLLEXTENSION);
+ oslModule hModule =
+ osl_loadModuleRelative( &thisModule, lib_name.pData, SAL_LOADMODULE_LAZY | SAL_LOADMODULE_GLOBAL );
+ if (0 == hModule)
+ {
+ jclass c = jni_env->FindClass( "java/lang/RuntimeException" );
+ jni_env->ThrowNew(
+ c, "error loading " SAL_DLLPREFIX "juhx" SAL_DLLEXTENSION "!" );
+ return false;
+ }
+ else
+ {
+ OUString symbol =
+ OUSTR("Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1writeInfo");
+ s_writeInfo = (fptr_writeInfo)osl_getFunctionSymbol(
+ hModule, symbol.pData );
+ symbol =
+ OUSTR("Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1getFactory");
+ s_getFactory = (fptr_getFactory)osl_getFunctionSymbol(
+ hModule, symbol.pData );
+ symbol =
+ OUSTR("Java_com_sun_star_comp_helper_RegistryServiceFactory_createRegistryServiceFactory");
+ s_createRegistryServiceFactory =
+ (fptr_createRegistryServiceFactory)osl_getFunctionSymbol(
+ hModule, symbol.pData );
+ symbol =
+ OUSTR("Java_com_sun_star_comp_helper_Bootstrap_cppuhelper_1bootstrap");
+ s_bootstrap =
+ (fptr_bootstrap)osl_getFunctionSymbol( hModule, symbol.pData );
+
+ if (0 == s_writeInfo ||
+ 0 == s_getFactory ||
+ 0 == s_createRegistryServiceFactory ||
+ 0 == s_bootstrap)
+ {
+ jclass c = jni_env->FindClass( "java/lang/RuntimeException" );
+ jni_env->ThrowNew(
+ c, "error resolving symbols of " SAL_DLLPREFIX "juhx" SAL_DLLEXTENSION "!" );
+ return false;
+ }
+ }
+ s_inited = true;
+ return true;
+}
+
+//==================================================================================================
+JNIEXPORT jboolean JNICALL
+Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1writeInfo(
+ JNIEnv * pJEnv, jclass jClass, jstring jLibName, jobject jSMgr,
+ jobject jRegKey, jobject loader )
+{
+ if (inited_juhx( pJEnv ))
+ return (*s_writeInfo)(
+ pJEnv, jClass, jLibName, jSMgr, jRegKey, loader );
+ return JNI_FALSE;
+}
+//==================================================================================================
+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 loader )
+{
+ if (inited_juhx( pJEnv ))
+ return (*s_getFactory)(
+ pJEnv, jClass, jLibName, jImplName, jSMgr, jRegKey, loader );
+ return 0;
+}
+//==================================================================================================
+JNIEXPORT jobject JNICALL
+Java_com_sun_star_comp_helper_RegistryServiceFactory_createRegistryServiceFactory(
+ JNIEnv * pJEnv, jclass jClass, jstring jWriteRegFile,
+ jstring jReadRegFile, jboolean jbReadOnly, jobject loader )
+{
+ if (inited_juhx( pJEnv ))
+ {
+ return (*s_createRegistryServiceFactory)(
+ pJEnv, jClass, jWriteRegFile, jReadRegFile, jbReadOnly, loader );
+ }
+ return 0;
+}
+//==================================================================================================
+JNIEXPORT jobject JNICALL
+Java_com_sun_star_comp_helper_Bootstrap_cppuhelper_1bootstrap(
+ JNIEnv * jni_env, jclass jClass, jstring juno_rc, jobjectArray jpairs,
+ jobject loader )
+{
+ if (inited_juhx( jni_env ))
+ return (*s_bootstrap)( jni_env, jClass, juno_rc, jpairs, loader );
+ return 0;
+}
+}
diff --git a/javaunohelper/source/vm.cxx b/javaunohelper/source/vm.cxx
new file mode 100644
index 000000000000..778e105f4961
--- /dev/null
+++ b/javaunohelper/source/vm.cxx
@@ -0,0 +1,150 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: vm.cxx,v $
+ * $Revision: 1.6 $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_javaunohelper.hxx"
+
+#include "sal/config.h"
+
+#include "vm.hxx"
+
+#include "com/sun/star/beans/NamedValue.hpp"
+#include "com/sun/star/lang/XSingleComponentFactory.hpp"
+#include "cppuhelper/compbase1.hxx"
+#include "cppuhelper/component_context.hxx"
+#include "jvmaccess/virtualmachine.hxx"
+#include "jvmaccess/unovirtualmachine.hxx"
+#include "osl/mutex.hxx"
+
+namespace {
+
+namespace css = ::com::sun::star;
+
+struct MutexHolder
+{
+ ::osl::Mutex m_mutex;
+};
+typedef ::cppu::WeakComponentImplHelper1<
+ css::lang::XSingleComponentFactory > t_impl;
+
+class SingletonFactory : public MutexHolder, public t_impl
+{
+ ::rtl::Reference< ::jvmaccess::UnoVirtualMachine > m_vm_access;
+
+protected:
+ virtual void SAL_CALL disposing();
+
+public:
+ inline SingletonFactory( ::rtl::Reference< ::jvmaccess::UnoVirtualMachine > const & vm_access )
+ : t_impl( m_mutex ),
+ m_vm_access( vm_access )
+ {}
+
+ // XSingleComponentFactory impl
+ virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithContext(
+ css::uno::Reference< css::uno::XComponentContext > const & xContext )
+ throw (css::uno::Exception);
+ virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithArgumentsAndContext(
+ css::uno::Sequence< css::uno::Any > const & args, css::uno::Reference< css::uno::XComponentContext > const & xContext )
+ throw (css::uno::Exception);
+};
+
+void SingletonFactory::disposing()
+{
+ m_vm_access.clear();
+}
+
+css::uno::Reference< css::uno::XInterface > SingletonFactory::createInstanceWithContext(
+ css::uno::Reference< css::uno::XComponentContext > const & xContext )
+ throw (css::uno::Exception)
+{
+ sal_Int64 handle = reinterpret_cast< sal_Int64 >( m_vm_access.get() );
+ css::uno::Any arg(
+ css::uno::makeAny(
+ css::beans::NamedValue(
+ rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM( "UnoVirtualMachine" ) ),
+ css::uno::makeAny( handle ) ) ) );
+ return xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
+ ::rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "com.sun.star.java.JavaVirtualMachine")),
+ css::uno::Sequence< css::uno::Any >( &arg, 1 ), xContext );
+}
+
+css::uno::Reference< css::uno::XInterface > SingletonFactory::createInstanceWithArgumentsAndContext(
+ css::uno::Sequence< css::uno::Any > const & args, css::uno::Reference< css::uno::XComponentContext > const & xContext )
+ throw (css::uno::Exception)
+{
+ return xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
+ ::rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "com.sun.star.java.JavaVirtualMachine")),
+ args, xContext );
+}
+
+}
+
+namespace javaunohelper {
+
+::rtl::Reference< ::jvmaccess::UnoVirtualMachine > create_vm_access(
+ JNIEnv * jni_env, jobject loader )
+{
+ JavaVM * vm;
+ jni_env->GetJavaVM( &vm );
+ try {
+ return new ::jvmaccess::UnoVirtualMachine(
+ new ::jvmaccess::VirtualMachine(
+ vm, JNI_VERSION_1_2, false, jni_env ),
+ loader );
+ } catch ( ::jvmaccess::UnoVirtualMachine::CreationException & ) {
+ throw css::uno::RuntimeException(
+ ::rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "jmvaccess::UnoVirtualMachine::CreationException"
+ " occurred" ) ),
+ css::uno::Reference< css::uno::XInterface >() );
+ }
+}
+
+css::uno::Reference< css::uno::XComponentContext > install_vm_singleton(
+ css::uno::Reference< ::css::uno::XComponentContext > const & xContext,
+ ::rtl::Reference< ::jvmaccess::UnoVirtualMachine > const & vm_access )
+{
+ css::uno::Reference< css::lang::XSingleComponentFactory > xFac( new SingletonFactory( vm_access ) );
+ ::cppu::ContextEntry_Init entry(
+ ::rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "/singletons/com.sun.star.java.theJavaVirtualMachine")),
+ css::uno::makeAny( xFac ), true );
+ return ::cppu::createComponentContext( &entry, 1, xContext );
+}
+
+}
diff --git a/javaunohelper/source/vm.hxx b/javaunohelper/source/vm.hxx
new file mode 100644
index 000000000000..f68bdd9f6ec0
--- /dev/null
+++ b/javaunohelper/source/vm.hxx
@@ -0,0 +1,58 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: vm.hxx,v $
+ * $Revision: 1.5 $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef INCLUDED_JAVAUNOHELPER_SOURCE_VM_HXX
+#define INCLUDED_JAVAUNOHELPER_SOURCE_VM_HXX
+
+#include "sal/config.h"
+
+#include "jni.h"
+#include "com/sun/star/uno/Reference.hxx"
+#include "rtl/ref.hxx"
+
+namespace com { namespace sun { namespace star { namespace uno {
+ class XComponentContext;
+} } } }
+namespace jvmaccess { class UnoVirtualMachine; }
+
+namespace javaunohelper {
+
+::rtl::Reference< ::jvmaccess::UnoVirtualMachine > create_vm_access(
+ JNIEnv * jni_env, jobject loader );
+
+::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >
+install_vm_singleton(
+ ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >
+ const & xContext,
+ ::rtl::Reference< ::jvmaccess::UnoVirtualMachine > const & vm_access );
+
+}
+
+#endif