bump product version to 6.4.0.3
[LibreOffice.git] / comphelper / source / processfactory / processfactory.cxx
blob515c4b6a7476f088da8f006a7a5af4bee1f430e3
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 .
20 #include <osl/mutex.hxx>
21 #include <comphelper/processfactory.hxx>
23 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include <com/sun/star/uno/DeploymentException.hpp>
25 #include <com/sun/star/uno/XComponentContext.hpp>
27 namespace com::sun::star::lang { class XMultiServiceFactory; }
28 namespace com::sun::star::uno { class XComponentContext; }
30 using namespace ::com::sun::star;
31 using namespace com::sun::star::uno;
32 using namespace com::sun::star::lang;
33 using namespace osl;
35 namespace comphelper
38 namespace {
40 class LocalProcessFactory {
41 public:
42 void set( const Reference< XMultiServiceFactory >& xSMgr )
44 Guard< Mutex > aGuard( Mutex::getGlobalMutex() );
46 xProcessFactory = xSMgr;
49 Reference< XMultiServiceFactory > get() const
51 Guard< Mutex > aGuard( Mutex::getGlobalMutex() );
53 return xProcessFactory;
56 private:
57 Reference< XMultiServiceFactory > xProcessFactory;
61 This var preserves only that the above xProcessFactory variable will not be create when
62 the library is loaded.
64 LocalProcessFactory localProcessFactory;
68 void setProcessServiceFactory(const Reference< XMultiServiceFactory >& xSMgr)
70 localProcessFactory.set( xSMgr );
73 Reference< XMultiServiceFactory > getProcessServiceFactory()
75 Reference< XMultiServiceFactory> xReturn = localProcessFactory.get();
76 if ( !xReturn.is() )
78 throw DeploymentException( "null process service factory" );
80 return xReturn;
83 Reference< XComponentContext > getComponentContext(
84 Reference< XMultiServiceFactory > const & factory)
86 Reference< XComponentContext > xRet;
87 uno::Reference<beans::XPropertySet> const xProps( factory, uno::UNO_QUERY );
88 if (xProps.is()) {
89 try {
90 xRet.set( xProps->getPropertyValue("DefaultContext"),
91 uno::UNO_QUERY );
93 catch (beans::UnknownPropertyException & e) {
94 throw DeploymentException(
95 "unknown service factory DefaultContext property: " + e.Message,
96 Reference<XInterface>(factory, UNO_QUERY) );
99 if ( !xRet.is() )
101 throw DeploymentException(
102 "no service factory DefaultContext",
103 Reference<XInterface>(factory, UNO_QUERY) );
105 return xRet;
108 Reference< XComponentContext > getProcessComponentContext()
110 return getComponentContext( getProcessServiceFactory() );
113 } // namespace comphelper
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */