LCOV - code coverage report
Current view: top level - jvmfwk/source - framework.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 222 609 36.5 %
Date: 2014-04-11 Functions: 17 39 43.6 %
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             : #include "boost/scoped_array.hpp"
      21             : #include "rtl/ustring.hxx"
      22             : #include "rtl/bootstrap.hxx"
      23             : #include "osl/thread.hxx"
      24             : #include "osl/file.hxx"
      25             : #include "osl/module.hxx"
      26             : #include "jvmfwk/framework.h"
      27             : #include "jvmfwk/vendorplugin.h"
      28             : #include <cassert>
      29             : #include <vector>
      30             : #include <functional>
      31             : #include <algorithm>
      32             : #include "framework.hxx"
      33             : #include "fwkutil.hxx"
      34             : #include "elements.hxx"
      35             : #include "fwkbase.hxx"
      36             : 
      37             : namespace {
      38             : 
      39             : static bool g_bEnabledSwitchedOn = false;
      40             : 
      41             : static JavaVM * g_pJavaVM = NULL;
      42             : 
      43           0 : bool areEqualJavaInfo(
      44             :     JavaInfo const * pInfoA,JavaInfo const * pInfoB)
      45             : {
      46           0 :     return jfw_areEqualJavaInfo(pInfoA, pInfoB);
      47             : }
      48             : 
      49             : }
      50             : 
      51             : #ifdef DISABLE_DYNLOADING
      52             : 
      53             : extern "C"
      54             : javaPluginError jfw_plugin_getAllJavaInfos(
      55             :     rtl_uString *sVendor,
      56             :     rtl_uString *sMinVersion,
      57             :     rtl_uString *sMaxVersion,
      58             :     rtl_uString  * *arExcludeList,
      59             :     sal_Int32  nLenList,
      60             :     JavaInfo*** parJavaInfo,
      61             :     sal_Int32 *nLenInfoList);
      62             : 
      63             : extern "C"
      64             : javaPluginError jfw_plugin_getJavaInfoByPath(
      65             :     rtl_uString *path,
      66             :     rtl_uString *sVendor,
      67             :     rtl_uString *sMinVersion,
      68             :     rtl_uString *sMaxVersion,
      69             :     rtl_uString  *  *arExcludeList,
      70             :     sal_Int32  nLenList,
      71             :     JavaInfo ** ppInfo);
      72             : 
      73             : extern "C"
      74             : javaPluginError jfw_plugin_startJavaVirtualMachine(
      75             :     const JavaInfo *pInfo,
      76             :     const JavaVMOption* arOptions,
      77             :     sal_Int32 cOptions,
      78             :     JavaVM ** ppVm,
      79             :     JNIEnv ** ppEnv);
      80             : 
      81             : extern "C"
      82             : javaPluginError jfw_plugin_existJRE(const JavaInfo *pInfo, sal_Bool *exist);
      83             : 
      84             : #endif
      85             : 
      86           0 : javaFrameworkError SAL_CALL jfw_findAllJREs(JavaInfo ***pparInfo, sal_Int32 *pSize)
      87             : {
      88           0 :     javaFrameworkError retVal = JFW_E_NONE;
      89             :     try
      90             :     {
      91           0 :         osl::MutexGuard guard(jfw::FwkMutex::get());
      92           0 :         javaFrameworkError errcode = JFW_E_NONE;
      93           0 :         if (pparInfo == NULL || pSize == NULL)
      94           0 :             return JFW_E_INVALID_ARG;
      95             : 
      96           0 :         jfw::VendorSettings aVendorSettings;
      97             :         //Get a list of plugins which provide Java information
      98             :         std::vector<jfw::PluginLibrary> vecPlugins =
      99           0 :             aVendorSettings.getPluginData();
     100             : #ifndef DISABLE_DYNLOADING
     101             :         //Create a vector that holds the libraries, which will be later
     102             :         //dynamically loaded;
     103           0 :         boost::scoped_array<osl::Module> sarModules;
     104           0 :         sarModules.reset(new osl::Module[vecPlugins.size()]);
     105           0 :         osl::Module * arModules = sarModules.get();
     106             : #endif
     107             :         //Add the JavaInfos found by jfw_plugin_getAllJavaInfos to the vector
     108             :         //Make sure that the contents are destroyed if this
     109             :         //function returns with an error
     110           0 :         std::vector<jfw::CJavaInfo> vecInfo;
     111             :         //Add the JavaInfos found by jfw_plugin_getJavaInfoByPath to this vector
     112             :         //Make sure that the contents are destroyed if this
     113             :         //function returns with an error
     114           0 :         std::vector<jfw::CJavaInfo> vecInfoManual;
     115             :         typedef std::vector<jfw::CJavaInfo>::iterator it_info;
     116             :         //get the list of paths to jre locations which have been
     117             :         //added manually
     118           0 :         const jfw::MergedSettings settings;
     119             :         const std::vector<OUString>& vecJRELocations =
     120           0 :             settings.getJRELocations();
     121             :         //Use every plug-in library to get Java installations.
     122             :         typedef std::vector<jfw::PluginLibrary>::const_iterator ci_pl;
     123           0 :         int cModule = 0;
     124           0 :          for (ci_pl i = vecPlugins.begin(); i != vecPlugins.end(); ++i, ++cModule)
     125             :          {
     126           0 :             const jfw::PluginLibrary & library = *i;
     127             :             jfw::VersionInfo versionInfo =
     128           0 :                 aVendorSettings.getVersionInformation(library.sVendor);
     129             : #ifndef DISABLE_DYNLOADING
     130           0 :             arModules[cModule].load(library.sPath);
     131           0 :             osl::Module & pluginLib = arModules[cModule];
     132             : 
     133           0 :             if (!pluginLib.is())
     134             :             {
     135             :                 OString msg = OUStringToOString(
     136           0 :                     library.sPath, osl_getThreadTextEncoding());
     137             :                 fprintf(stderr,"[jvmfwk] Could not load plugin %s\n" \
     138           0 :                         "Modify the javavendors.xml accordingly!\n", msg.getStr());
     139           0 :                 return JFW_E_NO_PLUGIN;
     140             :             }
     141             :             jfw_plugin_getAllJavaInfos_ptr getAllJavaFunc =
     142             :                 (jfw_plugin_getAllJavaInfos_ptr) pluginLib.getFunctionSymbol(
     143           0 :                     OUString("jfw_plugin_getAllJavaInfos"));
     144             : #else
     145             :             jfw_plugin_getAllJavaInfos_ptr getAllJavaFunc =
     146             :                 jfw_plugin_getAllJavaInfos;
     147             : #endif
     148             :             OSL_ASSERT(getAllJavaFunc);
     149           0 :             if (getAllJavaFunc == NULL)
     150           0 :                 return JFW_E_ERROR;
     151             : 
     152             :             //get all installations of one vendor according to minVersion,
     153             :             //maxVersion and excludeVersions
     154           0 :             sal_Int32 cInfos = 0;
     155           0 :             JavaInfo** arInfos = NULL;
     156             :             javaPluginError plerr  = (*getAllJavaFunc)(
     157             :                 library.sVendor.pData,
     158             :                 versionInfo.sMinVersion.pData,
     159             :                 versionInfo.sMaxVersion.pData,
     160             :                 versionInfo.getExcludeVersions(),
     161             :                 versionInfo.getExcludeVersionSize(),
     162             :                 & arInfos,
     163           0 :                 & cInfos);
     164             : 
     165           0 :             if (plerr != JFW_PLUGIN_E_NONE)
     166           0 :                 return JFW_E_ERROR;
     167             : 
     168           0 :             for (int j = 0; j < cInfos; j++)
     169           0 :                 vecInfo.push_back(jfw::CJavaInfo::createWrapper(arInfos[j]));
     170             : 
     171           0 :             rtl_freeMemory(arInfos);
     172             : 
     173             :             //Check if the current plugin can detect JREs at the location
     174             :             // of the paths added by jfw_setJRELocations or jfw_addJRELocation
     175             :             //get the function from the plugin
     176             : #ifndef DISABLE_DYNLOADING
     177             :             jfw_plugin_getJavaInfoByPath_ptr jfw_plugin_getJavaInfoByPathFunc =
     178             :                 (jfw_plugin_getJavaInfoByPath_ptr) pluginLib.getFunctionSymbol(
     179           0 :                     OUString("jfw_plugin_getJavaInfoByPath"));
     180             :             OSL_ASSERT(jfw_plugin_getJavaInfoByPathFunc);
     181           0 :             if (jfw_plugin_getJavaInfoByPathFunc == NULL)
     182           0 :                 return JFW_E_ERROR;
     183             : #else
     184             :             jfw_plugin_getJavaInfoByPath_ptr jfw_plugin_getJavaInfoByPathFunc =
     185             :                 jfw_plugin_getJavaInfoByPath;
     186             : #endif
     187             : 
     188             :             typedef std::vector<OUString>::const_iterator citLoc;
     189             :             //Check every manually added location
     190           0 :             for (citLoc ii = vecJRELocations.begin();
     191           0 :                 ii != vecJRELocations.end(); ++ii)
     192             :             {
     193           0 :                 jfw::CJavaInfo aInfo;
     194             :                 plerr = (*jfw_plugin_getJavaInfoByPathFunc)(
     195           0 :                     ii->pData,
     196             :                     library.sVendor.pData,
     197             :                     versionInfo.sMinVersion.pData,
     198             :                     versionInfo.sMaxVersion.pData,
     199             :                     versionInfo.getExcludeVersions(),
     200             :                     versionInfo.getExcludeVersionSize(),
     201           0 :                     & aInfo.pInfo);
     202           0 :                 if (plerr == JFW_PLUGIN_E_NO_JRE)
     203           0 :                     continue;
     204           0 :                 if (plerr == JFW_PLUGIN_E_FAILED_VERSION)
     205           0 :                     continue;
     206           0 :                 else if (plerr !=JFW_PLUGIN_E_NONE)
     207           0 :                     return JFW_E_ERROR;
     208             : 
     209           0 :                 if (aInfo)
     210             :                 {
     211             :                     //Was this JRE already added?. Different plugins could detect
     212             :                     //the same JRE
     213             :                     it_info it_duplicate =
     214             :                         std::find_if(vecInfoManual.begin(), vecInfoManual.end(),
     215           0 :                                 std::bind2nd(std::ptr_fun(areEqualJavaInfo), aInfo));
     216           0 :                     if (it_duplicate == vecInfoManual.end())
     217           0 :                         vecInfoManual.push_back(aInfo);
     218             :                 }
     219           0 :             }
     220           0 :         }
     221             :         //Make sure vecInfoManual contains only JavaInfos for the vendors for which
     222             :         //there is a javaSelection/plugins/library entry in the javavendors.xml
     223             :         //To obtain the JavaInfos for the manually added JRE locations the function
     224             :         //jfw_getJavaInfoByPath is called which can return a JavaInfo of any vendor.
     225           0 :         std::vector<jfw::CJavaInfo> vecInfoManual2;
     226           0 :         for (it_info ivm = vecInfoManual.begin(); ivm != vecInfoManual.end(); ++ivm)
     227             :         {
     228           0 :             for (ci_pl ii = vecPlugins.begin(); ii != vecPlugins.end(); ++ii)
     229             :             {
     230           0 :                 if ( ii->sVendor.equals((*ivm)->sVendor))
     231             :                 {
     232           0 :                     vecInfoManual2.push_back(*ivm);
     233           0 :                     break;
     234             :                 }
     235             :             }
     236             :         }
     237             :         //Check which JavaInfo from vector vecInfoManual2 is already
     238             :         //contained in vecInfo. If it already exists then remove it from
     239             :         //vecInfoManual2
     240           0 :         for (it_info j = vecInfo.begin(); j != vecInfo.end(); ++j)
     241             :         {
     242             :             it_info it_duplicate =
     243             :                 std::find_if(vecInfoManual2.begin(), vecInfoManual2.end(),
     244           0 :                             std::bind2nd(std::ptr_fun(areEqualJavaInfo), *j));
     245           0 :             if (it_duplicate != vecInfoManual2.end())
     246           0 :                 vecInfoManual2.erase(it_duplicate);
     247             :         }
     248             :         //create an fill the array of JavaInfo*
     249           0 :         sal_Int32 nSize = vecInfo.size() + vecInfoManual2.size();
     250             :         *pparInfo = (JavaInfo**) rtl_allocateMemory(
     251           0 :             nSize * sizeof(JavaInfo*));
     252           0 :         if (*pparInfo == NULL)
     253           0 :             return JFW_E_ERROR;
     254             : 
     255             :         typedef std::vector<jfw::CJavaInfo>::iterator it;
     256           0 :         int index = 0;
     257             :         //Add the automatically detected JREs
     258           0 :         for (it k = vecInfo.begin(); k != vecInfo.end(); ++k)
     259           0 :             (*pparInfo)[index++] = k->detach();
     260             :         //Add the manually detected JREs
     261           0 :         for (it l = vecInfoManual2.begin(); l != vecInfoManual2.end(); ++l)
     262           0 :             (*pparInfo)[index++] = l->detach();
     263             : 
     264           0 :         *pSize = nSize;
     265           0 :         return errcode;
     266             :     }
     267           0 :     catch (const jfw::FrameworkException& e)
     268             :     {
     269           0 :         retVal = e.errorCode;
     270           0 :         fprintf(stderr, "%s\n", e.message.getStr());
     271             :         OSL_FAIL(e.message.getStr());
     272             :     }
     273           0 :     return retVal;
     274             : }
     275             : 
     276          10 : javaFrameworkError SAL_CALL jfw_startVM(
     277             :     JavaInfo const * pInfo, JavaVMOption * arOptions, sal_Int32 cOptions,
     278             :     JavaVM ** ppVM, JNIEnv ** ppEnv)
     279             : {
     280          10 :     javaFrameworkError errcode = JFW_E_NONE;
     281          10 :     if (cOptions > 0 && arOptions == NULL)
     282           0 :         return JFW_E_INVALID_ARG;
     283             : 
     284             :     try
     285             :     {
     286          10 :         osl::MutexGuard guard(jfw::FwkMutex::get());
     287             : 
     288             :         //We keep this pointer so we can determine if a VM has already
     289             :         //been created.
     290          10 :         if (g_pJavaVM != NULL)
     291           0 :             return JFW_E_RUNNING_JVM;
     292             : 
     293          10 :         if (ppVM == NULL)
     294           0 :             return JFW_E_INVALID_ARG;
     295             : 
     296          16 :         std::vector<OString> vmParams;
     297          16 :         OString sUserClassPath;
     298          16 :         jfw::CJavaInfo aInfo;
     299          10 :         if (pInfo == NULL)
     300             :         {
     301           6 :             jfw::JFW_MODE mode = jfw::getMode();
     302           6 :             if (mode == jfw::JFW_MODE_APPLICATION)
     303             :             {
     304           4 :                 const jfw::MergedSettings settings;
     305           4 :                 if (!settings.getEnabled())
     306           0 :                     return JFW_E_JAVA_DISABLED;
     307           4 :                 aInfo.attach(settings.createJavaInfo());
     308             :                 //check if a Java has ever been selected
     309           4 :                 if (aInfo == NULL)
     310           4 :                     return JFW_E_NO_SELECT;
     311             : 
     312             : #ifdef WNT
     313             :                 //Because on Windows there is no system setting that we can use to determine
     314             :                 //if Assistive Technology Tool support is needed, we ship a .reg file that the
     315             :                 //user can use to create a registry setting. When the user forgets to set
     316             :                 //the key before he starts the office then a JRE may be selected without access bridge.
     317             :                 //When he later sets the key then we select a JRE with accessibility support but
     318             :                 //only if the user has not manually changed the selected JRE in the options dialog.
     319             :                 if (jfw::isAccessibilitySupportDesired())
     320             :                 {
     321             :                     // If no JRE has been selected then we do not select one. This function shall then
     322             :                     //return JFW_E_NO_SELECT
     323             :                     if (aInfo != NULL &&
     324             :                         (aInfo->nFeatures & JFW_FEATURE_ACCESSBRIDGE) == 0)
     325             :                     {
     326             :                         //has the user manually selected a JRE?
     327             :                         if (settings.getJavaInfoAttrAutoSelect() == true)
     328             :                         {
     329             :                             // if not then the automatism has previously selected a JRE
     330             :                             //without accessibility support. We return JFW_E_NO_SELECT
     331             :                             //to cause that we search for another JRE. The search code will
     332             :                             //then prefer a JRE with accessibility support.
     333             :                             return JFW_E_NO_SELECT;
     334             :                         }
     335             :                     }
     336             :                 }
     337             : #endif
     338             :                 //check if the javavendors.xml has changed after a Java was selected
     339           0 :                 OString sVendorUpdate = jfw::getElementUpdated();
     340             : 
     341           0 :                 if (sVendorUpdate != settings.getJavaInfoAttrVendorUpdate())
     342           0 :                     return JFW_E_INVALID_SETTINGS;
     343             : 
     344             :                 //check if JAVA is disabled
     345             :                 //If Java is enabled, but it was disabled when this process was started
     346             :                 // then no preparational work, such as setting the LD_LIBRARY_PATH, was
     347             :                 //done. Therefore if a JRE needs it it must not be started.
     348           0 :                 if (g_bEnabledSwitchedOn &&
     349           0 :                     (aInfo->nRequirements & JFW_REQUIRE_NEEDRESTART))
     350           0 :                     return JFW_E_NEED_RESTART;
     351             : 
     352             :                 //Check if the selected Java was set in this process. If so it
     353             :                 //must not have the requirments flag JFW_REQUIRE_NEEDRESTART
     354           0 :                 if ((aInfo->nRequirements & JFW_REQUIRE_NEEDRESTART)
     355           0 :                     &&
     356           0 :                     (jfw::wasJavaSelectedInSameProcess() == true))
     357           0 :                     return JFW_E_NEED_RESTART;
     358             : 
     359           0 :                 vmParams = settings.getVmParametersUtf8();
     360           0 :                 sUserClassPath = jfw::makeClassPathOption(settings.getUserClassPath());
     361             :             } // end mode FWK_MODE_OFFICE
     362           2 :             else if (mode == jfw::JFW_MODE_DIRECT)
     363             :             {
     364           2 :                 errcode = jfw_getSelectedJRE(&aInfo.pInfo);
     365           2 :                 if (errcode != JFW_E_NONE)
     366           0 :                     return errcode;
     367             :                 //In direct mode the options are specified by bootstrap variables
     368             :                 //of the form UNO_JAVA_JFW_PARAMETER_1 .. UNO_JAVA_JFW_PARAMETER_n
     369           2 :                 vmParams = jfw::BootParams::getVMParameters();
     370           4 :                 sUserClassPath =
     371           6 :                     "-Djava.class.path=" + jfw::BootParams::getClasspath();
     372             :             }
     373             :             else
     374             :                 OSL_ASSERT(false);
     375           2 :             pInfo = aInfo.pInfo;
     376             :         }
     377             :         assert(pInfo != NULL);
     378             : 
     379             :         //get the function jfw_plugin_startJavaVirtualMachine
     380          12 :         jfw::VendorSettings aVendorSettings;
     381          12 :         OUString sLibPath = aVendorSettings.getPluginLibrary(pInfo->sVendor);
     382             : 
     383             : #ifndef DISABLE_DYNLOADING
     384          12 :         osl::Module modulePlugin(sLibPath);
     385           6 :         if ( ! modulePlugin)
     386           0 :             return JFW_E_NO_PLUGIN;
     387             : 
     388          12 :         OUString sFunctionName("jfw_plugin_startJavaVirtualMachine");
     389             :         jfw_plugin_startJavaVirtualMachine_ptr pFunc =
     390             :             (jfw_plugin_startJavaVirtualMachine_ptr)
     391           6 :             osl_getFunctionSymbol(modulePlugin, sFunctionName.pData);
     392           6 :         if (pFunc == NULL)
     393           0 :             return JFW_E_ERROR;
     394             : #else
     395             :         jfw_plugin_startJavaVirtualMachine_ptr pFunc =
     396             :             jfw_plugin_startJavaVirtualMachine;
     397             : #endif
     398             : 
     399             :         // create JavaVMOptions array that is passed to the plugin
     400             :         // it contains the classpath and all options set in the
     401             :         //options dialog
     402             :         boost::scoped_array<JavaVMOption> sarJOptions(
     403          12 :             new JavaVMOption[cOptions + 2 + vmParams.size()]);
     404           6 :         JavaVMOption * arOpt = sarJOptions.get();
     405           6 :         if (! arOpt)
     406           0 :             return JFW_E_ERROR;
     407             : 
     408             :         //The first argument is the classpath
     409           6 :         arOpt[0].optionString= (char*) sUserClassPath.getStr();
     410           6 :         arOpt[0].extraInfo = NULL;
     411             :         // Set a flag that this JVM has been created via the JNI Invocation API
     412             :         // (used, for example, by UNO remote bridges to share a common thread pool
     413             :         // factory among Java and native bridge implementations):
     414           6 :         arOpt[1].optionString = (char *) "-Dorg.openoffice.native=";
     415           6 :         arOpt[1].extraInfo = 0;
     416             : 
     417             :         //add the options set by options dialog
     418           6 :         int index = 2;
     419             :         typedef std::vector<OString>::const_iterator cit;
     420           6 :         for (cit i = vmParams.begin(); i != vmParams.end(); ++i)
     421             :         {
     422           0 :             arOpt[index].optionString = const_cast<sal_Char*>(i->getStr());
     423           0 :             arOpt[index].extraInfo = 0;
     424           0 :             index ++;
     425             :         }
     426             :         //add all options of the arOptions argument
     427          16 :         for (int ii = 0; ii < cOptions; ii++)
     428             :         {
     429          10 :             arOpt[index].optionString = arOptions[ii].optionString;
     430          10 :             arOpt[index].extraInfo = arOptions[ii].extraInfo;
     431          10 :             index++;
     432             :         }
     433             : 
     434             :         //start Java
     435           6 :         JavaVM *pVm = NULL;
     436             :         SAL_INFO("jfw", "Starting Java");
     437           6 :         javaPluginError plerr = (*pFunc)(pInfo, arOpt, index, & pVm, ppEnv);
     438           6 :         if (plerr == JFW_PLUGIN_E_VM_CREATION_FAILED)
     439             :         {
     440           0 :             errcode = JFW_E_VM_CREATION_FAILED;
     441             :         }
     442           6 :         else if (plerr != JFW_PLUGIN_E_NONE )
     443             :         {
     444           0 :             errcode = JFW_E_ERROR;
     445             :         }
     446             :         else
     447             :         {
     448           6 :             g_pJavaVM = pVm;
     449           6 :             *ppVM = pVm;
     450             :         }
     451           6 :         OSL_ASSERT(plerr != JFW_PLUGIN_E_WRONG_VENDOR);
     452             :     }
     453           0 :     catch (const jfw::FrameworkException& e)
     454             :     {
     455           0 :         errcode = e.errorCode;
     456           0 :         fprintf(stderr, "%s\n", e.message.getStr());
     457             :         OSL_FAIL(e.message.getStr());
     458             :     }
     459             : 
     460           6 :     return errcode;
     461             : }
     462             : 
     463             : /** We do not use here jfw_findAllJREs and then check if a JavaInfo
     464             :     meets the requirements, because that means using all plug-ins, which
     465             :     may take quite a while. The implementation uses one plug-in and if
     466             :     it already finds a suitable JRE then it is done and does not need to
     467             :     load another plug-in
     468             :  */
     469           4 : javaFrameworkError SAL_CALL jfw_findAndSelectJRE(JavaInfo **pInfo)
     470             : {
     471           4 :     javaFrameworkError errcode = JFW_E_NONE;
     472             :     try
     473             :     {
     474           4 :         osl::MutexGuard guard(jfw::FwkMutex::get());
     475           4 :         if (jfw::getMode() == jfw::JFW_MODE_DIRECT)
     476           0 :             return JFW_E_DIRECT_MODE;
     477           4 :         sal_uInt64 nFeatureFlags = 0;
     478           8 :         jfw::CJavaInfo aCurrentInfo;
     479             : //Determine if accessibility support is needed
     480           4 :         bool bSupportAccessibility = jfw::isAccessibilitySupportDesired();
     481             :         nFeatureFlags = bSupportAccessibility ?
     482           4 :             JFW_FEATURE_ACCESSBRIDGE : 0L;
     483             : 
     484             :         //Get a list of services which provide Java information
     485           8 :         jfw::VendorSettings aVendorSettings;
     486             :         std::vector<jfw::PluginLibrary> vecPlugins =
     487           8 :              aVendorSettings.getPluginData();
     488             : #ifndef DISABLE_DYNLOADING
     489             :         //Create a vector that holds the libraries, which will be later
     490             :         //dynamically loaded;
     491           8 :         boost::scoped_array<osl::Module> sarModules;
     492           4 :         sarModules.reset(new osl::Module[vecPlugins.size()]);
     493           4 :         osl::Module * arModules = sarModules.get();
     494             : #endif
     495             :         //Use every plug-in library to get Java installations. At the first usable
     496             :         //Java the loop will break
     497             :         typedef std::vector<jfw::PluginLibrary>::const_iterator ci_pl;
     498           4 :         int cModule = 0;
     499           8 :         for (ci_pl i = vecPlugins.begin(); i != vecPlugins.end(); ++i, ++cModule)
     500             :         {
     501           8 :             const jfw::PluginLibrary & library = *i;
     502             :             jfw::VersionInfo versionInfo =
     503           8 :                 aVendorSettings.getVersionInformation(library.sVendor);
     504             : #ifndef DISABLE_DYNLOADING
     505           8 :             arModules[cModule].load(library.sPath);
     506           8 :             osl::Module & pluginLib = arModules[cModule];
     507           8 :             if (!pluginLib.is())
     508           0 :                 return JFW_E_NO_PLUGIN;
     509             : 
     510             :             jfw_plugin_getAllJavaInfos_ptr getAllJavaFunc =
     511             :                 (jfw_plugin_getAllJavaInfos_ptr) pluginLib.getFunctionSymbol(
     512           8 :                     OUString("jfw_plugin_getAllJavaInfos"));
     513             : #else
     514             :             jfw_plugin_getAllJavaInfos_ptr getAllJavaFunc =
     515             :                 jfw_plugin_getAllJavaInfos;
     516             : #endif
     517             :             OSL_ASSERT(getAllJavaFunc);
     518           8 :             if (getAllJavaFunc == NULL)
     519           0 :                 continue;
     520             : 
     521             :             //get all installations of one vendor according to minVersion,
     522             :             //maxVersion and excludeVersions
     523           8 :             sal_Int32 cInfos = 0;
     524           8 :             JavaInfo** arInfos = NULL;
     525             :             javaPluginError plerr  = (*getAllJavaFunc)(
     526             :                 library.sVendor.pData,
     527             :                 versionInfo.sMinVersion.pData,
     528             :                 versionInfo.sMaxVersion.pData,
     529             :                 versionInfo.getExcludeVersions(),
     530             :                 versionInfo.getExcludeVersionSize(),
     531             :                 & arInfos,
     532           8 :                 & cInfos);
     533             : 
     534           8 :             if (plerr != JFW_PLUGIN_E_NONE)
     535           0 :                 continue;
     536             :             //iterate over all installations to find the best which has
     537             :             //all features
     538           8 :             if (cInfos == 0)
     539             :             {
     540           4 :                 rtl_freeMemory(arInfos);
     541           4 :                 continue;
     542             :             }
     543           4 :             bool bInfoFound = false;
     544           4 :             for (int ii = 0; ii < cInfos; ii++)
     545             :             {
     546           4 :                 JavaInfo* pJInfo = arInfos[ii];
     547             : 
     548             :                 //We remember the very first installation in aCurrentInfo
     549           4 :                 if (aCurrentInfo.getLocation().isEmpty())
     550           4 :                         aCurrentInfo = pJInfo;
     551             :                 // compare features
     552             :                 // If the user does not require any features (nFeatureFlags = 0)
     553             :                 // then the first installation is used
     554           4 :                 if ((pJInfo->nFeatures & nFeatureFlags) == nFeatureFlags)
     555             :                 {
     556             :                     //the just found Java implements all required features
     557             :                     //currently there is only accessibility!!!
     558           4 :                     aCurrentInfo = pJInfo;
     559           4 :                     bInfoFound = true;
     560           4 :                     break;
     561             :                 }
     562             :             }
     563             :             //The array returned by jfw_plugin_getAllJavaInfos must be freed as well as
     564             :             //its contents
     565           8 :             for (int j = 0; j < cInfos; j++)
     566           4 :                 jfw_freeJavaInfo(arInfos[j]);
     567           4 :             rtl_freeMemory(arInfos);
     568             : 
     569           4 :             if (bInfoFound == true)
     570           4 :                 break;
     571             :             //All Java installations found by the current plug-in lib
     572             :             //do not provide the required features. Try the next plug-in
     573           0 :         }
     574           4 :         if ((JavaInfo*) aCurrentInfo == NULL)
     575             :         {//The plug-ins did not find a suitable Java. Now try the paths which have been
     576             :         //added manually.
     577             :             //get the list of paths to jre locations which have been added manually
     578           0 :             const jfw::MergedSettings settings;
     579             :             //node.loadFromSettings();
     580             :             const std::vector<OUString> & vecJRELocations =
     581           0 :                 settings.getJRELocations();
     582             :             //use every plug-in to determine the JavaInfo objects
     583           0 :             bool bInfoFound = false;
     584           0 :             for (ci_pl i = vecPlugins.begin(); i != vecPlugins.end(); ++i)
     585             :             {
     586           0 :                 const jfw::PluginLibrary & library = *i;
     587             :                 jfw::VersionInfo versionInfo =
     588           0 :                     aVendorSettings.getVersionInformation(library.sVendor);
     589             : #ifndef DISABLE_DYNLOADING
     590           0 :                 osl::Module pluginLib(library.sPath);
     591           0 :                 if (!pluginLib.is())
     592           0 :                     return JFW_E_NO_PLUGIN;
     593             :                 //Check if the current plugin can detect JREs at the location
     594             :                 // of the paths added by jfw_setJRELocations or jfw_addJRELocation
     595             :                 //get the function from the plugin
     596             :                 jfw_plugin_getJavaInfoByPath_ptr jfw_plugin_getJavaInfoByPathFunc =
     597             :                     (jfw_plugin_getJavaInfoByPath_ptr) pluginLib.getFunctionSymbol(
     598           0 :                         OUString("jfw_plugin_getJavaInfoByPath"));
     599             : #else
     600             :                 jfw_plugin_getJavaInfoByPath_ptr jfw_plugin_getJavaInfoByPathFunc =
     601             :                     jfw_plugin_getJavaInfoByPath;
     602             : #endif
     603             :                 OSL_ASSERT(jfw_plugin_getJavaInfoByPathFunc);
     604           0 :                 if (jfw_plugin_getJavaInfoByPathFunc == NULL)
     605           0 :                     return JFW_E_ERROR;
     606             : 
     607             :                 typedef std::vector<OUString>::const_iterator citLoc;
     608           0 :                 for (citLoc it = vecJRELocations.begin();
     609           0 :                     it != vecJRELocations.end(); ++it)
     610             :                 {
     611           0 :                     jfw::CJavaInfo aInfo;
     612             :                     javaPluginError err = (*jfw_plugin_getJavaInfoByPathFunc)(
     613           0 :                         it->pData,
     614             :                         library.sVendor.pData,
     615             :                         versionInfo.sMinVersion.pData,
     616             :                         versionInfo.sMaxVersion.pData,
     617             :                         versionInfo.getExcludeVersions(),
     618             :                         versionInfo.getExcludeVersionSize(),
     619           0 :                         & aInfo.pInfo);
     620           0 :                     if (err == JFW_PLUGIN_E_NO_JRE)
     621           0 :                         continue;
     622           0 :                     if (err == JFW_PLUGIN_E_FAILED_VERSION)
     623           0 :                         continue;
     624           0 :                     else if (err !=JFW_PLUGIN_E_NONE)
     625           0 :                         return JFW_E_ERROR;
     626             : 
     627           0 :                     if (aInfo)
     628             :                     {
     629             :                         //We remember the very first installation in aCurrentInfo
     630           0 :                         if (aCurrentInfo.getLocation().isEmpty())
     631           0 :                             aCurrentInfo = aInfo;
     632             :                         // compare features
     633             :                         // If the user does not require any features (nFeatureFlags = 0)
     634             :                         // then the first installation is used
     635           0 :                         if ((aInfo.getFeatures() & nFeatureFlags) == nFeatureFlags)
     636             :                         {
     637             :                             //the just found Java implements all required features
     638             :                             //currently there is only accessibility!!!
     639           0 :                             aCurrentInfo = aInfo;
     640           0 :                             bInfoFound = true;
     641           0 :                             break;
     642             :                         }
     643             :                     }
     644           0 :                 }//end iterate over paths
     645           0 :                 if (bInfoFound == true)
     646           0 :                     break;
     647           0 :             }// end iterate plug-ins
     648             :         }
     649           4 :         if ((JavaInfo*) aCurrentInfo)
     650             :         {
     651           4 :             jfw::NodeJava javaNode(jfw::NodeJava::USER);
     652           4 :             javaNode.setJavaInfo(aCurrentInfo,true);
     653           4 :             javaNode.write();
     654             :             //remember that this JRE was selected in this process
     655           4 :             jfw::setJavaSelected();
     656             : 
     657           4 :             if (pInfo !=NULL)
     658             :             {
     659             :                 //copy to out param
     660           4 :                 *pInfo = aCurrentInfo.cloneJavaInfo();
     661           4 :             }
     662             :         }
     663             :         else
     664             :         {
     665           0 :             errcode = JFW_E_NO_JAVA_FOUND;
     666           4 :         }
     667             :     }
     668           0 :     catch (const jfw::FrameworkException& e)
     669             :     {
     670           0 :         errcode = e.errorCode;
     671           0 :         fprintf(stderr, "%s\n", e.message.getStr());
     672             :         OSL_FAIL(e.message.getStr());
     673             :     }
     674             : 
     675           4 :     return errcode;
     676             : }
     677             : 
     678           0 : sal_Bool SAL_CALL jfw_areEqualJavaInfo(
     679             :     JavaInfo const * pInfoA,JavaInfo const * pInfoB)
     680             : {
     681           0 :     if (pInfoA == pInfoB)
     682           0 :         return sal_True;
     683           0 :     if (pInfoA == NULL || pInfoB == NULL)
     684           0 :         return sal_False;
     685           0 :     OUString sVendor(pInfoA->sVendor);
     686           0 :     OUString sLocation(pInfoA->sLocation);
     687           0 :     OUString sVersion(pInfoA->sVersion);
     688           0 :     rtl::ByteSequence sData(pInfoA->arVendorData);
     689           0 :     if (sVendor.equals(pInfoB->sVendor)
     690           0 :         && sLocation.equals(pInfoB->sLocation)
     691           0 :         && sVersion.equals(pInfoB->sVersion)
     692           0 :         && pInfoA->nFeatures == pInfoB->nFeatures
     693           0 :         && pInfoA->nRequirements == pInfoB->nRequirements
     694           0 :         && sData == pInfoB->arVendorData)
     695             :     {
     696           0 :         return sal_True;
     697             :     }
     698           0 :     return sal_False;
     699             : }
     700             : 
     701             : 
     702         239 : void SAL_CALL jfw_freeJavaInfo(JavaInfo *pInfo)
     703             : {
     704         239 :     if (pInfo == NULL)
     705         362 :         return;
     706         116 :     rtl_uString_release(pInfo->sVendor);
     707         116 :     rtl_uString_release(pInfo->sLocation);
     708         116 :     rtl_uString_release(pInfo->sVersion);
     709         116 :     rtl_byte_sequence_release(pInfo->arVendorData);
     710         116 :     rtl_freeMemory(pInfo);
     711             : }
     712             : 
     713          51 : javaFrameworkError SAL_CALL jfw_getSelectedJRE(JavaInfo **ppInfo)
     714             : {
     715          51 :     javaFrameworkError errcode = JFW_E_NONE;
     716             :     try
     717             :     {
     718          51 :         osl::MutexGuard guard(jfw::FwkMutex::get());
     719          51 :         if (ppInfo == NULL)
     720           0 :             return JFW_E_INVALID_ARG;
     721             : 
     722          51 :         if (jfw::getMode() == jfw::JFW_MODE_DIRECT)
     723             :         {
     724          51 :             OUString sJRE = jfw::BootParams::getJREHome();
     725             : 
     726         102 :             jfw::CJavaInfo aInfo;
     727          51 :             if ((errcode = jfw_getJavaInfoByPath(sJRE.pData, & aInfo.pInfo))
     728             :                 != JFW_E_NONE)
     729             :                 throw jfw::FrameworkException(
     730             :                     JFW_E_CONFIGURATION,
     731             :                     OString(
     732             :                         "[Java framework] The JRE specified by the bootstrap "
     733             :                         "variable UNO_JAVA_JFW_JREHOME  or  UNO_JAVA_JFW_ENV_JREHOME "
     734             :                         " could not be recognized. Check the values and make sure that you "
     735           0 :                         "use a plug-in library that can recognize that JRE."));
     736             : 
     737          51 :             *ppInfo = aInfo.detach();
     738         102 :             return JFW_E_NONE;
     739             :         }
     740             : 
     741           0 :         const jfw::MergedSettings settings;
     742           0 :         jfw::CJavaInfo aInfo;
     743           0 :         aInfo.attach(settings.createJavaInfo());
     744           0 :         if (! aInfo)
     745             :         {
     746           0 :             *ppInfo = NULL;
     747           0 :             return JFW_E_NONE;
     748             :         }
     749             :         //If the javavendors.xml has changed, then the current selected
     750             :         //Java is not valid anymore
     751             :         // /java/javaInfo/@vendorUpdate != javaSelection/updated (javavendors.xml)
     752           0 :         OString sUpdated = jfw::getElementUpdated();
     753             : 
     754           0 :         if (!sUpdated.equals(settings.getJavaInfoAttrVendorUpdate()))
     755           0 :             return JFW_E_INVALID_SETTINGS;
     756           0 :         *ppInfo = aInfo.detach();
     757             :     }
     758           0 :     catch (const jfw::FrameworkException& e)
     759             :     {
     760           0 :         errcode = e.errorCode;
     761           0 :         fprintf(stderr, "%s\n", e.message.getStr());
     762             :         OSL_FAIL(e.message.getStr());
     763             :     }
     764           0 :     return errcode;
     765             : }
     766             : 
     767           0 : javaFrameworkError SAL_CALL jfw_isVMRunning(sal_Bool *bRunning)
     768             : {
     769           0 :     osl::MutexGuard guard(jfw::FwkMutex::get());
     770           0 :     if (bRunning == NULL)
     771           0 :         return JFW_E_INVALID_ARG;
     772           0 :     if (g_pJavaVM == NULL)
     773           0 :         *bRunning = sal_False;
     774             :     else
     775           0 :         *bRunning = sal_True;
     776           0 :     return JFW_E_NONE;
     777             : }
     778             : 
     779          51 : javaFrameworkError SAL_CALL jfw_getJavaInfoByPath(
     780             :     rtl_uString *pPath, JavaInfo **ppInfo)
     781             : {
     782          51 :     javaFrameworkError errcode = JFW_E_NONE;
     783             :     try
     784             :     {
     785          51 :         osl::MutexGuard guard(jfw::FwkMutex::get());
     786          51 :         if (pPath == NULL || ppInfo == NULL)
     787           0 :             return JFW_E_INVALID_ARG;
     788             : 
     789         102 :         jfw::VendorSettings aVendorSettings;
     790             :         //Get a list of plugins which provide Java information
     791             :         std::vector<jfw::PluginLibrary> vecPlugins =
     792         102 :             aVendorSettings.getPluginData();
     793             : #ifndef DISABLE_DYNLOADING
     794             :         //Create a vector that holds the libraries, which will be later
     795             :         //dynamically loaded;
     796         102 :         boost::scoped_array<osl::Module> sarModules;
     797          51 :         sarModules.reset(new osl::Module[vecPlugins.size()]);
     798          51 :         osl::Module * arModules = sarModules.get();
     799             : #endif
     800             :         typedef std::vector<OUString>::const_iterator CIT_VENDOR;
     801             :         std::vector<OUString> vecVendors =
     802         102 :             aVendorSettings.getSupportedVendors();
     803             : 
     804             :         //Use every plug-in library to determine if the path represents a
     805             :         //JRE. If a plugin recognized it then the loop will break
     806             :         typedef std::vector<jfw::PluginLibrary>::const_iterator ci_pl;
     807          51 :         int cModule = 0;
     808         102 :         for (ci_pl i = vecPlugins.begin(); i != vecPlugins.end();
     809             :              ++i, ++cModule)
     810             :         {
     811         102 :             const jfw::PluginLibrary & library = *i;
     812             :             jfw::VersionInfo versionInfo =
     813         102 :                 aVendorSettings.getVersionInformation(library.sVendor);
     814             : 
     815             : #ifndef DISABLE_DYNLOADING
     816         102 :             arModules[cModule].load(library.sPath);
     817         102 :             osl::Module & pluginLib = arModules[cModule];
     818         102 :             if (!pluginLib.is())
     819             :             {
     820             :                 OString msg = OUStringToOString(
     821           0 :                     library.sPath, osl_getThreadTextEncoding());
     822             :                 fprintf(stderr,"[jvmfwk] Could not load plugin %s\n" \
     823           0 :                         "Modify the javavendors.xml accordingly!\n", msg.getStr());
     824           0 :                 return JFW_E_NO_PLUGIN;
     825             :             }
     826             : 
     827             :             jfw_plugin_getJavaInfoByPath_ptr jfw_plugin_getJavaInfoByPathFunc =
     828             :                 (jfw_plugin_getJavaInfoByPath_ptr) pluginLib.getFunctionSymbol(
     829         102 :                     OUString("jfw_plugin_getJavaInfoByPath"));
     830             : #else
     831             :             jfw_plugin_getJavaInfoByPath_ptr jfw_plugin_getJavaInfoByPathFunc =
     832             :                 jfw_plugin_getJavaInfoByPath;
     833             : #endif
     834             :             OSL_ASSERT(jfw_plugin_getJavaInfoByPathFunc);
     835         102 :             if (jfw_plugin_getJavaInfoByPathFunc == NULL)
     836           0 :                 continue;
     837             : 
     838             :             //ask the plugin if this is a JRE.
     839             :             //If so check if it meets the version requirements.
     840             :             //Only if it does return a JavaInfo
     841         102 :             JavaInfo* pInfo = NULL;
     842             :             javaPluginError plerr = (*jfw_plugin_getJavaInfoByPathFunc)(
     843             :                 pPath,
     844             :                 library.sVendor.pData,
     845             :                 versionInfo.sMinVersion.pData,
     846             :                 versionInfo.sMaxVersion.pData,
     847             :                 versionInfo.getExcludeVersions(),
     848             :                 versionInfo.getExcludeVersionSize(),
     849         102 :                 & pInfo);
     850             : 
     851         102 :             if (plerr == JFW_PLUGIN_E_NONE)
     852             :             {
     853             :                 //check if the vendor of the found JRE is supported
     854          51 :                 if (vecVendors.empty())
     855             :                 {
     856             :                     //vendor does not matter
     857           0 :                     *ppInfo = pInfo;
     858           0 :                     break;
     859             :                 }
     860             :                 else
     861             :                 {
     862          51 :                     OUString sVendor(pInfo->sVendor);
     863             :                     CIT_VENDOR ivendor = std::find(vecVendors.begin(), vecVendors.end(),
     864          51 :                                                    sVendor);
     865          51 :                     if (ivendor != vecVendors.end())
     866             :                     {
     867          51 :                         *ppInfo = pInfo;
     868             :                     }
     869             :                     else
     870             :                     {
     871           0 :                         *ppInfo = NULL;
     872           0 :                         errcode = JFW_E_NOT_RECOGNIZED;
     873             :                     }
     874          51 :                     break;
     875             :                 }
     876             :             }
     877          51 :             else if(plerr == JFW_PLUGIN_E_FAILED_VERSION)
     878             :             {//found JRE but it has the wrong version
     879           0 :                 *ppInfo = NULL;
     880           0 :                 errcode = JFW_E_FAILED_VERSION;
     881           0 :                 break;
     882             :             }
     883          51 :             else if (plerr == JFW_PLUGIN_E_NO_JRE)
     884             :             {// plugin does not recognize this path as belonging to JRE
     885          51 :                 continue;
     886             :             }
     887             :             OSL_ASSERT(false);
     888           0 :         }
     889          51 :         if (*ppInfo == NULL && errcode != JFW_E_FAILED_VERSION)
     890          51 :             errcode = JFW_E_NOT_RECOGNIZED;
     891             :     }
     892           0 :     catch (const jfw::FrameworkException& e)
     893             :     {
     894           0 :         errcode = e.errorCode;
     895           0 :         fprintf(stderr, "%s\n", e.message.getStr());
     896             :         OSL_FAIL(e.message.getStr());
     897             :     }
     898             : 
     899          51 :     return errcode;
     900             : }
     901             : 
     902             : 
     903           0 : javaFrameworkError SAL_CALL jfw_setSelectedJRE(JavaInfo const *pInfo)
     904             : {
     905           0 :     javaFrameworkError errcode = JFW_E_NONE;
     906             :     try
     907             :     {
     908           0 :         osl::MutexGuard guard(jfw::FwkMutex::get());
     909           0 :         if (jfw::getMode() == jfw::JFW_MODE_DIRECT)
     910           0 :             return JFW_E_DIRECT_MODE;
     911             :         //check if pInfo is the selected JRE
     912           0 :         JavaInfo *currentInfo = NULL;
     913           0 :         errcode = jfw_getSelectedJRE( & currentInfo);
     914           0 :         if (errcode != JFW_E_NONE && errcode != JFW_E_INVALID_SETTINGS)
     915           0 :             return errcode;
     916             : 
     917           0 :         if (jfw_areEqualJavaInfo(currentInfo, pInfo) == sal_False)
     918             :         {
     919           0 :             jfw::NodeJava node(jfw::NodeJava::USER);
     920           0 :             node.setJavaInfo(pInfo, false);
     921           0 :             node.write();
     922             :             //remember that the JRE was selected in this process
     923           0 :             jfw::setJavaSelected();
     924           0 :         }
     925             :     }
     926           0 :     catch (const jfw::FrameworkException& e)
     927             :     {
     928           0 :         errcode = e.errorCode;
     929           0 :         fprintf(stderr, "%s\n", e.message.getStr());
     930             :         OSL_FAIL(e.message.getStr());
     931             :     }
     932           0 :     return errcode;
     933             : }
     934           0 : javaFrameworkError SAL_CALL jfw_setEnabled(sal_Bool bEnabled)
     935             : {
     936           0 :     javaFrameworkError errcode = JFW_E_NONE;
     937             :     try
     938             :     {
     939           0 :         osl::MutexGuard guard(jfw::FwkMutex::get());
     940           0 :         if (jfw::getMode() == jfw::JFW_MODE_DIRECT)
     941           0 :             return JFW_E_DIRECT_MODE;
     942             : 
     943           0 :         if (g_bEnabledSwitchedOn == false && bEnabled == sal_True)
     944             :         {
     945             :             //When the process started then Enabled was false.
     946             :             //This is first time enabled is set to true.
     947             :             //That means, no preparational work has been done, such as setting the
     948             :             //LD_LIBRARY_PATH, etc.
     949             : 
     950             :             //check if Enabled is false;
     951           0 :             const jfw::MergedSettings settings;
     952           0 :             if (!settings.getEnabled())
     953           0 :                 g_bEnabledSwitchedOn = true;
     954             :         }
     955           0 :         jfw::NodeJava node(jfw::NodeJava::USER);
     956           0 :         node.setEnabled(bEnabled);
     957           0 :         node.write();
     958             :     }
     959           0 :     catch (const jfw::FrameworkException& e)
     960             :     {
     961           0 :         errcode = e.errorCode;
     962           0 :         fprintf(stderr, "%s\n", e.message.getStr());
     963             :         OSL_FAIL(e.message.getStr());
     964             :     }
     965           0 :     return errcode;
     966             : }
     967             : 
     968          57 : javaFrameworkError SAL_CALL jfw_getEnabled(sal_Bool *pbEnabled)
     969             : {
     970          57 :     javaFrameworkError errcode = JFW_E_NONE;
     971             :     try
     972             :     {
     973          57 :         if (jfw::getMode() == jfw::JFW_MODE_DIRECT)
     974          98 :             return JFW_E_DIRECT_MODE;
     975           8 :         osl::MutexGuard guard(jfw::FwkMutex::get());
     976           8 :         if (pbEnabled == NULL)
     977           0 :             return JFW_E_INVALID_ARG;
     978          16 :         jfw::MergedSettings settings;
     979          16 :         *pbEnabled = settings.getEnabled();
     980             :     }
     981           0 :     catch (const jfw::FrameworkException& e)
     982             :     {
     983           0 :         errcode = e.errorCode;
     984           0 :         fprintf(stderr, "%s\n", e.message.getStr());
     985             :         OSL_FAIL(e.message.getStr());
     986             :     }
     987           8 :     return errcode;
     988             : }
     989             : 
     990             : 
     991           0 : javaFrameworkError SAL_CALL jfw_setVMParameters(
     992             :     rtl_uString * * arOptions, sal_Int32 nLen)
     993             : {
     994           0 :     javaFrameworkError errcode = JFW_E_NONE;
     995             :     try
     996             :     {
     997           0 :         osl::MutexGuard guard(jfw::FwkMutex::get());
     998           0 :         if (jfw::getMode() == jfw::JFW_MODE_DIRECT)
     999           0 :             return JFW_E_DIRECT_MODE;
    1000           0 :         jfw::NodeJava node(jfw::NodeJava::USER);
    1001           0 :         if (arOptions == NULL && nLen != 0)
    1002           0 :             return JFW_E_INVALID_ARG;
    1003           0 :         node.setVmParameters(arOptions, nLen);
    1004           0 :         node.write();
    1005             :     }
    1006           0 :     catch (const jfw::FrameworkException& e)
    1007             :     {
    1008           0 :         errcode = e.errorCode;
    1009           0 :         fprintf(stderr, "%s\n", e.message.getStr());
    1010             :         OSL_FAIL(e.message.getStr());
    1011             :     }
    1012             : 
    1013           0 :     return errcode;
    1014             : }
    1015             : 
    1016           0 : javaFrameworkError SAL_CALL jfw_getVMParameters(
    1017             :     rtl_uString *** parOptions, sal_Int32 * pLen)
    1018             : {
    1019           0 :     javaFrameworkError errcode = JFW_E_NONE;
    1020             :     try
    1021             :     {
    1022           0 :         osl::MutexGuard guard(jfw::FwkMutex::get());
    1023           0 :         if (jfw::getMode() == jfw::JFW_MODE_DIRECT)
    1024           0 :             return JFW_E_DIRECT_MODE;
    1025             : 
    1026           0 :         if (parOptions == NULL || pLen == NULL)
    1027           0 :             return JFW_E_INVALID_ARG;
    1028           0 :         const jfw::MergedSettings settings;
    1029           0 :         settings.getVmParametersArray(parOptions, pLen);
    1030             :     }
    1031           0 :     catch (const jfw::FrameworkException& e)
    1032             :     {
    1033           0 :         errcode = e.errorCode;
    1034           0 :         fprintf(stderr, "%s\n", e.message.getStr());
    1035             :         OSL_FAIL(e.message.getStr());
    1036             :     }
    1037           0 :     return errcode;
    1038             : }
    1039             : 
    1040           0 : javaFrameworkError SAL_CALL jfw_setUserClassPath(rtl_uString * pCp)
    1041             : {
    1042           0 :     javaFrameworkError errcode = JFW_E_NONE;
    1043             :     try
    1044             :     {
    1045           0 :         osl::MutexGuard guard(jfw::FwkMutex::get());
    1046           0 :         if (jfw::getMode() == jfw::JFW_MODE_DIRECT)
    1047           0 :             return JFW_E_DIRECT_MODE;
    1048           0 :         jfw::NodeJava node(jfw::NodeJava::USER);
    1049           0 :         if (pCp == NULL)
    1050           0 :             return JFW_E_INVALID_ARG;
    1051           0 :         node.setUserClassPath(pCp);
    1052           0 :         node.write();
    1053             :     }
    1054           0 :     catch (const jfw::FrameworkException& e)
    1055             :     {
    1056           0 :         errcode = e.errorCode;
    1057           0 :         fprintf(stderr, "%s\n", e.message.getStr());
    1058             :         OSL_FAIL(e.message.getStr());
    1059             :     }
    1060           0 :     return errcode;
    1061             : }
    1062             : 
    1063           0 : javaFrameworkError SAL_CALL jfw_getUserClassPath(rtl_uString ** ppCP)
    1064             : {
    1065           0 :     javaFrameworkError errcode = JFW_E_NONE;
    1066             :     try
    1067             :     {
    1068           0 :         osl::MutexGuard guard(jfw::FwkMutex::get());
    1069           0 :         if (jfw::getMode() == jfw::JFW_MODE_DIRECT)
    1070           0 :             return JFW_E_DIRECT_MODE;
    1071           0 :         if (ppCP == NULL)
    1072           0 :             return JFW_E_INVALID_ARG;
    1073           0 :         const jfw::MergedSettings settings;
    1074           0 :         *ppCP = settings.getUserClassPath().pData;
    1075           0 :         rtl_uString_acquire(*ppCP);
    1076             :     }
    1077           0 :     catch (const jfw::FrameworkException& e)
    1078             :     {
    1079           0 :         errcode = e.errorCode;
    1080           0 :         fprintf(stderr, "%s\n", e.message.getStr());
    1081             :         OSL_FAIL(e.message.getStr());
    1082             :     }
    1083           0 :     return errcode;
    1084             : }
    1085             : 
    1086           0 : javaFrameworkError SAL_CALL jfw_addJRELocation(rtl_uString * sLocation)
    1087             : {
    1088           0 :     javaFrameworkError errcode = JFW_E_NONE;
    1089             :     try
    1090             :     {
    1091           0 :         osl::MutexGuard guard(jfw::FwkMutex::get());
    1092           0 :         if (jfw::getMode() == jfw::JFW_MODE_DIRECT)
    1093           0 :             return JFW_E_DIRECT_MODE;
    1094           0 :         jfw::NodeJava node(jfw::NodeJava::USER);
    1095           0 :         if (sLocation == NULL)
    1096           0 :             return JFW_E_INVALID_ARG;
    1097           0 :         node.load();
    1098           0 :         node.addJRELocation(sLocation);
    1099           0 :         node.write();
    1100             :     }
    1101           0 :     catch (const jfw::FrameworkException& e)
    1102             :     {
    1103           0 :         errcode = e.errorCode;
    1104           0 :         fprintf(stderr, "%s\n", e.message.getStr());
    1105             :         OSL_FAIL(e.message.getStr());
    1106             :     }
    1107             : 
    1108           0 :     return errcode;
    1109             : 
    1110             : }
    1111             : 
    1112           0 : javaFrameworkError SAL_CALL jfw_setJRELocations(
    1113             :     rtl_uString ** arLocations, sal_Int32 nLen)
    1114             : {
    1115           0 :     javaFrameworkError errcode = JFW_E_NONE;
    1116             :     try
    1117             :     {
    1118           0 :         osl::MutexGuard guard(jfw::FwkMutex::get());
    1119           0 :         if (jfw::getMode() == jfw::JFW_MODE_DIRECT)
    1120           0 :             return JFW_E_DIRECT_MODE;
    1121           0 :         jfw::NodeJava node(jfw::NodeJava::USER);
    1122           0 :         if (arLocations == NULL && nLen != 0)
    1123           0 :             return JFW_E_INVALID_ARG;
    1124           0 :         node.setJRELocations(arLocations, nLen);
    1125           0 :         node.write();
    1126             :     }
    1127           0 :     catch (const jfw::FrameworkException& e)
    1128             :     {
    1129           0 :         errcode = e.errorCode;
    1130           0 :         fprintf(stderr, "%s\n", e.message.getStr());
    1131             :         OSL_FAIL(e.message.getStr());
    1132             :     }
    1133           0 :     return errcode;
    1134             : 
    1135             : }
    1136             : 
    1137           0 : javaFrameworkError SAL_CALL jfw_getJRELocations(
    1138             :     rtl_uString *** parLocations, sal_Int32 *pLen)
    1139             : {
    1140           0 :     javaFrameworkError errcode = JFW_E_NONE;
    1141             :     try
    1142             :     {
    1143           0 :         osl::MutexGuard guard(jfw::FwkMutex::get());
    1144           0 :         if (jfw::getMode() == jfw::JFW_MODE_DIRECT)
    1145           0 :             return JFW_E_DIRECT_MODE;
    1146             : 
    1147           0 :         if (parLocations == NULL || pLen == NULL)
    1148           0 :             return JFW_E_INVALID_ARG;
    1149           0 :         const jfw::MergedSettings settings;
    1150           0 :         settings.getJRELocations(parLocations, pLen);
    1151             :     }
    1152           0 :     catch (const jfw::FrameworkException& e)
    1153             :     {
    1154           0 :         errcode = e.errorCode;
    1155           0 :         fprintf(stderr, "%s\n", e.message.getStr());
    1156             :         OSL_FAIL(e.message.getStr());
    1157             :     }
    1158             : 
    1159           0 :     return errcode;
    1160             : }
    1161             : 
    1162             : 
    1163          49 : javaFrameworkError jfw_existJRE(const JavaInfo *pInfo, sal_Bool *exist)
    1164             : {
    1165             :     //get the function jfw_plugin_existJRE
    1166          49 :     jfw::VendorSettings aVendorSettings;
    1167          98 :     jfw::CJavaInfo aInfo;
    1168          49 :     aInfo = (const ::JavaInfo*) pInfo; //makes a copy of pInfo
    1169             : #ifndef DISABLE_DYNLOADING
    1170          98 :     OUString sLibPath = aVendorSettings.getPluginLibrary(aInfo.getVendor());
    1171          98 :     osl::Module modulePlugin(sLibPath);
    1172          49 :     if ( ! modulePlugin)
    1173           0 :         return JFW_E_NO_PLUGIN;
    1174          98 :     OUString sFunctionName("jfw_plugin_existJRE");
    1175             :     jfw_plugin_existJRE_ptr pFunc =
    1176             :         (jfw_plugin_existJRE_ptr)
    1177          49 :         osl_getFunctionSymbol(modulePlugin, sFunctionName.pData);
    1178          49 :     if (pFunc == NULL)
    1179           0 :         return JFW_E_ERROR;
    1180             : #else
    1181             :     jfw_plugin_existJRE_ptr pFunc =
    1182             :         jfw_plugin_existJRE;
    1183             : #endif
    1184          49 :     javaPluginError plerr = (*pFunc)(pInfo, exist);
    1185             : 
    1186          49 :     javaFrameworkError ret = JFW_E_NONE;
    1187          49 :     switch (plerr)
    1188             :     {
    1189             :     case JFW_PLUGIN_E_NONE:
    1190          49 :         ret = JFW_E_NONE;
    1191          49 :         break;
    1192             :     case JFW_PLUGIN_E_INVALID_ARG:
    1193           0 :         ret = JFW_E_INVALID_ARG;
    1194           0 :         break;
    1195             :     case JFW_PLUGIN_E_ERROR:
    1196           0 :         ret = JFW_E_ERROR;
    1197           0 :         break;
    1198             :     default:
    1199           0 :         ret = JFW_E_ERROR;
    1200             :     }
    1201          98 :     return ret;
    1202             : }
    1203             : 
    1204           0 : void SAL_CALL jfw_lock()
    1205             : {
    1206           0 :     jfw::FwkMutex::get().acquire();
    1207           0 : }
    1208             : 
    1209           0 : void SAL_CALL jfw_unlock()
    1210             : {
    1211           0 :     jfw::FwkMutex::get().release();
    1212           0 : }
    1213             : 
    1214             : 
    1215             : namespace jfw
    1216             : {
    1217         114 : CJavaInfo::CJavaInfo(): pInfo(0)
    1218             : {
    1219         114 : }
    1220             : 
    1221           0 : CJavaInfo::CJavaInfo(const CJavaInfo & info)
    1222             : {
    1223           0 :     pInfo = copyJavaInfo(info.pInfo);
    1224           0 : }
    1225             : 
    1226           0 : CJavaInfo::CJavaInfo(::JavaInfo * info, _transfer_ownership)
    1227             : {
    1228           0 :     pInfo = info;
    1229           0 : }
    1230           0 : CJavaInfo CJavaInfo::createWrapper(::JavaInfo* info)
    1231             : {
    1232           0 :     return CJavaInfo(info, TRANSFER);
    1233             : }
    1234           4 : void CJavaInfo::attach(::JavaInfo * info)
    1235             : {
    1236           4 :     jfw_freeJavaInfo(pInfo);
    1237           4 :     pInfo = info;
    1238           4 : }
    1239          51 : ::JavaInfo * CJavaInfo::detach()
    1240             : {
    1241          51 :     JavaInfo * tmp = pInfo;
    1242          51 :     pInfo = NULL;
    1243          51 :     return tmp;
    1244             : }
    1245             : 
    1246         114 : CJavaInfo::~CJavaInfo()
    1247             : {
    1248         114 :     jfw_freeJavaInfo(pInfo);
    1249         114 : }
    1250             : 
    1251          16 : CJavaInfo::operator ::JavaInfo* ()
    1252             : {
    1253          16 :     return pInfo;
    1254             : }
    1255             : 
    1256          61 : JavaInfo * CJavaInfo::copyJavaInfo(const JavaInfo * pInfo)
    1257             : {
    1258          61 :     if (pInfo == NULL)
    1259           0 :         return NULL;
    1260             :     JavaInfo* newInfo =
    1261          61 :           (JavaInfo*) rtl_allocateMemory(sizeof(JavaInfo));
    1262          61 :     if (newInfo)
    1263             :     {
    1264          61 :         memcpy(newInfo, pInfo, sizeof(JavaInfo));
    1265          61 :         rtl_uString_acquire(pInfo->sVendor);
    1266          61 :         rtl_uString_acquire(pInfo->sLocation);
    1267          61 :         rtl_uString_acquire(pInfo->sVersion);
    1268          61 :         rtl_byte_sequence_acquire(pInfo->arVendorData);
    1269             :     }
    1270          61 :     return newInfo;
    1271             : }
    1272             : 
    1273             : 
    1274           4 : JavaInfo* CJavaInfo::cloneJavaInfo() const
    1275             : {
    1276           4 :     if (pInfo == NULL)
    1277           0 :         return NULL;
    1278           4 :     return copyJavaInfo(pInfo);
    1279             : }
    1280             : 
    1281           0 : CJavaInfo & CJavaInfo::operator = (const CJavaInfo& info)
    1282             : {
    1283           0 :     if (&info == this)
    1284           0 :         return *this;
    1285             : 
    1286           0 :     jfw_freeJavaInfo(pInfo);
    1287           0 :     pInfo = copyJavaInfo(info.pInfo);
    1288           0 :     return *this;
    1289             : }
    1290          57 : CJavaInfo & CJavaInfo::operator = (const ::JavaInfo* info)
    1291             : {
    1292          57 :     if (info == pInfo)
    1293           0 :         return *this;
    1294             : 
    1295          57 :     jfw_freeJavaInfo(pInfo);
    1296          57 :     pInfo = copyJavaInfo(info);
    1297          57 :     return *this;
    1298             : }
    1299             : 
    1300           0 : const ::JavaInfo* CJavaInfo::operator ->() const
    1301             : {
    1302           0 :     return pInfo;
    1303             : }
    1304             : 
    1305           0 : CJavaInfo::operator JavaInfo const * () const
    1306             : {
    1307           0 :     return pInfo;
    1308             : }
    1309             : 
    1310          49 : OUString CJavaInfo::getVendor() const
    1311             : {
    1312          49 :     if (pInfo)
    1313          49 :         return OUString(pInfo->sVendor);
    1314             :     else
    1315           0 :         return OUString();
    1316             : }
    1317             : 
    1318           4 : OUString CJavaInfo::getLocation() const
    1319             : {
    1320           4 :     if (pInfo)
    1321           0 :         return OUString(pInfo->sLocation);
    1322             :     else
    1323           4 :         return OUString();
    1324             : }
    1325             : 
    1326           0 : sal_uInt64 CJavaInfo::getFeatures() const
    1327             : {
    1328           0 :     if (pInfo)
    1329           0 :         return pInfo->nFeatures;
    1330             :     else
    1331           0 :         return 0l;
    1332             : }
    1333             : 
    1334             : }
    1335             : 
    1336             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10