xref: /aoo4110/main/stoc/source/javavm/javavm.hxx (revision b1cdbd2c)
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 #if !defined INCLUDED_STOC_JAVAVM_JAVAVM_HXX
25 #define INCLUDED_STOC_JAVAVM_JAVAVM_HXX
26 
27 #include "jvmargs.hxx"
28 
29 #include "com/sun/star/container/XContainerListener.hpp"
30 #include "com/sun/star/lang/XInitialization.hpp"
31 #include "com/sun/star/java/XJavaThreadRegister_11.hpp"
32 #include "com/sun/star/java/XJavaVM.hpp"
33 #include "com/sun/star/lang/XServiceInfo.hpp"
34 #include "com/sun/star/uno/Reference.hxx"
35 #include "cppuhelper/compbase5.hxx"
36 #include "osl/thread.hxx"
37 #include "rtl/ref.hxx"
38 #include <osl/mutex.hxx>
39 #include <rtl/ustring.hxx>
40 
41 namespace com { namespace sun { namespace star {
42     namespace container { class XContainer; }
43     namespace uno { class XComponentContext; }
44 } } }
45 namespace jvmaccess {
46     class UnoVirtualMachine;
47     class VirtualMachine;
48 }
49 
50 namespace stoc_javavm {
51 
52 bool configureJava(const com::sun::star::uno::Reference<
53                    com::sun::star::uno::XComponentContext>& xContext);
54 // The MS compiler needs a typedef here, so the JavaVirtualMachine ctor can call
55 // its base class ctor:
56 typedef
57 cppu::WeakComponentImplHelper5< com::sun::star::lang::XInitialization,
58                                 com::sun::star::lang::XServiceInfo,
59                                 com::sun::star::java::XJavaVM,
60                                 com::sun::star::java::XJavaThreadRegister_11,
61                                 com::sun::star::container::XContainerListener >
62 JavaVirtualMachine_Impl;
63 
64 class JavaVirtualMachine: private osl::Mutex, public JavaVirtualMachine_Impl
65 {
66 public:
67     explicit JavaVirtualMachine(
68         com::sun::star::uno::Reference<
69             com::sun::star::uno::XComponentContext > const & rContext);
70 
71     // XInitialization
72     virtual void SAL_CALL
73     initialize(com::sun::star::uno::Sequence< com::sun::star::uno::Any > const &
74                    rArguments)
75         throw (com::sun::star::uno::Exception);
76 
77     // XServiceInfo
78     virtual rtl::OUString SAL_CALL getImplementationName()
79         throw (com::sun::star::uno::RuntimeException);
80 
81     virtual sal_Bool SAL_CALL
82     supportsService(rtl::OUString const & rServiceName)
83         throw (com::sun::star::uno::RuntimeException);
84 
85     virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL
86     getSupportedServiceNames() throw (com::sun::star::uno::RuntimeException);
87 
88     // XJavaVM
89     virtual com::sun::star::uno::Any SAL_CALL
90     getJavaVM(com::sun::star::uno::Sequence< sal_Int8 > const & rProcessId)
91         throw (com::sun::star::uno::RuntimeException);
92 
93     virtual sal_Bool SAL_CALL isVMStarted()
94         throw (com::sun::star::uno::RuntimeException);
95 
96     virtual sal_Bool SAL_CALL isVMEnabled()
97         throw (com::sun::star::uno::RuntimeException);
98 
99     // XJavaThreadRegister_11
100     virtual sal_Bool SAL_CALL isThreadAttached()
101         throw (com::sun::star::uno::RuntimeException);
102 
103     virtual void SAL_CALL registerThread()
104         throw (com::sun::star::uno::RuntimeException);
105 
106     virtual void SAL_CALL revokeThread()
107         throw (com::sun::star::uno::RuntimeException);
108 
109     // XContainerListener
110     virtual void SAL_CALL
111     disposing(com::sun::star::lang::EventObject const & rSource)
112         throw (com::sun::star::uno::RuntimeException);
113 
114     virtual void SAL_CALL
115     elementInserted(com::sun::star::container::ContainerEvent const & rEvent)
116         throw (com::sun::star::uno::RuntimeException);
117 
118     virtual void SAL_CALL
119     elementRemoved(com::sun::star::container::ContainerEvent const & rEvent)
120         throw (com::sun::star::uno::RuntimeException);
121 
122     virtual void SAL_CALL
123     elementReplaced(com::sun::star::container::ContainerEvent const & rEvent)
124         throw (com::sun::star::uno::RuntimeException);
125 
126 private:
127     JavaVirtualMachine(JavaVirtualMachine &); // not implemented
128     void operator =(JavaVirtualMachine); // not implemented
129 
130     virtual ~JavaVirtualMachine();
131 
132     virtual void SAL_CALL disposing();
133 
134     JavaVM * createJavaVM(JVM const & jvm, JNIEnv ** pMainThreadEnv);
135         // throws com::sun::star::uno::RuntimeException
136 
137     void registerConfigChangesListener();
138 
139     void setINetSettingsInVM(bool set_reset);
140 
141     void setUpUnoVirtualMachine(JNIEnv * environment);
142 
143     void handleJniException(JNIEnv * environment);
144 
145     com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
146         m_xContext;
147 
148     // the following are controlled by the 'this' mutex:
149     bool m_bDisposed;
150     rtl::Reference< jvmaccess::VirtualMachine > m_xVirtualMachine;
151     rtl::Reference< jvmaccess::UnoVirtualMachine > m_xUnoVirtualMachine;
152     JavaVM * m_pJavaVm;
153         // stored as an instance member for backwards compatibility in getJavaVM
154     bool m_bDontCreateJvm;
155         // If the first creation of Java failed and this flag is set then the
156         // next call to getJavaVM throws a RuntimException.  This is useful when
157         // the second attempt to create Java might cause a crash.
158     com::sun::star::uno::Reference< com::sun::star::container::XContainer >
159         m_xInetConfiguration;
160     com::sun::star::uno::Reference< com::sun::star::container::XContainer >
161         m_xJavaConfiguration; // for Java settings
162 
163     osl::ThreadData m_aAttachGuards;
164 };
165 
166 }
167 
168 #endif // INCLUDED_STOC_JAVAVM_JAVAVM_HXX
169