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 
35 #include <cppuhelper/weak.hxx>
36 #include <com/sun/star/beans/PropertyValue.hpp>
37 #include <com/sun/star/configuration/theDefaultProvider.hpp>
38 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
39 #include <com/sun/star/container/XNameContainer.hpp>
40 #include <com/sun/star/util/XChangesBatch.hpp>
41 #include <com/sun/star/util/XChangesNotifier.hpp>
42 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
43 #include <o3tl/string_view.hxx>
44 #include <ucbhelper/macros.hxx>
45 #include <mutex>
46 
47 using namespace com::sun::star;
48 using namespace hierarchy_ucp;
49 
50 
51 // describe path of cfg entry
52 constexpr OUStringLiteral CFGPROPERTY_NODEPATH = u"nodepath";
53 
54 constexpr OUStringLiteral READ_SERVICE_NAME = u"com.sun.star.ucb.HierarchyDataReadAccess";
55 constexpr OUStringLiteral READWRITE_SERVICE_NAME = u"com.sun.star.ucb.HierarchyDataReadWriteAccess";
56 
57 constexpr OUStringLiteral CONFIG_DATA_ROOT_KEY = u"/org.openoffice.ucb.Hierarchy/Root";
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;
90 
91 public:
92  HierarchyDataAccess( const 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 
188  const uno::Reference< uno::XComponentContext > & rxContext )
189 : m_xContext( rxContext )
190 {
191 }
192 
193 
194 // virtual
195 HierarchyDataSource::~HierarchyDataSource()
196 {
197 }
198 
199 // XServiceInfo methods.
200 OUString SAL_CALL HierarchyDataSource::getImplementationName() \
201 {
202  return "com.sun.star.comp.ucb.HierarchyDataSource";
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 { "com.sun.star.ucb.DefaultHierarchyDataSource", "com.sun.star.ucb.HierarchyDataSource" };
211 }
212 
213 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
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  osl::Guard< osl::Mutex > aGuard( m_aMutex );
228 
229  if ( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() )
230  {
231  lang::EventObject aEvt;
232  aEvt.Source = static_cast< lang::XComponent * >( this );
233  m_pDisposeEventListeners->disposeAndClear( aEvt );
234  }
235 }
236 
237 
238 // virtual
239 void SAL_CALL HierarchyDataSource::addEventListener(
240  const uno::Reference< lang::XEventListener > & Listener )
241 {
242  osl::Guard< osl::Mutex > aGuard( m_aMutex );
243 
244  if ( !m_pDisposeEventListeners )
245  m_pDisposeEventListeners.reset(
247 
248  m_pDisposeEventListeners->addInterface( Listener );
249 }
250 
251 
252 // virtual
253 void SAL_CALL HierarchyDataSource::removeEventListener(
254  const uno::Reference< lang::XEventListener > & Listener )
255 {
256  osl::Guard< osl::Mutex > aGuard( m_aMutex );
257 
258  if ( m_pDisposeEventListeners )
259  m_pDisposeEventListeners->removeInterface( Listener );
260 }
261 
262 
263 // XMultiServiceFactory methods.
264 
265 
266 // virtual
267 uno::Reference< uno::XInterface > SAL_CALL
268 HierarchyDataSource::createInstance( const OUString & aServiceSpecifier )
269 {
270  // Create view to root node.
271 
272  beans::PropertyValue aProp = comphelper::makePropertyValue(CFGPROPERTY_NODEPATH,
273  OUString( CONFIG_DATA_ROOT_KEY ));
274 
275  uno::Sequence< uno::Any > aArguments{ uno::Any(aProp) };
276 
277  return createInstanceWithArguments( aServiceSpecifier, aArguments, false );
278 }
279 
280 
281 // virtual
282 uno::Reference< uno::XInterface > SAL_CALL
283 HierarchyDataSource::createInstanceWithArguments(
284  const OUString & ServiceSpecifier,
285  const uno::Sequence< uno::Any > & Arguments )
286 {
287  return createInstanceWithArguments( ServiceSpecifier, Arguments, true );
288 }
289 
290 
291 // virtual
292 uno::Sequence< OUString > SAL_CALL
293 HierarchyDataSource::getAvailableServiceNames()
294 {
296 }
297 
298 
299 // Non-interface methods
300 
301 
302 uno::Reference< uno::XInterface >
303 HierarchyDataSource::createInstanceWithArguments(
304  std::u16string_view ServiceSpecifier,
305  const uno::Sequence< uno::Any > & Arguments,
306  bool bCheckArgs )
307 {
308  osl::Guard< osl::Mutex > aGuard( m_aMutex );
309 
310  // Check service specifier.
311  bool bReadOnly = ServiceSpecifier == READ_SERVICE_NAME;
312  bool bReadWrite = !bReadOnly && ServiceSpecifier == READWRITE_SERVICE_NAME;
313 
314  if ( !bReadOnly && !bReadWrite )
315  {
316  OSL_FAIL( "HierarchyDataSource::createInstanceWithArguments - "
317  "Unsupported service specifier!" );
318  return uno::Reference< uno::XInterface >();
319  }
320 
321  uno::Sequence< uno::Any > aNewArgs( Arguments );
322  auto aNewArgsRange = asNonConstRange(aNewArgs);
323 
324  if ( bCheckArgs )
325  {
326  // Check arguments.
327  bool bHasNodePath = false;
328  sal_Int32 nCount = Arguments.getLength();
329  for ( sal_Int32 n = 0; n < nCount; ++n )
330  {
331  beans::PropertyValue aProp;
332  if ( Arguments[ n ] >>= aProp )
333  {
334  if ( aProp.Name == CFGPROPERTY_NODEPATH )
335  {
336  OUString aPath;
337  if ( aProp.Value >>= aPath )
338  {
339  bHasNodePath = true;
340 
341  // Create path to data inside the configuration.
342  OUString aConfigPath;
343  if ( !createConfigPath( aPath, aConfigPath ) )
344  {
345  OSL_FAIL( "HierarchyDataSource::"
346  "createInstanceWithArguments - "
347  "Invalid node path!" );
348  return uno::Reference< uno::XInterface >();
349  }
350 
351  aProp.Value <<= aConfigPath;
352 
353  // Set new path in arguments.
354  aNewArgsRange[ n ] <<= aProp;
355 
356  break;
357  }
358  else
359  {
360  OSL_FAIL( "HierarchyDataSource::createInstanceWithArguments - "
361  "Invalid type for property 'nodepath'!" );
362  return uno::Reference< uno::XInterface >();
363  }
364  }
365  }
366  }
367 
368  if ( !bHasNodePath )
369  {
370  OSL_FAIL( "HierarchyDataSource::createInstanceWithArguments - "
371  "No 'nodepath' property!" );
372  return uno::Reference< uno::XInterface >();
373  }
374  }
375 
376  // Create Configuration Provider.
377  uno::Reference< lang::XMultiServiceFactory > xProv = getConfigProvider();
378  if ( !xProv.is() )
379  return uno::Reference< uno::XInterface >();
380 
381  uno::Reference< uno::XInterface > xConfigAccess;
382  try
383  {
384  if ( bReadOnly )
385  {
386  // Create configuration read-only access object.
387  xConfigAccess = xProv->createInstanceWithArguments(
388  "com.sun.star.configuration.ConfigurationAccess",
389  aNewArgs );
390  }
391  else
392  {
393  // Create configuration read-write access object.
394  xConfigAccess = xProv->createInstanceWithArguments(
395  "com.sun.star.configuration.ConfigurationUpdateAccess",
396  aNewArgs );
397  }
398  }
399  catch ( uno::Exception const & )
400  {
401  OSL_FAIL( "HierarchyDataSource::createInstanceWithArguments - "
402  "Cannot instantiate configuration access!" );
403  throw;
404  }
405 
406  if ( !xConfigAccess.is() )
407  {
408  OSL_FAIL( "HierarchyDataSource::createInstanceWithArguments - "
409  "Cannot instantiate configuration access!" );
410  return xConfigAccess;
411  }
412 
413  return uno::Reference< uno::XInterface >(
414  static_cast< cppu::OWeakObject * >(
415  new HierarchyDataAccess( xConfigAccess, bReadOnly ) ) );
416 }
417 
418 
419 uno::Reference< lang::XMultiServiceFactory >
420 HierarchyDataSource::getConfigProvider()
421 {
422  if ( !m_xConfigProvider.is() )
423  {
424  osl::Guard< osl::Mutex > aGuard( m_aMutex );
425  if ( !m_xConfigProvider.is() )
426  {
427  try
428  {
429  m_xConfigProvider = configuration::theDefaultProvider::get( m_xContext );
430  }
431  catch ( uno::Exception const & )
432  {
433  OSL_FAIL( "HierarchyDataSource::getConfigProvider - "
434  "caught exception!" );
435  }
436  }
437  }
438 
439  return m_xConfigProvider;
440 }
441 
442 
443 bool HierarchyDataSource::createConfigPath(
444  std::u16string_view rInPath, OUString & rOutPath )
445 {
446  if ( !rInPath.empty() )
447  {
448  if ( o3tl::starts_with( rInPath, u"/" ) )
449  {
450  OSL_FAIL( "HierarchyDataSource::createConfigPath - "
451  "Leading slash in node path!" );
452  return false;
453  }
454 
455  if ( o3tl::ends_with( rInPath, u"/" ) )
456  {
457  OSL_FAIL( "HierarchyDataSource::createConfigPath - "
458  "Trailing slash in node path!" );
459  return false;
460  }
461 
462  rOutPath = CONFIG_DATA_ROOT_KEY + "/" + rInPath;
463  }
464  else
465  {
466  rOutPath = CONFIG_DATA_ROOT_KEY;
467  }
468 
469  return true;
470 }
471 
472 
473 // HierarchyDataAccess Implementation.
474 
475 template<class T>
476 css::uno::Reference<T> HierarchyDataAccess::ensureOrigInterface(css::uno::Reference<T>& x)
477 {
478  if ( x.is() )
479  return x;
480  std::scoped_lock aGuard( m_aMutex );
481  if ( !x.is() )
482  x.set( m_xConfigAccess, uno::UNO_QUERY );
483  return x;
484 }
485 
486 
487 HierarchyDataAccess::HierarchyDataAccess( const uno::Reference<
488  uno::XInterface > & xConfigAccess,
489  bool bReadOnly )
490 : m_xConfigAccess( xConfigAccess ),
491  m_bReadOnly( bReadOnly )
492 {
493 }
494 
495 // XInterface methods.
496 void SAL_CALL HierarchyDataAccess::acquire()
497  noexcept
498 {
499  OWeakObject::acquire();
500 }
501 
502 void SAL_CALL HierarchyDataAccess::release()
503  noexcept
504 {
505  OWeakObject::release();
506 }
507 
508 // virtual
509 uno::Any SAL_CALL HierarchyDataAccess::queryInterface( const uno::Type & aType )
510 {
511  // Interfaces supported in read-only and read-write mode.
512  uno::Any aRet = cppu::queryInterface( aType,
513  static_cast< lang::XTypeProvider * >( this ),
514  static_cast< lang::XServiceInfo * >( this ),
515  static_cast< lang::XComponent * >( this ),
516  static_cast< container::XHierarchicalNameAccess * >( this ),
517  static_cast< container::XNameAccess * >( this ),
518  static_cast< container::XElementAccess * >( this ),
519  static_cast< util::XChangesNotifier * >( this ) );
520 
521  // Interfaces supported only in read-write mode.
522  if ( !aRet.hasValue() && !m_bReadOnly )
523  {
524  aRet = cppu::queryInterface( aType,
525  static_cast< lang::XSingleServiceFactory * >( this ),
526  static_cast< container::XNameContainer * >( this ),
527  static_cast< container::XNameReplace * >( this ),
528  static_cast< util::XChangesBatch * >( this ) );
529  }
530 
531  return aRet.hasValue() ? aRet : OWeakObject::queryInterface( aType );
532 }
533 
534 
535 // XTypeProvider methods.
536 
537 
538 XTYPEPROVIDER_COMMON_IMPL( HierarchyDataAccess );
539 
540 
541 // virtual
542 uno::Sequence< uno::Type > SAL_CALL HierarchyDataAccess::getTypes()
543 {
544  if ( m_bReadOnly )
545  {
546  static cppu::OTypeCollection s_aReadOnlyTypes(
547  CPPU_TYPE_REF( lang::XTypeProvider ),
548  CPPU_TYPE_REF( lang::XServiceInfo ),
549  CPPU_TYPE_REF( lang::XComponent ),
550  CPPU_TYPE_REF( container::XHierarchicalNameAccess ),
551  CPPU_TYPE_REF( container::XNameAccess ),
552  CPPU_TYPE_REF( util::XChangesNotifier ) );
553 
554  return s_aReadOnlyTypes.getTypes();
555  }
556  else
557  {
558  static cppu::OTypeCollection s_aReadWriteTypes(
559  CPPU_TYPE_REF( lang::XTypeProvider ),
560  CPPU_TYPE_REF( lang::XServiceInfo ),
561  CPPU_TYPE_REF( lang::XComponent ),
562  CPPU_TYPE_REF( lang::XSingleServiceFactory ),
563  CPPU_TYPE_REF( container::XHierarchicalNameAccess ),
564  CPPU_TYPE_REF( container::XNameContainer ),
565  CPPU_TYPE_REF( util::XChangesBatch ),
566  CPPU_TYPE_REF( util::XChangesNotifier ) );
567 
568  return s_aReadWriteTypes.getTypes();
569  }
570 }
571 
572 
573 // XServiceInfo methods.
574 
575 OUString SAL_CALL HierarchyDataAccess::getImplementationName()
576 {
577  return "com.sun.star.comp.ucb.HierarchyDataAccess";
578 }
579 
580 sal_Bool SAL_CALL HierarchyDataAccess::supportsService( const OUString& ServiceName )
581 {
582  return cppu::supportsService( this, ServiceName );
583 }
584 
585 css::uno::Sequence< OUString > SAL_CALL HierarchyDataAccess::getSupportedServiceNames()
586 {
588 }
589 
590 
591 // XComponent methods.
592 
593 
594 // virtual
595 void SAL_CALL HierarchyDataAccess::dispose()
596 {
597  uno::Reference< lang::XComponent > xOrig
598  = ensureOrigInterface( m_xCfgC );
599 
600  OSL_ENSURE( xOrig.is(),
601  "HierarchyDataAccess : Data source is not an XComponent!" );
602  xOrig->dispose();
603 }
604 
605 
606 // virtual
607 void SAL_CALL HierarchyDataAccess::addEventListener(
608  const uno::Reference< lang::XEventListener > & xListener )
609 {
610  uno::Reference< lang::XComponent > xOrig
611  = ensureOrigInterface( m_xCfgC );
612 
613  OSL_ENSURE( xOrig.is(),
614  "HierarchyDataAccess : Data source is not an XComponent!" );
615  xOrig->addEventListener( xListener );
616 }
617 
618 
619 // virtual
620 void SAL_CALL HierarchyDataAccess::removeEventListener(
621  const uno::Reference< lang::XEventListener > & aListener )
622 {
623  uno::Reference< lang::XComponent > xOrig
624  = ensureOrigInterface( m_xCfgC );
625 
626  OSL_ENSURE( xOrig.is(),
627  "HierarchyDataAccess : Data source is not an XComponent!" );
628  xOrig->removeEventListener( aListener );
629 }
630 
631 
632 // XHierarchicalNameAccess methods.
633 
634 
635 // virtual
636 uno::Any SAL_CALL HierarchyDataAccess::getByHierarchicalName(
637  const OUString & aName )
638 {
639  uno::Reference< container::XHierarchicalNameAccess > xOrig
640  = ensureOrigInterface( m_xCfgHNA );
641 
642  OSL_ENSURE( xOrig.is(),
643  "HierarchyDataAccess : "
644  "Data source is not an XHierarchicalNameAccess!" );
645  return xOrig->getByHierarchicalName( aName );
646 }
647 
648 
649 // virtual
650 sal_Bool SAL_CALL HierarchyDataAccess::hasByHierarchicalName(
651  const OUString & aName )
652 {
653  uno::Reference< container::XHierarchicalNameAccess > xOrig
654  = ensureOrigInterface( m_xCfgHNA );
655 
656  OSL_ENSURE( xOrig.is(),
657  "HierarchyDataAccess : "
658  "Data source is not an XHierarchicalNameAccess!" );
659  return xOrig->hasByHierarchicalName( aName );
660 }
661 
662 
663 // XNameAccess methods.
664 
665 
666 // virtual
667 uno::Any SAL_CALL HierarchyDataAccess::getByName( const OUString & aName )
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->getByName( aName );
675 }
676 
677 
678 // virtual
679 uno::Sequence< OUString > SAL_CALL HierarchyDataAccess::getElementNames()
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->getElementNames();
687 }
688 
689 
690 // virtual
691 sal_Bool SAL_CALL HierarchyDataAccess::hasByName( const OUString & aName )
692 {
693  uno::Reference< container::XNameAccess > xOrig
694  = ensureOrigInterface( m_xCfgNA );
695 
696  OSL_ENSURE( xOrig.is(),
697  "HierarchyDataAccess : Data source is not an XNameAccess!" );
698  return xOrig->hasByName( aName );
699 }
700 
701 
702 // XElementAccess methods.
703 
704 
705 // virtual
706 uno::Type SAL_CALL HierarchyDataAccess::getElementType()
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->getElementType();
714 }
715 
716 
717 // virtual
718 sal_Bool SAL_CALL HierarchyDataAccess::hasElements()
719 {
720  uno::Reference< container::XElementAccess > xOrig
721  = ensureOrigInterface( m_xCfgEA );
722 
723  OSL_ENSURE( xOrig.is(),
724  "HierarchyDataAccess : Data source is not an XElementAccess!" );
725  return xOrig->hasElements();
726 }
727 
728 
729 // XChangesNotifier methods.
730 
731 
732 // virtual
733 void SAL_CALL HierarchyDataAccess::addChangesListener(
734  const uno::Reference< util::XChangesListener > & aListener )
735 {
736  uno::Reference< util::XChangesNotifier > xOrig
737  = ensureOrigInterface( m_xCfgCN );
738 
739  OSL_ENSURE( xOrig.is(),
740  "HierarchyDataAccess : Data source is not an XChangesNotifier!" );
741  xOrig->addChangesListener( aListener );
742 }
743 
744 
745 // virtual
746 void SAL_CALL HierarchyDataAccess::removeChangesListener(
747  const uno::Reference< util::XChangesListener > & aListener )
748 {
749  uno::Reference< util::XChangesNotifier > xOrig
750  = ensureOrigInterface( m_xCfgCN );
751 
752  OSL_ENSURE( xOrig.is(),
753  "HierarchyDataAccess : Data source is not an XChangesNotifier!" );
754  xOrig->removeChangesListener( aListener );
755 }
756 
757 
758 // XSingleServiceFactory methods.
759 
760 
761 // virtual
762 uno::Reference< uno::XInterface > SAL_CALL HierarchyDataAccess::createInstance()
763 {
764  uno::Reference< lang::XSingleServiceFactory > xOrig
765  = ensureOrigInterface( m_xCfgSSF );
766 
767  OSL_ENSURE( xOrig.is(),
768  "HierarchyDataAccess : Data source is not an XSingleServiceFactory!" );
769  return xOrig->createInstance();
770 }
771 
772 
773 // virtual
774 uno::Reference< uno::XInterface > SAL_CALL
775 HierarchyDataAccess::createInstanceWithArguments(
776  const uno::Sequence< uno::Any > & aArguments )
777 {
778  uno::Reference< lang::XSingleServiceFactory > xOrig
779  = ensureOrigInterface( m_xCfgSSF );
780 
781  OSL_ENSURE( xOrig.is(),
782  "HierarchyDataAccess : Data source is not an XSingleServiceFactory!" );
783  return xOrig->createInstanceWithArguments( aArguments );
784 }
785 
786 
787 // XNameContainer methods.
788 
789 
790 // virtual
791 void SAL_CALL
792 HierarchyDataAccess::insertByName( const OUString & aName,
793  const uno::Any & aElement )
794 {
795  uno::Reference< container::XNameContainer > xOrig
796  = ensureOrigInterface( m_xCfgNC );
797 
798  OSL_ENSURE( xOrig.is(),
799  "HierarchyDataAccess : Data source is not an XNameContainer!" );
800  xOrig->insertByName( aName, aElement );
801 }
802 
803 
804 // virtual
805 void SAL_CALL
806 HierarchyDataAccess::removeByName( const OUString & Name )
807 {
808  uno::Reference< container::XNameContainer > xOrig
809  = ensureOrigInterface( m_xCfgNC );
810 
811  OSL_ENSURE( xOrig.is(),
812  "HierarchyDataAccess : Data source is not an XNameContainer!" );
813  xOrig->removeByName( Name );
814 }
815 
816 
817 // XNameReplace methods.
818 
819 
820 // virtual
821 void SAL_CALL HierarchyDataAccess::replaceByName( const OUString & aName,
822  const uno::Any & aElement )
823 {
824  uno::Reference< container::XNameReplace > xOrig
825  = ensureOrigInterface( m_xCfgNR );
826 
827  OSL_ENSURE( xOrig.is(),
828  "HierarchyDataAccess : Data source is not an XNameReplace!" );
829  xOrig->replaceByName( aName, aElement );
830 }
831 
832 
833 // XChangesBatch methods.
834 
835 
836 // virtual
837 void SAL_CALL HierarchyDataAccess::commitChanges()
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  xOrig->commitChanges();
845 }
846 
847 
848 // virtual
849 sal_Bool SAL_CALL HierarchyDataAccess::hasPendingChanges()
850 {
851  uno::Reference< util::XChangesBatch > xOrig
852  = ensureOrigInterface( m_xCfgCB );
853 
854  OSL_ENSURE( xOrig.is(),
855  "HierarchyDataAccess : Data source is not an XChangesBatch!" );
856  return xOrig->hasPendingChanges();
857 }
858 
859 
860 // virtual
861 uno::Sequence< util::ElementChange > SAL_CALL
862 HierarchyDataAccess::getPendingChanges()
863 {
864  uno::Reference< util::XChangesBatch > xOrig
865  = ensureOrigInterface( m_xCfgCB );
866 
867  OSL_ENSURE( xOrig.is(),
868  "HierarchyDataAccess : Data source is not an XChangesBatch!" );
869  return xOrig->getPendingChanges();
870 }
871 
872 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Type
Reference< XMultiServiceFactory > m_xConfigProvider
bool hasValue()
signed char sal_Int8
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
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