xref: /aoo42x/main/stoc/source/javavm/javavm.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #if !defined INCLUDED_STOC_JAVAVM_JAVAVM_HXX
29 #define INCLUDED_STOC_JAVAVM_JAVAVM_HXX
30 
31 #include "jvmargs.hxx"
32 
33 #include "com/sun/star/container/XContainerListener.hpp"
34 #include "com/sun/star/lang/XInitialization.hpp"
35 #include "com/sun/star/java/XJavaThreadRegister_11.hpp"
36 #include "com/sun/star/java/XJavaVM.hpp"
37 #include "com/sun/star/lang/XServiceInfo.hpp"
38 #include "com/sun/star/uno/Reference.hxx"
39 #include "cppuhelper/compbase5.hxx"
40 #include "osl/thread.hxx"
41 #include "rtl/ref.hxx"
42 #include <osl/mutex.hxx>
43 #include <rtl/ustring.hxx>
44 
45 namespace com { namespace sun { namespace star {
46     namespace container { class XContainer; }
47     namespace uno { class XComponentContext; }
48 } } }
49 namespace jvmaccess {
50     class UnoVirtualMachine;
51     class VirtualMachine;
52 }
53 
54 namespace stoc_javavm {
55 
56 bool configureJava(const com::sun::star::uno::Reference<
57                    com::sun::star::uno::XComponentContext>& xContext);
58 // The MS compiler needs a typedef here, so the JavaVirtualMachine ctor can call
59 // its base class ctor:
60 typedef
61 cppu::WeakComponentImplHelper5< com::sun::star::lang::XInitialization,
62                                 com::sun::star::lang::XServiceInfo,
63                                 com::sun::star::java::XJavaVM,
64                                 com::sun::star::java::XJavaThreadRegister_11,
65                                 com::sun::star::container::XContainerListener >
66 JavaVirtualMachine_Impl;
67 
68 class JavaVirtualMachine: private osl::Mutex, public JavaVirtualMachine_Impl
69 {
70 public:
71     explicit JavaVirtualMachine(
72         com::sun::star::uno::Reference<
73             com::sun::star::uno::XComponentContext > const & rContext);
74 
75     // XInitialization
76     virtual void SAL_CALL
77     initialize(com::sun::star::uno::Sequence< com::sun::star::uno::Any > const &
78                    rArguments)
79         throw (com::sun::star::uno::Exception);
80 
81     // XServiceInfo
82     virtual rtl::OUString SAL_CALL getImplementationName()
83         throw (com::sun::star::uno::RuntimeException);
84 
85     virtual sal_Bool SAL_CALL
86     supportsService(rtl::OUString const & rServiceName)
87         throw (com::sun::star::uno::RuntimeException);
88 
89     virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL
90     getSupportedServiceNames() throw (com::sun::star::uno::RuntimeException);
91 
92     // XJavaVM
93     virtual com::sun::star::uno::Any SAL_CALL
94     getJavaVM(com::sun::star::uno::Sequence< sal_Int8 > const & rProcessId)
95         throw (com::sun::star::uno::RuntimeException);
96 
97     virtual sal_Bool SAL_CALL isVMStarted()
98         throw (com::sun::star::uno::RuntimeException);
99 
100     virtual sal_Bool SAL_CALL isVMEnabled()
101         throw (com::sun::star::uno::RuntimeException);
102 
103     // XJavaThreadRegister_11
104     virtual sal_Bool SAL_CALL isThreadAttached()
105         throw (com::sun::star::uno::RuntimeException);
106 
107     virtual void SAL_CALL registerThread()
108         throw (com::sun::star::uno::RuntimeException);
109 
110     virtual void SAL_CALL revokeThread()
111         throw (com::sun::star::uno::RuntimeException);
112 
113     // XContainerListener
114     virtual void SAL_CALL
115     disposing(com::sun::star::lang::EventObject const & rSource)
116         throw (com::sun::star::uno::RuntimeException);
117 
118     virtual void SAL_CALL
119     elementInserted(com::sun::star::container::ContainerEvent const & rEvent)
120         throw (com::sun::star::uno::RuntimeException);
121 
122     virtual void SAL_CALL
123     elementRemoved(com::sun::star::container::ContainerEvent const & rEvent)
124         throw (com::sun::star::uno::RuntimeException);
125 
126     virtual void SAL_CALL
127     elementReplaced(com::sun::star::container::ContainerEvent const & rEvent)
128         throw (com::sun::star::uno::RuntimeException);
129 
130 private:
131     JavaVirtualMachine(JavaVirtualMachine &); // not implemented
132     void operator =(JavaVirtualMachine); // not implemented
133 
134     virtual ~JavaVirtualMachine();
135 
136     virtual void SAL_CALL disposing();
137 
138     JavaVM * createJavaVM(JVM const & jvm, JNIEnv ** pMainThreadEnv);
139         // throws com::sun::star::uno::RuntimeException
140 
141     void registerConfigChangesListener();
142 
143     void setINetSettingsInVM(bool set_reset);
144 
145     void setUpUnoVirtualMachine(JNIEnv * environment);
146 
147     void handleJniException(JNIEnv * environment);
148 
149     com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
150         m_xContext;
151 
152     // the following are controlled by the 'this' mutex:
153     bool m_bDisposed;
154     rtl::Reference< jvmaccess::VirtualMachine > m_xVirtualMachine;
155     rtl::Reference< jvmaccess::UnoVirtualMachine > m_xUnoVirtualMachine;
156     JavaVM * m_pJavaVm;
157         // stored as an instance member for backwards compatibility in getJavaVM
158     bool m_bDontCreateJvm;
159         // If the first creation of Java failed and this flag is set then the
160         // next call to getJavaVM throws a RuntimException.  This is useful when
161         // the second attempt to create Java might cause a crash.
162     com::sun::star::uno::Reference< com::sun::star::container::XContainer >
163         m_xInetConfiguration;
164     com::sun::star::uno::Reference< com::sun::star::container::XContainer >
165         m_xJavaConfiguration; // for Java settings
166 
167     osl::ThreadData m_aAttachGuards;
168 };
169 
170 }
171 
172 #endif // INCLUDED_STOC_JAVAVM_JAVAVM_HXX
173