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: LocalRef.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 ************************************************************************/
31 #ifndef CONNECTIVITY_LOCALREF_HXX
32 #define CONNECTIVITY_LOCALREF_HXX
34 /** === begin UNO includes === **/
35 /** === end UNO includes === **/
37 #include <jvmaccess/virtualmachine.hxx>
39 //........................................................................
40 namespace connectivity
{ namespace jdbc
42 //........................................................................
44 //====================================================================
46 //====================================================================
47 /** helper class to hold a local ref to a JNI object
49 Note that this class never actually calls NewLocalRef. It is assumed that all objects
50 passed are already acquired with a local ref (as it usually is the case if you obtain
51 the object from an JNI method).
53 template< typename T
>
57 explicit LocalRef( JNIEnv
& environment
)
58 :m_environment( environment
)
63 LocalRef( JNIEnv
& environment
, T object
)
64 :m_environment( environment
)
81 void set( T object
) { reset(); m_object
= object
; }
85 if ( m_object
!= NULL
)
87 m_environment
.DeleteLocalRef( m_object
);
92 JNIEnv
& env() const { return m_environment
; }
93 T
get() const { return m_object
; }
94 bool is() const { return m_object
!= NULL
; }
97 LocalRef(LocalRef
&); // not defined
98 void operator =(LocalRef
&); // not defined
101 JNIEnv
& m_environment
;
105 //........................................................................
106 } } // namespace connectivity::jdbc
107 //........................................................................
109 #endif // CONNECTIVITY_LOCALREF_HXX