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