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