diff options
author | Jens-Heiner Rechtien <hr@openoffice.org> | 2004-11-09 15:12:48 +0000 |
---|---|---|
committer | Jens-Heiner Rechtien <hr@openoffice.org> | 2004-11-09 15:12:48 +0000 |
commit | 7aae12836e311fc43b487a0f57bf2f5eb0a50ffa (patch) | |
tree | 4dd698f7afc04819598ce2deaea018d19e20e5ac | |
parent | 05e53df2941f765fb521731b62a06fc0faaae655 (diff) |
INTEGRATION: CWS jl13 (1.19.8); FILE MERGED
2004/10/21 13:17:35 jl 1.19.8.7: RESYNC: (1.19-1.20); FILE MERGED
2004/10/08 17:31:03 jl 1.19.8.6: #29930#
2004/10/05 15:22:11 jl 1.19.8.5: #i29390#
2004/10/01 09:19:12 jl 1.19.8.4: #i29390#
2004/09/30 14:39:32 jl 1.19.8.3: #i29390#
2004/09/30 08:16:01 jl 1.19.8.2: #i29390#
2004/09/29 13:43:50 jl 1.19.8.1: #i29390# using framework in other applications
-rw-r--r-- | jvmfwk/source/framework.cxx | 1627 |
1 files changed, 858 insertions, 769 deletions
diff --git a/jvmfwk/source/framework.cxx b/jvmfwk/source/framework.cxx index 8eff841fce18..32f15523302d 100644 --- a/jvmfwk/source/framework.cxx +++ b/jvmfwk/source/framework.cxx @@ -2,9 +2,9 @@ * * $RCSfile: framework.cxx,v $ * - * $Revision: 1.21 $ + * $Revision: 1.22 $ * - * last change: $Author: hr $ $Date: 2004-11-09 11:52:29 $ + * last change: $Author: hr $ $Date: 2004-11-09 16:12:48 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -60,29 +60,18 @@ ************************************************************************/ #include "boost/scoped_array.hpp" #include "rtl/ustring.hxx" -#include "rtl/ustrbuf.hxx" +#include "rtl/bootstrap.hxx" #include "osl/thread.hxx" #include "osl/module.hxx" -#include "osl/process.h" -#include "sal/config.h" #include "jvmfwk/framework.h" #include "jvmfwk/vendorplugin.h" -#include "osl/mutex.hxx" -#include "libxml/parser.h" -#include "libxml/xpath.h" -#include "libxml/xpathInternals.h" #include <vector> -#include <algorithm> #include <functional> -#ifdef SOLAR_JAVA -#include "jni.h" -#endif - +#include <algorithm> #include "framework.hxx" -#include "libxmlutil.hxx" #include "fwkutil.hxx" #include "elements.hxx" -//#define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) ) +#include "fwkbase.hxx" #ifdef WNT /** The existence of the file useatjava.txt decides if a Java should be used @@ -91,6 +80,7 @@ #define USE_ACCESSIBILITY_FILE "useatjava.txt" #endif +#define UNO_JAVA_JFW_JREHOME "UNO_JAVA_JFW_JREHOME" namespace { JavaVM * g_pJavaVM = NULL; @@ -101,243 +91,182 @@ sal_Bool areEqualJavaInfo( { return jfw_areEqualJavaInfo(pInfoA, pInfoB); } - -struct EqualInfo -{ - const JavaInfo *pInfo; - EqualInfo(const JavaInfo* info):pInfo(info){} - - bool operator () (const JavaInfo* pInfo2) - { - return areEqualJavaInfo(pInfo, pInfo2) == sal_True ? true : false; - } -}; - -void freeJavaInfo( JavaInfo * pInfo) -{ - jfw_freeJavaInfo(pInfo); -} - } javaFrameworkError SAL_CALL jfw_findAllJREs(JavaInfo ***pparInfo, sal_Int32 *pSize) { - osl::MutexGuard guard(jfw::getFwkMutex()); - javaFrameworkError errcode = JFW_E_NONE; - if (pparInfo == NULL || pSize == NULL) - return JFW_E_INVALID_ARG; - - //Prepare the xml document and context - rtl::OString sSettingsPath = jfw::getVendorSettingsPath(); - jfw::CXmlDocPtr doc(xmlParseFile(sSettingsPath.getStr())); - if (doc == NULL) + javaFrameworkError retVal = JFW_E_NONE; + try { - OSL_ASSERT(0); - return JFW_E_ERROR; - } - jfw::CXPathContextPtr context(xmlXPathNewContext(doc)); - int reg = xmlXPathRegisterNs(context, (xmlChar*) "jf", - (xmlChar*) NS_JAVA_FRAMEWORK); - if (reg == -1) - return JFW_E_ERROR; - - //Get a list of plugins which provide Java information - std::vector<jfw::PluginLibrary> vecPlugins; - errcode = jfw::getVendorPluginURLs(doc, context, & vecPlugins); - if (errcode != JFW_E_NONE) - return errcode; + osl::MutexGuard guard(jfw::getFwkMutex()); + javaFrameworkError errcode = JFW_E_NONE; + if (pparInfo == NULL || pSize == NULL) + return JFW_E_INVALID_ARG; + + jfw::VendorSettings aVendorSettings; + //Get a list of plugins which provide Java information + std::vector<jfw::PluginLibrary> vecPlugins = + aVendorSettings.getPluginData(); + //Add the JavaInfos found by jfw_plugin_getAllJavaInfos to the vector + //Make sure that the contents are destroyed if this + //function returns with an error + std::vector<jfw::CJavaInfo> vecInfo; + //Add the JavaInfos found by jfw_plugin_getJavaInfoByPath to this vector + //Make sure that the contents are destroyed if this + //function returns with an error + std::vector<jfw::CJavaInfo> vecInfoManual; + typedef std::vector<jfw::CJavaInfo>::iterator it_info; + //get the list of paths to jre locations which have been + //added manually + jfw::CNodeJava node; + node.loadFromSettings(); + const std::vector<rtl::OString>& vecJRELocations = + node.getJRELocations(); + //Use every plug-in library to get Java installations. + typedef std::vector<jfw::PluginLibrary>::const_iterator ci_pl; + for (ci_pl i = vecPlugins.begin(); i != vecPlugins.end(); i++) + { + const jfw::PluginLibrary & library = *i; + //todo : adapt getVersionInformation to receive an empty string + jfw::VersionInfo versionInfo = + aVendorSettings.getVersionInformation(library.sVendor); - //Add the JavaInfos found by jfw_plugin_getAllJavaInfos to the vector - //Make sure that the contents are destroyed if this - //function returns with an error - std::vector<JavaInfo*> vecInfo; - //Add the JavaInfos found by jfw_plugin_getJavaInfoByPath to this vector - //Make sure that the contents are destroyed if this - //function returns with an error - std::vector<JavaInfo*> vecInfoManual; - typedef std::vector<JavaInfo*>::iterator it_info; - //get the list of paths to jre locations which have been - //added manually - jfw::CNodeJava node; - errcode = node.loadFromSettings(); - if (errcode != JFW_E_NONE) - return errcode; + osl::Module pluginLib(library.sPath); + if (pluginLib.is() == sal_False) + { + rtl::OString msg = rtl::OUStringToOString( + library.sPath, osl_getThreadTextEncoding()); + fprintf(stderr,"[jvmfwk] Could not load plugin %s\n" \ + "Modify the javavendors.xml accordingly!\n", msg.getStr()); + return JFW_E_NO_PLUGIN; + } + jfw_plugin_getAllJavaInfos_ptr getAllJavaFunc = + (jfw_plugin_getAllJavaInfos_ptr) pluginLib.getSymbol( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("jfw_plugin_getAllJavaInfos"))); - const std::vector<rtl::OString>& vecJRELocations = - node.getJRELocations(); - //Use every plug-in library to get Java installations. - typedef std::vector<jfw::PluginLibrary>::const_iterator ci_pl; - for (ci_pl i = vecPlugins.begin(); i != vecPlugins.end(); i++) - { - const jfw::PluginLibrary & library = *i; - jfw::VersionInfo versionInfo; - errcode = jfw::getVersionInformation(doc, context, library.sVendor, - & versionInfo); - if (errcode != JFW_E_NONE) - { //delete JavaInfo objects - std::for_each(vecInfo.begin(), vecInfo.end(), freeJavaInfo); - std::for_each(vecInfoManual.begin(), vecInfoManual.end(), - freeJavaInfo); - return JFW_E_CONFIG_READWRITE; - } - osl::Module pluginLib(library.sPath); - if (pluginLib.is() == sal_False) - { - //delete JavaInfo objects - std::for_each(vecInfo.begin(), vecInfo.end(), freeJavaInfo); - std::for_each(vecInfoManual.begin(), vecInfoManual.end(), - freeJavaInfo); - - rtl::OString msg = rtl::OUStringToOString( - library.sPath, osl_getThreadTextEncoding()); - fprintf(stderr,"[jvmfwk] Could not load plugin %s\n" \ - "Modify the javavendors.xml accordingly!\n", msg.getStr()); - return JFW_E_NO_PLUGIN; - } - jfw_plugin_getAllJavaInfos_ptr getAllJavaFunc = - (jfw_plugin_getAllJavaInfos_ptr) pluginLib.getSymbol( - rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("jfw_plugin_getAllJavaInfos"))); + OSL_ASSERT(getAllJavaFunc); + if (getAllJavaFunc == NULL) + return JFW_E_ERROR; - OSL_ASSERT(getAllJavaFunc); - if (getAllJavaFunc == NULL) - { - //delete JavaInfo objects - std::for_each(vecInfo.begin(), vecInfo.end(), freeJavaInfo); - std::for_each(vecInfoManual.begin(), vecInfoManual.end(), - freeJavaInfo); - return JFW_E_ERROR; - } - //get all installations of one vendor according to minVersion, - //maxVersion and excludeVersions - sal_Int32 cInfos = 0; - JavaInfo** arInfos = NULL; - javaPluginError plerr = (*getAllJavaFunc)( - library.sVendor.pData, - versionInfo.sMinVersion.pData, - versionInfo.sMaxVersion.pData, - versionInfo.getExcludeVersions(), - versionInfo.getExcludeVersionSize(), - & arInfos, - & cInfos); - - if (plerr != JFW_PLUGIN_E_NONE) - { //delete JavaInfo objects - std::for_each(vecInfo.begin(), vecInfo.end(), freeJavaInfo); - std::for_each(vecInfoManual.begin(), vecInfoManual.end(), - freeJavaInfo); - return JFW_E_ERROR; - } - for (int i = 0; i < cInfos; i++) - vecInfo.push_back(arInfos[i]); - rtl_freeMemory(arInfos); - - //Check if the current plugin can detect JREs at the location - // of the paths added by jfw_setJRELocations or jfw_addJRELocation - //get the function from the plugin - jfw_plugin_getJavaInfoByPath_ptr jfw_plugin_getJavaInfoByPathFunc = - (jfw_plugin_getJavaInfoByPath_ptr) pluginLib.getSymbol( - rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("jfw_plugin_getJavaInfoByPath"))); - - OSL_ASSERT(jfw_plugin_getJavaInfoByPathFunc); - if (jfw_plugin_getJavaInfoByPathFunc == NULL) - { //delete JavaInfo objects - std::for_each(vecInfo.begin(), vecInfo.end(), freeJavaInfo); - std::for_each(vecInfoManual.begin(), vecInfoManual.end(), - freeJavaInfo); - return JFW_E_ERROR; - } - typedef std::vector<rtl::OString>::const_iterator citLoc; - //Check every manually added location - for (citLoc ii = vecJRELocations.begin(); - ii != vecJRELocations.end(); ii++) - { - rtl::OUString sLocation = - rtl::OStringToOUString(*ii, RTL_TEXTENCODING_UTF8); - JavaInfo* pInfo = NULL; - plerr = (*jfw_plugin_getJavaInfoByPathFunc)( - sLocation.pData, + //get all installations of one vendor according to minVersion, + //maxVersion and excludeVersions + sal_Int32 cInfos = 0; + JavaInfo** arInfos = NULL; + javaPluginError plerr = (*getAllJavaFunc)( + library.sVendor.pData, versionInfo.sMinVersion.pData, versionInfo.sMaxVersion.pData, versionInfo.getExcludeVersions(), versionInfo.getExcludeVersionSize(), - & pInfo); - if (plerr == JFW_PLUGIN_E_NO_JRE) - continue; - if (plerr == JFW_PLUGIN_E_FAILED_VERSION) - continue; - else if (plerr !=JFW_PLUGIN_E_NONE) - { //delete JavaInfo objects - std::for_each(vecInfo.begin(), vecInfo.end(), freeJavaInfo); - std::for_each(vecInfoManual.begin(), vecInfoManual.end(), - freeJavaInfo); + & arInfos, + & cInfos); + + if (plerr != JFW_PLUGIN_E_NONE) return JFW_E_ERROR; - } - if (pInfo) + + for (int i = 0; i < cInfos; i++) + vecInfo.push_back(jfw::CJavaInfo::createWrapper(arInfos[i])); + + rtl_freeMemory(arInfos); + + //Check if the current plugin can detect JREs at the location + // of the paths added by jfw_setJRELocations or jfw_addJRELocation + //get the function from the plugin + jfw_plugin_getJavaInfoByPath_ptr jfw_plugin_getJavaInfoByPathFunc = + (jfw_plugin_getJavaInfoByPath_ptr) pluginLib.getSymbol( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("jfw_plugin_getJavaInfoByPath"))); + + OSL_ASSERT(jfw_plugin_getJavaInfoByPathFunc); + if (jfw_plugin_getJavaInfoByPathFunc == NULL) + return JFW_E_ERROR; + + typedef std::vector<rtl::OString>::const_iterator citLoc; + //Check every manually added location + for (citLoc ii = vecJRELocations.begin(); + ii != vecJRELocations.end(); ii++) { - //Was this JRE already added?. Different plugins could detect - //the same JRE - it_info it_duplicate = - std::find_if(vecInfoManual.begin(), vecInfoManual.end(), - EqualInfo(pInfo)); - if (it_duplicate == vecInfoManual.end()) - vecInfoManual.push_back(pInfo); - else - jfw_freeJavaInfo(pInfo); + rtl::OUString sLocation = + rtl::OStringToOUString(*ii, RTL_TEXTENCODING_UTF8); + jfw::CJavaInfo aInfo; + plerr = (*jfw_plugin_getJavaInfoByPathFunc)( + sLocation.pData, + versionInfo.sMinVersion.pData, + versionInfo.sMaxVersion.pData, + versionInfo.getExcludeVersions(), + versionInfo.getExcludeVersionSize(), + & aInfo.pInfo); + if (plerr == JFW_PLUGIN_E_NO_JRE) + continue; + if (plerr == JFW_PLUGIN_E_FAILED_VERSION) + continue; + else if (plerr !=JFW_PLUGIN_E_NONE) + return JFW_E_ERROR; + + if (aInfo) + { + //Was this JRE already added?. Different plugins could detect + //the same JRE + it_info it_duplicate = + std::find_if(vecInfoManual.begin(), vecInfoManual.end(), + std::bind2nd(std::ptr_fun(areEqualJavaInfo), aInfo)); + if (it_duplicate == vecInfoManual.end()) + vecInfoManual.push_back(aInfo); + } } } - } - //Make sure vecInfoManual contains only JavaInfos for the vendors for which - //there is a javaSelection/plugins/library entry in the javavendors.xml - //To obtain the JavaInfos for the manually added JRE locations the function - //jfw_getJavaInfoByPath is called which can return a JavaInfo of any vendor. - std::vector<JavaInfo*> vecInfoManual2; - for (it_info ivm = vecInfoManual.begin(); ivm != vecInfoManual.end(); ivm++) - { - bool bAllowedVendor = false; - for (ci_pl ii = vecPlugins.begin(); ii != vecPlugins.end(); ii++) + //Make sure vecInfoManual contains only JavaInfos for the vendors for which + //there is a javaSelection/plugins/library entry in the javavendors.xml + //To obtain the JavaInfos for the manually added JRE locations the function + //jfw_getJavaInfoByPath is called which can return a JavaInfo of any vendor. + std::vector<jfw::CJavaInfo> vecInfoManual2; + for (it_info ivm = vecInfoManual.begin(); ivm != vecInfoManual.end(); ivm++) { - if ( ii->sVendor.equals((*ivm)->sVendor)) + for (ci_pl ii = vecPlugins.begin(); ii != vecPlugins.end(); ii++) { - vecInfoManual2.push_back(*ivm); - bAllowedVendor = true; - break; + if ( ii->sVendor.equals((*ivm)->sVendor)) + { + vecInfoManual2.push_back(*ivm); + break; + } } } - if (bAllowedVendor == false) - jfw_freeJavaInfo(*ivm); + //Check which JavaInfo from vector vecInfoManual2 is already + //contained in vecInfo. If it already exists then remove it from + //vecInfoManual2 + for (it_info j = vecInfo.begin(); j != vecInfo.end(); j++) + { + it_info it_duplicate = + std::find_if(vecInfoManual2.begin(), vecInfoManual2.end(), + std::bind2nd(std::ptr_fun(areEqualJavaInfo), *j)); + if (it_duplicate != vecInfoManual2.end()) + vecInfoManual2.erase(it_duplicate); + } + //create an fill the array of JavaInfo* + sal_Int32 nSize = vecInfo.size() + vecInfoManual2.size(); + *pparInfo = (JavaInfo**) rtl_allocateMemory( + nSize * sizeof(JavaInfo*)); + if (*pparInfo == NULL) + return JFW_E_ERROR; + + typedef std::vector<jfw::CJavaInfo>::iterator it; + int index = 0; + //Add the automatically detected JREs + for (it k = vecInfo.begin(); k != vecInfo.end(); k++) + (*pparInfo)[index++] = k->detach(); + //Add the manually detected JREs + for (it l = vecInfoManual2.begin(); l != vecInfoManual2.end(); l++) + (*pparInfo)[index++] = l->detach(); + + *pSize = nSize; + return errcode; } - //Check which JavaInfo from vector vecInfoManual2 is already - //contained in vecInfo. If it already exists then remove it from - //vecInfoManual2 - for (it_info j = vecInfo.begin(); j != vecInfo.end(); j++) + catch (jfw::FrameworkException& e) { - it_info it_duplicate = - std::find_if(vecInfoManual2.begin(), vecInfoManual2.end(), - std::bind2nd(std::ptr_fun(areEqualJavaInfo), *j)); - if (it_duplicate != vecInfoManual2.end()) - vecInfoManual2.erase(it_duplicate); + retVal = e.errorCode; + fprintf(stderr, e.message.getStr()); + OSL_ENSURE(0, e.message.getStr()); } - //create an fill the array of JavaInfo* - sal_Int32 nSize = vecInfo.size() + vecInfoManual2.size(); - *pparInfo = (JavaInfo**) rtl_allocateMemory( - nSize * sizeof(JavaInfo*)); - if (*pparInfo == NULL) - { //delete JavaInfo objects - std::for_each(vecInfo.begin(), vecInfo.end(), freeJavaInfo); - std::for_each(vecInfoManual2.begin(), vecInfoManual2.end(), freeJavaInfo); - return JFW_E_ERROR; - } - typedef std::vector<JavaInfo*>::iterator it; - int index = 0; - //Add the automatically detected JREs - for (it k = vecInfo.begin(); k != vecInfo.end(); k++) - (*pparInfo)[index++] = *k; - //Add the manually detected JREs - for (it l = vecInfoManual2.begin(); l != vecInfoManual2.end(); l++) - (*pparInfo)[index++] = *l; - - *pSize = nSize; - return errcode; + return retVal; } javaFrameworkError SAL_CALL jfw_startVM(JavaVMOption *arOptions, sal_Int32 cOptions, @@ -346,178 +275,202 @@ javaFrameworkError SAL_CALL jfw_startVM(JavaVMOption *arOptions, sal_Int32 cOpti #ifndef SOLAR_JAVA return JFW_E_ERROR; #else - osl::MutexGuard guard(jfw::getFwkMutex()); javaFrameworkError errcode = JFW_E_NONE; - //We keep this pointer so we can determine if a VM has already - //been created. - if (g_pJavaVM != NULL) - return JFW_E_RUNNING_JVM; - if (ppVM == NULL) - return JFW_E_INVALID_ARG; + try + { + osl::MutexGuard guard(jfw::getFwkMutex()); + + //We keep this pointer so we can determine if a VM has already + //been created. + if (g_pJavaVM != NULL) + return JFW_E_RUNNING_JVM; + //check if Java is disabled + sal_Bool bEnabled = sal_False; + if ((errcode = jfw_getEnabled(&bEnabled)) == JFW_E_NONE) + { + if (bEnabled == sal_False) + return JFW_E_JAVA_DISABLED; + } + else + { + return errcode; + } - jfw::CNodeJava javaSettings; - jfw::CJavaInfo aInfo; - jfw::JFW_MODE mode = jfw::getMode(); + if (ppVM == NULL) + return JFW_E_INVALID_ARG; - if (mode == jfw::JFW_MODE_OFFICE) - { -#ifdef WNT - //Because on Windows there is no system setting that we can use to determine - //if Assistive Technology Tool support is needed, we ship a .reg file that the - //user can use to create a registry setting. When the user forgets to set - //the key before he starts the office then a JRE may be selected without access bridge. - //When he later sets the key then we select a JRE with accessibility support but - //only if the user has not manually changed the selected JRE in the options dialog. - if (jfw::isAccessibilitySupportDesired()) + jfw::CNodeJava javaSettings; + jfw::CJavaInfo aInfo; + jfw::JFW_MODE mode = jfw::getMode(); + + if (mode == jfw::JFW_MODE_APPLICATION) { - jfw::CJavaInfo info = NULL; - javaFrameworkError err = JFW_E_NONE; - if ((err = jfw_getSelectedJRE( & info)) != JFW_E_NONE) - return err; - // If no JRE has been selected then we do no select one. This function shall then - //return JFW_E_NO_SELECT - if (info != NULL && - (info->nFeatures & JFW_FEATURE_ACCESSBRIDGE) == 0) +#ifdef WNT + //Because on Windows there is no system setting that we can use to determine + //if Assistive Technology Tool support is needed, we ship a .reg file that the + //user can use to create a registry setting. When the user forgets to set + //the key before he starts the office then a JRE may be selected without access bridge. + //When he later sets the key then we select a JRE with accessibility support but + //only if the user has not manually changed the selected JRE in the options dialog. + if (jfw::isAccessibilitySupportDesired()) { - //has the user manually selected a JRE? - jfw::CNodeJava settings; - if ((errcode = settings.loadFromSettings()) != JFW_E_NONE) - return errcode; - if (settings.getJavaInfoAttrAutoSelect() == true) + jfw::CJavaInfo info; + javaFrameworkError err = JFW_E_NONE; + if ((err = jfw_getSelectedJRE( & info.pInfo)) != JFW_E_NONE) + return err; + // If no JRE has been selected then we do no select one. This function shall then + //return JFW_E_NO_SELECT + if (info != NULL && + (info->nFeatures & JFW_FEATURE_ACCESSBRIDGE) == 0) { - //The currently selected JRE has no access bridge - if ((err = jfw_findAndSelectJRE(NULL)) != JFW_E_NONE) - return err; + //has the user manually selected a JRE? + jfw::CNodeJava settings; + settings.loadFromSettings(); + if (settings.getJavaInfoAttrAutoSelect() == true) + { + //The currently selected JRE has no access bridge + if ((err = jfw_findAndSelectJRE(NULL)) != JFW_E_NONE) + return err; + } } } - } #endif - if ((errcode = javaSettings.loadFromSettings()) != JFW_E_NONE) - return errcode; + javaSettings.loadFromSettings(); + + //get the current java setting (javaInfo) + aInfo = jfw::CJavaInfo::createWrapper(javaSettings.createJavaInfo()); + + //check if a Java has ever been selected + if (aInfo == NULL) + return JFW_E_NO_SELECT; + //check if the javavendors.xml has changed after a Java was selected + rtl::OString sVendorUpdate = jfw::getElementUpdated(); + + if (sVendorUpdate != javaSettings.getJavaInfoAttrVendorUpdate()) + return JFW_E_INVALID_SETTINGS; + + //check if JAVA is disabled + //If Java is enabled, but it was disabled when this process was started + // then no preparational work, such as setting the LD_LIBRARY_PATH, was + //done. Therefore if a JRE needs it it must not be started. + if (g_bEnabledSwitchedOn && + (aInfo->nRequirements & JFW_REQUIRE_NEEDRESTART)) + return JFW_E_NEED_RESTART; + + //Check if the selected Java was set in this process. If so it + //must not have the requirments flag JFW_REQUIRE_NEEDRESTART + if ((aInfo->nRequirements & JFW_REQUIRE_NEEDRESTART) + && + (jfw::wasJavaSelectedInSameProcess() == true)) + return JFW_E_NEED_RESTART; + } // end mode FWK_MODE_OFFICE + else if (mode == jfw::JFW_MODE_DIRECT) + { + errcode = jfw_getSelectedJRE(&aInfo.pInfo); + if (errcode != JFW_E_NONE) + return errcode; + } + else + OSL_ASSERT(0); - //get the current java setting (javaInfo) - aInfo = javaSettings.getJavaInfo(); - //check if a Java has ever been selected - if (aInfo == NULL) - return JFW_E_NO_SELECT; - //check if the javavendors.xml has changed after a Java was selected - rtl::OString sVendorUpdate; - if ((errcode = jfw::getElementUpdated(sVendorUpdate)) - != JFW_E_NONE) - return errcode; - if (sVendorUpdate != javaSettings.getJavaInfoAttrVendorUpdate()) - return JFW_E_INVALID_SETTINGS; + //get the function jfw_plugin_startJavaVirtualMachine + jfw::VendorSettings aVendorSettings; + rtl::OUString sLibPath = aVendorSettings.getPluginLibrary(aInfo.getVendor()); - //check if JAVA is disabled - //If Java is enabled, but it was disabled when this process was started - // then no preparational work, such as setting the LD_LIBRARY_PATH, was - //done. Therefore if a JRE needs it it must not be started. - if (javaSettings.getEnabled() == sal_False) - return JFW_E_JAVA_DISABLED; - else if (g_bEnabledSwitchedOn && - (aInfo->nRequirements & JFW_REQUIRE_NEEDRESTART)) - return JFW_E_NEED_RESTART; - - //Check if the selected Java was set in this process. If so it - //must not have the requirments flag JFW_REQUIRE_NEEDRESTART - if ((aInfo->nRequirements & JFW_REQUIRE_NEEDRESTART) - && - (jfw::wasJavaSelectedInSameProcess() == true)) - return JFW_E_NEED_RESTART; - } // end mode FWK_MODE_OFFICE - else if (mode == jfw::JFW_MODE_ENV_SIMPLE) - { - rtl::OUString sOO_USE_JRE(RTL_CONSTASCII_USTRINGPARAM(ENVIRONMENT_VAR_JRE_PATH)); + osl::Module modulePlugin(sLibPath); + if ( ! modulePlugin) + return JFW_E_NO_PLUGIN; - //get JAVA_HOME - rtl_uString * psJAVA_HOME = 0; - if (osl_getEnvironment(sOO_USE_JRE.pData, & psJAVA_HOME) != osl_Process_E_None) + rtl::OUString sFunctionName( + RTL_CONSTASCII_USTRINGPARAM("jfw_plugin_startJavaVirtualMachine")); + jfw_plugin_startJavaVirtualMachine_ptr pFunc = + (jfw_plugin_startJavaVirtualMachine_ptr) + osl_getSymbol(modulePlugin, sFunctionName.pData); + if (pFunc == NULL) return JFW_E_ERROR; - rtl::OUString sJAVA_HOME(psJAVA_HOME, SAL_NO_ACQUIRE); - //convert to file URL - rtl_uString * pJavaUrl = 0; - if (osl_getFileURLFromSystemPath(sJAVA_HOME.pData, & pJavaUrl) != osl_File_E_None) + + // create JavaVMOptions array that is passed to the plugin + // it contains the classpath and all options set in the + //options dialog + //In direct mode the options are specified by bootstrap variables + //of the form UNO_JAVA_JFW_PARAMETER_1 .. UNO_JAVA_JFW_PARAMETER_n + if (cOptions > 0 && arOptions == NULL) + return JFW_E_INVALID_ARG; + + std::vector<rtl::OString> vecDirectModeOptions = + jfw::BootParams::getVMParameters(); + + boost::scoped_array<JavaVMOption> sarJOptions; + + if (mode == jfw::JFW_MODE_APPLICATION) + sarJOptions.reset(new JavaVMOption[cOptions + 2 + javaSettings.getVmParameters().size()]); + else // direct mode + sarJOptions.reset(new JavaVMOption[cOptions + 2 + vecDirectModeOptions.size()]); + + JavaVMOption * arOpt = sarJOptions.get(); + if (! arOpt) return JFW_E_ERROR; - rtl::OUString sJavaUrl(pJavaUrl, SAL_NO_ACQUIRE); - if ((errcode = jfw_getJavaInfoByPath(sJavaUrl.pData, & aInfo)) - != JFW_E_NONE) - return errcode; - } - //get the function jfw_plugin_startJavaVirtualMachine - rtl::OUString sLibPath; - if ((errcode = jfw::getPluginLibrary(aInfo.getVendor(), sLibPath)) != JFW_E_NONE) - return errcode; - osl::Module modulePlugin(sLibPath); - if ( ! modulePlugin) - return JFW_E_NO_PLUGIN; - - rtl::OUString sFunctionName( - RTL_CONSTASCII_USTRINGPARAM("jfw_plugin_startJavaVirtualMachine")); - jfw_plugin_startJavaVirtualMachine_ptr pFunc = - (jfw_plugin_startJavaVirtualMachine_ptr) - osl_getSymbol(modulePlugin, sFunctionName.pData); - if (pFunc == NULL) - return JFW_E_ERROR; - - // create JavaVMOptions array that is passed to the plugin - // it contains the classpath and all options set in the - //options dialog - if (cOptions > 0 && arOptions == NULL) - return JFW_E_INVALID_ARG; - boost::scoped_array<JavaVMOption> sarJOptions( - new JavaVMOption[cOptions + 2 + javaSettings.getVmParameters().size()]); - JavaVMOption * arOpt = sarJOptions.get(); - if (! arOpt) - return JFW_E_ERROR; - - //The first argument is the classpath - rtl::OString sOptionClassPath; - if ((errcode = jfw::makeClassPathOption( - mode, javaSettings, sOptionClassPath)) != JFW_E_NONE) - return errcode; - arOpt[0].optionString= (char*) sOptionClassPath.getStr(); - arOpt[0].extraInfo = NULL; - // Set a flag that this JVM has been created via the JNI Invocation API - // (used, for example, by UNO remote bridges to share a common thread pool - // factory among Java and native bridge implementations): - arOpt[1].optionString = "-Dorg.openoffice.native="; - arOpt[1].extraInfo = 0; - - //add the options set by options dialog - typedef std::vector<rtl::OString>::const_iterator cit; - const std::vector<rtl::OString> & params = javaSettings.getVmParameters(); - int index = 2; - for (cit i = params.begin(); i != params.end(); i ++) - { - arOpt[index].optionString= (char*) i->getStr(); - arOpt[index].extraInfo = 0; - index ++; - } - //add all options of the arOptions argument - for (int ii = 0; ii < cOptions; ii++) - { - arOpt[index].optionString = arOptions[ii].optionString; - arOpt[index].extraInfo = arOptions[ii].extraInfo; - index++; - } - //start Java - JavaVM *pVm = NULL; - javaPluginError plerr = (*pFunc)(aInfo, arOpt, index, & pVm, ppEnv); - if (plerr == JFW_PLUGIN_E_VM_CREATION_FAILED) - { - errcode = JFW_E_VM_CREATION_FAILED; - } - else if (plerr != JFW_PLUGIN_E_NONE ) - { - errcode = JFW_E_ERROR; + //The first argument is the classpath + rtl::OString sOptionClassPath = + jfw::makeClassPathOption(javaSettings); + arOpt[0].optionString= (char*) sOptionClassPath.getStr(); + arOpt[0].extraInfo = NULL; + // Set a flag that this JVM has been created via the JNI Invocation API + // (used, for example, by UNO remote bridges to share a common thread pool + // factory among Java and native bridge implementations): + arOpt[1].optionString = (char *) "-Dorg.openoffice.native="; + arOpt[1].extraInfo = 0; + + //add the options set by options dialog + typedef std::vector<rtl::OString>::const_iterator cit; + std::vector<rtl::OString> params; + + if (mode == jfw::JFW_MODE_APPLICATION) + params = javaSettings.getVmParameters(); + else // JFW_MODE_DIRECT + params = vecDirectModeOptions; + + int index = 2; + for (cit i = params.begin(); i != params.end(); i ++) + { + arOpt[index].optionString= (char*) i->getStr(); + arOpt[index].extraInfo = 0; + index ++; + } + //add all options of the arOptions argument + for (int ii = 0; ii < cOptions; ii++) + { + arOpt[index].optionString = arOptions[ii].optionString; + arOpt[index].extraInfo = arOptions[ii].extraInfo; + index++; + } + + //start Java + JavaVM *pVm = NULL; + javaPluginError plerr = (*pFunc)(aInfo, arOpt, index, & pVm, ppEnv); + if (plerr == JFW_PLUGIN_E_VM_CREATION_FAILED) + { + errcode = JFW_E_VM_CREATION_FAILED; + } + else if (plerr != JFW_PLUGIN_E_NONE ) + { + errcode = JFW_E_ERROR; + } + else + { + g_pJavaVM = pVm; + *ppVM = pVm; + } + OSL_ASSERT(plerr != JFW_PLUGIN_E_WRONG_VENDOR); } - else + catch (jfw::FrameworkException& e) { - g_pJavaVM = pVm; - *ppVM = pVm; + errcode = e.errorCode; + fprintf(stderr, e.message.getStr()); + OSL_ENSURE(0, e.message.getStr()); } - OSL_ASSERT(plerr != JFW_PLUGIN_E_WRONG_VENDOR); + return errcode; #endif } @@ -530,205 +483,197 @@ javaFrameworkError SAL_CALL jfw_startVM(JavaVMOption *arOptions, sal_Int32 cOpti */ javaFrameworkError SAL_CALL jfw_findAndSelectJRE(JavaInfo **pInfo) { - osl::MutexGuard guard(jfw::getFwkMutex()); javaFrameworkError errcode = JFW_E_NONE; - sal_Int64 nFeatureFlags = 0L; - jfw::CJavaInfo aCurrentInfo; - //Prepare the xml document and context - rtl::OString sSettingsPath = jfw::getVendorSettingsPath(); - jfw::CXmlDocPtr doc(xmlParseFile(sSettingsPath.getStr())); - if (doc == NULL) - { - OSL_ASSERT(0); - return JFW_E_ERROR; - } - jfw::CXPathContextPtr context(xmlXPathNewContext(doc)); - int reg = xmlXPathRegisterNs(context, (xmlChar*) "jf", - (xmlChar*) NS_JAVA_FRAMEWORK); - if (reg == -1) - return JFW_E_ERROR; - //Determine if accessibility support is needed - bool bSupportAccessibility = jfw::isAccessibilitySupportDesired(); - nFeatureFlags = bSupportAccessibility ? - JFW_FEATURE_ACCESSBRIDGE : 0L; - - //Get a list of services which provide Java information - std::vector<jfw::PluginLibrary> vecPlugins; - errcode = jfw::getVendorPluginURLs(doc, context, & vecPlugins); - if (errcode != JFW_E_NONE) - return errcode; - - //Use every plug-in library to get Java installations. At the first usable - //Java the loop will break - typedef std::vector<jfw::PluginLibrary>::const_iterator ci_pl; - for (ci_pl i = vecPlugins.begin(); i != vecPlugins.end(); i++) + try { - const jfw::PluginLibrary & library = *i; - jfw::VersionInfo versionInfo; - errcode = jfw::getVersionInformation(doc, context, library.sVendor, - & versionInfo); - if (errcode != JFW_E_NONE) - return JFW_E_CONFIG_READWRITE; - osl::Module pluginLib(library.sPath); - if (pluginLib.is() == sal_False) - return JFW_E_NO_PLUGIN; - - jfw_plugin_getAllJavaInfos_ptr getAllJavaFunc = - (jfw_plugin_getAllJavaInfos_ptr) pluginLib.getSymbol( - rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("jfw_plugin_getAllJavaInfos"))); - - OSL_ASSERT(getAllJavaFunc); - if (getAllJavaFunc == NULL) - continue; - - //get all installations of one vendor according to minVersion, - //maxVersion and excludeVersions - sal_Int32 cInfos = 0; - JavaInfo** arInfos = NULL; - javaPluginError plerr = (*getAllJavaFunc)( - library.sVendor.pData, - versionInfo.sMinVersion.pData, - versionInfo.sMaxVersion.pData, - versionInfo.getExcludeVersions(), - versionInfo.getExcludeVersionSize(), - & arInfos, - & cInfos); - - if (plerr != JFW_PLUGIN_E_NONE) - continue; - //iterate over all installations to find the best which has - //all features - if (cInfos == 0) - { - rtl_freeMemory(arInfos); - continue; - } - bool bInfoFound = false; - for (int ii = 0; ii < cInfos; ii++) - { - JavaInfo* pInfo = arInfos[ii]; - - //We remember the very first installation in aCurrentInfo - if (aCurrentInfo.getLocation().getLength() == 0) - aCurrentInfo = pInfo; - // compare features - // If the user does not require any features (nFeatureFlags = 0) - // then the first installation is used - if ((pInfo->nFeatures & nFeatureFlags) == nFeatureFlags) - { - //the just found Java implements all required features - //currently there is only accessibility!!! - aCurrentInfo = pInfo; - bInfoFound = true; - break; - } - } - //The array returned by jfw_plugin_getAllJavaInfos must be freed as well as - //its contents - for (int i = 0; i < cInfos; i++) - jfw_freeJavaInfo(arInfos[i]); - rtl_freeMemory(arInfos); - - if (bInfoFound == true) - break; - //All Java installations found by the current plug-in lib - //do not provide the required features. Try the next plug-in - } - if ((JavaInfo*) aCurrentInfo == NULL) - {//The plug-ins did not find a suitable Java. Now try the paths which have been - //added manually. - //get the list of paths to jre locations which have been added manually - jfw::CNodeJava node; - errcode = node.loadFromSettings(); - if (errcode != JFW_E_NONE) - return errcode; - const std::vector<rtl::OString> & vecJRELocations = - node.getJRELocations(); - //use every plug-in to determine the JavaInfo objects - bool bInfoFound = false; + osl::MutexGuard guard(jfw::getFwkMutex()); + if (jfw::getMode() == jfw::JFW_MODE_DIRECT) + return JFW_E_DIRECT_MODE; + sal_Int64 nFeatureFlags = 0L; + jfw::CJavaInfo aCurrentInfo; +//Determine if accessibility support is needed + bool bSupportAccessibility = jfw::isAccessibilitySupportDesired(); + nFeatureFlags = bSupportAccessibility ? + JFW_FEATURE_ACCESSBRIDGE : 0L; + + //Get a list of services which provide Java information + jfw::VendorSettings aVendorSettings; + std::vector<jfw::PluginLibrary> vecPlugins = + aVendorSettings.getPluginData(); + + //Use every plug-in library to get Java installations. At the first usable + //Java the loop will break + typedef std::vector<jfw::PluginLibrary>::const_iterator ci_pl; for (ci_pl i = vecPlugins.begin(); i != vecPlugins.end(); i++) { const jfw::PluginLibrary & library = *i; - jfw::VersionInfo versionInfo; - errcode = jfw::getVersionInformation(doc, context, library.sVendor, - & versionInfo); - if (errcode != JFW_E_NONE) - return JFW_E_CONFIG_READWRITE; + jfw::VersionInfo versionInfo = + aVendorSettings.getVersionInformation(library.sVendor); + osl::Module pluginLib(library.sPath); if (pluginLib.is() == sal_False) return JFW_E_NO_PLUGIN; - //Check if the current plugin can detect JREs at the location - // of the paths added by jfw_setJRELocations or jfw_addJRELocation - //get the function from the plugin - jfw_plugin_getJavaInfoByPath_ptr jfw_plugin_getJavaInfoByPathFunc = - (jfw_plugin_getJavaInfoByPath_ptr) pluginLib.getSymbol( - rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("jfw_plugin_getJavaInfoByPath"))); - OSL_ASSERT(jfw_plugin_getJavaInfoByPathFunc); - if (jfw_plugin_getJavaInfoByPathFunc == NULL) - return JFW_E_ERROR; + jfw_plugin_getAllJavaInfos_ptr getAllJavaFunc = + (jfw_plugin_getAllJavaInfos_ptr) pluginLib.getSymbol( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("jfw_plugin_getAllJavaInfos"))); - typedef std::vector<rtl::OString>::const_iterator citLoc; - for (citLoc i = vecJRELocations.begin(); - i != vecJRELocations.end(); i++) + OSL_ASSERT(getAllJavaFunc); + if (getAllJavaFunc == NULL) + continue; + + //get all installations of one vendor according to minVersion, + //maxVersion and excludeVersions + sal_Int32 cInfos = 0; + JavaInfo** arInfos = NULL; + javaPluginError plerr = (*getAllJavaFunc)( + library.sVendor.pData, + versionInfo.sMinVersion.pData, + versionInfo.sMaxVersion.pData, + versionInfo.getExcludeVersions(), + versionInfo.getExcludeVersionSize(), + & arInfos, + & cInfos); + + if (plerr != JFW_PLUGIN_E_NONE) + continue; + //iterate over all installations to find the best which has + //all features + if (cInfos == 0) { - rtl::OUString sLocation = - rtl::OStringToOUString(*i, RTL_TEXTENCODING_UTF8); - JavaInfo* pInfo = NULL; - javaPluginError err = (*jfw_plugin_getJavaInfoByPathFunc)( - sLocation.pData, - versionInfo.sMinVersion.pData, - versionInfo.sMaxVersion.pData, - versionInfo.getExcludeVersions(), - versionInfo.getExcludeVersionSize(), - & pInfo); - if (err == JFW_PLUGIN_E_NO_JRE) - continue; - if (err == JFW_PLUGIN_E_FAILED_VERSION) - continue; - else if (err !=JFW_PLUGIN_E_NONE) - return JFW_E_ERROR; + rtl_freeMemory(arInfos); + continue; + } + bool bInfoFound = false; + for (int ii = 0; ii < cInfos; ii++) + { + JavaInfo* pInfo = arInfos[ii]; - if (pInfo) - { - //We remember the very first installation in aCurrentInfo - if (aCurrentInfo.getLocation().getLength() == 0) + //We remember the very first installation in aCurrentInfo + if (aCurrentInfo.getLocation().getLength() == 0) aCurrentInfo = pInfo; - // compare features - // If the user does not require any features (nFeatureFlags = 0) - // then the first installation is used - if ((pInfo->nFeatures & nFeatureFlags) == nFeatureFlags) - { - //the just found Java implements all required features - //currently there is only accessibility!!! - aCurrentInfo = pInfo; - bInfoFound = true; - break; - } + // compare features + // If the user does not require any features (nFeatureFlags = 0) + // then the first installation is used + if ((pInfo->nFeatures & nFeatureFlags) == nFeatureFlags) + { + //the just found Java implements all required features + //currently there is only accessibility!!! + aCurrentInfo = pInfo; + bInfoFound = true; + break; } - }//end iterate over paths + } + //The array returned by jfw_plugin_getAllJavaInfos must be freed as well as + //its contents + for (int i = 0; i < cInfos; i++) + jfw_freeJavaInfo(arInfos[i]); + rtl_freeMemory(arInfos); + if (bInfoFound == true) break; - }// end iterate plug-ins - } - if ((JavaInfo*) aCurrentInfo) - { - jfw::CNodeJava javaNode; - javaNode.setJavaInfo(aCurrentInfo,true); - errcode = javaNode.writeSettings(); + //All Java installations found by the current plug-in lib + //do not provide the required features. Try the next plug-in + } + if ((JavaInfo*) aCurrentInfo == NULL) + {//The plug-ins did not find a suitable Java. Now try the paths which have been + //added manually. + //get the list of paths to jre locations which have been added manually + jfw::CNodeJava node; + node.loadFromSettings(); + const std::vector<rtl::OString> & vecJRELocations = + node.getJRELocations(); + //use every plug-in to determine the JavaInfo objects + bool bInfoFound = false; + for (ci_pl i = vecPlugins.begin(); i != vecPlugins.end(); i++) + { + const jfw::PluginLibrary & library = *i; + jfw::VersionInfo versionInfo = + aVendorSettings.getVersionInformation(library.sVendor); + + osl::Module pluginLib(library.sPath); + if (pluginLib.is() == sal_False) + return JFW_E_NO_PLUGIN; + //Check if the current plugin can detect JREs at the location + // of the paths added by jfw_setJRELocations or jfw_addJRELocation + //get the function from the plugin + jfw_plugin_getJavaInfoByPath_ptr jfw_plugin_getJavaInfoByPathFunc = + (jfw_plugin_getJavaInfoByPath_ptr) pluginLib.getSymbol( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("jfw_plugin_getJavaInfoByPath"))); + + OSL_ASSERT(jfw_plugin_getJavaInfoByPathFunc); + if (jfw_plugin_getJavaInfoByPathFunc == NULL) + return JFW_E_ERROR; - if (errcode == JFW_E_NONE && pInfo !=NULL) + typedef std::vector<rtl::OString>::const_iterator citLoc; + for (citLoc i = vecJRELocations.begin(); + i != vecJRELocations.end(); i++) + { + rtl::OUString sLocation = + rtl::OStringToOUString(*i, RTL_TEXTENCODING_UTF8); + jfw::CJavaInfo aInfo; + javaPluginError err = (*jfw_plugin_getJavaInfoByPathFunc)( + sLocation.pData, + versionInfo.sMinVersion.pData, + versionInfo.sMaxVersion.pData, + versionInfo.getExcludeVersions(), + versionInfo.getExcludeVersionSize(), + & aInfo.pInfo); + if (err == JFW_PLUGIN_E_NO_JRE) + continue; + if (err == JFW_PLUGIN_E_FAILED_VERSION) + continue; + else if (err !=JFW_PLUGIN_E_NONE) + return JFW_E_ERROR; + + if (aInfo) + { + //We remember the very first installation in aCurrentInfo + if (aCurrentInfo.getLocation().getLength() == 0) + aCurrentInfo = aInfo; + // compare features + // If the user does not require any features (nFeatureFlags = 0) + // then the first installation is used + if ((aInfo.getFeatures() & nFeatureFlags) == nFeatureFlags) + { + //the just found Java implements all required features + //currently there is only accessibility!!! + aCurrentInfo = aInfo; + bInfoFound = true; + break; + } + } + }//end iterate over paths + if (bInfoFound == true) + break; + }// end iterate plug-ins + } + if ((JavaInfo*) aCurrentInfo) { - //copy to out param - *pInfo = aCurrentInfo.cloneJavaInfo(); - //remember that this JRE was selected in this process - jfw::setJavaSelected(); + jfw::CNodeJava javaNode; + javaNode.setJavaInfo(aCurrentInfo,true); + javaNode.writeSettings(); + + if (pInfo !=NULL) + { + //copy to out param + *pInfo = aCurrentInfo.cloneJavaInfo(); + //remember that this JRE was selected in this process + jfw::setJavaSelected(); + } + } + else + { + errcode = JFW_E_NO_JAVA_FOUND; } } - else + catch (jfw::FrameworkException& e) { - errcode = JFW_E_NO_JAVA_FOUND; + errcode = e.errorCode; + fprintf(stderr, e.message.getStr()); + OSL_ENSURE(0, e.message.getStr()); } + return errcode; } sal_Bool SAL_CALL jfw_areEqualJavaInfo( @@ -768,16 +713,37 @@ void SAL_CALL jfw_freeJavaInfo(JavaInfo *pInfo) javaFrameworkError SAL_CALL jfw_getSelectedJRE(JavaInfo **ppInfo) { - osl::MutexGuard guard(jfw::getFwkMutex()); javaFrameworkError errcode = JFW_E_NONE; - if (ppInfo == NULL) - return JFW_E_INVALID_ARG; - jfw::CNodeJava aSettings; - errcode = aSettings.loadFromSettings(); - if (errcode == JFW_E_NONE) + try { - jfw::CJavaInfo aInfo(aSettings.getJavaInfo()); - if (aInfo == NULL) + osl::MutexGuard guard(jfw::getFwkMutex()); + if (ppInfo == NULL) + return JFW_E_INVALID_ARG; + + if (jfw::getMode() == jfw::JFW_MODE_DIRECT) + { + rtl::OUString sJRE = jfw::BootParams::getJREHome(); + + jfw::CJavaInfo aInfo; + if ((errcode = jfw_getJavaInfoByPath(sJRE.pData, & aInfo.pInfo)) + != JFW_E_NONE) + throw jfw::FrameworkException( + JFW_E_CONFIGURATION, + rtl::OString( + "[Java framework] The JRE specified by the bootstrap " + "variable UNO_JAVA_JFW_JREHOME or UNO_JAVA_JFW_ENV_JREHOME " + " could not be recognized. Check the values and make sure that you " + "use a plug-in library that can recognize that JRE.")); + + *ppInfo = aInfo.detach(); + return JFW_E_NONE; + } + + jfw::CNodeJava aSettings; + aSettings.loadFromSettings(); + jfw::CJavaInfo aInfo; + aInfo.attach(aSettings.createJavaInfo()); + if (! aInfo) { *ppInfo = NULL; return JFW_E_NONE; @@ -785,14 +751,18 @@ javaFrameworkError SAL_CALL jfw_getSelectedJRE(JavaInfo **ppInfo) //If the javavendors.xml has changed, then the current selected //Java is not valid anymore // /java/javaInfo/@vendorUpdate != javaSelection/updated (javavendors.xml) - rtl::OString sUpdated; - if ((errcode = jfw::getElementUpdated(sUpdated)) != JFW_E_NONE) - return errcode; + rtl::OString sUpdated = jfw::getElementUpdated(); + if (sUpdated.equals(aSettings.getJavaInfoAttrVendorUpdate()) == sal_False) return JFW_E_INVALID_SETTINGS; - *ppInfo = aSettings.getJavaInfo(); + *ppInfo = aInfo.detach(); + } + catch (jfw::FrameworkException& e) + { + errcode = e.errorCode; + fprintf(stderr, e.message.getStr()); + OSL_ENSURE(0, e.message.getStr()); } - return errcode; } @@ -811,175 +781,205 @@ javaFrameworkError SAL_CALL jfw_isVMRunning(sal_Bool *bRunning) javaFrameworkError SAL_CALL jfw_getJavaInfoByPath( rtl_uString *pPath, JavaInfo **ppInfo) { - osl::MutexGuard guard(jfw::getFwkMutex()); - if (pPath == NULL || ppInfo == NULL) - return JFW_E_INVALID_ARG; javaFrameworkError errcode = JFW_E_NONE; - //Prepare the xml document and context - rtl::OString sSettingsPath = jfw::getVendorSettingsPath(); - jfw::CXmlDocPtr doc(xmlParseFile(sSettingsPath.getStr())); - if (doc == NULL) - { - OSL_ASSERT(0); - return JFW_E_ERROR; - } - jfw::CXPathContextPtr context(xmlXPathNewContext(doc)); - int reg = xmlXPathRegisterNs(context, (xmlChar*) "jf", - (xmlChar*) NS_JAVA_FRAMEWORK); - if (reg == -1) - return JFW_E_ERROR; - - //Get a list of plugins which provide Java information - std::vector<jfw::PluginLibrary> vecPlugins; - errcode = jfw::getVendorPluginURLs(doc, context, & vecPlugins); - if (errcode != JFW_E_NONE) - return errcode; - std::vector<rtl::OUString> vecVendors; - typedef std::vector<rtl::OUString>::const_iterator CIT_VENDOR; - errcode = jfw::getSupportedVendors(doc, context, & vecVendors); - if (errcode != JFW_E_NONE) - return errcode; - - //Use every plug-in library to determine if the path represents a - //JRE. If a plugin recognized it then the loop will break - typedef std::vector<jfw::PluginLibrary>::const_iterator ci_pl; - for (ci_pl i = vecPlugins.begin(); i != vecPlugins.end(); i++) + try { - const jfw::PluginLibrary & library = *i; - jfw::VersionInfo versionInfo; - errcode = jfw::getVersionInformation(doc, context, library.sVendor, - & versionInfo); - if (errcode != JFW_E_NONE) - return JFW_E_CONFIG_READWRITE; - osl::Module pluginLib(library.sPath); - - if (pluginLib.is() == sal_False) + osl::MutexGuard guard(jfw::getFwkMutex()); + if (pPath == NULL || ppInfo == NULL) + return JFW_E_INVALID_ARG; + + jfw::VendorSettings aVendorSettings; + //Get a list of plugins which provide Java information + std::vector<jfw::PluginLibrary> vecPlugins = + aVendorSettings.getPluginData(); + typedef std::vector<rtl::OUString>::const_iterator CIT_VENDOR; + std::vector<rtl::OUString> vecVendors = + aVendorSettings.getSupportedVendors(); + + //Use every plug-in library to determine if the path represents a + //JRE. If a plugin recognized it then the loop will break + typedef std::vector<jfw::PluginLibrary>::const_iterator ci_pl; + for (ci_pl i = vecPlugins.begin(); i != vecPlugins.end(); i++) { - rtl::OString msg = rtl::OUStringToOString( - library.sPath, osl_getThreadTextEncoding()); - fprintf(stderr,"[jvmfwk] Could not load plugin %s\n" \ - "Modify the javavendors.xml accordingly!\n", msg.getStr()); - return JFW_E_NO_PLUGIN; - } + const jfw::PluginLibrary & library = *i; + jfw::VersionInfo versionInfo = + aVendorSettings.getVersionInformation(library.sVendor); - jfw_plugin_getJavaInfoByPath_ptr jfw_plugin_getJavaInfoByPathFunc = - (jfw_plugin_getJavaInfoByPath_ptr) pluginLib.getSymbol( - rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("jfw_plugin_getJavaInfoByPath"))); - - OSL_ASSERT(jfw_plugin_getJavaInfoByPathFunc); - if (jfw_plugin_getJavaInfoByPathFunc == NULL) - continue; - - //ask the plugin if this is a JRE. - //If so check if it meets the version requirements. - //Only if it does return a JavaInfo - JavaInfo* pInfo = NULL; - javaPluginError plerr = (*jfw_plugin_getJavaInfoByPathFunc)( - pPath, - versionInfo.sMinVersion.pData, - versionInfo.sMaxVersion.pData, - versionInfo.getExcludeVersions(), - versionInfo.getExcludeVersionSize(), - & pInfo); - - if (plerr == JFW_PLUGIN_E_NONE) - { - //check if the vendor of the found JRE is supported - rtl::OUString sVendor(pInfo->sVendor); - CIT_VENDOR ivendor = std::find(vecVendors.begin(), vecVendors.end(), - sVendor); - if (ivendor != vecVendors.end()) + osl::Module pluginLib(library.sPath); + if (pluginLib.is() == sal_False) { - *ppInfo = pInfo; + rtl::OString msg = rtl::OUStringToOString( + library.sPath, osl_getThreadTextEncoding()); + fprintf(stderr,"[jvmfwk] Could not load plugin %s\n" \ + "Modify the javavendors.xml accordingly!\n", msg.getStr()); + return JFW_E_NO_PLUGIN; } - else + + jfw_plugin_getJavaInfoByPath_ptr jfw_plugin_getJavaInfoByPathFunc = + (jfw_plugin_getJavaInfoByPath_ptr) pluginLib.getSymbol( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("jfw_plugin_getJavaInfoByPath"))); + + OSL_ASSERT(jfw_plugin_getJavaInfoByPathFunc); + if (jfw_plugin_getJavaInfoByPathFunc == NULL) + continue; + + //ask the plugin if this is a JRE. + //If so check if it meets the version requirements. + //Only if it does return a JavaInfo + JavaInfo* pInfo = NULL; + javaPluginError plerr = (*jfw_plugin_getJavaInfoByPathFunc)( + pPath, + versionInfo.sMinVersion.pData, + versionInfo.sMaxVersion.pData, + versionInfo.getExcludeVersions(), + versionInfo.getExcludeVersionSize(), + & pInfo); + + if (plerr == JFW_PLUGIN_E_NONE) { + //check if the vendor of the found JRE is supported + if (vecVendors.size() == 0) + { + //vendor does not matter + *ppInfo = pInfo; + break; + } + else + { + rtl::OUString sVendor(pInfo->sVendor); + CIT_VENDOR ivendor = std::find(vecVendors.begin(), vecVendors.end(), + sVendor); + if (ivendor != vecVendors.end()) + { + *ppInfo = pInfo; + } + else + { + *ppInfo = NULL; + errcode = JFW_E_NOT_RECOGNIZED; + } + break; + } + } + else if(plerr == JFW_PLUGIN_E_FAILED_VERSION) + {//found JRE but it has the wrong version *ppInfo = NULL; - errcode = JFW_E_NOT_RECOGNIZED; + errcode = JFW_E_FAILED_VERSION; + break; } - break; - } - else if(plerr == JFW_PLUGIN_E_FAILED_VERSION) - {//found JRE but it has the wrong version - *ppInfo = NULL; - errcode = JFW_E_FAILED_VERSION; - break; - } - else if (plerr == JFW_PLUGIN_E_NO_JRE) - {// plugin does not recognize this path as belonging to JRE - continue; + else if (plerr == JFW_PLUGIN_E_NO_JRE) + {// plugin does not recognize this path as belonging to JRE + continue; + } + OSL_ASSERT(0); } - OSL_ASSERT(0); + if (*ppInfo == NULL && errcode != JFW_E_FAILED_VERSION) + errcode = JFW_E_NOT_RECOGNIZED; + } + catch (jfw::FrameworkException& e) + { + errcode = e.errorCode; + fprintf(stderr, e.message.getStr()); + OSL_ENSURE(0, e.message.getStr()); } - if (*ppInfo == NULL && errcode != JFW_E_FAILED_VERSION) - errcode = JFW_E_NOT_RECOGNIZED; + return errcode; } javaFrameworkError SAL_CALL jfw_setSelectedJRE(JavaInfo const *pInfo) { - osl::MutexGuard guard(jfw::getFwkMutex()); javaFrameworkError errcode = JFW_E_NONE; - //check if pInfo is the selected JRE - JavaInfo *currentInfo = NULL; - errcode = jfw_getSelectedJRE( & currentInfo); - if (errcode != JFW_E_NONE && errcode != JFW_E_INVALID_SETTINGS) - return errcode; - - if (jfw_areEqualJavaInfo(currentInfo, pInfo) == sal_False) + try { - jfw::CNodeJava node; - node.setJavaInfo(pInfo, false); - errcode = node.writeSettings(); - if (errcode != JFW_E_NONE) + osl::MutexGuard guard(jfw::getFwkMutex()); + if (jfw::getMode() == jfw::JFW_MODE_DIRECT) + return JFW_E_DIRECT_MODE; + //check if pInfo is the selected JRE + JavaInfo *currentInfo = NULL; + errcode = jfw_getSelectedJRE( & currentInfo); + if (errcode != JFW_E_NONE && errcode != JFW_E_INVALID_SETTINGS) return errcode; - //remember that the JRE was selected in this process - jfw::setJavaSelected(); + + if (jfw_areEqualJavaInfo(currentInfo, pInfo) == sal_False) + { + jfw::CNodeJava node; + node.setJavaInfo(pInfo, false); + node.writeSettings(); + //remember that the JRE was selected in this process + jfw::setJavaSelected(); + } + } + catch (jfw::FrameworkException& e) + { + errcode = e.errorCode; + fprintf(stderr, e.message.getStr()); + OSL_ENSURE(0, e.message.getStr()); } return errcode; } javaFrameworkError SAL_CALL jfw_setEnabled(sal_Bool bEnabled) { - osl::MutexGuard guard(jfw::getFwkMutex()); javaFrameworkError errcode = JFW_E_NONE; - jfw::CNodeJava node; + try + { + osl::MutexGuard guard(jfw::getFwkMutex()); + if (jfw::getMode() == jfw::JFW_MODE_DIRECT) + return JFW_E_DIRECT_MODE; + + jfw::CNodeJava node; - if (g_bEnabledSwitchedOn == false && bEnabled == sal_True) + if (g_bEnabledSwitchedOn == false && bEnabled == sal_True) + { + //When the process started then Enabled was false. + //This is first time enabled is set to true. + //That means, no preparational work has been done, such as setting the + //LD_LIBRARY_PATH, etc. + + //check if Enabled is false; + node.loadFromSettings(); + if (node.getEnabled() == sal_False) + g_bEnabledSwitchedOn = true; + } + node.setEnabled(bEnabled); + node.writeSettings(); + } + catch (jfw::FrameworkException& e) { - //When the process started then Enabled was false. - //This is first time enabled is set to true. - //That means, no preparational work has been done, such as setting the - //LD_LIBRARY_PATH, etc. - - //check if Enabled is false; - errcode = node.loadFromSettings(); - if (errcode != JFW_E_NONE) - return errcode; - if (node.getEnabled() == sal_False) - g_bEnabledSwitchedOn = true; + errcode = e.errorCode; + fprintf(stderr, e.message.getStr()); + OSL_ENSURE(0, e.message.getStr()); } - node.setEnabled(bEnabled); - errcode = node.writeSettings(); - if (errcode != JFW_E_NONE) - return errcode; - //remember if the enabled was false at the beginning and has - //been changed to true. return errcode; } javaFrameworkError SAL_CALL jfw_getEnabled(sal_Bool *pbEnabled) { - osl::MutexGuard guard(jfw::getFwkMutex()); javaFrameworkError errcode = JFW_E_NONE; - if (pbEnabled == NULL) - return JFW_E_INVALID_ARG; - jfw::CNodeJava node; - errcode = node.loadFromSettings(); - if (errcode == JFW_E_NONE) + try { + osl::MutexGuard guard(jfw::getFwkMutex()); + if (jfw::getMode() == jfw::JFW_MODE_DIRECT) + { + if (jfw::BootParams::getDisable() == true) + *pbEnabled = sal_False; + else + *pbEnabled = sal_True; + return JFW_E_NONE; + } + + if (pbEnabled == NULL) + return JFW_E_INVALID_ARG; + jfw::CNodeJava node; + node.loadFromSettings(); *pbEnabled = node.getEnabled(); } + catch (jfw::FrameworkException& e) + { + errcode = e.errorCode; + fprintf(stderr, e.message.getStr()); + OSL_ENSURE(0, e.message.getStr()); + } return errcode; } @@ -987,81 +987,122 @@ javaFrameworkError SAL_CALL jfw_getEnabled(sal_Bool *pbEnabled) javaFrameworkError SAL_CALL jfw_setVMParameters( rtl_uString * * arOptions, sal_Int32 nLen) { - osl::MutexGuard guard(jfw::getFwkMutex()); javaFrameworkError errcode = JFW_E_NONE; - jfw::CNodeJava node; + try + { + osl::MutexGuard guard(jfw::getFwkMutex()); + if (jfw::getMode() == jfw::JFW_MODE_DIRECT) + return JFW_E_DIRECT_MODE; + jfw::CNodeJava node; + if (arOptions == NULL && nLen != 0) + return JFW_E_INVALID_ARG; + node.setVmParameters(arOptions, nLen); + node.writeSettings(); + } + catch (jfw::FrameworkException& e) + { + errcode = e.errorCode; + fprintf(stderr, e.message.getStr()); + OSL_ENSURE(0, e.message.getStr()); + } - if (arOptions == NULL && nLen != 0) - return JFW_E_INVALID_ARG; - node.setVmParameters(arOptions, nLen); - errcode = node.writeSettings(); - if (errcode != JFW_E_NONE) - return errcode; return errcode; } javaFrameworkError SAL_CALL jfw_getVMParameters( rtl_uString *** parOptions, sal_Int32 * pLen) { - osl::MutexGuard guard(jfw::getFwkMutex()); javaFrameworkError errcode = JFW_E_NONE; - if (parOptions == NULL || pLen == NULL) - return JFW_E_INVALID_ARG; - jfw::CNodeJava node; - errcode = node.loadFromSettings(); - if (errcode == JFW_E_NONE) + try { + osl::MutexGuard guard(jfw::getFwkMutex()); + if (jfw::getMode() == jfw::JFW_MODE_DIRECT) + return JFW_E_DIRECT_MODE; + + if (parOptions == NULL || pLen == NULL) + return JFW_E_INVALID_ARG; + jfw::CNodeJava node; + node.loadFromSettings(); node.getVmParametersArray(parOptions, pLen); } + catch (jfw::FrameworkException& e) + { + errcode = e.errorCode; + fprintf(stderr, e.message.getStr()); + OSL_ENSURE(0, e.message.getStr()); + } return errcode; } javaFrameworkError SAL_CALL jfw_setUserClassPath(rtl_uString * pCp) { - osl::MutexGuard guard(jfw::getFwkMutex()); javaFrameworkError errcode = JFW_E_NONE; - jfw::CNodeJava node; - - if (pCp == NULL) - return JFW_E_INVALID_ARG; - node.setUserClassPath(pCp); - errcode = node.writeSettings(); - if (errcode != JFW_E_NONE) - return errcode; + try + { + osl::MutexGuard guard(jfw::getFwkMutex()); + if (jfw::getMode() == jfw::JFW_MODE_DIRECT) + return JFW_E_DIRECT_MODE; + jfw::CNodeJava node; + if (pCp == NULL) + return JFW_E_INVALID_ARG; + node.setUserClassPath(pCp); + node.writeSettings(); + } + catch (jfw::FrameworkException& e) + { + errcode = e.errorCode; + fprintf(stderr, e.message.getStr()); + OSL_ENSURE(0, e.message.getStr()); + } return errcode; } javaFrameworkError SAL_CALL jfw_getUserClassPath(rtl_uString ** ppCP) { - osl::MutexGuard guard(jfw::getFwkMutex()); javaFrameworkError errcode = JFW_E_NONE; - if (ppCP == NULL) - return JFW_E_INVALID_ARG; - jfw::CNodeJava node; - errcode = node.loadFromSettings(); - if (errcode == JFW_E_NONE) + try { + osl::MutexGuard guard(jfw::getFwkMutex()); + if (jfw::getMode() == jfw::JFW_MODE_DIRECT) + return JFW_E_DIRECT_MODE; + if (ppCP == NULL) + return JFW_E_INVALID_ARG; + jfw::CNodeJava node; + node.loadFromSettings(); *ppCP = node.getUserClassPath().pData; rtl_uString_acquire(*ppCP); } + catch (jfw::FrameworkException& e) + { + errcode = e.errorCode; + fprintf(stderr, e.message.getStr()); + OSL_ENSURE(0, e.message.getStr()); + } return errcode; } javaFrameworkError SAL_CALL jfw_addJRELocation(rtl_uString * sLocation) { - osl::MutexGuard guard(jfw::getFwkMutex()); javaFrameworkError errcode = JFW_E_NONE; - jfw::CNodeJava node; + try + { + osl::MutexGuard guard(jfw::getFwkMutex()); + if (jfw::getMode() == jfw::JFW_MODE_DIRECT) + return JFW_E_DIRECT_MODE; + jfw::CNodeJava node; + if (sLocation == NULL) + return JFW_E_INVALID_ARG; + node.loadFromSettings(); + node.addJRELocation(sLocation); + node.writeSettings(); + } + catch (jfw::FrameworkException& e) + { + errcode = e.errorCode; + fprintf(stderr, e.message.getStr()); + OSL_ENSURE(0, e.message.getStr()); + } - if (sLocation == NULL) - return JFW_E_INVALID_ARG; - errcode = node.loadFromSettings(); - if (errcode != JFW_E_NONE) - return errcode; - node.addJRELocation(sLocation); - errcode = node.writeSettings(); - if (errcode != JFW_E_NONE) - return errcode; return errcode; } @@ -1069,16 +1110,24 @@ javaFrameworkError SAL_CALL jfw_addJRELocation(rtl_uString * sLocation) javaFrameworkError SAL_CALL jfw_setJRELocations( rtl_uString ** arLocations, sal_Int32 nLen) { - osl::MutexGuard guard(jfw::getFwkMutex()); javaFrameworkError errcode = JFW_E_NONE; - jfw::CNodeJava node; - - if (arLocations == NULL && nLen != 0) - return JFW_E_INVALID_ARG; - node.setJRELocations(arLocations, nLen); - errcode = node.writeSettings(); - if (errcode != JFW_E_NONE) - return errcode; + try + { + osl::MutexGuard guard(jfw::getFwkMutex()); + if (jfw::getMode() == jfw::JFW_MODE_DIRECT) + return JFW_E_DIRECT_MODE; + jfw::CNodeJava node; + if (arLocations == NULL && nLen != 0) + return JFW_E_INVALID_ARG; + node.setJRELocations(arLocations, nLen); + node.writeSettings(); + } + catch (jfw::FrameworkException& e) + { + errcode = e.errorCode; + fprintf(stderr, e.message.getStr()); + OSL_ENSURE(0, e.message.getStr()); + } return errcode; } @@ -1086,16 +1135,26 @@ javaFrameworkError SAL_CALL jfw_setJRELocations( javaFrameworkError SAL_CALL jfw_getJRELocations( rtl_uString *** parLocations, sal_Int32 *pLen) { - osl::MutexGuard guard(jfw::getFwkMutex()); javaFrameworkError errcode = JFW_E_NONE; - if (parLocations == NULL || pLen == NULL) - return JFW_E_INVALID_ARG; - jfw::CNodeJava node; - errcode = node.loadFromSettings(); - if (errcode == JFW_E_NONE) + try { + osl::MutexGuard guard(jfw::getFwkMutex()); + if (jfw::getMode() == jfw::JFW_MODE_DIRECT) + return JFW_E_DIRECT_MODE; + + if (parLocations == NULL || pLen == NULL) + return JFW_E_INVALID_ARG; + jfw::CNodeJava node; + node.loadFromSettings(); node.getJRELocations(parLocations, pLen); } + catch (jfw::FrameworkException& e) + { + errcode = e.errorCode; + fprintf(stderr, e.message.getStr()); + OSL_ENSURE(0, e.message.getStr()); + } + return errcode; } @@ -1118,6 +1177,30 @@ CJavaInfo::CJavaInfo(): pInfo(0) { } +CJavaInfo::CJavaInfo(const CJavaInfo & info) +{ + pInfo = copyJavaInfo(info.pInfo); +} + +CJavaInfo::CJavaInfo(::JavaInfo * info, _transfer_ownership) +{ + pInfo = info; +} +CJavaInfo CJavaInfo::createWrapper(::JavaInfo* info) +{ + return CJavaInfo(info, TRANSFER); +} +void CJavaInfo::attach(::JavaInfo * info) +{ + jfw_freeJavaInfo(pInfo); + pInfo = info; +} +::JavaInfo * CJavaInfo::detach() +{ + JavaInfo * tmp = pInfo; + pInfo = NULL; + return tmp; +} CJavaInfo::CJavaInfo(const ::JavaInfo* info): pInfo(0) { pInfo = copyJavaInfo(info); @@ -1157,17 +1240,23 @@ JavaInfo* CJavaInfo::cloneJavaInfo() const return NULL; return copyJavaInfo(pInfo); } + +CJavaInfo & CJavaInfo::operator = (const CJavaInfo& info) +{ + if (&info == this) + return *this; + + jfw_freeJavaInfo(pInfo); + pInfo = copyJavaInfo(info.pInfo); + return *this; +} CJavaInfo & CJavaInfo::operator = (const ::JavaInfo* info) { if (info == pInfo) return *this; jfw_freeJavaInfo(pInfo); - pInfo = NULL; - if (info != NULL) - { - pInfo = copyJavaInfo(info); - } + pInfo = copyJavaInfo(info); return *this; } @@ -1180,10 +1269,10 @@ CJavaInfo::operator JavaInfo const * () const { return pInfo; } -::JavaInfo** CJavaInfo::operator & () -{ - return & pInfo; -} +// ::JavaInfo** CJavaInfo::operator & () +// { +// return & pInfo; +// } rtl::OUString CJavaInfo::getVendor() const { |