1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: services.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <osl/mutex.hxx>
32 #include <rtl/ustring.hxx>
33 #include <com/sun/star/uno/Reference.h>
34 #include <com/sun/star/uno/Reference.hxx>
35 #include <cppuhelper/interfacecontainer.h>
36 #include <cppuhelper/factory.hxx>
37 #include <com/sun/star/lang/XServiceInfo.hpp>
38 #include <com/sun/star/uno/Exception.hpp>
39 #include <com/sun/star/lang/XComponent.hpp>
40 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
41 #include <com/sun/star/registry/XRegistryKey.hpp>
42 #include <cppuhelper/factory.hxx>
44 #include "../dom/documentbuilder.hxx"
45 #include "../dom/saxbuilder.hxx"
46 #include "../xpath/xpathapi.hxx"
47 #include "../events/testlistener.hxx"
49 using namespace ::DOM
;
50 using namespace ::DOM::events
;
51 using namespace ::XPath
;
52 using ::rtl::OUString
;
53 using namespace ::com::sun::star::uno
;
54 using namespace ::com::sun::star::lang
;
55 using namespace ::com::sun::star::registry
;
61 component_getImplementationEnvironment(const sal_Char
**ppEnvironmentTypeName
, uno_Environment
** /*ppEnvironment */)
63 *ppEnvironmentTypeName
= CPPU_CURRENT_LANGUAGE_BINDING_NAME
;
67 component_writeInfo(void * /*pServiceManager*/, void* pRegistryKey
)
69 Reference
< XRegistryKey
> xKey(reinterpret_cast< XRegistryKey
* >(pRegistryKey
));
70 Reference
< XRegistryKey
> xNewKey
;
73 // register DOM service
74 aImpl
= OUString(RTL_CONSTASCII_USTRINGPARAM("/"));
75 aImpl
+= CDocumentBuilder::_getImplementationName();
76 aImpl
+= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES"));
77 xNewKey
= xKey
->createKey(aImpl
);
78 xNewKey
->createKey(CDocumentBuilder::_getSupportedServiceNames()[0]);
80 // register DOM service
81 aImpl
= OUString(RTL_CONSTASCII_USTRINGPARAM("/"));
82 aImpl
+= CSAXDocumentBuilder::_getImplementationName();
83 aImpl
+= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES"));
84 xNewKey
= xKey
->createKey(aImpl
);
85 xNewKey
->createKey(CSAXDocumentBuilder::_getSupportedServiceNames()[0]);
87 // register XPath service
88 aImpl
= OUString(RTL_CONSTASCII_USTRINGPARAM("/"));
89 aImpl
+= CXPathAPI::_getImplementationName();
90 aImpl
+= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES"));
91 xNewKey
= xKey
->createKey(aImpl
);
92 xNewKey
->createKey(CXPathAPI::_getSupportedServiceNames()[0]);
94 // register EventTest service
95 aImpl
= OUString(RTL_CONSTASCII_USTRINGPARAM("/"));
96 aImpl
+= CTestListener::_getImplementationName();
97 aImpl
+= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES"));
98 xNewKey
= xKey
->createKey(aImpl
);
99 xNewKey
->createKey(CTestListener::_getSupportedServiceNames()[0]);
105 component_getFactory(const sal_Char
*pImplementationName
, void *pServiceManager
, void * /*pRegistryKey*/)
107 void* pReturn
= NULL
;
108 if ( pImplementationName
&& pServiceManager
)
110 // Define variables which are used in following macros.
111 Reference
< XSingleServiceFactory
> xFactory
;
112 Reference
< XMultiServiceFactory
> xServiceManager(
113 reinterpret_cast< XMultiServiceFactory
* >(pServiceManager
));
115 if (CDocumentBuilder::_getImplementationName().compareToAscii( pImplementationName
) == 0 )
117 xFactory
= Reference
< XSingleServiceFactory
>(
118 cppu::createOneInstanceFactory(
119 xServiceManager
, CDocumentBuilder::_getImplementationName(),
120 CDocumentBuilder::_getInstance
, CDocumentBuilder::_getSupportedServiceNames()));
122 else if (CSAXDocumentBuilder::_getImplementationName().compareToAscii( pImplementationName
) == 0 )
124 xFactory
= Reference
< XSingleServiceFactory
>(
125 cppu::createSingleFactory(
126 xServiceManager
, CSAXDocumentBuilder::_getImplementationName(),
127 CSAXDocumentBuilder::_getInstance
, CSAXDocumentBuilder::_getSupportedServiceNames()));
129 else if (CXPathAPI::_getImplementationName().compareToAscii( pImplementationName
) == 0 )
131 xFactory
= Reference
< XSingleServiceFactory
>(
132 cppu::createSingleFactory(
133 xServiceManager
, CXPathAPI::_getImplementationName(),
134 CXPathAPI::_getInstance
, CXPathAPI::_getSupportedServiceNames()));
136 else if (CTestListener::_getImplementationName().compareToAscii( pImplementationName
) == 0 )
138 xFactory
= Reference
< XSingleServiceFactory
>(
139 cppu::createSingleFactory(
140 xServiceManager
, CTestListener::_getImplementationName(),
141 CTestListener::_getInstance
, CTestListener::_getSupportedServiceNames()));
144 // Factory is valid - service was found.
148 pReturn
= xFactory
.get();
152 // Return with result of this operation.