merge the formfield patch from ooo-build
[ooovba.git] / javaunohelper / source / preload.cxx
blobe402e2787075fb56718b626766921e4befcc0c08
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: preload.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_javaunohelper.hxx"
34 #include "jni.h"
36 #include "rtl/ustring.hxx"
37 #include "osl/module.h"
39 #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
41 #if ! defined SAL_DLLPREFIX
42 #define SAL_DLLPREFIX ""
43 #endif
45 using ::rtl::OUString;
47 extern "C"
49 typedef jboolean (JNICALL * fptr_writeInfo)(
50 JNIEnv *, jclass, jstring, jobject, jobject, jobject );
51 typedef jobject (JNICALL * fptr_getFactory)(
52 JNIEnv *, jclass, jstring, jstring, jobject, jobject, jobject );
53 typedef jobject (JNICALL * fptr_createRegistryServiceFactory)(
54 JNIEnv *, jclass, jstring, jstring, jboolean, jobject );
55 typedef jobject (JNICALL * fptr_bootstrap)(
56 JNIEnv *_env, jclass, jstring, jobjectArray, jobject );
58 static fptr_writeInfo s_writeInfo;
59 static fptr_getFactory s_getFactory;
60 static fptr_createRegistryServiceFactory s_createRegistryServiceFactory;
61 static fptr_bootstrap s_bootstrap;
62 static bool s_inited = false;
64 extern "C" { static void SAL_CALL thisModule() {} }
66 //--------------------------------------------------------------------------------------------------
67 static bool inited_juhx( JNIEnv * jni_env )
69 if (s_inited)
70 return true;
71 OUString lib_name = OUSTR(SAL_DLLPREFIX "juhx" SAL_DLLEXTENSION);
72 oslModule hModule =
73 osl_loadModuleRelative( &thisModule, lib_name.pData, SAL_LOADMODULE_LAZY | SAL_LOADMODULE_GLOBAL );
74 if (0 == hModule)
76 jclass c = jni_env->FindClass( "java/lang/RuntimeException" );
77 jni_env->ThrowNew(
78 c, "error loading " SAL_DLLPREFIX "juhx" SAL_DLLEXTENSION "!" );
79 return false;
81 else
83 OUString symbol =
84 OUSTR("Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1writeInfo");
85 s_writeInfo = (fptr_writeInfo)osl_getFunctionSymbol(
86 hModule, symbol.pData );
87 symbol =
88 OUSTR("Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1getFactory");
89 s_getFactory = (fptr_getFactory)osl_getFunctionSymbol(
90 hModule, symbol.pData );
91 symbol =
92 OUSTR("Java_com_sun_star_comp_helper_RegistryServiceFactory_createRegistryServiceFactory");
93 s_createRegistryServiceFactory =
94 (fptr_createRegistryServiceFactory)osl_getFunctionSymbol(
95 hModule, symbol.pData );
96 symbol =
97 OUSTR("Java_com_sun_star_comp_helper_Bootstrap_cppuhelper_1bootstrap");
98 s_bootstrap =
99 (fptr_bootstrap)osl_getFunctionSymbol( hModule, symbol.pData );
101 if (0 == s_writeInfo ||
102 0 == s_getFactory ||
103 0 == s_createRegistryServiceFactory ||
104 0 == s_bootstrap)
106 jclass c = jni_env->FindClass( "java/lang/RuntimeException" );
107 jni_env->ThrowNew(
108 c, "error resolving symbols of " SAL_DLLPREFIX "juhx" SAL_DLLEXTENSION "!" );
109 return false;
112 s_inited = true;
113 return true;
116 //==================================================================================================
117 JNIEXPORT jboolean JNICALL
118 Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1writeInfo(
119 JNIEnv * pJEnv, jclass jClass, jstring jLibName, jobject jSMgr,
120 jobject jRegKey, jobject loader )
122 if (inited_juhx( pJEnv ))
123 return (*s_writeInfo)(
124 pJEnv, jClass, jLibName, jSMgr, jRegKey, loader );
125 return JNI_FALSE;
127 //==================================================================================================
128 JNIEXPORT jobject JNICALL
129 Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1getFactory(
130 JNIEnv * pJEnv, jclass jClass, jstring jLibName, jstring jImplName,
131 jobject jSMgr, jobject jRegKey, jobject loader )
133 if (inited_juhx( pJEnv ))
134 return (*s_getFactory)(
135 pJEnv, jClass, jLibName, jImplName, jSMgr, jRegKey, loader );
136 return 0;
138 //==================================================================================================
139 JNIEXPORT jobject JNICALL
140 Java_com_sun_star_comp_helper_RegistryServiceFactory_createRegistryServiceFactory(
141 JNIEnv * pJEnv, jclass jClass, jstring jWriteRegFile,
142 jstring jReadRegFile, jboolean jbReadOnly, jobject loader )
144 if (inited_juhx( pJEnv ))
146 return (*s_createRegistryServiceFactory)(
147 pJEnv, jClass, jWriteRegFile, jReadRegFile, jbReadOnly, loader );
149 return 0;
151 //==================================================================================================
152 JNIEXPORT jobject JNICALL
153 Java_com_sun_star_comp_helper_Bootstrap_cppuhelper_1bootstrap(
154 JNIEnv * jni_env, jclass jClass, jstring juno_rc, jobjectArray jpairs,
155 jobject loader )
157 if (inited_juhx( jni_env ))
158 return (*s_bootstrap)( jni_env, jClass, juno_rc, jpairs, loader );
159 return 0;