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