xref: /trunk/main/unoxml/source/service/services.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 #include <osl/mutex.hxx>
29 #include <rtl/ustring.hxx>
30 #include <com/sun/star/uno/Reference.h>
31 #include <com/sun/star/uno/Reference.hxx>
32 #include <cppuhelper/interfacecontainer.h>
33 #include <cppuhelper/factory.hxx>
34 #include <com/sun/star/lang/XServiceInfo.hpp>
35 #include <com/sun/star/uno/Exception.hpp>
36 #include <com/sun/star/lang/XComponent.hpp>
37 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
38 #include <com/sun/star/registry/XRegistryKey.hpp>
39 #include <cppuhelper/factory.hxx>
40 
41 #include "../dom/documentbuilder.hxx"
42 #include "../dom/saxbuilder.hxx"
43 #include "../xpath/xpathapi.hxx"
44 #include "../events/testlistener.hxx"
45 
46 using namespace ::DOM;
47 using namespace ::DOM::events;
48 using namespace ::XPath;
49 using ::rtl::OUString;
50 using namespace ::com::sun::star::uno;
51 using namespace ::com::sun::star::lang;
52 using namespace ::com::sun::star::registry;
53 
54 extern "C"
55 {
56 
57 SAL_DLLPUBLIC_EXPORT void SAL_CALL
58 component_getImplementationEnvironment(const sal_Char **ppEnvironmentTypeName, uno_Environment ** /*ppEnvironment */)
59 {
60     *ppEnvironmentTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME ;
61 }
62 
63 SAL_DLLPUBLIC_EXPORT void* SAL_CALL
64 component_getFactory(const sal_Char *pImplementationName, void *pServiceManager, void * /*pRegistryKey*/)
65 {
66     void* pReturn = NULL ;
67     if  ( pImplementationName && pServiceManager )
68     {
69         // Define variables which are used in following macros.
70         Reference< XSingleServiceFactory > xFactory;
71         Reference< XMultiServiceFactory >  xServiceManager(
72             reinterpret_cast< XMultiServiceFactory* >(pServiceManager));
73 
74         if (CDocumentBuilder::_getImplementationName().compareToAscii( pImplementationName ) == 0 )
75         {
76             xFactory = Reference< XSingleServiceFactory >(
77                 cppu::createOneInstanceFactory(
78                     xServiceManager, CDocumentBuilder::_getImplementationName(),
79                     CDocumentBuilder::_getInstance, CDocumentBuilder::_getSupportedServiceNames()));
80         }
81         else if (CSAXDocumentBuilder::_getImplementationName().compareToAscii( pImplementationName ) == 0 )
82         {
83             xFactory = Reference< XSingleServiceFactory >(
84                 cppu::createSingleFactory(
85                     xServiceManager, CSAXDocumentBuilder::_getImplementationName(),
86                     CSAXDocumentBuilder::_getInstance, CSAXDocumentBuilder::_getSupportedServiceNames()));
87         }
88         else if (CXPathAPI::_getImplementationName().compareToAscii( pImplementationName ) == 0 )
89         {
90             xFactory = Reference< XSingleServiceFactory >(
91                 cppu::createSingleFactory(
92                     xServiceManager, CXPathAPI::_getImplementationName(),
93                     CXPathAPI::_getInstance, CXPathAPI::_getSupportedServiceNames()));
94         }
95         else if (CTestListener::_getImplementationName().compareToAscii( pImplementationName ) == 0 )
96         {
97             xFactory = Reference< XSingleServiceFactory >(
98                 cppu::createSingleFactory(
99                     xServiceManager, CTestListener::_getImplementationName(),
100                     CTestListener::_getInstance, CTestListener::_getSupportedServiceNames()));
101         }
102 
103         // Factory is valid - service was found.
104         if ( xFactory.is() )
105         {
106             xFactory->acquire();
107             pReturn = xFactory.get();
108         }
109     }
110 
111     // Return with result of this operation.
112     return pReturn ;
113 }
114 
115 } // extern "C"
116