1*647a425cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*647a425cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*647a425cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*647a425cSAndrew Rist  * distributed with this work for additional information
6*647a425cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*647a425cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*647a425cSAndrew Rist  * "License"); you may not use this file except in compliance
9*647a425cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*647a425cSAndrew Rist  *
11*647a425cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*647a425cSAndrew Rist  *
13*647a425cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*647a425cSAndrew Rist  * software distributed under the License is distributed on an
15*647a425cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*647a425cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*647a425cSAndrew Rist  * specific language governing permissions and limitations
18*647a425cSAndrew Rist  * under the License.
19*647a425cSAndrew Rist  *
20*647a425cSAndrew Rist  *************************************************************/
21*647a425cSAndrew Rist 
22*647a425cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_stoc.hxx"
26cdf0e10cSrcweir #include <osl/diagnose.h>
27cdf0e10cSrcweir #include "tdmgr_common.hxx"
28cdf0e10cSrcweir #include "tdmgr_tdenumeration.hxx"
29cdf0e10cSrcweir 
30cdf0e10cSrcweir using namespace com::sun::star;
31cdf0e10cSrcweir 
32cdf0e10cSrcweir extern rtl_StandardModuleCount g_moduleCount;
33cdf0e10cSrcweir 
34cdf0e10cSrcweir namespace stoc_tdmgr
35cdf0e10cSrcweir {
36cdf0e10cSrcweir 
37cdf0e10cSrcweir //=========================================================================
38cdf0e10cSrcweir //=========================================================================
39cdf0e10cSrcweir //
40cdf0e10cSrcweir // TypeDescriptionEnumerationImpl Implementation.
41cdf0e10cSrcweir //
42cdf0e10cSrcweir //=========================================================================
43cdf0e10cSrcweir //=========================================================================
44cdf0e10cSrcweir 
TypeDescriptionEnumerationImpl(const rtl::OUString & rModuleName,const com::sun::star::uno::Sequence<com::sun::star::uno::TypeClass> & rTypes,com::sun::star::reflection::TypeDescriptionSearchDepth eDepth,const TDEnumerationAccessStack & rTDEAS)45cdf0e10cSrcweir TypeDescriptionEnumerationImpl::TypeDescriptionEnumerationImpl(
46cdf0e10cSrcweir         const rtl::OUString & rModuleName,
47cdf0e10cSrcweir         const com::sun::star::uno::Sequence<
48cdf0e10cSrcweir             com::sun::star::uno::TypeClass > & rTypes,
49cdf0e10cSrcweir         com::sun::star::reflection::TypeDescriptionSearchDepth eDepth,
50cdf0e10cSrcweir         const TDEnumerationAccessStack & rTDEAS )
51cdf0e10cSrcweir : m_aModuleName( rModuleName ),
52cdf0e10cSrcweir   m_aTypes( rTypes ),
53cdf0e10cSrcweir   m_eDepth( eDepth ),
54cdf0e10cSrcweir   m_aChildren( rTDEAS )
55cdf0e10cSrcweir {
56cdf0e10cSrcweir     ::g_moduleCount.modCnt.acquire( &::g_moduleCount.modCnt );
57cdf0e10cSrcweir }
58cdf0e10cSrcweir 
59cdf0e10cSrcweir //=========================================================================
60cdf0e10cSrcweir // virtual
~TypeDescriptionEnumerationImpl()61cdf0e10cSrcweir TypeDescriptionEnumerationImpl::~TypeDescriptionEnumerationImpl()
62cdf0e10cSrcweir {
63cdf0e10cSrcweir     ::g_moduleCount.modCnt.release( &::g_moduleCount.modCnt );
64cdf0e10cSrcweir }
65cdf0e10cSrcweir 
66cdf0e10cSrcweir //=========================================================================
67cdf0e10cSrcweir //
68cdf0e10cSrcweir // XEnumeration (base of XTypeDescriptionEnumeration) methods
69cdf0e10cSrcweir //
70cdf0e10cSrcweir //=========================================================================
71cdf0e10cSrcweir 
72cdf0e10cSrcweir // virtual
hasMoreElements()73cdf0e10cSrcweir sal_Bool SAL_CALL TypeDescriptionEnumerationImpl::hasMoreElements()
74cdf0e10cSrcweir     throw ( uno::RuntimeException )
75cdf0e10cSrcweir {
76cdf0e10cSrcweir     uno::Reference< reflection::XTypeDescriptionEnumeration > xEnum
77cdf0e10cSrcweir         = queryCurrentChildEnumeration();
78cdf0e10cSrcweir     if ( xEnum.is() )
79cdf0e10cSrcweir         return xEnum->hasMoreElements();
80cdf0e10cSrcweir 
81cdf0e10cSrcweir     return sal_False;
82cdf0e10cSrcweir }
83cdf0e10cSrcweir 
84cdf0e10cSrcweir //=========================================================================
85cdf0e10cSrcweir // virtual
nextElement()86cdf0e10cSrcweir uno::Any SAL_CALL TypeDescriptionEnumerationImpl::nextElement()
87cdf0e10cSrcweir     throw ( container::NoSuchElementException,
88cdf0e10cSrcweir             lang::WrappedTargetException,
89cdf0e10cSrcweir             uno::RuntimeException )
90cdf0e10cSrcweir {
91cdf0e10cSrcweir     uno::Reference< reflection::XTypeDescriptionEnumeration > xEnum
92cdf0e10cSrcweir         = queryCurrentChildEnumeration();
93cdf0e10cSrcweir     if ( xEnum.is() )
94cdf0e10cSrcweir         return xEnum->nextElement();
95cdf0e10cSrcweir 
96cdf0e10cSrcweir     throw container::NoSuchElementException(
97cdf0e10cSrcweir         rtl::OUString::createFromAscii(
98cdf0e10cSrcweir             "No further elements in enumeration!" ),
99cdf0e10cSrcweir         static_cast< cppu::OWeakObject * >( this  ) );
100cdf0e10cSrcweir }
101cdf0e10cSrcweir 
102cdf0e10cSrcweir //=========================================================================
103cdf0e10cSrcweir //
104cdf0e10cSrcweir // XTypeDescriptionEnumeration methods
105cdf0e10cSrcweir //
106cdf0e10cSrcweir //=========================================================================
107cdf0e10cSrcweir 
108cdf0e10cSrcweir // virtual
109cdf0e10cSrcweir uno::Reference< reflection::XTypeDescription > SAL_CALL
nextTypeDescription()110cdf0e10cSrcweir TypeDescriptionEnumerationImpl::nextTypeDescription()
111cdf0e10cSrcweir     throw ( container::NoSuchElementException,
112cdf0e10cSrcweir             uno::RuntimeException )
113cdf0e10cSrcweir {
114cdf0e10cSrcweir     uno::Reference< reflection::XTypeDescriptionEnumeration > xEnum
115cdf0e10cSrcweir         = queryCurrentChildEnumeration();
116cdf0e10cSrcweir     if ( xEnum.is() )
117cdf0e10cSrcweir         return xEnum->nextTypeDescription();
118cdf0e10cSrcweir 
119cdf0e10cSrcweir     throw container::NoSuchElementException(
120cdf0e10cSrcweir         rtl::OUString::createFromAscii(
121cdf0e10cSrcweir             "No further elements in enumeration!" ),
122cdf0e10cSrcweir         static_cast< cppu::OWeakObject * >( this  ) );
123cdf0e10cSrcweir }
124cdf0e10cSrcweir 
125cdf0e10cSrcweir //=========================================================================
126cdf0e10cSrcweir uno::Reference< reflection::XTypeDescriptionEnumeration >
queryCurrentChildEnumeration()127cdf0e10cSrcweir TypeDescriptionEnumerationImpl::queryCurrentChildEnumeration()
128cdf0e10cSrcweir {
129cdf0e10cSrcweir     osl::MutexGuard aGuard( m_aMutex );
130cdf0e10cSrcweir 
131cdf0e10cSrcweir     for (;;)
132cdf0e10cSrcweir     {
133cdf0e10cSrcweir         if ( m_xEnum.is() )
134cdf0e10cSrcweir         {
135cdf0e10cSrcweir             if ( m_xEnum->hasMoreElements() )
136cdf0e10cSrcweir             {
137cdf0e10cSrcweir                 return m_xEnum;
138cdf0e10cSrcweir             }
139cdf0e10cSrcweir             else
140cdf0e10cSrcweir             {
141cdf0e10cSrcweir                 // Forget about enumeration without further elements. Try next.
142cdf0e10cSrcweir                 m_xEnum.clear();
143cdf0e10cSrcweir             }
144cdf0e10cSrcweir         }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir         // Note: m_xEnum is always null here.
147cdf0e10cSrcweir 
148cdf0e10cSrcweir         if ( m_aChildren.empty() )
149cdf0e10cSrcweir         {
150cdf0e10cSrcweir             // No child enumerations left.
151cdf0e10cSrcweir             return m_xEnum;
152cdf0e10cSrcweir         }
153cdf0e10cSrcweir 
154cdf0e10cSrcweir         try
155cdf0e10cSrcweir         {
156cdf0e10cSrcweir             m_xEnum =
157cdf0e10cSrcweir                 m_aChildren.top()->createTypeDescriptionEnumeration(
158cdf0e10cSrcweir                     m_aModuleName, m_aTypes, m_eDepth );
159cdf0e10cSrcweir         }
160cdf0e10cSrcweir         catch ( reflection::NoSuchTypeNameException const & )
161cdf0e10cSrcweir         {
162cdf0e10cSrcweir             OSL_ENSURE( sal_False,
163cdf0e10cSrcweir                "TypeDescriptionEnumerationImpl::queryCurrentChildEnumeration "
164cdf0e10cSrcweir                "- Caught NoSuchTypeNameException!" );
165cdf0e10cSrcweir         }
166cdf0e10cSrcweir         catch ( reflection::InvalidTypeNameException const & )
167cdf0e10cSrcweir         {
168cdf0e10cSrcweir             OSL_ENSURE( sal_False,
169cdf0e10cSrcweir                "TypeDescriptionEnumerationImpl::queryCurrentChildEnumeration "
170cdf0e10cSrcweir                "- Caught InvalidTypeNameException!" );
171cdf0e10cSrcweir         }
172cdf0e10cSrcweir 
173cdf0e10cSrcweir         // We're done with this enumeration access in any case (Either
174cdf0e10cSrcweir         // enumeration was successfully created or creation failed for some
175cdf0e10cSrcweir         // reason).
176cdf0e10cSrcweir         m_aChildren.pop();
177cdf0e10cSrcweir     }
178cdf0e10cSrcweir 
179cdf0e10cSrcweir     // unreachable
180cdf0e10cSrcweir }
181cdf0e10cSrcweir 
182cdf0e10cSrcweir } // namespace stoc_tdmgr
183cdf0e10cSrcweir 
184