Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / jvmaccess / source / unovirtualmachine.cxx
blobdc2d680f5b1458f2dae3d89b82639ab1402ed877
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #include "sal/config.h"
22 #include "jvmaccess/unovirtualmachine.hxx"
24 #include "osl/diagnose.h"
26 #include "jvmaccess/virtualmachine.hxx"
28 #if defined SOLAR_JAVA
29 #include "jni.h"
30 #endif
32 namespace jvmaccess {
34 UnoVirtualMachine::CreationException::CreationException() {}
36 UnoVirtualMachine::CreationException::CreationException(
37 CreationException const &)
40 UnoVirtualMachine::CreationException::~CreationException() {}
42 UnoVirtualMachine::CreationException &
43 UnoVirtualMachine::CreationException::operator =(CreationException const &) {
44 return *this;
47 UnoVirtualMachine::UnoVirtualMachine(
48 rtl::Reference< jvmaccess::VirtualMachine > const & virtualMachine,
49 void * classLoader):
50 m_virtualMachine(virtualMachine),
51 m_classLoader(0)
53 #if defined SOLAR_JAVA
54 try {
55 m_classLoader =
56 jvmaccess::VirtualMachine::AttachGuard(m_virtualMachine).
57 getEnvironment()->NewGlobalRef(static_cast< jobject >(classLoader));
58 } catch (jvmaccess::VirtualMachine::AttachGuard::CreationException &) {}
59 #else
60 (void) classLoader;
61 #endif
62 if (m_classLoader == 0) {
63 throw CreationException();
67 rtl::Reference< jvmaccess::VirtualMachine >
68 UnoVirtualMachine::getVirtualMachine() const {
69 return m_virtualMachine;
72 void * UnoVirtualMachine::getClassLoader() const {
73 return m_classLoader;
76 UnoVirtualMachine::~UnoVirtualMachine() {
77 #if defined SOLAR_JAVA
78 try {
79 jvmaccess::VirtualMachine::AttachGuard(m_virtualMachine).
80 getEnvironment()->DeleteGlobalRef(
81 static_cast< jobject >(m_classLoader));
82 } catch (jvmaccess::VirtualMachine::AttachGuard::CreationException &) {
83 OSL_TRACE(
84 "jvmaccess::UnoVirtualMachine::~UnoVirtualMachine:"
85 " jvmaccess::VirtualMachine::AttachGuard::CreationException" );
87 #endif
92 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */