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 #ifndef __FRAMEWORK_HELPER_OCOMPONENTENUMERATION_HXX_
25 #define __FRAMEWORK_HELPER_OCOMPONENTENUMERATION_HXX_
26 
27 //_________________________________________________________________________________________________________________
28 //	my own includes
29 //_________________________________________________________________________________________________________________
30 
31 #ifndef __FRAMEWORK_OMUTEXMEMBER_HXX_
32 #include <threadhelp/threadhelpbase.hxx>
33 #endif
34 #include <macros/generic.hxx>
35 #include <macros/xinterface.hxx>
36 #include <macros/xtypeprovider.hxx>
37 #include <macros/debug.hxx>
38 #include <general.h>
39 
40 //_________________________________________________________________________________________________________________
41 //	interface includes
42 //_________________________________________________________________________________________________________________
43 #include <com/sun/star/lang/XEventListener.hpp>
44 #include <com/sun/star/container/XEnumeration.hpp>
45 #include <com/sun/star/lang/XComponent.hpp>
46 
47 //_________________________________________________________________________________________________________________
48 //	other includes
49 //_________________________________________________________________________________________________________________
50 #include <cppuhelper/implbase2.hxx>
51 
52 //_________________________________________________________________________________________________________________
53 //	namespace
54 //_________________________________________________________________________________________________________________
55 
56 namespace framework{
57 
58 //_________________________________________________________________________________________________________________
59 //	exported const
60 //_________________________________________________________________________________________________________________
61 
62 //_________________________________________________________________________________________________________________
63 //	exported definitions
64 //_________________________________________________________________________________________________________________
65 
66 /*-************************************************************************************************************//**
67 	@short			implement a helper for a oneway enumeration of components
68 	@descr			You can step during this list only for one time! Its a snapshot.
69 					Don't forget to release the reference. You are the owner of an instance of this implementation.
70 					You cant use this as a baseclass. Please use it as a dynamical object for return.
71 
72 	@implements		XInterface
73 					XTypeProvider
74 					XEventListener
75 					XEnumeration
76 
77 	@base			ThreadHelpBase
78 					OWeakObject
79 
80 	@devstatus		ready to use
81 	@threadsafe		yes
82 *//*-*************************************************************************************************************/
83 
84 class OComponentEnumeration	:	public ThreadHelpBase               ,
85 								public ::cppu::WeakImplHelper2< ::com::sun::star::container::XEnumeration,::com::sun::star::lang::XEventListener >
86 {
87 	//-------------------------------------------------------------------------------------------------------------
88 	//	public methods
89 	//-------------------------------------------------------------------------------------------------------------
90 
91 	public:
92 
93 		//---------------------------------------------------------------------------------------------------------
94 		//	constructor / destructor
95 		//---------------------------------------------------------------------------------------------------------
96 
97 		/*-****************************************************************************************************//**
98 			@short		constructor to initialize this enumeration
99 			@descr		An enumeration is a list with oneway-access! You can get every member only for one time.
100 						This method allow to initialize this oneway list with values.
101 
102 			@seealso	-
103 
104 			@param		"seqComponents" is a sequence of interfaces, which are components.
105 			@return		-
106 
107 			@onerror	Do nothing and reset this object to default with an empty list.
108 		*//*-*****************************************************************************************************/
109 
110 	 	OComponentEnumeration( const css::uno::Sequence< css::uno::Reference< css::lang::XComponent > >& seqComponents );
111 
112 		//---------------------------------------------------------------------------------------------------------
113 		//	XEventListener
114 		//---------------------------------------------------------------------------------------------------------
115 
116 		/*-****************************************************************************************************//**
117 			@short		last chance to release all references and free memory
118 			@descr		This method is called, if the enumeration is used completly and has no more elements.
119 						Then we must destroy ouer list and release all references to other objects.
120 
121 			@seealso	interface XEventListener
122 
123 			@param		"aEvent" describe the source of this event.
124 			@return		-
125 
126 			@onerror	-
127 		*//*-*****************************************************************************************************/
128 
129 		virtual void SAL_CALL disposing( const css::lang::EventObject& aEvent ) throw( css::uno::RuntimeException );
130 
131 		//---------------------------------------------------------------------------------------------------------
132 		//	XEnumeration
133 		//---------------------------------------------------------------------------------------------------------
134 
135 		/*-****************************************************************************************************//**
136 			@short		check count of accessible elements of enumeration
137 			@descr		You can call this method to get information about accessible elements in future.
138 						Elements you have already getted are not accessible!
139 
140 			@seealso	interface XEnumeration
141 
142 			@param		-
143 			@return		sal_True  = if more elements accessible<BR>
144 						sal_False = other way
145 
146 			@onerror	sal_False<BR>
147 						(List is emtpy and there no accessible elements ...)
148 		*//*-*****************************************************************************************************/
149 
150     	virtual sal_Bool SAL_CALL hasMoreElements() throw( css::uno::RuntimeException );
151 
152 		/*-****************************************************************************************************//**
153 			@short		give the next element, if some exist
154 			@descr		If a call "hasMoreElements()" return true, you can get the next element of list.
155 
156 			@seealso	interface XEnumeration
157 
158 			@param		-
159 			@return		A Reference to a component, safed in an Any-structure.
160 
161 			@onerror	If end of enumeration is arrived or there are no elements in list => a NoSuchElementException is thrown.
162 		*//*-*****************************************************************************************************/
163 
164     	virtual css::uno::Any SAL_CALL nextElement() throw(	css::container::NoSuchElementException	,
165 							 								css::lang::WrappedTargetException		,
166 															css::uno::RuntimeException				);
167 
168 	//-------------------------------------------------------------------------------------------------------------
169 	//	protected methods
170 	//-------------------------------------------------------------------------------------------------------------
171 
172 	protected:
173 
174 		/*-****************************************************************************************************//**
175 			@short		standard destructor
176 			@descr		This method destruct an instance of this class and clear some member.
177 						We make it protected, because its not supported to use this class as normal instance!
178 						You must create it dynamical in memory and use a pointer.
179 
180 			@seealso	-
181 
182 			@param		-
183 			@return		-
184 
185 			@onerror	-
186 		*//*-*****************************************************************************************************/
187 
188 		virtual	~OComponentEnumeration();
189 
190 		/*-****************************************************************************************************//**
191 			@short		reset instance to default values
192 
193 			@descr		There are two ways to delete an instance of this class.<BR>
194 						1) delete with destructor<BR>
195 						2) dispose from parent or factory ore ...<BR>
196 						This method do the same for both ways! It free used memory and release references ...
197 
198 			@seealso	method dispose()
199 			@seealso	destructor ~TaskEnumeration()
200 
201 			@param		-
202 
203 			@return		-
204 
205 			@onerror	-
206 		*//*-*****************************************************************************************************/
207 
208 		virtual void impl_resetObject();
209 
210 	//-------------------------------------------------------------------------------------------------------------
211 	//	private methods
212 	//-------------------------------------------------------------------------------------------------------------
213 
214 	private:
215 
216 	//-------------------------------------------------------------------------------------------------------------
217 	//	debug methods
218 	//	(should be private everyway!)
219 	//-------------------------------------------------------------------------------------------------------------
220 
221 		/*-****************************************************************************************************//**
222 			@short		debug-method to check incoming parameter of some other mehods of this class
223 			@descr		The following methods are used to check parameters for other methods
224 						of this class. The return value is used directly for an ASSERT(...).
225 
226 			@seealso	ASSERT in implementation!
227 
228 			@param		references to checking variables
229 			@return		sal_False on invalid parameter<BR>
230 						sal_True  otherway
231 
232 			@onerror	-
233 		*//*-*****************************************************************************************************/
234 
235 	#ifdef ENABLE_ASSERTIONS
236 
237 	private:
238 
239 		static sal_Bool impldbg_checkParameter_OComponentEnumerationCtor	(	const	css::uno::Sequence< css::uno::Reference< css::lang::XComponent > >&	seqComponents	);
240 		static sal_Bool impldbg_checkParameter_disposing					(	const	css::lang::EventObject&			   									aEvent			);
241 
242 	#endif	// #ifdef ENABLE_ASSERTIONS
243 
244 	//-------------------------------------------------------------------------------------------------------------
245 	//	variables
246 	//	(should be private everyway!)
247 	//-------------------------------------------------------------------------------------------------------------
248 
249 	private:
250 
251 		sal_uInt32																m_nPosition			;	/// current position in enumeration
252 		css::uno::Sequence< css::uno::Reference< css::lang::XComponent > >		m_seqComponents		;	/// list of current components
253 
254 };		//	class OComponentEnumeration
255 
256 }		//	namespace framework
257 
258 #endif	//	#ifndef __FRAMEWORK_HELPER_OCOMPONENTENUMERATION_HXX_
259