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