xref: /AOO41X/main/stoc/source/registry_tdprovider/tdprovider.cxx (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 // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_stoc.hxx"
30*cdf0e10cSrcweir #include <osl/diagnose.h>
31*cdf0e10cSrcweir #include <osl/mutex.hxx>
32*cdf0e10cSrcweir #include <uno/dispatcher.h>
33*cdf0e10cSrcweir #include <uno/mapping.hxx>
34*cdf0e10cSrcweir #include <cppuhelper/factory.hxx>
35*cdf0e10cSrcweir #include <cppuhelper/compbase4.hxx>
36*cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx>
37*cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #include <cppuhelper/weakref.hxx>
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/lang/XTypeProvider.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/registry/XSimpleRegistry.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/registry/XRegistryKey.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/reflection/XTypeDescriptionEnumerationAccess.hpp>
49*cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir #include "registry/reader.hxx"
52*cdf0e10cSrcweir #include "registry/version.h"
53*cdf0e10cSrcweir #include "base.hxx"
54*cdf0e10cSrcweir #include "rdbtdp_tdenumeration.hxx"
55*cdf0e10cSrcweir #include "structtypedescription.hxx"
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir #define SERVICENAME "com.sun.star.reflection.TypeDescriptionProvider"
58*cdf0e10cSrcweir #define IMPLNAME	"com.sun.star.comp.stoc.RegistryTypeDescriptionProvider"
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir using namespace com::sun::star;
61*cdf0e10cSrcweir using namespace com::sun::star::beans;
62*cdf0e10cSrcweir using namespace com::sun::star::registry;
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir extern rtl_StandardModuleCount g_moduleCount;
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir namespace stoc_bootstrap
67*cdf0e10cSrcweir {
68*cdf0e10cSrcweir uno::Sequence< OUString > rdbtdp_getSupportedServiceNames()
69*cdf0e10cSrcweir {
70*cdf0e10cSrcweir 	static Sequence < OUString > *pNames = 0;
71*cdf0e10cSrcweir 	if( ! pNames )
72*cdf0e10cSrcweir 	{
73*cdf0e10cSrcweir 		MutexGuard guard( Mutex::getGlobalMutex() );
74*cdf0e10cSrcweir 		if( !pNames )
75*cdf0e10cSrcweir 		{
76*cdf0e10cSrcweir 			static Sequence< OUString > seqNames(1);
77*cdf0e10cSrcweir 			seqNames.getArray()[0] = OUString(RTL_CONSTASCII_USTRINGPARAM(SERVICENAME));
78*cdf0e10cSrcweir 			pNames = &seqNames;
79*cdf0e10cSrcweir 		}
80*cdf0e10cSrcweir 	}
81*cdf0e10cSrcweir 	return *pNames;
82*cdf0e10cSrcweir }
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir OUString rdbtdp_getImplementationName()
85*cdf0e10cSrcweir {
86*cdf0e10cSrcweir 	static OUString *pImplName = 0;
87*cdf0e10cSrcweir 	if( ! pImplName )
88*cdf0e10cSrcweir 	{
89*cdf0e10cSrcweir 		MutexGuard guard( Mutex::getGlobalMutex() );
90*cdf0e10cSrcweir 		if( ! pImplName )
91*cdf0e10cSrcweir 		{
92*cdf0e10cSrcweir 			static OUString implName( RTL_CONSTASCII_USTRINGPARAM( IMPLNAME ) );
93*cdf0e10cSrcweir 			pImplName = &implName;
94*cdf0e10cSrcweir 		}
95*cdf0e10cSrcweir 	}
96*cdf0e10cSrcweir 	return *pImplName;
97*cdf0e10cSrcweir }
98*cdf0e10cSrcweir }
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir namespace stoc_rdbtdp
101*cdf0e10cSrcweir {
102*cdf0e10cSrcweir struct MutexHolder
103*cdf0e10cSrcweir {
104*cdf0e10cSrcweir 	Mutex _aComponentMutex;
105*cdf0e10cSrcweir };
106*cdf0e10cSrcweir //==================================================================================================
107*cdf0e10cSrcweir class ProviderImpl
108*cdf0e10cSrcweir 	: public MutexHolder
109*cdf0e10cSrcweir     , public WeakComponentImplHelper4< XServiceInfo,
110*cdf0e10cSrcweir                                        XHierarchicalNameAccess,
111*cdf0e10cSrcweir                                        XTypeDescriptionEnumerationAccess,
112*cdf0e10cSrcweir                                        XInitialization >
113*cdf0e10cSrcweir {
114*cdf0e10cSrcweir     // XHierarchicalNameAccess + XTypeDescriptionEnumerationAccess wrapper
115*cdf0e10cSrcweir     // first asking the tdmgr instance, then looking up locally
116*cdf0e10cSrcweir     class TypeDescriptionManagerWrapper
117*cdf0e10cSrcweir         : public ::cppu::WeakImplHelper2<
118*cdf0e10cSrcweir             container::XHierarchicalNameAccess,
119*cdf0e10cSrcweir             reflection::XTypeDescriptionEnumerationAccess>
120*cdf0e10cSrcweir     {
121*cdf0e10cSrcweir         com::sun::star::uno::Reference<container::XHierarchicalNameAccess>
122*cdf0e10cSrcweir         m_xTDMgr;
123*cdf0e10cSrcweir         com::sun::star::uno::Reference<container::XHierarchicalNameAccess>
124*cdf0e10cSrcweir         m_xThisProvider;
125*cdf0e10cSrcweir     public:
126*cdf0e10cSrcweir         TypeDescriptionManagerWrapper( ProviderImpl * pProvider )
127*cdf0e10cSrcweir             : m_xTDMgr( pProvider->_xContext->getValueByName(
128*cdf0e10cSrcweir                             OUString( RTL_CONSTASCII_USTRINGPARAM(
129*cdf0e10cSrcweir                                           "/singletons/com.sun.star.reflection."
130*cdf0e10cSrcweir                                           "theTypeDescriptionManager") ) ),
131*cdf0e10cSrcweir                         UNO_QUERY_THROW ),
132*cdf0e10cSrcweir               m_xThisProvider( pProvider )
133*cdf0e10cSrcweir             {}
134*cdf0e10cSrcweir         // XHierarchicalNameAccess
135*cdf0e10cSrcweir         virtual Any SAL_CALL getByHierarchicalName( OUString const & name )
136*cdf0e10cSrcweir             throw (container::NoSuchElementException, RuntimeException);
137*cdf0e10cSrcweir         virtual sal_Bool SAL_CALL hasByHierarchicalName( OUString const & name )
138*cdf0e10cSrcweir             throw (RuntimeException);
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir         // XTypeDescriptionEnumerationAccess
141*cdf0e10cSrcweir         virtual uno::Reference<
142*cdf0e10cSrcweir             reflection::XTypeDescriptionEnumeration > SAL_CALL
143*cdf0e10cSrcweir         createTypeDescriptionEnumeration(
144*cdf0e10cSrcweir             const ::rtl::OUString& moduleName,
145*cdf0e10cSrcweir             const uno::Sequence< uno::TypeClass >& types,
146*cdf0e10cSrcweir             reflection::TypeDescriptionSearchDepth depth )
147*cdf0e10cSrcweir                 throw ( reflection::NoSuchTypeNameException,
148*cdf0e10cSrcweir                         reflection::InvalidTypeNameException,
149*cdf0e10cSrcweir                         uno::RuntimeException );
150*cdf0e10cSrcweir     };
151*cdf0e10cSrcweir     friend class TypeDescriptionManagerWrapper;
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir     com::sun::star::uno::Reference< XComponentContext >              _xContext;
154*cdf0e10cSrcweir     com::sun::star::uno::WeakReference<XHierarchicalNameAccess> _xTDMgr;
155*cdf0e10cSrcweir     com::sun::star::uno::Reference< XHierarchicalNameAccess > getTDMgr() SAL_THROW( () );
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir 	RegistryKeyList                             _aBaseKeys;
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir protected:
160*cdf0e10cSrcweir     virtual void SAL_CALL disposing();
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir public:
163*cdf0e10cSrcweir     ProviderImpl( const com::sun::star::uno::Reference< XComponentContext > & xContext );
164*cdf0e10cSrcweir 	virtual ~ProviderImpl();
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir     // XInitialization
167*cdf0e10cSrcweir     virtual void SAL_CALL initialize( const Sequence< Any > & args ) throw (Exception, RuntimeException);
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir 	// XServiceInfo
170*cdf0e10cSrcweir 	virtual OUString SAL_CALL getImplementationName() throw(::com::sun::star::uno::RuntimeException);
171*cdf0e10cSrcweir 	virtual sal_Bool SAL_CALL supportsService( const OUString & rServiceName ) throw(::com::sun::star::uno::RuntimeException);
172*cdf0e10cSrcweir 	virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException);
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir 	// XHierarchicalNameAccess
175*cdf0e10cSrcweir 	Any getByHierarchicalNameImpl( const OUString & rName );
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir 	virtual Any SAL_CALL getByHierarchicalName( const OUString & rName ) throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException);
178*cdf0e10cSrcweir 	virtual sal_Bool SAL_CALL hasByHierarchicalName( const OUString & rName ) throw(::com::sun::star::uno::RuntimeException);
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir     // XTypeDescriptionEnumerationAccess
181*cdf0e10cSrcweir     virtual ::com::sun::star::uno::Reference<
182*cdf0e10cSrcweir         ::com::sun::star::reflection::XTypeDescriptionEnumeration > SAL_CALL
183*cdf0e10cSrcweir     createTypeDescriptionEnumeration(
184*cdf0e10cSrcweir         const ::rtl::OUString& moduleName,
185*cdf0e10cSrcweir         const ::com::sun::star::uno::Sequence<
186*cdf0e10cSrcweir             ::com::sun::star::uno::TypeClass >& types,
187*cdf0e10cSrcweir         ::com::sun::star::reflection::TypeDescriptionSearchDepth depth )
188*cdf0e10cSrcweir             throw ( ::com::sun::star::reflection::NoSuchTypeNameException,
189*cdf0e10cSrcweir                     ::com::sun::star::reflection::InvalidTypeNameException,
190*cdf0e10cSrcweir                     ::com::sun::star::uno::RuntimeException );
191*cdf0e10cSrcweir };
192*cdf0e10cSrcweir //__________________________________________________________________________________________________
193*cdf0e10cSrcweir ProviderImpl::ProviderImpl( const com::sun::star::uno::Reference< XComponentContext > & xContext )
194*cdf0e10cSrcweir     : WeakComponentImplHelper4<
195*cdf0e10cSrcweir         XServiceInfo, XHierarchicalNameAccess,
196*cdf0e10cSrcweir         XTypeDescriptionEnumerationAccess, XInitialization >( _aComponentMutex )
197*cdf0e10cSrcweir 	, _xContext( xContext )
198*cdf0e10cSrcweir {
199*cdf0e10cSrcweir 	g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
200*cdf0e10cSrcweir }
201*cdf0e10cSrcweir //__________________________________________________________________________________________________
202*cdf0e10cSrcweir ProviderImpl::~ProviderImpl()
203*cdf0e10cSrcweir {
204*cdf0e10cSrcweir 	g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
205*cdf0e10cSrcweir }
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir //______________________________________________________________________________
208*cdf0e10cSrcweir Any ProviderImpl::TypeDescriptionManagerWrapper::getByHierarchicalName(
209*cdf0e10cSrcweir     OUString const & name ) throw (container::NoSuchElementException,
210*cdf0e10cSrcweir                                    RuntimeException)
211*cdf0e10cSrcweir {
212*cdf0e10cSrcweir     try
213*cdf0e10cSrcweir     {
214*cdf0e10cSrcweir         // first try tdmgr:
215*cdf0e10cSrcweir 		return m_xTDMgr->getByHierarchicalName( name );
216*cdf0e10cSrcweir     }
217*cdf0e10cSrcweir     catch (container::NoSuchElementException &)
218*cdf0e10cSrcweir     {
219*cdf0e10cSrcweir         // then lookup locally:
220*cdf0e10cSrcweir 		return m_xThisProvider->getByHierarchicalName( name );
221*cdf0e10cSrcweir     }
222*cdf0e10cSrcweir }
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir //______________________________________________________________________________
225*cdf0e10cSrcweir sal_Bool ProviderImpl::TypeDescriptionManagerWrapper::hasByHierarchicalName(
226*cdf0e10cSrcweir     OUString const & name ) throw (RuntimeException)
227*cdf0e10cSrcweir {
228*cdf0e10cSrcweir 	return m_xTDMgr->hasByHierarchicalName( name ) || m_xThisProvider->hasByHierarchicalName( name );
229*cdf0e10cSrcweir }
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir //______________________________________________________________________________
232*cdf0e10cSrcweir uno::Reference< reflection::XTypeDescriptionEnumeration > SAL_CALL
233*cdf0e10cSrcweir ProviderImpl::TypeDescriptionManagerWrapper::createTypeDescriptionEnumeration(
234*cdf0e10cSrcweir         const ::rtl::OUString& moduleName,
235*cdf0e10cSrcweir         const uno::Sequence< uno::TypeClass >& types,
236*cdf0e10cSrcweir         reflection::TypeDescriptionSearchDepth depth )
237*cdf0e10cSrcweir     throw ( reflection::NoSuchTypeNameException,
238*cdf0e10cSrcweir             reflection::InvalidTypeNameException,
239*cdf0e10cSrcweir             uno::RuntimeException )
240*cdf0e10cSrcweir {
241*cdf0e10cSrcweir     try
242*cdf0e10cSrcweir     {
243*cdf0e10cSrcweir         // first try tdmgr:
244*cdf0e10cSrcweir         uno::Reference< reflection::XTypeDescriptionEnumerationAccess > xTDEA(
245*cdf0e10cSrcweir             m_xTDMgr, uno::UNO_QUERY_THROW );
246*cdf0e10cSrcweir         return
247*cdf0e10cSrcweir             xTDEA->createTypeDescriptionEnumeration( moduleName, types, depth );
248*cdf0e10cSrcweir     }
249*cdf0e10cSrcweir     catch (reflection::NoSuchTypeNameException &)
250*cdf0e10cSrcweir     {
251*cdf0e10cSrcweir         // then lookup locally:
252*cdf0e10cSrcweir         uno::Reference< reflection::XTypeDescriptionEnumerationAccess > xTDEA(
253*cdf0e10cSrcweir             m_xThisProvider, uno::UNO_QUERY_THROW );
254*cdf0e10cSrcweir         return
255*cdf0e10cSrcweir             xTDEA->createTypeDescriptionEnumeration( moduleName, types, depth );
256*cdf0e10cSrcweir     }
257*cdf0e10cSrcweir }
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir //__________________________________________________________________________________________________
260*cdf0e10cSrcweir com::sun::star::uno::Reference< XHierarchicalNameAccess > ProviderImpl::getTDMgr()
261*cdf0e10cSrcweir     SAL_THROW( () )
262*cdf0e10cSrcweir {
263*cdf0e10cSrcweir     // harden weak reference:
264*cdf0e10cSrcweir     com::sun::star::uno::Reference<container::XHierarchicalNameAccess> xTDMgr(
265*cdf0e10cSrcweir         _xTDMgr );
266*cdf0e10cSrcweir     if (! xTDMgr.is())
267*cdf0e10cSrcweir     {
268*cdf0e10cSrcweir         xTDMgr.set( new TypeDescriptionManagerWrapper(this) );
269*cdf0e10cSrcweir         {
270*cdf0e10cSrcweir         MutexGuard guard( _aComponentMutex );
271*cdf0e10cSrcweir         _xTDMgr = xTDMgr;
272*cdf0e10cSrcweir         }
273*cdf0e10cSrcweir     }
274*cdf0e10cSrcweir     return xTDMgr;
275*cdf0e10cSrcweir }
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir //__________________________________________________________________________________________________
278*cdf0e10cSrcweir void ProviderImpl::disposing()
279*cdf0e10cSrcweir {
280*cdf0e10cSrcweir 	_xContext.clear();
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir 	for ( RegistryKeyList::const_iterator iPos( _aBaseKeys.begin() );
283*cdf0e10cSrcweir 		  iPos != _aBaseKeys.end(); ++iPos )
284*cdf0e10cSrcweir 	{
285*cdf0e10cSrcweir 		(*iPos)->closeKey();
286*cdf0e10cSrcweir 	}
287*cdf0e10cSrcweir 	_aBaseKeys.clear();
288*cdf0e10cSrcweir }
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir // XInitialization
291*cdf0e10cSrcweir //__________________________________________________________________________________________________
292*cdf0e10cSrcweir void ProviderImpl::initialize(
293*cdf0e10cSrcweir     const Sequence< Any > & args )
294*cdf0e10cSrcweir     throw (Exception, RuntimeException)
295*cdf0e10cSrcweir {
296*cdf0e10cSrcweir     // registries to read from
297*cdf0e10cSrcweir     Any const * pRegistries = args.getConstArray();
298*cdf0e10cSrcweir     for ( sal_Int32 nPos = 0; nPos < args.getLength(); ++nPos )
299*cdf0e10cSrcweir     {
300*cdf0e10cSrcweir         com::sun::star::uno::Reference< XSimpleRegistry > xRegistry( pRegistries[ nPos ], UNO_QUERY );
301*cdf0e10cSrcweir         if (xRegistry.is() && xRegistry->isValid())
302*cdf0e10cSrcweir         {
303*cdf0e10cSrcweir             com::sun::star::uno::Reference< XRegistryKey > xKey( xRegistry->getRootKey()->openKey(
304*cdf0e10cSrcweir                 OUString( RTL_CONSTASCII_USTRINGPARAM("/UCR") ) ) );
305*cdf0e10cSrcweir             if (xKey.is() && xKey->isValid())
306*cdf0e10cSrcweir             {
307*cdf0e10cSrcweir                 _aBaseKeys.push_back( xKey );
308*cdf0e10cSrcweir             }
309*cdf0e10cSrcweir         }
310*cdf0e10cSrcweir     }
311*cdf0e10cSrcweir }
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir // XServiceInfo
314*cdf0e10cSrcweir //__________________________________________________________________________________________________
315*cdf0e10cSrcweir OUString ProviderImpl::getImplementationName()
316*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
317*cdf0e10cSrcweir {
318*cdf0e10cSrcweir 	return stoc_bootstrap::rdbtdp_getImplementationName();
319*cdf0e10cSrcweir }
320*cdf0e10cSrcweir //__________________________________________________________________________________________________
321*cdf0e10cSrcweir sal_Bool ProviderImpl::supportsService( const OUString & rServiceName )
322*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
323*cdf0e10cSrcweir {
324*cdf0e10cSrcweir 	const Sequence< OUString > & rSNL = getSupportedServiceNames();
325*cdf0e10cSrcweir 	const OUString * pArray = rSNL.getConstArray();
326*cdf0e10cSrcweir 	for ( sal_Int32 nPos = rSNL.getLength(); nPos--; )
327*cdf0e10cSrcweir 	{
328*cdf0e10cSrcweir 		if (pArray[nPos] == rServiceName)
329*cdf0e10cSrcweir 			return sal_True;
330*cdf0e10cSrcweir 	}
331*cdf0e10cSrcweir 	return sal_False;
332*cdf0e10cSrcweir }
333*cdf0e10cSrcweir //__________________________________________________________________________________________________
334*cdf0e10cSrcweir Sequence< OUString > ProviderImpl::getSupportedServiceNames()
335*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
336*cdf0e10cSrcweir {
337*cdf0e10cSrcweir 	return stoc_bootstrap::rdbtdp_getSupportedServiceNames();
338*cdf0e10cSrcweir }
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir // XHierarchicalNameAccess
341*cdf0e10cSrcweir //__________________________________________________________________________________________________
342*cdf0e10cSrcweir Any ProviderImpl::getByHierarchicalNameImpl( const OUString & rName )
343*cdf0e10cSrcweir {
344*cdf0e10cSrcweir 	Any aRet;
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir     // read from registry
347*cdf0e10cSrcweir     OUString aKey( rName.replace( '.', '/' ) );
348*cdf0e10cSrcweir     for ( RegistryKeyList::const_iterator iPos( _aBaseKeys.begin() );
349*cdf0e10cSrcweir           !aRet.hasValue() && iPos != _aBaseKeys.end(); ++iPos )
350*cdf0e10cSrcweir     {
351*cdf0e10cSrcweir         try
352*cdf0e10cSrcweir         {
353*cdf0e10cSrcweir             com::sun::star::uno::Reference< XRegistryKey > xBaseKey( *iPos );
354*cdf0e10cSrcweir             com::sun::star::uno::Reference< XRegistryKey > xKey( xBaseKey->openKey( aKey ) );
355*cdf0e10cSrcweir             if (xKey.is())
356*cdf0e10cSrcweir             {
357*cdf0e10cSrcweir                 // closes key in it's dtor (which is
358*cdf0e10cSrcweir                 // called even in case of exceptions).
359*cdf0e10cSrcweir                 RegistryKeyCloser aCloser( xKey );
360*cdf0e10cSrcweir 
361*cdf0e10cSrcweir                 if ( xKey->isValid() )
362*cdf0e10cSrcweir                 {
363*cdf0e10cSrcweir                     if (xKey->getValueType() == RegistryValueType_BINARY)
364*cdf0e10cSrcweir                     {
365*cdf0e10cSrcweir                         Sequence< sal_Int8 > aBytes( xKey->getBinaryValue() );
366*cdf0e10cSrcweir                         com::sun::star::uno::Reference< XTypeDescription > xTD(
367*cdf0e10cSrcweir                             createTypeDescription( aBytes,
368*cdf0e10cSrcweir                                                    getTDMgr(),
369*cdf0e10cSrcweir                                                    true ) );
370*cdf0e10cSrcweir                         if ( xTD.is() )
371*cdf0e10cSrcweir                             aRet <<= xTD;
372*cdf0e10cSrcweir                     }
373*cdf0e10cSrcweir                 }
374*cdf0e10cSrcweir             }
375*cdf0e10cSrcweir             else // might be a constant
376*cdf0e10cSrcweir             {
377*cdf0e10cSrcweir                 sal_Int32 nIndex = aKey.lastIndexOf( '/' );
378*cdf0e10cSrcweir                 if (nIndex > 0)
379*cdf0e10cSrcweir                 {
380*cdf0e10cSrcweir                     // open module
381*cdf0e10cSrcweir                     com::sun::star::uno::Reference< XRegistryKey > xKey2( xBaseKey->openKey( aKey.copy( 0, nIndex ) ) );
382*cdf0e10cSrcweir                     if (xKey2.is())
383*cdf0e10cSrcweir                     {
384*cdf0e10cSrcweir                         // closes key in it's dtor (which is
385*cdf0e10cSrcweir                         // called even in case of exceptions).
386*cdf0e10cSrcweir                         RegistryKeyCloser aCloser( xKey2 );
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir                         if ( xKey2->isValid() )
389*cdf0e10cSrcweir                         {
390*cdf0e10cSrcweir                             if (xKey2->getValueType() == RegistryValueType_BINARY)
391*cdf0e10cSrcweir                             {
392*cdf0e10cSrcweir                                 Sequence< sal_Int8 > aBytes( xKey2->getBinaryValue() );
393*cdf0e10cSrcweir                                 typereg::Reader aReader(
394*cdf0e10cSrcweir                                     aBytes.getConstArray(), aBytes.getLength(),
395*cdf0e10cSrcweir                                     false, TYPEREG_VERSION_1);
396*cdf0e10cSrcweir 
397*cdf0e10cSrcweir                                 if (aReader.getTypeClass() == RT_TYPE_MODULE ||
398*cdf0e10cSrcweir                                     aReader.getTypeClass() == RT_TYPE_CONSTANTS ||
399*cdf0e10cSrcweir                                     aReader.getTypeClass() == RT_TYPE_ENUM)
400*cdf0e10cSrcweir                                 {
401*cdf0e10cSrcweir                                     OUString aFieldName( aKey.copy( nIndex+1, aKey.getLength() - nIndex -1 ) );
402*cdf0e10cSrcweir                                     sal_Int16 nPos = aReader.getFieldCount();
403*cdf0e10cSrcweir                                     while (nPos--)
404*cdf0e10cSrcweir                                     {
405*cdf0e10cSrcweir                                         if (aFieldName.equals(
406*cdf0e10cSrcweir                                                 aReader.getFieldName(nPos)))
407*cdf0e10cSrcweir                                             break;
408*cdf0e10cSrcweir                                     }
409*cdf0e10cSrcweir                                     if (nPos >= 0)
410*cdf0e10cSrcweir                                         aRet = getRTValue(
411*cdf0e10cSrcweir                                             aReader.getFieldValue(nPos));
412*cdf0e10cSrcweir                                 }
413*cdf0e10cSrcweir                             }
414*cdf0e10cSrcweir                         }
415*cdf0e10cSrcweir                     }
416*cdf0e10cSrcweir                 }
417*cdf0e10cSrcweir             }
418*cdf0e10cSrcweir         }
419*cdf0e10cSrcweir         catch ( InvalidRegistryException const & )
420*cdf0e10cSrcweir         {
421*cdf0e10cSrcweir             OSL_ENSURE( sal_False,
422*cdf0e10cSrcweir                         "ProviderImpl::getByHierarchicalName "
423*cdf0e10cSrcweir                         "- Caught InvalidRegistryException!" );
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir             // openKey, closeKey, getValueType, getBinaryValue, isValid
426*cdf0e10cSrcweir 
427*cdf0e10cSrcweir             // Don't stop iteration in this case.
428*cdf0e10cSrcweir         }
429*cdf0e10cSrcweir 		catch ( NoSuchElementException const & )
430*cdf0e10cSrcweir 		{
431*cdf0e10cSrcweir 		}
432*cdf0e10cSrcweir     }
433*cdf0e10cSrcweir 	return aRet;
434*cdf0e10cSrcweir }
435*cdf0e10cSrcweir 
436*cdf0e10cSrcweir Any SAL_CALL ProviderImpl::getByHierarchicalName( const OUString & rName )
437*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException, com::sun::star::container::NoSuchElementException)
438*cdf0e10cSrcweir {
439*cdf0e10cSrcweir 	Any aRet( getByHierarchicalNameImpl( rName ) );
440*cdf0e10cSrcweir 
441*cdf0e10cSrcweir     if ( !aRet.hasValue() )
442*cdf0e10cSrcweir         throw NoSuchElementException(
443*cdf0e10cSrcweir             rName, static_cast< cppu::OWeakObject * >( this  ) );
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir 	return aRet;
446*cdf0e10cSrcweir }
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir //__________________________________________________________________________________________________
449*cdf0e10cSrcweir sal_Bool ProviderImpl::hasByHierarchicalName( const OUString & rName )
450*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
451*cdf0e10cSrcweir {
452*cdf0e10cSrcweir 	return getByHierarchicalNameImpl( rName ).hasValue();
453*cdf0e10cSrcweir }
454*cdf0e10cSrcweir 
455*cdf0e10cSrcweir // XTypeDescriptionEnumerationAccess
456*cdf0e10cSrcweir //__________________________________________________________________________________________________
457*cdf0e10cSrcweir // virtual
458*cdf0e10cSrcweir com::sun::star::uno::Reference< XTypeDescriptionEnumeration > SAL_CALL
459*cdf0e10cSrcweir ProviderImpl::createTypeDescriptionEnumeration(
460*cdf0e10cSrcweir         const OUString & moduleName,
461*cdf0e10cSrcweir         const Sequence< TypeClass > & types,
462*cdf0e10cSrcweir         TypeDescriptionSearchDepth depth )
463*cdf0e10cSrcweir     throw ( NoSuchTypeNameException,
464*cdf0e10cSrcweir             InvalidTypeNameException,
465*cdf0e10cSrcweir             RuntimeException )
466*cdf0e10cSrcweir {
467*cdf0e10cSrcweir     return com::sun::star::uno::Reference< XTypeDescriptionEnumeration >(
468*cdf0e10cSrcweir         TypeDescriptionEnumerationImpl::createInstance( getTDMgr(),
469*cdf0e10cSrcweir                                                         moduleName,
470*cdf0e10cSrcweir                                                         types,
471*cdf0e10cSrcweir                                                         depth,
472*cdf0e10cSrcweir                                                         _aBaseKeys ).get() );
473*cdf0e10cSrcweir }
474*cdf0e10cSrcweir 
475*cdf0e10cSrcweir //__________________________________________________________________________________________________
476*cdf0e10cSrcweir // global helper function
477*cdf0e10cSrcweir 
478*cdf0e10cSrcweir com::sun::star::uno::Reference< XTypeDescription > resolveTypedefs(
479*cdf0e10cSrcweir     com::sun::star::uno::Reference< XTypeDescription > const & type)
480*cdf0e10cSrcweir {
481*cdf0e10cSrcweir     com::sun::star::uno::Reference< XTypeDescription > resolved(type);
482*cdf0e10cSrcweir     while (resolved->getTypeClass() == TypeClass_TYPEDEF) {
483*cdf0e10cSrcweir         resolved = com::sun::star::uno::Reference< XIndirectTypeDescription >(
484*cdf0e10cSrcweir             resolved, UNO_QUERY_THROW)->getReferencedType();
485*cdf0e10cSrcweir     }
486*cdf0e10cSrcweir     return resolved;
487*cdf0e10cSrcweir }
488*cdf0e10cSrcweir 
489*cdf0e10cSrcweir com::sun::star::uno::Reference< XTypeDescription > createTypeDescription(
490*cdf0e10cSrcweir     const Sequence< sal_Int8 > & rData,
491*cdf0e10cSrcweir     const com::sun::star::uno::Reference< XHierarchicalNameAccess > & xNameAccess,
492*cdf0e10cSrcweir     bool bReturnEmptyRefForUnknownType )
493*cdf0e10cSrcweir {
494*cdf0e10cSrcweir     typereg::Reader aReader(
495*cdf0e10cSrcweir         rData.getConstArray(), rData.getLength(), false, TYPEREG_VERSION_1);
496*cdf0e10cSrcweir 
497*cdf0e10cSrcweir     OUString aName( aReader.getTypeName().replace( '/', '.' ) );
498*cdf0e10cSrcweir 
499*cdf0e10cSrcweir     switch (aReader.getTypeClass())
500*cdf0e10cSrcweir     {
501*cdf0e10cSrcweir         case RT_TYPE_INTERFACE:
502*cdf0e10cSrcweir         {
503*cdf0e10cSrcweir             sal_uInt16 n = aReader.getSuperTypeCount();
504*cdf0e10cSrcweir             com::sun::star::uno::Sequence< rtl::OUString > aBaseTypeNames(n);
505*cdf0e10cSrcweir             {for (sal_uInt16 i = 0; i < n; ++i) {
506*cdf0e10cSrcweir                 aBaseTypeNames[i] = aReader.getSuperTypeName(i).replace(
507*cdf0e10cSrcweir                     '/', '.');
508*cdf0e10cSrcweir             }}
509*cdf0e10cSrcweir             sal_uInt16 n2 = aReader.getReferenceCount();
510*cdf0e10cSrcweir             com::sun::star::uno::Sequence< rtl::OUString >
511*cdf0e10cSrcweir                 aOptionalBaseTypeNames(n2);
512*cdf0e10cSrcweir             {for (sal_uInt16 i = 0; i < n2; ++i) {
513*cdf0e10cSrcweir                 OSL_ASSERT(
514*cdf0e10cSrcweir                     aReader.getReferenceSort(i) == RT_REF_SUPPORTS
515*cdf0e10cSrcweir                     && aReader.getReferenceFlags(i) == RT_ACCESS_OPTIONAL);
516*cdf0e10cSrcweir                 aOptionalBaseTypeNames[i] = aReader.getReferenceTypeName(i);
517*cdf0e10cSrcweir             }}
518*cdf0e10cSrcweir             return com::sun::star::uno::Reference< XTypeDescription >(
519*cdf0e10cSrcweir                 new InterfaceTypeDescriptionImpl( xNameAccess,
520*cdf0e10cSrcweir                                                   aName,
521*cdf0e10cSrcweir                                                   aBaseTypeNames,
522*cdf0e10cSrcweir                                                   aOptionalBaseTypeNames,
523*cdf0e10cSrcweir                                                   rData,
524*cdf0e10cSrcweir                                                   aReader.isPublished() ) );
525*cdf0e10cSrcweir         }
526*cdf0e10cSrcweir 
527*cdf0e10cSrcweir         case RT_TYPE_MODULE:
528*cdf0e10cSrcweir         {
529*cdf0e10cSrcweir             com::sun::star::uno::Reference<
530*cdf0e10cSrcweir                 XTypeDescriptionEnumerationAccess > xTDEA(
531*cdf0e10cSrcweir                     xNameAccess, UNO_QUERY );
532*cdf0e10cSrcweir 
533*cdf0e10cSrcweir             OSL_ENSURE( xTDEA.is(),
534*cdf0e10cSrcweir                         "No XTypeDescriptionEnumerationAccess!" );
535*cdf0e10cSrcweir 
536*cdf0e10cSrcweir             return com::sun::star::uno::Reference< XTypeDescription >(
537*cdf0e10cSrcweir                 new ModuleTypeDescriptionImpl( xTDEA, aName ) );
538*cdf0e10cSrcweir         }
539*cdf0e10cSrcweir 
540*cdf0e10cSrcweir         case RT_TYPE_STRUCT:
541*cdf0e10cSrcweir             {
542*cdf0e10cSrcweir                 rtl::OUString superTypeName;
543*cdf0e10cSrcweir                 if (aReader.getSuperTypeCount() == 1) {
544*cdf0e10cSrcweir                     superTypeName = aReader.getSuperTypeName(0).replace(
545*cdf0e10cSrcweir                         '/', '.');
546*cdf0e10cSrcweir                 }
547*cdf0e10cSrcweir                 return com::sun::star::uno::Reference< XTypeDescription >(
548*cdf0e10cSrcweir                     new stoc::registry_tdprovider::StructTypeDescription(
549*cdf0e10cSrcweir                         xNameAccess, aName, superTypeName, rData,
550*cdf0e10cSrcweir                         aReader.isPublished()));
551*cdf0e10cSrcweir             }
552*cdf0e10cSrcweir 
553*cdf0e10cSrcweir         case RT_TYPE_ENUM:
554*cdf0e10cSrcweir             return com::sun::star::uno::Reference< XTypeDescription >(
555*cdf0e10cSrcweir                 new EnumTypeDescriptionImpl( xNameAccess,
556*cdf0e10cSrcweir                                              aName,
557*cdf0e10cSrcweir                                              getRTValueAsInt32(
558*cdf0e10cSrcweir                                                 aReader.getFieldValue( 0 ) ),
559*cdf0e10cSrcweir                                              rData, aReader.isPublished() ) );
560*cdf0e10cSrcweir 
561*cdf0e10cSrcweir         case RT_TYPE_EXCEPTION:
562*cdf0e10cSrcweir             {
563*cdf0e10cSrcweir                 rtl::OUString superTypeName;
564*cdf0e10cSrcweir                 if (aReader.getSuperTypeCount() == 1) {
565*cdf0e10cSrcweir                     superTypeName = aReader.getSuperTypeName(0).replace(
566*cdf0e10cSrcweir                         '/', '.');
567*cdf0e10cSrcweir                 }
568*cdf0e10cSrcweir                 return com::sun::star::uno::Reference< XTypeDescription >(
569*cdf0e10cSrcweir                     new CompoundTypeDescriptionImpl(
570*cdf0e10cSrcweir                         xNameAccess, TypeClass_EXCEPTION, aName, superTypeName,
571*cdf0e10cSrcweir                         rData, aReader.isPublished()));
572*cdf0e10cSrcweir             }
573*cdf0e10cSrcweir 
574*cdf0e10cSrcweir         case RT_TYPE_TYPEDEF:
575*cdf0e10cSrcweir             return com::sun::star::uno::Reference< XTypeDescription >(
576*cdf0e10cSrcweir                 new TypedefTypeDescriptionImpl( xNameAccess,
577*cdf0e10cSrcweir                                                 aName,
578*cdf0e10cSrcweir                                                 aReader.getSuperTypeName(0)
579*cdf0e10cSrcweir                                                     .replace( '/', '.' ),
580*cdf0e10cSrcweir                                                 aReader.isPublished() ) );
581*cdf0e10cSrcweir         case RT_TYPE_SERVICE:
582*cdf0e10cSrcweir             return com::sun::star::uno::Reference< XTypeDescription >(
583*cdf0e10cSrcweir                 new ServiceTypeDescriptionImpl(
584*cdf0e10cSrcweir                     xNameAccess, aName, rData, aReader.isPublished() ) );
585*cdf0e10cSrcweir 
586*cdf0e10cSrcweir         case RT_TYPE_CONSTANTS:
587*cdf0e10cSrcweir             return com::sun::star::uno::Reference< XTypeDescription >(
588*cdf0e10cSrcweir                 new ConstantsTypeDescriptionImpl(
589*cdf0e10cSrcweir                     aName, rData, aReader.isPublished() ) );
590*cdf0e10cSrcweir 
591*cdf0e10cSrcweir         case RT_TYPE_SINGLETON:
592*cdf0e10cSrcweir             return com::sun::star::uno::Reference< XTypeDescription >(
593*cdf0e10cSrcweir                 new SingletonTypeDescriptionImpl( xNameAccess,
594*cdf0e10cSrcweir                                                   aName,
595*cdf0e10cSrcweir                                                   aReader.getSuperTypeName(0)
596*cdf0e10cSrcweir                                                     .replace( '/', '.' ),
597*cdf0e10cSrcweir                                                   aReader.isPublished() ) );
598*cdf0e10cSrcweir         case RT_TYPE_INVALID:
599*cdf0e10cSrcweir         case RT_TYPE_OBJECT:      // deprecated and not used
600*cdf0e10cSrcweir         case RT_TYPE_UNION:       // deprecated and not used
601*cdf0e10cSrcweir             OSL_ENSURE( sal_False, "createTypeDescription - Unsupported Type!" );
602*cdf0e10cSrcweir             break;
603*cdf0e10cSrcweir 
604*cdf0e10cSrcweir         default:
605*cdf0e10cSrcweir             OSL_ENSURE( sal_False, "createTypeDescription - Unknown Type!" );
606*cdf0e10cSrcweir             break;
607*cdf0e10cSrcweir     }
608*cdf0e10cSrcweir 
609*cdf0e10cSrcweir     // Unknown type.
610*cdf0e10cSrcweir 
611*cdf0e10cSrcweir     if ( bReturnEmptyRefForUnknownType )
612*cdf0e10cSrcweir         return com::sun::star::uno::Reference< XTypeDescription >();
613*cdf0e10cSrcweir 
614*cdf0e10cSrcweir     return com::sun::star::uno::Reference< XTypeDescription >(
615*cdf0e10cSrcweir                 new TypeDescriptionImpl( TypeClass_UNKNOWN, aName ) );
616*cdf0e10cSrcweir }
617*cdf0e10cSrcweir 
618*cdf0e10cSrcweir }
619*cdf0e10cSrcweir 
620*cdf0e10cSrcweir namespace stoc_bootstrap
621*cdf0e10cSrcweir {
622*cdf0e10cSrcweir //==================================================================================================
623*cdf0e10cSrcweir com::sun::star::uno::Reference< XInterface > SAL_CALL ProviderImpl_create(
624*cdf0e10cSrcweir     com::sun::star::uno::Reference< XComponentContext > const & xContext )
625*cdf0e10cSrcweir 	throw(::com::sun::star::uno::Exception)
626*cdf0e10cSrcweir {
627*cdf0e10cSrcweir     return com::sun::star::uno::Reference< XInterface >( *new stoc_rdbtdp::ProviderImpl( xContext ) );
628*cdf0e10cSrcweir }
629*cdf0e10cSrcweir }
630