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