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_DETECTORFACTORY_HXX_
29 #define __FRAMEWORK_SERVICES_DETECTORFACTORY_HXX_
30 
31 //_______________________________________________
32 // includes of own project
33 
34 #include <classes/filtercache.hxx>
35 #include <threadhelp/threadhelpbase.hxx>
36 #include <macros/xinterface.hxx>
37 #include <macros/xtypeprovider.hxx>
38 #include <macros/xserviceinfo.hxx>
39 #include <macros/generic.hxx>
40 #include <macros/debug.hxx>
41 #include <general.h>
42 
43 //_______________________________________________
44 // includes of interfaces
45 #include <com/sun/star/beans/PropertyValue.hpp>
46 #include <com/sun/star/lang/XInitialization.hpp>
47 #include <com/sun/star/lang/WrappedTargetException.hpp>
48 #include <com/sun/star/lang/IllegalArgumentException.hpp>
49 #include <com/sun/star/container/ElementExistException.hpp>
50 #include <com/sun/star/container/NoSuchElementException.hpp>
51 #include <com/sun/star/container/XNameContainer.hpp>
52 #include <com/sun/star/container/NoSuchElementException.hpp>
53 #include <com/sun/star/io/XInputStream.hpp>
54 #include <com/sun/star/util/XFlushable.hpp>
55 
56 //_______________________________________________
57 // includes of other projects
58 #include <cppuhelper/interfacecontainer.hxx>
59 #include <cppuhelper/weak.hxx>
60 
61 //_______________________________________________
62 // namespace
63 
64 namespace framework{
65 
66 //_______________________________________________
67 // exported const
68 
69 //_______________________________________________
70 // exported definitions
71 
72 /// @HTML
73 /** @short      factory to create detect service objects and initialize it in the right way.
74 
75     @descr      This class can be used to create new detect services for specified contents.
76                 It uses cached values of the configuration to lay down, which detector match
77                 a given name. Further this class provides full access to the configuration data
78                 of such detect services and following implementations will support some special
79                 query modes.
80 
81     @author     as96863
82 
83     @docdate    07.03.2003 by as96863
84 
85     @todo       <ul>
86                     <li>implementation of query mode</li>
87                     <li>simple restore mechanism of last consistent cache state,
88                         if flush failed</li>
89                 </ul>
90  */
91 /// @NOHTML
92 
93 class DetectorFactory : // interfaces
94 						public	css::lang::XTypeProvider			,
95 						public	css::lang::XServiceInfo				,
96 						public	css::lang::XMultiServiceFactory		,
97 						public	css::container::XNameContainer		,		// => XNameReplace => XNameAccess => XElementAccess
98 						public	css::util::XFlushable				,
99 						// base classes
100 						// Order is neccessary for right initialization of it!
101                         private ThreadHelpBase                      ,
102 						public	::cppu::OWeakObject
103 {
104     //-------------------------------------------
105     // member
106 
107     private:
108 
109         /** reference to the global uno service manager.
110             It will be used to create own needed services on demand. */
111         css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR;
112 
113         /** singleton, which contains all needed configuration data and provides
114             read/write access on it. */
115         FilterCache m_aCache;
116 
117         /** contains all registered listener. */
118         ::cppu::OMultiTypeInterfaceContainerHelper m_aListenerContainer;
119 
120     //-------------------------------------------
121     // interface
122 
123 	public:
124 
125         //---------------------------------------
126         // XInterface, XTypeProvider, XServiceInfo
127 
128         DECLARE_XINTERFACE
129         DECLARE_XTYPEPROVIDER
130         DECLARE_XSERVICEINFO
131 
132         #ifdef ENABLE_AUTODOC_FIX
133         ;
134         #endif
135 
136         //---------------------------------------
137 
138         /** @short  initialize new instance of this class.
139 
140             @param  xSMGR
141                     reference to the global uno service manager, which created this new factory instance.
142                     It must be used during runtime to create own needed services.
143          */
144 
145         DetectorFactory( const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR );
146 
147         //---------------------------------------
148 
149         /** @short  release internal structures.
150          */
151 
152         virtual ~DetectorFactory();
153 
154         //---------------------------------------
155         // XMultiServiceFactory
156 
157         /** @short  create a new detect service and initialize it with it's own configuration data.
158 
159             @param  sName
160                     means the uno implementation name of a detect service.
161 
162             @exception  com::sun::star::uno::Exception
163                         if the requested service could not be created or initialized.
164          */
165 
166         virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance( const ::rtl::OUString& sName )
167             throw(css::uno::Exception       ,
168                   css::uno::RuntimeException);
169 
170         //---------------------------------------
171         // XMultiServiceFactory
172 
173         /** @short  does the same as createInstance() method, but initialize created detect service with some
174                     additional data.
175 
176             @param  sName
177                     means the uno implementation name of a detect service.
178 
179             @param  lArguments
180                     the optional arguments, which are passed to the created detect service against
181                     it's own configuration data.
182 
183             @exception  com::sun::star::uno::Exception
184                         if the requested service could not be created or initialized.
185          */
186 
187         virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithArguments( const ::rtl::OUString&                     sName      ,
188                                                                                                   const css::uno::Sequence< css::uno::Any >& lArguments )
189             throw(css::uno::Exception       ,
190                   css::uno::RuntimeException);
191 
192         //---------------------------------------
193         // XMultiServiceFactory
194 
195         /** @short  return list of all well know detect services, which can be created by this factory.
196 
197             @attention  Because this service implements read/write access to the configuration too,
198                         this list is dynamic. Means: in multithreaded environments some items of this
199                         return list could be invalid next time!
200 
201             @return A list of all registered detect services.
202          */
203 
204         virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getAvailableServiceNames()
205             throw(css::uno::RuntimeException);
206 
207         //---------------------------------------
208         // XNameContainer
209 
210         /** @short  add new detect service entry to this container.
211 
212             @descr  This will change all internal structures only!
213                     Updating of the configuration layer and notify of all registered
214                     listener will be done inside API call XFlushable::flush() on this
215                     container.
216 
217             @param  sName
218                     means the uno implementation name of this new detect service entry.
219 
220             @param  aPropertySet [sequence< com::sun::star::beans::PropertyValue >!]
221                     describe this new entry. For a list of all supported properties
222                     have a look on method >>getByName()<<.
223                     Note: Missing values will be created with defaults!
224 
225             @exception  com::sun::star::lang::IllegalArgumentException
226                         if one of the incoming parameters seams to be invalid.
227                         That doesn't include the check, if this item already exist!
228 
229             @exception  com::sun::star::container::ElementExistException
230                         if this item already exist inside this container.
231 
232             @exception  com::sun::star::lang::WrappedTargetException
233                         f creation of the internal structures failed.
234          */
235 
236         virtual void SAL_CALL insertByName( const ::rtl::OUString& sName        ,
237                                             const css::uno::Any&   aPropertySet )
238             throw(css::lang::IllegalArgumentException  ,
239                   css::container::ElementExistException,
240                   css::lang::WrappedTargetException    ,
241                   css::uno::RuntimeException           );
242 
243         //---------------------------------------
244         // XNameContainer
245 
246         /** @short  remove a detect service entry from this container.
247 
248             @descr  This will change all internal structures only!
249                     Updating of the configuration layer and notify of all registered
250                     listener will be done inside API call XFlushable::flush() on this
251                     container.
252 
253             @param  sName
254                     means the uno implementation name of a detect service entry.
255 
256             @exception  com::sun::star::container::NoSuchElementException
257                         if the requested item does not exist inside this container.
258 
259             @exception  com::sun::star::lang::WrappedTargetException
260                         if creation of the internal structures failed.
261          */
262 
263         virtual void SAL_CALL removeByName( const ::rtl::OUString& sName )
264             throw(css::container::NoSuchElementException,
265                   css::lang::WrappedTargetException     ,
266                   css::uno::RuntimeException            );
267 
268         //---------------------------------------
269         // XNameReplace
270 
271         /** @short  change a detect service entry inside this container.
272 
273             @descr  This will change all internal structures only!
274                     Updating of the configuration layer and notify of all registered
275                     listener will be done inside API call XFlushable::flush() on this
276                     container.
277 
278             @param  sName
279                     means the uno implementation name of a detect service entry.
280 
281             @param  aPropertySet [sequence< com::sun::star::beans::PropertyValue >!]
282                     describe the changes on this entry. For a list of all supported properties
283                     have a look on method getByName().
284                     Note: Missing properties will be untouched.
285 
286             @exception  com::sun::star::lang::IllegalArgumentException
287                         if one of the incoming parameters seams to be invalid.
288                         That doesn't include the check, if this item exist!
289 
290             @exception  com::sun::star::container::NoSuchElementException
291                         if the requested item does not exist inside this container.
292 
293             @exception  com::sun::star::lang::WrappedTargetException
294                         if updating of the internal structures failed.
295          */
296 
297         virtual void SAL_CALL replaceByName( const ::rtl::OUString& sName        ,
298                                              const css::uno::Any&   aPropertySet )
299             throw(css::lang::IllegalArgumentException   ,
300                   css::container::NoSuchElementException,
301                   css::lang::WrappedTargetException     ,
302                   css::uno::RuntimeException            );
303 
304         //---------------------------------------
305         // XNameAccess
306 
307         /// @HTML
308         /** @short  return properties of queried detector item.
309 
310             @descr  Use this method to get all informations about a detector item of this cache.
311                     A sequence< com::sun::star::beans::PropertyValue > packed inside an Any will be returned.
312                     Following properties are defined:
313                     <table border=1>
314                     <tr>
315                         <td><b>Property</b></td>
316                         <td><b>Value<b></td>
317                         <td><b>Description<b></td>
318                     </tr>
319                     <tr>
320                         <td>Name</td>
321                         <td>[string]</td>
322                             <td>the uno implementation name for this detect service</td>
323                     </tr>
324                     <tr>
325                         <td>Types</td>
326                         <td>[sequence< string >]</td>
327                         <td>a list of all internbal type names, which this detect service is registered for</td>
328                     </tr>
329                     </table>
330 
331             @param  sName
332                     the uno implementation name the requested detector.
333 
334             @return A property set, which describe this detect service.
335                     It uses a sequence< com::sun::star::beans::PropertyValue > internaly.
336 
337             @exception  com::sun::star::container::NoSuchElementException
338                         if the requested entry does not exist inside this container.
339          */
340         /// @NOHTML
341 
342         virtual css::uno::Any SAL_CALL getByName( const ::rtl::OUString& sName )
343             throw(css::container::NoSuchElementException,
344                   css::lang::WrappedTargetException     ,
345                   css::uno::RuntimeException            );
346 
347         //---------------------------------------
348         // XNameAccess
349 
350         /** @short  return list of all well know container entries available on this container.
351 
352             @attention  Because this service implements read/write access to the configuration too,
353                         this list is dynamic. Means: in multithreaded environments some items of this
354                         return list could be invalid next time!
355 
356             @return A list of all well known container items.
357          */
358 
359         virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames()
360             throw(css::uno::RuntimeException);
361 
362         //---------------------------------------
363         // XNameAccess
364 
365         /** @short  check if searched entry exist inside this container.
366 
367             @attention  In multithreaded environments it's not guaranteed, that a
368                         queried item exist next time realy! It can be deleted by
369                         another thread ...
370 
371             @param  sName
372                     the name of the queried container entry.
373 
374             @return sal_True if the requested item exist; sal_False otherwise.
375          */
376 
377         virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& sName )
378             throw(css::uno::RuntimeException);
379 
380         //---------------------------------------
381         // XElementAccess
382 
383         /** @short  return the uno type, which is used for all container items.
384 
385             @return Type of sequence< com::sun::star::beans::PropertyValue > everytime - because it's fix.
386          */
387 
388         virtual css::uno::Type SAL_CALL getElementType()
389             throw(css::uno::RuntimeException);
390 
391         //---------------------------------------
392         // XElementAccess
393 
394         /** @short  return fill state of this cache.
395 
396             @return sal_True if any item exist inside this conatiner; sal_False otherwhise.
397          */
398 
399         virtual sal_Bool SAL_CALL hasElements()
400             throw(css::uno::RuntimeException);
401 
402         //---------------------------------------
403         // XFlushable
404 
405         /** @short  update the configuration layer and notify all registered listener.
406 
407             @descr  All container interface methods update the internal structures of
408                     this container only. But the underlying configuration layer and
409                     may some possible other caches was not updated.
410                     Calling of flush() will do that.
411                     At the same time all currently registered flush listener will be informed,
412                     so they can update her structures too.
413                     Note: Before all these operations are started realy, all changes will be
414                     verified and if neccessary some corrections will be done.
415                     In case the cache will be invalid and could not be repaired an exception is thrown!
416                     Normaly this container will not work correctly afterwards ...
417 
418             @exception  com::sun::star::uno::RuntimeException
419                         if the changes on this container was invald and could not be repaired.
420          */
421 
422         virtual void SAL_CALL flush()
423             throw(css::uno::RuntimeException);
424 
425         //---------------------------------------
426         // XFlushable
427 
428         /** @short  register listener for container updates.
429 
430             @param  xListener
431                     reference to listener, which wish to be registered.
432 
433             @exception  com::sun::star::uno::RuntimeException
434                         if the given listener is an invalid reference.
435                         Note: multiple calls of this method for the same listener won't be checked!
436          */
437 
438         virtual void SAL_CALL addFlushListener( const css::uno::Reference< css::util::XFlushListener >& xListener )
439             throw(css::uno::RuntimeException);
440 
441         //---------------------------------------
442         // XFlushable
443 
444         /** @short  deregister listener for container updates.
445 
446             @param  xListener
447                     reference to listener, which wish to be deregistered.
448 
449             @exception  com::sun::star::uno::RuntimeException
450                         if the given listener is an invalid reference.
451                         Note: multiple calls of this method for the same listener won't be checked!
452          */
453 
454         virtual void SAL_CALL removeFlushListener( const css::uno::Reference< css::util::XFlushListener >& xListener )
455             throw(css::uno::RuntimeException);
456 
457 }; // class DetectorFactory
458 
459 } // namespace framework
460 
461 #endif // #ifndef __FRAMEWORK_SERVICES_DETECTORFACTORY_HXX_
462