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