merge the formfield patch from ooo-build
[ooovba.git] / connectivity / source / inc / java / ContextClassLoader.hxx
bloba84c81cb62823221e870941f46073e6bf0a8f1e8
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: ContextClassLoader.hxx,v $
10 * $Revision: 1.3 $
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 === **/
39 namespace comphelper
41 class ResourceBasedEventLogger;
44 //........................................................................
45 namespace connectivity { namespace jdbc
47 //........................................................................
49 //====================================================================
50 //= ContextClassLoaderScope
51 //====================================================================
52 /**
54 class ContextClassLoaderScope
56 public:
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
60 @param environment
61 the current JNI environment
62 @param newClassLoader
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
66 an error occurs
67 @param _rxErrorContext
68 the context which should be passed to java_lang_object::ThrowLoggedSQLException in case
69 an error occurs
72 ContextClassLoaderScope(
73 JNIEnv& environment,
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); }
83 bool isActive() const
85 return ( m_currentThread.is() )
86 && ( m_setContextClassLoaderMethod != NULL );
89 private:
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