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: Object.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 ************************************************************************/
30 #ifndef _CONNECTIVITY_JAVA_LANG_OBJECT_HXX_
31 #define _CONNECTIVITY_JAVA_LANG_OBJECT_HXX_
33 #if STLPORT_VERSION>=321
34 // jni.h needs cstdarg for std::va_list
37 #include <osl/thread.h>
38 #include <com/sun/star/sdbc/SQLException.hpp>
39 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
40 #include <osl/diagnose.h>
41 #include <jvmaccess/virtualmachine.hxx>
44 #include <boost/shared_ptr.hpp>
46 //=====================================================================
48 #ifdef HAVE_64BIT_POINTERS
49 #error "no 64 bit pointer"
52 #define PVOID_TO_INT64(x) (jlong)(sal_Int32)x
53 #define INT64_TO_PVOID(x) (void *)x
55 #endif //HAVE_64BIT_POINTERS
59 class ResourceBasedEventLogger
;
62 namespace connectivity
64 typedef ::boost::shared_ptr
< jvmaccess::VirtualMachine::AttachGuard
> TGuard
;
67 jvmaccess::VirtualMachine::AttachGuard m_aGuard
;
68 SDBThreadAttach(SDBThreadAttach
&);
69 SDBThreadAttach
& operator= (SDBThreadAttach
&);
76 static void releaseRef();
81 // according to the documentation of jvmaccess::VirtualMachine::AttachGuard, our env is never
82 // NULL, so why bothering with pointer checks?
86 //=====================================================================
87 //=====================================================================
88 class java_lang_Class
;
89 class java_lang_Object
91 // Zuweisungsoperator und Copy Konstruktor sind verboten
92 java_lang_Object
& operator= (java_lang_Object
&);
93 java_lang_Object(java_lang_Object
&);
95 // nur zum Zerstoeren des C++ Pointers in vom JSbxObject
96 // abgeleiteten Java Objekten
97 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
> m_xFactory
;
100 // der JAVA Handle zu dieser Klasse
105 static jclass theClass
; // die Klasse braucht nur einmal angefordert werden !
107 virtual jclass
getMyClass() const;
110 // der Konstruktor, der fuer die abgeleiteten Klassen verwendet
112 java_lang_Object( JNIEnv
* pEnv
, jobject myObj
);
113 // der eigentliche Konstruktor
114 java_lang_Object(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rxFactory
=NULL
);
116 virtual ~java_lang_Object();
118 void saveRef( JNIEnv
* pEnv
, jobject myObj
);
119 jobject
getJavaObject() const { return object
; }
120 java_lang_Object
* GetWrapper() { return this; }
121 void clearObject(JNIEnv
& rEnv
);
124 java_lang_Class
* getClass();
126 virtual ::rtl::OUString
toString() const;
127 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
> getORB() { return m_xFactory
; }
129 static void ThrowSQLException(JNIEnv
* pEnv
,const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> & _rContext
);
130 static void ThrowLoggedSQLException(
131 const ::comphelper::ResourceBasedEventLogger
& _rLogger
,
132 JNIEnv
* pEnvironment
,
133 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _rxContext
136 static ::rtl::Reference
< jvmaccess::VirtualMachine
> getVM(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rxFactory
=NULL
);
138 static jclass
findMyClass(const char* _pClassName
);
139 void obtainMethodId(JNIEnv
* _pEnv
, const char* _pMethodName
, const char* _pSignature
, jmethodID
& _inout_MethodID
) const;
141 sal_Bool
callBooleanMethod( const char* _pMethodName
, jmethodID
& _inout_MethodID
) const;
142 sal_Bool
callBooleanMethodWithIntArg( const char* _pMethodName
, jmethodID
& _inout_MethodID
, sal_Int32 _nArgument
) const;
143 jobject
callResultSetMethod( JNIEnv
& _rEnv
, const char* _pMethodName
, jmethodID
& _inout_MethodID
) const;
144 sal_Int32
callIntMethod( const char* _pMethodName
, jmethodID
& _inout_MethodID
,bool _bIgnoreException
= false ) const;
145 sal_Int32
callIntMethodWithIntArg( const char* _pMethodName
, jmethodID
& _inout_MethodID
, sal_Int32 _nArgument
) const;
146 sal_Int32
callIntMethodWithStringArg( const char* _pMethodName
, jmethodID
& _inout_MethodID
,const ::rtl::OUString
& _nArgument
) const;
147 ::rtl::OUString
callStringMethod( const char* _pMethodName
, jmethodID
& _inout_MethodID
) const;
148 ::rtl::OUString
callStringMethodWithIntArg( const char* _pMethodName
, jmethodID
& _inout_MethodID
, sal_Int32 _nArgument
) const;
149 void callVoidMethod( const char* _pMethodName
, jmethodID
& _inout_MethodID
) const;
150 void callVoidMethodWithIntArg( const char* _pMethodName
, jmethodID
& _inout_MethodID
, sal_Int32 _nArgument
,bool _bIgnoreException
= false ) const;
151 void callVoidMethodWithBoolArg( const char* _pMethodName
, jmethodID
& _inout_MethodID
, sal_Int32 _nArgument
,bool _bIgnoreException
= false ) const;
152 void callVoidMethodWithStringArg( const char* _pMethodName
, jmethodID
& _inout_MethodID
, const ::rtl::OUString
& _nArgument
) const;
153 jobject
callObjectMethod( JNIEnv
* pEnv
, const char* _pMethodName
, const char* _pSignature
, jmethodID
& _inout_MethodID
) const;
154 jobject
callObjectMethodWithIntArg( JNIEnv
* pEnv
, const char* _pMethodName
, const char* _pSignature
, jmethodID
& _inout_MethodID
, sal_Int32 _nArgument
) const;
156 template< typename T
>
157 T
callMethodWithIntArg(T (JNIEnv::*pCallMethod
)( jobject obj
, jmethodID methodID
, ... ) ,const char* _pMethodName
, const char* _pSignature
, jmethodID
& _inout_MethodID
, sal_Int32 _nArgument
) const
160 obtainMethodId(t
.pEnv
, _pMethodName
,_pSignature
, _inout_MethodID
);
161 T out
= (t
.pEnv
->*pCallMethod
)( object
, _inout_MethodID
,_nArgument
);
162 ThrowSQLException( t
.pEnv
, NULL
);
166 template< typename T
>
167 void callVoidMethod(const char* _pMethodName
, const char* _pSignature
, jmethodID
& _inout_MethodID
,sal_Int32 _nArgument
, const T
& _aValue
) const
170 obtainMethodId(t
.pEnv
, _pMethodName
,_pSignature
, _inout_MethodID
);
171 t
.pEnv
->CallVoidMethod( object
, _inout_MethodID
,_nArgument
,_aValue
);
172 ThrowSQLException( t
.pEnv
, NULL
);
178 #endif //_CONNECTIVITY_JAVA_LANG_OBJJECT_HXX_