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