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_SERVICES_CONTENTHANDLERFACTORY_HXX_
29 #define __FRAMEWORK_SERVICES_CONTENTHANDLERFACTORY_HXX_
30 
31 //_________________________________________________________________________________________________________________
32 //	my own includes
33 //_________________________________________________________________________________________________________________
34 
35 #include <classes/filtercache.hxx>
36 #include <macros/generic.hxx>
37 #include <macros/debug.hxx>
38 #include <macros/xinterface.hxx>
39 #include <macros/xtypeprovider.hxx>
40 #include <macros/xserviceinfo.hxx>
41 #include <threadhelp/threadhelpbase.hxx>
42 
43 #ifndef __FRAMEWORK_THREADHELP_TRANSACTIONBASE_HXX_
44 #include <threadhelp/transactionbase.hxx>
45 #endif
46 #include <general.h>
47 
48 //_________________________________________________________________________________________________________________
49 //	interface includes
50 //_________________________________________________________________________________________________________________
51 #include <com/sun/star/beans/PropertyValue.hpp>
52 #include <com/sun/star/lang/XInitialization.hpp>
53 #include <com/sun/star/lang/WrappedTargetException.hpp>
54 #include <com/sun/star/lang/IllegalArgumentException.hpp>
55 #include <com/sun/star/container/ElementExistException.hpp>
56 #include <com/sun/star/container/NoSuchElementException.hpp>
57 #include <com/sun/star/container/XNameContainer.hpp>
58 #include <com/sun/star/container/NoSuchElementException.hpp>
59 #include <com/sun/star/io/XInputStream.hpp>
60 #include <com/sun/star/util/XFlushable.hpp>
61 
62 //_________________________________________________________________________________________________________________
63 //	other includes
64 //_________________________________________________________________________________________________________________
65 #include <cppuhelper/interfacecontainer.hxx>
66 #include <cppuhelper/weak.hxx>
67 
68 //_________________________________________________________________________________________________________________
69 //	namespace
70 //_________________________________________________________________________________________________________________
71 
72 namespace framework{
73 
74 //_________________________________________________________________________________________________________________
75 //	exported const
76 //_________________________________________________________________________________________________________________
77 
78 //_________________________________________________________________________________________________________________
79 //	exported definitions
80 //_________________________________________________________________________________________________________________
81 
82 /*-************************************************************************************************************//**
83     @short      factory to create handler-objects
84     @descr      These class can be used to create new handler for specified contents.
85                 We use cached values of our configuration to lay down, which handler match
86                 a given URL or handlername. (use service TypeDetection to do that)
87                 With a detected type name you can search a registered handler and create it with these factory.
88 
89 	@implements	XInterface
90 				XTypeProvider
91 				XServiceInfo
92 				XMultiServiceFactory
93 				XNameContainer
94 				XNameReplace
95 				XNameAccess
96 				XElementAccess
97 				XFlushable
98 
99     @base       ThreadHelpBase
100 				OWeakObject
101 
102 	@devstatus	ready to use
103 	@threadsafe	yes
104 *//*-*************************************************************************************************************/
105 
106 class ContentHandlerFactory :   // interfaces
107 						public	css::lang::XTypeProvider			,
108 						public	css::lang::XServiceInfo				,
109 						public	css::lang::XMultiServiceFactory		,
110 						public	css::container::XNameContainer		,		// => XNameReplace => XNameAccess => XElementAccess
111 						public	css::util::XFlushable				,
112 						// base classes
113 						// Order is neccessary for right initialization of it!
114                         private ThreadHelpBase                      ,
115                         private TransactionBase                     ,
116 						public	::cppu::OWeakObject
117 {
118 	//-------------------------------------------------------------------------------------------------------------
119 	//	public methods
120 	//-------------------------------------------------------------------------------------------------------------
121 
122 	public:
123 
124 		//---------------------------------------------------------------------------------------------------------
125 		//	constructor / destructor
126 		//---------------------------------------------------------------------------------------------------------
127                  ContentHandlerFactory( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory );
128         virtual ~ContentHandlerFactory(                                                                        );
129 
130 		//---------------------------------------------------------------------------------------------------------
131 		//	XInterface, XTypeProvider, XServiceInfo
132 		//---------------------------------------------------------------------------------------------------------
133 		DECLARE_XINTERFACE
134 		DECLARE_XTYPEPROVIDER
135 		DECLARE_XSERVICEINFO
136 
137 		//---------------------------------------------------------------------------------------------------------
138 		//	XMultiServiceFactory
139 		//---------------------------------------------------------------------------------------------------------
140         virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance             ( const ::rtl::OUString&                        sTypeName   ) throw( css::uno::Exception        ,
141                                                                                                                                                                      css::uno::RuntimeException );
142         virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithArguments( const ::rtl::OUString&                        sTypeName   ,
143                                                                                                   const css::uno::Sequence< css::uno::Any >&    lArguments  ) throw( css::uno::Exception, css::uno::RuntimeException );
144         virtual css::uno::Sequence< ::rtl::OUString >       SAL_CALL getAvailableServiceNames   (                                                           ) throw( css::uno::RuntimeException );
145 
146 		//---------------------------------------------------------------------------------------------------------
147 		//	XNameContainer
148 		//---------------------------------------------------------------------------------------------------------
149         virtual void SAL_CALL insertByName( const ::rtl::OUString&  sHandlerName        ,
150                                             const css::uno::Any&    aHandlerProperties  ) throw( css::lang::IllegalArgumentException     ,
151                                                                                                  css::container::ElementExistException   ,
152                                                                                                  css::lang::WrappedTargetException       ,
153                                                                                                  css::uno::RuntimeException              );
154         virtual void SAL_CALL removeByName( const ::rtl::OUString&  sHandlerName        ) throw( css::container::NoSuchElementException  ,
155                                                                                                  css::lang::WrappedTargetException       ,
156                                                                                                  css::uno::RuntimeException              );
157 
158 		//---------------------------------------------------------------------------------------------------------
159 		//	XNameReplace
160 		//---------------------------------------------------------------------------------------------------------
161         virtual void SAL_CALL replaceByName( const ::rtl::OUString& sHandlerName       ,
162                                              const css::uno::Any&   aHandlerProperties ) throw( css::lang::IllegalArgumentException    ,
163                                                                                                 css::container::NoSuchElementException ,
164                                                                                                 css::lang::WrappedTargetException      ,
165                                                                                                 css::uno::RuntimeException             );
166 
167 		//---------------------------------------------------------------------------------------------------------
168 		//	XNameAccess
169 		//---------------------------------------------------------------------------------------------------------
170         virtual css::uno::Any                         SAL_CALL getByName      ( const ::rtl::OUString& sName ) throw( css::container::NoSuchElementException ,
171                                                                                                                       css::lang::WrappedTargetException      ,
172                                                                                                                       css::uno::RuntimeException             );
173         virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames(                              ) throw( css::uno::RuntimeException             );
174         virtual sal_Bool                              SAL_CALL hasByName      ( const ::rtl::OUString& sName ) throw( css::uno::RuntimeException             );
175 
176 		//---------------------------------------------------------------------------------------------------------
177 		//	XElementAccess
178 		//---------------------------------------------------------------------------------------------------------
179         virtual css::uno::Type SAL_CALL getElementType() throw( css::uno::RuntimeException );
180         virtual sal_Bool       SAL_CALL hasElements   () throw( css::uno::RuntimeException );
181 
182 		//---------------------------------------------------------------------------------------------------------
183 		//	XFlushable
184 		//---------------------------------------------------------------------------------------------------------
185         virtual void SAL_CALL flush              (                                                                   ) throw ( css::uno::RuntimeException );
186         virtual void SAL_CALL addFlushListener   ( const css::uno::Reference< css::util::XFlushListener >& xListener ) throw ( css::uno::RuntimeException );
187     	virtual void SAL_CALL removeFlushListener( const css::uno::Reference< css::util::XFlushListener >& xListener ) throw ( css::uno::RuntimeException );
188 
189 	//-------------------------------------------------------------------------------------------------------------
190 	//	protected methods
191 	//-------------------------------------------------------------------------------------------------------------
192 
193 	protected:
194 
195 	//-------------------------------------------------------------------------------------------------------------
196 	//	debug methods
197 	//	(should be private everyway!)
198 	//-------------------------------------------------------------------------------------------------------------
199 
200 		/*-****************************************************************************************************//**
201 			@short		debug-method to check incoming parameter of some other mehods of this class
202 			@descr		The following methods are used to check parameters for other methods
203 						of this class. The return value is used directly for an ASSERT(...).
204 
205 			@seealso	ASSERTs in implementation!
206 
207 			@param		references to checking variables
208 			@return		sal_False ,on invalid parameter
209 			@return		sal_True  ,otherwise
210 
211 			@onerror	-
212 		*//*-*****************************************************************************************************/
213 
214 	#ifdef ENABLE_ASSERTIONS
215 
216 	private:
217 
218         static sal_Bool implcp_ContentHandlerFactory        (   const   css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory            );
219     	static sal_Bool implcp_createInstanceWithArguments	(	const	::rtl::OUString&										sTypeName			,
220 							  									const	css::uno::Sequence< css::uno::Any >&					lArguments			);
221     	static sal_Bool implcp_getByName					(	const	::rtl::OUString&										sName				);
222     	static sal_Bool implcp_hasByName					(	const	::rtl::OUString&										sName				);
223         static sal_Bool implcp_removeByName                 (   const   ::rtl::OUString&                                        sHandlerName        );
224 
225 	#endif	//	#ifdef ENABLE_ASSERTIONS
226 
227 	//-------------------------------------------------------------------------------------------------------------
228 	//	private variables
229 	//	(should be private everyway!)
230 	//-------------------------------------------------------------------------------------------------------------
231 
232 	private:
233 
234 		css::uno::Reference< css::lang::XMultiServiceFactory >		m_xFactory				;
235         FilterCache                                                 m_aCache                ;
236 //		::cppu::OMultiTypeInterfaceContainerHelper					m_aListenerContainer	;
237 
238 };      //  class ContentHandlerFactory
239 
240 }		//	namespace framework
241 
242 #endif  //  #ifndef __FRAMEWORK_SERVICES_CONTENTHANDLERFACTORY_HXX_
243