xref: /AOO41X/main/comphelper/source/processfactory/componentfactory.cxx (revision dde7d3faf6dcd9cbeb7b48ba6d0cea5ffcc883d0)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_comphelper.hxx"
26 #include <comphelper/componentfactory.hxx>
27 #include <comphelper/processfactory.hxx>
28 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
29 
30 #ifndef _COM_SUN_STAR_REGISTRY_XREGISTRYKEY_HDL_
31 #include <com/sun/star/registry/XRegistryKey.hpp>
32 #endif
33 #include <cppuhelper/shlib.hxx>
34 
35 
36 #ifndef GCC
37 #endif
38 
39 
40 using namespace ::com::sun::star;
41 using namespace ::com::sun::star::uno;
42 using namespace ::com::sun::star::lang;
43 using namespace ::com::sun::star::registry;
44 using namespace ::rtl;
45 
46 
47 namespace comphelper
48 {
49 
getComponentInstance(const OUString & rLibraryName,const OUString & rImplementationName)50 Reference< XInterface > getComponentInstance(
51             const OUString & rLibraryName,
52             const OUString & rImplementationName
53             )
54 {
55     Reference< XInterface > xI;
56     Reference< XMultiServiceFactory > xMSF = ::comphelper::getProcessServiceFactory();
57     if ( xMSF.is() )
58         xI = xMSF->createInstance( rImplementationName );
59     if( !xI.is() )
60     {
61         Reference< XSingleServiceFactory > xSSF =
62             loadLibComponentFactory( rLibraryName, rImplementationName,
63             Reference< XMultiServiceFactory >(), Reference< XRegistryKey >() );
64         if (xSSF.is())
65             xI = xSSF->createInstance();
66     }
67     return xI;
68 }
69 
70 
loadLibComponentFactory(const OUString & rLibName,const OUString & rImplName,const Reference<XMultiServiceFactory> & xSF,const Reference<XRegistryKey> & xKey)71 Reference< XSingleServiceFactory > loadLibComponentFactory(
72             const OUString & rLibName,
73             const OUString & rImplName,
74             const Reference< XMultiServiceFactory > & xSF,
75             const Reference< XRegistryKey > & xKey
76             )
77 {
78     return Reference< XSingleServiceFactory >( ::cppu::loadSharedLibComponentFactory(
79         rLibName, OUString(), rImplName, xSF, xKey ), UNO_QUERY );
80 }
81 
82 }   // namespace comphelper
83