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