1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
/**************************************************************************
TODO
**************************************************************************
Note: Configuration Management classes do not support XAggregation.
So I have to wrap the interesting interfaces manually.
*************************************************************************/
#include "hierarchydatasource.hxx"
#include <osl/diagnose.h>
#include "osl/doublecheckedlocking.h"
#include <cppuhelper/interfacecontainer.hxx>
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/container/XHierarchicalNameAccess.hpp>
#include <com/sun/star/container/XNameContainer.hpp>
#include <com/sun/star/util/XChangesBatch.hpp>
#include <com/sun/star/util/XChangesNotifier.hpp>
using namespace com::sun::star;
using namespace hierarchy_ucp;
//=========================================================================
// describe path of cfg entry
#define CFGPROPERTY_NODEPATH "nodepath"
// true->async. update; false->sync. update
#define CFGPROPERTY_LAZYWRITE "lazywrite"
#define READ_SERVICE_NAME "com.sun.star.ucb.HierarchyDataReadAccess"
#define READWRITE_SERVICE_NAME "com.sun.star.ucb.HierarchyDataReadWriteAccess"
#define CONFIG_PROVIDER_SERVICE_NAME \
"com.sun.star.configuration.ConfigurationProvider"
#define CONFIG_READ_SERVICE_NAME \
"com.sun.star.configuration.ConfigurationAccess"
#define CONFIG_READWRITE_SERVICE_NAME \
"com.sun.star.configuration.ConfigurationUpdateAccess"
#define CONFIG_DATA_ROOT_KEY \
"/org.openoffice.ucb.Hierarchy/Root"
//=========================================================================
namespace hcp_impl
{
//=========================================================================
//
// HierarchyDataReadAccess Implementation.
//
//=========================================================================
class HierarchyDataAccess : public cppu::OWeakObject,
public lang::XServiceInfo,
public lang::XTypeProvider,
public lang::XComponent,
public lang::XSingleServiceFactory,
public container::XHierarchicalNameAccess,
public container::XNameContainer,
public util::XChangesNotifier,
public util::XChangesBatch
{
osl::Mutex m_aMutex;
uno::Reference< uno::XInterface > m_xConfigAccess;
uno::Reference< lang::XComponent > m_xCfgC;
uno::Reference< lang::XSingleServiceFactory > m_xCfgSSF;
uno::Reference< container::XHierarchicalNameAccess > m_xCfgHNA;
uno::Reference< container::XNameContainer > m_xCfgNC;
uno::Reference< container::XNameReplace > m_xCfgNR;
uno::Reference< container::XNameAccess > m_xCfgNA;
uno::Reference< container::XElementAccess > m_xCfgEA;
uno::Reference< util::XChangesNotifier > m_xCfgCN;
uno::Reference< util::XChangesBatch > m_xCfgCB;
bool m_bReadOnly;
public:
HierarchyDataAccess( const uno::Reference<
uno::XInterface > & xConfigAccess,
bool bReadOnly );
virtual ~HierarchyDataAccess();
// XInterface
XINTERFACE_DECL()
// XServiceInfo
XSERVICEINFO_DECL()
// XTypeProvider
XTYPEPROVIDER_DECL()
// XComponent
virtual void SAL_CALL
dispose()
throw ( uno::RuntimeException );
virtual void SAL_CALL
addEventListener( const uno::Reference< lang::XEventListener > & xListener )
throw ( uno::RuntimeException );
virtual void SAL_CALL
removeEventListener( const uno::Reference<
lang::XEventListener > & aListener )
throw ( uno::RuntimeException );
// XSingleServiceFactory
virtual uno::Reference< uno::XInterface > SAL_CALL
createInstance()
throw ( uno::Exception, uno::RuntimeException );
virtual uno::Reference< uno::XInterface > SAL_CALL
createInstanceWithArguments( const uno::Sequence< uno::Any > & aArguments )
throw ( uno::Exception, uno::RuntimeException );
// XHierarchicalNameAccess
virtual uno::Any SAL_CALL
getByHierarchicalName( const rtl::OUString & aName )
throw ( container::NoSuchElementException, uno::RuntimeException );
virtual sal_Bool SAL_CALL
hasByHierarchicalName( const rtl::OUString & aName )
throw ( uno::RuntimeException );
// XNameContainer
virtual void SAL_CALL
insertByName( const rtl::OUString & aName, const uno::Any & aElement )
throw ( lang::IllegalArgumentException,
container::ElementExistException,
lang::WrappedTargetException,
uno::RuntimeException );
virtual void SAL_CALL
removeByName( const rtl::OUString & Name )
throw ( container::NoSuchElementException,
lang::WrappedTargetException,
uno::RuntimeException );
// XNameReplace ( base of XNameContainer )
virtual void SAL_CALL
replaceByName( const rtl::OUString & aName, const uno::Any & aElement )
throw ( lang::IllegalArgumentException,
container::NoSuchElementException,
lang::WrappedTargetException,
uno::RuntimeException );
// XNameAccess ( base of XNameReplace )
virtual uno::Any SAL_CALL
getByName( const rtl::OUString & aName )
throw ( container::NoSuchElementException,
lang::WrappedTargetException,
uno::RuntimeException );
virtual uno::Sequence< rtl::OUString > SAL_CALL
getElementNames()
throw ( uno::RuntimeException );
virtual sal_Bool SAL_CALL
hasByName( const rtl::OUString & aName )
throw ( uno::RuntimeException );
// XElementAccess ( base of XNameAccess )
virtual uno::Type SAL_CALL
getElementType()
throw ( uno::RuntimeException );
virtual sal_Bool SAL_CALL
hasElements()
throw ( uno::RuntimeException );
// XChangesNotifier
virtual void SAL_CALL
addChangesListener( const uno::Reference<
util::XChangesListener > & aListener )
throw ( uno::RuntimeException );
virtual void SAL_CALL
removeChangesListener( const uno::Reference<
util::XChangesListener > & aListener )
throw ( uno::RuntimeException );
// XChangesBatch
virtual void SAL_CALL
commitChanges()
throw ( lang::WrappedTargetException, uno::RuntimeException );
virtual sal_Bool SAL_CALL
hasPendingChanges()
throw ( uno::RuntimeException );
virtual uno::Sequence< util::ElementChange > SAL_CALL
getPendingChanges()
throw ( uno::RuntimeException );
};
} // namespace hcp_impl
using namespace hcp_impl;
//=========================================================================
//=========================================================================
//
// HierarchyDataSource Implementation.
//
//=========================================================================
//=========================================================================
HierarchyDataSource::HierarchyDataSource(
const uno::Reference< lang::XMultiServiceFactory > & rxServiceMgr )
: m_xSMgr( rxServiceMgr ),
m_pDisposeEventListeners( 0 )
{
}
//=========================================================================
// virtual
HierarchyDataSource::~HierarchyDataSource()
{
delete m_pDisposeEventListeners;
}
//=========================================================================
//
// XInterface methods.
//
//=========================================================================
XINTERFACE_IMPL_4( HierarchyDataSource,
lang::XTypeProvider,
lang::XServiceInfo,
lang::XComponent,
lang::XMultiServiceFactory );
//=========================================================================
//
// XTypeProvider methods.
//
//=========================================================================
XTYPEPROVIDER_IMPL_4( HierarchyDataSource,
lang::XTypeProvider,
lang::XServiceInfo,
lang::XComponent,
lang::XMultiServiceFactory );
//=========================================================================
//
// XServiceInfo methods.
//
//=========================================================================
XSERVICEINFO_IMPL_0( HierarchyDataSource,
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
"com.sun.star.comp.ucb.HierarchyDataSource" )) )
{
uno::Sequence< rtl::OUString > aSNS( 2 );
aSNS[ 0 ] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
"com.sun.star.ucb.DefaultHierarchyDataSource" ));
aSNS[ 1 ] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
"com.sun.star.ucb.HierarchyDataSource" ));
return aSNS;
}
ONE_INSTANCE_SERVICE_FACTORY_IMPL( HierarchyDataSource );
//=========================================================================
//
// XComponent methods.
//
//=========================================================================
// virtual
void SAL_CALL HierarchyDataSource::dispose()
throw( uno::RuntimeException )
{
osl::Guard< osl::Mutex > aGuard( m_aMutex );
if ( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() )
{
lang::EventObject aEvt;
aEvt.Source = static_cast< lang::XComponent * >( this );
m_pDisposeEventListeners->disposeAndClear( aEvt );
}
}
//=========================================================================
// virtual
void SAL_CALL HierarchyDataSource::addEventListener(
const uno::Reference< lang::XEventListener > & Listener )
throw( uno::RuntimeException )
{
osl::Guard< osl::Mutex > aGuard( m_aMutex );
if ( !m_pDisposeEventListeners )
m_pDisposeEventListeners
= new cppu::OInterfaceContainerHelper( m_aMutex );
m_pDisposeEventListeners->addInterface( Listener );
}
//=========================================================================
// virtual
void SAL_CALL HierarchyDataSource::removeEventListener(
const uno::Reference< lang::XEventListener > & Listener )
throw( uno::RuntimeException )
{
osl::Guard< osl::Mutex > aGuard( m_aMutex );
if ( m_pDisposeEventListeners )
m_pDisposeEventListeners->removeInterface( Listener );
}
//=========================================================================
//
// XMultiServiceFactory methods.
//
//=========================================================================
// virtual
uno::Reference< uno::XInterface > SAL_CALL
HierarchyDataSource::createInstance( const rtl::OUString & aServiceSpecifier )
throw ( uno::Exception, uno::RuntimeException )
{
// Create view to root node.
beans::PropertyValue aProp;
aProp.Name = rtl::OUString(
RTL_CONSTASCII_USTRINGPARAM( CFGPROPERTY_NODEPATH ) );
aProp.Value <<=
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CONFIG_DATA_ROOT_KEY ) );
uno::Sequence< uno::Any > aArguments( 1 );
aArguments[ 0 ] <<= aProp;
return createInstanceWithArguments( aServiceSpecifier, aArguments, false );
}
//=========================================================================
// virtual
uno::Reference< uno::XInterface > SAL_CALL
HierarchyDataSource::createInstanceWithArguments(
const rtl::OUString & ServiceSpecifier,
const uno::Sequence< uno::Any > & Arguments )
throw ( uno::Exception, uno::RuntimeException )
{
return createInstanceWithArguments( ServiceSpecifier, Arguments, true );
}
//=========================================================================
// virtual
uno::Sequence< rtl::OUString > SAL_CALL
HierarchyDataSource::getAvailableServiceNames()
throw ( uno::RuntimeException )
{
uno::Sequence< rtl::OUString > aNames( 2 );
aNames[ 0 ] = rtl::OUString(
RTL_CONSTASCII_USTRINGPARAM( READ_SERVICE_NAME ) );
aNames[ 1 ] = rtl::OUString(
RTL_CONSTASCII_USTRINGPARAM( READWRITE_SERVICE_NAME ) );
return aNames;
}
//=========================================================================
//
// Non-interface methods
//
//=========================================================================
uno::Reference< uno::XInterface > SAL_CALL
HierarchyDataSource::createInstanceWithArguments(
const rtl::OUString & ServiceSpecifier,
const uno::Sequence< uno::Any > & Arguments,
bool bCheckArgs )
throw ( uno::Exception, uno::RuntimeException )
{
osl::Guard< osl::Mutex > aGuard( m_aMutex );
// Check service specifier.
bool bReadOnly = !!ServiceSpecifier.equalsAsciiL(
RTL_CONSTASCII_STRINGPARAM( READ_SERVICE_NAME ) );
bool bReadWrite = !bReadOnly &&
ServiceSpecifier.equalsAsciiL(
RTL_CONSTASCII_STRINGPARAM( READWRITE_SERVICE_NAME ) );
if ( !bReadOnly && !bReadWrite )
{
OSL_FAIL( "HierarchyDataSource::createInstanceWithArguments - "
"Unsupported service specifier!" );
return uno::Reference< uno::XInterface >();
}
uno::Sequence< uno::Any > aNewArgs( Arguments );
bool bHasLazyWriteProp = bReadOnly; // property must be added only if
// a writable view is requested.
if ( bCheckArgs )
{
// Check arguments.
bool bHasNodePath = false;
sal_Int32 nCount = Arguments.getLength();
for ( sal_Int32 n = 0; n < nCount; ++n )
{
beans::PropertyValue aProp;
if ( Arguments[ n ] >>= aProp )
{
if ( aProp.Name.equalsAsciiL(
RTL_CONSTASCII_STRINGPARAM( CFGPROPERTY_NODEPATH ) ) )
{
rtl::OUString aPath;
if ( aProp.Value >>= aPath )
{
bHasNodePath = true;
// Create path to data inside the configuration.
rtl::OUString aConfigPath;
if ( !createConfigPath( aPath, aConfigPath ) )
{
OSL_FAIL( "HierarchyDataSource::"
"createInstanceWithArguments - "
"Invalid node path!" );
return uno::Reference< uno::XInterface >();
}
aProp.Value <<= aConfigPath;
// Set new path in arguments.
aNewArgs[ n ] <<= aProp;
if ( bHasLazyWriteProp )
break;
}
else
{
OSL_FAIL( "HierarchyDataSource::createInstanceWithArguments - "
"Invalid type for property 'nodepath'!" );
return uno::Reference< uno::XInterface >();
}
}
else if ( aProp.Name.equalsAsciiL(
RTL_CONSTASCII_STRINGPARAM(
CFGPROPERTY_LAZYWRITE ) ) )
{
if ( aProp.Value.getValueType() == getCppuBooleanType() )
{
bHasLazyWriteProp = true;
if ( bHasNodePath )
break;
}
else
{
OSL_FAIL( "HierarchyDataSource::createInstanceWithArguments - "
"Invalid type for property 'lazywrite'!" );
return uno::Reference< uno::XInterface >();
}
}
}
}
if ( !bHasNodePath )
{
OSL_FAIL( "HierarchyDataSource::createInstanceWithArguments - "
"No 'nodepath' property!" );
return uno::Reference< uno::XInterface >();
}
}
// Create Configuration Provider.
uno::Reference< lang::XMultiServiceFactory > xProv = getConfigProvider();
if ( !xProv.is() )
return uno::Reference< uno::XInterface >();
uno::Reference< uno::XInterface > xConfigAccess;
try
{
if ( bReadOnly )
{
// Create configuration read-only access object.
xConfigAccess = xProv->createInstanceWithArguments(
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
CONFIG_READ_SERVICE_NAME ) ),
aNewArgs );
}
else
{
// Append 'lazywrite' property value, if not already present.
if ( !bHasLazyWriteProp )
{
sal_Int32 nLen = aNewArgs.getLength();
aNewArgs.realloc( nLen + 1 );
beans::PropertyValue aProp;
aProp.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
CFGPROPERTY_LAZYWRITE ) );
aProp.Value <<= sal_True;
aNewArgs[ nLen ] <<= aProp;
}
// Create configuration read-write access object.
xConfigAccess = xProv->createInstanceWithArguments(
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
CONFIG_READWRITE_SERVICE_NAME ) ),
aNewArgs );
}
}
catch ( uno::Exception const & )
{
OSL_FAIL( "HierarchyDataSource::createInstanceWithArguments - "
"Cannot instanciate configuration access!" );
throw;
}
if ( !xConfigAccess.is() )
{
OSL_FAIL( "HierarchyDataSource::createInstanceWithArguments - "
"Cannot instanciate configuration access!" );
return xConfigAccess;
}
return uno::Reference< uno::XInterface >(
static_cast< cppu::OWeakObject * >(
new HierarchyDataAccess( xConfigAccess, bReadOnly ) ) );
}
//=========================================================================
uno::Reference< lang::XMultiServiceFactory >
HierarchyDataSource::getConfigProvider()
{
if ( !m_xConfigProvider.is() )
{
osl::Guard< osl::Mutex > aGuard( m_aMutex );
if ( !m_xConfigProvider.is() )
{
try
{
m_xConfigProvider
= uno::Reference< lang::XMultiServiceFactory >(
m_xSMgr->createInstance(
rtl::OUString(
RTL_CONSTASCII_USTRINGPARAM(
CONFIG_PROVIDER_SERVICE_NAME ) ) ),
uno::UNO_QUERY );
OSL_ENSURE( m_xConfigProvider.is(),
"HierarchyDataSource::getConfigProvider - "
"No configuration provider!" );
}
catch ( uno::Exception const & )
{
OSL_FAIL( "HierarchyDataSource::getConfigProvider - "
"caught exception!" );
}
}
}
return m_xConfigProvider;
}
//=========================================================================
bool HierarchyDataSource::createConfigPath(
const rtl::OUString & rInPath, rtl::OUString & rOutPath )
{
if ( rInPath.getLength() )
{
if ( rInPath.indexOf( '/' ) == 0 )
{
OSL_FAIL( "HierarchyDataSource::createConfigPath - "
"Leading slash in node path!" );
return false;
}
if ( rInPath.lastIndexOf( '/' ) == rInPath.getLength() - 1 )
{
OSL_FAIL( "HierarchyDataSource::createConfigPath - "
"Trailing slash in node path!" );
return false;
}
rtl::OUString aOutPath(
RTL_CONSTASCII_USTRINGPARAM( CONFIG_DATA_ROOT_KEY "/" ) );
aOutPath += rInPath;
rOutPath = aOutPath;
}
else
{
rOutPath = rtl::OUString(
RTL_CONSTASCII_USTRINGPARAM( CONFIG_DATA_ROOT_KEY ) );
}
return true;
}
//=========================================================================
//=========================================================================
//
// HierarchyDataAccess Implementation.
//
//=========================================================================
//=========================================================================
#define ENSURE_ORIG_INTERFACE( interface_name, member_name ) \
m_xCfg##member_name; \
if ( !m_xCfg##member_name.is() ) \
{ \
osl::Guard< osl::Mutex > aGuard( m_aMutex ); \
if ( !m_xCfg##member_name.is() ) \
m_xCfg##member_name \
= uno::Reference< interface_name >( \
m_xConfigAccess, uno::UNO_QUERY ); \
xOrig = m_xCfg##member_name; \
}
//=========================================================================
HierarchyDataAccess::HierarchyDataAccess( const uno::Reference<
uno::XInterface > & xConfigAccess,
bool bReadOnly )
: m_xConfigAccess( xConfigAccess ),
m_bReadOnly( bReadOnly )
{
}
//=========================================================================
// virtual
HierarchyDataAccess::~HierarchyDataAccess()
{
}
//=========================================================================
//
// XInterface methods.
//
//=========================================================================
XINTERFACE_COMMON_IMPL( HierarchyDataAccess );
//=========================================================================
// virtual
uno::Any SAL_CALL HierarchyDataAccess::queryInterface( const uno::Type & aType )
throw ( uno::RuntimeException )
{
// Interfaces supported in read-only and read-write mode.
uno::Any aRet = cppu::queryInterface( aType,
static_cast< lang::XTypeProvider * >( this ),
static_cast< lang::XServiceInfo * >( this ),
static_cast< lang::XComponent * >( this ),
static_cast< container::XHierarchicalNameAccess * >( this ),
static_cast< container::XNameAccess * >( this ),
static_cast< container::XElementAccess * >( this ),
static_cast< util::XChangesNotifier * >( this ) );
// Interfaces supported only in read-write mode.
if ( !aRet.hasValue() && !m_bReadOnly )
{
aRet = cppu::queryInterface( aType,
static_cast< lang::XSingleServiceFactory * >( this ),
static_cast< container::XNameContainer * >( this ),
static_cast< container::XNameReplace * >( this ),
static_cast< util::XChangesBatch * >( this ) );
}
return aRet.hasValue() ? aRet : OWeakObject::queryInterface( aType );
}
//=========================================================================
//
// XTypeProvider methods.
//
//=========================================================================
XTYPEPROVIDER_COMMON_IMPL( HierarchyDataAccess );
//=========================================================================
// virtual
uno::Sequence< uno::Type > SAL_CALL HierarchyDataAccess::getTypes()
throw( uno::RuntimeException )
{
cppu::OTypeCollection * pCollection = 0;
if ( m_bReadOnly )
{
static cppu::OTypeCollection* pReadOnlyTypes = 0;
pCollection = pReadOnlyTypes;
if ( !pCollection )
{
osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
pCollection = pReadOnlyTypes;
if ( !pCollection )
{
static cppu::OTypeCollection aCollection(
CPPU_TYPE_REF( lang::XTypeProvider ),
CPPU_TYPE_REF( lang::XServiceInfo ),
CPPU_TYPE_REF( lang::XComponent ),
CPPU_TYPE_REF( container::XHierarchicalNameAccess ),
CPPU_TYPE_REF( container::XNameAccess ),
CPPU_TYPE_REF( util::XChangesNotifier ) );
pCollection = &aCollection;
OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
pReadOnlyTypes = pCollection;
}
}
else {
OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
}
}
else
{
static cppu::OTypeCollection* pReadWriteTypes = 0;
pCollection = pReadWriteTypes;
if ( !pCollection )
{
osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
pCollection = pReadWriteTypes;
if ( !pCollection )
{
static cppu::OTypeCollection aCollection(
CPPU_TYPE_REF( lang::XTypeProvider ),
CPPU_TYPE_REF( lang::XServiceInfo ),
CPPU_TYPE_REF( lang::XComponent ),
CPPU_TYPE_REF( lang::XSingleServiceFactory ),
CPPU_TYPE_REF( container::XHierarchicalNameAccess ),
CPPU_TYPE_REF( container::XNameContainer ),
CPPU_TYPE_REF( util::XChangesBatch ),
CPPU_TYPE_REF( util::XChangesNotifier ) );
pCollection = &aCollection;
OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
pReadWriteTypes = pCollection;
}
}
else {
OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
}
}
return (*pCollection).getTypes();
}
//=========================================================================
//
// XServiceInfo methods.
//
//=========================================================================
XSERVICEINFO_NOFACTORY_IMPL_0(
HierarchyDataAccess,
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
"com.sun.star.comp.ucb.HierarchyDataAccess" ) ) )
{
uno::Sequence< rtl::OUString > aSNS( 2 );
aSNS[ 0 ] = rtl::OUString(
RTL_CONSTASCII_USTRINGPARAM( READ_SERVICE_NAME ) );
aSNS[ 1 ] = rtl::OUString(
RTL_CONSTASCII_USTRINGPARAM( READWRITE_SERVICE_NAME ) );
return aSNS;
}
//=========================================================================
//
// XComponent methods.
//
//=========================================================================
// virtual
void SAL_CALL HierarchyDataAccess::dispose()
throw ( uno::RuntimeException )
{
uno::Reference< lang::XComponent > xOrig
= ENSURE_ORIG_INTERFACE( lang::XComponent, C );
OSL_ENSURE( xOrig.is(),
"HierarchyDataAccess : Data source is not an XComponent!" );
xOrig->dispose();
}
//=========================================================================
// virtual
void SAL_CALL HierarchyDataAccess::addEventListener(
const uno::Reference< lang::XEventListener > & xListener )
throw ( uno::RuntimeException )
{
uno::Reference< lang::XComponent > xOrig
= ENSURE_ORIG_INTERFACE( lang::XComponent, C );
OSL_ENSURE( xOrig.is(),
"HierarchyDataAccess : Data source is not an XComponent!" );
xOrig->addEventListener( xListener );
}
//=========================================================================
// virtual
void SAL_CALL HierarchyDataAccess::removeEventListener(
const uno::Reference< lang::XEventListener > & aListener )
throw ( uno::RuntimeException )
{
uno::Reference< lang::XComponent > xOrig
= ENSURE_ORIG_INTERFACE( lang::XComponent, C );
OSL_ENSURE( xOrig.is(),
"HierarchyDataAccess : Data source is not an XComponent!" );
xOrig->removeEventListener( aListener );
}
//=========================================================================
//
// XHierarchicalNameAccess methods.
//
//=========================================================================
// virtual
uno::Any SAL_CALL HierarchyDataAccess::getByHierarchicalName(
const rtl::OUString & aName )
throw ( container::NoSuchElementException, uno::RuntimeException )
{
uno::Reference< container::XHierarchicalNameAccess > xOrig
= ENSURE_ORIG_INTERFACE( container::XHierarchicalNameAccess, HNA );
OSL_ENSURE( xOrig.is(),
"HierarchyDataAccess : "
"Data source is not an XHierarchicalNameAccess!" );
return xOrig->getByHierarchicalName( aName );
}
//=========================================================================
// virtual
sal_Bool SAL_CALL HierarchyDataAccess::hasByHierarchicalName(
const rtl::OUString & aName )
throw ( uno::RuntimeException )
{
uno::Reference< container::XHierarchicalNameAccess > xOrig
= ENSURE_ORIG_INTERFACE( container::XHierarchicalNameAccess, HNA );
OSL_ENSURE( xOrig.is(),
"HierarchyDataAccess : "
"Data source is not an XHierarchicalNameAccess!" );
return xOrig->hasByHierarchicalName( aName );
}
//=========================================================================
//
// XNameAccess methods.
//
//=========================================================================
// virtual
uno::Any SAL_CALL HierarchyDataAccess::getByName( const rtl::OUString & aName )
throw ( container::NoSuchElementException,
lang::WrappedTargetException,
uno::RuntimeException )
{
uno::Reference< container::XNameAccess > xOrig
= ENSURE_ORIG_INTERFACE( container::XNameAccess, NA );
OSL_ENSURE( xOrig.is(),
"HierarchyDataAccess : Data source is not an XNameAccess!" );
return xOrig->getByName( aName );
}
//=========================================================================
// virtual
uno::Sequence< rtl::OUString > SAL_CALL HierarchyDataAccess::getElementNames()
throw ( uno::RuntimeException )
{
uno::Reference< container::XNameAccess > xOrig
= ENSURE_ORIG_INTERFACE( container::XNameAccess, NA );
OSL_ENSURE( xOrig.is(),
"HierarchyDataAccess : Data source is not an XNameAccess!" );
return xOrig->getElementNames();
}
//=========================================================================
// virtual
sal_Bool SAL_CALL HierarchyDataAccess::hasByName( const rtl::OUString & aName )
throw ( uno::RuntimeException )
{
uno::Reference< container::XNameAccess > xOrig
= ENSURE_ORIG_INTERFACE( container::XNameAccess, NA );
OSL_ENSURE( xOrig.is(),
"HierarchyDataAccess : Data source is not an XNameAccess!" );
return xOrig->hasByName( aName );
}
//=========================================================================
//
// XElementAccess methods.
//
//=========================================================================
// virtual
uno::Type SAL_CALL HierarchyDataAccess::getElementType()
throw ( uno::RuntimeException )
{
uno::Reference< container::XElementAccess > xOrig
= ENSURE_ORIG_INTERFACE( container::XElementAccess, EA );
OSL_ENSURE( xOrig.is(),
"HierarchyDataAccess : Data source is not an XElementAccess!" );
return xOrig->getElementType();
}
//=========================================================================
// virtual
sal_Bool SAL_CALL HierarchyDataAccess::hasElements()
throw ( uno::RuntimeException )
{
uno::Reference< container::XElementAccess > xOrig
= ENSURE_ORIG_INTERFACE( container::XElementAccess, EA );
OSL_ENSURE( xOrig.is(),
"HierarchyDataAccess : Data source is not an XElementAccess!" );
return xOrig->hasElements();
}
//=========================================================================
//
// XChangesNotifier methods.
//
//=========================================================================
// virtual
void SAL_CALL HierarchyDataAccess::addChangesListener(
const uno::Reference< util::XChangesListener > & aListener )
throw ( uno::RuntimeException )
{
uno::Reference< util::XChangesNotifier > xOrig
= ENSURE_ORIG_INTERFACE( util::XChangesNotifier, CN );
OSL_ENSURE( xOrig.is(),
"HierarchyDataAccess : Data source is not an XChangesNotifier!" );
xOrig->addChangesListener( aListener );
}
//=========================================================================
// virtual
void SAL_CALL HierarchyDataAccess::removeChangesListener(
const uno::Reference< util::XChangesListener > & aListener )
throw ( uno::RuntimeException )
{
uno::Reference< util::XChangesNotifier > xOrig
= ENSURE_ORIG_INTERFACE( util::XChangesNotifier, CN );
OSL_ENSURE( xOrig.is(),
"HierarchyDataAccess : Data source is not an XChangesNotifier!" );
xOrig->removeChangesListener( aListener );
}
//=========================================================================
//
// XSingleServiceFactory methods.
//
//=========================================================================
// virtual
uno::Reference< uno::XInterface > SAL_CALL HierarchyDataAccess::createInstance()
throw ( uno::Exception, uno::RuntimeException )
{
uno::Reference< lang::XSingleServiceFactory > xOrig
= ENSURE_ORIG_INTERFACE( lang::XSingleServiceFactory, SSF );
OSL_ENSURE( xOrig.is(),
"HierarchyDataAccess : Data source is not an XSingleServiceFactory!" );
return xOrig->createInstance();
}
//=========================================================================
// virtual
uno::Reference< uno::XInterface > SAL_CALL
HierarchyDataAccess::createInstanceWithArguments(
const uno::Sequence< uno::Any > & aArguments )
throw ( uno::Exception, uno::RuntimeException )
{
uno::Reference< lang::XSingleServiceFactory > xOrig
= ENSURE_ORIG_INTERFACE( lang::XSingleServiceFactory, SSF );
OSL_ENSURE( xOrig.is(),
"HierarchyDataAccess : Data source is not an XSingleServiceFactory!" );
return xOrig->createInstanceWithArguments( aArguments );
}
//=========================================================================
//
// XNameContainer methods.
//
//=========================================================================
// virtual
void SAL_CALL
HierarchyDataAccess::insertByName( const rtl::OUString & aName,
const uno::Any & aElement )
throw ( lang::IllegalArgumentException,
container::ElementExistException,
lang::WrappedTargetException,
uno::RuntimeException )
{
uno::Reference< container::XNameContainer > xOrig
= ENSURE_ORIG_INTERFACE( container::XNameContainer, NC );
OSL_ENSURE( xOrig.is(),
"HierarchyDataAccess : Data source is not an XNameContainer!" );
xOrig->insertByName( aName, aElement );
}
//=========================================================================
// virtual
void SAL_CALL
HierarchyDataAccess::removeByName( const rtl::OUString & Name )
throw ( container::NoSuchElementException,
lang::WrappedTargetException,
uno::RuntimeException )
{
uno::Reference< container::XNameContainer > xOrig
= ENSURE_ORIG_INTERFACE( container::XNameContainer, NC );
OSL_ENSURE( xOrig.is(),
"HierarchyDataAccess : Data source is not an XNameContainer!" );
xOrig->removeByName( Name );
}
//=========================================================================
//
// XNameReplace methods.
//
//=========================================================================
// virtual
void SAL_CALL HierarchyDataAccess::replaceByName( const rtl::OUString & aName,
const uno::Any & aElement )
throw ( lang::IllegalArgumentException,
container::NoSuchElementException,
lang::WrappedTargetException,
uno::RuntimeException )
{
uno::Reference< container::XNameReplace > xOrig
= ENSURE_ORIG_INTERFACE( container::XNameReplace, NR );
OSL_ENSURE( xOrig.is(),
"HierarchyDataAccess : Data source is not an XNameReplace!" );
xOrig->replaceByName( aName, aElement );
}
//=========================================================================
//
// XChangesBatch methods.
//
//=========================================================================
// virtual
void SAL_CALL HierarchyDataAccess::commitChanges()
throw ( lang::WrappedTargetException, uno::RuntimeException )
{
uno::Reference< util::XChangesBatch > xOrig
= ENSURE_ORIG_INTERFACE( util::XChangesBatch, CB );
OSL_ENSURE( xOrig.is(),
"HierarchyDataAccess : Data source is not an XChangesBatch!" );
xOrig->commitChanges();
}
//=========================================================================
// virtual
sal_Bool SAL_CALL HierarchyDataAccess::hasPendingChanges()
throw ( uno::RuntimeException )
{
uno::Reference< util::XChangesBatch > xOrig
= ENSURE_ORIG_INTERFACE( util::XChangesBatch, CB );
OSL_ENSURE( xOrig.is(),
"HierarchyDataAccess : Data source is not an XChangesBatch!" );
return xOrig->hasPendingChanges();
}
//=========================================================================
// virtual
uno::Sequence< util::ElementChange > SAL_CALL
HierarchyDataAccess::getPendingChanges()
throw ( uno::RuntimeException )
{
uno::Reference< util::XChangesBatch > xOrig
= ENSURE_ORIG_INTERFACE( util::XChangesBatch, CB );
OSL_ENSURE( xOrig.is(),
"HierarchyDataAccess : Data source is not an XChangesBatch!" );
return xOrig->getPendingChanges();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|