1caf5cd79SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3caf5cd79SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4caf5cd79SAndrew Rist * or more contributor license agreements. See the NOTICE file 5caf5cd79SAndrew Rist * distributed with this work for additional information 6caf5cd79SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7caf5cd79SAndrew Rist * to you under the Apache License, Version 2.0 (the 8caf5cd79SAndrew Rist * "License"); you may not use this file except in compliance 9caf5cd79SAndrew Rist * with the License. You may obtain a copy of the License at 10caf5cd79SAndrew Rist * 11caf5cd79SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12caf5cd79SAndrew Rist * 13caf5cd79SAndrew Rist * Unless required by applicable law or agreed to in writing, 14caf5cd79SAndrew Rist * software distributed under the License is distributed on an 15caf5cd79SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16caf5cd79SAndrew Rist * KIND, either express or implied. See the License for the 17caf5cd79SAndrew Rist * specific language governing permissions and limitations 18caf5cd79SAndrew Rist * under the License. 19caf5cd79SAndrew Rist * 20caf5cd79SAndrew Rist *************************************************************/ 21caf5cd79SAndrew Rist 22caf5cd79SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef CONNECTIVITY_CONTEXTCLASSLOADER_HXX 25cdf0e10cSrcweir #define CONNECTIVITY_CONTEXTCLASSLOADER_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "java/GlobalRef.hxx" 28cdf0e10cSrcweir 29cdf0e10cSrcweir /** === begin UNO includes === **/ 30cdf0e10cSrcweir /** === end UNO includes === **/ 31cdf0e10cSrcweir 32cdf0e10cSrcweir namespace comphelper 33cdf0e10cSrcweir { 34cdf0e10cSrcweir class ResourceBasedEventLogger; 35cdf0e10cSrcweir } 36cdf0e10cSrcweir 37cdf0e10cSrcweir //........................................................................ 38cdf0e10cSrcweir namespace connectivity { namespace jdbc 39cdf0e10cSrcweir { 40cdf0e10cSrcweir //........................................................................ 41cdf0e10cSrcweir 42cdf0e10cSrcweir //==================================================================== 43cdf0e10cSrcweir //= ContextClassLoaderScope 44cdf0e10cSrcweir //==================================================================== 45cdf0e10cSrcweir /** 46cdf0e10cSrcweir */ 47cdf0e10cSrcweir class ContextClassLoaderScope 48cdf0e10cSrcweir { 49cdf0e10cSrcweir public: 50cdf0e10cSrcweir /** creates the instance. If isActive returns <FALSE/> afterwards, then an exception 51*07a3d7f1SPedro Giffuni happened in the JVM, which should be raised as UNO exception by the caller 52cdf0e10cSrcweir 53cdf0e10cSrcweir @param environment 54cdf0e10cSrcweir the current JNI environment 55cdf0e10cSrcweir @param newClassLoader 56cdf0e10cSrcweir the new class loader to set at the current thread 57cdf0e10cSrcweir @param _rLoggerForErrors 58cdf0e10cSrcweir the logger which should be passed to java_lang_object::ThrowLoggedSQLException in case 59cdf0e10cSrcweir an error occurs 60cdf0e10cSrcweir @param _rxErrorContext 61cdf0e10cSrcweir the context which should be passed to java_lang_object::ThrowLoggedSQLException in case 62cdf0e10cSrcweir an error occurs 63cdf0e10cSrcweir 64cdf0e10cSrcweir */ 65cdf0e10cSrcweir ContextClassLoaderScope( 66cdf0e10cSrcweir JNIEnv& environment, 67cdf0e10cSrcweir const GlobalRef< jobject >& newClassLoader, 68cdf0e10cSrcweir const ::comphelper::ResourceBasedEventLogger& _rLoggerForErrors, 69cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxErrorContext 70cdf0e10cSrcweir ); 71cdf0e10cSrcweir ~ContextClassLoaderScope()72cdf0e10cSrcweir ~ContextClassLoaderScope() { pop(true); } 73cdf0e10cSrcweir pop()74cdf0e10cSrcweir void pop() { pop(false); } 75cdf0e10cSrcweir isActive() const76cdf0e10cSrcweir bool isActive() const 77cdf0e10cSrcweir { 78cdf0e10cSrcweir return ( m_currentThread.is() ) 79cdf0e10cSrcweir && ( m_setContextClassLoaderMethod != NULL ); 80cdf0e10cSrcweir } 81cdf0e10cSrcweir 82cdf0e10cSrcweir private: 83cdf0e10cSrcweir ContextClassLoaderScope(ContextClassLoaderScope &); // not defined 84cdf0e10cSrcweir void operator =(ContextClassLoaderScope &); // not defined 85cdf0e10cSrcweir 86cdf0e10cSrcweir void pop( bool clearExceptions ); 87cdf0e10cSrcweir 88cdf0e10cSrcweir JNIEnv& m_environment; 89cdf0e10cSrcweir LocalRef< jobject > m_currentThread; 90cdf0e10cSrcweir LocalRef< jobject > m_oldContextClassLoader; 91cdf0e10cSrcweir jmethodID m_setContextClassLoaderMethod; 92cdf0e10cSrcweir }; 93cdf0e10cSrcweir 94cdf0e10cSrcweir 95cdf0e10cSrcweir //........................................................................ 96cdf0e10cSrcweir } } // namespace connectivity::jdbc 97cdf0e10cSrcweir //........................................................................ 98cdf0e10cSrcweir 99cdf0e10cSrcweir #endif // CONNECTIVITY_CONTEXTCLASSLOADER_HXX 100