1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_STOC_SOURCE_JAVAVM_JAVAVM_HXX
21 #define INCLUDED_STOC_SOURCE_JAVAVM_JAVAVM_HXX
25 #include <com/sun/star/container/XContainerListener.hpp>
26 #include <com/sun/star/lang/XInitialization.hpp>
27 #include <com/sun/star/java/XJavaThreadRegister_11.hpp>
28 #include <com/sun/star/java/XJavaVM.hpp>
29 #include <com/sun/star/lang/XServiceInfo.hpp>
30 #include <com/sun/star/uno/Reference.hxx>
31 #include <cppuhelper/basemutex.hxx>
32 #include <cppuhelper/compbase.hxx>
33 #include <osl/thread.hxx>
34 #include <rtl/ref.hxx>
35 #include <rtl/ustring.hxx>
37 namespace com::sun::star
{
38 namespace container
{ class XContainer
; }
39 namespace uno
{ class XComponentContext
; }
42 class UnoVirtualMachine
;
46 namespace stoc_javavm
{
48 // The MS compiler needs a typedef here, so the JavaVirtualMachine ctor can call
49 // its base class ctor:
51 cppu::WeakComponentImplHelper
< css::lang::XInitialization
,
52 css::lang::XServiceInfo
,
54 css::java::XJavaThreadRegister_11
,
55 css::container::XContainerListener
>
56 JavaVirtualMachine_Impl
;
58 class JavaVirtualMachine
:
59 private cppu::BaseMutex
, public JavaVirtualMachine_Impl
62 explicit JavaVirtualMachine(
64 css::uno::XComponentContext
> const & rContext
);
68 initialize(css::uno::Sequence
< css::uno::Any
> const &
72 virtual OUString SAL_CALL
getImplementationName() override
;
74 virtual sal_Bool SAL_CALL
75 supportsService(OUString
const & rServiceName
) override
;
77 virtual css::uno::Sequence
< OUString
> SAL_CALL
78 getSupportedServiceNames() override
;
81 virtual css::uno::Any SAL_CALL
82 getJavaVM(css::uno::Sequence
< sal_Int8
> const & rProcessId
) override
;
84 virtual sal_Bool SAL_CALL
isVMStarted() override
;
86 virtual sal_Bool SAL_CALL
isVMEnabled() override
;
88 // XJavaThreadRegister_11
89 virtual sal_Bool SAL_CALL
isThreadAttached() override
;
91 virtual void SAL_CALL
registerThread() override
;
93 virtual void SAL_CALL
revokeThread() override
;
97 disposing(css::lang::EventObject
const & rSource
) override
;
100 elementInserted(css::container::ContainerEvent
const & rEvent
) override
;
102 virtual void SAL_CALL
103 elementRemoved(css::container::ContainerEvent
const & rEvent
) override
;
105 virtual void SAL_CALL
106 elementReplaced(css::container::ContainerEvent
const & rEvent
) override
;
109 virtual void SAL_CALL
113 JavaVirtualMachine(JavaVirtualMachine
const &) = delete;
114 void operator =(const JavaVirtualMachine
&) = delete;
116 virtual ~JavaVirtualMachine() override
;
118 virtual void SAL_CALL
disposing() override
;
120 void registerConfigChangesListener();
122 void setINetSettingsInVM(bool set_reset
);
124 void setUpUnoVirtualMachine(JNIEnv
* environment
);
126 void handleJniException(JNIEnv
* environment
);
128 css::uno::Reference
< css::uno::XComponentContext
>
131 // the following are controlled by BaseMutex::m_aMutex:
133 rtl::Reference
< jvmaccess::VirtualMachine
> m_xVirtualMachine
;
134 rtl::Reference
< jvmaccess::UnoVirtualMachine
> m_xUnoVirtualMachine
;
136 // If the first creation of Java failed and this flag is set then the
137 // next call to getJavaVM throws a RuntimException. This is useful when
138 // the second attempt to create Java might cause a crash.
139 css::uno::Reference
< css::container::XContainer
>
140 m_xInetConfiguration
;
141 css::uno::Reference
< css::container::XContainer
>
142 m_xJavaConfiguration
; // for Java settings
144 osl::ThreadData m_aAttachGuards
;
149 #endif // INCLUDED_STOC_SOURCE_JAVAVM_JAVAVM_HXX
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */