LibreOffice Module stoc (master) 1
javavm.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#ifndef INCLUDED_STOC_SOURCE_JAVAVM_JAVAVM_HXX
21#define INCLUDED_STOC_SOURCE_JAVAVM_JAVAVM_HXX
22
23#if defined __clang__
24#pragma clang diagnostic push
25#pragma clang diagnostic ignored "-Wunknown-attributes"
26#endif
27#include <jni.h>
28#if defined __clang__
29#pragma clang diagnostic pop
30#endif
31
32#include <com/sun/star/container/XContainerListener.hpp>
33#include <com/sun/star/lang/XInitialization.hpp>
34#include <com/sun/star/java/XJavaThreadRegister_11.hpp>
35#include <com/sun/star/java/XJavaVM.hpp>
36#include <com/sun/star/lang/XServiceInfo.hpp>
37#include <com/sun/star/uno/Reference.hxx>
40#include <osl/thread.hxx>
41#include <rtl/ref.hxx>
42#include <rtl/ustring.hxx>
43
44namespace com::sun::star {
45 namespace container { class XContainer; }
46 namespace uno { class XComponentContext; }
47}
48namespace jvmaccess {
49 class UnoVirtualMachine;
50 class VirtualMachine;
51}
52
53namespace stoc_javavm {
54
56 private cppu::BaseMutex,
57 public cppu::WeakComponentImplHelper<
58 css::lang::XInitialization, css::lang::XServiceInfo, css::java::XJavaVM,
59 css::java::XJavaThreadRegister_11, css::container::XContainerListener>
60{
61public:
62 explicit JavaVirtualMachine(
63 css::uno::Reference<
64 css::uno::XComponentContext > xContext);
65
66 // XInitialization
67 virtual void SAL_CALL
68 initialize(css::uno::Sequence< css::uno::Any > const &
69 rArguments) override;
70
71 // XServiceInfo
72 virtual OUString SAL_CALL getImplementationName() override;
73
74 virtual sal_Bool SAL_CALL
75 supportsService(OUString const & rServiceName) override;
76
77 virtual css::uno::Sequence< OUString > SAL_CALL
78 getSupportedServiceNames() override;
79
80 // XJavaVM
81 virtual css::uno::Any SAL_CALL
82 getJavaVM(css::uno::Sequence< sal_Int8 > const & rProcessId) override;
83
84 virtual sal_Bool SAL_CALL isVMStarted() override;
85
86 virtual sal_Bool SAL_CALL isVMEnabled() override;
87
88 // XJavaThreadRegister_11
89 virtual sal_Bool SAL_CALL isThreadAttached() override;
90
91 virtual void SAL_CALL registerThread() override;
92
93 virtual void SAL_CALL revokeThread() override;
94
95 // XContainerListener
96 virtual void SAL_CALL
97 disposing(css::lang::EventObject const & rSource) override;
98
99 virtual void SAL_CALL
100 elementInserted(css::container::ContainerEvent const & rEvent) override;
101
102 virtual void SAL_CALL
103 elementRemoved(css::container::ContainerEvent const & rEvent) override;
104
105 virtual void SAL_CALL
106 elementReplaced(css::container::ContainerEvent const & rEvent) override;
107
108private:
110 void operator =(const JavaVirtualMachine&) = delete;
111
112 virtual ~JavaVirtualMachine() override;
113
114 virtual void SAL_CALL disposing() override;
115
117
118 void setINetSettingsInVM(bool set_reset);
119
120 void setUpUnoVirtualMachine(JNIEnv * environment);
121
122 void handleJniException(JNIEnv * environment);
123
124 css::uno::Reference< css::uno::XComponentContext >
126
127 // the following are controlled by BaseMutex::m_aMutex:
131 JavaVM * m_pJavaVm;
132 // If the first creation of Java failed and this flag is set then the
133 // next call to getJavaVM throws a RuntimException. This is useful when
134 // the second attempt to create Java might cause a crash.
135 css::uno::Reference< css::container::XContainer >
137 css::uno::Reference< css::container::XContainer >
138 m_xJavaConfiguration; // for Java settings
139
140 osl::ThreadData m_aAttachGuards;
141};
142
143}
144
145#endif // INCLUDED_STOC_SOURCE_JAVAVM_JAVAVM_HXX
146
147/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL elementInserted(css::container::ContainerEvent const &rEvent) override
Definition: javavm.cxx:882
virtual sal_Bool SAL_CALL isThreadAttached() override
Definition: javavm.cxx:806
virtual void SAL_CALL elementReplaced(css::container::ContainerEvent const &rEvent) override
Definition: javavm.cxx:895
virtual void SAL_CALL revokeThread() override
Definition: javavm.cxx:852
virtual ~JavaVirtualMachine() override
Definition: javavm.cxx:1123
void handleJniException(JNIEnv *environment)
Definition: javavm.cxx:1464
JavaVirtualMachine(css::uno::Reference< css::uno::XComponentContext > xContext)
Definition: javavm.cxx:473
virtual void SAL_CALL elementRemoved(css::container::ContainerEvent const &rEvent) override
Definition: javavm.cxx:886
virtual void SAL_CALL registerThread() override
Definition: javavm.cxx:819
rtl::Reference< jvmaccess::VirtualMachine > m_xVirtualMachine
Definition: javavm.hxx:129
css::uno::Reference< css::container::XContainer > m_xJavaConfiguration
Definition: javavm.hxx:138
rtl::Reference< jvmaccess::UnoVirtualMachine > m_xUnoVirtualMachine
Definition: javavm.hxx:130
JavaVirtualMachine(JavaVirtualMachine const &)=delete
virtual sal_Bool SAL_CALL supportsService(OUString const &rServiceName) override
Definition: javavm.cxx:545
virtual OUString SAL_CALL getImplementationName() override
Definition: javavm.cxx:539
css::uno::Reference< css::uno::XComponentContext > m_xContext
Definition: javavm.hxx:125
virtual css::uno::Any SAL_CALL getJavaVM(css::uno::Sequence< sal_Int8 > const &rProcessId) override
Definition: javavm.cxx:557
virtual sal_Bool SAL_CALL isVMEnabled() override
Definition: javavm.cxx:788
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: javavm.cxx:551
void operator=(const JavaVirtualMachine &)=delete
virtual void SAL_CALL disposing() override
Definition: javavm.cxx:1147
css::uno::Reference< css::container::XContainer > m_xInetConfiguration
Definition: javavm.hxx:136
void setINetSettingsInVM(bool set_reset)
Definition: javavm.cxx:1221
osl::ThreadData m_aAttachGuards
Definition: javavm.hxx:140
virtual void SAL_CALL initialize(css::uno::Sequence< css::uno::Any > const &rArguments) override
Definition: javavm.cxx:483
virtual sal_Bool SAL_CALL isVMStarted() override
Definition: javavm.cxx:779
void setUpUnoVirtualMachine(JNIEnv *environment)
Definition: javavm.cxx:1350
unsigned char sal_Bool