Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #include <osl/diagnose.h>
21 : : #include "tdmgr_common.hxx"
22 : : #include "tdmgr_tdenumeration.hxx"
23 : :
24 : : using namespace com::sun::star;
25 : :
26 : : extern rtl_StandardModuleCount g_moduleCount;
27 : :
28 : : namespace stoc_tdmgr
29 : : {
30 : :
31 : : //=========================================================================
32 : : //=========================================================================
33 : : //
34 : : // TypeDescriptionEnumerationImpl Implementation.
35 : : //
36 : : //=========================================================================
37 : : //=========================================================================
38 : :
39 : 7 : TypeDescriptionEnumerationImpl::TypeDescriptionEnumerationImpl(
40 : : const rtl::OUString & rModuleName,
41 : : const com::sun::star::uno::Sequence<
42 : : com::sun::star::uno::TypeClass > & rTypes,
43 : : com::sun::star::reflection::TypeDescriptionSearchDepth eDepth,
44 : : const TDEnumerationAccessStack & rTDEAS )
45 : : : m_aModuleName( rModuleName ),
46 : : m_aTypes( rTypes ),
47 : : m_eDepth( eDepth ),
48 [ + - ][ + - ]: 7 : m_aChildren( rTDEAS )
[ + - ]
49 : : {
50 [ + - ]: 7 : ::g_moduleCount.modCnt.acquire( &::g_moduleCount.modCnt );
51 : 7 : }
52 : :
53 : : //=========================================================================
54 : : // virtual
55 [ + - ][ + - ]: 7 : TypeDescriptionEnumerationImpl::~TypeDescriptionEnumerationImpl()
56 : : {
57 [ + - ]: 7 : ::g_moduleCount.modCnt.release( &::g_moduleCount.modCnt );
58 [ - + ]: 14 : }
59 : :
60 : : //=========================================================================
61 : : //
62 : : // XEnumeration (base of XTypeDescriptionEnumeration) methods
63 : : //
64 : : //=========================================================================
65 : :
66 : : // virtual
67 : 1659 : sal_Bool SAL_CALL TypeDescriptionEnumerationImpl::hasMoreElements()
68 : : throw ( uno::RuntimeException )
69 : : {
70 : : uno::Reference< reflection::XTypeDescriptionEnumeration > xEnum
71 [ + - ]: 1659 : = queryCurrentChildEnumeration();
72 [ + + ]: 1659 : if ( xEnum.is() )
73 [ + - ][ + - ]: 1652 : return xEnum->hasMoreElements();
74 : :
75 : 1659 : return sal_False;
76 : : }
77 : :
78 : : //=========================================================================
79 : : // virtual
80 : 1652 : uno::Any SAL_CALL TypeDescriptionEnumerationImpl::nextElement()
81 : : throw ( container::NoSuchElementException,
82 : : lang::WrappedTargetException,
83 : : uno::RuntimeException )
84 : : {
85 : : uno::Reference< reflection::XTypeDescriptionEnumeration > xEnum
86 [ + - ]: 1652 : = queryCurrentChildEnumeration();
87 [ + - ]: 1652 : if ( xEnum.is() )
88 [ + - ][ + - ]: 3304 : return xEnum->nextElement();
89 : :
90 : : throw container::NoSuchElementException(
91 : : rtl::OUString(
92 : : RTL_CONSTASCII_USTRINGPARAM("No further elements in enumeration!") ),
93 [ # # ][ # # ]: 1652 : static_cast< cppu::OWeakObject * >( this ) );
[ # # ]
94 : : }
95 : :
96 : : //=========================================================================
97 : : //
98 : : // XTypeDescriptionEnumeration methods
99 : : //
100 : : //=========================================================================
101 : :
102 : : // virtual
103 : : uno::Reference< reflection::XTypeDescription > SAL_CALL
104 : 0 : TypeDescriptionEnumerationImpl::nextTypeDescription()
105 : : throw ( container::NoSuchElementException,
106 : : uno::RuntimeException )
107 : : {
108 : : uno::Reference< reflection::XTypeDescriptionEnumeration > xEnum
109 [ # # ]: 0 : = queryCurrentChildEnumeration();
110 [ # # ]: 0 : if ( xEnum.is() )
111 [ # # ][ # # ]: 0 : return xEnum->nextTypeDescription();
112 : :
113 : : throw container::NoSuchElementException(
114 : : rtl::OUString(
115 : : RTL_CONSTASCII_USTRINGPARAM("No further elements in enumeration!") ),
116 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >( this ) );
[ # # ]
117 : : }
118 : :
119 : : //=========================================================================
120 : : uno::Reference< reflection::XTypeDescriptionEnumeration >
121 : 3311 : TypeDescriptionEnumerationImpl::queryCurrentChildEnumeration()
122 : : {
123 [ + - ]: 3311 : osl::MutexGuard aGuard( m_aMutex );
124 : :
125 : 7 : for (;;)
126 : : {
127 [ + + ]: 3318 : if ( m_xEnum.is() )
128 : : {
129 [ + - ][ + - ]: 3306 : if ( m_xEnum->hasMoreElements() )
[ + + ]
130 : : {
131 : 3304 : return m_xEnum;
132 : : }
133 : : else
134 : : {
135 : : // Forget about enumeration without further elements. Try next.
136 : 2 : m_xEnum.clear();
137 : : }
138 : : }
139 : :
140 : : // Note: m_xEnum is always null here.
141 : :
142 [ + + ]: 14 : if ( m_aChildren.empty() )
143 : : {
144 : : // No child enumerations left.
145 : 7 : return m_xEnum;
146 : : }
147 : :
148 : : try
149 : : {
150 : : m_xEnum =
151 [ + - ][ + - ]: 7 : m_aChildren.top()->createTypeDescriptionEnumeration(
152 [ + + ][ + - ]: 7 : m_aModuleName, m_aTypes, m_eDepth );
[ - + - ]
153 : : }
154 [ + - ]: 5 : catch ( reflection::NoSuchTypeNameException const & )
155 : : {
156 : : OSL_FAIL( "TypeDescriptionEnumerationImpl::queryCurrentChildEnumeration "
157 : : "- Caught NoSuchTypeNameException!" );
158 : : }
159 [ # # ]: 0 : catch ( reflection::InvalidTypeNameException const & )
160 : : {
161 : : OSL_FAIL( "TypeDescriptionEnumerationImpl::queryCurrentChildEnumeration "
162 : : "- Caught InvalidTypeNameException!" );
163 : : }
164 : :
165 : : // We're done with this enumeration access in any case (Either
166 : : // enumeration was successfully created or creation failed for some
167 : : // reason).
168 [ + - ]: 7 : m_aChildren.pop();
169 [ + - ]: 3311 : }
170 : :
171 : : // unreachable
172 : : }
173 : :
174 : : } // namespace stoc_tdmgr
175 : :
176 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|