LCOV - code coverage report
Current view: top level - connectivity/source/inc/java/lang - Object.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 15 15 100.0 %
Date: 2015-06-13 12:38:46 Functions: 4 15 26.7 %
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             : #ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_LANG_OBJECT_HXX
      20             : #define INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_LANG_OBJECT_HXX
      21             : 
      22             : #include <cstdarg>
      23             : #include <osl/thread.h>
      24             : #include <com/sun/star/sdbc/SQLException.hpp>
      25             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      26             : #include <com/sun/star/uno/XComponentContext.hpp>
      27             : #include <osl/diagnose.h>
      28             : #include <jvmaccess/virtualmachine.hxx>
      29             : #include <functional>
      30             : #include <boost/shared_ptr.hpp>
      31             : 
      32             : 
      33             : 
      34             : #ifdef HAVE_64BIT_POINTERS
      35             : #error "no 64 bit pointer"
      36             : #endif //HAVE_64BIT_POINTERS
      37             : 
      38             : namespace comphelper
      39             : {
      40             :     class ResourceBasedEventLogger;
      41             : }
      42             : 
      43             : namespace connectivity
      44             : {
      45             :     typedef ::boost::shared_ptr< jvmaccess::VirtualMachine::AttachGuard> TGuard;
      46             :     class SDBThreadAttach
      47             :     {
      48             :         jvmaccess::VirtualMachine::AttachGuard m_aGuard;
      49             :         SDBThreadAttach(SDBThreadAttach&) SAL_DELETED_FUNCTION;
      50             :         SDBThreadAttach& operator= (SDBThreadAttach&) SAL_DELETED_FUNCTION;
      51             :     public:
      52             :         SDBThreadAttach();
      53             :         ~SDBThreadAttach();
      54             : 
      55             :         JNIEnv* pEnv;
      56             :         static void addRef();
      57             :         static void releaseRef();
      58             : 
      59             :     public:
      60       15083 :         JNIEnv& env() const
      61             :         {
      62             :             // according to the documentation of jvmaccess::VirtualMachine::AttachGuard, our env is never
      63             :             // NULL, so why bothering with pointer checks?
      64       15083 :             return *pEnv;
      65             :         }
      66             :     };
      67             : 
      68             : 
      69             :     class  java_lang_Object
      70             :     {
      71             :         java_lang_Object& operator= (java_lang_Object&) SAL_DELETED_FUNCTION;
      72             :         java_lang_Object(java_lang_Object&) SAL_DELETED_FUNCTION;
      73             : 
      74             :     protected:
      75             :         // The Java handle to this class
      76             :         jobject object;
      77             : 
      78             :         // Class definition
      79             :         // New in SJ2:
      80             :         static jclass theClass; // The class needs to be requested only once!
      81             : 
      82             :         virtual jclass getMyClass() const;
      83             : 
      84             :     public:
      85             :         // Ctor that should be used for the derived classes
      86             :         java_lang_Object( JNIEnv * pEnv, jobject myObj );
      87             : 
      88             :         // The actual ctor
      89             :         java_lang_Object();
      90             : 
      91             :         virtual ~java_lang_Object();
      92             : 
      93             :         void                saveRef( JNIEnv * pEnv, jobject myObj );
      94         285 :         jobject             getJavaObject() const { return object; }
      95             :         java_lang_Object *  GetWrapper() { return this; }
      96             :         void clearObject(JNIEnv& rEnv);
      97             :         void clearObject();
      98             : 
      99             :         OUString toString() const;
     100             : 
     101             :         static void ThrowSQLException(JNIEnv * pEnv,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface> & _rContext);
     102             :         static void ThrowLoggedSQLException(
     103             :             const ::comphelper::ResourceBasedEventLogger& _rLogger,
     104             :             JNIEnv* pEnvironment,
     105             :             const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxContext
     106             :         );
     107             :         static void ThrowRuntimeException(JNIEnv * pEnv,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface> & _rContext);
     108             : 
     109             :         static ::rtl::Reference< jvmaccess::VirtualMachine > getVM(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext=NULL);
     110             : 
     111             :         static jclass   findMyClass(const char* _pClassName);
     112             :         void            obtainMethodId_throwSQL(JNIEnv* _pEnv, const char* _pMethodName, const char* _pSignature, jmethodID& _inout_MethodID) const;
     113             :         void            obtainMethodId_throwRuntime(JNIEnv* _pEnv, const char* _pMethodName, const char* _pSignature, jmethodID& _inout_MethodID) const;
     114             : 
     115             :         bool        callBooleanMethod( const char* _pMethodName, jmethodID& _inout_MethodID ) const;
     116             :         bool        callBooleanMethodWithIntArg( const char* _pMethodName, jmethodID& _inout_MethodID, sal_Int32 _nArgument ) const;
     117             :         jobject         callResultSetMethod( JNIEnv& _rEnv, const char* _pMethodName, jmethodID& _inout_MethodID ) const;
     118             :         sal_Int32       callIntMethod_ThrowSQL(const char* _pMethodName, jmethodID& _inout_MethodID) const;
     119             :         sal_Int32       callIntMethod_ThrowRuntime(const char* _pMethodName, jmethodID& _inout_MethodID) const;
     120             :         sal_Int32       callIntMethodWithIntArg_ThrowSQL( const char* _pMethodName, jmethodID& _inout_MethodID, sal_Int32 _nArgument ) const;
     121             :         sal_Int32       callIntMethodWithIntArg_ThrowRuntime( const char* _pMethodName, jmethodID& _inout_MethodID, sal_Int32 _nArgument ) const;
     122             :         sal_Int32       callIntMethodWithStringArg( const char* _pMethodName, jmethodID& _inout_MethodID,const OUString& _nArgument ) const;
     123             :         OUString callStringMethod( const char* _pMethodName, jmethodID& _inout_MethodID ) const;
     124             :         OUString callStringMethodWithIntArg( const char* _pMethodName, jmethodID& _inout_MethodID , sal_Int32 _nArgument) const;
     125             :         void            callVoidMethod_ThrowSQL( const char* _pMethodName, jmethodID& _inout_MethodID) const;
     126             :         void            callVoidMethod_ThrowRuntime( const char* _pMethodName, jmethodID& _inout_MethodID) const;
     127             :         void            callVoidMethodWithIntArg_ThrowSQL( const char* _pMethodName, jmethodID& _inout_MethodID, sal_Int32 _nArgument ) const;
     128             :         void            callVoidMethodWithIntArg_ThrowRuntime( const char* _pMethodName, jmethodID& _inout_MethodID, sal_Int32 _nArgument ) const;
     129             :         void            callVoidMethodWithBoolArg_ThrowSQL( const char* _pMethodName, jmethodID& _inout_MethodID, bool _nArgument ) const;
     130             :         void            callVoidMethodWithBoolArg_ThrowRuntime( const char* _pMethodName, jmethodID& _inout_MethodID, bool _nArgument ) const;
     131             :         void            callVoidMethodWithStringArg( const char* _pMethodName, jmethodID& _inout_MethodID, const OUString& _nArgument ) const;
     132             :         jobject         callObjectMethod( JNIEnv * pEnv, const char* _pMethodName, const char* _pSignature, jmethodID& _inout_MethodID ) const;
     133             :         jobject         callObjectMethodWithIntArg( JNIEnv * pEnv, const char* _pMethodName, const char* _pSignature, jmethodID& _inout_MethodID , sal_Int32 _nArgument) const;
     134             : 
     135             :         template< typename T >
     136           3 :                         T callMethodWithIntArg(T (JNIEnv::*pCallMethod)( jobject obj, jmethodID methodID, ... ) ,const char* _pMethodName, const char* _pSignature, jmethodID& _inout_MethodID , sal_Int32 _nArgument) const
     137             :         {
     138           3 :             SDBThreadAttach t;
     139           3 :             obtainMethodId_throwSQL(t.pEnv, _pMethodName,_pSignature, _inout_MethodID);
     140           3 :             T out = (t.pEnv->*pCallMethod)( object, _inout_MethodID,_nArgument);
     141           3 :             ThrowSQLException( t.pEnv, NULL );
     142           3 :             return out;
     143             :         }
     144             : 
     145             :         template< typename T >
     146       14101 :                         void callVoidMethod_ThrowSQL(const char* _pMethodName, const char* _pSignature, jmethodID& _inout_MethodID,sal_Int32 _nArgument, const T& _aValue) const
     147             :         {
     148       14101 :             SDBThreadAttach t;
     149       14101 :             obtainMethodId_throwSQL(t.pEnv, _pMethodName,_pSignature, _inout_MethodID);
     150       14101 :             t.pEnv->CallVoidMethod( object, _inout_MethodID,_nArgument,_aValue);
     151       14101 :             ThrowSQLException( t.pEnv, NULL );
     152       14101 :         }
     153             : 
     154             : 
     155             :     };
     156             : }
     157             : #endif //_CONNECTIVITY_JAVA_LANG_OBJJECT_HXX_
     158             : 
     159             : 
     160             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11