update dev300-m58
[ooovba.git] / filter / source / config / cache / basecontainer.hxx
blobaf37e91c49cfe0a68011d1b3a278016bee2128b2
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: basecontainer.hxx,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef __FILTER_CONFIG_BASECONTAINER_HXX_
31 #define __FILTER_CONFIG_BASECONTAINER_HXX_
33 //_______________________________________________
34 // includes
36 #include "filtercache.hxx"
37 #include <com/sun/star/uno/Exception.hpp>
38 #include <com/sun/star/lang/XServiceInfo.hpp>
39 #include <com/sun/star/util/XRefreshable.hpp>
40 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
41 #include <com/sun/star/container/XNameContainer.hpp>
42 #include <com/sun/star/container/XContainerQuery.hpp>
43 #include <com/sun/star/util/XFlushable.hpp>
44 #include <cppuhelper/interfacecontainer.h>
45 #include <salhelper/singletonref.hxx>
46 #include <cppuhelper/implbase4.hxx>
47 #include <cppuhelper/weakref.hxx>
48 #include <rtl/ustring.hxx>
50 //_______________________________________________
51 // namespace
53 namespace filter{
54 namespace config{
56 //_______________________________________________
57 // definitions
59 //_______________________________________________
61 /** @short implements the interface css::container::XNameContainer
62 on top of a FilterCache reference.
64 @descr This class can be used as base for own service implementations,
65 which must provide read/write access to the filter configuration.
66 Parameters regulate read/write access, which sub set of informations
67 should be available etc.
69 @attention The base class BaseLock must be the first of declared ones.
70 Otherwhise we cant be shure, that our own mutex member (which is
71 present by this base class!) was full initialized inside our own
72 ctor as first!
74 class BaseContainer : public BaseLock
75 , public ::cppu::WeakImplHelper4< css::lang::XServiceInfo ,
76 css::container::XNameContainer , // => XNameReplace => XNameAccess => XElementAccess
77 css::container::XContainerQuery ,
78 css::util::XFlushable >
80 //-------------------------------------------
81 // member
83 protected:
85 /** @short reference to an uno service manager, which can be used
86 to create own needed services. */
87 css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR;
89 // TODO
90 css::uno::WeakReference< css::util::XRefreshable > m_xRefreshBroadcaster;
92 /** @short the implementation name of our derived class, which we provide
93 at the interface XServiceInfo of our class ... */
94 ::rtl::OUString m_sImplementationName;
96 /** @short the list of supported uno service names of our derived class, which we provide
97 at the interface XServiceInfo of our class ... */
98 css::uno::Sequence< ::rtl::OUString > m_lServiceNames;
100 /** @short reference(!) to a singleton filter cache implementation,
101 which is used to work with the underlying configuration. */
102 ::salhelper::SingletonRef< FilterCache > m_rCache;
104 /** @short local filter cache, which is used to collect changes on the
105 filter configuration first and flush it later.
107 @descr Normaly this member isnt used nor initialized. Thats true,
108 if this container is used for reading only. The first write access
109 (e.g. by calling insertByName()) creates a copy of the current
110 global cache m_rCache to initialize the m_pFlushCache member.
112 Afterwards only the flush cache copy is used. Inside flush() this
113 copy will be removed and m_rCache can be used again.
115 m_pFlushCache and m_rCache must not be synchronized manually here.
116 m_rCache listen on the global configuration, where m_pFlushCache
117 write its data. m_rCache update itself automaticly.
119 FilterCache* m_pFlushCache;
121 /** @short specify, which sub container of the used filter cache
122 must be wrapped by this container interface. */
123 FilterCache::EItemType m_eType;
125 /** @short holds all listener, which are registered at this instance. */
126 ::cppu::OMultiTypeInterfaceContainerHelper m_lListener;
128 /** @short hold at least on filter cache instance alive and
129 prevent he office from unloading this cache if no filter
130 is currently used.*/
131 static ::salhelper::SingletonRef< FilterCache >* m_pPerformanceOptimizer;
133 //-------------------------------------------
134 // native interface
136 public:
138 //---------------------------------------
139 // ctor/dtor
141 /** @short standard ctor.
143 @descr Because mostly this class is used as base class for own service
144 implementations in combination with a ImplInheritanceHelper2 template ...
145 there is no way to provide some initializing data through the ctor :-(
146 This base class will be created inside its default ctor and must be
147 initialized with its needed parameters explicitly by calling: "init()".
149 @see init()
151 BaseContainer();
153 //---------------------------------------
155 /** @short standard dtor.
157 virtual ~BaseContainer();
159 //---------------------------------------
161 /** @short initialize this generic intsnace with some specialized values
162 from our derived object.
164 @descr Because an outside class must use ImplInheritanceHelper2 template to
165 use us a base class ... and there is no way to pass such initializing
166 parameters trough a required default ctor ... we must be initialized
167 by this special method. Of course this method must be called first before
168 any other interface method is used.
170 @param xSMGR
171 reference to the uno service manager, which created this service instance.
173 @param sImplementationName
174 the implementation name of our derived class, which we provide
175 at the interface XServiceInfo of our class ...
177 @param lServiceNames
178 the list of supported uno service names of our derived class, which we provide
179 at the interface XServiceInfo of our class ...
181 @param eType
182 specify, which sub container of the used filter cache
183 must be wrapped by this container interface.
185 virtual void init(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR ,
186 const ::rtl::OUString& sImplementationName,
187 const css::uno::Sequence< ::rtl::OUString >& lServiceNames ,
188 FilterCache::EItemType eType );
190 //-------------------------------------------
191 // helper
193 protected:
195 //---------------------------------------
197 /** @short check if the underlying configuration data was already loaded
198 and do it if neccessary automaticly.
200 void impl_loadOnDemand();
202 //---------------------------------------
204 /** @short it creates the global instance m_pFilterCache, which is a copy
205 of the global instance m_rCache, and will be used to change the
206 configuration.
208 @descr If no exception occures, its guaranteed, that the member m_rFlushCache
209 was initialized right and can be used further.
211 void impl_initFlushMode()
212 throw (css::uno::RuntimeException);
214 //---------------------------------------
216 /** @short returns a pointer to the current used cache member.
218 @descr Its a point to the FilterCache instance behind m_pFlushCache
219 or m_rCache.
221 @note The lifetime of this pointer is restricted to the time, where
222 the mutex of this BaseContainer instance is locked.
223 Otherwhise may be the interface method flush() will destroy
224 m_pFlushCache and the here returned pointer will be invalid!
226 Use:
228 Guard aLock(m_aLock);
229 FilterCache* p = impl_getWorkingCache();
230 p->doSomething();
231 aLock.clear();
232 // after this point p cant b e guaranteed any longer!
234 FilterCache* impl_getWorkingCache() const;
236 //-------------------------------------------
237 // uno interface
239 public:
241 //---------------------------------------
242 // XServiceInfo
244 virtual ::rtl::OUString SAL_CALL getImplementationName()
245 throw (css::uno::RuntimeException);
247 virtual sal_Bool SAL_CALL supportsService(const ::rtl::OUString& sServiceName)
248 throw (css::uno::RuntimeException);
250 virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
251 throw (css::uno::RuntimeException);
253 //---------------------------------------
254 // XNameContainer
256 virtual void SAL_CALL insertByName(const ::rtl::OUString& sItem ,
257 const css::uno::Any& aValue)
258 throw (css::lang::IllegalArgumentException ,
259 css::container::ElementExistException,
260 css::lang::WrappedTargetException ,
261 css::uno::RuntimeException );
263 virtual void SAL_CALL removeByName(const ::rtl::OUString& sItem)
264 throw (css::container::NoSuchElementException,
265 css::lang::WrappedTargetException ,
266 css::uno::RuntimeException );
268 //---------------------------------------
269 // XNameReplace
271 virtual void SAL_CALL replaceByName(const ::rtl::OUString& sItem ,
272 const css::uno::Any& aValue)
273 throw (css::lang::IllegalArgumentException ,
274 css::container::NoSuchElementException,
275 css::lang::WrappedTargetException ,
276 css::uno::RuntimeException );
278 //---------------------------------------
279 // XElementAccess
281 virtual css::uno::Any SAL_CALL getByName(const ::rtl::OUString& sItem)
282 throw (css::container::NoSuchElementException,
283 css::lang::WrappedTargetException ,
284 css::uno::RuntimeException );
286 virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames()
287 throw (css::uno::RuntimeException);
289 virtual sal_Bool SAL_CALL hasByName(const ::rtl::OUString& sItem)
290 throw (css::uno::RuntimeException);
292 virtual css::uno::Type SAL_CALL getElementType()
293 throw (css::uno::RuntimeException);
295 virtual sal_Bool SAL_CALL hasElements()
296 throw (css::uno::RuntimeException);
298 //---------------------------------------
299 // XContainerQuery
301 // must be implemented realy by derived class ...
302 // We implement return of an empty result here only!
303 // But we show an assertion :-)
304 virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createSubSetEnumerationByQuery(const ::rtl::OUString& sQuery)
305 throw (css::uno::RuntimeException);
307 virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createSubSetEnumerationByProperties(const css::uno::Sequence< css::beans::NamedValue >& lProperties)
308 throw (css::uno::RuntimeException);
310 //---------------------------------------
311 // XFlushable
313 virtual void SAL_CALL flush()
314 throw (css::uno::RuntimeException);
316 virtual void SAL_CALL addFlushListener(const css::uno::Reference< css::util::XFlushListener >& xListener)
317 throw (css::uno::RuntimeException);
319 virtual void SAL_CALL removeFlushListener(const css::uno::Reference< css::util::XFlushListener >& xListener)
320 throw (css::uno::RuntimeException);
323 } // namespace config
324 } // namespace filter
326 #endif // __FILTER_CONFIG_BASECONTAINER_HXX_