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