tdf#156866 use mSize instead of mPixelSize for inverted surface
[LibreOffice.git] / javaunohelper / source / vm.cxx
blob7191e586027309b5d911e5fd775c79ce401562ac
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
21 #include <sal/config.h>
23 #include "vm.hxx"
25 #include <com/sun/star/beans/NamedValue.hpp>
26 #include <com/sun/star/lang/XSingleComponentFactory.hpp>
27 #include <cppuhelper/compbase.hxx>
28 #include <cppuhelper/component_context.hxx>
29 #include <cppuhelper/basemutex.hxx>
30 #include <jvmaccess/virtualmachine.hxx>
31 #include <jvmaccess/unovirtualmachine.hxx>
32 #include <utility>
34 namespace {
36 typedef ::cppu::WeakComponentImplHelper<
37 css::lang::XSingleComponentFactory > t_impl;
39 class SingletonFactory : public cppu::BaseMutex, public t_impl
41 ::rtl::Reference< ::jvmaccess::UnoVirtualMachine > m_vm_access;
43 protected:
44 virtual void SAL_CALL disposing() override;
46 public:
47 explicit SingletonFactory( ::rtl::Reference< ::jvmaccess::UnoVirtualMachine > vm_access )
48 : t_impl( m_aMutex ),
49 m_vm_access(std::move( vm_access ))
52 // XSingleComponentFactory impl
53 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithContext(
54 css::uno::Reference< css::uno::XComponentContext > const & xContext ) override;
55 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithArgumentsAndContext(
56 css::uno::Sequence< css::uno::Any > const & args, css::uno::Reference< css::uno::XComponentContext > const & xContext ) override;
59 void SingletonFactory::disposing()
61 m_vm_access.clear();
64 css::uno::Reference< css::uno::XInterface > SingletonFactory::createInstanceWithContext(
65 css::uno::Reference< css::uno::XComponentContext > const & xContext )
67 sal_Int64 handle = reinterpret_cast< sal_Int64 >( m_vm_access.get() );
68 css::uno::Any arg( css::beans::NamedValue( "UnoVirtualMachine", css::uno::Any( handle ) ) );
69 return xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
70 "com.sun.star.java.JavaVirtualMachine",
71 css::uno::Sequence< css::uno::Any >( &arg, 1 ), xContext );
74 css::uno::Reference< css::uno::XInterface > SingletonFactory::createInstanceWithArgumentsAndContext(
75 css::uno::Sequence< css::uno::Any > const & args, css::uno::Reference< css::uno::XComponentContext > const & xContext )
77 return xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
78 "com.sun.star.java.JavaVirtualMachine",
79 args, xContext );
84 namespace javaunohelper {
86 ::rtl::Reference< ::jvmaccess::UnoVirtualMachine > create_vm_access(
87 JNIEnv * jni_env, jobject loader )
89 JavaVM * vm;
90 jni_env->GetJavaVM( &vm );
91 try {
92 return new ::jvmaccess::UnoVirtualMachine(
93 new ::jvmaccess::VirtualMachine(
94 vm, JNI_VERSION_1_2, false, jni_env ),
95 loader );
96 } catch ( ::jvmaccess::UnoVirtualMachine::CreationException & ) {
97 throw css::uno::RuntimeException( "jvmaccess::UnoVirtualMachine::CreationException occurred" );
101 css::uno::Reference< css::uno::XComponentContext > install_vm_singleton(
102 css::uno::Reference< css::uno::XComponentContext > const & xContext,
103 ::rtl::Reference< ::jvmaccess::UnoVirtualMachine > const & vm_access )
105 css::uno::Reference< css::lang::XSingleComponentFactory > xFac( new SingletonFactory( vm_access ) );
106 ::cppu::ContextEntry_Init entry(
107 "/singletons/com.sun.star.java.theJavaVirtualMachine",
108 css::uno::Any( xFac ), true );
109 return ::cppu::createComponentContext( &entry, 1, xContext );
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */