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 :
20 : #include "sal/config.h"
21 :
22 : #include "jvmaccess/unovirtualmachine.hxx"
23 :
24 : #include "osl/diagnose.h"
25 :
26 : #include "jvmaccess/virtualmachine.hxx"
27 :
28 : #if defined SOLAR_JAVA
29 : #include "jni.h"
30 : #endif
31 :
32 : namespace jvmaccess {
33 :
34 0 : UnoVirtualMachine::CreationException::CreationException() {}
35 :
36 0 : UnoVirtualMachine::CreationException::CreationException(
37 0 : CreationException const &)
38 0 : {}
39 :
40 0 : UnoVirtualMachine::CreationException::~CreationException() {}
41 :
42 : UnoVirtualMachine::CreationException &
43 0 : UnoVirtualMachine::CreationException::operator =(CreationException const &) {
44 0 : return *this;
45 : }
46 :
47 0 : UnoVirtualMachine::UnoVirtualMachine(
48 : rtl::Reference< jvmaccess::VirtualMachine > const & virtualMachine,
49 : void * classLoader):
50 : m_virtualMachine(virtualMachine),
51 0 : m_classLoader(0)
52 : {
53 : #if defined SOLAR_JAVA
54 : try {
55 : m_classLoader =
56 : jvmaccess::VirtualMachine::AttachGuard(m_virtualMachine).
57 0 : getEnvironment()->NewGlobalRef(static_cast< jobject >(classLoader));
58 0 : } catch (jvmaccess::VirtualMachine::AttachGuard::CreationException &) {}
59 : #else
60 : (void) classLoader;
61 : #endif
62 0 : if (m_classLoader == 0) {
63 0 : throw CreationException();
64 : }
65 0 : }
66 :
67 : rtl::Reference< jvmaccess::VirtualMachine >
68 0 : UnoVirtualMachine::getVirtualMachine() const {
69 0 : return m_virtualMachine;
70 : }
71 :
72 0 : void * UnoVirtualMachine::getClassLoader() const {
73 0 : return m_classLoader;
74 : }
75 :
76 0 : UnoVirtualMachine::~UnoVirtualMachine() {
77 : #if defined SOLAR_JAVA
78 : try {
79 : jvmaccess::VirtualMachine::AttachGuard(m_virtualMachine).
80 : getEnvironment()->DeleteGlobalRef(
81 0 : static_cast< jobject >(m_classLoader));
82 0 : } catch (jvmaccess::VirtualMachine::AttachGuard::CreationException &) {
83 : OSL_TRACE(
84 : "jvmaccess::UnoVirtualMachine::~UnoVirtualMachine:"
85 : " jvmaccess::VirtualMachine::AttachGuard::CreationException" );
86 : }
87 : #endif
88 0 : }
89 :
90 : }
91 :
92 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|