1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ContextClassLoader.hxx,v $
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 #ifndef CONNECTIVITY_CONTEXTCLASSLOADER_HXX
32 #define CONNECTIVITY_CONTEXTCLASSLOADER_HXX
34 #include "java/GlobalRef.hxx"
36 /** === begin UNO includes === **/
37 /** === end UNO includes === **/
41 class ResourceBasedEventLogger
;
44 //........................................................................
45 namespace connectivity
{ namespace jdbc
47 //........................................................................
49 //====================================================================
50 //= ContextClassLoaderScope
51 //====================================================================
54 class ContextClassLoaderScope
57 /** creates the instance. If isActive returns <FALSE/> afterwards, then an exception
58 happend in the JVM, which should be raised as UNO exception by the caller
61 the current JNI environment
63 the new class loader to set at the current thread
64 @param _rLoggerForErrors
65 the logger which should be passed to java_lang_object::ThrowLoggedSQLException in case
67 @param _rxErrorContext
68 the context which should be passed to java_lang_object::ThrowLoggedSQLException in case
72 ContextClassLoaderScope(
74 const GlobalRef
< jobject
>& newClassLoader
,
75 const ::comphelper::ResourceBasedEventLogger
& _rLoggerForErrors
,
76 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _rxErrorContext
79 ~ContextClassLoaderScope() { pop(true); }
81 void pop() { pop(false); }
85 return ( m_currentThread
.is() )
86 && ( m_setContextClassLoaderMethod
!= NULL
);
90 ContextClassLoaderScope(ContextClassLoaderScope
&); // not defined
91 void operator =(ContextClassLoaderScope
&); // not defined
93 void pop( bool clearExceptions
);
95 JNIEnv
& m_environment
;
96 LocalRef
< jobject
> m_currentThread
;
97 LocalRef
< jobject
> m_oldContextClassLoader
;
98 jmethodID m_setContextClassLoaderMethod
;
102 //........................................................................
103 } } // namespace connectivity::jdbc
104 //........................................................................
106 #endif // CONNECTIVITY_CONTEXTCLASSLOADER_HXX