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

Generated by: LCOV version 1.10