LCOV - code coverage report
Current view: top level - connectivity/source/drivers/jdbc - ContextClassLoader.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 44 0.0 %
Date: 2014-04-14 Functions: 0 2 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "java/ContextClassLoader.hxx"
      21             : #include "java/lang/Object.hxx"
      22             : 
      23             : 
      24             : namespace connectivity { namespace jdbc
      25             : {
      26             : 
      27             : 
      28             :     using ::com::sun::star::uno::Reference;
      29             :     using ::com::sun::star::uno::XInterface;
      30             : 
      31             :     using ::connectivity::java_lang_Object;
      32             : 
      33             : 
      34             :     //= ContextClassLoaderScope
      35             : 
      36             : 
      37           0 :     ContextClassLoaderScope::ContextClassLoaderScope( JNIEnv& environment, const GlobalRef< jobject >& newClassLoader,
      38             :         const ::comphelper::ResourceBasedEventLogger& _rLoggerForErrors, const Reference< XInterface >& _rxErrorContext )
      39             :         :m_environment( environment )
      40             :         ,m_currentThread( environment )
      41             :         ,m_oldContextClassLoader( environment )
      42           0 :         ,m_setContextClassLoaderMethod( NULL )
      43             :     {
      44           0 :         if ( !newClassLoader.is() )
      45           0 :             return;
      46             : 
      47             :         do  // artificial loop for easier flow control
      48             :         {
      49             : 
      50           0 :         LocalRef< jclass > threadClass( m_environment );
      51           0 :         threadClass.set( m_environment.FindClass( "java/lang/Thread" ) );
      52           0 :         if ( !threadClass.is() )
      53           0 :             break;
      54             : 
      55             :         jmethodID currentThreadMethod( m_environment.GetStaticMethodID(
      56           0 :             threadClass.get(), "currentThread", "()Ljava/lang/Thread;" ) );
      57           0 :         if ( currentThreadMethod == NULL )
      58           0 :             break;
      59             : 
      60           0 :         m_currentThread.set( m_environment.CallStaticObjectMethod( threadClass.get(), currentThreadMethod ) );
      61           0 :         if ( !m_currentThread.is() )
      62           0 :             break;
      63             : 
      64             :         jmethodID getContextClassLoaderMethod( m_environment.GetMethodID(
      65           0 :             threadClass.get(), "getContextClassLoader", "()Ljava/lang/ClassLoader;" ) );
      66           0 :         if ( getContextClassLoaderMethod == NULL )
      67           0 :             break;
      68           0 :         m_oldContextClassLoader.set( m_environment.CallObjectMethod( m_currentThread.get(), getContextClassLoaderMethod ) );
      69           0 :         LocalRef< jthrowable > throwable( m_environment, m_environment.ExceptionOccurred() );
      70           0 :         if ( throwable.is() )
      71           0 :             break;
      72             : 
      73             :         m_setContextClassLoaderMethod = m_environment.GetMethodID(
      74           0 :             threadClass.get(), "setContextClassLoader", "(Ljava/lang/ClassLoader;)V" );
      75           0 :         if ( m_setContextClassLoaderMethod == NULL )
      76           0 :             break;
      77             : 
      78             :         }
      79             :         while ( false );
      80             : 
      81           0 :         if ( !isActive() )
      82             :         {
      83           0 :             java_lang_Object::ThrowLoggedSQLException( _rLoggerForErrors, &environment, _rxErrorContext );
      84           0 :             return;
      85             :         }
      86             : 
      87             :         // set the new class loader
      88           0 :         m_environment.CallObjectMethod( m_currentThread.get(), m_setContextClassLoaderMethod, newClassLoader.get() );
      89           0 :         LocalRef< jthrowable > throwable( m_environment, m_environment.ExceptionOccurred() );
      90           0 :         if ( throwable.is() )
      91             :         {
      92           0 :             m_currentThread.reset();
      93           0 :             m_setContextClassLoaderMethod = NULL;
      94           0 :             java_lang_Object::ThrowLoggedSQLException( _rLoggerForErrors, &environment, _rxErrorContext );
      95           0 :         }
      96             :     }
      97             : 
      98             : 
      99           0 :     void ContextClassLoaderScope::pop( bool clearExceptions )
     100             :     {
     101           0 :         if ( isActive() )
     102             :         {
     103           0 :             LocalRef< jobject > currentThread( m_currentThread.env(), m_currentThread.release() );
     104           0 :             jmethodID setContextClassLoaderMethod( m_setContextClassLoaderMethod );
     105           0 :             m_setContextClassLoaderMethod = NULL;
     106             : 
     107           0 :             m_environment.CallObjectMethod( currentThread.get(), setContextClassLoaderMethod, m_oldContextClassLoader.get() );
     108           0 :             if ( clearExceptions )
     109             :             {
     110           0 :                 m_environment.ExceptionClear();
     111           0 :             }
     112             :         }
     113           0 :     }
     114             : 
     115             : } } // namespace connectivity::jdbc
     116             : 
     117             : 
     118             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10