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