2010-10-14 01:30:07 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2005-07-07 04:58:34 -05:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-11 04:58:19 -05:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2005-07-07 04:58:34 -05:00
|
|
|
*
|
2010-02-12 08:01:35 -06:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2005-07-07 04:58:34 -05:00
|
|
|
*
|
2008-04-11 04:58:19 -05:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2005-07-07 04:58:34 -05:00
|
|
|
*
|
2008-04-11 04:58:19 -05:00
|
|
|
* This file is part of OpenOffice.org.
|
2005-07-07 04:58:34 -05:00
|
|
|
*
|
2008-04-11 04:58:19 -05:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2005-07-07 04:58:34 -05:00
|
|
|
*
|
2008-04-11 04:58:19 -05:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2005-07-07 04:58:34 -05:00
|
|
|
*
|
2008-04-11 04:58:19 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2005-07-07 04:58:34 -05:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-17 10:07:05 -05:00
|
|
|
|
2005-07-07 04:58:34 -05:00
|
|
|
#include "sal/config.h"
|
|
|
|
|
|
|
|
#include "vm.hxx"
|
|
|
|
|
2006-01-03 05:42:46 -06:00
|
|
|
#include "com/sun/star/beans/NamedValue.hpp"
|
2005-07-07 04:58:34 -05:00
|
|
|
#include "com/sun/star/lang/XSingleComponentFactory.hpp"
|
|
|
|
#include "cppuhelper/compbase1.hxx"
|
|
|
|
#include "cppuhelper/component_context.hxx"
|
|
|
|
#include "jvmaccess/virtualmachine.hxx"
|
|
|
|
#include "jvmaccess/unovirtualmachine.hxx"
|
|
|
|
#include "osl/mutex.hxx"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
namespace css = ::com::sun::star;
|
|
|
|
|
|
|
|
struct MutexHolder
|
|
|
|
{
|
|
|
|
::osl::Mutex m_mutex;
|
|
|
|
};
|
|
|
|
typedef ::cppu::WeakComponentImplHelper1<
|
|
|
|
css::lang::XSingleComponentFactory > t_impl;
|
|
|
|
|
|
|
|
class SingletonFactory : public MutexHolder, public t_impl
|
|
|
|
{
|
2006-01-03 05:42:46 -06:00
|
|
|
::rtl::Reference< ::jvmaccess::UnoVirtualMachine > m_vm_access;
|
2005-07-07 04:58:34 -05:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void SAL_CALL disposing();
|
|
|
|
|
|
|
|
public:
|
2006-01-03 05:42:46 -06:00
|
|
|
inline SingletonFactory( ::rtl::Reference< ::jvmaccess::UnoVirtualMachine > const & vm_access )
|
2005-07-07 04:58:34 -05:00
|
|
|
: t_impl( m_mutex ),
|
|
|
|
m_vm_access( vm_access )
|
|
|
|
{}
|
|
|
|
|
|
|
|
// XSingleComponentFactory impl
|
|
|
|
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithContext(
|
|
|
|
css::uno::Reference< css::uno::XComponentContext > const & xContext )
|
|
|
|
throw (css::uno::Exception);
|
|
|
|
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithArgumentsAndContext(
|
|
|
|
css::uno::Sequence< css::uno::Any > const & args, css::uno::Reference< css::uno::XComponentContext > const & xContext )
|
|
|
|
throw (css::uno::Exception);
|
|
|
|
};
|
|
|
|
|
|
|
|
void SingletonFactory::disposing()
|
|
|
|
{
|
|
|
|
m_vm_access.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
css::uno::Reference< css::uno::XInterface > SingletonFactory::createInstanceWithContext(
|
|
|
|
css::uno::Reference< css::uno::XComponentContext > const & xContext )
|
|
|
|
throw (css::uno::Exception)
|
|
|
|
{
|
|
|
|
sal_Int64 handle = reinterpret_cast< sal_Int64 >( m_vm_access.get() );
|
2006-01-03 05:42:46 -06:00
|
|
|
css::uno::Any arg(
|
|
|
|
css::uno::makeAny(
|
|
|
|
css::beans::NamedValue(
|
|
|
|
rtl::OUString(
|
|
|
|
RTL_CONSTASCII_USTRINGPARAM( "UnoVirtualMachine" ) ),
|
|
|
|
css::uno::makeAny( handle ) ) ) );
|
2005-07-07 04:58:34 -05:00
|
|
|
return xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
|
|
|
|
::rtl::OUString(
|
|
|
|
RTL_CONSTASCII_USTRINGPARAM(
|
|
|
|
"com.sun.star.java.JavaVirtualMachine")),
|
|
|
|
css::uno::Sequence< css::uno::Any >( &arg, 1 ), xContext );
|
|
|
|
}
|
|
|
|
|
|
|
|
css::uno::Reference< css::uno::XInterface > SingletonFactory::createInstanceWithArgumentsAndContext(
|
|
|
|
css::uno::Sequence< css::uno::Any > const & args, css::uno::Reference< css::uno::XComponentContext > const & xContext )
|
|
|
|
throw (css::uno::Exception)
|
|
|
|
{
|
|
|
|
return xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
|
|
|
|
::rtl::OUString(
|
|
|
|
RTL_CONSTASCII_USTRINGPARAM(
|
|
|
|
"com.sun.star.java.JavaVirtualMachine")),
|
|
|
|
args, xContext );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace javaunohelper {
|
|
|
|
|
|
|
|
::rtl::Reference< ::jvmaccess::UnoVirtualMachine > create_vm_access(
|
|
|
|
JNIEnv * jni_env, jobject loader )
|
|
|
|
{
|
|
|
|
JavaVM * vm;
|
|
|
|
jni_env->GetJavaVM( &vm );
|
|
|
|
try {
|
|
|
|
return new ::jvmaccess::UnoVirtualMachine(
|
|
|
|
new ::jvmaccess::VirtualMachine(
|
|
|
|
vm, JNI_VERSION_1_2, false, jni_env ),
|
|
|
|
loader );
|
|
|
|
} catch ( ::jvmaccess::UnoVirtualMachine::CreationException & ) {
|
|
|
|
throw css::uno::RuntimeException(
|
|
|
|
::rtl::OUString(
|
|
|
|
RTL_CONSTASCII_USTRINGPARAM(
|
|
|
|
"jmvaccess::UnoVirtualMachine::CreationException"
|
|
|
|
" occurred" ) ),
|
|
|
|
css::uno::Reference< css::uno::XInterface >() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
css::uno::Reference< css::uno::XComponentContext > install_vm_singleton(
|
|
|
|
css::uno::Reference< ::css::uno::XComponentContext > const & xContext,
|
2006-01-03 05:42:46 -06:00
|
|
|
::rtl::Reference< ::jvmaccess::UnoVirtualMachine > const & vm_access )
|
2005-07-07 04:58:34 -05:00
|
|
|
{
|
|
|
|
css::uno::Reference< css::lang::XSingleComponentFactory > xFac( new SingletonFactory( vm_access ) );
|
|
|
|
::cppu::ContextEntry_Init entry(
|
|
|
|
::rtl::OUString(
|
|
|
|
RTL_CONSTASCII_USTRINGPARAM(
|
|
|
|
"/singletons/com.sun.star.java.theJavaVirtualMachine")),
|
|
|
|
css::uno::makeAny( xFac ), true );
|
|
|
|
return ::cppu::createComponentContext( &entry, 1, xContext );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2010-10-14 01:30:07 -05:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|