xref: /trunk/main/configmgr/source/access.hxx (revision a2faadff)
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 INCLUDED_CONFIGMGR_SOURCE_ACCESS_HXX
25 #define INCLUDED_CONFIGMGR_SOURCE_ACCESS_HXX
26 
27 #include "sal/config.h"
28 
29 #include <map>
30 #include <set>
31 #include <vector>
32 
33 #include "boost/noncopyable.hpp"
34 #include "com/sun/star/beans/PropertyVetoException.hpp"
35 #include "com/sun/star/beans/UnknownPropertyException.hpp"
36 #include "com/sun/star/beans/XExactName.hpp"
37 #include "com/sun/star/beans/XHierarchicalPropertySet.hpp"
38 #include "com/sun/star/beans/XHierarchicalPropertySetInfo.hpp"
39 #include "com/sun/star/beans/XMultiHierarchicalPropertySet.hpp"
40 #include "com/sun/star/beans/XMultiPropertySet.hpp"
41 #include "com/sun/star/beans/XProperty.hpp"
42 #include "com/sun/star/beans/XPropertySet.hpp"
43 #include "com/sun/star/beans/XPropertySetInfo.hpp"
44 #include "com/sun/star/container/ElementExistException.hpp"
45 #include "com/sun/star/container/NoSuchElementException.hpp"
46 #include "com/sun/star/container/XContainer.hpp"
47 #include "com/sun/star/container/XHierarchicalName.hpp"
48 #include "com/sun/star/container/XHierarchicalNameAccess.hpp"
49 #include "com/sun/star/container/XNameContainer.hpp"
50 #include "com/sun/star/container/XNamed.hpp"
51 #include "com/sun/star/lang/IllegalArgumentException.hpp"
52 #include "com/sun/star/lang/NoSupportException.hpp"
53 #include "com/sun/star/lang/WrappedTargetException.hpp"
54 #include "com/sun/star/lang/XComponent.hpp"
55 #include "com/sun/star/lang/XServiceInfo.hpp"
56 #include "com/sun/star/lang/XTypeProvider.hpp"
57 #include "com/sun/star/lang/XSingleServiceFactory.hpp"
58 #include "com/sun/star/uno/Exception.hpp"
59 #include "com/sun/star/uno/Reference.hxx"
60 #include "com/sun/star/uno/RuntimeException.hpp"
61 #include "com/sun/star/uno/Sequence.hxx"
62 #include "cppuhelper/weak.hxx"
63 #include "osl/interlck.h"
64 #include "rtl/ref.hxx"
65 #include "sal/types.h"
66 
67 #include "modifications.hxx"
68 #include "path.hxx"
69 #include "type.hxx"
70 
71 namespace com { namespace sun { namespace star {
72     namespace beans {
73         class XHierarchicalPropertySetInfo;
74         class XPropertiesChangeListener;
75         class XPropertyChangeListener;
76         class XVetoableChangeListener;
77         struct Property;
78     }
79     namespace container { class XContainerListener; }
80     namespace lang { class XEventListener; }
81     namespace uno {
82         class Any;
83         class Type;
84         class XInterface;
85     }
86     namespace util { struct ElementChange; }
87 } } }
88 namespace rtl { class OUString; }
89 
90 namespace configmgr {
91 
92 class Broadcaster;
93 class Change;
94 class ChildAccess;
95 class Components;
96 class Node;
97 class RootAccess;
98 
99 class Access:
100     public cppu::OWeakObject, public com::sun::star::lang::XTypeProvider,
101     public com::sun::star::lang::XServiceInfo,
102     public com::sun::star::lang::XComponent,
103     public com::sun::star::container::XHierarchicalNameAccess,
104     public com::sun::star::container::XContainer,
105     public com::sun::star::beans::XExactName,
106     public com::sun::star::beans::XPropertySetInfo,
107     public com::sun::star::container::XHierarchicalName,
108     public com::sun::star::container::XNamed,
109     public com::sun::star::beans::XProperty,
110     public com::sun::star::beans::XPropertySet,
111     public com::sun::star::beans::XMultiPropertySet,
112     public com::sun::star::beans::XHierarchicalPropertySet,
113     public com::sun::star::beans::XMultiHierarchicalPropertySet,
114     public com::sun::star::beans::XHierarchicalPropertySetInfo,
115     public com::sun::star::container::XNameContainer,
116     public com::sun::star::lang::XSingleServiceFactory,
117     private boost::noncopyable
118 {
119 public:
120     oslInterlockedCount acquireCounting();
121 
122     void releaseNondeleting();
123 
124     bool isValue();
125 
126     void markChildAsModified(rtl::Reference< ChildAccess > const & child);
127 
128     void releaseChild(rtl::OUString const & name);
129 
130     virtual Path getAbsolutePath() = 0;
131 
132     virtual Path getRelativePath() = 0;
133 
134     virtual rtl::OUString getRelativePathRepresentation() = 0;
135 
136     virtual rtl::Reference< Node > getNode() = 0;
137 
138     virtual bool isFinalized() = 0;
139 
140     virtual void initBroadcaster(
141         Modifications::Node const & modifications, Broadcaster * broadcaster);
142 
143     using OWeakObject::acquire;
144     using OWeakObject::release;
145 
146 protected:
147     Access(Components & components);
148 
149     virtual ~Access();
150 
151     virtual rtl::OUString getNameInternal() = 0;
152 
153     virtual rtl::Reference< RootAccess > getRootAccess() = 0;
154 
155     virtual rtl::Reference< Access > getParentAccess() = 0;
156 
157     virtual void addTypes(std::vector< com::sun::star::uno::Type > * types)
158         const = 0;
159 
160     virtual void addSupportedServiceNames(
161         std::vector< rtl::OUString > * services) = 0;
162 
163     virtual void initDisposeBroadcaster(Broadcaster * broadcaster);
164 
165     virtual void clearListeners() throw ();
166 
167     virtual com::sun::star::uno::Any SAL_CALL queryInterface(
168         com::sun::star::uno::Type const & aType)
169         throw (com::sun::star::uno::RuntimeException);
170 
171     Components & getComponents() const;
172 
173     void checkLocalizedPropertyAccess();
174 
175     rtl::Reference< Node > getParentNode();
176 
177     rtl::Reference< ChildAccess > getChild(rtl::OUString const & name);
178 
179     std::vector< rtl::Reference< ChildAccess > > getAllChildren();
180 
181     void checkValue(
182         com::sun::star::uno::Any const & value, Type type, bool nillable);
183 
184     void insertLocalizedValueChild(
185         rtl::OUString const & name, com::sun::star::uno::Any const & value,
186         Modifications * localModifications);
187 
188     void reportChildChanges(
189         std::vector< com::sun::star::util::ElementChange > * changes);
190 
191     void commitChildChanges(bool valid, Modifications * globalModifications);
192 
193     void initBroadcasterAndChanges(
194         Modifications::Node const & modifications, Broadcaster * broadcaster,
195         std::vector< com::sun::star::util::ElementChange > * changes);
196 
197     bool isDisposed() const;
198 
199 private:
200     struct ModifiedChild {
201         rtl::Reference< ChildAccess > child;
202         bool directlyModified;
203 
204         ModifiedChild();
205 
206         ModifiedChild(
207             rtl::Reference< ChildAccess > const & theChild,
208             bool theDirectlyModified);
209     };
210 
211     typedef std::map< rtl::OUString, ModifiedChild > ModifiedChildren;
212 
213     virtual com::sun::star::uno::Sequence< com::sun::star::uno::Type > SAL_CALL
214     getTypes() throw (com::sun::star::uno::RuntimeException);
215 
216     virtual com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL
217     getImplementationId() throw (com::sun::star::uno::RuntimeException);
218 
219     virtual rtl::OUString SAL_CALL getImplementationName()
220         throw (com::sun::star::uno::RuntimeException);
221 
222     virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & ServiceName)
223         throw (com::sun::star::uno::RuntimeException);
224 
225     virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL
226     getSupportedServiceNames() throw (com::sun::star::uno::RuntimeException);
227 
228     virtual void SAL_CALL dispose()
229         throw (com::sun::star::uno::RuntimeException);
230 
231     virtual void SAL_CALL addEventListener(
232         com::sun::star::uno::Reference< com::sun::star::lang::XEventListener >
233             const & xListener)
234         throw (com::sun::star::uno::RuntimeException);
235 
236     virtual void SAL_CALL removeEventListener(
237         com::sun::star::uno::Reference< com::sun::star::lang::XEventListener >
238             const & aListener)
239         throw (com::sun::star::uno::RuntimeException);
240 
241     virtual com::sun::star::uno::Type SAL_CALL getElementType()
242         throw (com::sun::star::uno::RuntimeException);
243 
244     virtual sal_Bool SAL_CALL hasElements()
245         throw (com::sun::star::uno::RuntimeException);
246 
247     virtual com::sun::star::uno::Any SAL_CALL getByName(
248         rtl::OUString const & aName)
249         throw (
250             com::sun::star::container::NoSuchElementException,
251             com::sun::star::lang::WrappedTargetException,
252             com::sun::star::uno::RuntimeException);
253 
254     virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL
255     getElementNames() throw (com::sun::star::uno::RuntimeException);
256 
257     virtual sal_Bool SAL_CALL hasByName(rtl::OUString const & aName)
258         throw (com::sun::star::uno::RuntimeException);
259 
260     virtual com::sun::star::uno::Any SAL_CALL getByHierarchicalName(
261         rtl::OUString const & aName)
262         throw (
263             com::sun::star::container::NoSuchElementException,
264             com::sun::star::uno::RuntimeException);
265 
266     virtual sal_Bool SAL_CALL hasByHierarchicalName(rtl::OUString const & aName)
267         throw (com::sun::star::uno::RuntimeException);
268 
269     virtual void SAL_CALL addContainerListener(
270         com::sun::star::uno::Reference<
271             com::sun::star::container::XContainerListener > const & xListener)
272         throw (com::sun::star::uno::RuntimeException);
273 
274     virtual void SAL_CALL removeContainerListener(
275         com::sun::star::uno::Reference<
276             com::sun::star::container::XContainerListener > const & xListener)
277         throw (com::sun::star::uno::RuntimeException);
278 
279     virtual rtl::OUString SAL_CALL getExactName(
280         rtl::OUString const & aApproximateName)
281         throw (com::sun::star::uno::RuntimeException);
282 
283     virtual com::sun::star::uno::Sequence< com::sun::star::beans::Property >
284     SAL_CALL getProperties() throw (com::sun::star::uno::RuntimeException);
285 
286     virtual com::sun::star::beans::Property SAL_CALL getPropertyByName(
287         rtl::OUString const & aName)
288         throw (
289             com::sun::star::beans::UnknownPropertyException,
290             com::sun::star::uno::RuntimeException);
291 
292     virtual sal_Bool SAL_CALL hasPropertyByName(rtl::OUString const & Name)
293         throw (com::sun::star::uno::RuntimeException);
294 
295     virtual rtl::OUString SAL_CALL getHierarchicalName()
296         throw (com::sun::star::uno::RuntimeException);
297 
298     virtual rtl::OUString SAL_CALL composeHierarchicalName(
299         rtl::OUString const & aRelativeName)
300         throw (
301             com::sun::star::lang::IllegalArgumentException,
302             com::sun::star::lang::NoSupportException,
303             com::sun::star::uno::RuntimeException);
304 
305     virtual rtl::OUString SAL_CALL getName()
306         throw (com::sun::star::uno::RuntimeException);
307 
308     virtual void SAL_CALL setName(rtl::OUString const & aName)
309         throw (com::sun::star::uno::RuntimeException);
310 
311     virtual com::sun::star::beans::Property SAL_CALL getAsProperty()
312         throw (com::sun::star::uno::RuntimeException);
313 
314     virtual
315     com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo >
316     SAL_CALL getPropertySetInfo() throw (com::sun::star::uno::RuntimeException);
317 
318     virtual void SAL_CALL setPropertyValue(
319         rtl::OUString const & aPropertyName,
320         com::sun::star::uno::Any const & aValue)
321         throw (
322             com::sun::star::beans::UnknownPropertyException,
323             com::sun::star::beans::PropertyVetoException,
324             com::sun::star::lang::IllegalArgumentException,
325             com::sun::star::lang::WrappedTargetException,
326             com::sun::star::uno::RuntimeException);
327 
328     virtual com::sun::star::uno::Any SAL_CALL getPropertyValue(
329         rtl::OUString const & PropertyName)
330         throw (
331             com::sun::star::beans::UnknownPropertyException,
332             com::sun::star::lang::WrappedTargetException,
333             com::sun::star::uno::RuntimeException);
334 
335     virtual void SAL_CALL addPropertyChangeListener(
336         rtl::OUString const & aPropertyName,
337         com::sun::star::uno::Reference<
338             com::sun::star::beans::XPropertyChangeListener > const & xListener)
339         throw (
340             com::sun::star::beans::UnknownPropertyException,
341             com::sun::star::lang::WrappedTargetException,
342             com::sun::star::uno::RuntimeException);
343 
344     virtual void SAL_CALL removePropertyChangeListener(
345         rtl::OUString const & aPropertyName,
346         com::sun::star::uno::Reference<
347             com::sun::star::beans::XPropertyChangeListener > const & aListener)
348         throw (
349             com::sun::star::beans::UnknownPropertyException,
350             com::sun::star::lang::WrappedTargetException,
351             com::sun::star::uno::RuntimeException);
352 
353     virtual void SAL_CALL addVetoableChangeListener(
354         rtl::OUString const & PropertyName,
355         com::sun::star::uno::Reference<
356             com::sun::star::beans::XVetoableChangeListener > const & aListener)
357         throw (
358             com::sun::star::beans::UnknownPropertyException,
359             com::sun::star::lang::WrappedTargetException,
360             com::sun::star::uno::RuntimeException);
361 
362     virtual void SAL_CALL removeVetoableChangeListener(
363         rtl::OUString const & PropertyName,
364         com::sun::star::uno::Reference<
365             com::sun::star::beans::XVetoableChangeListener > const & aListener)
366         throw (
367             com::sun::star::beans::UnknownPropertyException,
368             com::sun::star::lang::WrappedTargetException,
369             com::sun::star::uno::RuntimeException);
370 
371     virtual void SAL_CALL setPropertyValues(
372         com::sun::star::uno::Sequence< rtl::OUString > const & aPropertyNames,
373         com::sun::star::uno::Sequence< com::sun::star::uno::Any > const &
374             aValues)
375         throw (
376             com::sun::star::beans::PropertyVetoException,
377             com::sun::star::lang::IllegalArgumentException,
378             com::sun::star::lang::WrappedTargetException,
379             com::sun::star::uno::RuntimeException);
380 
381     virtual com::sun::star::uno::Sequence< com::sun::star::uno::Any > SAL_CALL
382     getPropertyValues(
383         com::sun::star::uno::Sequence< rtl::OUString > const & aPropertyNames)
384         throw (com::sun::star::uno::RuntimeException);
385 
386     virtual void SAL_CALL addPropertiesChangeListener(
387         com::sun::star::uno::Sequence< rtl::OUString > const & aPropertyNames,
388         com::sun::star::uno::Reference<
389             com::sun::star::beans::XPropertiesChangeListener > const &
390                 xListener)
391         throw (com::sun::star::uno::RuntimeException);
392 
393     virtual void SAL_CALL removePropertiesChangeListener(
394         com::sun::star::uno::Reference<
395             com::sun::star::beans::XPropertiesChangeListener > const &
396                 xListener)
397         throw (com::sun::star::uno::RuntimeException);
398 
399     virtual void SAL_CALL firePropertiesChangeEvent(
400         com::sun::star::uno::Sequence< rtl::OUString > const & aPropertyNames,
401         com::sun::star::uno::Reference<
402             com::sun::star::beans::XPropertiesChangeListener > const &
403                 xListener)
404         throw (com::sun::star::uno::RuntimeException);
405 
406     virtual
407     com::sun::star::uno::Reference<
408         com::sun::star::beans::XHierarchicalPropertySetInfo > SAL_CALL
409     getHierarchicalPropertySetInfo()
410         throw (com::sun::star::uno::RuntimeException);
411 
412     virtual void SAL_CALL setHierarchicalPropertyValue(
413         rtl::OUString const & aHierarchicalPropertyName,
414         com::sun::star::uno::Any const & aValue)
415         throw (
416             com::sun::star::beans::UnknownPropertyException,
417             com::sun::star::beans::PropertyVetoException,
418             com::sun::star::lang::IllegalArgumentException,
419             com::sun::star::lang::WrappedTargetException,
420             com::sun::star::uno::RuntimeException);
421 
422     virtual com::sun::star::uno::Any SAL_CALL getHierarchicalPropertyValue(
423         rtl::OUString const & aHierarchicalPropertyName)
424         throw (
425             com::sun::star::beans::UnknownPropertyException,
426             com::sun::star::lang::IllegalArgumentException,
427             com::sun::star::lang::WrappedTargetException,
428             com::sun::star::uno::RuntimeException);
429 
430     virtual void SAL_CALL setHierarchicalPropertyValues(
431         com::sun::star::uno::Sequence< rtl::OUString > const &
432             aHierarchicalPropertyNames,
433         com::sun::star::uno::Sequence< com::sun::star::uno::Any > const &
434             Values)
435         throw (
436             com::sun::star::beans::PropertyVetoException,
437             com::sun::star::lang::IllegalArgumentException,
438             com::sun::star::lang::WrappedTargetException,
439             com::sun::star::uno::RuntimeException);
440 
441     virtual com::sun::star::uno::Sequence< com::sun::star::uno::Any > SAL_CALL
442     getHierarchicalPropertyValues(
443         com::sun::star::uno::Sequence< rtl::OUString > const &
444             aHierarchicalPropertyNames)
445         throw (
446             com::sun::star::lang::IllegalArgumentException,
447             com::sun::star::lang::WrappedTargetException,
448             com::sun::star::uno::RuntimeException);
449 
450     virtual com::sun::star::beans::Property SAL_CALL
451     getPropertyByHierarchicalName(rtl::OUString const & aHierarchicalName)
452         throw (
453             com::sun::star::beans::UnknownPropertyException,
454             com::sun::star::uno::RuntimeException);
455 
456     virtual sal_Bool SAL_CALL hasPropertyByHierarchicalName(
457         rtl::OUString const & aHierarchicalName)
458         throw (com::sun::star::uno::RuntimeException);
459 
460     virtual void SAL_CALL replaceByName(
461         rtl::OUString const & aName, com::sun::star::uno::Any const & aElement)
462         throw (
463             com::sun::star::lang::IllegalArgumentException,
464             com::sun::star::container::NoSuchElementException,
465             com::sun::star::lang::WrappedTargetException,
466             com::sun::star::uno::RuntimeException);
467 
468     virtual void SAL_CALL insertByName(
469         rtl::OUString const & aName, com::sun::star::uno::Any const & aElement)
470         throw (
471             com::sun::star::lang::IllegalArgumentException,
472             com::sun::star::container::ElementExistException,
473             com::sun::star::lang::WrappedTargetException,
474             com::sun::star::uno::RuntimeException);
475 
476     virtual void SAL_CALL removeByName(rtl::OUString const & aName)
477         throw (
478             com::sun::star::container::NoSuchElementException,
479             com::sun::star::lang::WrappedTargetException,
480             com::sun::star::uno::RuntimeException);
481 
482     virtual com::sun::star::uno::Reference< com::sun::star::uno::XInterface >
483     SAL_CALL createInstance()
484         throw (
485             com::sun::star::uno::Exception,
486             com::sun::star::uno::RuntimeException);
487 
488     virtual com::sun::star::uno::Reference< com::sun::star::uno::XInterface >
489     SAL_CALL createInstanceWithArguments(
490         com::sun::star::uno::Sequence< com::sun::star::uno::Any > const &
491             aArguments)
492         throw (
493             com::sun::star::uno::Exception,
494             com::sun::star::uno::RuntimeException);
495 
496     rtl::Reference< ChildAccess > getModifiedChild(
497         ModifiedChildren::iterator const & childIterator);
498 
499     rtl::Reference< ChildAccess > getUnmodifiedChild(
500         rtl::OUString const & name);
501 
502     rtl::Reference< ChildAccess > getSubChild(rtl::OUString const & path);
503 
504     bool setChildProperty(
505         rtl::OUString const & name, com::sun::star::uno::Any const & value,
506         Modifications * localModifications);
507 
508     com::sun::star::beans::Property asProperty();
509 
510     void checkFinalized();
511 
512     void checkKnownProperty(rtl::OUString const & descriptor);
513 
514     rtl::Reference< ChildAccess > getFreeSetMember(
515         com::sun::star::uno::Any const & value);
516 
517     rtl::Reference< Access > getNotificationRoot();
518 
519     typedef std::map< rtl::OUString, ChildAccess * > WeakChildMap;
520 
521     typedef
522         std::multiset<
523             com::sun::star::uno::Reference<
524                 com::sun::star::lang::XEventListener > >
525         DisposeListeners;
526 
527     typedef
528         std::multiset<
529             com::sun::star::uno::Reference<
530                 com::sun::star::container::XContainerListener > >
531         ContainerListeners;
532 
533     typedef
534         std::multiset<
535             com::sun::star::uno::Reference<
536                 com::sun::star::beans::XPropertyChangeListener > >
537         PropertyChangeListenersElement;
538 
539     typedef std::map< rtl::OUString, PropertyChangeListenersElement >
540         PropertyChangeListeners;
541 
542     typedef
543         std::multiset<
544             com::sun::star::uno::Reference<
545                 com::sun::star::beans::XVetoableChangeListener > >
546         VetoableChangeListenersElement;
547 
548     typedef std::map< rtl::OUString, VetoableChangeListenersElement >
549         VetoableChangeListeners;
550 
551     typedef
552         std::multiset<
553             com::sun::star::uno::Reference<
554                 com::sun::star::beans::XPropertiesChangeListener > >
555         PropertiesChangeListeners;
556 
557     Components & components_;
558     ModifiedChildren modifiedChildren_;
559     WeakChildMap cachedChildren_;
560     DisposeListeners disposeListeners_;
561     ContainerListeners containerListeners_;
562     PropertyChangeListeners propertyChangeListeners_;
563     VetoableChangeListeners vetoableChangeListeners_;
564     PropertiesChangeListeners propertiesChangeListeners_;
565     bool disposed_;
566 
567 #if OSL_DEBUG_LEVEL > 0
568 protected:
569     enum {
570         IS_ANY = 0, IS_GROUP = 0x01, IS_SET = 0x02, IS_EXTENSIBLE = 0x04,
571         IS_GROUP_MEMBER = 0x08, IS_SET_MEMBER = 0x10, IS_UPDATE = 0x20 };
572     bool thisIs(int what);
573 #endif
574 };
575 
576 }
577 
578 #endif
579