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