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
, sal_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
, sal_True
);
58 Reference
< XMultiServiceFactory
> getProcessServiceFactory()
60 Reference
< XMultiServiceFactory
> xReturn
;
61 xReturn
= localProcessFactory( xReturn
, sal_False
);
64 throw DeploymentException(
65 "null process service factory", Reference
< XInterface
>() );
70 Reference
< XComponentContext
> getComponentContext(
71 Reference
< XMultiServiceFactory
> const & factory
)
73 Reference
< XComponentContext
> xRet
;
74 uno::Reference
<beans::XPropertySet
> const xProps( factory
, uno::UNO_QUERY
);
77 xRet
.set( xProps
->getPropertyValue( OUString("DefaultContext") ),
80 catch (beans::UnknownPropertyException
& e
) {
81 throw DeploymentException(
82 "unknown service factory DefaultContext property: " + e
.Message
,
83 Reference
< XInterface
>( factory
, UNO_QUERY
) );
88 throw DeploymentException(
89 "no service factory DefaultContext",
90 Reference
< XInterface
>( factory
, UNO_QUERY
) );
95 Reference
< XComponentContext
> getProcessComponentContext()
97 return getComponentContext( getProcessServiceFactory() );
100 } // namespace comphelper
103 uno::XComponentContext
* comphelper_getProcessComponentContext()
105 uno::Reference
<uno::XComponentContext
> xRet
;
106 xRet
= ::comphelper::getProcessComponentContext();
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */