Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / jvmaccess / source / unovirtualmachine.cxx
bloba2c038571d6229d91c829439b4f7906840445214
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "sal/config.h"
31 #include "jvmaccess/unovirtualmachine.hxx"
33 #include "osl/diagnose.h"
35 #include "jvmaccess/virtualmachine.hxx"
37 #if defined SOLAR_JAVA
38 #include "jni.h"
39 #endif
41 namespace jvmaccess {
43 UnoVirtualMachine::CreationException::CreationException() {}
45 UnoVirtualMachine::CreationException::CreationException(
46 CreationException const &)
49 UnoVirtualMachine::CreationException::~CreationException() {}
51 UnoVirtualMachine::CreationException &
52 UnoVirtualMachine::CreationException::operator =(CreationException const &) {
53 return *this;
56 UnoVirtualMachine::UnoVirtualMachine(
57 rtl::Reference< jvmaccess::VirtualMachine > const & virtualMachine,
58 void * classLoader):
59 m_virtualMachine(virtualMachine),
60 m_classLoader(0)
62 #if defined SOLAR_JAVA
63 try {
64 m_classLoader =
65 jvmaccess::VirtualMachine::AttachGuard(m_virtualMachine).
66 getEnvironment()->NewGlobalRef(static_cast< jobject >(classLoader));
67 } catch (jvmaccess::VirtualMachine::AttachGuard::CreationException &) {}
68 #else
69 (void) classLoader;
70 #endif
71 if (m_classLoader == 0) {
72 throw CreationException();
76 rtl::Reference< jvmaccess::VirtualMachine >
77 UnoVirtualMachine::getVirtualMachine() const {
78 return m_virtualMachine;
81 void * UnoVirtualMachine::getClassLoader() const {
82 return m_classLoader;
85 UnoVirtualMachine::~UnoVirtualMachine() {
86 #if defined SOLAR_JAVA
87 try {
88 jvmaccess::VirtualMachine::AttachGuard(m_virtualMachine).
89 getEnvironment()->DeleteGlobalRef(
90 static_cast< jobject >(m_classLoader));
91 } catch (jvmaccess::VirtualMachine::AttachGuard::CreationException &) {
92 OSL_TRACE(
93 "jvmaccess::UnoVirtualMachine::~UnoVirtualMachine:"
94 " jvmaccess::VirtualMachine::AttachGuard::CreationException" );
96 #endif
101 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */