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 #ifndef INCLUDED_JVMACCESS_UNOVIRTUALMACHINE_HXX 25 #define INCLUDED_JVMACCESS_UNOVIRTUALMACHINE_HXX 26 27 #include "sal/config.h" 28 #include "salhelper/simplereferenceobject.hxx" 29 #include "rtl/ref.hxx" 30 31 namespace jvmaccess { 32 33 class VirtualMachine; 34 35 /** An encapsulating wrapper around a Java virtual machine and an appropriate 36 UNO class loader. 37 */ 38 class UnoVirtualMachine: public salhelper::SimpleReferenceObject { 39 public: 40 /** An exception indicating failure to create a UnoVirtualMachine. 41 */ 42 class CreationException 43 { 44 public: 45 CreationException(); 46 47 CreationException(CreationException const &); 48 49 virtual ~CreationException(); 50 51 CreationException & operator =(CreationException const &); 52 }; 53 54 /** Create a wrapper around a Java virtual machine and an appropriate UNO 55 class loader. 56 57 @param virtualMachine 58 A Java virtual machine wrapper. Must not be null. 59 60 @param classLoader 61 A local or global JNI reference, relative to the given virtualMachine, 62 to an appropriate UNO class loader instance. Must not be null. This 63 parameter should be of type jobject, not void *, but the exact 64 definition of jobject is different for different JDK versions, so that 65 the mangled C++ name of the constructor would depend on the JDK version 66 used at compile time. 67 68 @exception CreationException 69 Thrown in case creation fails (due to a JNI problem). 70 */ 71 UnoVirtualMachine( 72 rtl::Reference< jvmaccess::VirtualMachine > const & virtualMachine, 73 void * classLoader); 74 75 /** Get the Java virtual machine wrapper. 76 77 @return 78 The Java virtual machine wrapper. Will never be null. 79 */ 80 rtl::Reference< jvmaccess::VirtualMachine > getVirtualMachine() const; 81 82 /** Get the UNO class loader. 83 84 @return 85 A global JNI reference to the UNO class loader. (The JNI reference must 86 not be deleted by client code.) Will never be null. This should be of 87 type jobject, not void *, but the exact definition of jobject is 88 different for different JDK versions, so that the mangled C++ name of 89 the function would depend on the JDK version used at compile time. 90 */ 91 void * getClassLoader() const; 92 93 private: 94 UnoVirtualMachine(UnoVirtualMachine &); // not defined 95 void operator =(UnoVirtualMachine &); // not defined 96 97 virtual ~UnoVirtualMachine(); 98 99 rtl::Reference< jvmaccess::VirtualMachine > m_virtualMachine; 100 void * m_classLoader; 101 }; 102 103 } 104 105 #endif 106