1*dde7d3faSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*dde7d3faSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*dde7d3faSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*dde7d3faSAndrew Rist  * distributed with this work for additional information
6*dde7d3faSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*dde7d3faSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*dde7d3faSAndrew Rist  * "License"); you may not use this file except in compliance
9*dde7d3faSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*dde7d3faSAndrew Rist  *
11*dde7d3faSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*dde7d3faSAndrew Rist  *
13*dde7d3faSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*dde7d3faSAndrew Rist  * software distributed under the License is distributed on an
15*dde7d3faSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*dde7d3faSAndrew Rist  * KIND, either express or implied.  See the License for the
17*dde7d3faSAndrew Rist  * specific language governing permissions and limitations
18*dde7d3faSAndrew Rist  * under the License.
19*dde7d3faSAndrew Rist  *
20*dde7d3faSAndrew Rist  *************************************************************/
21*dde7d3faSAndrew Rist 
22*dde7d3faSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_comphelper.hxx"
26cdf0e10cSrcweir #include <osl/mutex.hxx>
27cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
28cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include "com/sun/star/beans/XPropertySet.hpp"
31cdf0e10cSrcweir 
32cdf0e10cSrcweir 
33cdf0e10cSrcweir using namespace ::com::sun::star;
34cdf0e10cSrcweir using namespace com::sun::star::uno;
35cdf0e10cSrcweir using namespace com::sun::star::lang;
36cdf0e10cSrcweir using namespace osl;
37cdf0e10cSrcweir 
38cdf0e10cSrcweir namespace comphelper
39cdf0e10cSrcweir {
40cdf0e10cSrcweir 
41cdf0e10cSrcweir /*
42cdf0e10cSrcweir 	This function preserves only that the xProcessFactory variable will not be create when
43cdf0e10cSrcweir 	the library is loaded.
44cdf0e10cSrcweir */
localProcessFactory(const Reference<XMultiServiceFactory> & xSMgr,sal_Bool bSet)45cdf0e10cSrcweir Reference< XMultiServiceFactory > localProcessFactory( const Reference< XMultiServiceFactory >& xSMgr, sal_Bool bSet )
46cdf0e10cSrcweir {
47cdf0e10cSrcweir 	Guard< Mutex > aGuard( Mutex::getGlobalMutex() );
48cdf0e10cSrcweir 
49cdf0e10cSrcweir 	static Reference< XMultiServiceFactory > xProcessFactory;
50cdf0e10cSrcweir 	if ( bSet )
51cdf0e10cSrcweir 	{
52cdf0e10cSrcweir 		xProcessFactory = xSMgr;
53cdf0e10cSrcweir 	}
54cdf0e10cSrcweir 
55cdf0e10cSrcweir 	return xProcessFactory;
56cdf0e10cSrcweir }
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 
setProcessServiceFactory(const Reference<XMultiServiceFactory> & xSMgr)59cdf0e10cSrcweir void setProcessServiceFactory(const Reference< XMultiServiceFactory >& xSMgr)
60cdf0e10cSrcweir {
61cdf0e10cSrcweir 	localProcessFactory( xSMgr, sal_True );
62cdf0e10cSrcweir }
63cdf0e10cSrcweir 
getProcessServiceFactory()64cdf0e10cSrcweir Reference< XMultiServiceFactory > getProcessServiceFactory()
65cdf0e10cSrcweir {
66cdf0e10cSrcweir 	Reference< XMultiServiceFactory> xReturn;
67cdf0e10cSrcweir 	xReturn = localProcessFactory( xReturn, sal_False );
68cdf0e10cSrcweir 	return xReturn;
69cdf0e10cSrcweir }
70cdf0e10cSrcweir 
createProcessComponent(const::rtl::OUString & _rServiceSpecifier)71cdf0e10cSrcweir Reference< XInterface > createProcessComponent( const ::rtl::OUString& _rServiceSpecifier ) SAL_THROW( ( RuntimeException ) )
72cdf0e10cSrcweir {
73cdf0e10cSrcweir 	Reference< XInterface > xComponent;
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 	Reference< XMultiServiceFactory > xFactory( getProcessServiceFactory() );
76cdf0e10cSrcweir 	if ( xFactory.is() )
77cdf0e10cSrcweir 		xComponent = xFactory->createInstance( _rServiceSpecifier );
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 	return xComponent;
80cdf0e10cSrcweir }
81cdf0e10cSrcweir 
createProcessComponentWithArguments(const::rtl::OUString & _rServiceSpecifier,const Sequence<Any> & _rArgs)82cdf0e10cSrcweir Reference< XInterface > createProcessComponentWithArguments( const ::rtl::OUString& _rServiceSpecifier,
83cdf0e10cSrcweir 		const Sequence< Any >& _rArgs ) SAL_THROW( ( RuntimeException ) )
84cdf0e10cSrcweir {
85cdf0e10cSrcweir 	Reference< XInterface > xComponent;
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 	Reference< XMultiServiceFactory > xFactory( getProcessServiceFactory() );
88cdf0e10cSrcweir 	if ( xFactory.is() )
89cdf0e10cSrcweir 		xComponent = xFactory->createInstanceWithArguments( _rServiceSpecifier, _rArgs );
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 	return xComponent;
92cdf0e10cSrcweir }
93cdf0e10cSrcweir 
getProcessComponentContext()94cdf0e10cSrcweir Reference< XComponentContext > getProcessComponentContext()
95cdf0e10cSrcweir {
96cdf0e10cSrcweir     Reference< XComponentContext > xRet;
97cdf0e10cSrcweir     uno::Reference<beans::XPropertySet> const xProps(
98cdf0e10cSrcweir         comphelper::getProcessServiceFactory(), uno::UNO_QUERY );
99cdf0e10cSrcweir     if (xProps.is()) {
100cdf0e10cSrcweir         try {
101cdf0e10cSrcweir             xRet.set( xProps->getPropertyValue( rtl::OUString(
102cdf0e10cSrcweir                               RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ),
103cdf0e10cSrcweir                       uno::UNO_QUERY );
104cdf0e10cSrcweir         }
105cdf0e10cSrcweir         catch (beans::UnknownPropertyException const&) {
106cdf0e10cSrcweir         }
107cdf0e10cSrcweir     }
108cdf0e10cSrcweir     return xRet;
109cdf0e10cSrcweir }
110cdf0e10cSrcweir 
111cdf0e10cSrcweir } // namespace comphelper
112cdf0e10cSrcweir 
113cdf0e10cSrcweir extern "C" {
comphelper_getProcessComponentContext()114cdf0e10cSrcweir uno::XComponentContext * comphelper_getProcessComponentContext()
115cdf0e10cSrcweir {
116cdf0e10cSrcweir     uno::Reference<uno::XComponentContext> xRet;
117cdf0e10cSrcweir     xRet = ::comphelper::getProcessComponentContext();
118cdf0e10cSrcweir     if (xRet.is())
119cdf0e10cSrcweir         xRet->acquire();
120cdf0e10cSrcweir     return xRet.get();
121cdf0e10cSrcweir }
122cdf0e10cSrcweir } // extern "C"
123cdf0e10cSrcweir 
124