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