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