update dev300-m58
[ooovba.git] / dbaccess / source / inc / registrationhelper.hxx
blob6c710d27f52e12bf138e5045daecd57703f2647f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: registrationhelper.hxx,v $
10 * $Revision: 1.7 $
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 #ifndef _REGISTRATIONHELPER_INCLUDED_INDIRECTLY_
32 #error "don't include this file directly! use dbu_reghelper.hxx instead!"
33 #endif
35 typedef ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > (SAL_CALL *FactoryInstantiation)
37 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rServiceManager,
38 const ::rtl::OUString & _rComponentName,
39 ::cppu::ComponentInstantiation _pCreateFunction,
40 const ::com::sun::star::uno::Sequence< ::rtl::OUString > & _rServiceNames,
41 rtl_ModuleCount* _p
44 //==========================================================================
45 class OModuleRegistration
47 static ::com::sun::star::uno::Sequence< ::rtl::OUString >*
48 s_pImplementationNames;
49 static ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::rtl::OUString > >*
50 s_pSupportedServices;
51 static ::com::sun::star::uno::Sequence< sal_Int64 >*
52 s_pCreationFunctionPointers;
53 static ::com::sun::star::uno::Sequence< sal_Int64 >*
54 s_pFactoryFunctionPointers;
56 // no direct instantiation, only static members/methods
57 OModuleRegistration() { }
59 public:
60 /** register a component implementing a service with the given data.
61 @param _rImplementationName the implementation name of the component
62 @param _rServiceNames the services the component supports
63 @param _pCreateFunction a function for creating an instance of the component
64 @param _pFactoryFunction a function for creating a factory for that component
65 @see revokeComponent
67 static void registerComponent(
68 const ::rtl::OUString& _rImplementationName,
69 const ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rServiceNames,
70 ::cppu::ComponentInstantiation _pCreateFunction,
71 FactoryInstantiation _pFactoryFunction);
73 /** revoke the registration for the specified component
74 @param _rImplementationName the implementation name of the component
76 static void revokeComponent(
77 const ::rtl::OUString& _rImplementationName);
79 /** writes the registration information of all components which are currently registered into the specified registry.
80 Usually used from within component_writeInfo.
81 @param _rxServiceManager the service manager
82 @param _rRootKey the registry key under which the information will be stored
83 @return sal_True if the registration of all implementations was successfull, sal_False otherwise
85 static sal_Bool writeComponentInfos(
86 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxServiceManager,
87 const ::com::sun::star::uno::Reference< ::com::sun::star::registry::XRegistryKey >& _rRootKey);
89 /** creates a Factory for the component with the given implementation name. Usually used from within component_getFactory.
90 @param _rxServiceManager a pointer to an XMultiServiceFactory interface as got in component_getFactory
91 @param _pImplementationName the implementation name of the component
92 @return the XInterface access to a factory for the component
94 static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > getComponentFactory(
95 const ::rtl::OUString& _rImplementationName,
96 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxServiceManager
100 //==========================================================================
101 template <class TYPE>
102 class OMultiInstanceAutoRegistration
104 public:
105 /** assumed that the template argument has the three methods<BR>
106 <code>static ::rtl::OUString getImplementationName_Static()</code><BR>
107 <code>static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static()</code><BR>
108 and<BR>
109 <code>static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
110 Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&)</code><BR>
111 the instantiation of this object will automatically register the class via <code>OModuleRegistration::registerComponent</code>.
112 The factory creation function used is <code>::cppu::createSingleFactory</code>.<BR>
113 @see OOneInstanceAutoRegistration
115 OMultiInstanceAutoRegistration();
116 ~OMultiInstanceAutoRegistration();
119 template <class TYPE>
120 OMultiInstanceAutoRegistration<TYPE>::OMultiInstanceAutoRegistration()
122 OModuleRegistration::registerComponent(
123 TYPE::getImplementationName_Static(),
124 TYPE::getSupportedServiceNames_Static(),
125 TYPE::Create,
126 ::cppu::createSingleFactory
130 template <class TYPE>
131 OMultiInstanceAutoRegistration<TYPE>::~OMultiInstanceAutoRegistration()
133 OModuleRegistration::revokeComponent(TYPE::getImplementationName_Static());
136 //==========================================================================
137 template <class TYPE>
138 class OOneInstanceAutoRegistration
140 public:
141 /** provided that the template argument has three methods<BR>
142 <code>static ::rtl::OUString getImplementationName_Static()</code><BR>
143 <code>static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static()</code><BR>
144 and<BR>
145 <code>static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
146 Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&)</code><BR>
147 the instantiation of this object will automatically register the class via <code>OModuleRegistration::registerComponent</code>.
148 The factory creation function used is <code>::cppu::createSingleFactory</code>.<BR>
149 @see OMultiInstanceAutoRegistration
151 OOneInstanceAutoRegistration();
152 ~OOneInstanceAutoRegistration();
155 template <class TYPE>
156 OOneInstanceAutoRegistration<TYPE>::OOneInstanceAutoRegistration()
158 OModuleRegistration::registerComponent(
159 TYPE::getImplementationName_Static(),
160 TYPE::getSupportedServiceNames_Static(),
161 TYPE::Create,
162 ::cppu::createOneInstanceFactory
166 template <class TYPE>
167 OOneInstanceAutoRegistration<TYPE>::~OOneInstanceAutoRegistration()
169 OModuleRegistration::revokeComponent(TYPE::getImplementationName_Static());