xref: /AOO41X/main/stoc/source/registry_tdprovider/rdbtdp_tdenumeration.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 
31*cdf0e10cSrcweir //=========================================================================
32*cdf0e10cSrcweir // Todo:
33*cdf0e10cSrcweir //
34*cdf0e10cSrcweir // - closeKey() calls (according to JSC not really needed because XRegistry
35*cdf0e10cSrcweir //   implementation closes key in it's dtor.
36*cdf0e10cSrcweir //
37*cdf0e10cSrcweir //=========================================================================
38*cdf0e10cSrcweir #include <osl/diagnose.h>
39*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
40*cdf0e10cSrcweir #include "com/sun/star/reflection/XPublished.hpp"
41*cdf0e10cSrcweir #include "cppuhelper/implbase1.hxx"
42*cdf0e10cSrcweir #include "registry/reader.hxx"
43*cdf0e10cSrcweir #include "registry/version.h"
44*cdf0e10cSrcweir #include "base.hxx"
45*cdf0e10cSrcweir #include "rdbtdp_tdenumeration.hxx"
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir using namespace com::sun::star;
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir namespace {
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir class IndividualConstantTypeDescriptionImpl:
52*cdf0e10cSrcweir     public cppu::ImplInheritanceHelper1<
53*cdf0e10cSrcweir         stoc_rdbtdp::ConstantTypeDescriptionImpl,
54*cdf0e10cSrcweir         com::sun::star::reflection::XPublished >
55*cdf0e10cSrcweir {
56*cdf0e10cSrcweir public:
57*cdf0e10cSrcweir     IndividualConstantTypeDescriptionImpl(
58*cdf0e10cSrcweir         rtl::OUString const & name, com::sun::star::uno::Any const & value,
59*cdf0e10cSrcweir         bool published):
60*cdf0e10cSrcweir         cppu::ImplInheritanceHelper1<
61*cdf0e10cSrcweir             stoc_rdbtdp::ConstantTypeDescriptionImpl,
62*cdf0e10cSrcweir             com::sun::star::reflection::XPublished >(name, value),
63*cdf0e10cSrcweir         m_published(published) {}
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir     virtual sal_Bool SAL_CALL isPublished()
66*cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException)
67*cdf0e10cSrcweir     { return m_published; }
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir private:
70*cdf0e10cSrcweir     bool m_published;
71*cdf0e10cSrcweir };
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir }
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir namespace stoc_rdbtdp
76*cdf0e10cSrcweir {
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir //=========================================================================
79*cdf0e10cSrcweir //=========================================================================
80*cdf0e10cSrcweir //
81*cdf0e10cSrcweir // TypeDescriptionEnumerationImpl Implementation.
82*cdf0e10cSrcweir //
83*cdf0e10cSrcweir //=========================================================================
84*cdf0e10cSrcweir //=========================================================================
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir // static
87*cdf0e10cSrcweir rtl::Reference< TypeDescriptionEnumerationImpl >
88*cdf0e10cSrcweir TypeDescriptionEnumerationImpl::createInstance(
89*cdf0e10cSrcweir         const uno::Reference< container::XHierarchicalNameAccess > & xTDMgr,
90*cdf0e10cSrcweir         const rtl::OUString & rModuleName,
91*cdf0e10cSrcweir         const uno::Sequence< uno::TypeClass > & rTypes,
92*cdf0e10cSrcweir         reflection::TypeDescriptionSearchDepth eDepth,
93*cdf0e10cSrcweir         const RegistryKeyList & rBaseKeys )
94*cdf0e10cSrcweir     throw ( reflection::NoSuchTypeNameException,
95*cdf0e10cSrcweir             reflection::InvalidTypeNameException,
96*cdf0e10cSrcweir             uno::RuntimeException )
97*cdf0e10cSrcweir {
98*cdf0e10cSrcweir     if ( rModuleName.getLength() == 0 )
99*cdf0e10cSrcweir     {
100*cdf0e10cSrcweir         // Enumeration for root requested.
101*cdf0e10cSrcweir         return rtl::Reference< TypeDescriptionEnumerationImpl >(
102*cdf0e10cSrcweir             new TypeDescriptionEnumerationImpl(
103*cdf0e10cSrcweir                 xTDMgr, rBaseKeys, rTypes, eDepth ) );
104*cdf0e10cSrcweir     }
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir     RegistryKeyList aModuleKeys;
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir     rtl::OUString aKey( rModuleName.replace( '.', '/' ) );
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir     bool bOpenKeySucceeded = false;
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir     const RegistryKeyList::const_iterator end = rBaseKeys.end();
113*cdf0e10cSrcweir     RegistryKeyList::const_iterator it = rBaseKeys.begin();
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir     while ( it != end )
116*cdf0e10cSrcweir     {
117*cdf0e10cSrcweir         uno::Reference< registry::XRegistryKey > xKey;
118*cdf0e10cSrcweir         try
119*cdf0e10cSrcweir         {
120*cdf0e10cSrcweir             xKey = (*it)->openKey( aKey );
121*cdf0e10cSrcweir             if ( xKey.is() )
122*cdf0e10cSrcweir             {
123*cdf0e10cSrcweir                 // closes key in it's dtor (which is
124*cdf0e10cSrcweir                 // called even in case of exceptions).
125*cdf0e10cSrcweir                 RegistryKeyCloser aCloser( xKey );
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir                 if ( xKey->isValid() )
128*cdf0e10cSrcweir                 {
129*cdf0e10cSrcweir                     bOpenKeySucceeded = true;
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir                     if ( xKey->getValueType()
132*cdf0e10cSrcweir                          == registry::RegistryValueType_BINARY )
133*cdf0e10cSrcweir                     {
134*cdf0e10cSrcweir                         uno::Sequence< sal_Int8 > aBytes(
135*cdf0e10cSrcweir                             xKey->getBinaryValue() );
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir                         typereg::Reader aReader(
138*cdf0e10cSrcweir                             aBytes.getConstArray(), aBytes.getLength(), false,
139*cdf0e10cSrcweir                             TYPEREG_VERSION_1);
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir                         rtl::OUString aName(
142*cdf0e10cSrcweir                             aReader.getTypeName().replace( '/', '.' ) );
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir                         if ( aReader.getTypeClass() == RT_TYPE_MODULE )
145*cdf0e10cSrcweir                         {
146*cdf0e10cSrcweir                             // Do not close xKey!
147*cdf0e10cSrcweir                             aCloser.reset();
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir                             aModuleKeys.push_back( xKey );
150*cdf0e10cSrcweir                         }
151*cdf0e10cSrcweir                     }
152*cdf0e10cSrcweir                 }
153*cdf0e10cSrcweir                 else
154*cdf0e10cSrcweir                 {
155*cdf0e10cSrcweir                     OSL_ENSURE(
156*cdf0e10cSrcweir                         sal_False,
157*cdf0e10cSrcweir                         "TypeDescriptionEnumerationImpl::createInstance "
158*cdf0e10cSrcweir                         "- Invalid registry key!" );
159*cdf0e10cSrcweir                 }
160*cdf0e10cSrcweir             }
161*cdf0e10cSrcweir         }
162*cdf0e10cSrcweir         catch ( registry::InvalidRegistryException const & )
163*cdf0e10cSrcweir         {
164*cdf0e10cSrcweir             // openKey, getValueType, getBinaryValue
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir             OSL_ENSURE( sal_False,
167*cdf0e10cSrcweir                         "TypeDescriptionEnumerationImpl::createInstance "
168*cdf0e10cSrcweir                         "- Caught InvalidRegistryException!" );
169*cdf0e10cSrcweir         }
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir         it++;
172*cdf0e10cSrcweir     }
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir     if ( !bOpenKeySucceeded )
175*cdf0e10cSrcweir         throw reflection::NoSuchTypeNameException();
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir     if ( aModuleKeys.size() == 0 )
178*cdf0e10cSrcweir         throw reflection::InvalidTypeNameException();
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir     return rtl::Reference< TypeDescriptionEnumerationImpl >(
181*cdf0e10cSrcweir         new TypeDescriptionEnumerationImpl(
182*cdf0e10cSrcweir                 xTDMgr, aModuleKeys, rTypes, eDepth ) );
183*cdf0e10cSrcweir }
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir //=========================================================================
186*cdf0e10cSrcweir TypeDescriptionEnumerationImpl::TypeDescriptionEnumerationImpl(
187*cdf0e10cSrcweir     const uno::Reference< container::XHierarchicalNameAccess > & xTDMgr,
188*cdf0e10cSrcweir     const RegistryKeyList & rModuleKeys,
189*cdf0e10cSrcweir     const uno::Sequence< uno::TypeClass > & rTypes,
190*cdf0e10cSrcweir     reflection::TypeDescriptionSearchDepth eDepth )
191*cdf0e10cSrcweir : m_aModuleKeys( rModuleKeys ),
192*cdf0e10cSrcweir   m_aTypes( rTypes ),
193*cdf0e10cSrcweir   m_eDepth( eDepth ),
194*cdf0e10cSrcweir   m_xTDMgr( xTDMgr )
195*cdf0e10cSrcweir {
196*cdf0e10cSrcweir     g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
197*cdf0e10cSrcweir }
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir //=========================================================================
200*cdf0e10cSrcweir // virtual
201*cdf0e10cSrcweir TypeDescriptionEnumerationImpl::~TypeDescriptionEnumerationImpl()
202*cdf0e10cSrcweir {
203*cdf0e10cSrcweir     RegistryKeyList::const_iterator it = m_aModuleKeys.begin();
204*cdf0e10cSrcweir     RegistryKeyList::const_iterator end = m_aModuleKeys.end();
205*cdf0e10cSrcweir /*
206*cdf0e10cSrcweir    @@@ in case we enumerate root and queryMore was never called, then
207*cdf0e10cSrcweir        m_aModuleKeys contains open root keys which where passed from
208*cdf0e10cSrcweir        tdprov and must not be closed by us.
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir     while ( it != end )
211*cdf0e10cSrcweir     {
212*cdf0e10cSrcweir         try
213*cdf0e10cSrcweir         {
214*cdf0e10cSrcweir             if ( (*it)->isValid() )
215*cdf0e10cSrcweir                 (*it)->closeKey();
216*cdf0e10cSrcweir         }
217*cdf0e10cSrcweir         catch (...)
218*cdf0e10cSrcweir         {
219*cdf0e10cSrcweir             // No exceptions from dtors, please!
220*cdf0e10cSrcweir             OSL_ENSURE( sal_False,
221*cdf0e10cSrcweir             "TypeDescriptionEnumerationImpl::~TypeDescriptionEnumerationImpl "
222*cdf0e10cSrcweir             "- Caught exception!" );
223*cdf0e10cSrcweir         }
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir         it++;
226*cdf0e10cSrcweir     }
227*cdf0e10cSrcweir */
228*cdf0e10cSrcweir     it = m_aCurrentModuleSubKeys.begin();
229*cdf0e10cSrcweir     end = m_aCurrentModuleSubKeys.end();
230*cdf0e10cSrcweir     while ( it != end )
231*cdf0e10cSrcweir     {
232*cdf0e10cSrcweir         try
233*cdf0e10cSrcweir         {
234*cdf0e10cSrcweir             if ( (*it)->isValid() )
235*cdf0e10cSrcweir                 (*it)->closeKey();
236*cdf0e10cSrcweir         }
237*cdf0e10cSrcweir         catch (Exception &)
238*cdf0e10cSrcweir         {
239*cdf0e10cSrcweir             // No exceptions from dtors, please!
240*cdf0e10cSrcweir             OSL_ENSURE( sal_False,
241*cdf0e10cSrcweir             "TypeDescriptionEnumerationImpl::~TypeDescriptionEnumerationImpl "
242*cdf0e10cSrcweir             "- Caught exception!" );
243*cdf0e10cSrcweir         }
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir         it++;
246*cdf0e10cSrcweir     }
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir     g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
249*cdf0e10cSrcweir }
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir //=========================================================================
252*cdf0e10cSrcweir //
253*cdf0e10cSrcweir // XEnumeration (base of XTypeDescriptionEnumeration) methods
254*cdf0e10cSrcweir //
255*cdf0e10cSrcweir //=========================================================================
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir // virtual
258*cdf0e10cSrcweir sal_Bool SAL_CALL TypeDescriptionEnumerationImpl::hasMoreElements()
259*cdf0e10cSrcweir     throw ( uno::RuntimeException )
260*cdf0e10cSrcweir {
261*cdf0e10cSrcweir     return queryMore();
262*cdf0e10cSrcweir }
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir //=========================================================================
265*cdf0e10cSrcweir // virtual
266*cdf0e10cSrcweir uno::Any SAL_CALL TypeDescriptionEnumerationImpl::nextElement()
267*cdf0e10cSrcweir     throw ( container::NoSuchElementException,
268*cdf0e10cSrcweir             lang::WrappedTargetException,
269*cdf0e10cSrcweir             uno::RuntimeException )
270*cdf0e10cSrcweir {
271*cdf0e10cSrcweir     return uno::Any( uno::makeAny( nextTypeDescription() ) );
272*cdf0e10cSrcweir }
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir //=========================================================================
275*cdf0e10cSrcweir //
276*cdf0e10cSrcweir // XTypeDescriptionEnumeration methods
277*cdf0e10cSrcweir //
278*cdf0e10cSrcweir //=========================================================================
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir // virtual
281*cdf0e10cSrcweir uno::Reference< reflection::XTypeDescription > SAL_CALL
282*cdf0e10cSrcweir TypeDescriptionEnumerationImpl::nextTypeDescription()
283*cdf0e10cSrcweir     throw ( container::NoSuchElementException,
284*cdf0e10cSrcweir             uno::RuntimeException )
285*cdf0e10cSrcweir {
286*cdf0e10cSrcweir     uno::Reference< reflection::XTypeDescription > xTD( queryNext() );
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir     if ( xTD.is() )
289*cdf0e10cSrcweir         return xTD;
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir     throw container::NoSuchElementException(
292*cdf0e10cSrcweir         rtl::OUString::createFromAscii(
293*cdf0e10cSrcweir             "No further elements in enumeration!" ),
294*cdf0e10cSrcweir         static_cast< cppu::OWeakObject * >( this  ) );
295*cdf0e10cSrcweir }
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir //=========================================================================
298*cdf0e10cSrcweir bool TypeDescriptionEnumerationImpl::match(
299*cdf0e10cSrcweir     RTTypeClass eType1, uno::TypeClass eType2 )
300*cdf0e10cSrcweir {
301*cdf0e10cSrcweir     switch ( eType1 )
302*cdf0e10cSrcweir     {
303*cdf0e10cSrcweir     case RT_TYPE_INTERFACE:
304*cdf0e10cSrcweir         return eType2 == uno::TypeClass_INTERFACE;
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir     case RT_TYPE_MODULE:
307*cdf0e10cSrcweir         return eType2 == uno::TypeClass_MODULE;
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir     case RT_TYPE_STRUCT:
310*cdf0e10cSrcweir         return eType2 == uno::TypeClass_STRUCT;
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir     case RT_TYPE_ENUM:
313*cdf0e10cSrcweir         return eType2 == uno::TypeClass_ENUM;
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir     case RT_TYPE_EXCEPTION:
316*cdf0e10cSrcweir         return eType2 == uno::TypeClass_EXCEPTION;
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir     case RT_TYPE_TYPEDEF:
319*cdf0e10cSrcweir         return eType2 == uno::TypeClass_TYPEDEF;
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir     case RT_TYPE_SERVICE:
322*cdf0e10cSrcweir         return eType2 == uno::TypeClass_SERVICE;
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir     case RT_TYPE_SINGLETON:
325*cdf0e10cSrcweir         return eType2 == uno::TypeClass_SINGLETON;
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir     case RT_TYPE_CONSTANTS:
328*cdf0e10cSrcweir         return eType2 == uno::TypeClass_CONSTANTS;
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir     case RT_TYPE_UNION:
331*cdf0e10cSrcweir         return eType2 == uno::TypeClass_UNION;
332*cdf0e10cSrcweir 
333*cdf0e10cSrcweir     default:
334*cdf0e10cSrcweir         return false;
335*cdf0e10cSrcweir     }
336*cdf0e10cSrcweir }
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir //=========================================================================
339*cdf0e10cSrcweir bool TypeDescriptionEnumerationImpl::queryMore()
340*cdf0e10cSrcweir {
341*cdf0e10cSrcweir     osl::MutexGuard aGuard( m_aMutex );
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir     for (;;)
344*cdf0e10cSrcweir     {
345*cdf0e10cSrcweir         if ( !m_aCurrentModuleSubKeys.empty() || !m_aTypeDescs.empty() )
346*cdf0e10cSrcweir         {
347*cdf0e10cSrcweir             // Okay, there is at least one more element.
348*cdf0e10cSrcweir             return true;
349*cdf0e10cSrcweir         }
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir         if ( m_aModuleKeys.empty() )
352*cdf0e10cSrcweir         {
353*cdf0e10cSrcweir             // No module keys (therefore no elements) left.
354*cdf0e10cSrcweir             return false;
355*cdf0e10cSrcweir         }
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir         // Note: m_aCurrentModuleSubKeys is always empty AND m_aModuleKeys is
358*cdf0e10cSrcweir         //       never empty when ariving here.
359*cdf0e10cSrcweir         //       ==> select new module key, fill m_aCurrentModuleSubKeys
360*cdf0e10cSrcweir 
361*cdf0e10cSrcweir         uno::Sequence< uno::Reference< registry::XRegistryKey > > aKeys;
362*cdf0e10cSrcweir         try
363*cdf0e10cSrcweir         {
364*cdf0e10cSrcweir             aKeys = m_aModuleKeys.front()->openKeys();
365*cdf0e10cSrcweir             for ( sal_Int32 n = 0; n < aKeys.getLength(); ++n )
366*cdf0e10cSrcweir             {
367*cdf0e10cSrcweir                 uno::Reference< registry::XRegistryKey > xKey = aKeys[ n ];
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir                 // closes key in it's dtor (which is
370*cdf0e10cSrcweir                 // called even in case of exceptions).
371*cdf0e10cSrcweir                 RegistryKeyCloser aCloser( xKey );
372*cdf0e10cSrcweir 
373*cdf0e10cSrcweir                 try
374*cdf0e10cSrcweir                 {
375*cdf0e10cSrcweir                     if ( xKey->isValid() )
376*cdf0e10cSrcweir                     {
377*cdf0e10cSrcweir                         if ( xKey->getValueType()
378*cdf0e10cSrcweir                                 == registry::RegistryValueType_BINARY )
379*cdf0e10cSrcweir                         {
380*cdf0e10cSrcweir                             bool bIncludeIt = (m_aTypes.getLength() == 0);
381*cdf0e10cSrcweir                             bool bNeedTypeClass =
382*cdf0e10cSrcweir                                 ((m_aTypes.getLength() > 0) ||
383*cdf0e10cSrcweir                                  (m_eDepth
384*cdf0e10cSrcweir                                     == reflection::TypeDescriptionSearchDepth_INFINITE));
385*cdf0e10cSrcweir                             if ( bNeedTypeClass )
386*cdf0e10cSrcweir                             {
387*cdf0e10cSrcweir                                 uno::Sequence< sal_Int8 > aBytes(
388*cdf0e10cSrcweir                                     xKey->getBinaryValue() );
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir                                 typereg::Reader aReader(
391*cdf0e10cSrcweir                                     aBytes.getConstArray(), aBytes.getLength(),
392*cdf0e10cSrcweir                                     false, TYPEREG_VERSION_1);
393*cdf0e10cSrcweir 
394*cdf0e10cSrcweir                                 RTTypeClass eTypeClass = aReader.getTypeClass();
395*cdf0e10cSrcweir 
396*cdf0e10cSrcweir                                 // Does key match requested types? Empty
397*cdf0e10cSrcweir                                 // sequence means include all.
398*cdf0e10cSrcweir                                 if ( m_aTypes.getLength() > 0 )
399*cdf0e10cSrcweir                                 {
400*cdf0e10cSrcweir                                     for ( sal_Int32 m = 0;
401*cdf0e10cSrcweir                                           m < m_aTypes.getLength();
402*cdf0e10cSrcweir                                           ++m )
403*cdf0e10cSrcweir                                     {
404*cdf0e10cSrcweir                                         if ( match(eTypeClass, m_aTypes[ m ]) )
405*cdf0e10cSrcweir                                         {
406*cdf0e10cSrcweir                                             bIncludeIt = true;
407*cdf0e10cSrcweir                                             break;
408*cdf0e10cSrcweir                                         }
409*cdf0e10cSrcweir                                     }
410*cdf0e10cSrcweir                                 }
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir                                 if ( m_eDepth ==
413*cdf0e10cSrcweir                                         reflection::TypeDescriptionSearchDepth_INFINITE )
414*cdf0e10cSrcweir                                 {
415*cdf0e10cSrcweir                                     if ( eTypeClass == RT_TYPE_MODULE )
416*cdf0e10cSrcweir                                     {
417*cdf0e10cSrcweir                                         // Do not close xKey!
418*cdf0e10cSrcweir                                         aCloser.reset();
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir                                         // Remember new module key.
421*cdf0e10cSrcweir                                         m_aModuleKeys.push_back( xKey );
422*cdf0e10cSrcweir                                     }
423*cdf0e10cSrcweir                                 }
424*cdf0e10cSrcweir                             }
425*cdf0e10cSrcweir 
426*cdf0e10cSrcweir                             if ( bIncludeIt )
427*cdf0e10cSrcweir                             {
428*cdf0e10cSrcweir                                 // Do not close xKey!
429*cdf0e10cSrcweir                                 aCloser.reset();
430*cdf0e10cSrcweir 
431*cdf0e10cSrcweir                                 m_aCurrentModuleSubKeys.push_back( xKey );
432*cdf0e10cSrcweir                             }
433*cdf0e10cSrcweir                         }
434*cdf0e10cSrcweir                     }
435*cdf0e10cSrcweir                     else
436*cdf0e10cSrcweir                     {
437*cdf0e10cSrcweir                         OSL_ENSURE( sal_False,
438*cdf0e10cSrcweir                             "TypeDescriptionEnumerationImpl::queryMore "
439*cdf0e10cSrcweir                             "- Invalid registry key!" );
440*cdf0e10cSrcweir                     }
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir                 }
443*cdf0e10cSrcweir                 catch ( registry::InvalidRegistryException const & )
444*cdf0e10cSrcweir                 {
445*cdf0e10cSrcweir                     // getValueType, getBinaryValue
446*cdf0e10cSrcweir 
447*cdf0e10cSrcweir                     OSL_ENSURE( sal_False,
448*cdf0e10cSrcweir                                 "TypeDescriptionEnumerationImpl::queryMore "
449*cdf0e10cSrcweir                                 "- Caught InvalidRegistryException!" );
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir                     // Don't stop iterating!
452*cdf0e10cSrcweir                 }
453*cdf0e10cSrcweir             }
454*cdf0e10cSrcweir         }
455*cdf0e10cSrcweir         catch ( registry::InvalidRegistryException const & )
456*cdf0e10cSrcweir         {
457*cdf0e10cSrcweir             // openKeys
458*cdf0e10cSrcweir 
459*cdf0e10cSrcweir             for ( sal_Int32 n = 0; n < aKeys.getLength(); ++n )
460*cdf0e10cSrcweir             {
461*cdf0e10cSrcweir                 try
462*cdf0e10cSrcweir                 {
463*cdf0e10cSrcweir                     aKeys[ n ]->closeKey();
464*cdf0e10cSrcweir                 }
465*cdf0e10cSrcweir                 catch ( registry::InvalidRegistryException const & )
466*cdf0e10cSrcweir                 {
467*cdf0e10cSrcweir                     OSL_ENSURE( sal_False,
468*cdf0e10cSrcweir                                 "TypeDescriptionEnumerationImpl::queryMore "
469*cdf0e10cSrcweir                                 "- Caught InvalidRegistryException!" );
470*cdf0e10cSrcweir                 }
471*cdf0e10cSrcweir             }
472*cdf0e10cSrcweir         }
473*cdf0e10cSrcweir 
474*cdf0e10cSrcweir         /////////////////////////////////////////////////////////////////////
475*cdf0e10cSrcweir         // Special handling for constants contained directly in module.
476*cdf0e10cSrcweir         /////////////////////////////////////////////////////////////////////
477*cdf0e10cSrcweir 
478*cdf0e10cSrcweir         // Constants requested?
479*cdf0e10cSrcweir         bool bIncludeConstants = ( m_aTypes.getLength() == 0 );
480*cdf0e10cSrcweir         if ( !bIncludeConstants )
481*cdf0e10cSrcweir         {
482*cdf0e10cSrcweir             for ( sal_Int32 m = 0; m < m_aTypes.getLength(); ++m )
483*cdf0e10cSrcweir             {
484*cdf0e10cSrcweir                 if ( m_aTypes[ m ] == uno::TypeClass_CONSTANT )
485*cdf0e10cSrcweir                 {
486*cdf0e10cSrcweir                     bIncludeConstants = true;
487*cdf0e10cSrcweir                     break;
488*cdf0e10cSrcweir                 }
489*cdf0e10cSrcweir             }
490*cdf0e10cSrcweir 
491*cdf0e10cSrcweir         }
492*cdf0e10cSrcweir 
493*cdf0e10cSrcweir         if ( bIncludeConstants )
494*cdf0e10cSrcweir         {
495*cdf0e10cSrcweir             if ( m_aModuleKeys.front()->getValueType()
496*cdf0e10cSrcweir                     == registry::RegistryValueType_BINARY )
497*cdf0e10cSrcweir             {
498*cdf0e10cSrcweir                 try
499*cdf0e10cSrcweir                 {
500*cdf0e10cSrcweir                     uno::Sequence< sal_Int8 > aBytes(
501*cdf0e10cSrcweir                         m_aModuleKeys.front()->getBinaryValue() );
502*cdf0e10cSrcweir 
503*cdf0e10cSrcweir                     typereg::Reader aReader(
504*cdf0e10cSrcweir                         aBytes.getConstArray(), aBytes.getLength(), false,
505*cdf0e10cSrcweir                         TYPEREG_VERSION_1);
506*cdf0e10cSrcweir 
507*cdf0e10cSrcweir                     if ( aReader.getTypeClass() == RT_TYPE_MODULE )
508*cdf0e10cSrcweir                     {
509*cdf0e10cSrcweir                         sal_uInt16 nFields = aReader.getFieldCount();
510*cdf0e10cSrcweir                         while ( nFields-- )
511*cdf0e10cSrcweir                         {
512*cdf0e10cSrcweir                             rtl::OUStringBuffer aName(
513*cdf0e10cSrcweir                                 aReader.getTypeName().replace( '/', '.' ) );
514*cdf0e10cSrcweir                             aName.appendAscii( "." );
515*cdf0e10cSrcweir                             aName.append( aReader.getFieldName( nFields ) );
516*cdf0e10cSrcweir 
517*cdf0e10cSrcweir                             uno::Any aValue(
518*cdf0e10cSrcweir                                 getRTValue(
519*cdf0e10cSrcweir                                     aReader.getFieldValue( nFields ) ) );
520*cdf0e10cSrcweir 
521*cdf0e10cSrcweir                             m_aTypeDescs.push_back(
522*cdf0e10cSrcweir                                 new IndividualConstantTypeDescriptionImpl(
523*cdf0e10cSrcweir                                     aName.makeStringAndClear(), aValue,
524*cdf0e10cSrcweir                                     ( ( aReader.getFieldFlags( nFields )
525*cdf0e10cSrcweir                                         & RT_ACCESS_PUBLISHED )
526*cdf0e10cSrcweir                                       != 0 ) ) );
527*cdf0e10cSrcweir                         }
528*cdf0e10cSrcweir                     }
529*cdf0e10cSrcweir                 }
530*cdf0e10cSrcweir                 catch ( registry::InvalidRegistryException const & )
531*cdf0e10cSrcweir                 {
532*cdf0e10cSrcweir                     // getBinaryValue
533*cdf0e10cSrcweir 
534*cdf0e10cSrcweir                     OSL_ENSURE( sal_False,
535*cdf0e10cSrcweir                                 "TypeDescriptionEnumerationImpl::queryMore "
536*cdf0e10cSrcweir                                 "- Caught InvalidRegistryException!" );
537*cdf0e10cSrcweir                 }
538*cdf0e10cSrcweir             }
539*cdf0e10cSrcweir         }
540*cdf0e10cSrcweir 
541*cdf0e10cSrcweir         /////////////////////////////////////////////////////////////////////
542*cdf0e10cSrcweir 
543*cdf0e10cSrcweir /*
544*cdf0e10cSrcweir    @@@ m_aModuleKeys.front() may have open sub keys (may be contained in
545*cdf0e10cSrcweir        both m_aModuleKeys and m_aCurrentModuleSubKeys)!
546*cdf0e10cSrcweir 
547*cdf0e10cSrcweir         try
548*cdf0e10cSrcweir         {
549*cdf0e10cSrcweir            m_aModuleKeys.front()->closeKey();
550*cdf0e10cSrcweir         }
551*cdf0e10cSrcweir         catch ( registry::InvalidRegistryException const & )
552*cdf0e10cSrcweir         {
553*cdf0e10cSrcweir             OSL_ENSURE( sal_False,
554*cdf0e10cSrcweir                         "TypeDescriptionEnumerationImpl::queryMore "
555*cdf0e10cSrcweir                         "- Caught InvalidRegistryException!" );
556*cdf0e10cSrcweir         }
557*cdf0e10cSrcweir */
558*cdf0e10cSrcweir         // We're done with this module key, even if there were errors.
559*cdf0e10cSrcweir         m_aModuleKeys.pop_front();
560*cdf0e10cSrcweir     }
561*cdf0e10cSrcweir 
562*cdf0e10cSrcweir     // unreachable
563*cdf0e10cSrcweir }
564*cdf0e10cSrcweir 
565*cdf0e10cSrcweir //=========================================================================
566*cdf0e10cSrcweir uno::Reference< reflection::XTypeDescription >
567*cdf0e10cSrcweir TypeDescriptionEnumerationImpl::queryNext()
568*cdf0e10cSrcweir {
569*cdf0e10cSrcweir     osl::MutexGuard aGuard( m_aMutex );
570*cdf0e10cSrcweir 
571*cdf0e10cSrcweir     for (;;)
572*cdf0e10cSrcweir     {
573*cdf0e10cSrcweir         if ( !queryMore() )
574*cdf0e10cSrcweir             return uno::Reference< reflection::XTypeDescription >();
575*cdf0e10cSrcweir 
576*cdf0e10cSrcweir         uno::Reference< reflection::XTypeDescription > xTD;
577*cdf0e10cSrcweir 
578*cdf0e10cSrcweir         if ( !m_aTypeDescs.empty() )
579*cdf0e10cSrcweir         {
580*cdf0e10cSrcweir             xTD = m_aTypeDescs.front();
581*cdf0e10cSrcweir             m_aTypeDescs.pop_front();
582*cdf0e10cSrcweir             return xTD;
583*cdf0e10cSrcweir         }
584*cdf0e10cSrcweir 
585*cdf0e10cSrcweir         // Note: xKey is already opened.
586*cdf0e10cSrcweir         uno::Reference< registry::XRegistryKey >
587*cdf0e10cSrcweir             xKey( m_aCurrentModuleSubKeys.front() );
588*cdf0e10cSrcweir /*
589*cdf0e10cSrcweir    @@@ xKey may still be contained in m_aModuleKeys, too
590*cdf0e10cSrcweir 
591*cdf0e10cSrcweir         // closes key in it's dtor (which is
592*cdf0e10cSrcweir         // called even in case of exceptions).
593*cdf0e10cSrcweir         RegistryKeyCloser aCloser( xKey );
594*cdf0e10cSrcweir */
595*cdf0e10cSrcweir         try
596*cdf0e10cSrcweir         {
597*cdf0e10cSrcweir             {
598*cdf0e10cSrcweir                 if ( xKey->isValid() )
599*cdf0e10cSrcweir                 {
600*cdf0e10cSrcweir                     if ( xKey->getValueType()
601*cdf0e10cSrcweir                             == registry::RegistryValueType_BINARY )
602*cdf0e10cSrcweir                     {
603*cdf0e10cSrcweir                         uno::Sequence< sal_Int8 > aBytes(
604*cdf0e10cSrcweir                             xKey->getBinaryValue() );
605*cdf0e10cSrcweir 
606*cdf0e10cSrcweir                         xTD = createTypeDescription( aBytes,
607*cdf0e10cSrcweir                                                      m_xTDMgr,
608*cdf0e10cSrcweir                                                      false );
609*cdf0e10cSrcweir                         OSL_ENSURE( xTD.is(),
610*cdf0e10cSrcweir                             "TypeDescriptionEnumerationImpl::queryNext "
611*cdf0e10cSrcweir                             "- No XTypeDescription created!" );
612*cdf0e10cSrcweir                     }
613*cdf0e10cSrcweir                 }
614*cdf0e10cSrcweir                 else
615*cdf0e10cSrcweir                 {
616*cdf0e10cSrcweir                     OSL_ENSURE( sal_False,
617*cdf0e10cSrcweir                         "TypeDescriptionEnumerationImpl::queryNext "
618*cdf0e10cSrcweir                         "- Invalid registry key!" );
619*cdf0e10cSrcweir                 }
620*cdf0e10cSrcweir             }
621*cdf0e10cSrcweir         }
622*cdf0e10cSrcweir         catch ( registry::InvalidRegistryException const & )
623*cdf0e10cSrcweir         {
624*cdf0e10cSrcweir             // getValueType, getBinaryValue
625*cdf0e10cSrcweir 
626*cdf0e10cSrcweir             OSL_ENSURE( sal_False,
627*cdf0e10cSrcweir                         "TypeDescriptionEnumerationImpl::queryNext "
628*cdf0e10cSrcweir                         "- Caught InvalidRegistryException!" );
629*cdf0e10cSrcweir         }
630*cdf0e10cSrcweir 
631*cdf0e10cSrcweir         // We're done with this key, even if there were errors.
632*cdf0e10cSrcweir         m_aCurrentModuleSubKeys.pop_front();
633*cdf0e10cSrcweir 
634*cdf0e10cSrcweir         if ( xTD.is() )
635*cdf0e10cSrcweir             return xTD;
636*cdf0e10cSrcweir 
637*cdf0e10cSrcweir         // next try...
638*cdf0e10cSrcweir 
639*cdf0e10cSrcweir     } // for (;;)
640*cdf0e10cSrcweir }
641*cdf0e10cSrcweir 
642*cdf0e10cSrcweir } // namespace stoc_rdbtdp
643*cdf0e10cSrcweir 
644