xref: /trunk/main/dbaccess/source/inc/registrationhelper.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef _REGISTRATIONHELPER_INCLUDED_INDIRECTLY_
29*cdf0e10cSrcweir #error "don't include this file directly! use dbu_reghelper.hxx instead!"
30*cdf0e10cSrcweir #endif
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir typedef ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > (SAL_CALL *FactoryInstantiation)
33*cdf0e10cSrcweir         (
34*cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rServiceManager,
35*cdf0e10cSrcweir             const ::rtl::OUString & _rComponentName,
36*cdf0e10cSrcweir             ::cppu::ComponentInstantiation _pCreateFunction,
37*cdf0e10cSrcweir             const ::com::sun::star::uno::Sequence< ::rtl::OUString > & _rServiceNames,
38*cdf0e10cSrcweir             rtl_ModuleCount* _p
39*cdf0e10cSrcweir         );
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir //==========================================================================
42*cdf0e10cSrcweir class OModuleRegistration
43*cdf0e10cSrcweir {
44*cdf0e10cSrcweir     static  ::com::sun::star::uno::Sequence< ::rtl::OUString >*
45*cdf0e10cSrcweir         s_pImplementationNames;
46*cdf0e10cSrcweir     static  ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::rtl::OUString > >*
47*cdf0e10cSrcweir         s_pSupportedServices;
48*cdf0e10cSrcweir     static  ::com::sun::star::uno::Sequence< sal_Int64 >*
49*cdf0e10cSrcweir         s_pCreationFunctionPointers;
50*cdf0e10cSrcweir     static  ::com::sun::star::uno::Sequence< sal_Int64 >*
51*cdf0e10cSrcweir         s_pFactoryFunctionPointers;
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir     // no direct instantiation, only static members/methods
54*cdf0e10cSrcweir     OModuleRegistration() { }
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir public:
57*cdf0e10cSrcweir     /** register a component implementing a service with the given data.
58*cdf0e10cSrcweir         @param      _rImplementationName        the implementation name of the component
59*cdf0e10cSrcweir         @param      _rServiceNames              the services the component supports
60*cdf0e10cSrcweir         @param      _pCreateFunction            a function for creating an instance of the component
61*cdf0e10cSrcweir         @param      _pFactoryFunction           a function for creating a factory for that component
62*cdf0e10cSrcweir         @see revokeComponent
63*cdf0e10cSrcweir     */
64*cdf0e10cSrcweir     static void registerComponent(
65*cdf0e10cSrcweir         const ::rtl::OUString& _rImplementationName,
66*cdf0e10cSrcweir         const ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rServiceNames,
67*cdf0e10cSrcweir         ::cppu::ComponentInstantiation _pCreateFunction,
68*cdf0e10cSrcweir         FactoryInstantiation _pFactoryFunction);
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir     /** revoke the registration for the specified component
71*cdf0e10cSrcweir         @param      _rImplementationName        the implementation name of the component
72*cdf0e10cSrcweir     */
73*cdf0e10cSrcweir     static void revokeComponent(
74*cdf0e10cSrcweir         const ::rtl::OUString& _rImplementationName);
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir     /** creates a Factory for the component with the given implementation name. Usually used from within component_getFactory.
77*cdf0e10cSrcweir         @param      _rxServiceManager       a pointer to an XMultiServiceFactory interface as got in component_getFactory
78*cdf0e10cSrcweir         @param      _pImplementationName    the implementation name of the component
79*cdf0e10cSrcweir         @return                             the XInterface access to a factory for the component
80*cdf0e10cSrcweir     */
81*cdf0e10cSrcweir     static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > getComponentFactory(
82*cdf0e10cSrcweir         const ::rtl::OUString& _rImplementationName,
83*cdf0e10cSrcweir         const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxServiceManager
84*cdf0e10cSrcweir         );
85*cdf0e10cSrcweir };
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir //==========================================================================
88*cdf0e10cSrcweir template <class TYPE>
89*cdf0e10cSrcweir class OMultiInstanceAutoRegistration
90*cdf0e10cSrcweir {
91*cdf0e10cSrcweir public:
92*cdf0e10cSrcweir     /** assumed that the template argument has the three methods<BR>
93*cdf0e10cSrcweir         <code>static ::rtl::OUString getImplementationName_Static()</code><BR>
94*cdf0e10cSrcweir         <code>static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static()</code><BR>
95*cdf0e10cSrcweir         and<BR>
96*cdf0e10cSrcweir         <code>static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
97*cdf0e10cSrcweir             Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&)</code><BR>
98*cdf0e10cSrcweir         the instantiation of this object will automatically register the class via <code>OModuleRegistration::registerComponent</code>.
99*cdf0e10cSrcweir         The factory creation function used is <code>::cppu::createSingleFactory</code>.<BR>
100*cdf0e10cSrcweir         @see OOneInstanceAutoRegistration
101*cdf0e10cSrcweir     */
102*cdf0e10cSrcweir     OMultiInstanceAutoRegistration();
103*cdf0e10cSrcweir     ~OMultiInstanceAutoRegistration();
104*cdf0e10cSrcweir };
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir template <class TYPE>
107*cdf0e10cSrcweir OMultiInstanceAutoRegistration<TYPE>::OMultiInstanceAutoRegistration()
108*cdf0e10cSrcweir {
109*cdf0e10cSrcweir     OModuleRegistration::registerComponent(
110*cdf0e10cSrcweir         TYPE::getImplementationName_Static(),
111*cdf0e10cSrcweir         TYPE::getSupportedServiceNames_Static(),
112*cdf0e10cSrcweir         TYPE::Create,
113*cdf0e10cSrcweir         ::cppu::createSingleFactory
114*cdf0e10cSrcweir         );
115*cdf0e10cSrcweir }
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir template <class TYPE>
118*cdf0e10cSrcweir OMultiInstanceAutoRegistration<TYPE>::~OMultiInstanceAutoRegistration()
119*cdf0e10cSrcweir {
120*cdf0e10cSrcweir     OModuleRegistration::revokeComponent(TYPE::getImplementationName_Static());
121*cdf0e10cSrcweir }
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir //==========================================================================
124*cdf0e10cSrcweir template <class TYPE>
125*cdf0e10cSrcweir class OOneInstanceAutoRegistration
126*cdf0e10cSrcweir {
127*cdf0e10cSrcweir public:
128*cdf0e10cSrcweir     /** provided that the template argument has three methods<BR>
129*cdf0e10cSrcweir         <code>static ::rtl::OUString getImplementationName_Static()</code><BR>
130*cdf0e10cSrcweir         <code>static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static()</code><BR>
131*cdf0e10cSrcweir         and<BR>
132*cdf0e10cSrcweir         <code>static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
133*cdf0e10cSrcweir             Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&)</code><BR>
134*cdf0e10cSrcweir         the instantiation of this object will automatically register the class via <code>OModuleRegistration::registerComponent</code>.
135*cdf0e10cSrcweir         The factory creation function used is <code>::cppu::createSingleFactory</code>.<BR>
136*cdf0e10cSrcweir         @see OMultiInstanceAutoRegistration
137*cdf0e10cSrcweir     */
138*cdf0e10cSrcweir     OOneInstanceAutoRegistration();
139*cdf0e10cSrcweir     ~OOneInstanceAutoRegistration();
140*cdf0e10cSrcweir };
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir template <class TYPE>
143*cdf0e10cSrcweir OOneInstanceAutoRegistration<TYPE>::OOneInstanceAutoRegistration()
144*cdf0e10cSrcweir {
145*cdf0e10cSrcweir     OModuleRegistration::registerComponent(
146*cdf0e10cSrcweir         TYPE::getImplementationName_Static(),
147*cdf0e10cSrcweir         TYPE::getSupportedServiceNames_Static(),
148*cdf0e10cSrcweir         TYPE::Create,
149*cdf0e10cSrcweir         ::cppu::createOneInstanceFactory
150*cdf0e10cSrcweir         );
151*cdf0e10cSrcweir }
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir template <class TYPE>
154*cdf0e10cSrcweir OOneInstanceAutoRegistration<TYPE>::~OOneInstanceAutoRegistration()
155*cdf0e10cSrcweir {
156*cdf0e10cSrcweir     OModuleRegistration::revokeComponent(TYPE::getImplementationName_Static());
157*cdf0e10cSrcweir }
158*cdf0e10cSrcweir 
159