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 #include <osl/mutex.hxx>
21 #include <comphelper/processfactory.hxx>
22 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
24 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <com/sun/star/uno/DeploymentException.hpp>
27 using namespace ::com::sun::star
;
28 using namespace com::sun::star::uno
;
29 using namespace com::sun::star::lang
;
36 This function preserves only that the xProcessFactory variable will not be create when
37 the library is loaded.
39 Reference
< XMultiServiceFactory
> localProcessFactory( const Reference
< XMultiServiceFactory
>& xSMgr
, bool bSet
)
41 Guard
< Mutex
> aGuard( Mutex::getGlobalMutex() );
43 static Reference
< XMultiServiceFactory
> xProcessFactory
;
46 xProcessFactory
= xSMgr
;
49 return xProcessFactory
;
53 void setProcessServiceFactory(const Reference
< XMultiServiceFactory
>& xSMgr
)
55 localProcessFactory( xSMgr
, true );
58 Reference
< XMultiServiceFactory
> getProcessServiceFactory()
60 Reference
< XMultiServiceFactory
> xReturn
;
61 xReturn
= localProcessFactory( xReturn
, false );
64 throw DeploymentException( "null process service factory" );
69 Reference
< XComponentContext
> getComponentContext(
70 Reference
< XMultiServiceFactory
> const & factory
)
72 Reference
< XComponentContext
> xRet
;
73 uno::Reference
<beans::XPropertySet
> const xProps( factory
, uno::UNO_QUERY
);
76 xRet
.set( xProps
->getPropertyValue("DefaultContext"),
79 catch (beans::UnknownPropertyException
& e
) {
80 throw DeploymentException(
81 "unknown service factory DefaultContext property: " + e
.Message
,
82 Reference
<XInterface
>(factory
, UNO_QUERY
) );
87 throw DeploymentException(
88 "no service factory DefaultContext",
89 Reference
<XInterface
>(factory
, UNO_QUERY
) );
94 Reference
< XComponentContext
> getProcessComponentContext()
96 return getComponentContext( getProcessServiceFactory() );
99 } // namespace comphelper
101 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */