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