| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* This file is part of the LibreOffice project. |
| 4 |
* |
| 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/. |
| 8 |
* |
| 9 |
* This file incorporates work covered by the following license notice: |
| 10 |
* |
| 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 . |
| 18 |
*/ |
| 19 |
|
| 20 |
|
| 21 |
/************************************************************************** |
| 22 |
TODO |
| 23 |
************************************************************************** |
| 24 |
|
| 25 |
Note: Configuration Management classes do not support XAggregation. |
| 26 |
So I have to wrap the interesting interfaces manually. |
| 27 |
|
| 28 |
*************************************************************************/ |
| 29 |
#include "hierarchydatasource.hxx" |
| 30 |
#include <osl/diagnose.h> |
| 31 |
|
| 32 |
#include <comphelper/propertyvalue.hxx> |
| 33 |
#include <cppuhelper/queryinterface.hxx> |
| 34 |
#include <cppuhelper/weak.hxx> |
| 35 |
#include <com/sun/star/beans/PropertyValue.hpp> |
| 36 |
#include <com/sun/star/configuration/theDefaultProvider.hpp> |
| 37 |
#include <com/sun/star/container/XHierarchicalNameAccess.hpp> |
| 38 |
#include <com/sun/star/container/XNameContainer.hpp> |
| 39 |
#include <com/sun/star/util/XChangesBatch.hpp> |
| 40 |
#include <com/sun/star/util/XChangesNotifier.hpp> |
| 41 |
#include <com/sun/star/lang/XSingleServiceFactory.hpp> |
| 42 |
#include <o3tl/string_view.hxx> |
| 43 |
#include <ucbhelper/macros.hxx> |
| 44 |
#include <mutex> |
| 45 |
#include <utility> |
| 46 |
|
| 47 |
using namespace com::sun::star; |
| 48 |
using namespace hierarchy_ucp; |
| 49 |
|
| 50 |
|
| 51 |
// describe path of cfg entry |
| 52 |
constexpr OUString CFGPROPERTY_NODEPATH = u"nodepath"_ustr; |
| 53 |
|
| 54 |
constexpr OUString READ_SERVICE_NAME = u"com.sun.star.ucb.HierarchyDataReadAccess"_ustr; |
| 55 |
constexpr OUString READWRITE_SERVICE_NAME = u"com.sun.star.ucb.HierarchyDataReadWriteAccess"_ustr; |
| 56 |
|
| 57 |
constexpr OUString CONFIG_DATA_ROOT_KEY = u"/org.openoffice.ucb.Hierarchy/Root"_ustr; |
| 58 |
|
| 59 |
|
| 60 |
namespace hcp_impl |
| 61 |
{ |
| 62 |
|
| 63 |
|
| 64 |
// HierarchyDataReadAccess Implementation. |
| 65 |
|
| 66 |
namespace { |
| 67 |
|
| 68 |
class HierarchyDataAccess : public cppu::OWeakObject, |
| 69 |
public lang::XServiceInfo, |
| 70 |
public lang::XTypeProvider, |
| 71 |
public lang::XComponent, |
| 72 |
public lang::XSingleServiceFactory, |
| 73 |
public container::XHierarchicalNameAccess, |
| 74 |
public container::XNameContainer, |
| 75 |
public util::XChangesNotifier, |
| 76 |
public util::XChangesBatch |
| 77 |
{ |
| 78 |
std::mutex m_aMutex; |
| 79 |
uno::Reference< uno::XInterface > m_xConfigAccess; |
| 80 |
uno::Reference< lang::XComponent > m_xCfgC; |
| 81 |
uno::Reference< lang::XSingleServiceFactory > m_xCfgSSF; |
| 82 |
uno::Reference< container::XHierarchicalNameAccess > m_xCfgHNA; |
| 83 |
uno::Reference< container::XNameContainer > m_xCfgNC; |
| 84 |
uno::Reference< container::XNameReplace > m_xCfgNR; |
| 85 |
uno::Reference< container::XNameAccess > m_xCfgNA; |
| 86 |
uno::Reference< container::XElementAccess > m_xCfgEA; |
| 87 |
uno::Reference< util::XChangesNotifier > m_xCfgCN; |
| 88 |
uno::Reference< util::XChangesBatch > m_xCfgCB; |
| 89 |
bool m_bReadOnly; |
| 90 |
|
| 91 |
public: |
| 92 |
HierarchyDataAccess( uno::Reference< |
| 93 |
uno::XInterface > xConfigAccess, |
| 94 |
bool bReadOnly ); |
| 95 |
|
| 96 |
// XInterface |
| 97 |
virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; |
| 98 |
virtual void SAL_CALL acquire() |
| 99 |
noexcept override; |
| 100 |
virtual void SAL_CALL release() |
| 101 |
noexcept override; |
| 102 |
|
| 103 |
// XServiceInfo |
| 104 |
virtual OUString SAL_CALL getImplementationName() override; |
| 105 |
virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; |
| 106 |
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; |
| 107 |
|
| 108 |
// XTypeProvider |
| 109 |
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override; |
| 110 |
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override; |
| 111 |
|
| 112 |
// XComponent |
| 113 |
virtual void SAL_CALL |
| 114 |
dispose() override; |
| 115 |
virtual void SAL_CALL |
| 116 |
addEventListener( const uno::Reference< lang::XEventListener > & xListener ) override; |
| 117 |
virtual void SAL_CALL |
| 118 |
removeEventListener( const uno::Reference< |
| 119 |
lang::XEventListener > & aListener ) override; |
| 120 |
|
| 121 |
// XSingleServiceFactory |
| 122 |
virtual uno::Reference< uno::XInterface > SAL_CALL |
| 123 |
createInstance() override; |
| 124 |
virtual uno::Reference< uno::XInterface > SAL_CALL |
| 125 |
createInstanceWithArguments( const uno::Sequence< uno::Any > & aArguments ) override; |
| 126 |
|
| 127 |
// XHierarchicalNameAccess |
| 128 |
virtual uno::Any SAL_CALL |
| 129 |
getByHierarchicalName( const OUString & aName ) override; |
| 130 |
virtual sal_Bool SAL_CALL |
| 131 |
hasByHierarchicalName( const OUString & aName ) override; |
| 132 |
|
| 133 |
// XNameContainer |
| 134 |
virtual void SAL_CALL |
| 135 |
insertByName( const OUString & aName, const uno::Any & aElement ) override; |
| 136 |
virtual void SAL_CALL |
| 137 |
removeByName( const OUString & Name ) override; |
| 138 |
|
| 139 |
// XNameReplace ( base of XNameContainer ) |
| 140 |
virtual void SAL_CALL |
| 141 |
replaceByName( const OUString & aName, const uno::Any & aElement ) override; |
| 142 |
|
| 143 |
// XNameAccess ( base of XNameReplace ) |
| 144 |
virtual uno::Any SAL_CALL |
| 145 |
getByName( const OUString & aName ) override; |
| 146 |
virtual uno::Sequence< OUString > SAL_CALL |
| 147 |
getElementNames() override; |
| 148 |
virtual sal_Bool SAL_CALL |
| 149 |
hasByName( const OUString & aName ) override; |
| 150 |
|
| 151 |
// XElementAccess ( base of XNameAccess ) |
| 152 |
virtual uno::Type SAL_CALL |
| 153 |
getElementType() override; |
| 154 |
virtual sal_Bool SAL_CALL |
| 155 |
hasElements() override; |
| 156 |
|
| 157 |
// XChangesNotifier |
| 158 |
virtual void SAL_CALL |
| 159 |
addChangesListener( const uno::Reference< |
| 160 |
util::XChangesListener > & aListener ) override; |
| 161 |
virtual void SAL_CALL |
| 162 |
removeChangesListener( const uno::Reference< |
| 163 |
util::XChangesListener > & aListener ) override; |
| 164 |
|
| 165 |
// XChangesBatch |
| 166 |
virtual void SAL_CALL |
| 167 |
commitChanges() override; |
| 168 |
virtual sal_Bool SAL_CALL |
| 169 |
hasPendingChanges() override; |
| 170 |
virtual uno::Sequence< util::ElementChange > SAL_CALL |
| 171 |
getPendingChanges() override; |
| 172 |
private: |
| 173 |
template<class T> |
| 174 |
css::uno::Reference<T> ensureOrigInterface(css::uno::Reference<T>& x); |
| 175 |
}; |
| 176 |
|
| 177 |
} |
| 178 |
|
| 179 |
} // namespace hcp_impl |
| 180 |
|
| 181 |
using namespace hcp_impl; |
| 182 |
|
| 183 |
|
| 184 |
// HierarchyDataSource Implementation. |
| 185 |
|
| 186 |
|
| 187 |
HierarchyDataSource::HierarchyDataSource( |
| 188 |
uno::Reference< uno::XComponentContext > xContext ) |
| 189 |
: m_xContext(std::move( xContext )) |
| 190 |
{ |
| 191 |
} |
| 192 |
|
| 193 |
|
| 194 |
// virtual |
| 195 |
HierarchyDataSource::~HierarchyDataSource() |
| 196 |
{ |
| 197 |
} |
| 198 |
|
| 199 |
// XServiceInfo methods. |
| 200 |
OUString SAL_CALL HierarchyDataSource::getImplementationName() \ |
| 201 |
{ |
| 202 |
return u"com.sun.star.comp.ucb.HierarchyDataSource"_ustr; |
| 203 |
} |
| 204 |
sal_Bool SAL_CALL HierarchyDataSource::supportsService( const OUString& ServiceName ) |
| 205 |
{ |
| 206 |
return cppu::supportsService( this, ServiceName ); |
| 207 |
} |
| 208 |
css::uno::Sequence< OUString > HierarchyDataSource::getSupportedServiceNames() |
| 209 |
{ |
| 210 |
return { u"com.sun.star.ucb.DefaultHierarchyDataSource"_ustr, u"com.sun.star.ucb.HierarchyDataSource"_ustr }; |
| 211 |
} |
| 212 |
|
| 213 |
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* |
| 214 |
ucb_HierarchyDataSource_get_implementation( |
| 215 |
css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&) |
| 216 |
{ |
| 217 |
return cppu::acquire(new HierarchyDataSource(context)); |
| 218 |
} |
| 219 |
|
| 220 |
|
| 221 |
// XComponent methods. |
| 222 |
|
| 223 |
|
| 224 |
// virtual |
| 225 |
void SAL_CALL HierarchyDataSource::dispose() |
| 226 |
{ |
| 227 |
std::unique_lock aGuard( m_aMutex ); |
| 228 |
|
| 229 |
if ( m_aDisposeEventListeners.getLength(aGuard) ) |
| 230 |
{ |
| 231 |
lang::EventObject aEvt; |
| 232 |
aEvt.Source = static_cast< lang::XComponent * >( this ); |
| 233 |
m_aDisposeEventListeners.disposeAndClear( aGuard, aEvt ); |
| 234 |
} |
| 235 |
} |
| 236 |
|
| 237 |
|
| 238 |
// virtual |
| 239 |
void SAL_CALL HierarchyDataSource::addEventListener( |
| 240 |
const uno::Reference< lang::XEventListener > & Listener ) |
| 241 |
{ |
| 242 |
std::unique_lock aGuard( m_aMutex ); |
| 243 |
|
| 244 |
m_aDisposeEventListeners.addInterface( aGuard, Listener ); |
| 245 |
} |
| 246 |
|
| 247 |
|
| 248 |
// virtual |
| 249 |
void SAL_CALL HierarchyDataSource::removeEventListener( |
| 250 |
const uno::Reference< lang::XEventListener > & Listener ) |
| 251 |
{ |
| 252 |
std::unique_lock aGuard( m_aMutex ); |
| 253 |
|
| 254 |
m_aDisposeEventListeners.removeInterface( aGuard, Listener ); |
| 255 |
} |
| 256 |
|
| 257 |
|
| 258 |
// XMultiServiceFactory methods. |
| 259 |
|
| 260 |
|
| 261 |
// virtual |
| 262 |
uno::Reference< uno::XInterface > SAL_CALL |
| 263 |
HierarchyDataSource::createInstance( const OUString & aServiceSpecifier ) |
| 264 |
{ |
| 265 |
// Create view to root node. |
| 266 |
|
| 267 |
beans::PropertyValue aProp = comphelper::makePropertyValue(CFGPROPERTY_NODEPATH, |
| 268 |
CONFIG_DATA_ROOT_KEY); |
| 269 |
|
| 270 |
uno::Sequence< uno::Any > aArguments{ uno::Any(aProp) }; |
| 271 |
|
| 272 |
return createInstanceWithArguments( aServiceSpecifier, aArguments, false ); |
| 273 |
} |
| 274 |
|
| 275 |
|
| 276 |
// virtual |
| 277 |
uno::Reference< uno::XInterface > SAL_CALL |
| 278 |
HierarchyDataSource::createInstanceWithArguments( |
| 279 |
const OUString & ServiceSpecifier, |
| 280 |
const uno::Sequence< uno::Any > & Arguments ) |
| 281 |
{ |
| 282 |
return createInstanceWithArguments( ServiceSpecifier, Arguments, true ); |
| 283 |
} |
| 284 |
|
| 285 |
|
| 286 |
// virtual |
| 287 |
uno::Sequence< OUString > SAL_CALL |
| 288 |
HierarchyDataSource::getAvailableServiceNames() |
| 289 |
{ |
| 290 |
return { READ_SERVICE_NAME, READWRITE_SERVICE_NAME }; |
| 291 |
} |
| 292 |
|
| 293 |
|
| 294 |
// Non-interface methods |
| 295 |
|
| 296 |
|
| 297 |
uno::Reference< uno::XInterface > |
| 298 |
HierarchyDataSource::createInstanceWithArguments( |
| 299 |
std::u16string_view ServiceSpecifier, |
| 300 |
const uno::Sequence< uno::Any > & Arguments, |
| 301 |
bool bCheckArgs ) |
| 302 |
{ |
| 303 |
// Check service specifier. |
| 304 |
bool bReadOnly = ServiceSpecifier == READ_SERVICE_NAME; |
| 305 |
bool bReadWrite = !bReadOnly && ServiceSpecifier == READWRITE_SERVICE_NAME; |
| 306 |
|
| 307 |
if ( !bReadOnly && !bReadWrite ) |
| 308 |
{ |
| 309 |
OSL_FAIL( "HierarchyDataSource::createInstanceWithArguments - " |
| 310 |
"Unsupported service specifier!" ); |
| 311 |
return uno::Reference< uno::XInterface >(); |
| 312 |
} |
| 313 |
|
| 314 |
uno::Sequence< uno::Any > aNewArgs( Arguments ); |
| 315 |
auto aNewArgsRange = asNonConstRange(aNewArgs); |
| 316 |
|
| 317 |
if ( bCheckArgs ) |
| 318 |
{ |
| 319 |
// Check arguments. |
| 320 |
bool bHasNodePath = false; |
| 321 |
sal_Int32 nCount = Arguments.getLength(); |
| 322 |
for ( sal_Int32 n = 0; n < nCount; ++n ) |
| 323 |
{ |
| 324 |
beans::PropertyValue aProp; |
| 325 |
if ( Arguments[ n ] >>= aProp ) |
| 326 |
{ |
| 327 |
if ( aProp.Name == CFGPROPERTY_NODEPATH ) |
| 328 |
{ |
| 329 |
OUString aPath; |
| 330 |
if ( aProp.Value >>= aPath ) |
| 331 |
{ |
| 332 |
bHasNodePath = true; |
| 333 |
|
| 334 |
// Create path to data inside the configuration. |
| 335 |
OUString aConfigPath; |
| 336 |
if ( !createConfigPath( aPath, aConfigPath ) ) |
| 337 |
{ |
| 338 |
OSL_FAIL( "HierarchyDataSource::" |
| 339 |
"createInstanceWithArguments - " |
| 340 |
"Invalid node path!" ); |
| 341 |
return uno::Reference< uno::XInterface >(); |
| 342 |
} |
| 343 |
|
| 344 |
aProp.Value <<= aConfigPath; |
| 345 |
|
| 346 |
// Set new path in arguments. |
| 347 |
aNewArgsRange[ n ] <<= aProp; |
| 348 |
|
| 349 |
break; |
| 350 |
} |
| 351 |
else |
| 352 |
{ |
| 353 |
OSL_FAIL( "HierarchyDataSource::createInstanceWithArguments - " |
| 354 |
"Invalid type for property 'nodepath'!" ); |
| 355 |
return uno::Reference< uno::XInterface >(); |
| 356 |
} |
| 357 |
} |
| 358 |
} |
| 359 |
} |
| 360 |
|
| 361 |
if ( !bHasNodePath ) |
| 362 |
{ |
| 363 |
OSL_FAIL( "HierarchyDataSource::createInstanceWithArguments - " |
| 364 |
"No 'nodepath' property!" ); |
| 365 |
return uno::Reference< uno::XInterface >(); |
| 366 |
} |
| 367 |
} |
| 368 |
|
| 369 |
// Create Configuration Provider. |
| 370 |
uno::Reference< lang::XMultiServiceFactory > xProv = getConfigProvider(); |
| 371 |
if ( !xProv.is() ) |
| 372 |
return uno::Reference< uno::XInterface >(); |
| 373 |
|
| 374 |
uno::Reference< uno::XInterface > xConfigAccess; |
| 375 |
try |
| 376 |
{ |
| 377 |
if ( bReadOnly ) |
| 378 |
{ |
| 379 |
// Create configuration read-only access object. |
| 380 |
xConfigAccess = xProv->createInstanceWithArguments( |
| 381 |
u"com.sun.star.configuration.ConfigurationAccess"_ustr, |
| 382 |
aNewArgs ); |
| 383 |
} |
| 384 |
else |
| 385 |
{ |
| 386 |
// Create configuration read-write access object. |
| 387 |
xConfigAccess = xProv->createInstanceWithArguments( |
| 388 |
u"com.sun.star.configuration.ConfigurationUpdateAccess"_ustr, |
| 389 |
aNewArgs ); |
| 390 |
} |
| 391 |
} |
| 392 |
catch ( uno::Exception const & ) |
| 393 |
{ |
| 394 |
OSL_FAIL( "HierarchyDataSource::createInstanceWithArguments - " |
| 395 |
"Cannot instantiate configuration access!" ); |
| 396 |
throw; |
| 397 |
} |
| 398 |
|
| 399 |
if ( !xConfigAccess.is() ) |
| 400 |
{ |
| 401 |
OSL_FAIL( "HierarchyDataSource::createInstanceWithArguments - " |
| 402 |
"Cannot instantiate configuration access!" ); |
| 403 |
return xConfigAccess; |
| 404 |
} |
| 405 |
|
| 406 |
return cppu::getXWeak(new HierarchyDataAccess(xConfigAccess, bReadOnly)); |
| 407 |
} |
| 408 |
|
| 409 |
|
| 410 |
uno::Reference< lang::XMultiServiceFactory > |
| 411 |
HierarchyDataSource::getConfigProvider() |
| 412 |
{ |
| 413 |
std::unique_lock aGuard( m_aMutex ); |
| 414 |
if ( !m_xConfigProvider.is() ) |
| 415 |
{ |
| 416 |
try |
| 417 |
{ |
| 418 |
m_xConfigProvider = configuration::theDefaultProvider::get( m_xContext ); |
| 419 |
} |
| 420 |
catch ( uno::Exception const & ) |
| 421 |
{ |
| 422 |
OSL_FAIL( "HierarchyDataSource::getConfigProvider - " |
| 423 |
"caught exception!" ); |
| 424 |
} |
| 425 |
} |
| 426 |
|
| 427 |
return m_xConfigProvider; |
| 428 |
} |
| 429 |
|
| 430 |
|
| 431 |
bool HierarchyDataSource::createConfigPath( |
| 432 |
std::u16string_view rInPath, OUString & rOutPath ) |
| 433 |
{ |
| 434 |
if ( !rInPath.empty() ) |
| 435 |
{ |
| 436 |
if ( o3tl::starts_with( rInPath, u"/" ) ) |
| 437 |
{ |
| 438 |
OSL_FAIL( "HierarchyDataSource::createConfigPath - " |
| 439 |
"Leading slash in node path!" ); |
| 440 |
return false; |
| 441 |
} |
| 442 |
|
| 443 |
if ( o3tl::ends_with( rInPath, u"/" ) ) |
| 444 |
{ |
| 445 |
OSL_FAIL( "HierarchyDataSource::createConfigPath - " |
| 446 |
"Trailing slash in node path!" ); |
| 447 |
return false; |
| 448 |
} |
| 449 |
|
| 450 |
rOutPath = CONFIG_DATA_ROOT_KEY + "/" + rInPath; |
| 451 |
} |
| 452 |
else |
| 453 |
{ |
| 454 |
rOutPath = CONFIG_DATA_ROOT_KEY; |
| 455 |
} |
| 456 |
|
| 457 |
return true; |
| 458 |
} |
| 459 |
|
| 460 |
|
| 461 |
// HierarchyDataAccess Implementation. |
| 462 |
|
| 463 |
template<class T> |
| 464 |
css::uno::Reference<T> HierarchyDataAccess::ensureOrigInterface(css::uno::Reference<T>& x) |
| 465 |
{ |
| 466 |
if ( x.is() ) |
| 467 |
return x; |
| 468 |
std::scoped_lock aGuard( m_aMutex ); |
| 469 |
if ( !x.is() ) |
| 470 |
x.set( m_xConfigAccess, uno::UNO_QUERY ); |
| 471 |
return x; |
| 472 |
} |
| 473 |
|
| 474 |
|
| 475 |
HierarchyDataAccess::HierarchyDataAccess( uno::Reference< |
| 476 |
uno::XInterface > xConfigAccess, |
| 477 |
bool bReadOnly ) |
| 478 |
: m_xConfigAccess(std::move( xConfigAccess )), |
| 479 |
m_bReadOnly( bReadOnly ) |
| 480 |
{ |
| 481 |
} |
| 482 |
|
| 483 |
// XInterface methods. |
| 484 |
void SAL_CALL HierarchyDataAccess::acquire() |
| 485 |
noexcept |
| 486 |
{ |
| 487 |
OWeakObject::acquire(); |
| 488 |
} |
| 489 |
|
| 490 |
void SAL_CALL HierarchyDataAccess::release() |
| 491 |
noexcept |
| 492 |
{ |
| 493 |
OWeakObject::release(); |
| 494 |
} |
| 495 |
|
| 496 |
// virtual |
| 497 |
uno::Any SAL_CALL HierarchyDataAccess::queryInterface( const uno::Type & aType ) |
| 498 |
{ |
| 499 |
// Interfaces supported in read-only and read-write mode. |
| 500 |
uno::Any aRet = cppu::queryInterface( aType, |
| 501 |
static_cast< lang::XTypeProvider * >( this ), |
| 502 |
static_cast< lang::XServiceInfo * >( this ), |
| 503 |
static_cast< lang::XComponent * >( this ), |
| 504 |
static_cast< container::XHierarchicalNameAccess * >( this ), |
| 505 |
static_cast< container::XNameAccess * >( this ), |
| 506 |
static_cast< container::XElementAccess * >( this ), |
| 507 |
static_cast< util::XChangesNotifier * >( this ) ); |
| 508 |
|
| 509 |
// Interfaces supported only in read-write mode. |
| 510 |
if ( !aRet.hasValue() && !m_bReadOnly ) |
| 511 |
{ |
| 512 |
aRet = cppu::queryInterface( aType, |
| 513 |
static_cast< lang::XSingleServiceFactory * >( this ), |
| 514 |
static_cast< container::XNameContainer * >( this ), |
| 515 |
static_cast< container::XNameReplace * >( this ), |
| 516 |
static_cast< util::XChangesBatch * >( this ) ); |
| 517 |
} |
| 518 |
|
| 519 |
return aRet.hasValue() ? aRet : OWeakObject::queryInterface( aType ); |
| 520 |
} |
| 521 |
|
| 522 |
|
| 523 |
// XTypeProvider methods. |
| 524 |
|
| 525 |
|
| 526 |
XTYPEPROVIDER_COMMON_IMPL( HierarchyDataAccess ); |
| 527 |
|
| 528 |
|
| 529 |
// virtual |
| 530 |
uno::Sequence< uno::Type > SAL_CALL HierarchyDataAccess::getTypes() |
| 531 |
{ |
| 532 |
if ( m_bReadOnly ) |
| 533 |
{ |
| 534 |
static cppu::OTypeCollection s_aReadOnlyTypes( |
| 535 |
CPPU_TYPE_REF( lang::XTypeProvider ), |
| 536 |
CPPU_TYPE_REF( lang::XServiceInfo ), |
| 537 |
CPPU_TYPE_REF( lang::XComponent ), |
| 538 |
CPPU_TYPE_REF( container::XHierarchicalNameAccess ), |
| 539 |
CPPU_TYPE_REF( container::XNameAccess ), |
| 540 |
CPPU_TYPE_REF( util::XChangesNotifier ) ); |
| 541 |
|
| 542 |
return s_aReadOnlyTypes.getTypes(); |
| 543 |
} |
| 544 |
else |
| 545 |
{ |
| 546 |
static cppu::OTypeCollection s_aReadWriteTypes( |
| 547 |
CPPU_TYPE_REF( lang::XTypeProvider ), |
| 548 |
CPPU_TYPE_REF( lang::XServiceInfo ), |
| 549 |
CPPU_TYPE_REF( lang::XComponent ), |
| 550 |
CPPU_TYPE_REF( lang::XSingleServiceFactory ), |
| 551 |
CPPU_TYPE_REF( container::XHierarchicalNameAccess ), |
| 552 |
CPPU_TYPE_REF( container::XNameContainer ), |
| 553 |
CPPU_TYPE_REF( util::XChangesBatch ), |
| 554 |
CPPU_TYPE_REF( util::XChangesNotifier ) ); |
| 555 |
|
| 556 |
return s_aReadWriteTypes.getTypes(); |
| 557 |
} |
| 558 |
} |
| 559 |
|
| 560 |
|
| 561 |
// XServiceInfo methods. |
| 562 |
|
| 563 |
OUString SAL_CALL HierarchyDataAccess::getImplementationName() |
| 564 |
{ |
| 565 |
return u"com.sun.star.comp.ucb.HierarchyDataAccess"_ustr; |
| 566 |
} |
| 567 |
|
| 568 |
sal_Bool SAL_CALL HierarchyDataAccess::supportsService( const OUString& ServiceName ) |
| 569 |
{ |
| 570 |
return cppu::supportsService( this, ServiceName ); |
| 571 |
} |
| 572 |
|
| 573 |
css::uno::Sequence< OUString > SAL_CALL HierarchyDataAccess::getSupportedServiceNames() |
| 574 |
{ |
| 575 |
return { READ_SERVICE_NAME, READWRITE_SERVICE_NAME }; |
| 576 |
} |
| 577 |
|
| 578 |
|
| 579 |
// XComponent methods. |
| 580 |
|
| 581 |
|
| 582 |
// virtual |
| 583 |
void SAL_CALL HierarchyDataAccess::dispose() |
| 584 |
{ |
| 585 |
uno::Reference< lang::XComponent > xOrig |
| 586 |
= ensureOrigInterface( m_xCfgC ); |
| 587 |
|
| 588 |
OSL_ENSURE( xOrig.is(), |
| 589 |
"HierarchyDataAccess : Data source is not an XComponent!" ); |
| 590 |
xOrig->dispose(); |
| 591 |
} |
| 592 |
|
| 593 |
|
| 594 |
// virtual |
| 595 |
void SAL_CALL HierarchyDataAccess::addEventListener( |
| 596 |
const uno::Reference< lang::XEventListener > & xListener ) |
| 597 |
{ |
| 598 |
uno::Reference< lang::XComponent > xOrig |
| 599 |
= ensureOrigInterface( m_xCfgC ); |
| 600 |
|
| 601 |
OSL_ENSURE( xOrig.is(), |
| 602 |
"HierarchyDataAccess : Data source is not an XComponent!" ); |
| 603 |
xOrig->addEventListener( xListener ); |
| 604 |
} |
| 605 |
|
| 606 |
|
| 607 |
// virtual |
| 608 |
void SAL_CALL HierarchyDataAccess::removeEventListener( |
| 609 |
const uno::Reference< lang::XEventListener > & aListener ) |
| 610 |
{ |
| 611 |
uno::Reference< lang::XComponent > xOrig |
| 612 |
= ensureOrigInterface( m_xCfgC ); |
| 613 |
|
| 614 |
OSL_ENSURE( xOrig.is(), |
| 615 |
"HierarchyDataAccess : Data source is not an XComponent!" ); |
| 616 |
xOrig->removeEventListener( aListener ); |
| 617 |
} |
| 618 |
|
| 619 |
|
| 620 |
// XHierarchicalNameAccess methods. |
| 621 |
|
| 622 |
|
| 623 |
// virtual |
| 624 |
uno::Any SAL_CALL HierarchyDataAccess::getByHierarchicalName( |
| 625 |
const OUString & aName ) |
| 626 |
{ |
| 627 |
uno::Reference< container::XHierarchicalNameAccess > xOrig |
| 628 |
= ensureOrigInterface( m_xCfgHNA ); |
| 629 |
|
| 630 |
OSL_ENSURE( xOrig.is(), |
| 631 |
"HierarchyDataAccess : " |
| 632 |
"Data source is not an XHierarchicalNameAccess!" ); |
| 633 |
return xOrig->getByHierarchicalName( aName ); |
| 634 |
} |
| 635 |
|
| 636 |
|
| 637 |
// virtual |
| 638 |
sal_Bool SAL_CALL HierarchyDataAccess::hasByHierarchicalName( |
| 639 |
const OUString & aName ) |
| 640 |
{ |
| 641 |
uno::Reference< container::XHierarchicalNameAccess > xOrig |
| 642 |
= ensureOrigInterface( m_xCfgHNA ); |
| 643 |
|
| 644 |
OSL_ENSURE( xOrig.is(), |
| 645 |
"HierarchyDataAccess : " |
| 646 |
"Data source is not an XHierarchicalNameAccess!" ); |
| 647 |
return xOrig->hasByHierarchicalName( aName ); |
| 648 |
} |
| 649 |
|
| 650 |
|
| 651 |
// XNameAccess methods. |
| 652 |
|
| 653 |
|
| 654 |
// virtual |
| 655 |
uno::Any SAL_CALL HierarchyDataAccess::getByName( const OUString & aName ) |
| 656 |
{ |
| 657 |
uno::Reference< container::XNameAccess > xOrig |
| 658 |
= ensureOrigInterface( m_xCfgNA ); |
| 659 |
|
| 660 |
OSL_ENSURE( xOrig.is(), |
| 661 |
"HierarchyDataAccess : Data source is not an XNameAccess!" ); |
| 662 |
return xOrig->getByName( aName ); |
| 663 |
} |
| 664 |
|
| 665 |
|
| 666 |
// virtual |
| 667 |
uno::Sequence< OUString > SAL_CALL HierarchyDataAccess::getElementNames() |
| 668 |
{ |
| 669 |
uno::Reference< container::XNameAccess > xOrig |
| 670 |
= ensureOrigInterface( m_xCfgNA ); |
| 671 |
|
| 672 |
OSL_ENSURE( xOrig.is(), |
| 673 |
"HierarchyDataAccess : Data source is not an XNameAccess!" ); |
| 674 |
return xOrig->getElementNames(); |
| 675 |
} |
| 676 |
|
| 677 |
|
| 678 |
// virtual |
| 679 |
sal_Bool SAL_CALL HierarchyDataAccess::hasByName( const OUString & aName ) |
| 680 |
{ |
| 681 |
uno::Reference< container::XNameAccess > xOrig |
| 682 |
= ensureOrigInterface( m_xCfgNA ); |
| 683 |
|
| 684 |
OSL_ENSURE( xOrig.is(), |
| 685 |
"HierarchyDataAccess : Data source is not an XNameAccess!" ); |
| 686 |
return xOrig->hasByName( aName ); |
| 687 |
} |
| 688 |
|
| 689 |
|
| 690 |
// XElementAccess methods. |
| 691 |
|
| 692 |
|
| 693 |
// virtual |
| 694 |
uno::Type SAL_CALL HierarchyDataAccess::getElementType() |
| 695 |
{ |
| 696 |
uno::Reference< container::XElementAccess > xOrig |
| 697 |
= ensureOrigInterface( m_xCfgEA ); |
| 698 |
|
| 699 |
OSL_ENSURE( xOrig.is(), |
| 700 |
"HierarchyDataAccess : Data source is not an XElementAccess!" ); |
| 701 |
return xOrig->getElementType(); |
| 702 |
} |
| 703 |
|
| 704 |
|
| 705 |
// virtual |
| 706 |
sal_Bool SAL_CALL HierarchyDataAccess::hasElements() |
| 707 |
{ |
| 708 |
uno::Reference< container::XElementAccess > xOrig |
| 709 |
= ensureOrigInterface( m_xCfgEA ); |
| 710 |
|
| 711 |
OSL_ENSURE( xOrig.is(), |
| 712 |
"HierarchyDataAccess : Data source is not an XElementAccess!" ); |
| 713 |
return xOrig->hasElements(); |
| 714 |
} |
| 715 |
|
| 716 |
|
| 717 |
// XChangesNotifier methods. |
| 718 |
|
| 719 |
|
| 720 |
// virtual |
| 721 |
void SAL_CALL HierarchyDataAccess::addChangesListener( |
| 722 |
const uno::Reference< util::XChangesListener > & aListener ) |
| 723 |
{ |
| 724 |
uno::Reference< util::XChangesNotifier > xOrig |
| 725 |
= ensureOrigInterface( m_xCfgCN ); |
| 726 |
|
| 727 |
OSL_ENSURE( xOrig.is(), |
| 728 |
"HierarchyDataAccess : Data source is not an XChangesNotifier!" ); |
| 729 |
xOrig->addChangesListener( aListener ); |
| 730 |
} |
| 731 |
|
| 732 |
|
| 733 |
// virtual |
| 734 |
void SAL_CALL HierarchyDataAccess::removeChangesListener( |
| 735 |
const uno::Reference< util::XChangesListener > & aListener ) |
| 736 |
{ |
| 737 |
uno::Reference< util::XChangesNotifier > xOrig |
| 738 |
= ensureOrigInterface( m_xCfgCN ); |
| 739 |
|
| 740 |
OSL_ENSURE( xOrig.is(), |
| 741 |
"HierarchyDataAccess : Data source is not an XChangesNotifier!" ); |
| 742 |
xOrig->removeChangesListener( aListener ); |
| 743 |
} |
| 744 |
|
| 745 |
|
| 746 |
// XSingleServiceFactory methods. |
| 747 |
|
| 748 |
|
| 749 |
// virtual |
| 750 |
uno::Reference< uno::XInterface > SAL_CALL HierarchyDataAccess::createInstance() |
| 751 |
{ |
| 752 |
uno::Reference< lang::XSingleServiceFactory > xOrig |
| 753 |
= ensureOrigInterface( m_xCfgSSF ); |
| 754 |
|
| 755 |
OSL_ENSURE( xOrig.is(), |
| 756 |
"HierarchyDataAccess : Data source is not an XSingleServiceFactory!" ); |
| 757 |
return xOrig->createInstance(); |
| 758 |
} |
| 759 |
|
| 760 |
|
| 761 |
// virtual |
| 762 |
uno::Reference< uno::XInterface > SAL_CALL |
| 763 |
HierarchyDataAccess::createInstanceWithArguments( |
| 764 |
const uno::Sequence< uno::Any > & aArguments ) |
| 765 |
{ |
| 766 |
uno::Reference< lang::XSingleServiceFactory > xOrig |
| 767 |
= ensureOrigInterface( m_xCfgSSF ); |
| 768 |
|
| 769 |
OSL_ENSURE( xOrig.is(), |
| 770 |
"HierarchyDataAccess : Data source is not an XSingleServiceFactory!" ); |
| 771 |
return xOrig->createInstanceWithArguments( aArguments ); |
| 772 |
} |
| 773 |
|
| 774 |
|
| 775 |
// XNameContainer methods. |
| 776 |
|
| 777 |
|
| 778 |
// virtual |
| 779 |
void SAL_CALL |
| 780 |
HierarchyDataAccess::insertByName( const OUString & aName, |
| 781 |
const uno::Any & aElement ) |
| 782 |
{ |
| 783 |
uno::Reference< container::XNameContainer > xOrig |
| 784 |
= ensureOrigInterface( m_xCfgNC ); |
| 785 |
|
| 786 |
OSL_ENSURE( xOrig.is(), |
| 787 |
"HierarchyDataAccess : Data source is not an XNameContainer!" ); |
| 788 |
xOrig->insertByName( aName, aElement ); |
| 789 |
} |
| 790 |
|
| 791 |
|
| 792 |
// virtual |
| 793 |
void SAL_CALL |
| 794 |
HierarchyDataAccess::removeByName( const OUString & Name ) |
| 795 |
{ |
| 796 |
uno::Reference< container::XNameContainer > xOrig |
| 797 |
= ensureOrigInterface( m_xCfgNC ); |
| 798 |
|
| 799 |
OSL_ENSURE( xOrig.is(), |
| 800 |
"HierarchyDataAccess : Data source is not an XNameContainer!" ); |
| 801 |
xOrig->removeByName( Name ); |
| 802 |
} |
| 803 |
|
| 804 |
|
| 805 |
// XNameReplace methods. |
| 806 |
|
| 807 |
|
| 808 |
// virtual |
| 809 |
void SAL_CALL HierarchyDataAccess::replaceByName( const OUString & aName, |
| 810 |
const uno::Any & aElement ) |
| 811 |
{ |
| 812 |
uno::Reference< container::XNameReplace > xOrig |
| 813 |
= ensureOrigInterface( m_xCfgNR ); |
| 814 |
|
| 815 |
OSL_ENSURE( xOrig.is(), |
| 816 |
"HierarchyDataAccess : Data source is not an XNameReplace!" ); |
| 817 |
xOrig->replaceByName( aName, aElement ); |
| 818 |
} |
| 819 |
|
| 820 |
|
| 821 |
// XChangesBatch methods. |
| 822 |
|
| 823 |
|
| 824 |
// virtual |
| 825 |
void SAL_CALL HierarchyDataAccess::commitChanges() |
| 826 |
{ |
| 827 |
uno::Reference< util::XChangesBatch > xOrig |
| 828 |
= ensureOrigInterface( m_xCfgCB ); |
| 829 |
|
| 830 |
OSL_ENSURE( xOrig.is(), |
| 831 |
"HierarchyDataAccess : Data source is not an XChangesBatch!" ); |
| 832 |
xOrig->commitChanges(); |
| 833 |
} |
| 834 |
|
| 835 |
|
| 836 |
// virtual |
| 837 |
sal_Bool SAL_CALL HierarchyDataAccess::hasPendingChanges() |
| 838 |
{ |
| 839 |
uno::Reference< util::XChangesBatch > xOrig |
| 840 |
= ensureOrigInterface( m_xCfgCB ); |
| 841 |
|
| 842 |
OSL_ENSURE( xOrig.is(), |
| 843 |
"HierarchyDataAccess : Data source is not an XChangesBatch!" ); |
| 844 |
return xOrig->hasPendingChanges(); |
| 845 |
} |
| 846 |
|
| 847 |
|
| 848 |
// virtual |
| 849 |
uno::Sequence< util::ElementChange > SAL_CALL |
| 850 |
HierarchyDataAccess::getPendingChanges() |
| 851 |
{ |
| 852 |
uno::Reference< util::XChangesBatch > xOrig |
| 853 |
= ensureOrigInterface( m_xCfgCB ); |
| 854 |
|
| 855 |
OSL_ENSURE( xOrig.is(), |
| 856 |
"HierarchyDataAccess : Data source is not an XChangesBatch!" ); |
| 857 |
return xOrig->getPendingChanges(); |
| 858 |
} |
| 859 |
|
| 860 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |