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