update dev300-m57
[ooovba.git] / jvmaccess / source / unovirtualmachine.cxx
blobf239cce492eea95f950263e8dec7faaab62d44ee
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unovirtualmachine.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "sal/config.h"
33 #include "jvmaccess/unovirtualmachine.hxx"
35 #include "osl/diagnose.h"
37 #include "jvmaccess/virtualmachine.hxx"
39 #if defined SOLAR_JAVA
40 #include "jni.h"
41 #endif
43 namespace jvmaccess {
45 UnoVirtualMachine::CreationException::CreationException() {}
47 UnoVirtualMachine::CreationException::CreationException(
48 CreationException const &)
51 UnoVirtualMachine::CreationException::~CreationException() {}
53 UnoVirtualMachine::CreationException &
54 UnoVirtualMachine::CreationException::operator =(CreationException const &) {
55 return *this;
58 UnoVirtualMachine::UnoVirtualMachine(
59 rtl::Reference< jvmaccess::VirtualMachine > const & virtualMachine,
60 void * classLoader):
61 m_virtualMachine(virtualMachine),
62 m_classLoader(0)
64 #if defined SOLAR_JAVA
65 try {
66 m_classLoader =
67 jvmaccess::VirtualMachine::AttachGuard(m_virtualMachine).
68 getEnvironment()->NewGlobalRef(static_cast< jobject >(classLoader));
69 } catch (jvmaccess::VirtualMachine::AttachGuard::CreationException &) {}
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