Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / configmgr / source / access.hxx
blob1e91fedf1bdc88a8d46b5a5486df8c57b2110b80
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_CONFIGMGR_SOURCE_ACCESS_HXX
21 #define INCLUDED_CONFIGMGR_SOURCE_ACCESS_HXX
23 #include "sal/config.h"
25 #include <map>
26 #include <set>
27 #include <vector>
29 #include "boost/noncopyable.hpp"
30 #include "boost/shared_ptr.hpp"
31 #include "com/sun/star/beans/PropertyVetoException.hpp"
32 #include "com/sun/star/beans/UnknownPropertyException.hpp"
33 #include "com/sun/star/beans/XExactName.hpp"
34 #include "com/sun/star/beans/XHierarchicalPropertySet.hpp"
35 #include "com/sun/star/beans/XHierarchicalPropertySetInfo.hpp"
36 #include "com/sun/star/beans/XMultiHierarchicalPropertySet.hpp"
37 #include "com/sun/star/beans/XMultiPropertySet.hpp"
38 #include "com/sun/star/beans/XProperty.hpp"
39 #include "com/sun/star/beans/XPropertySet.hpp"
40 #include "com/sun/star/beans/XPropertySetInfo.hpp"
41 #include "com/sun/star/container/ElementExistException.hpp"
42 #include "com/sun/star/container/NoSuchElementException.hpp"
43 #include "com/sun/star/container/XContainer.hpp"
44 #include "com/sun/star/container/XHierarchicalName.hpp"
45 #include "com/sun/star/container/XHierarchicalNameReplace.hpp"
46 #include "com/sun/star/container/XNameContainer.hpp"
47 #include "com/sun/star/container/XNamed.hpp"
48 #include "com/sun/star/lang/IllegalArgumentException.hpp"
49 #include "com/sun/star/lang/NoSupportException.hpp"
50 #include "com/sun/star/lang/WrappedTargetException.hpp"
51 #include "com/sun/star/lang/XComponent.hpp"
52 #include "com/sun/star/lang/XServiceInfo.hpp"
53 #include "com/sun/star/lang/XTypeProvider.hpp"
54 #include "com/sun/star/lang/XSingleServiceFactory.hpp"
55 #include "com/sun/star/uno/Exception.hpp"
56 #include "com/sun/star/uno/Reference.hxx"
57 #include "com/sun/star/uno/RuntimeException.hpp"
58 #include "com/sun/star/uno/Sequence.hxx"
59 #include "cppuhelper/weak.hxx"
60 #include "osl/interlck.h"
61 #include "rtl/ref.hxx"
62 #include "sal/types.h"
64 #include "modifications.hxx"
65 #include "path.hxx"
66 #include "type.hxx"
68 namespace com { namespace sun { namespace star {
69 namespace beans {
70 class XHierarchicalPropertySetInfo;
71 class XPropertiesChangeListener;
72 class XPropertyChangeListener;
73 class XVetoableChangeListener;
74 struct Property;
76 namespace container { class XContainerListener; }
77 namespace lang { class XEventListener; }
78 namespace uno {
79 class Any;
80 class Type;
81 class XInterface;
83 namespace util { struct ElementChange; }
84 } } }
85 namespace rtl { class OUString; }
87 namespace configmgr {
89 class Broadcaster;
90 class ChildAccess;
91 class Components;
92 class Node;
93 class RootAccess;
95 class Access:
96 public cppu::OWeakObject, public com::sun::star::lang::XTypeProvider,
97 public com::sun::star::lang::XServiceInfo,
98 public com::sun::star::lang::XComponent,
99 public com::sun::star::container::XHierarchicalNameReplace,
100 public com::sun::star::container::XContainer,
101 public com::sun::star::beans::XExactName,
102 public com::sun::star::beans::XPropertySetInfo,
103 public com::sun::star::container::XHierarchicalName,
104 public com::sun::star::container::XNamed,
105 public com::sun::star::beans::XProperty,
106 public com::sun::star::beans::XPropertySet,
107 public com::sun::star::beans::XMultiPropertySet,
108 public com::sun::star::beans::XHierarchicalPropertySet,
109 public com::sun::star::beans::XMultiHierarchicalPropertySet,
110 public com::sun::star::beans::XHierarchicalPropertySetInfo,
111 public com::sun::star::container::XNameContainer,
112 public com::sun::star::lang::XSingleServiceFactory,
113 private boost::noncopyable
115 public:
116 oslInterlockedCount acquireCounting();
118 void releaseNondeleting();
120 bool isValue();
122 void markChildAsModified(rtl::Reference< ChildAccess > const & child);
123 void releaseChild(rtl::OUString const & name);
125 virtual Path getAbsolutePath() = 0;
126 virtual Path getRelativePath() = 0;
128 virtual rtl::OUString getRelativePathRepresentation() = 0;
129 virtual rtl::Reference< Node > getNode() = 0;
131 virtual bool isFinalized() = 0;
133 virtual void initBroadcaster(
134 Modifications::Node const & modifications, Broadcaster * broadcaster);
136 using OWeakObject::acquire;
137 using OWeakObject::release;
139 virtual com::sun::star::uno::Sequence< com::sun::star::uno::Type > SAL_CALL
140 getTypes() throw (com::sun::star::uno::RuntimeException);
142 virtual com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL
143 getImplementationId() throw (com::sun::star::uno::RuntimeException);
145 virtual rtl::OUString SAL_CALL getImplementationName()
146 throw (com::sun::star::uno::RuntimeException);
148 virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & ServiceName)
149 throw (com::sun::star::uno::RuntimeException);
151 virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL
152 getSupportedServiceNames() throw (com::sun::star::uno::RuntimeException);
154 virtual void SAL_CALL dispose()
155 throw (com::sun::star::uno::RuntimeException);
157 virtual void SAL_CALL addEventListener(
158 com::sun::star::uno::Reference< com::sun::star::lang::XEventListener >
159 const & xListener)
160 throw (com::sun::star::uno::RuntimeException);
162 virtual void SAL_CALL removeEventListener(
163 com::sun::star::uno::Reference< com::sun::star::lang::XEventListener >
164 const & aListener)
165 throw (com::sun::star::uno::RuntimeException);
167 virtual com::sun::star::uno::Type SAL_CALL getElementType()
168 throw (com::sun::star::uno::RuntimeException);
170 virtual sal_Bool SAL_CALL hasElements()
171 throw (com::sun::star::uno::RuntimeException);
173 virtual com::sun::star::uno::Any SAL_CALL getByName(
174 rtl::OUString const & aName)
175 throw (
176 com::sun::star::container::NoSuchElementException,
177 com::sun::star::lang::WrappedTargetException,
178 com::sun::star::uno::RuntimeException);
180 virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL
181 getElementNames() throw (com::sun::star::uno::RuntimeException);
183 virtual sal_Bool SAL_CALL hasByName(rtl::OUString const & aName)
184 throw (com::sun::star::uno::RuntimeException);
186 virtual com::sun::star::uno::Any SAL_CALL getByHierarchicalName(
187 rtl::OUString const & aName)
188 throw (
189 com::sun::star::container::NoSuchElementException,
190 com::sun::star::uno::RuntimeException);
192 virtual sal_Bool SAL_CALL hasByHierarchicalName(rtl::OUString const & aName)
193 throw (com::sun::star::uno::RuntimeException);
195 virtual void SAL_CALL replaceByHierarchicalName(
196 rtl::OUString const & aName, com::sun::star::uno::Any const & aElement)
197 throw (
198 com::sun::star::lang::IllegalArgumentException,
199 com::sun::star::container::NoSuchElementException,
200 com::sun::star::lang::WrappedTargetException,
201 com::sun::star::uno::RuntimeException);
203 virtual void SAL_CALL addContainerListener(
204 com::sun::star::uno::Reference<
205 com::sun::star::container::XContainerListener > const & xListener)
206 throw (com::sun::star::uno::RuntimeException);
208 virtual void SAL_CALL removeContainerListener(
209 com::sun::star::uno::Reference<
210 com::sun::star::container::XContainerListener > const & xListener)
211 throw (com::sun::star::uno::RuntimeException);
213 virtual rtl::OUString SAL_CALL getExactName(
214 rtl::OUString const & aApproximateName)
215 throw (com::sun::star::uno::RuntimeException);
217 virtual com::sun::star::uno::Sequence< com::sun::star::beans::Property >
218 SAL_CALL getProperties() throw (com::sun::star::uno::RuntimeException);
220 virtual com::sun::star::beans::Property SAL_CALL getPropertyByName(
221 rtl::OUString const & aName)
222 throw (
223 com::sun::star::beans::UnknownPropertyException,
224 com::sun::star::uno::RuntimeException);
226 virtual sal_Bool SAL_CALL hasPropertyByName(rtl::OUString const & Name)
227 throw (com::sun::star::uno::RuntimeException);
229 virtual rtl::OUString SAL_CALL getHierarchicalName()
230 throw (com::sun::star::uno::RuntimeException);
232 virtual rtl::OUString SAL_CALL composeHierarchicalName(
233 rtl::OUString const & aRelativeName)
234 throw (
235 com::sun::star::lang::IllegalArgumentException,
236 com::sun::star::lang::NoSupportException,
237 com::sun::star::uno::RuntimeException);
239 virtual rtl::OUString SAL_CALL getName()
240 throw (com::sun::star::uno::RuntimeException);
242 virtual void SAL_CALL setName(rtl::OUString const & aName)
243 throw (com::sun::star::uno::RuntimeException);
245 virtual com::sun::star::beans::Property SAL_CALL getAsProperty()
246 throw (com::sun::star::uno::RuntimeException);
248 virtual
249 com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo >
250 SAL_CALL getPropertySetInfo() throw (com::sun::star::uno::RuntimeException);
252 virtual void SAL_CALL setPropertyValue(
253 rtl::OUString const & aPropertyName,
254 com::sun::star::uno::Any const & aValue)
255 throw (
256 com::sun::star::beans::UnknownPropertyException,
257 com::sun::star::beans::PropertyVetoException,
258 com::sun::star::lang::IllegalArgumentException,
259 com::sun::star::lang::WrappedTargetException,
260 com::sun::star::uno::RuntimeException);
262 virtual com::sun::star::uno::Any SAL_CALL getPropertyValue(
263 rtl::OUString const & PropertyName)
264 throw (
265 com::sun::star::beans::UnknownPropertyException,
266 com::sun::star::lang::WrappedTargetException,
267 com::sun::star::uno::RuntimeException);
269 virtual void SAL_CALL addPropertyChangeListener(
270 rtl::OUString const & aPropertyName,
271 com::sun::star::uno::Reference<
272 com::sun::star::beans::XPropertyChangeListener > const & xListener)
273 throw (
274 com::sun::star::beans::UnknownPropertyException,
275 com::sun::star::lang::WrappedTargetException,
276 com::sun::star::uno::RuntimeException);
278 virtual void SAL_CALL removePropertyChangeListener(
279 rtl::OUString const & aPropertyName,
280 com::sun::star::uno::Reference<
281 com::sun::star::beans::XPropertyChangeListener > const & aListener)
282 throw (
283 com::sun::star::beans::UnknownPropertyException,
284 com::sun::star::lang::WrappedTargetException,
285 com::sun::star::uno::RuntimeException);
287 virtual void SAL_CALL addVetoableChangeListener(
288 rtl::OUString const & PropertyName,
289 com::sun::star::uno::Reference<
290 com::sun::star::beans::XVetoableChangeListener > const & aListener)
291 throw (
292 com::sun::star::beans::UnknownPropertyException,
293 com::sun::star::lang::WrappedTargetException,
294 com::sun::star::uno::RuntimeException);
296 virtual void SAL_CALL removeVetoableChangeListener(
297 rtl::OUString const & PropertyName,
298 com::sun::star::uno::Reference<
299 com::sun::star::beans::XVetoableChangeListener > const & aListener)
300 throw (
301 com::sun::star::beans::UnknownPropertyException,
302 com::sun::star::lang::WrappedTargetException,
303 com::sun::star::uno::RuntimeException);
305 virtual void SAL_CALL setPropertyValues(
306 com::sun::star::uno::Sequence< rtl::OUString > const & aPropertyNames,
307 com::sun::star::uno::Sequence< com::sun::star::uno::Any > const &
308 aValues)
309 throw (
310 com::sun::star::beans::PropertyVetoException,
311 com::sun::star::lang::IllegalArgumentException,
312 com::sun::star::lang::WrappedTargetException,
313 com::sun::star::uno::RuntimeException);
315 virtual com::sun::star::uno::Sequence< com::sun::star::uno::Any > SAL_CALL
316 getPropertyValues(
317 com::sun::star::uno::Sequence< rtl::OUString > const & aPropertyNames)
318 throw (com::sun::star::uno::RuntimeException);
320 virtual void SAL_CALL addPropertiesChangeListener(
321 com::sun::star::uno::Sequence< rtl::OUString > const & aPropertyNames,
322 com::sun::star::uno::Reference<
323 com::sun::star::beans::XPropertiesChangeListener > const &
324 xListener)
325 throw (com::sun::star::uno::RuntimeException);
327 virtual void SAL_CALL removePropertiesChangeListener(
328 com::sun::star::uno::Reference<
329 com::sun::star::beans::XPropertiesChangeListener > const &
330 xListener)
331 throw (com::sun::star::uno::RuntimeException);
333 virtual void SAL_CALL firePropertiesChangeEvent(
334 com::sun::star::uno::Sequence< rtl::OUString > const & aPropertyNames,
335 com::sun::star::uno::Reference<
336 com::sun::star::beans::XPropertiesChangeListener > const &
337 xListener)
338 throw (com::sun::star::uno::RuntimeException);
340 virtual
341 com::sun::star::uno::Reference<
342 com::sun::star::beans::XHierarchicalPropertySetInfo > SAL_CALL
343 getHierarchicalPropertySetInfo()
344 throw (com::sun::star::uno::RuntimeException);
346 virtual void SAL_CALL setHierarchicalPropertyValue(
347 rtl::OUString const & aHierarchicalPropertyName,
348 com::sun::star::uno::Any const & aValue)
349 throw (
350 com::sun::star::beans::UnknownPropertyException,
351 com::sun::star::beans::PropertyVetoException,
352 com::sun::star::lang::IllegalArgumentException,
353 com::sun::star::lang::WrappedTargetException,
354 com::sun::star::uno::RuntimeException);
356 virtual com::sun::star::uno::Any SAL_CALL getHierarchicalPropertyValue(
357 rtl::OUString const & aHierarchicalPropertyName)
358 throw (
359 com::sun::star::beans::UnknownPropertyException,
360 com::sun::star::lang::IllegalArgumentException,
361 com::sun::star::lang::WrappedTargetException,
362 com::sun::star::uno::RuntimeException);
364 virtual void SAL_CALL setHierarchicalPropertyValues(
365 com::sun::star::uno::Sequence< rtl::OUString > const &
366 aHierarchicalPropertyNames,
367 com::sun::star::uno::Sequence< com::sun::star::uno::Any > const &
368 Values)
369 throw (
370 com::sun::star::beans::PropertyVetoException,
371 com::sun::star::lang::IllegalArgumentException,
372 com::sun::star::lang::WrappedTargetException,
373 com::sun::star::uno::RuntimeException);
375 virtual com::sun::star::uno::Sequence< com::sun::star::uno::Any > SAL_CALL
376 getHierarchicalPropertyValues(
377 com::sun::star::uno::Sequence< rtl::OUString > const &
378 aHierarchicalPropertyNames)
379 throw (
380 com::sun::star::lang::IllegalArgumentException,
381 com::sun::star::lang::WrappedTargetException,
382 com::sun::star::uno::RuntimeException);
384 virtual com::sun::star::beans::Property SAL_CALL
385 getPropertyByHierarchicalName(rtl::OUString const & aHierarchicalName)
386 throw (
387 com::sun::star::beans::UnknownPropertyException,
388 com::sun::star::uno::RuntimeException);
390 virtual sal_Bool SAL_CALL hasPropertyByHierarchicalName(
391 rtl::OUString const & aHierarchicalName)
392 throw (com::sun::star::uno::RuntimeException);
394 virtual void SAL_CALL replaceByName(
395 rtl::OUString const & aName, com::sun::star::uno::Any const & aElement)
396 throw (
397 com::sun::star::lang::IllegalArgumentException,
398 com::sun::star::container::NoSuchElementException,
399 com::sun::star::lang::WrappedTargetException,
400 com::sun::star::uno::RuntimeException);
402 virtual void SAL_CALL insertByName(
403 rtl::OUString const & aName, com::sun::star::uno::Any const & aElement)
404 throw (
405 com::sun::star::lang::IllegalArgumentException,
406 com::sun::star::container::ElementExistException,
407 com::sun::star::lang::WrappedTargetException,
408 com::sun::star::uno::RuntimeException);
410 virtual void SAL_CALL removeByName(rtl::OUString const & aName)
411 throw (
412 com::sun::star::container::NoSuchElementException,
413 com::sun::star::lang::WrappedTargetException,
414 com::sun::star::uno::RuntimeException);
416 virtual com::sun::star::uno::Reference< com::sun::star::uno::XInterface >
417 SAL_CALL createInstance()
418 throw (
419 com::sun::star::uno::Exception,
420 com::sun::star::uno::RuntimeException);
422 virtual com::sun::star::uno::Reference< com::sun::star::uno::XInterface >
423 SAL_CALL createInstanceWithArguments(
424 com::sun::star::uno::Sequence< com::sun::star::uno::Any > const &
425 aArguments)
426 throw (
427 com::sun::star::uno::Exception,
428 com::sun::star::uno::RuntimeException);
430 protected:
431 Access(Components & components);
433 virtual ~Access();
435 virtual rtl::OUString getNameInternal() = 0;
436 virtual rtl::Reference< RootAccess > getRootAccess() = 0;
437 virtual rtl::Reference< Access > getParentAccess() = 0;
439 virtual void addTypes(std::vector< com::sun::star::uno::Type > * types)
440 const = 0;
442 virtual void addSupportedServiceNames(
443 std::vector< rtl::OUString > * services) = 0;
445 virtual void initDisposeBroadcaster(Broadcaster * broadcaster);
446 virtual void clearListeners() throw ();
448 virtual com::sun::star::uno::Any SAL_CALL queryInterface(
449 com::sun::star::uno::Type const & aType)
450 throw (com::sun::star::uno::RuntimeException);
452 Components & getComponents() const;
454 void checkLocalizedPropertyAccess();
456 rtl::Reference< Node > getParentNode();
457 rtl::Reference< ChildAccess > getChild(rtl::OUString const & name);
458 std::vector< rtl::Reference< ChildAccess > > getAllChildren();
460 void checkValue(
461 com::sun::star::uno::Any const & value, Type type, bool nillable);
463 void insertLocalizedValueChild(
464 rtl::OUString const & name, com::sun::star::uno::Any const & value,
465 Modifications * localModifications);
467 void reportChildChanges(
468 std::vector< com::sun::star::util::ElementChange > * changes);
470 void commitChildChanges(bool valid, Modifications * globalModifications);
472 void initBroadcasterAndChanges(
473 Modifications::Node const & modifications, Broadcaster * broadcaster,
474 std::vector< com::sun::star::util::ElementChange > * changes);
476 bool isDisposed() const;
478 private:
479 struct ModifiedChild {
480 rtl::Reference< ChildAccess > child;
481 bool directlyModified;
483 ModifiedChild();
485 ModifiedChild(
486 rtl::Reference< ChildAccess > const & theChild,
487 bool theDirectlyModified);
490 typedef std::map< rtl::OUString, ModifiedChild > ModifiedChildren;
492 rtl::Reference< ChildAccess > getModifiedChild(
493 ModifiedChildren::iterator const & childIterator);
495 rtl::Reference< ChildAccess > getUnmodifiedChild(
496 rtl::OUString const & name);
498 rtl::Reference< ChildAccess > getSubChild(rtl::OUString const & path);
500 bool setChildProperty(
501 rtl::OUString const & name, com::sun::star::uno::Any const & value,
502 Modifications * localModifications);
504 com::sun::star::beans::Property asProperty();
506 void checkFinalized();
508 void checkKnownProperty(rtl::OUString const & descriptor);
510 rtl::Reference< ChildAccess > getFreeSetMember(
511 com::sun::star::uno::Any const & value);
513 rtl::Reference< Access > getNotificationRoot();
515 typedef std::map< rtl::OUString, ChildAccess * > WeakChildMap;
517 typedef
518 std::multiset<
519 com::sun::star::uno::Reference<
520 com::sun::star::lang::XEventListener > >
521 DisposeListeners;
523 typedef
524 std::multiset<
525 com::sun::star::uno::Reference<
526 com::sun::star::container::XContainerListener > >
527 ContainerListeners;
529 typedef
530 std::multiset<
531 com::sun::star::uno::Reference<
532 com::sun::star::beans::XPropertyChangeListener > >
533 PropertyChangeListenersElement;
535 typedef std::map< rtl::OUString, PropertyChangeListenersElement >
536 PropertyChangeListeners;
538 typedef
539 std::multiset<
540 com::sun::star::uno::Reference<
541 com::sun::star::beans::XVetoableChangeListener > >
542 VetoableChangeListenersElement;
544 typedef std::map< rtl::OUString, VetoableChangeListenersElement >
545 VetoableChangeListeners;
547 typedef
548 std::multiset<
549 com::sun::star::uno::Reference<
550 com::sun::star::beans::XPropertiesChangeListener > >
551 PropertiesChangeListeners;
553 Components & components_;
554 ModifiedChildren modifiedChildren_;
555 WeakChildMap cachedChildren_;
556 DisposeListeners disposeListeners_;
557 ContainerListeners containerListeners_;
558 PropertyChangeListeners propertyChangeListeners_;
559 VetoableChangeListeners vetoableChangeListeners_;
560 PropertiesChangeListeners propertiesChangeListeners_;
561 bool disposed_;
563 boost::shared_ptr<osl::Mutex> lock_;
565 #if !defined NDEBUG
566 protected:
567 enum {
568 IS_ANY = 0, IS_GROUP = 0x01, IS_SET = 0x02, IS_EXTENSIBLE = 0x04,
569 IS_GROUP_MEMBER = 0x08, IS_SET_MEMBER = 0x10, IS_UPDATE = 0x20 };
570 bool thisIs(int what);
571 #endif
576 #endif
578 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */