merged tag ooo/OOO330_m14
[LibreOffice.git] / comphelper / source / processfactory / processfactory.cxx
blob514d3377edab4ebf0d449f1e7be8595283ae5e0b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_comphelper.hxx"
30 #include <osl/mutex.hxx>
31 #include <comphelper/processfactory.hxx>
32 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34 #include "com/sun/star/beans/XPropertySet.hpp"
37 using namespace ::com::sun::star;
38 using namespace com::sun::star::uno;
39 using namespace com::sun::star::lang;
40 using namespace osl;
42 namespace comphelper
46 This function preserves only that the xProcessFactory variable will not be create when
47 the library is loaded.
49 Reference< XMultiServiceFactory > localProcessFactory( const Reference< XMultiServiceFactory >& xSMgr, sal_Bool bSet )
51 Guard< Mutex > aGuard( Mutex::getGlobalMutex() );
53 static Reference< XMultiServiceFactory > xProcessFactory;
54 if ( bSet )
56 xProcessFactory = xSMgr;
59 return xProcessFactory;
63 void setProcessServiceFactory(const Reference< XMultiServiceFactory >& xSMgr)
65 localProcessFactory( xSMgr, sal_True );
68 Reference< XMultiServiceFactory > getProcessServiceFactory()
70 Reference< XMultiServiceFactory> xReturn;
71 xReturn = localProcessFactory( xReturn, sal_False );
72 return xReturn;
75 Reference< XInterface > createProcessComponent( const ::rtl::OUString& _rServiceSpecifier ) SAL_THROW( ( RuntimeException ) )
77 Reference< XInterface > xComponent;
79 Reference< XMultiServiceFactory > xFactory( getProcessServiceFactory() );
80 if ( xFactory.is() )
81 xComponent = xFactory->createInstance( _rServiceSpecifier );
83 return xComponent;
86 Reference< XInterface > createProcessComponentWithArguments( const ::rtl::OUString& _rServiceSpecifier,
87 const Sequence< Any >& _rArgs ) SAL_THROW( ( RuntimeException ) )
89 Reference< XInterface > xComponent;
91 Reference< XMultiServiceFactory > xFactory( getProcessServiceFactory() );
92 if ( xFactory.is() )
93 xComponent = xFactory->createInstanceWithArguments( _rServiceSpecifier, _rArgs );
95 return xComponent;
98 Reference< XComponentContext > getProcessComponentContext()
100 Reference< XComponentContext > xRet;
101 uno::Reference<beans::XPropertySet> const xProps(
102 comphelper::getProcessServiceFactory(), uno::UNO_QUERY );
103 if (xProps.is()) {
104 try {
105 xRet.set( xProps->getPropertyValue( rtl::OUString(
106 RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ),
107 uno::UNO_QUERY );
109 catch (beans::UnknownPropertyException const&) {
112 return xRet;
115 } // namespace comphelper
117 extern "C" {
118 uno::XComponentContext * comphelper_getProcessComponentContext()
120 uno::Reference<uno::XComponentContext> xRet;
121 xRet = ::comphelper::getProcessComponentContext();
122 if (xRet.is())
123 xRet->acquire();
124 return xRet.get();
126 } // extern "C"