2000-09-18 14:29:57 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
|
|
|
* $RCSfile: javavm.cxx,v $
|
|
|
|
*
|
2000-09-28 16:34:41 +00:00
|
|
|
* $Revision: 1.2 $
|
2000-09-18 14:29:57 +00:00
|
|
|
*
|
2000-09-28 16:34:41 +00:00
|
|
|
* last change: $Author: kr $ $Date: 2000-09-28 17:34:41 $
|
2000-09-18 14:29:57 +00:00
|
|
|
*
|
|
|
|
* The Contents of this file are made available subject to the terms of
|
|
|
|
* either of the following licenses
|
|
|
|
*
|
|
|
|
* - GNU Lesser General Public License Version 2.1
|
|
|
|
* - Sun Industry Standards Source License Version 1.1
|
|
|
|
*
|
|
|
|
* Sun Microsystems Inc., October, 2000
|
|
|
|
*
|
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2000 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library 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 for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Sun Industry Standards Source License Version 1.1
|
|
|
|
* =================================================
|
|
|
|
* The contents of this file are subject to the Sun Industry Standards
|
|
|
|
* Source License Version 1.1 (the "License"); You may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of the
|
|
|
|
* License at http://www.openoffice.org/license.html.
|
|
|
|
*
|
|
|
|
* Software provided under this License is provided on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
|
|
|
|
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
|
|
|
|
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
|
|
|
|
* See the License for the specific provisions governing your rights and
|
|
|
|
* obligations concerning the Software.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
|
|
|
|
*
|
|
|
|
* Copyright: 2000 by Sun Microsystems, Inc.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s): _______________________________________
|
|
|
|
*
|
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
#include <osl/diagnose.h>
|
|
|
|
#include <osl/file.hxx>
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
#include <rtl/process.h>
|
2000-09-18 14:29:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include <vos/module.hxx>
|
|
|
|
#include <vos/thread.hxx>
|
|
|
|
#include <vos/conditn.hxx>
|
|
|
|
#include <vos/profile.hxx>
|
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
#include <uno/environment.h>
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
#include <cppuhelper/factory.hxx>
|
|
|
|
#include <cppuhelper/implbase3.hxx>
|
|
|
|
#include <com/sun/star/uno/Sequence.hxx>
|
2000-09-18 14:29:57 +00:00
|
|
|
|
|
|
|
#include <com/sun/star/lang/XServiceInfo.hpp>
|
|
|
|
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
|
|
|
|
|
|
|
|
#include <com/sun/star/java/XJavaVM.hpp>
|
|
|
|
#include <com/sun/star/java/XJavaThreadRegister_11.hpp>
|
|
|
|
|
|
|
|
#include <com/sun/star/registry/XRegistryKey.hpp>
|
|
|
|
#include <com/sun/star/registry/XSimpleRegistry.hpp>
|
|
|
|
#include <com/sun/star/registry/InvalidRegistryException.hpp>
|
|
|
|
#include <com/sun/star/frame/XConfigManager.hpp>
|
|
|
|
|
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
#include <bridges/java/jvmcontext.hxx>
|
2000-09-18 14:29:57 +00:00
|
|
|
|
|
|
|
#include "jvmargs.hxx"
|
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// Properties of the javavm can be put
|
|
|
|
// as a komma separated list in this
|
|
|
|
// environment variable
|
|
|
|
#define PROPERTIES_ENV "OO_JAVA_PROPERTIES"
|
|
|
|
|
2000-09-18 14:29:57 +00:00
|
|
|
|
|
|
|
#ifdef UNIX
|
|
|
|
#define INI_FILE "javarc"
|
2000-09-28 16:34:41 +00:00
|
|
|
#define DEF_JAVALIB "libjvm.so"
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
#define TIMEZONE "MEZ"
|
2000-09-18 14:29:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
#else
|
2000-09-28 16:34:41 +00:00
|
|
|
#define INI_FILE "java.ini"
|
|
|
|
#define DEF_JAVALIB "javai.dll"
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
#define TIMEZONE "MET"
|
2000-09-18 14:29:57 +00:00
|
|
|
|
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
#endif
|
2000-09-18 14:29:57 +00:00
|
|
|
|
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
using namespace com::sun::star::uno;
|
|
|
|
using namespace com::sun::star::lang;
|
|
|
|
using namespace com::sun::star::java;
|
|
|
|
using namespace com::sun::star::registry;
|
|
|
|
using namespace com::sun::star::frame;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
using namespace vos;
|
|
|
|
using namespace rtl;
|
|
|
|
using namespace cppu;
|
|
|
|
using namespace osl;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
namespace stoc_javavm {
|
|
|
|
static jint JNICALL vm_vfprintf( FILE *fp, const char *format, va_list args ) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
char buff[1024];
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
vsprintf( buff, format, args );
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
OSL_TRACE("%s", buff);
|
|
|
|
return strlen(buff);
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
static void JNICALL vm_exit(jint code) {
|
|
|
|
OSL_TRACE("vm_exit: %d\n", code);
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
static void JNICALL vm_abort() {
|
|
|
|
OSL_TRACE("vm_abort\n");
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
typedef ::std::hash_map<sal_uInt32, sal_uInt32/*, ::std::hash<sal_uInt32>, ::std::equal_to<sal_uInt32*/> UINT32_UINT32_HashMap;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
class JavaVirtualMachine_Impl;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
class OCreatorThread : public OThread {
|
|
|
|
JavaVirtualMachine_Impl * _pJavaVirtualMachine_Impl;
|
|
|
|
JavaVM * _pJVM;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
OCondition _start_Condition;
|
|
|
|
OCondition _wait_Condition;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
JVM _jvm;
|
|
|
|
RuntimeException _runtimeException;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
protected:
|
|
|
|
virtual void SAL_CALL run() throw();
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
public:
|
|
|
|
OCreatorThread(JavaVirtualMachine_Impl * pJavaVirtualMachine_Impl) throw();
|
|
|
|
JavaVM * createJavaVM(const JVM & jvm) throw (RuntimeException);
|
|
|
|
void disposeJavaVM() throw();
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
};
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
class JavaVirtualMachine_Impl : public WeakImplHelper3<XJavaVM, XJavaThreadRegister_11, XServiceInfo> {
|
|
|
|
Mutex _Mutex;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
OCreatorThread _creatorThread;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
uno_Environment * _pJava_environment;
|
|
|
|
JavaVMContext * _pVMContext;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
Reference<XMultiServiceFactory> _xSMgr;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// void setLanguageAndCountrySection( XSimpleRegistry* pOfficeReg, JVM* pjvm );
|
2000-09-18 14:29:57 +00:00
|
|
|
|
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
OModule _javaLib;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
public:
|
|
|
|
int _error;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
JavaVirtualMachine_Impl(const Reference<XMultiServiceFactory> & rSMgr) throw();
|
|
|
|
~JavaVirtualMachine_Impl() throw();
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// XJavaVM
|
|
|
|
virtual Any SAL_CALL getJavaVM(const Sequence<sal_Int8> & processID) throw(RuntimeException);
|
|
|
|
virtual sal_Bool SAL_CALL isVMStarted(void) throw( RuntimeException);
|
|
|
|
virtual sal_Bool SAL_CALL isVMEnabled(void) throw( RuntimeException);
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// XJavaThreadRegister_11
|
|
|
|
virtual sal_Bool SAL_CALL isThreadAttached(void) throw(RuntimeException);
|
|
|
|
virtual void SAL_CALL registerThread(void) throw(RuntimeException);
|
|
|
|
virtual void SAL_CALL revokeThread(void) throw(RuntimeException);
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// XServiceInfo
|
|
|
|
virtual OUString SAL_CALL getImplementationName() throw(RuntimeException);
|
|
|
|
virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw(RuntimeException);
|
|
|
|
virtual Sequence<OUString> SAL_CALL getSupportedServiceNames(void) throw(RuntimeException);
|
2000-09-18 14:29:57 +00:00
|
|
|
|
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
static OUString SAL_CALL getImplementationName_Static() throw() {
|
|
|
|
return OUString::createFromAscii("com.sun.star.comp.stoc.JavaVirtualMachine");
|
|
|
|
}
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
static Sequence<OUString> SAL_CALL getSupportedServiceNames_Static() throw() {
|
|
|
|
Sequence<OUString> aSNS(1);
|
|
|
|
aSNS.getArray()[0] = OUString::createFromAscii("com.sun.star.java.JavaVirtualMachine");
|
|
|
|
return aSNS;
|
|
|
|
}
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
JavaVM * createJavaVM(const JVM & jvm) throw(RuntimeException);
|
|
|
|
void disposeJavaVM() throw();
|
|
|
|
};
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
OCreatorThread::OCreatorThread(JavaVirtualMachine_Impl * pJavaVirtualMachine_Impl) throw()
|
|
|
|
: _pJVM(NULL)
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2000-09-28 16:34:41 +00:00
|
|
|
_pJavaVirtualMachine_Impl = pJavaVirtualMachine_Impl;
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
void OCreatorThread::run() throw() {
|
|
|
|
_start_Condition.wait();
|
|
|
|
_start_Condition.reset();
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
try {
|
|
|
|
_pJVM = _pJavaVirtualMachine_Impl->createJavaVM(_jvm);
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
2000-09-28 16:34:41 +00:00
|
|
|
catch(RuntimeException & runtimeException) {
|
|
|
|
_runtimeException = runtimeException;
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
_wait_Condition.set();
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
#if defined(WNT) || defined(OS2)
|
|
|
|
suspend();
|
2000-09-18 14:29:57 +00:00
|
|
|
|
|
|
|
#else
|
2000-09-28 16:34:41 +00:00
|
|
|
if (_pJVM) {
|
|
|
|
_start_Condition.wait();
|
|
|
|
_start_Condition.reset();
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
_pJavaVirtualMachine_Impl->disposeJavaVM();
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
_wait_Condition.set();
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
2000-09-28 16:34:41 +00:00
|
|
|
#endif
|
|
|
|
}
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
JavaVM * OCreatorThread::createJavaVM(const JVM & jvm ) throw(RuntimeException) {
|
|
|
|
_jvm = jvm;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
create();
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
if (!_pJVM) {
|
|
|
|
_start_Condition.set();
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
_wait_Condition.wait();
|
|
|
|
_wait_Condition.reset();
|
|
|
|
}
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
if(!_pJVM)
|
|
|
|
throw _runtimeException;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
return _pJVM;
|
|
|
|
}
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
void OCreatorThread::disposeJavaVM() throw() {
|
|
|
|
_start_Condition.set(); // start disposing vm
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
#ifdef UNX
|
|
|
|
_wait_Condition.wait(); // wait until disposed
|
|
|
|
_wait_Condition.reset();
|
2000-09-18 14:29:57 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// XServiceInfo
|
|
|
|
OUString SAL_CALL JavaVirtualMachine_Impl::getImplementationName() throw(RuntimeException) {
|
|
|
|
return JavaVirtualMachine_Impl::getImplementationName_Static();
|
|
|
|
}
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// XServiceInfo
|
|
|
|
sal_Bool SAL_CALL JavaVirtualMachine_Impl::supportsService(const OUString& ServiceName) throw(RuntimeException) {
|
|
|
|
Sequence<OUString> aSNL = getSupportedServiceNames();
|
|
|
|
const OUString * pArray = aSNL.getConstArray();
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
for (sal_Int32 i = 0; i < aSNL.getLength(); ++ i)
|
|
|
|
if (pArray[i] == ServiceName)
|
|
|
|
return sal_True;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
return sal_False;
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// XServiceInfo
|
|
|
|
Sequence<OUString> SAL_CALL JavaVirtualMachine_Impl::getSupportedServiceNames() throw(RuntimeException) {
|
|
|
|
return getSupportedServiceNames_Static();
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// TEMPORARY DISABLED
|
|
|
|
// void JavaVirtualMachine_Impl::setLanguageAndCountrySection( XSimpleRegistry* pOfficeReg, JVM* pjvm) {
|
|
|
|
// OUString aValue;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// Reference<XRegistryKey> xRegistryRootKey = pOfficeReg->getRootKey();
|
|
|
|
// aValue = getValue( xRegistryRootKey, OUString::createFromAscii("User/Language") );
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// if ( aValue.len() )
|
|
|
|
// {
|
|
|
|
// OUString aLanguage;
|
|
|
|
// OUString aCountry;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// // LanguageType aLangNum = (LanguageType) String( OUStringToOString( aValue, RTL_TEXTENCODING_ASCII_US) );
|
|
|
|
// LanguageType aLangNum = (LanguageType) aValue.toInt32();
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// {
|
|
|
|
// String langStr;
|
|
|
|
// String countryStr;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// ConvertLanguageToIsoNames( aLangNum, langStr, countryStr );
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// aLanguage = OUString( langStr );
|
|
|
|
// aCountry = OUString( countryStr );
|
|
|
|
// }
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// if ( aLanguage.getLength() ) pjvm->pushProp( OUString::createFromAscii("user.language=") + aLanguage );
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// if ( aCountry.getLength() ) pjvm->pushProp( OUString::createFromAscii("user.region=") + aCountry );
|
|
|
|
// }
|
|
|
|
// }
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
static void setTimeZone(JVM * pjvm) throw() {
|
|
|
|
/* A Bug in the Java function
|
|
|
|
** struct Hjava_util_Properties * java_lang_System_initProperties(
|
|
|
|
** struct Hjava_lang_System *this,
|
|
|
|
** struct Hjava_util_Properties *props);
|
|
|
|
** This function doesn't detect MEZ, MET or "W. Europe Standard Time"
|
|
|
|
*/
|
|
|
|
struct tm *tmData;
|
|
|
|
time_t clock = time(NULL);
|
|
|
|
tzset();
|
|
|
|
tmData = localtime(&clock);
|
|
|
|
char * p = tzname[0];
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
if (!strcmp(TIMEZONE, p))
|
|
|
|
pjvm->pushProp(OUString::createFromAscii("user.timezone=ECT"));
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
static OUString getValue(const Reference<XRegistryKey> & xRegistryRootKey, const OUString& rKey) throw() {
|
|
|
|
OUString aEntryValue;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
try {
|
|
|
|
Reference<XRegistryKey> aEntry = xRegistryRootKey->openKey(rKey);
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
if (aEntry.is() && aEntry->isValid())
|
|
|
|
aEntryValue = aEntry->getStringValue();
|
|
|
|
}
|
|
|
|
catch (InvalidRegistryException e) {
|
|
|
|
}
|
|
|
|
catch (InvalidValueException e) {
|
|
|
|
}
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
return aEntryValue;
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
static void readINetSection(const Reference<XSimpleRegistry> & xOfficeReg, JVM * pjvm) throw (RuntimeException) {
|
|
|
|
Reference<XRegistryKey> xRegistryRootKey = xOfficeReg->getRootKey();
|
|
|
|
if(!xRegistryRootKey.is())
|
|
|
|
throw RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM("javavm.cxx: readINetSection")), Reference<XInterface>());
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// HTTPProxyHost, HTTPProxyPort, FTPProxyHost, FTPProxyPort
|
|
|
|
// Reading proxy and port values in the INet section
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
OUString prop;
|
|
|
|
OUString right;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// HTTPProxy
|
|
|
|
right = getValue(xRegistryRootKey, OUString(RTL_CONSTASCII_USTRINGPARAM("INet/HTTPProxyName")));
|
|
|
|
if (right.getLength()) {
|
|
|
|
prop = OUString(RTL_CONSTASCII_USTRINGPARAM("http.proxyHost="));
|
|
|
|
prop += right;
|
|
|
|
pjvm->pushProp(prop);
|
|
|
|
}
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// HTTPProxyPort
|
|
|
|
right = getValue(xRegistryRootKey, OUString(RTL_CONSTASCII_USTRINGPARAM("INet/HTTPProxyPort")));
|
|
|
|
if (right.getLength()) {
|
|
|
|
prop = OUString(RTL_CONSTASCII_USTRINGPARAM("http.proxyPort="));
|
|
|
|
prop += right;
|
|
|
|
pjvm->pushProp(prop);
|
|
|
|
}
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// FTPPProxy
|
|
|
|
right = getValue(xRegistryRootKey, OUString(RTL_CONSTASCII_USTRINGPARAM("INet/FTPProxyName")));
|
|
|
|
if (right.getLength()) {
|
|
|
|
prop = OUString(RTL_CONSTASCII_USTRINGPARAM("ftpProxyHost="));
|
|
|
|
prop += right;
|
|
|
|
pjvm->pushProp(prop);
|
|
|
|
}
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// FTPProxyPort
|
|
|
|
right = getValue(xRegistryRootKey, OUString(RTL_CONSTASCII_USTRINGPARAM("INet/FTPProxyPort")));
|
|
|
|
if (right.getLength()) {
|
|
|
|
prop = OUString(RTL_CONSTASCII_USTRINGPARAM("FTPProxyPort="));
|
|
|
|
prop += right;
|
|
|
|
pjvm->pushProp(prop);
|
|
|
|
}
|
|
|
|
}
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
static void getXfromConfiguration(JVM * pjvm, const Reference<XMultiServiceFactory> & xSMgr) throw(Exception) {
|
|
|
|
OSL_TRACE("trying configuration...");
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
Reference<XInterface> xInterfaceRef_1(xSMgr->createInstance(OUString::createFromAscii("com.sun.star.config.SpecialConfigManager")));
|
|
|
|
Reference<XSimpleRegistry> xSofficeReg(xInterfaceRef_1, UNO_QUERY);
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
if (!xSofficeReg.is() || !xSofficeReg->isValid())
|
|
|
|
throw RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM("javavm.cxx: 1")), Reference<XInterface>());
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// read proxy data
|
|
|
|
readINetSection(xSofficeReg, pjvm);
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
Reference<XConfigManager> xConfigManager(xInterfaceRef_1, UNO_QUERY);
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
OUString iniFileName;
|
|
|
|
sal_Bool bIniFound = sal_False;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
Reference<XRegistryKey> xRegistryRootKey = xSofficeReg->getRootKey();
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
if (!xRegistryRootKey.is() || !xRegistryRootKey->isValid())
|
|
|
|
throw RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM("javavm.cxx: 2")), Reference<XInterface>());
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
::osl::DirectoryItem aJavaIni;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
try {
|
|
|
|
OUString tmpFileName;
|
|
|
|
OUString fileName;
|
|
|
|
tmpFileName = getValue( xRegistryRootKey, OUString::createFromAscii("Directories/UserConfig-Path") );
|
|
|
|
tmpFileName = xConfigManager->substituteVariables( tmpFileName );
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
File::normalizePath( tmpFileName, fileName );
|
|
|
|
fileName += OUString::createFromAscii("/" INI_FILE);
|
|
|
|
bIniFound = DirectoryItem::get( fileName, aJavaIni ) == FileBase::E_None;
|
|
|
|
}
|
|
|
|
catch(Exception e) {
|
|
|
|
bIniFound = sal_False;
|
|
|
|
}
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
if(!bIniFound) {
|
|
|
|
OUString tmpFileName;
|
|
|
|
OUString fileName;
|
|
|
|
tmpFileName = getValue( xRegistryRootKey, OUString::createFromAscii("Directories/Config-Dir") );
|
|
|
|
tmpFileName = xConfigManager->substituteVariables( tmpFileName );
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
File::normalizePath( tmpFileName, fileName );
|
|
|
|
fileName += OUString::createFromAscii("/" INI_FILE);
|
|
|
|
bIniFound = DirectoryItem::get( fileName, aJavaIni ) == FileBase::E_None;
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
if (bIniFound) {
|
|
|
|
FileStatus fileStatus(FileStatusMask_FilePath /*FileStatusMask_NativePath*/);
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
if (FileBase::E_None == aJavaIni.getFileStatus(fileStatus ))
|
|
|
|
iniFileName = fileStatus.getFilePath();
|
|
|
|
//iniFileName = fileStatus.getNativePath();
|
|
|
|
else
|
|
|
|
bIniFound = sal_False;
|
|
|
|
}
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
if (!bIniFound) // search the java.ini beneath the executable
|
|
|
|
iniFileName = OUString::createFromAscii(INI_FILE);
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
if(!bIniFound)
|
|
|
|
throw RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM("javavm.cxx: couldn't find " INI_FILE)), Reference<XInterface>());
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
Reference<XInterface> xInterfaceRef_2(xSMgr->createInstance(OUString::createFromAscii("com.sun.star.config.ConfigManager")));
|
|
|
|
Reference<XSimpleRegistry> xJavaReg(xInterfaceRef_2, UNO_QUERY);
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
OUString tmpJavaIni;
|
|
|
|
File::getFileURLFromNormalizedPath(iniFileName, tmpJavaIni);
|
|
|
|
xJavaReg->open(tmpJavaIni, sal_True, sal_False);
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
if (!xJavaReg.is() || !xJavaReg->isValid())
|
|
|
|
throw RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM("javavm.cxx: 4")), Reference<XInterface>());
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
Reference<XRegistryKey> xJavaSection = xJavaReg->getRootKey()->openKey(OUString::createFromAscii("Java"));
|
|
|
|
if(!xJavaSection.is() || !xJavaSection->isValid())
|
|
|
|
throw RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM("javavm.cxx: 5")), Reference<XInterface>());
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
Sequence<OUString> javaProperties = xJavaSection->getKeyNames();
|
|
|
|
OUString * pSectionEntry = javaProperties.getArray();
|
|
|
|
sal_Int32 nCount = javaProperties.getLength();
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
for(sal_Int32 i=0; i < nCount; ++ i) {
|
|
|
|
OUString entryValue = (xJavaSection->openKey(pSectionEntry[i]))->getStringValue();
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
if(entryValue.len()) {
|
|
|
|
pSectionEntry[i] += OUString::createFromAscii("=");
|
|
|
|
pSectionEntry[i] += entryValue;
|
|
|
|
}
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
pjvm->pushProp(pSectionEntry[i]);
|
|
|
|
}
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
xJavaReg->close();
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// don't close soffice
|
|
|
|
// xSofficeReg->close();
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// #include <windows.h>
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// /*
|
|
|
|
// * Returns string data for the specified registry value name, or
|
|
|
|
// * NULL if not found.
|
|
|
|
// */
|
|
|
|
// static OUString getStringValue(HKEY key, const OUString & keyName)
|
|
|
|
// {
|
|
|
|
// DWORD type, size;
|
|
|
|
// OUString value;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// OString osKeyName = OUStringToOString(keyName, RTL_TEXTENCODING_ASCII_US);
|
|
|
|
// if (RegQueryValueEx(key, osKeyName.getStr(), 0, &type, 0, &size) == 0 && type == REG_SZ) {
|
|
|
|
// unsigned char * pValue;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// pValue = (unsigned char *)malloc(size);
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// if (RegQueryValueEx(key, (const char *)osKeyName.getStr(), 0, 0, pValue, &size) == 0)
|
|
|
|
// value = OUString::createFromAscii((char *)pValue);
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// free(pValue);
|
|
|
|
// }
|
|
|
|
// return value;
|
|
|
|
// }
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// #define JRE_KEY "Software\\JavaSoft\\Java Runtime Environment"
|
|
|
|
// #define JDK_KEY "Software\\JavaSoft\\Java Development Kit"
|
|
|
|
// #define MS_VM_KEY "Software\\Mircosoft\\Java VM"
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// static void getXfromRegistry(JVM * jvm) throw(RuntimeException) {
|
|
|
|
// OSL_TRACE("trying registry...");
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// OUString version;
|
|
|
|
// OUString home;
|
|
|
|
// OUString runtimeLib;
|
|
|
|
// OUString systemClasspath;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// HKEY hKey;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// if (!RegOpenKeyEx(HKEY_LOCAL_MACHINE, JRE_KEY, 0, KEY_READ, &hKey)) {
|
|
|
|
// version = getStringValue(hKey, OUString(RTL_CONSTASCII_USTRINGPARAM("CurrentVersion")));
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// OUString keyName(RTL_CONSTASCII_USTRINGPARAM(JRE_KEY));
|
|
|
|
// keyName += OUString(RTL_CONSTASCII_USTRINGPARAM("\\"));
|
|
|
|
// keyName += version;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// OString osKeyName = OUStringToOString(keyName, RTL_TEXTENCODING_ASCII_US);
|
|
|
|
// HKEY curr_key;
|
|
|
|
// if(!RegOpenKeyEx(HKEY_LOCAL_MACHINE, osKeyName.getStr(), 0, KEY_READ, &curr_key)) {
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// home = getStringValue(curr_key, OUString(RTL_CONSTASCII_USTRINGPARAM("JavaHome")));
|
|
|
|
// runtimeLib = getStringValue(curr_key, OUString(RTL_CONSTASCII_USTRINGPARAM("RuntimeLib")));
|
|
|
|
// RegCloseKey(curr_key);
|
|
|
|
// }
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// RegCloseKey(hKey);
|
|
|
|
// }
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// if(version.equals(OUString(RTL_CONSTASCII_USTRINGPARAM("1.2")))
|
|
|
|
// || version.equals(OUString(RTL_CONSTASCII_USTRINGPARAM("1.3"))))
|
2000-09-18 14:29:57 +00:00
|
|
|
// {
|
2000-09-28 16:34:41 +00:00
|
|
|
// systemClasspath += home;
|
|
|
|
// systemClasspath += OUString(RTL_CONSTASCII_USTRINGPARAM("\\rt.jar;"));
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// systemClasspath += home;
|
|
|
|
// systemClasspath += OUString(RTL_CONSTASCII_USTRINGPARAM("\\i18n.jar;"));
|
2000-09-18 14:29:57 +00:00
|
|
|
// }
|
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// jvm->setSystemClasspath(systemClasspath);
|
|
|
|
// jvm->setEnabled(1);
|
|
|
|
// jvm->setRuntimeLib(runtimeLib);
|
2000-09-18 14:29:57 +00:00
|
|
|
// }
|
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
static void getXfromEnvironment(JVM * pjvm) throw() {
|
|
|
|
OSL_TRACE("trying environment...");
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// try some defaults for CLASSPATH and runtime lib
|
|
|
|
const char * pClassPath = getenv("CLASSPATH");
|
|
|
|
pjvm->setSystemClasspath(OUString::createFromAscii(pClassPath));
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
pjvm->setRuntimeLib(OUString::createFromAscii(DEF_JAVALIB));
|
|
|
|
pjvm->setEnabled(1);
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// See if properties have been set and parse them
|
|
|
|
const char * pOOjavaProperties = getenv(PROPERTIES_ENV);
|
|
|
|
if(pOOjavaProperties) {
|
|
|
|
OUString properties(OUString::createFromAscii(pOOjavaProperties));
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
sal_Int32 index;
|
|
|
|
sal_Int32 lastIndex = 0;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
do {
|
|
|
|
index = properties.indexOf((sal_Unicode)',', lastIndex);
|
|
|
|
OUString token = (index == -1) ? properties.copy(lastIndex) : properties.copy(lastIndex, index - lastIndex);
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
lastIndex = index + 1;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
pjvm->pushProp(token);
|
|
|
|
}
|
|
|
|
while(index > -1);
|
|
|
|
}
|
|
|
|
}
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
static void initVMConfiguration(JVM * pjvm, const Reference<XMultiServiceFactory> & xSMgr) throw() {
|
|
|
|
try {
|
|
|
|
JVM jvm;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
getXfromConfiguration(&jvm, xSMgr);
|
|
|
|
*pjvm = jvm;
|
|
|
|
}
|
|
|
|
catch(Exception & exception) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
OString message = OUStringToOString(exception.Message, RTL_TEXTENCODING_ASCII_US);
|
|
|
|
OSL_TRACE("javavm.cxx: couldn't use configuration cause of >%s<", message.getStr());
|
|
|
|
#endif
|
|
|
|
// try {
|
|
|
|
// JVM jvm;
|
|
|
|
// getXfromRegistry(&jvm);
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// *pjvm = jvm;
|
|
|
|
// }
|
|
|
|
// catch(RuntimeException & runtimeException) {
|
|
|
|
JVM jvm;
|
|
|
|
|
|
|
|
getXfromEnvironment(&jvm);
|
|
|
|
*pjvm = jvm;
|
|
|
|
// }
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
2000-09-28 16:34:41 +00:00
|
|
|
setTimeZone(pjvm);
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
pjvm->setPrint(vm_vfprintf);
|
|
|
|
pjvm->setExit(vm_exit);
|
|
|
|
pjvm->setAbort(vm_abort);
|
|
|
|
}
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
JavaVirtualMachine_Impl::JavaVirtualMachine_Impl(const Reference<XMultiServiceFactory> & rSMgr) throw()
|
|
|
|
: _pVMContext(NULL),
|
|
|
|
_xSMgr(rSMgr),
|
|
|
|
_error(0),
|
|
|
|
_creatorThread(this),
|
|
|
|
_pJava_environment(NULL)
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
JavaVirtualMachine_Impl::~JavaVirtualMachine_Impl() throw() {
|
|
|
|
if (_pVMContext)
|
|
|
|
_creatorThread.disposeJavaVM();
|
|
|
|
}
|
2000-09-18 14:29:57 +00:00
|
|
|
|
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
JavaVM * JavaVirtualMachine_Impl::createJavaVM(const JVM & jvm) throw(RuntimeException) {
|
|
|
|
if(!_javaLib.load(jvm.getRuntimeLib()))
|
|
|
|
throw RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM("javavm.cxx: cannot find java runtime")), Reference<XInterface>());
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
JNI_InitArgs_Type * initArgs = (JNI_InitArgs_Type *)_javaLib.getSymbol(OUString::createFromAscii("JNI_GetDefaultJavaVMInitArgs"));
|
|
|
|
if(!initArgs)
|
|
|
|
throw RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM("javavm.cxx: 8")), Reference<XInterface>());
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
JNI_CreateVM_Type * pCreateJavaVM = (JNI_CreateVM_Type *)_javaLib.getSymbol(OUString::createFromAscii("JNI_CreateJavaVM"));
|
|
|
|
if (!pCreateJavaVM)
|
|
|
|
throw RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM("javavm.cxx: 9")), Reference<XInterface>());
|
2000-09-18 14:29:57 +00:00
|
|
|
|
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
JDK1_1InitArgs vm_args;
|
|
|
|
initArgs(&vm_args);
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
jvm.setArgs(&vm_args);
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
JNIEnv * pJNIEnv = NULL;
|
|
|
|
JavaVM * pJavaVM;
|
|
|
|
jint err = pCreateJavaVM(&pJavaVM, &pJNIEnv, &vm_args);
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
OSL_TRACE("javavm.cxx: JavaVirtualMachine_Impl::createJavaVM: %d", err);
|
|
|
|
if(err)
|
|
|
|
throw RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM("javavm.cxx: 10")), Reference<XInterface>());
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
return pJavaVM;
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// XJavaVM
|
|
|
|
Any JavaVirtualMachine_Impl::getJavaVM(const Sequence<sal_Int8> & processId) throw (RuntimeException) {
|
|
|
|
MutexGuard guarg(_Mutex);
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
Sequence<sal_Int8> localProcessID(16);
|
|
|
|
rtl_getGlobalProcessId( (sal_uInt8*) localProcessID.getArray() );
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
if (localProcessID == processId && !_pVMContext && !_error) {
|
|
|
|
uno_Environment ** ppEnviroments = NULL;
|
|
|
|
sal_Int32 size = 0;
|
|
|
|
OUString java(OUString::createFromAscii("java"));
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
uno_getRegisteredEnvironments(&ppEnviroments, &size, (uno_memAlloc)malloc, java.pData);
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
if(size) { // do we found an existing java environment?
|
|
|
|
OSL_TRACE("javavm.cxx: found an existing environment");
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
_pJava_environment = ppEnviroments[0];
|
|
|
|
_pJava_environment->acquire(_pJava_environment);
|
|
|
|
_pVMContext = (JavaVMContext *)_pJava_environment->pContext;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
for(sal_Int32 i = 0; i < size; ++ i)
|
|
|
|
ppEnviroments[i]->release(ppEnviroments[i]);
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
free(ppEnviroments);
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
2000-09-28 16:34:41 +00:00
|
|
|
else {
|
|
|
|
JVM jvm;
|
|
|
|
JavaVM * pJavaVM;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
initVMConfiguration(&jvm, _xSMgr);
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
if (jvm.isEnabled()) {
|
|
|
|
// create the java vm
|
|
|
|
pJavaVM = _creatorThread.createJavaVM(jvm);
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// create a context
|
|
|
|
_pVMContext = new JavaVMContext(pJavaVM);
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// register the java vm at the uno runtime
|
|
|
|
uno_getEnvironment(&_pJava_environment, java.pData, _pVMContext);
|
|
|
|
}
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
2000-09-28 16:34:41 +00:00
|
|
|
}
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
Any any;
|
|
|
|
if(_pVMContext) {
|
|
|
|
if(sizeof(_pVMContext->_pJavaVM) == sizeof(sal_Int32)) { // 32 bit system?
|
|
|
|
sal_Int32 nP = (sal_Int32)_pVMContext->_pJavaVM;
|
|
|
|
any <<= nP;
|
|
|
|
}
|
|
|
|
else if(sizeof(_pVMContext->_pJavaVM) == sizeof(sal_Int64)) { // 64 bit system?
|
|
|
|
sal_Int64 nP = (sal_Int64)_pVMContext->_pJavaVM;
|
|
|
|
any <<= nP;
|
|
|
|
}
|
|
|
|
}
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
OSL_TRACE("javavm.cxx: JavaVirtualMachine_Impl::getJavaVM: %x", any.getValue());
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
return any;
|
|
|
|
}
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// XJavaVM
|
|
|
|
sal_Bool JavaVirtualMachine_Impl::isVMStarted(void) throw(RuntimeException) {
|
|
|
|
return _pVMContext != NULL;
|
|
|
|
}
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// XJavaVM
|
|
|
|
sal_Bool JavaVirtualMachine_Impl::isVMEnabled(void) throw(RuntimeException) {
|
|
|
|
JVM jvm;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
initVMConfiguration(&jvm, _xSMgr);
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
return jvm.isEnabled();
|
|
|
|
}
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// XJavaThreadRegister_11
|
|
|
|
sal_Bool JavaVirtualMachine_Impl::isThreadAttached(void) throw (RuntimeException) {
|
|
|
|
if(!_pVMContext)
|
|
|
|
throw RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM("javavm.cxx: 11")), Reference<XInterface>());
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
return _pVMContext->isThreadAttached();
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// XJavaThreadRegister_11
|
|
|
|
void JavaVirtualMachine_Impl::registerThread(void) throw (RuntimeException) {
|
|
|
|
if(!_pVMContext)
|
|
|
|
throw RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM("javavm.cxx: 12")), Reference<XInterface>());
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
_pVMContext->registerThread();
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// XJavaThreadRegister_11
|
|
|
|
void JavaVirtualMachine_Impl::revokeThread(void) throw (RuntimeException) {
|
|
|
|
if(!_pVMContext)
|
|
|
|
throw RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM("javavm.cxx: 13")), Reference<XInterface>());
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
_pVMContext->revokeThread();
|
|
|
|
}
|
2000-09-18 14:29:57 +00:00
|
|
|
|
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
// JavaVirtualMachine_Impl_CreateInstance()
|
|
|
|
static Reference<XInterface> SAL_CALL JavaVirtualMachine_Impl_createInstance(const Reference<XMultiServiceFactory> & rSMgr)
|
|
|
|
throw (RuntimeException)
|
|
|
|
{
|
|
|
|
XJavaVM *pJVM= static_cast<XJavaVM *>(new JavaVirtualMachine_Impl(rSMgr));
|
|
|
|
return Reference<XInterface>(pJVM);
|
|
|
|
}
|
2000-09-18 14:29:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
void JavaVirtualMachine_Impl::disposeJavaVM() throw() {
|
|
|
|
if (_pVMContext){
|
|
|
|
// pJavaVM->DestroyJavaVM();
|
|
|
|
// _pJavaVM = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
extern "C" {
|
|
|
|
void SAL_CALL component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv){
|
|
|
|
*ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
|
|
|
|
}
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
sal_Bool SAL_CALL component_writeInfo(void * pServiceManager, void * pRegistryKey) throw() {
|
|
|
|
if (pRegistryKey) {
|
|
|
|
try {
|
|
|
|
Reference<XRegistryKey> xNewKey(reinterpret_cast<XRegistryKey *>(pRegistryKey)->createKey(
|
|
|
|
OUString::createFromAscii("/") +
|
|
|
|
stoc_javavm::JavaVirtualMachine_Impl::getImplementationName_Static() +
|
|
|
|
OUString::createFromAscii("/UNO/SERVICES")));
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
const Sequence<OUString> & rSNL = stoc_javavm::JavaVirtualMachine_Impl::getSupportedServiceNames_Static();
|
|
|
|
const OUString * pArray = rSNL.getConstArray();
|
|
|
|
for(sal_Int32 nPos = rSNL.getLength(); nPos--;)
|
|
|
|
xNewKey->createKey(pArray[nPos]);
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
return sal_True;
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
2000-09-28 16:34:41 +00:00
|
|
|
catch (InvalidRegistryException &) {
|
|
|
|
OSL_ENSHURE( sal_False, "### InvalidRegistryException!" );
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
}
|
2000-09-28 16:34:41 +00:00
|
|
|
return sal_False;
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
void * SAL_CALL component_getFactory(const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey) throw() {
|
|
|
|
void * pRet = 0;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
if (stoc_javavm::JavaVirtualMachine_Impl::getImplementationName_Static().equals(OUString::createFromAscii(pImplName))) {
|
|
|
|
Reference<XSingleServiceFactory> xFactory( createOneInstanceFactory(
|
|
|
|
reinterpret_cast<XMultiServiceFactory *>(pServiceManager),
|
|
|
|
stoc_javavm::JavaVirtualMachine_Impl::getImplementationName_Static(),
|
|
|
|
stoc_javavm::JavaVirtualMachine_Impl_createInstance,
|
|
|
|
stoc_javavm::JavaVirtualMachine_Impl::getSupportedServiceNames_Static()));
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
if (xFactory.is())
|
|
|
|
{
|
|
|
|
xFactory->acquire();
|
|
|
|
pRet = xFactory.get();
|
|
|
|
}
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
|
2000-09-28 16:34:41 +00:00
|
|
|
return pRet;
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
}
|