LCOV - code coverage report
Current view: top level - libreoffice/stoc/source/javavm - javavm.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 742 0.0 %
Date: 2012-12-17 Functions: 0 43 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include "javavm.hxx"
      22             : 
      23             : #include "interact.hxx"
      24             : #include "jvmargs.hxx"
      25             : 
      26             : #include "com/sun/star/beans/NamedValue.hpp"
      27             : #include "com/sun/star/beans/PropertyState.hpp"
      28             : #include "com/sun/star/beans/PropertyValue.hpp"
      29             : #include "com/sun/star/container/XContainer.hpp"
      30             : #include "com/sun/star/java/JavaNotFoundException.hpp"
      31             : #include "com/sun/star/java/InvalidJavaSettingsException.hpp"
      32             : #include "com/sun/star/java/RestartRequiredException.hpp"
      33             : #include "com/sun/star/java/JavaDisabledException.hpp"
      34             : #include "com/sun/star/java/JavaVMCreationFailureException.hpp"
      35             : #include "com/sun/star/lang/DisposedException.hpp"
      36             : #include "com/sun/star/lang/IllegalArgumentException.hpp"
      37             : #include "com/sun/star/lang/XEventListener.hpp"
      38             : #include "com/sun/star/lang/XMultiComponentFactory.hpp"
      39             : #include "com/sun/star/lang/XSingleComponentFactory.hpp"
      40             : #include "com/sun/star/lang/WrappedTargetRuntimeException.hpp"
      41             : #include "com/sun/star/registry/XRegistryKey.hpp"
      42             : #include "com/sun/star/registry/XSimpleRegistry.hpp"
      43             : #include "com/sun/star/task/XInteractionHandler.hpp"
      44             : #include "com/sun/star/uno/Exception.hpp"
      45             : #include "com/sun/star/uno/Reference.hxx"
      46             : #include "com/sun/star/uno/RuntimeException.hpp"
      47             : #include "com/sun/star/uno/Sequence.hxx"
      48             : #include "com/sun/star/uno/XComponentContext.hpp"
      49             : #include "com/sun/star/uno/XCurrentContext.hpp"
      50             : #include "com/sun/star/uno/XInterface.hpp"
      51             : #include "com/sun/star/util/XMacroExpander.hpp"
      52             : #include "com/sun/star/container/XNameAccess.hpp"
      53             : #include "cppuhelper/exc_hlp.hxx"
      54             : #include "cppuhelper/factory.hxx"
      55             : #include "cppuhelper/implbase1.hxx"
      56             : #include "cppuhelper/implementationentry.hxx"
      57             : #include "jvmaccess/classpath.hxx"
      58             : #include "jvmaccess/unovirtualmachine.hxx"
      59             : #include "jvmaccess/virtualmachine.hxx"
      60             : #include "osl/file.hxx"
      61             : #include "osl/thread.h"
      62             : #include "rtl/bootstrap.hxx"
      63             : #include "rtl/process.h"
      64             : #include "rtl/string.h"
      65             : #include "rtl/ustrbuf.hxx"
      66             : #include "rtl/ustring.h"
      67             : #include "rtl/ustring.hxx"
      68             : #include "rtl/uri.hxx"
      69             : #include "sal/types.h"
      70             : #include "uno/current_context.hxx"
      71             : #include "uno/environment.h"
      72             : #include "uno/lbnames.h"
      73             : #include "jvmfwk/framework.h"
      74             : #include "jni.h"
      75             : 
      76             : #include <stack>
      77             : #include <string.h>
      78             : #include <time.h>
      79             : #include <memory>
      80             : #include <vector>
      81             : #include "boost/scoped_array.hpp"
      82             : #define OUSTR(x) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( x ))
      83             : 
      84             : // Properties of the javavm can be put
      85             : // as a komma separated list in this
      86             : // environment variable
      87             : #define PROPERTIES_ENV "OO_JAVA_PROPERTIES"
      88             : #ifdef UNIX
      89             : #define INI_FILE "javarc"
      90             : #ifdef MACOSX
      91             : #define DEF_JAVALIB "JavaVM.framework"
      92             : #else
      93             : #define DEF_JAVALIB "libjvm.so"
      94             : #endif
      95             : #define TIMEZONE "MEZ"
      96             : #else
      97             : #define INI_FILE "java.ini"
      98             : #define DEF_JAVALIB "jvm.dll"
      99             : #define TIMEZONE "MET"
     100             : #endif
     101             : 
     102             : /* Within this implementation of the com.sun.star.java.JavaVirtualMachine
     103             :  * service and com.sun.star.java.theJavaVirtualMachine singleton, the method
     104             :  * com.sun.star.java.XJavaVM.getJavaVM relies on the following:
     105             :  * 1  The string "$URE_INTERNAL_JAVA_DIR/" is expanded via the
     106             :  * com.sun.star.util.theMacroExpander singleton into an internal (see the
     107             :  * com.sun.star.uri.ExternalUriReferenceTranslator service), hierarchical URI
     108             :  * reference relative to which the URE JAR files can be addressed.
     109             :  * 2  The string "$URE_INTERNAL_JAVA_CLASSPATH" is either not expandable via the
     110             :  * com.sun.star.util.theMacroExpander singleton
     111             :  * (com.sun.star.lang.IllegalArgumentException), or is expanded via the
     112             :  * com.sun.star.util.theMacroExpander singleton into a list of zero or more
     113             :  * internal (see the com.sun.star.uri.ExternalUriReferenceTranslator service)
     114             :  * URIs, where any space characters (U+0020) are ignored (and, in particular,
     115             :  * separate adjacent URIs).
     116             :  * If either of these requirements is not met, getJavaVM raises a
     117             :  * com.sun.star.uno.RuntimeException.
     118             :  */
     119             : 
     120             : using stoc_javavm::JavaVirtualMachine;
     121             : 
     122             : namespace {
     123             : 
     124             : 
     125             : 
     126             : class NoJavaIniException: public css::uno::Exception
     127             : {
     128             : };
     129             : 
     130             : class SingletonFactory:
     131             :     private cppu::WeakImplHelper1< css::lang::XEventListener >
     132             : {
     133             : public:
     134             :     static css::uno::Reference< css::uno::XInterface > getSingleton(
     135             :         css::uno::Reference< css::uno::XComponentContext > const & rContext);
     136             : 
     137             : private:
     138             :     SingletonFactory(SingletonFactory &); // not implemented
     139             :     void operator =(SingletonFactory); // not implemented
     140             : 
     141           0 :     inline SingletonFactory() {}
     142             : 
     143           0 :     virtual inline ~SingletonFactory() {}
     144             : 
     145             :     virtual void SAL_CALL disposing(css::lang::EventObject const &)
     146             :         throw (css::uno::RuntimeException);
     147             : 
     148             :     static void dispose();
     149             : 
     150             :     // TODO ok to keep these static?
     151             :     static osl::Mutex m_aMutex;
     152             :     static css::uno::Reference< css::uno::XInterface > m_xSingleton;
     153             :     static bool m_bDisposed;
     154             : };
     155             : 
     156           0 : css::uno::Reference< css::uno::XInterface > SingletonFactory::getSingleton(
     157             :     css::uno::Reference< css::uno::XComponentContext > const & rContext)
     158             : {
     159           0 :     css::uno::Reference< css::uno::XInterface > xSingleton;
     160           0 :     css::uno::Reference< css::lang::XComponent > xComponent;
     161             :     {
     162           0 :         osl::MutexGuard aGuard(m_aMutex);
     163           0 :         if (!m_xSingleton.is())
     164             :         {
     165           0 :             if (m_bDisposed)
     166           0 :                 throw css::lang::DisposedException();
     167             :             xComponent = css::uno::Reference< css::lang::XComponent >(
     168           0 :                 rContext, css::uno::UNO_QUERY_THROW);
     169             :             m_xSingleton = static_cast< cppu::OWeakObject * >(
     170           0 :                 new JavaVirtualMachine(rContext));
     171             :         }
     172           0 :         xSingleton = m_xSingleton;
     173             :     }
     174           0 :     if (xComponent.is())
     175             :         try
     176             :         {
     177           0 :             xComponent->addEventListener(new SingletonFactory);
     178             :         }
     179           0 :         catch (...)
     180             :         {
     181           0 :             dispose();
     182           0 :             throw;
     183             :         }
     184           0 :     return xSingleton;
     185             : }
     186             : 
     187           0 : void SAL_CALL SingletonFactory::disposing(css::lang::EventObject const &)
     188             :     throw (css::uno::RuntimeException)
     189             : {
     190           0 :     dispose();
     191           0 : }
     192             : 
     193           0 : void SingletonFactory::dispose()
     194             : {
     195           0 :     css::uno::Reference< css::lang::XComponent > xComponent;
     196             :     {
     197           0 :         osl::MutexGuard aGuard(m_aMutex);
     198             :         xComponent = css::uno::Reference< css::lang::XComponent >(
     199           0 :             m_xSingleton, css::uno::UNO_QUERY);
     200           0 :         m_xSingleton.clear();
     201           0 :         m_bDisposed = true;
     202             :     }
     203           0 :     if (xComponent.is())
     204           0 :         xComponent->dispose();
     205           0 : }
     206             : 
     207           0 : osl::Mutex SingletonFactory::m_aMutex;
     208           0 : css::uno::Reference< css::uno::XInterface > SingletonFactory::m_xSingleton;
     209             : bool SingletonFactory::m_bDisposed = false;
     210             : 
     211           0 : rtl::OUString serviceGetImplementationName()
     212             : {
     213             :     return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
     214           0 :                              "com.sun.star.comp.stoc.JavaVirtualMachine"));
     215             : }
     216             : 
     217           0 : css::uno::Sequence< rtl::OUString > serviceGetSupportedServiceNames()
     218             : {
     219             :     rtl::OUString aServiceName(
     220           0 :         RTL_CONSTASCII_USTRINGPARAM("com.sun.star.java.JavaVirtualMachine"));
     221           0 :     return css::uno::Sequence< rtl::OUString >(&aServiceName, 1);
     222             : }
     223             : 
     224           0 : css::uno::Reference< css::uno::XInterface > SAL_CALL serviceCreateInstance(
     225             :     css::uno::Reference< css::uno::XComponentContext > const & rContext)
     226             :     SAL_THROW((css::uno::Exception))
     227             : {
     228             :     // Only one single instance of this service is ever constructed, and is
     229             :     // available until the component context used to create this instance is
     230             :     // disposed.  Afterwards, this function throws a DisposedException (as do
     231             :     // all relevant methods on the single service instance).
     232           0 :     return SingletonFactory::getSingleton(rContext);
     233             : }
     234             : 
     235             : cppu::ImplementationEntry const aServiceImplementation[]
     236             :     = { { serviceCreateInstance,
     237             :           serviceGetImplementationName,
     238             :           serviceGetSupportedServiceNames,
     239             :           cppu::createSingleComponentFactory,
     240             :           0, 0 },
     241             :         { 0, 0, 0, 0, 0, 0 } };
     242             : 
     243             : typedef std::stack< jvmaccess::VirtualMachine::AttachGuard * > GuardStack;
     244             : 
     245             : extern "C" {
     246             : 
     247           0 : static void destroyAttachGuards(void * pData)
     248             : {
     249           0 :     GuardStack * pStack = static_cast< GuardStack * >(pData);
     250           0 :     if (pStack != 0)
     251             :     {
     252           0 :         while (!pStack->empty())
     253             :         {
     254           0 :             delete pStack->top();
     255           0 :             pStack->pop();
     256             :         }
     257           0 :         delete pStack;
     258             :     }
     259           0 : }
     260             : 
     261             : }
     262             : 
     263           0 : bool askForRetry(css::uno::Any const & rException)
     264             : {
     265             :     css::uno::Reference< css::uno::XCurrentContext > xContext(
     266           0 :         css::uno::getCurrentContext());
     267           0 :     if (xContext.is())
     268             :     {
     269           0 :         css::uno::Reference< css::task::XInteractionHandler > xHandler;
     270           0 :         xContext->getValueByName(rtl::OUString(
     271             :                                      RTL_CONSTASCII_USTRINGPARAM(
     272           0 :                                          "java-vm.interaction-handler")))
     273           0 :             >>= xHandler;
     274           0 :         if (xHandler.is())
     275             :         {
     276             :             rtl::Reference< stoc_javavm::InteractionRequest > xRequest(
     277           0 :                 new stoc_javavm::InteractionRequest(rException));
     278           0 :             xHandler->handle(xRequest.get());
     279           0 :             return xRequest->retry();
     280           0 :         }
     281             :     }
     282           0 :     return false;
     283             : }
     284             : 
     285             : // Only gets the properties if the "Proxy Server" entry in the option dialog is
     286             : // set to manual (i.e. not to none)
     287           0 : void getINetPropsFromConfig(stoc_javavm::JVM * pjvm,
     288             :                             const css::uno::Reference<css::lang::XMultiComponentFactory> & xSMgr,
     289             :                             const css::uno::Reference<css::uno::XComponentContext> &xCtx ) throw (css::uno::Exception)
     290             : {
     291           0 :     css::uno::Reference<css::uno::XInterface> xConfRegistry = xSMgr->createInstanceWithContext(
     292             :             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.configuration.ConfigurationRegistry")),
     293           0 :             xCtx );
     294           0 :     if(!xConfRegistry.is()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("javavm.cxx: couldn't get ConfigurationRegistry")), 0);
     295             : 
     296           0 :     css::uno::Reference<css::registry::XSimpleRegistry> xConfRegistry_simple(xConfRegistry, css::uno::UNO_QUERY);
     297           0 :     if(!xConfRegistry_simple.is()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("javavm.cxx: couldn't get ConfigurationRegistry")), 0);
     298             : 
     299           0 :     xConfRegistry_simple->open(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Inet")), sal_True, sal_False);
     300           0 :     css::uno::Reference<css::registry::XRegistryKey> xRegistryRootKey = xConfRegistry_simple->getRootKey();
     301             : 
     302             : //  if ooInetProxyType is not 0 then read the settings
     303           0 :     css::uno::Reference<css::registry::XRegistryKey> proxyEnable= xRegistryRootKey->openKey(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Settings/ooInetProxyType")));
     304           0 :     if( proxyEnable.is() && 0 != proxyEnable->getLongValue())
     305             :     {
     306             :         // read ftp proxy name
     307           0 :         css::uno::Reference<css::registry::XRegistryKey> ftpProxy_name = xRegistryRootKey->openKey(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Settings/ooInetFTPProxyName")));
     308           0 :         if(ftpProxy_name.is() && !ftpProxy_name->getStringValue().isEmpty()) {
     309           0 :             rtl::OUString ftpHost = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ftp.proxyHost="));
     310           0 :             ftpHost += ftpProxy_name->getStringValue();
     311             : 
     312             :             // read ftp proxy port
     313           0 :             css::uno::Reference<css::registry::XRegistryKey> ftpProxy_port = xRegistryRootKey->openKey(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Settings/ooInetFTPProxyPort")));
     314           0 :             if(ftpProxy_port.is() && ftpProxy_port->getLongValue()) {
     315           0 :                 rtl::OUString ftpPort = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ftp.proxyPort="));
     316           0 :                 ftpPort += rtl::OUString::valueOf(ftpProxy_port->getLongValue());
     317             : 
     318           0 :                 pjvm->pushProp(ftpHost);
     319           0 :                 pjvm->pushProp(ftpPort);
     320           0 :             }
     321             :         }
     322             : 
     323             :         // read http proxy name
     324           0 :         css::uno::Reference<css::registry::XRegistryKey> httpProxy_name = xRegistryRootKey->openKey(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Settings/ooInetHTTPProxyName")));
     325           0 :         if(httpProxy_name.is() && !httpProxy_name->getStringValue().isEmpty()) {
     326           0 :             rtl::OUString httpHost = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("http.proxyHost="));
     327           0 :             httpHost += httpProxy_name->getStringValue();
     328             : 
     329             :             // read http proxy port
     330           0 :             css::uno::Reference<css::registry::XRegistryKey> httpProxy_port = xRegistryRootKey->openKey(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Settings/ooInetHTTPProxyPort")));
     331           0 :             if(httpProxy_port.is() && httpProxy_port->getLongValue()) {
     332           0 :                 rtl::OUString httpPort = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("http.proxyPort="));
     333           0 :                 httpPort += rtl::OUString::valueOf(httpProxy_port->getLongValue());
     334             : 
     335           0 :                 pjvm->pushProp(httpHost);
     336           0 :                 pjvm->pushProp(httpPort);
     337           0 :             }
     338             :         }
     339             : 
     340             :         // read https proxy name
     341           0 :         css::uno::Reference<css::registry::XRegistryKey> httpsProxy_name = xRegistryRootKey->openKey(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Settings/ooInetHTTPSProxyName")));
     342           0 :         if(httpsProxy_name.is() && !httpsProxy_name->getStringValue().isEmpty()) {
     343           0 :             rtl::OUString httpsHost = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("https.proxyHost="));
     344           0 :             httpsHost += httpsProxy_name->getStringValue();
     345             : 
     346             :             // read https proxy port
     347           0 :             css::uno::Reference<css::registry::XRegistryKey> httpsProxy_port = xRegistryRootKey->openKey(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Settings/ooInetHTTPSProxyPort")));
     348           0 :             if(httpsProxy_port.is() && httpsProxy_port->getLongValue()) {
     349           0 :                 rtl::OUString httpsPort = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("https.proxyPort="));
     350           0 :                 httpsPort += rtl::OUString::valueOf(httpsProxy_port->getLongValue());
     351             : 
     352           0 :                 pjvm->pushProp(httpsHost);
     353           0 :                 pjvm->pushProp(httpsPort);
     354           0 :             }
     355             :         }
     356             : 
     357             :         // read  nonProxyHosts
     358           0 :         css::uno::Reference<css::registry::XRegistryKey> nonProxies_name = xRegistryRootKey->openKey(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Settings/ooInetNoProxy")));
     359           0 :         if(nonProxies_name.is() && !nonProxies_name->getStringValue().isEmpty()) {
     360           0 :             rtl::OUString httpNonProxyHosts = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("http.nonProxyHosts="));
     361           0 :             rtl::OUString ftpNonProxyHosts= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ftp.nonProxyHosts="));
     362           0 :             rtl::OUString value= nonProxies_name->getStringValue();
     363             :             // replace the separator ";" by "|"
     364           0 :             value= value.replace((sal_Unicode)';', (sal_Unicode)'|');
     365             : 
     366           0 :             httpNonProxyHosts += value;
     367           0 :             ftpNonProxyHosts += value;
     368             : 
     369           0 :             pjvm->pushProp(httpNonProxyHosts);
     370           0 :             pjvm->pushProp(ftpNonProxyHosts);
     371           0 :         }
     372             : 
     373             :         // read socks settings
     374             : /*      Reference<XRegistryKey> socksProxy_name = xRegistryRootKey->openKey(OUSTR("Settings/ooInetSOCKSProxyName"));
     375             :         if (socksProxy_name.is() && httpProxy_name->getStringValue().getLength()) {
     376             :             OUString socksHost = OUSTR("socksProxyHost=");
     377             :             socksHost += socksProxy_name->getStringValue();
     378             : 
     379             :             // read http proxy port
     380             :             Reference<XRegistryKey> socksProxy_port = xRegistryRootKey->openKey(OUSTR("Settings/ooInetSOCKSProxyPort"));
     381             :             if (socksProxy_port.is() && socksProxy_port->getLongValue()) {
     382             :                 OUString socksPort = OUSTR("socksProxyPort=");
     383             :                 socksPort += OUString::valueOf(socksProxy_port->getLongValue());
     384             : 
     385             :                 pjvm->pushProp(socksHost);
     386             :                 pjvm->pushProp(socksPort);
     387             :             }
     388             :         }
     389             : */  }
     390           0 :     xConfRegistry_simple->close();
     391           0 : }
     392             : 
     393           0 : void getDefaultLocaleFromConfig(
     394             :     stoc_javavm::JVM * pjvm,
     395             :     const css::uno::Reference<css::lang::XMultiComponentFactory> & xSMgr,
     396             :     const css::uno::Reference<css::uno::XComponentContext> &xCtx ) throw(css::uno::Exception)
     397             : {
     398             :     css::uno::Reference<css::uno::XInterface> xConfRegistry =
     399           0 :         xSMgr->createInstanceWithContext(
     400             :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
     401           0 :                           "com.sun.star.configuration.ConfigurationRegistry")), xCtx );
     402           0 :     if(!xConfRegistry.is())
     403             :         throw css::uno::RuntimeException(
     404           0 :             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("javavm.cxx: couldn't get ConfigurationRegistry")), 0);
     405             : 
     406             :     css::uno::Reference<css::registry::XSimpleRegistry> xConfRegistry_simple(
     407           0 :         xConfRegistry, css::uno::UNO_QUERY);
     408           0 :     if(!xConfRegistry_simple.is())
     409             :         throw css::uno::RuntimeException(
     410           0 :             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("javavm.cxx: couldn't get ConfigurationRegistry")), 0);
     411             : 
     412           0 :     xConfRegistry_simple->open(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Setup")), sal_True, sal_False);
     413           0 :     css::uno::Reference<css::registry::XRegistryKey> xRegistryRootKey = xConfRegistry_simple->getRootKey();
     414             : 
     415             :     // read locale
     416           0 :     css::uno::Reference<css::registry::XRegistryKey> locale = xRegistryRootKey->openKey(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("L10N/ooLocale")));
     417           0 :     if(locale.is() && !locale->getStringValue().isEmpty()) {
     418           0 :         rtl::OUString language;
     419           0 :         rtl::OUString country;
     420             : 
     421           0 :         sal_Int32 index = locale->getStringValue().indexOf((sal_Unicode) '-');
     422             : 
     423           0 :         if(index >= 0) {
     424           0 :             language = locale->getStringValue().copy(0, index);
     425           0 :             country = locale->getStringValue().copy(index + 1);
     426             : 
     427           0 :             if(!language.isEmpty()) {
     428           0 :                 rtl::OUString prop(RTL_CONSTASCII_USTRINGPARAM("user.language="));
     429           0 :                 prop += language;
     430             : 
     431           0 :                 pjvm->pushProp(prop);
     432             :             }
     433             : 
     434           0 :             if(!country.isEmpty()) {
     435           0 :                 rtl::OUString prop(RTL_CONSTASCII_USTRINGPARAM("user.country="));
     436           0 :                 prop += country;
     437             : 
     438           0 :                 pjvm->pushProp(prop);
     439             :             }
     440           0 :         }
     441             :     }
     442             : 
     443           0 :     xConfRegistry_simple->close();
     444           0 : }
     445             : 
     446             : 
     447             : 
     448           0 : void getJavaPropsFromSafetySettings(
     449             :     stoc_javavm::JVM * pjvm,
     450             :     const css::uno::Reference<css::lang::XMultiComponentFactory> & xSMgr,
     451             :     const css::uno::Reference<css::uno::XComponentContext> &xCtx) throw(css::uno::Exception)
     452             : {
     453             :     css::uno::Reference<css::uno::XInterface> xConfRegistry =
     454           0 :         xSMgr->createInstanceWithContext(
     455             :             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
     456             :                               "com.sun.star.configuration.ConfigurationRegistry")),
     457           0 :             xCtx);
     458           0 :     if(!xConfRegistry.is())
     459             :         throw css::uno::RuntimeException(
     460           0 :             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("javavm.cxx: couldn't get ConfigurationRegistry")), 0);
     461             : 
     462             :     css::uno::Reference<css::registry::XSimpleRegistry> xConfRegistry_simple(
     463           0 :         xConfRegistry, css::uno::UNO_QUERY);
     464           0 :     if(!xConfRegistry_simple.is())
     465             :         throw css::uno::RuntimeException(
     466           0 :             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("javavm.cxx: couldn't get ConfigurationRegistry")), 0);
     467             : 
     468           0 :     xConfRegistry_simple->open(
     469             :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Office.Java")),
     470           0 :         sal_True, sal_False);
     471             :     css::uno::Reference<css::registry::XRegistryKey> xRegistryRootKey =
     472           0 :         xConfRegistry_simple->getRootKey();
     473             : 
     474           0 :     if (xRegistryRootKey.is())
     475             :     {
     476           0 :         css::uno::Reference<css::registry::XRegistryKey> key_NetAccess= xRegistryRootKey->openKey(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("VirtualMachine/NetAccess")));
     477           0 :         if (key_NetAccess.is())
     478             :         {
     479           0 :             sal_Int32 val= key_NetAccess->getLongValue();
     480           0 :             rtl::OUString sVal;
     481           0 :             switch( val)
     482             :             {
     483           0 :             case 0: sVal= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("host"));
     484           0 :                 break;
     485           0 :             case 1: sVal= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("unrestricted"));
     486           0 :                 break;
     487           0 :             case 3: sVal= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("none"));
     488           0 :                 break;
     489             :             }
     490           0 :             rtl::OUString sProperty( RTL_CONSTASCII_USTRINGPARAM("appletviewer.security.mode="));
     491           0 :             sProperty= sProperty + sVal;
     492           0 :             pjvm->pushProp(sProperty);
     493             :         }
     494           0 :         css::uno::Reference<css::registry::XRegistryKey> key_CheckSecurity= xRegistryRootKey->openKey(
     495           0 :             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("VirtualMachine/Security")));
     496           0 :         if( key_CheckSecurity.is())
     497             :         {
     498           0 :             sal_Bool val= (sal_Bool) key_CheckSecurity->getLongValue();
     499           0 :             rtl::OUString sProperty(RTL_CONSTASCII_USTRINGPARAM("stardiv.security.disableSecurity="));
     500           0 :             if( val)
     501           0 :                 sProperty= sProperty + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("false"));
     502             :             else
     503           0 :                 sProperty= sProperty + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("true"));
     504           0 :             pjvm->pushProp( sProperty);
     505           0 :         }
     506             :     }
     507           0 :     xConfRegistry_simple->close();
     508           0 : }
     509             : 
     510           0 : static void setTimeZone(stoc_javavm::JVM * pjvm) throw() {
     511             :     /* A Bug in the Java function
     512             :     ** struct Hjava_util_Properties * java_lang_System_initProperties(
     513             :     ** struct Hjava_lang_System *this,
     514             :     ** struct Hjava_util_Properties *props);
     515             :     ** This function doesn't detect MEZ, MET or "W. Europe Standard Time"
     516             :     */
     517             :     struct tm *tmData;
     518           0 :     time_t clock = time(NULL);
     519           0 :     tzset();
     520           0 :     tmData = localtime(&clock);
     521             : #ifdef MACOSX
     522             :     char * p = tmData->tm_zone;
     523             : #else
     524           0 :     char * p = tzname[0];
     525             :     (void)tmData;
     526             : #endif
     527             : 
     528           0 :     if (!strcmp(TIMEZONE, p))
     529           0 :         pjvm->pushProp(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("user.timezone=ECT")));
     530           0 : }
     531             : 
     532           0 : void initVMConfiguration(
     533             :     stoc_javavm::JVM * pjvm,
     534             :     const css::uno::Reference<css::lang::XMultiComponentFactory> & xSMgr,
     535             :     const css::uno::Reference<css::uno::XComponentContext > &xCtx) throw(css::uno::Exception)
     536             : {
     537           0 :     stoc_javavm::JVM jvm;
     538             :     try {
     539           0 :         getINetPropsFromConfig(&jvm, xSMgr, xCtx);
     540             :     }
     541           0 :     catch(const css::uno::Exception & exception) {
     542             : #if OSL_DEBUG_LEVEL > 1
     543             :         rtl::OString message = rtl::OUStringToOString(exception.Message, RTL_TEXTENCODING_ASCII_US);
     544             :         OSL_TRACE("javavm.cxx: can not get INetProps cause of >%s<", message.getStr());
     545             : #else
     546             :         (void) exception; // unused
     547             : #endif
     548             :     }
     549             : 
     550             :     try {
     551           0 :         getDefaultLocaleFromConfig(&jvm, xSMgr,xCtx);
     552             :     }
     553           0 :     catch(const css::uno::Exception & exception) {
     554             : #if OSL_DEBUG_LEVEL > 1
     555             :         rtl::OString message = rtl::OUStringToOString(exception.Message, RTL_TEXTENCODING_ASCII_US);
     556             :         OSL_TRACE("javavm.cxx: can not get locale cause of >%s<", message.getStr());
     557             : #else
     558             :         (void) exception; // unused
     559             : #endif
     560             :     }
     561             : 
     562             :     try
     563             :     {
     564           0 :         getJavaPropsFromSafetySettings(&jvm, xSMgr, xCtx);
     565             :     }
     566           0 :     catch(const css::uno::Exception & exception) {
     567             : #if OSL_DEBUG_LEVEL > 1
     568             :         rtl::OString message = rtl::OUStringToOString(exception.Message, RTL_TEXTENCODING_ASCII_US);
     569             :         OSL_TRACE("javavm.cxx: couldn't get safety settings because of >%s<", message.getStr());
     570             : #else
     571             :         (void) exception; // unused
     572             : #endif
     573             :     }
     574             : 
     575           0 :     *pjvm= jvm;
     576           0 :     setTimeZone(pjvm);
     577             : 
     578           0 : }
     579             : 
     580             : class DetachCurrentThread {
     581             : public:
     582           0 :     explicit DetachCurrentThread(JavaVM * jvm): m_jvm(jvm) {}
     583             : 
     584           0 :     ~DetachCurrentThread() {
     585           0 :         if (m_jvm->DetachCurrentThread() != 0) {
     586             :             OSL_ASSERT(false);
     587             :         }
     588           0 :     }
     589             : 
     590             : private:
     591             :     DetachCurrentThread(DetachCurrentThread &); // not defined
     592             :     void operator =(DetachCurrentThread &); // not defined
     593             : 
     594             :     JavaVM * m_jvm;
     595             : };
     596             : 
     597             : }
     598             : 
     599           0 : extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL javavm_component_getFactory(sal_Char const * pImplName,
     600             :                                                 void * pServiceManager,
     601             :                                                 void * pRegistryKey)
     602             : {
     603             :     return cppu::component_getFactoryHelper(pImplName, pServiceManager,
     604             :                                             pRegistryKey,
     605           0 :                                             aServiceImplementation);
     606             : }
     607             : 
     608             : // There is no component_canUnload, as the library cannot be unloaded.
     609             : 
     610           0 : JavaVirtualMachine::JavaVirtualMachine(
     611             :     css::uno::Reference< css::uno::XComponentContext > const & rContext):
     612             :     JavaVirtualMachine_Impl(*static_cast< osl::Mutex * >(this)),
     613             :     m_xContext(rContext),
     614             :     m_bDisposed(false),
     615             :     m_pJavaVm(0),
     616             :     m_bDontCreateJvm(false),
     617           0 :     m_aAttachGuards(destroyAttachGuards) // TODO check for validity
     618           0 : {}
     619             : 
     620             : void SAL_CALL
     621           0 : JavaVirtualMachine::initialize(css::uno::Sequence< css::uno::Any > const &
     622             :                                    rArguments)
     623             :     throw (css::uno::Exception)
     624             : {
     625           0 :     osl::MutexGuard aGuard(*this);
     626           0 :     if (m_bDisposed)
     627             :         throw css::lang::DisposedException(
     628           0 :             rtl::OUString(), static_cast< cppu::OWeakObject * >(this));
     629           0 :     if (m_xUnoVirtualMachine.is())
     630             :         throw css::uno::RuntimeException(
     631             :             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
     632             :                               "bad call to initialize")),
     633           0 :             static_cast< cppu::OWeakObject * >(this));
     634           0 :     css::beans::NamedValue val;
     635           0 :     if (rArguments.getLength() == 1 && (rArguments[0] >>= val) && val.Name == "UnoVirtualMachine" )
     636             :     {
     637             :         OSL_ENSURE(
     638             :             sizeof (sal_Int64) >= sizeof (jvmaccess::UnoVirtualMachine *),
     639             :             "Pointer cannot be represented as sal_Int64");
     640             :         sal_Int64 nPointer = reinterpret_cast< sal_Int64 >(
     641           0 :             static_cast< jvmaccess::UnoVirtualMachine * >(0));
     642           0 :         val.Value >>= nPointer;
     643             :         m_xUnoVirtualMachine =
     644           0 :             reinterpret_cast< jvmaccess::UnoVirtualMachine * >(nPointer);
     645             :     } else {
     646             :         OSL_ENSURE(
     647             :             sizeof (sal_Int64) >= sizeof (jvmaccess::VirtualMachine *),
     648             :             "Pointer cannot be represented as sal_Int64");
     649             :         sal_Int64 nPointer = reinterpret_cast< sal_Int64 >(
     650           0 :             static_cast< jvmaccess::VirtualMachine * >(0));
     651           0 :         if (rArguments.getLength() == 1)
     652           0 :             rArguments[0] >>= nPointer;
     653             :         rtl::Reference< jvmaccess::VirtualMachine > vm(
     654           0 :             reinterpret_cast< jvmaccess::VirtualMachine * >(nPointer));
     655           0 :         if (vm.is()) {
     656             :             try {
     657           0 :                 m_xUnoVirtualMachine = new jvmaccess::UnoVirtualMachine(vm, 0);
     658           0 :             } catch (jvmaccess::UnoVirtualMachine::CreationException &) {
     659             :                 throw css::uno::RuntimeException(
     660             :                     rtl::OUString(
     661             :                         RTL_CONSTASCII_USTRINGPARAM(
     662             :                             "jvmaccess::UnoVirtualMachine::CreationException")),
     663           0 :                     static_cast< cppu::OWeakObject * >(this));
     664             :             }
     665           0 :         }
     666             :     }
     667           0 :     if (!m_xUnoVirtualMachine.is()) {
     668             :         throw css::lang::IllegalArgumentException(
     669             :             rtl::OUString(
     670             :                 RTL_CONSTASCII_USTRINGPARAM(
     671             :                     "sequence of exactly one any containing either (a) a"
     672             :                     " com.sun.star.beans.NamedValue with Name"
     673             :                     " \"UnoVirtualMachine\" and Value a hyper representing a"
     674             :                     " non-null pointer to a jvmaccess:UnoVirtualMachine, or (b)"
     675             :                     " a hyper representing a non-null pointer to a"
     676             :                     " jvmaccess::VirtualMachine required")),
     677           0 :             static_cast< cppu::OWeakObject * >(this), 0);
     678             :     }
     679           0 :     m_xVirtualMachine = m_xUnoVirtualMachine->getVirtualMachine();
     680           0 : }
     681             : 
     682           0 : rtl::OUString SAL_CALL JavaVirtualMachine::getImplementationName()
     683             :     throw (css::uno::RuntimeException)
     684             : {
     685           0 :     return serviceGetImplementationName();
     686             : }
     687             : 
     688             : sal_Bool SAL_CALL
     689           0 : JavaVirtualMachine::supportsService(rtl::OUString const & rServiceName)
     690             :     throw (css::uno::RuntimeException)
     691             : {
     692           0 :     css::uno::Sequence< rtl::OUString > aNames(getSupportedServiceNames());
     693           0 :     for (sal_Int32 i = 0; i < aNames.getLength(); ++i)
     694           0 :         if (aNames[i] == rServiceName)
     695           0 :             return true;
     696           0 :     return false;
     697             : }
     698             : 
     699             : css::uno::Sequence< rtl::OUString > SAL_CALL
     700           0 : JavaVirtualMachine::getSupportedServiceNames()
     701             :     throw (css::uno::RuntimeException)
     702             : {
     703           0 :     return serviceGetSupportedServiceNames();
     704             : }
     705             : 
     706             : css::uno::Any SAL_CALL
     707           0 : JavaVirtualMachine::getJavaVM(css::uno::Sequence< sal_Int8 > const & rProcessId)
     708             :     throw (css::uno::RuntimeException)
     709             : {
     710           0 :     osl::MutexGuard aGuard(*this);
     711           0 :     if (m_bDisposed)
     712             :         throw css::lang::DisposedException(
     713           0 :             rtl::OUString(), static_cast< cppu::OWeakObject * >(this));
     714           0 :     css::uno::Sequence< sal_Int8 > aId(16);
     715           0 :     rtl_getGlobalProcessId(reinterpret_cast< sal_uInt8 * >(aId.getArray()));
     716             :     enum ReturnType {
     717             :         RETURN_JAVAVM, RETURN_VIRTUALMACHINE, RETURN_UNOVIRTUALMACHINE };
     718             :     ReturnType returnType =
     719           0 :         rProcessId.getLength() == 17 && rProcessId[16] == 0
     720             :         ? RETURN_VIRTUALMACHINE
     721           0 :         : rProcessId.getLength() == 17 && rProcessId[16] == 1
     722             :         ? RETURN_UNOVIRTUALMACHINE
     723           0 :         : RETURN_JAVAVM;
     724           0 :     css::uno::Sequence< sal_Int8 > aProcessId(rProcessId);
     725           0 :     if (returnType != RETURN_JAVAVM)
     726           0 :         aProcessId.realloc(16);
     727           0 :     if (aId != aProcessId)
     728           0 :         return css::uno::Any();
     729             : 
     730           0 :     while (!m_xVirtualMachine.is()) // retry until successful
     731             :     {
     732             :         // This is the second attempt to create Java.  m_bDontCreateJvm is
     733             :         // set which means instantiating the JVM might crash.
     734           0 :         if (m_bDontCreateJvm)
     735             :             //throw css::uno::RuntimeException();
     736           0 :             return css::uno::Any();
     737             : 
     738           0 :         stoc_javavm::JVM aJvm;
     739           0 :         initVMConfiguration(&aJvm, m_xContext->getServiceManager(),
     740           0 :                             m_xContext);
     741             :         //Create the JavaVMOption array
     742           0 :         const std::vector<rtl::OUString> & props = aJvm.getProperties();
     743             :         boost::scoped_array<JavaVMOption> sarOptions(
     744           0 :             new JavaVMOption[props.size()]);
     745           0 :         JavaVMOption * arOptions = sarOptions.get();
     746             :         //Create an array that contains the strings which are passed
     747             :         //into the options
     748             :         boost::scoped_array<rtl::OString> sarPropStrings(
     749           0 :              new rtl::OString[props.size()]);
     750           0 :         rtl::OString * arPropStrings = sarPropStrings.get();
     751             : 
     752           0 :         rtl::OString sJavaOption("-");
     753             :         typedef std::vector<rtl::OUString>::const_iterator cit;
     754           0 :         int index = 0;
     755           0 :         for (cit i = props.begin(); i != props.end(); ++i)
     756             :         {
     757             :             rtl::OString sOption = rtl::OUStringToOString(
     758           0 :                 *i, osl_getThreadTextEncoding());
     759             : 
     760           0 :             if (!sOption.matchIgnoreAsciiCase(sJavaOption, 0))
     761           0 :                 arPropStrings[index]= rtl::OString("-D") + sOption;
     762             :             else
     763           0 :                 arPropStrings[index] = sOption;
     764             : 
     765           0 :             arOptions[index].optionString = (sal_Char*)arPropStrings[index].getStr();
     766           0 :             arOptions[index].extraInfo = 0;
     767           0 :             index ++;
     768           0 :         }
     769             : 
     770           0 :         JNIEnv * pMainThreadEnv = 0;
     771           0 :         javaFrameworkError errcode = JFW_E_NONE;
     772             : 
     773           0 :         if (getenv("STOC_FORCE_NO_JRE"))
     774           0 :             errcode = JFW_E_NO_SELECT;
     775             :         else
     776             :             errcode = jfw_startVM(arOptions, index, & m_pJavaVm,
     777           0 :                                   & pMainThreadEnv);
     778             : 
     779           0 :         bool bStarted = false;
     780           0 :         switch (errcode)
     781             :         {
     782           0 :         case JFW_E_NONE: bStarted = true; break;
     783             :         case JFW_E_NO_SELECT:
     784             :         {
     785             :             // No Java configured. We silenty run the java configuration
     786             :             // Java.
     787           0 :             javaFrameworkError errFind = jfw_findAndSelectJRE( NULL );
     788           0 :             if (getenv("STOC_FORCE_NO_JRE"))
     789           0 :                 errFind = JFW_E_NO_JAVA_FOUND;
     790           0 :             if (errFind == JFW_E_NONE)
     791             :             {
     792           0 :                 continue;
     793             :             }
     794           0 :             else if (errFind == JFW_E_NO_JAVA_FOUND)
     795             :             {
     796             : 
     797             :                 //Warning MessageBox:
     798             :                 //%PRODUCTNAME requires a Java runtime environment (JRE) to perform this task.
     799             :                 //Please install a JRE and restart %PRODUCTNAME.
     800             :                 css::java::JavaNotFoundException exc(
     801             :                     rtl::OUString(
     802             :                         RTL_CONSTASCII_USTRINGPARAM(
     803             :                             "JavaVirtualMachine::getJavaVM failed because"
     804             :                             " No suitable JRE found!")),
     805           0 :                     static_cast< cppu::OWeakObject * >(this));
     806           0 :                 askForRetry(css::uno::makeAny(exc));
     807           0 :                 return css::uno::Any();
     808             :             }
     809             :             else
     810             :             {
     811             :                 //An unexpected error occurred
     812             :                 throw css::uno::RuntimeException(
     813             :                     rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
     814             :                                       "[JavaVirtualMachine]:An unexpected error occurred"
     815           0 :                                       " while searching for a Java!")), 0);
     816             :             }
     817             :         }
     818             :         case JFW_E_INVALID_SETTINGS:
     819             :         {
     820             :             //Warning MessageBox:
     821             :             // The %PRODUCTNAME configuration has been changed. Under Tools
     822             :             // - Options - %PRODUCTNAME - Java, select the Java runtime environment
     823             :             // you want to have used by %PRODUCTNAME.
     824             :             css::java::InvalidJavaSettingsException exc(
     825             :                 rtl::OUString(
     826             :                     RTL_CONSTASCII_USTRINGPARAM(
     827             :                         "JavaVirtualMachine::getJavaVM failed because"
     828             :                         " Java settings have changed!")),
     829           0 :                 static_cast< cppu::OWeakObject * >(this));
     830           0 :             askForRetry(css::uno::makeAny(exc));
     831           0 :             return css::uno::Any();
     832             :         }
     833             :         case JFW_E_JAVA_DISABLED:
     834             :         {
     835             :             //QueryBox:
     836             :             //%PRODUCTNAME requires a Java runtime environment (JRE) to perform
     837             :             //this task. However, use of a JRE has been disabled. Do you want to
     838             :             //enable the use of a JRE now?
     839             :             css::java::JavaDisabledException exc(
     840             :                 rtl::OUString(
     841             :                     RTL_CONSTASCII_USTRINGPARAM(
     842             :                         "JavaVirtualMachine::getJavaVM failed because"
     843             :                         " Java is disabled!")),
     844           0 :                 static_cast< cppu::OWeakObject * >(this));
     845           0 :             if( ! askForRetry(css::uno::makeAny(exc)))
     846           0 :                 return css::uno::Any();
     847           0 :             continue;
     848             :         }
     849             :         case JFW_E_VM_CREATION_FAILED:
     850             :         {
     851             :             //If the creation failed because the JRE has been uninstalled then
     852             :             //we search another one. As long as there is a javaldx, we should
     853             :             //never come into this situation. javaldx checks alway if the JRE
     854             :             //still exist.
     855           0 :             JavaInfo * pJavaInfo = NULL;
     856           0 :             if (JFW_E_NONE == jfw_getSelectedJRE(&pJavaInfo))
     857             :             {
     858           0 :                 sal_Bool bExist = sal_False;
     859           0 :                 if (JFW_E_NONE == jfw_existJRE(pJavaInfo, &bExist))
     860             :                 {
     861           0 :                     if (bExist == sal_False
     862           0 :                         && ! (pJavaInfo->nRequirements & JFW_REQUIRE_NEEDRESTART))
     863             :                     {
     864           0 :                         javaFrameworkError errFind = jfw_findAndSelectJRE( NULL );
     865           0 :                         if (errFind == JFW_E_NONE)
     866             :                         {
     867           0 :                             continue;
     868             :                         }
     869             :                     }
     870             :                 }
     871             :             }
     872             : 
     873           0 :             jfw_freeJavaInfo(pJavaInfo);
     874             :             //
     875             :             //Error: %PRODUCTNAME requires a Java
     876             :             //runtime environment (JRE) to perform this task. The selected JRE
     877             :             //is defective. Please select another version or install a new JRE
     878             :             //and select it under Tools - Options - %PRODUCTNAME - Java.
     879             :             css::java::JavaVMCreationFailureException exc(
     880             :                 rtl::OUString(
     881             :                     RTL_CONSTASCII_USTRINGPARAM(
     882             :                         "JavaVirtualMachine::getJavaVM failed because"
     883             :                         " Java is defective!")),
     884           0 :                 static_cast< cppu::OWeakObject * >(this), 0);
     885           0 :             askForRetry(css::uno::makeAny(exc));
     886           0 :             return css::uno::Any();
     887             :         }
     888             :         case JFW_E_RUNNING_JVM:
     889             :         {
     890             :             //This service should make sure that we do not start java twice.
     891             :             OSL_ASSERT(0);
     892           0 :             break;
     893             :         }
     894             :         case JFW_E_NEED_RESTART:
     895             :         {
     896             :             //Error:
     897             :             //For the selected Java runtime environment to work properly,
     898             :             //%PRODUCTNAME must be restarted. Please restart %PRODUCTNAME now.
     899             :             css::java::RestartRequiredException exc(
     900             :                 rtl::OUString(
     901             :                     RTL_CONSTASCII_USTRINGPARAM(
     902             :                         "JavaVirtualMachine::getJavaVM failed because"
     903             :                         "Office must be restarted before Java can be used!")),
     904           0 :                 static_cast< cppu::OWeakObject * >(this));
     905           0 :             askForRetry(css::uno::makeAny(exc));
     906           0 :             return css::uno::Any();
     907             :         }
     908             :         default:
     909             :             //RuntimeException: error is somewhere in the java framework.
     910             :             //An unexpected error occurred
     911             :             throw css::uno::RuntimeException(
     912             :                 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
     913             :                                   "[JavaVirtualMachine]:An unexpected error occurred"
     914           0 :                                   " while starting Java!")), 0);
     915             :         }
     916             : 
     917           0 :         if (bStarted)
     918             :         {
     919             :             {
     920           0 :                 DetachCurrentThread detach(m_pJavaVm);
     921             :                     // necessary to make debugging work; this thread will be
     922             :                     // suspended when the destructor of detach returns
     923             :                 m_xVirtualMachine = new jvmaccess::VirtualMachine(
     924           0 :                     m_pJavaVm, JNI_VERSION_1_2, true, pMainThreadEnv);
     925           0 :                 setUpUnoVirtualMachine(pMainThreadEnv);
     926             :             }
     927             :             // Listen for changes in the configuration (e.g. proxy settings):
     928             :             // TODO this is done too late; changes to the configuration done
     929             :             // after the above call to initVMConfiguration are lost
     930           0 :             registerConfigChangesListener();
     931             : 
     932             :             break;
     933             :         }
     934           0 :     }
     935           0 :     if (!m_xUnoVirtualMachine.is()) {
     936             :         try {
     937           0 :             jvmaccess::VirtualMachine::AttachGuard guard(m_xVirtualMachine);
     938           0 :             setUpUnoVirtualMachine(guard.getEnvironment());
     939           0 :         } catch (jvmaccess::VirtualMachine::AttachGuard::CreationException &) {
     940             :             throw css::uno::RuntimeException(
     941             :                 rtl::OUString(
     942             :                     RTL_CONSTASCII_USTRINGPARAM(
     943             :                         "jvmaccess::VirtualMachine::AttachGuard::"
     944             :                         "CreationException occurred")),
     945           0 :                 static_cast< cppu::OWeakObject * >(this));
     946             :         }
     947             :     }
     948           0 :     switch (returnType) {
     949             :     default: // RETURN_JAVAVM
     950           0 :         if (m_pJavaVm == 0) {
     951             :             throw css::uno::RuntimeException(
     952             :                 rtl::OUString(
     953             :                     RTL_CONSTASCII_USTRINGPARAM(
     954             :                         "JavaVirtualMachine service was initialized in a way"
     955             :                         " that the requested JavaVM pointer is not available")),
     956           0 :                 static_cast< cppu::OWeakObject * >(this));
     957             :         }
     958           0 :         return css::uno::makeAny(reinterpret_cast< sal_IntPtr >(m_pJavaVm));
     959             :     case RETURN_VIRTUALMACHINE:
     960             :         OSL_ASSERT(sizeof (sal_Int64) >= sizeof (jvmaccess::VirtualMachine *));
     961             :         return css::uno::makeAny(
     962             :             reinterpret_cast< sal_Int64 >(
     963           0 :                 m_xUnoVirtualMachine->getVirtualMachine().get()));
     964             :     case RETURN_UNOVIRTUALMACHINE:
     965             :         OSL_ASSERT(sizeof (sal_Int64) >= sizeof (jvmaccess::VirtualMachine *));
     966             :         return css::uno::makeAny(
     967           0 :             reinterpret_cast< sal_Int64 >(m_xUnoVirtualMachine.get()));
     968           0 :     }
     969             : }
     970             : 
     971           0 : sal_Bool SAL_CALL JavaVirtualMachine::isVMStarted()
     972             :     throw (css::uno::RuntimeException)
     973             : {
     974           0 :     osl::MutexGuard aGuard(*this);
     975           0 :     if (m_bDisposed)
     976             :         throw css::lang::DisposedException(
     977           0 :             rtl::OUString(), static_cast< cppu::OWeakObject * >(this));
     978           0 :     return m_xUnoVirtualMachine.is();
     979             : }
     980             : 
     981           0 : sal_Bool SAL_CALL JavaVirtualMachine::isVMEnabled()
     982             :     throw (css::uno::RuntimeException)
     983             : {
     984             :     {
     985           0 :         osl::MutexGuard aGuard(*this);
     986           0 :         if (m_bDisposed)
     987             :             throw css::lang::DisposedException(
     988           0 :                 rtl::OUString(), static_cast< cppu::OWeakObject * >(this));
     989             :     }
     990             : //    stoc_javavm::JVM aJvm;
     991             : //    initVMConfiguration(&aJvm, m_xContext->getServiceManager(), m_xContext);
     992             : //    return aJvm.isEnabled();
     993             :     //ToDo
     994           0 :     sal_Bool bEnabled = sal_False;
     995           0 :     if (jfw_getEnabled( & bEnabled) != JFW_E_NONE)
     996           0 :         throw css::uno::RuntimeException();
     997           0 :     return bEnabled;
     998             : }
     999             : 
    1000           0 : sal_Bool SAL_CALL JavaVirtualMachine::isThreadAttached()
    1001             :     throw (css::uno::RuntimeException)
    1002             : {
    1003           0 :     osl::MutexGuard aGuard(*this);
    1004           0 :     if (m_bDisposed)
    1005             :         throw css::lang::DisposedException(
    1006           0 :             rtl::OUString(), static_cast< cppu::OWeakObject * >(this));
    1007             :     // TODO isThreadAttached only returns true if the thread was attached via
    1008             :     // registerThread:
    1009             :     GuardStack * pStack
    1010           0 :         = static_cast< GuardStack * >(m_aAttachGuards.getData());
    1011           0 :     return pStack != 0 && !pStack->empty();
    1012             : }
    1013             : 
    1014           0 : void SAL_CALL JavaVirtualMachine::registerThread()
    1015             :     throw (css::uno::RuntimeException)
    1016             : {
    1017           0 :     osl::MutexGuard aGuard(*this);
    1018           0 :     if (m_bDisposed)
    1019             :         throw css::lang::DisposedException(
    1020           0 :             rtl::OUString(), static_cast< cppu::OWeakObject * >(this));
    1021           0 :     if (!m_xUnoVirtualMachine.is())
    1022             :         throw css::uno::RuntimeException(
    1023             :             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
    1024             :                               "JavaVirtualMachine::registerThread:"
    1025             :                               " null VirtualMachine")),
    1026           0 :             static_cast< cppu::OWeakObject * >(this));
    1027             :     GuardStack * pStack
    1028           0 :         = static_cast< GuardStack * >(m_aAttachGuards.getData());
    1029           0 :     if (pStack == 0)
    1030             :     {
    1031           0 :         pStack = new GuardStack;
    1032           0 :         m_aAttachGuards.setData(pStack);
    1033             :     }
    1034             :     try
    1035             :     {
    1036             :         pStack->push(
    1037             :             new jvmaccess::VirtualMachine::AttachGuard(
    1038           0 :                 m_xUnoVirtualMachine->getVirtualMachine()));
    1039             :     }
    1040           0 :     catch (jvmaccess::VirtualMachine::AttachGuard::CreationException &)
    1041             :     {
    1042             :         throw css::uno::RuntimeException(
    1043             :             rtl::OUString(
    1044             :                 RTL_CONSTASCII_USTRINGPARAM(
    1045             :                     "JavaVirtualMachine::registerThread: jvmaccess::"
    1046             :                     "VirtualMachine::AttachGuard::CreationException")),
    1047           0 :             static_cast< cppu::OWeakObject * >(this));
    1048           0 :     }
    1049           0 : }
    1050             : 
    1051           0 : void SAL_CALL JavaVirtualMachine::revokeThread()
    1052             :     throw (css::uno::RuntimeException)
    1053             : {
    1054           0 :     osl::MutexGuard aGuard(*this);
    1055           0 :     if (m_bDisposed)
    1056             :         throw css::lang::DisposedException(
    1057           0 :             rtl::OUString(), static_cast< cppu::OWeakObject * >(this));
    1058           0 :     if (!m_xUnoVirtualMachine.is())
    1059             :         throw css::uno::RuntimeException(
    1060             :             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
    1061             :                               "JavaVirtualMachine::revokeThread:"
    1062             :                               " null VirtualMachine")),
    1063           0 :             static_cast< cppu::OWeakObject * >(this));
    1064             :     GuardStack * pStack
    1065           0 :         = static_cast< GuardStack * >(m_aAttachGuards.getData());
    1066           0 :     if (pStack == 0 || pStack->empty())
    1067             :         throw css::uno::RuntimeException(
    1068             :             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
    1069             :                               "JavaVirtualMachine::revokeThread:"
    1070             :                               " no matching registerThread")),
    1071           0 :             static_cast< cppu::OWeakObject * >(this));
    1072           0 :     delete pStack->top();
    1073           0 :     pStack->pop();
    1074           0 : }
    1075             : 
    1076             : void SAL_CALL
    1077           0 : JavaVirtualMachine::disposing(css::lang::EventObject const & rSource)
    1078             :     throw (css::uno::RuntimeException)
    1079             : {
    1080           0 :     osl::MutexGuard aGuard(*this);
    1081           0 :     if (rSource.Source == m_xInetConfiguration)
    1082           0 :         m_xInetConfiguration.clear();
    1083           0 :     if (rSource.Source == m_xJavaConfiguration)
    1084           0 :         m_xJavaConfiguration.clear();
    1085           0 : }
    1086             : 
    1087           0 : void SAL_CALL JavaVirtualMachine::elementInserted(
    1088             :     css::container::ContainerEvent const &)
    1089             :     throw (css::uno::RuntimeException)
    1090           0 : {}
    1091             : 
    1092           0 : void SAL_CALL JavaVirtualMachine::elementRemoved(
    1093             :     css::container::ContainerEvent const &)
    1094             :     throw (css::uno::RuntimeException)
    1095           0 : {}
    1096             : 
    1097             : // If a user changes the setting, for example for proxy settings, then this
    1098             : // function will be called from the configuration manager.  Even if the .xml
    1099             : // file does not contain an entry yet and that entry has to be inserted, this
    1100             : // function will be called.  We call java.lang.System.setProperty for the new
    1101             : // values.
    1102           0 : void SAL_CALL JavaVirtualMachine::elementReplaced(
    1103             :     css::container::ContainerEvent const & rEvent)
    1104             :     throw (css::uno::RuntimeException)
    1105             : {
    1106             :     // TODO Using the new value stored in rEvent is wrong here.  If two threads
    1107             :     // receive different elementReplaced calls in quick succession, it is
    1108             :     // unspecified which changes the JVM's system properties last.  A correct
    1109             :     // solution must atomically (i.e., protected by a mutex) read the latest
    1110             :     // value from the configuration and set it as a system property at the JVM.
    1111             : 
    1112           0 :     rtl::OUString aAccessor;
    1113           0 :     rEvent.Accessor >>= aAccessor;
    1114           0 :     rtl::OUString aPropertyName;
    1115           0 :     rtl::OUString aPropertyName2;
    1116           0 :     rtl::OUString aPropertyValue;
    1117           0 :     bool bSecurityChanged = false;
    1118           0 :     if ( aAccessor == "ooInetProxyType" )
    1119             :     {
    1120             :         // Proxy none, manually
    1121           0 :         sal_Int32 value = 0;
    1122           0 :         rEvent.Element >>= value;
    1123           0 :         setINetSettingsInVM(value != 0);
    1124             :         return;
    1125             :     }
    1126           0 :     else if ( aAccessor == "ooInetHTTPProxyName" )
    1127             :     {
    1128             :         aPropertyName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
    1129           0 :                                           "http.proxyHost"));
    1130           0 :         rEvent.Element >>= aPropertyValue;
    1131             :     }
    1132           0 :     else if ( aAccessor == "ooInetHTTPProxyPort" )
    1133             :     {
    1134             :         aPropertyName
    1135           0 :             = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("http.proxyPort"));
    1136           0 :         sal_Int32 n = 0;
    1137           0 :         rEvent.Element >>= n;
    1138           0 :         aPropertyValue = rtl::OUString::valueOf(n);
    1139             :     }
    1140           0 :     else if ( aAccessor == "ooInetHTTPSProxyName" )
    1141             :     {
    1142             :         aPropertyName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
    1143           0 :                                           "https.proxyHost"));
    1144           0 :         rEvent.Element >>= aPropertyValue;
    1145             :     }
    1146           0 :     else if ( aAccessor == "ooInetHTTPSProxyPort" )
    1147             :     {
    1148             :         aPropertyName
    1149           0 :             = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("https.proxyPort"));
    1150           0 :         sal_Int32 n = 0;
    1151           0 :         rEvent.Element >>= n;
    1152           0 :         aPropertyValue = rtl::OUString::valueOf(n);
    1153             :     }
    1154           0 :     else if ( aAccessor == "ooInetFTPProxyName" )
    1155             :     {
    1156             :         aPropertyName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
    1157           0 :                                           "ftp.proxyHost"));
    1158           0 :         rEvent.Element >>= aPropertyValue;
    1159             :     }
    1160           0 :     else if ( aAccessor == "ooInetFTPProxyPort" )
    1161             :     {
    1162             :         aPropertyName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
    1163           0 :                                           "ftp.proxyPort"));
    1164           0 :         sal_Int32 n = 0;
    1165           0 :         rEvent.Element >>= n;
    1166           0 :         aPropertyValue = rtl::OUString::valueOf(n);
    1167             :     }
    1168           0 :     else if ( aAccessor == "ooInetNoProxy" )
    1169             :     {
    1170             :         aPropertyName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
    1171           0 :                                           "http.nonProxyHosts"));
    1172             :         aPropertyName2 = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
    1173           0 :                                            "ftp.nonProxyHosts"));
    1174           0 :         rEvent.Element >>= aPropertyValue;
    1175           0 :         aPropertyValue = aPropertyValue.replace(';', '|');
    1176             :     }
    1177           0 :     else if ( aAccessor == "NetAccess" )
    1178             :     {
    1179             :         aPropertyName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
    1180           0 :                                           "appletviewer.security.mode"));
    1181           0 :         sal_Int32 n = 0;
    1182           0 :         if (rEvent.Element >>= n)
    1183           0 :             switch (n)
    1184             :             {
    1185             :             case 0:
    1186             :                 aPropertyValue = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
    1187           0 :                                                    "host"));
    1188           0 :                 break;
    1189             :             case 1:
    1190             :                 aPropertyValue = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
    1191           0 :                                                    "unrestricted"));
    1192           0 :                 break;
    1193             :             case 3:
    1194             :                 aPropertyValue = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
    1195           0 :                                                    "none"));
    1196           0 :                 break;
    1197             :             }
    1198             :         else
    1199             :             return;
    1200           0 :         bSecurityChanged = true;
    1201             :     }
    1202           0 :     else if ( aAccessor == "Security" )
    1203             :     {
    1204             :         aPropertyName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
    1205           0 :                                           "stardiv.security.disableSecurity"));
    1206           0 :         sal_Bool b = sal_Bool();
    1207           0 :         if (rEvent.Element >>= b)
    1208           0 :             if (b)
    1209             :                 aPropertyValue = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
    1210           0 :                                                    "false"));
    1211             :             else
    1212             :                 aPropertyValue = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
    1213           0 :                                                    "true"));
    1214             :         else
    1215             :             return;
    1216           0 :         bSecurityChanged = true;
    1217             :     }
    1218             :     else
    1219             :         return;
    1220             : 
    1221           0 :     rtl::Reference< jvmaccess::VirtualMachine > xVirtualMachine;
    1222             :     {
    1223           0 :         osl::MutexGuard aGuard(*this);
    1224           0 :         if (m_xUnoVirtualMachine.is()) {
    1225           0 :             xVirtualMachine = m_xUnoVirtualMachine->getVirtualMachine();
    1226           0 :         }
    1227             :     }
    1228           0 :     if (xVirtualMachine.is())
    1229             :     {
    1230             :         try
    1231             :         {
    1232             :             jvmaccess::VirtualMachine::AttachGuard aAttachGuard(
    1233           0 :                 xVirtualMachine);
    1234           0 :             JNIEnv * pJNIEnv = aAttachGuard.getEnvironment();
    1235             : 
    1236             :             // call java.lang.System.setProperty
    1237             :             // String setProperty( String key, String value)
    1238           0 :             jclass jcSystem= pJNIEnv->FindClass("java/lang/System");
    1239           0 :             if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:FindClass java/lang/System")), 0);
    1240           0 :             jmethodID jmSetProps= pJNIEnv->GetStaticMethodID( jcSystem, "setProperty","(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;");
    1241           0 :             if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:GetStaticMethodID java.lang.System.setProperty")), 0);
    1242             : 
    1243           0 :             jstring jsPropName= pJNIEnv->NewString( aPropertyName.getStr(), aPropertyName.getLength());
    1244           0 :             if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:NewString")), 0);
    1245             : 
    1246             :             // remove the property if it does not have a value ( user left the dialog field empty)
    1247             :             // or if the port is set to 0
    1248           0 :             aPropertyValue= aPropertyValue.trim();
    1249           0 :             if( aPropertyValue.isEmpty() ||
    1250           0 :                ( ( aPropertyName == "ftp.proxyPort" || aPropertyName == "http.proxyPort" /*|| aPropertyName == "socksProxyPort"*/ ) && aPropertyValue == "0" )
    1251             :               )
    1252             :             {
    1253             :                 // call java.lang.System.getProperties
    1254           0 :                 jmethodID jmGetProps= pJNIEnv->GetStaticMethodID( jcSystem, "getProperties","()Ljava/util/Properties;");
    1255           0 :                 if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:GetStaticMethodID java.lang.System.getProperties")), 0);
    1256           0 :                 jobject joProperties= pJNIEnv->CallStaticObjectMethod( jcSystem, jmGetProps);
    1257           0 :                 if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:CallStaticObjectMethod java.lang.System.getProperties")), 0);
    1258             :                 // call java.util.Properties.remove
    1259           0 :                 jclass jcProperties= pJNIEnv->FindClass("java/util/Properties");
    1260           0 :                 if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:FindClass java/util/Properties")), 0);
    1261           0 :                 jmethodID jmRemove= pJNIEnv->GetMethodID( jcProperties, "remove", "(Ljava/lang/Object;)Ljava/lang/Object;");
    1262           0 :                 if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:GetMethodID java.util.Properties.remove")), 0);
    1263           0 :                 pJNIEnv->CallObjectMethod( joProperties, jmRemove, jsPropName);
    1264             : 
    1265             :                 // special calse for ftp.nonProxyHosts and http.nonProxyHosts. The office only
    1266             :                 // has a value for two java properties
    1267           0 :                 if (!aPropertyName2.isEmpty())
    1268             :                 {
    1269           0 :                     jstring jsPropName2= pJNIEnv->NewString( aPropertyName2.getStr(), aPropertyName2.getLength());
    1270           0 :                     if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:NewString")), 0);
    1271           0 :                     pJNIEnv->CallObjectMethod( joProperties, jmRemove, jsPropName2);
    1272             :                 }
    1273             :             }
    1274             :             else
    1275             :             {
    1276             :                 // Change the Value of the property
    1277           0 :                 jstring jsPropValue= pJNIEnv->NewString( aPropertyValue.getStr(), aPropertyValue.getLength());
    1278           0 :                 if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:NewString")), 0);
    1279           0 :                 pJNIEnv->CallStaticObjectMethod( jcSystem, jmSetProps, jsPropName, jsPropValue);
    1280           0 :                 if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:CallStaticObjectMethod java.lang.System.setProperty")), 0);
    1281             : 
    1282             :                 // special calse for ftp.nonProxyHosts and http.nonProxyHosts. The office only
    1283             :                 // has a value for two java properties
    1284           0 :                 if (!aPropertyName2.isEmpty())
    1285             :                 {
    1286           0 :                     jstring jsPropName2= pJNIEnv->NewString( aPropertyName2.getStr(), aPropertyName2.getLength());
    1287           0 :                     if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:NewString")), 0);
    1288           0 :                     jsPropValue= pJNIEnv->NewString( aPropertyValue.getStr(), aPropertyValue.getLength());
    1289           0 :                     if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:NewString")), 0);
    1290           0 :                     pJNIEnv->CallStaticObjectMethod( jcSystem, jmSetProps, jsPropName2, jsPropValue);
    1291           0 :                     if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:CallStaticObjectMethod java.lang.System.setProperty")), 0);
    1292             :                 }
    1293             :             }
    1294             : 
    1295             :             // If the settings for Security and NetAccess changed then we have to notify the SandboxSecurity
    1296             :             // SecurityManager
    1297             :             // call System.getSecurityManager()
    1298           0 :             if (bSecurityChanged)
    1299             :             {
    1300           0 :                 jmethodID jmGetSecur= pJNIEnv->GetStaticMethodID( jcSystem,"getSecurityManager","()Ljava/lang/SecurityManager;");
    1301           0 :                 if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:GetStaticMethodID java.lang.System.getSecurityManager")), 0);
    1302           0 :                 jobject joSecur= pJNIEnv->CallStaticObjectMethod( jcSystem, jmGetSecur);
    1303           0 :                 if (joSecur != 0)
    1304             :                 {
    1305             :                     // Make sure the SecurityManager is our SandboxSecurity
    1306             :                     // FindClass("com.sun.star.lib.sandbox.SandboxSecurityManager" only worked at the first time
    1307             :                     // this code was executed. Maybe it is a security feature. However, all attempts to debug the
    1308             :                     // SandboxSecurity class (maybe the VM invokes checkPackageAccess)  failed.
    1309             : //                  jclass jcSandboxSec= pJNIEnv->FindClass("com.sun.star.lib.sandbox.SandboxSecurity");
    1310             : //                  if(pJNIEnv->ExceptionOccurred()) throw RuntimeException(OUSTR("JNI:FindClass com.sun.star.lib.sandbox.SandboxSecurity"), Reference<XInterface>());
    1311             : //                  jboolean bIsSand= pJNIEnv->IsInstanceOf( joSecur, jcSandboxSec);
    1312             :                     // The SecurityManagers class Name must be com.sun.star.lib.sandbox.SandboxSecurity
    1313           0 :                     jclass jcSec= pJNIEnv->GetObjectClass( joSecur);
    1314           0 :                     jclass jcClass= pJNIEnv->FindClass("java/lang/Class");
    1315           0 :                     if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:FindClass java.lang.Class")), 0);
    1316           0 :                     jmethodID jmName= pJNIEnv->GetMethodID( jcClass,"getName","()Ljava/lang/String;");
    1317           0 :                     if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:GetMethodID java.lang.Class.getName")), 0);
    1318           0 :                     jstring jsClass= (jstring) pJNIEnv->CallObjectMethod( jcSec, jmName);
    1319           0 :                     const jchar* jcharName= pJNIEnv->GetStringChars( jsClass, NULL);
    1320           0 :                     rtl::OUString sName( jcharName);
    1321             :                     jboolean bIsSandbox;
    1322           0 :                     if ( sName == "com.sun.star.lib.sandbox.SandboxSecurity" )
    1323           0 :                         bIsSandbox= JNI_TRUE;
    1324             :                     else
    1325           0 :                         bIsSandbox= JNI_FALSE;
    1326           0 :                     pJNIEnv->ReleaseStringChars( jsClass, jcharName);
    1327             : 
    1328           0 :                     if (bIsSandbox == JNI_TRUE)
    1329             :                     {
    1330             :                         // call SandboxSecurity.reset
    1331           0 :                         jmethodID jmReset= pJNIEnv->GetMethodID( jcSec,"reset","()V");
    1332           0 :                         if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:GetMethodID com.sun.star.lib.sandbox.SandboxSecurity.reset")), 0);
    1333           0 :                         pJNIEnv->CallVoidMethod( joSecur, jmReset);
    1334           0 :                         if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:CallVoidMethod com.sun.star.lib.sandbox.SandboxSecurity.reset")), 0);
    1335           0 :                     }
    1336             :                 }
    1337           0 :             }
    1338             :         }
    1339           0 :         catch (jvmaccess::VirtualMachine::AttachGuard::CreationException &)
    1340             :         {
    1341             :             throw css::uno::RuntimeException(
    1342             :                 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
    1343             :                                   "jvmaccess::VirtualMachine::AttachGuard::"
    1344             :                                   "CreationException")),
    1345           0 :                 0);
    1346             :         }
    1347           0 :     }
    1348             : }
    1349             : 
    1350           0 : JavaVirtualMachine::~JavaVirtualMachine()
    1351             : {
    1352           0 :     if (m_xInetConfiguration.is())
    1353             :         // We should never get here, but just in case...
    1354             :         try
    1355             :         {
    1356           0 :             m_xInetConfiguration->removeContainerListener(this);
    1357             :         }
    1358           0 :         catch (css::uno::Exception &)
    1359             :         {
    1360             :             OSL_FAIL("com.sun.star.uno.Exception caught");
    1361             :         }
    1362           0 :     if (m_xJavaConfiguration.is())
    1363             :         // We should never get here, but just in case...
    1364             :         try
    1365             :         {
    1366           0 :             m_xJavaConfiguration->removeContainerListener(this);
    1367             :         }
    1368           0 :         catch (css::uno::Exception &)
    1369             :         {
    1370             :             OSL_FAIL("com.sun.star.uno.Exception caught");
    1371             :         }
    1372           0 : }
    1373             : 
    1374           0 : void SAL_CALL JavaVirtualMachine::disposing()
    1375             : {
    1376           0 :     css::uno::Reference< css::container::XContainer > xContainer1;
    1377           0 :     css::uno::Reference< css::container::XContainer > xContainer2;
    1378             :     {
    1379           0 :         osl::MutexGuard aGuard(*this);
    1380           0 :         m_bDisposed = true;
    1381           0 :         xContainer1 = m_xInetConfiguration;
    1382           0 :         m_xInetConfiguration.clear();
    1383           0 :         xContainer2 = m_xJavaConfiguration;
    1384           0 :         m_xJavaConfiguration.clear();
    1385             :     }
    1386           0 :     if (xContainer1.is())
    1387           0 :         xContainer1->removeContainerListener(this);
    1388           0 :     if (xContainer2.is())
    1389           0 :         xContainer2->removeContainerListener(this);
    1390           0 : }
    1391             : 
    1392             : /*We listen to changes in the configuration. For example, the user changes the proxy
    1393             :   settings in the options dialog (menu tools). Then we are notified of this change and
    1394             :   if the java vm is already running we change the properties (System.lang.System.setProperties)
    1395             :   through JNI.
    1396             :   To receive notifications this class implements XContainerListener.
    1397             : */
    1398           0 : void JavaVirtualMachine::registerConfigChangesListener()
    1399             : {
    1400             :     try
    1401             :     {
    1402             :         css::uno::Reference< css::lang::XMultiServiceFactory > xConfigProvider(
    1403           0 :             m_xContext->getServiceManager()->createInstanceWithContext( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
    1404           0 :                 "com.sun.star.configuration.ConfigurationProvider")), m_xContext), css::uno::UNO_QUERY);
    1405             : 
    1406           0 :         if (xConfigProvider.is())
    1407             :         {
    1408             :             // We register this instance as listener to changes in org.openoffice.Inet/Settings
    1409             :             // arguments for ConfigurationAccess
    1410           0 :             css::uno::Sequence< css::uno::Any > aArguments(2);
    1411           0 :             aArguments[0] <<= css::beans::PropertyValue(
    1412             :                 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("nodepath")),
    1413             :                 0,
    1414             :                 css::uno::makeAny(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Inet/Settings"))),
    1415           0 :                 css::beans::PropertyState_DIRECT_VALUE);
    1416             :             // depth: -1 means unlimited
    1417           0 :             aArguments[1] <<= css::beans::PropertyValue(
    1418             :                 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("depth")),
    1419             :                 0,
    1420             :                 css::uno::makeAny( (sal_Int32)-1),
    1421           0 :                 css::beans::PropertyState_DIRECT_VALUE);
    1422             : 
    1423             :             m_xInetConfiguration
    1424             :                 = css::uno::Reference< css::container::XContainer >(
    1425           0 :                     xConfigProvider->createInstanceWithArguments(
    1426             :                         rtl::OUString(
    1427             :                             RTL_CONSTASCII_USTRINGPARAM(
    1428             :                              "com.sun.star.configuration.ConfigurationAccess")),
    1429           0 :                         aArguments),
    1430           0 :                     css::uno::UNO_QUERY);
    1431             : 
    1432           0 :             if (m_xInetConfiguration.is())
    1433           0 :                 m_xInetConfiguration->addContainerListener(this);
    1434             : 
    1435             :             // now register as listener to changes in org.openoffice.Java/VirtualMachine
    1436           0 :             css::uno::Sequence< css::uno::Any > aArguments2(2);
    1437           0 :             aArguments2[0] <<= css::beans::PropertyValue(
    1438             :                 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("nodepath")),
    1439             :                 0,
    1440             :                 css::uno::makeAny(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Office.Java/VirtualMachine"))),
    1441           0 :                 css::beans::PropertyState_DIRECT_VALUE);
    1442             :             // depth: -1 means unlimited
    1443           0 :             aArguments2[1] <<= css::beans::PropertyValue(
    1444             :                 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("depth")),
    1445             :                 0,
    1446             :                 css::uno::makeAny( (sal_Int32)-1),
    1447           0 :                 css::beans::PropertyState_DIRECT_VALUE);
    1448             : 
    1449             :             m_xJavaConfiguration
    1450             :                 = css::uno::Reference< css::container::XContainer >(
    1451           0 :                     xConfigProvider->createInstanceWithArguments(
    1452             :                         rtl::OUString(
    1453             :                             RTL_CONSTASCII_USTRINGPARAM(
    1454             :                              "com.sun.star.configuration.ConfigurationAccess")),
    1455           0 :                         aArguments2),
    1456           0 :                     css::uno::UNO_QUERY);
    1457             : 
    1458           0 :             if (m_xJavaConfiguration.is())
    1459           0 :                 m_xJavaConfiguration->addContainerListener(this);
    1460           0 :         }
    1461           0 :     }catch(const css::uno::Exception & e)
    1462             :     {
    1463             : #if OSL_DEBUG_LEVEL > 1
    1464             :         rtl::OString message = rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US);
    1465             :         OSL_TRACE("javavm.cxx: could not set up listener for Configuration because of >%s<", message.getStr());
    1466             : #else
    1467             :         (void) e; // unused
    1468             : #endif
    1469             :     }
    1470           0 : }
    1471             : 
    1472             : // param true: all Inet setting are set as Java Properties on a live VM.
    1473             : // false: the Java net properties are set to empty value.
    1474           0 : void JavaVirtualMachine::setINetSettingsInVM(bool set_reset)
    1475             : {
    1476           0 :     osl::MutexGuard aGuard(*this);
    1477             :     try
    1478             :     {
    1479           0 :         if (m_xUnoVirtualMachine.is())
    1480             :         {
    1481             :             jvmaccess::VirtualMachine::AttachGuard aAttachGuard(
    1482           0 :                 m_xUnoVirtualMachine->getVirtualMachine());
    1483           0 :             JNIEnv * pJNIEnv = aAttachGuard.getEnvironment();
    1484             : 
    1485             :             // The Java Properties
    1486           0 :             rtl::OUString sFtpProxyHost(RTL_CONSTASCII_USTRINGPARAM("ftp.proxyHost") );
    1487           0 :             rtl::OUString sFtpProxyPort(RTL_CONSTASCII_USTRINGPARAM("ftp.proxyPort") );
    1488           0 :             rtl::OUString sFtpNonProxyHosts (RTL_CONSTASCII_USTRINGPARAM("ftp.nonProxyHosts"));
    1489           0 :             rtl::OUString sHttpProxyHost(RTL_CONSTASCII_USTRINGPARAM("http.proxyHost") );
    1490           0 :             rtl::OUString sHttpProxyPort(RTL_CONSTASCII_USTRINGPARAM("http.proxyPort") );
    1491           0 :             rtl::OUString sHttpNonProxyHosts(RTL_CONSTASCII_USTRINGPARAM("http.nonProxyHosts"));
    1492             : 
    1493             :             // creat Java Properties as JNI strings
    1494           0 :             jstring jsFtpProxyHost= pJNIEnv->NewString( sFtpProxyHost.getStr(), sFtpProxyHost.getLength());
    1495           0 :             if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:NewString")), 0);
    1496           0 :             jstring jsFtpProxyPort= pJNIEnv->NewString( sFtpProxyPort.getStr(), sFtpProxyPort.getLength());
    1497           0 :             if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:NewString")), 0);
    1498           0 :             jstring jsFtpNonProxyHosts= pJNIEnv->NewString( sFtpNonProxyHosts.getStr(), sFtpNonProxyHosts.getLength());
    1499           0 :             if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:NewString")), 0);
    1500           0 :             jstring jsHttpProxyHost= pJNIEnv->NewString( sHttpProxyHost.getStr(), sHttpProxyHost.getLength());
    1501           0 :             if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:NewString")), 0);
    1502           0 :             jstring jsHttpProxyPort= pJNIEnv->NewString( sHttpProxyPort.getStr(), sHttpProxyPort.getLength());
    1503           0 :             if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:NewString")), 0);
    1504           0 :             jstring jsHttpNonProxyHosts= pJNIEnv->NewString( sHttpNonProxyHosts.getStr(), sHttpNonProxyHosts.getLength());
    1505           0 :             if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:NewString")), 0);
    1506             : 
    1507             :             // prepare java.lang.System.setProperty
    1508           0 :             jclass jcSystem= pJNIEnv->FindClass("java/lang/System");
    1509           0 :             if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:FindClass java/lang/System")), 0);
    1510           0 :             jmethodID jmSetProps= pJNIEnv->GetStaticMethodID( jcSystem, "setProperty","(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;");
    1511           0 :             if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:GetStaticMethodID java.lang.System.setProperty")), 0);
    1512             : 
    1513             :             // call java.lang.System.getProperties
    1514           0 :             jmethodID jmGetProps= pJNIEnv->GetStaticMethodID( jcSystem, "getProperties","()Ljava/util/Properties;");
    1515           0 :             if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:GetStaticMethodID java.lang.System.getProperties")), 0);
    1516           0 :             jobject joProperties= pJNIEnv->CallStaticObjectMethod( jcSystem, jmGetProps);
    1517           0 :             if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:CallStaticObjectMethod java.lang.System.getProperties")), 0);
    1518             :             // prepare java.util.Properties.remove
    1519           0 :             jclass jcProperties= pJNIEnv->FindClass("java/util/Properties");
    1520           0 :             if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:FindClass java/util/Properties")), 0);
    1521             : 
    1522           0 :             if (set_reset)
    1523             :             {
    1524             :                 // Set all network properties with the VM
    1525           0 :                 JVM jvm;
    1526           0 :                 getINetPropsFromConfig( &jvm, m_xContext->getServiceManager(), m_xContext);
    1527           0 :                 const ::std::vector< rtl::OUString> & Props = jvm.getProperties();
    1528             :                 typedef ::std::vector< rtl::OUString >::const_iterator C_IT;
    1529             : 
    1530           0 :                 for( C_IT i= Props.begin(); i != Props.end(); ++i)
    1531             :                 {
    1532           0 :                     rtl::OUString prop= *i;
    1533           0 :                     sal_Int32 index= prop.indexOf( (sal_Unicode)'=');
    1534           0 :                     rtl::OUString propName= prop.copy( 0, index);
    1535           0 :                     rtl::OUString propValue= prop.copy( index + 1);
    1536             : 
    1537           0 :                     if( propName.equals( sFtpProxyHost))
    1538             :                     {
    1539           0 :                         jstring jsVal= pJNIEnv->NewString( propValue.getStr(), propValue.getLength());
    1540           0 :                         if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:NewString")), 0);
    1541           0 :                         pJNIEnv->CallStaticObjectMethod( jcSystem, jmSetProps, jsFtpProxyHost, jsVal);
    1542           0 :                         if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:CallStaticObjectMethod java.lang.System.setProperty")), 0);
    1543             :                     }
    1544           0 :                     else if( propName.equals( sFtpProxyPort))
    1545             :                     {
    1546           0 :                         jstring jsVal= pJNIEnv->NewString( propValue.getStr(), propValue.getLength());
    1547           0 :                         if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:NewString")), 0);
    1548           0 :                         pJNIEnv->CallStaticObjectMethod( jcSystem, jmSetProps, jsFtpProxyPort, jsVal);
    1549           0 :                         if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:CallStaticObjectMethod java.lang.System.setProperty")), 0);
    1550             :                     }
    1551           0 :                     else if( propName.equals( sFtpNonProxyHosts))
    1552             :                     {
    1553           0 :                         jstring jsVal= pJNIEnv->NewString( propValue.getStr(), propValue.getLength());
    1554           0 :                         if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:NewString")), 0);
    1555           0 :                         pJNIEnv->CallStaticObjectMethod( jcSystem, jmSetProps, jsFtpNonProxyHosts, jsVal);
    1556           0 :                         if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:CallStaticObjectMethod java.lang.System.setProperty")), 0);
    1557             :                     }
    1558           0 :                     else if( propName.equals( sHttpProxyHost))
    1559             :                     {
    1560           0 :                         jstring jsVal= pJNIEnv->NewString( propValue.getStr(), propValue.getLength());
    1561           0 :                         if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:NewString")), 0);
    1562           0 :                         pJNIEnv->CallStaticObjectMethod( jcSystem, jmSetProps, jsHttpProxyHost, jsVal);
    1563           0 :                         if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:CallStaticObjectMethod java.lang.System.setProperty")), 0);
    1564             :                     }
    1565           0 :                     else if( propName.equals( sHttpProxyPort))
    1566             :                     {
    1567           0 :                         jstring jsVal= pJNIEnv->NewString( propValue.getStr(), propValue.getLength());
    1568           0 :                         if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:NewString")), 0);
    1569           0 :                         pJNIEnv->CallStaticObjectMethod( jcSystem, jmSetProps, jsHttpProxyPort, jsVal);
    1570           0 :                         if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:CallStaticObjectMethod java.lang.System.setProperty")), 0);
    1571             :                     }
    1572           0 :                     else if( propName.equals( sHttpNonProxyHosts))
    1573             :                     {
    1574           0 :                         jstring jsVal= pJNIEnv->NewString( propValue.getStr(), propValue.getLength());
    1575           0 :                         if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:NewString")), 0);
    1576           0 :                         pJNIEnv->CallStaticObjectMethod( jcSystem, jmSetProps, jsHttpNonProxyHosts, jsVal);
    1577           0 :                         if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:CallStaticObjectMethod java.lang.System.setProperty")), 0);
    1578             :                     }
    1579           0 :                 }
    1580             :             }
    1581             :             else
    1582             :             {
    1583             :                 // call java.util.Properties.remove
    1584           0 :                 jmethodID jmRemove= pJNIEnv->GetMethodID( jcProperties, "remove", "(Ljava/lang/Object;)Ljava/lang/Object;");
    1585           0 :                 if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:GetMethodID java.util.Property.remove")), 0);
    1586           0 :                 pJNIEnv->CallObjectMethod( joProperties, jmRemove, jsFtpProxyHost);
    1587           0 :                 pJNIEnv->CallObjectMethod( joProperties, jmRemove, jsFtpProxyPort);
    1588           0 :                 pJNIEnv->CallObjectMethod( joProperties, jmRemove, jsFtpNonProxyHosts);
    1589           0 :                 pJNIEnv->CallObjectMethod( joProperties, jmRemove, jsHttpProxyHost);
    1590           0 :                 pJNIEnv->CallObjectMethod( joProperties, jmRemove, jsHttpProxyPort);
    1591           0 :                 pJNIEnv->CallObjectMethod( joProperties, jmRemove, jsHttpNonProxyHosts);
    1592           0 :             }
    1593             :         }
    1594             :     }
    1595           0 :     catch (css::uno::RuntimeException &)
    1596             :     {
    1597             :         OSL_FAIL("RuntimeException");
    1598             :     }
    1599           0 :     catch (jvmaccess::VirtualMachine::AttachGuard::CreationException &)
    1600             :     {
    1601             :         OSL_FAIL("jvmaccess::VirtualMachine::AttachGuard::CreationException");
    1602           0 :     }
    1603           0 : }
    1604             : 
    1605           0 : void JavaVirtualMachine::setUpUnoVirtualMachine(JNIEnv * environment) {
    1606           0 :     css::uno::Reference< css::util::XMacroExpander > exp;
    1607           0 :     if (!(m_xContext->getValueByName(
    1608             :               rtl::OUString(
    1609             :                   RTL_CONSTASCII_USTRINGPARAM(
    1610           0 :                       "/singletons/com.sun.star.util.theMacroExpander")))
    1611           0 :           >>= exp)
    1612           0 :         || !exp.is())
    1613             :     {
    1614             :         throw css::uno::RuntimeException(
    1615             :             rtl::OUString(
    1616             :                 RTL_CONSTASCII_USTRINGPARAM(
    1617             :                     "component context fails to supply singleton"
    1618             :                     " com.sun.star.util.theMacroExpander of type"
    1619             :                     " com.sun.star.util.XMacroExpander")),
    1620           0 :             m_xContext);
    1621             :     }
    1622           0 :     rtl::OUString baseUrl;
    1623             :     try {
    1624           0 :         baseUrl = exp->expandMacros(
    1625             :             rtl::OUString(
    1626           0 :                 RTL_CONSTASCII_USTRINGPARAM("$URE_INTERNAL_JAVA_DIR/")));
    1627           0 :     } catch (css::lang::IllegalArgumentException &) {
    1628             :         throw css::uno::RuntimeException(
    1629             :             rtl::OUString(
    1630             :                 RTL_CONSTASCII_USTRINGPARAM(
    1631             :                     "com::sun::star::lang::IllegalArgumentException")),
    1632           0 :             static_cast< cppu::OWeakObject * >(this));
    1633             :     }
    1634           0 :     rtl::OUString classPath;
    1635             :     try {
    1636           0 :         classPath = exp->expandMacros(
    1637             :             rtl::OUString(
    1638           0 :                 RTL_CONSTASCII_USTRINGPARAM("$URE_INTERNAL_JAVA_CLASSPATH")));
    1639           0 :     } catch (css::lang::IllegalArgumentException &) {}
    1640             :     jclass class_URLClassLoader = environment->FindClass(
    1641           0 :         "java/net/URLClassLoader");
    1642           0 :     if (class_URLClassLoader == 0) {
    1643           0 :         handleJniException(environment);
    1644             :     }
    1645             :     jmethodID ctor_URLClassLoader = environment->GetMethodID(
    1646           0 :         class_URLClassLoader, "<init>", "([Ljava/net/URL;)V");
    1647           0 :     if (ctor_URLClassLoader == 0) {
    1648           0 :         handleJniException(environment);
    1649             :     }
    1650           0 :     jclass class_URL = environment->FindClass("java/net/URL");
    1651           0 :     if (class_URL == 0) {
    1652           0 :         handleJniException(environment);
    1653             :     }
    1654             :     jmethodID ctor_URL_1 = environment->GetMethodID(
    1655           0 :         class_URL, "<init>", "(Ljava/lang/String;)V");
    1656           0 :     if (ctor_URL_1 == 0) {
    1657           0 :         handleJniException(environment);
    1658             :     }
    1659             :     jvalue args[3];
    1660             :     args[0].l = environment->NewString(
    1661             :         static_cast< jchar const * >(baseUrl.getStr()),
    1662           0 :         static_cast< jsize >(baseUrl.getLength()));
    1663           0 :     if (args[0].l == 0) {
    1664           0 :         handleJniException(environment);
    1665             :     }
    1666           0 :     jobject base = environment->NewObjectA(class_URL, ctor_URL_1, args);
    1667           0 :     if (base == 0) {
    1668           0 :         handleJniException(environment);
    1669             :     }
    1670             :     jmethodID ctor_URL_2 = environment->GetMethodID(
    1671           0 :         class_URL, "<init>", "(Ljava/net/URL;Ljava/lang/String;)V");
    1672           0 :     if (ctor_URL_2 == 0) {
    1673           0 :         handleJniException(environment);
    1674             :     }
    1675             :     jobjectArray classpath = jvmaccess::ClassPath::translateToUrls(
    1676           0 :         m_xContext, environment, classPath);
    1677           0 :     if (classpath == 0) {
    1678           0 :         handleJniException(environment);
    1679             :     }
    1680           0 :     args[0].l = base;
    1681           0 :     args[1].l = environment->NewStringUTF("unoloader.jar");
    1682           0 :     if (args[1].l == 0) {
    1683           0 :         handleJniException(environment);
    1684             :     }
    1685           0 :     args[0].l = environment->NewObjectA(class_URL, ctor_URL_2, args);
    1686           0 :     if (args[0].l == 0) {
    1687           0 :         handleJniException(environment);
    1688             :     }
    1689           0 :     args[0].l = environment->NewObjectArray(1, class_URL, args[0].l);
    1690           0 :     if (args[0].l == 0) {
    1691           0 :         handleJniException(environment);
    1692             :     }
    1693             :     jobject cl1 = environment->NewObjectA(
    1694           0 :         class_URLClassLoader, ctor_URLClassLoader, args);
    1695           0 :     if (cl1 == 0) {
    1696           0 :         handleJniException(environment);
    1697             :     }
    1698             :     jmethodID method_loadClass = environment->GetMethodID(
    1699             :         class_URLClassLoader, "loadClass",
    1700           0 :         "(Ljava/lang/String;)Ljava/lang/Class;");
    1701           0 :     if (method_loadClass == 0) {
    1702           0 :         handleJniException(environment);
    1703             :     }
    1704             :     args[0].l = environment->NewStringUTF(
    1705           0 :         "com.sun.star.lib.unoloader.UnoClassLoader");
    1706           0 :     if (args[0].l == 0) {
    1707           0 :         handleJniException(environment);
    1708             :     }
    1709             :     jclass class_UnoClassLoader = static_cast< jclass >(
    1710           0 :         environment->CallObjectMethodA(cl1, method_loadClass, args));
    1711           0 :     if (class_UnoClassLoader == 0) {
    1712           0 :         handleJniException(environment);
    1713             :     }
    1714             :     jmethodID ctor_UnoClassLoader = environment->GetMethodID(
    1715             :         class_UnoClassLoader, "<init>",
    1716           0 :         "(Ljava/net/URL;[Ljava/net/URL;Ljava/lang/ClassLoader;)V");
    1717           0 :     if (ctor_UnoClassLoader == 0) {
    1718           0 :         handleJniException(environment);
    1719             :     }
    1720           0 :     args[0].l = base;
    1721           0 :     args[1].l = classpath;
    1722           0 :     args[2].l = cl1;
    1723             :     jobject cl2 = environment->NewObjectA(
    1724           0 :         class_UnoClassLoader, ctor_UnoClassLoader, args);
    1725           0 :     if (cl2 == 0) {
    1726           0 :         handleJniException(environment);
    1727             :     }
    1728             :     try {
    1729             :         m_xUnoVirtualMachine = new jvmaccess::UnoVirtualMachine(
    1730           0 :             m_xVirtualMachine, cl2);
    1731           0 :     } catch (jvmaccess::UnoVirtualMachine::CreationException &) {
    1732             :         throw css::uno::RuntimeException(
    1733             :             rtl::OUString(
    1734             :                 RTL_CONSTASCII_USTRINGPARAM(
    1735             :                     "jvmaccess::UnoVirtualMachine::CreationException")),
    1736           0 :             static_cast< cppu::OWeakObject * >(this));
    1737           0 :     }
    1738           0 : }
    1739             : 
    1740           0 : void JavaVirtualMachine::handleJniException(JNIEnv * environment) {
    1741           0 :     environment->ExceptionClear();
    1742             :     throw css::uno::RuntimeException(
    1743             :         rtl::OUString(
    1744             :             RTL_CONSTASCII_USTRINGPARAM("JNI exception occurred")),
    1745           0 :         static_cast< cppu::OWeakObject * >(this));
    1746           0 : }
    1747             : 
    1748             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10