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