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