1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_GLOBALREF_HXX
21 #define INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_GLOBALREF_HXX
23 #include "java/LocalRef.hxx"
24 #include "java/lang/Object.hxx"
26 #include <jvmaccess/virtualmachine.hxx>
29 namespace connectivity
{ namespace jdbc
31 /** helper class to hold a local ref to a JNI object
33 template< typename T
>
42 GlobalRef( const GlobalRef
& _source
)
48 GlobalRef
& operator=( const GlobalRef
& _source
)
50 if ( &_source
== this )
54 set( t
.env(), _source
.get() );
65 if ( m_object
!= NULL
)
68 t
.env().DeleteGlobalRef( m_object
);
73 void set( JNIEnv
& _environment
, T _object
)
75 if ( m_object
!= NULL
)
76 _environment
.DeleteGlobalRef( m_object
);
79 m_object
= static_cast< T
>( _environment
.NewGlobalRef( m_object
) );
82 void set( LocalRef
< T
>& _object
)
84 set( _object
.env(), _object
.release() );
94 return m_object
!= NULL
;
103 } } // namespace connectivity::jdbc
106 #endif // INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_GLOBALREF_HXX
108 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */