1*dff3f235SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*dff3f235SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*dff3f235SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*dff3f235SAndrew Rist  * distributed with this work for additional information
6*dff3f235SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*dff3f235SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*dff3f235SAndrew Rist  * "License"); you may not use this file except in compliance
9*dff3f235SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*dff3f235SAndrew Rist  *
11*dff3f235SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*dff3f235SAndrew Rist  *
13*dff3f235SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*dff3f235SAndrew Rist  * software distributed under the License is distributed on an
15*dff3f235SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*dff3f235SAndrew Rist  * KIND, either express or implied.  See the License for the
17*dff3f235SAndrew Rist  * specific language governing permissions and limitations
18*dff3f235SAndrew Rist  * under the License.
19*dff3f235SAndrew Rist  *
20*dff3f235SAndrew Rist  *************************************************************/
21*dff3f235SAndrew Rist 
22*dff3f235SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "sal/config.h"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "jvmaccess/unovirtualmachine.hxx"
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include "osl/diagnose.h"
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include "jvmaccess/virtualmachine.hxx"
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #if defined SOLAR_JAVA
33cdf0e10cSrcweir #include "jni.h"
34cdf0e10cSrcweir #endif
35cdf0e10cSrcweir 
36cdf0e10cSrcweir namespace jvmaccess {
37cdf0e10cSrcweir 
CreationException()38cdf0e10cSrcweir UnoVirtualMachine::CreationException::CreationException() {}
39cdf0e10cSrcweir 
CreationException(CreationException const &)40cdf0e10cSrcweir UnoVirtualMachine::CreationException::CreationException(
41cdf0e10cSrcweir     CreationException const &)
42cdf0e10cSrcweir {}
43cdf0e10cSrcweir 
~CreationException()44cdf0e10cSrcweir UnoVirtualMachine::CreationException::~CreationException() {}
45cdf0e10cSrcweir 
46cdf0e10cSrcweir UnoVirtualMachine::CreationException &
operator =(CreationException const &)47cdf0e10cSrcweir UnoVirtualMachine::CreationException::operator =(CreationException const &) {
48cdf0e10cSrcweir     return *this;
49cdf0e10cSrcweir }
50cdf0e10cSrcweir 
UnoVirtualMachine(rtl::Reference<jvmaccess::VirtualMachine> const & virtualMachine,void * classLoader)51cdf0e10cSrcweir UnoVirtualMachine::UnoVirtualMachine(
52cdf0e10cSrcweir     rtl::Reference< jvmaccess::VirtualMachine > const & virtualMachine,
53cdf0e10cSrcweir     void * classLoader):
54cdf0e10cSrcweir     m_virtualMachine(virtualMachine),
55cdf0e10cSrcweir     m_classLoader(0)
56cdf0e10cSrcweir {
57cdf0e10cSrcweir #if defined SOLAR_JAVA
58cdf0e10cSrcweir     try {
59cdf0e10cSrcweir         m_classLoader =
60cdf0e10cSrcweir             jvmaccess::VirtualMachine::AttachGuard(m_virtualMachine).
61cdf0e10cSrcweir             getEnvironment()->NewGlobalRef(static_cast< jobject >(classLoader));
62cdf0e10cSrcweir     } catch (jvmaccess::VirtualMachine::AttachGuard::CreationException &) {}
63cdf0e10cSrcweir #endif
64cdf0e10cSrcweir     if (m_classLoader == 0) {
65cdf0e10cSrcweir         throw CreationException();
66cdf0e10cSrcweir     }
67cdf0e10cSrcweir }
68cdf0e10cSrcweir 
69cdf0e10cSrcweir rtl::Reference< jvmaccess::VirtualMachine >
getVirtualMachine() const70cdf0e10cSrcweir UnoVirtualMachine::getVirtualMachine() const {
71cdf0e10cSrcweir     return m_virtualMachine;
72cdf0e10cSrcweir }
73cdf0e10cSrcweir 
getClassLoader() const74cdf0e10cSrcweir void * UnoVirtualMachine::getClassLoader() const {
75cdf0e10cSrcweir     return m_classLoader;
76cdf0e10cSrcweir }
77cdf0e10cSrcweir 
~UnoVirtualMachine()78cdf0e10cSrcweir UnoVirtualMachine::~UnoVirtualMachine() {
79cdf0e10cSrcweir #if defined SOLAR_JAVA
80cdf0e10cSrcweir     try {
81cdf0e10cSrcweir         jvmaccess::VirtualMachine::AttachGuard(m_virtualMachine).
82cdf0e10cSrcweir             getEnvironment()->DeleteGlobalRef(
83cdf0e10cSrcweir                 static_cast< jobject >(m_classLoader));
84cdf0e10cSrcweir     } catch (jvmaccess::VirtualMachine::AttachGuard::CreationException &) {
85cdf0e10cSrcweir         OSL_TRACE(
86cdf0e10cSrcweir             "jvmaccess::UnoVirtualMachine::~UnoVirtualMachine:"
87cdf0e10cSrcweir             " jvmaccess::VirtualMachine::AttachGuard::CreationException" );
88cdf0e10cSrcweir     }
89cdf0e10cSrcweir #endif
90cdf0e10cSrcweir }
91cdf0e10cSrcweir 
92cdf0e10cSrcweir }
93