1*2f86921cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2f86921cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2f86921cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2f86921cSAndrew Rist  * distributed with this work for additional information
6*2f86921cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2f86921cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2f86921cSAndrew Rist  * "License"); you may not use this file except in compliance
9*2f86921cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2f86921cSAndrew Rist  *
11*2f86921cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2f86921cSAndrew Rist  *
13*2f86921cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2f86921cSAndrew Rist  * software distributed under the License is distributed on an
15*2f86921cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2f86921cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*2f86921cSAndrew Rist  * specific language governing permissions and limitations
18*2f86921cSAndrew Rist  * under the License.
19*2f86921cSAndrew Rist  *
20*2f86921cSAndrew Rist  *************************************************************/
21*2f86921cSAndrew Rist 
22*2f86921cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_ucb.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir /**************************************************************************
28cdf0e10cSrcweir 								TODO
29cdf0e10cSrcweir  **************************************************************************
30cdf0e10cSrcweir 
31cdf0e10cSrcweir  Note: Configuration Management classes do not support XAggregation.
32cdf0e10cSrcweir        So I have to wrap the interesting interfaces manually.
33cdf0e10cSrcweir 
34cdf0e10cSrcweir  *************************************************************************/
35cdf0e10cSrcweir #include "hierarchydatasource.hxx"
36cdf0e10cSrcweir #include <osl/diagnose.h>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #include "osl/doublecheckedlocking.h"
39cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx>
40cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
41cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
42cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
43cdf0e10cSrcweir #include <com/sun/star/util/XChangesBatch.hpp>
44cdf0e10cSrcweir #include <com/sun/star/util/XChangesNotifier.hpp>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir using namespace com::sun::star;
47cdf0e10cSrcweir using namespace hierarchy_ucp;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir //=========================================================================
50cdf0e10cSrcweir 
51cdf0e10cSrcweir // describe path of cfg entry
52cdf0e10cSrcweir #define	CFGPROPERTY_NODEPATH	"nodepath"
53cdf0e10cSrcweir // true->async. update; false->sync. update
54cdf0e10cSrcweir #define	CFGPROPERTY_LAZYWRITE	"lazywrite"
55cdf0e10cSrcweir 
56cdf0e10cSrcweir #define READ_SERVICE_NAME      "com.sun.star.ucb.HierarchyDataReadAccess"
57cdf0e10cSrcweir #define READWRITE_SERVICE_NAME "com.sun.star.ucb.HierarchyDataReadWriteAccess"
58cdf0e10cSrcweir 
59cdf0e10cSrcweir #define CONFIG_PROVIDER_SERVICE_NAME  \
60cdf0e10cSrcweir                         "com.sun.star.configuration.ConfigurationProvider"
61cdf0e10cSrcweir #define CONFIG_READ_SERVICE_NAME      \
62cdf0e10cSrcweir                         "com.sun.star.configuration.ConfigurationAccess"
63cdf0e10cSrcweir #define CONFIG_READWRITE_SERVICE_NAME \
64cdf0e10cSrcweir                         "com.sun.star.configuration.ConfigurationUpdateAccess"
65cdf0e10cSrcweir #define CONFIG_DATA_ROOT_KEY          \
66cdf0e10cSrcweir                         "/org.openoffice.ucb.Hierarchy/Root"
67cdf0e10cSrcweir 
68cdf0e10cSrcweir //=========================================================================
69cdf0e10cSrcweir 
70cdf0e10cSrcweir namespace hcp_impl
71cdf0e10cSrcweir {
72cdf0e10cSrcweir 
73cdf0e10cSrcweir //=========================================================================
74cdf0e10cSrcweir //
75cdf0e10cSrcweir // HierarchyDataReadAccess Implementation.
76cdf0e10cSrcweir //
77cdf0e10cSrcweir //=========================================================================
78cdf0e10cSrcweir 
79cdf0e10cSrcweir class HierarchyDataAccess : public cppu::OWeakObject,
80cdf0e10cSrcweir                             public lang::XServiceInfo,
81cdf0e10cSrcweir                             public lang::XTypeProvider,
82cdf0e10cSrcweir                             public lang::XComponent,
83cdf0e10cSrcweir                             public lang::XSingleServiceFactory,
84cdf0e10cSrcweir                             public container::XHierarchicalNameAccess,
85cdf0e10cSrcweir                             public container::XNameContainer,
86cdf0e10cSrcweir                             public util::XChangesNotifier,
87cdf0e10cSrcweir                             public util::XChangesBatch
88cdf0e10cSrcweir {
89cdf0e10cSrcweir     osl::Mutex m_aMutex;
90cdf0e10cSrcweir     uno::Reference< uno::XInterface > m_xConfigAccess;
91cdf0e10cSrcweir     uno::Reference< lang::XComponent >                   m_xCfgC;
92cdf0e10cSrcweir     uno::Reference< lang::XSingleServiceFactory >        m_xCfgSSF;
93cdf0e10cSrcweir     uno::Reference< container::XHierarchicalNameAccess > m_xCfgHNA;
94cdf0e10cSrcweir     uno::Reference< container::XNameContainer >          m_xCfgNC;
95cdf0e10cSrcweir     uno::Reference< container::XNameReplace >            m_xCfgNR;
96cdf0e10cSrcweir     uno::Reference< container::XNameAccess >             m_xCfgNA;
97cdf0e10cSrcweir     uno::Reference< container::XElementAccess >          m_xCfgEA;
98cdf0e10cSrcweir     uno::Reference< util::XChangesNotifier >             m_xCfgCN;
99cdf0e10cSrcweir     uno::Reference< util::XChangesBatch >                m_xCfgCB;
100cdf0e10cSrcweir     bool m_bReadOnly;
101cdf0e10cSrcweir 
102cdf0e10cSrcweir public:
103cdf0e10cSrcweir     HierarchyDataAccess( const uno::Reference<
104cdf0e10cSrcweir                                         uno::XInterface > & xConfigAccess,
105cdf0e10cSrcweir                          bool bReadOnly );
106cdf0e10cSrcweir     virtual ~HierarchyDataAccess();
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 	// XInterface
109cdf0e10cSrcweir 	XINTERFACE_DECL()
110cdf0e10cSrcweir 
111cdf0e10cSrcweir     // XServiceInfo
112cdf0e10cSrcweir 	XSERVICEINFO_DECL()
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 	// XTypeProvider
115cdf0e10cSrcweir 	XTYPEPROVIDER_DECL()
116cdf0e10cSrcweir 
117cdf0e10cSrcweir     // XComponent
118cdf0e10cSrcweir     virtual void SAL_CALL
119cdf0e10cSrcweir     dispose()
120cdf0e10cSrcweir         throw ( uno::RuntimeException );
121cdf0e10cSrcweir     virtual void SAL_CALL
122cdf0e10cSrcweir     addEventListener( const uno::Reference< lang::XEventListener > & xListener )
123cdf0e10cSrcweir         throw ( uno::RuntimeException );
124cdf0e10cSrcweir     virtual void SAL_CALL
125cdf0e10cSrcweir     removeEventListener( const uno::Reference<
126cdf0e10cSrcweir                             lang::XEventListener > & aListener )
127cdf0e10cSrcweir         throw ( uno::RuntimeException );
128cdf0e10cSrcweir 
129cdf0e10cSrcweir     // XSingleServiceFactory
130cdf0e10cSrcweir     virtual uno::Reference< uno::XInterface > SAL_CALL
131cdf0e10cSrcweir     createInstance()
132cdf0e10cSrcweir         throw ( uno::Exception, uno::RuntimeException );
133cdf0e10cSrcweir     virtual uno::Reference< uno::XInterface > SAL_CALL
134cdf0e10cSrcweir     createInstanceWithArguments( const uno::Sequence< uno::Any > & aArguments )
135cdf0e10cSrcweir         throw ( uno::Exception, uno::RuntimeException );
136cdf0e10cSrcweir 
137cdf0e10cSrcweir     // XHierarchicalNameAccess
138cdf0e10cSrcweir     virtual uno::Any SAL_CALL
139cdf0e10cSrcweir     getByHierarchicalName( const rtl::OUString & aName )
140cdf0e10cSrcweir         throw ( container::NoSuchElementException, uno::RuntimeException );
141cdf0e10cSrcweir     virtual sal_Bool SAL_CALL
142cdf0e10cSrcweir     hasByHierarchicalName( const rtl::OUString & aName )
143cdf0e10cSrcweir         throw ( uno::RuntimeException );
144cdf0e10cSrcweir 
145cdf0e10cSrcweir     // XNameContainer
146cdf0e10cSrcweir     virtual void SAL_CALL
147cdf0e10cSrcweir     insertByName( const rtl::OUString & aName, const uno::Any & aElement )
148cdf0e10cSrcweir         throw ( lang::IllegalArgumentException,
149cdf0e10cSrcweir                 container::ElementExistException,
150cdf0e10cSrcweir                 lang::WrappedTargetException,
151cdf0e10cSrcweir                 uno::RuntimeException );
152cdf0e10cSrcweir     virtual void SAL_CALL
153cdf0e10cSrcweir     removeByName( const rtl::OUString & Name )
154cdf0e10cSrcweir         throw ( container::NoSuchElementException,
155cdf0e10cSrcweir                 lang::WrappedTargetException,
156cdf0e10cSrcweir                 uno::RuntimeException );
157cdf0e10cSrcweir 
158cdf0e10cSrcweir     // XNameReplace ( base of XNameContainer )
159cdf0e10cSrcweir     virtual void SAL_CALL
160cdf0e10cSrcweir     replaceByName( const rtl::OUString & aName, const uno::Any & aElement )
161cdf0e10cSrcweir         throw ( lang::IllegalArgumentException,
162cdf0e10cSrcweir                 container::NoSuchElementException,
163cdf0e10cSrcweir                 lang::WrappedTargetException,
164cdf0e10cSrcweir                 uno::RuntimeException );
165cdf0e10cSrcweir 
166cdf0e10cSrcweir     // XNameAccess ( base of XNameReplace )
167cdf0e10cSrcweir     virtual uno::Any SAL_CALL
168cdf0e10cSrcweir     getByName( const rtl::OUString & aName )
169cdf0e10cSrcweir         throw ( container::NoSuchElementException,
170cdf0e10cSrcweir                 lang::WrappedTargetException,
171cdf0e10cSrcweir                 uno::RuntimeException );
172cdf0e10cSrcweir     virtual uno::Sequence< rtl::OUString > SAL_CALL
173cdf0e10cSrcweir     getElementNames()
174cdf0e10cSrcweir         throw ( uno::RuntimeException );
175cdf0e10cSrcweir     virtual sal_Bool SAL_CALL
176cdf0e10cSrcweir     hasByName( const rtl::OUString & aName )
177cdf0e10cSrcweir         throw ( uno::RuntimeException );
178cdf0e10cSrcweir 
179cdf0e10cSrcweir     // XElementAccess ( base of XNameAccess )
180cdf0e10cSrcweir     virtual uno::Type SAL_CALL
181cdf0e10cSrcweir     getElementType()
182cdf0e10cSrcweir         throw ( uno::RuntimeException );
183cdf0e10cSrcweir     virtual sal_Bool SAL_CALL
184cdf0e10cSrcweir     hasElements()
185cdf0e10cSrcweir         throw ( uno::RuntimeException );
186cdf0e10cSrcweir 
187cdf0e10cSrcweir     // XChangesNotifier
188cdf0e10cSrcweir     virtual void SAL_CALL
189cdf0e10cSrcweir     addChangesListener( const uno::Reference<
190cdf0e10cSrcweir                             util::XChangesListener > & aListener )
191cdf0e10cSrcweir         throw ( uno::RuntimeException );
192cdf0e10cSrcweir     virtual void SAL_CALL
193cdf0e10cSrcweir     removeChangesListener( const uno::Reference<
194cdf0e10cSrcweir                             util::XChangesListener > & aListener )
195cdf0e10cSrcweir         throw ( uno::RuntimeException );
196cdf0e10cSrcweir 
197cdf0e10cSrcweir     // XChangesBatch
198cdf0e10cSrcweir     virtual void SAL_CALL
199cdf0e10cSrcweir     commitChanges()
200cdf0e10cSrcweir         throw ( lang::WrappedTargetException, uno::RuntimeException );
201cdf0e10cSrcweir     virtual sal_Bool SAL_CALL
202cdf0e10cSrcweir     hasPendingChanges()
203cdf0e10cSrcweir         throw ( uno::RuntimeException );
204cdf0e10cSrcweir     virtual uno::Sequence< util::ElementChange > SAL_CALL
205cdf0e10cSrcweir     getPendingChanges()
206cdf0e10cSrcweir         throw ( uno::RuntimeException );
207cdf0e10cSrcweir };
208cdf0e10cSrcweir 
209cdf0e10cSrcweir } // namespace hcp_impl
210cdf0e10cSrcweir 
211cdf0e10cSrcweir using namespace hcp_impl;
212cdf0e10cSrcweir 
213cdf0e10cSrcweir //=========================================================================
214cdf0e10cSrcweir //=========================================================================
215cdf0e10cSrcweir //
216cdf0e10cSrcweir // HierarchyDataSource Implementation.
217cdf0e10cSrcweir //
218cdf0e10cSrcweir //=========================================================================
219cdf0e10cSrcweir //=========================================================================
220cdf0e10cSrcweir 
221cdf0e10cSrcweir HierarchyDataSource::HierarchyDataSource(
222cdf0e10cSrcweir         const uno::Reference< lang::XMultiServiceFactory > & rxServiceMgr )
223cdf0e10cSrcweir : m_xSMgr( rxServiceMgr ),
224cdf0e10cSrcweir   m_pDisposeEventListeners( 0 )
225cdf0e10cSrcweir {
226cdf0e10cSrcweir }
227cdf0e10cSrcweir 
228cdf0e10cSrcweir //=========================================================================
229cdf0e10cSrcweir // virtual
230cdf0e10cSrcweir HierarchyDataSource::~HierarchyDataSource()
231cdf0e10cSrcweir {
232cdf0e10cSrcweir     delete m_pDisposeEventListeners;
233cdf0e10cSrcweir }
234cdf0e10cSrcweir 
235cdf0e10cSrcweir //=========================================================================
236cdf0e10cSrcweir //
237cdf0e10cSrcweir // XInterface methods.
238cdf0e10cSrcweir //
239cdf0e10cSrcweir //=========================================================================
240cdf0e10cSrcweir 
241cdf0e10cSrcweir XINTERFACE_IMPL_4( HierarchyDataSource,
242cdf0e10cSrcweir                    lang::XTypeProvider,
243cdf0e10cSrcweir                    lang::XServiceInfo,
244cdf0e10cSrcweir                    lang::XComponent,
245cdf0e10cSrcweir                    lang::XMultiServiceFactory );
246cdf0e10cSrcweir 
247cdf0e10cSrcweir //=========================================================================
248cdf0e10cSrcweir //
249cdf0e10cSrcweir // XTypeProvider methods.
250cdf0e10cSrcweir //
251cdf0e10cSrcweir //=========================================================================
252cdf0e10cSrcweir 
253cdf0e10cSrcweir XTYPEPROVIDER_IMPL_4( HierarchyDataSource,
254cdf0e10cSrcweir                       lang::XTypeProvider,
255cdf0e10cSrcweir                       lang::XServiceInfo,
256cdf0e10cSrcweir                       lang::XComponent,
257cdf0e10cSrcweir                       lang::XMultiServiceFactory );
258cdf0e10cSrcweir 
259cdf0e10cSrcweir //=========================================================================
260cdf0e10cSrcweir //
261cdf0e10cSrcweir // XServiceInfo methods.
262cdf0e10cSrcweir //
263cdf0e10cSrcweir //=========================================================================
264cdf0e10cSrcweir 
265cdf0e10cSrcweir XSERVICEINFO_IMPL_0( HierarchyDataSource,
266cdf0e10cSrcweir                      rtl::OUString::createFromAscii(
267cdf0e10cSrcweir                         "com.sun.star.comp.ucb.HierarchyDataSource" ) )
268cdf0e10cSrcweir {
269cdf0e10cSrcweir     uno::Sequence< rtl::OUString > aSNS( 2 );
270cdf0e10cSrcweir     aSNS[ 0 ] = rtl::OUString::createFromAscii(
271cdf0e10cSrcweir                     "com.sun.star.ucb.DefaultHierarchyDataSource" );
272cdf0e10cSrcweir     aSNS[ 1 ] = rtl::OUString::createFromAscii(
273cdf0e10cSrcweir                     "com.sun.star.ucb.HierarchyDataSource" );
274cdf0e10cSrcweir     return aSNS;
275cdf0e10cSrcweir }
276cdf0e10cSrcweir 
277cdf0e10cSrcweir ONE_INSTANCE_SERVICE_FACTORY_IMPL( HierarchyDataSource );
278cdf0e10cSrcweir 
279cdf0e10cSrcweir //=========================================================================
280cdf0e10cSrcweir //
281cdf0e10cSrcweir // XComponent methods.
282cdf0e10cSrcweir //
283cdf0e10cSrcweir //=========================================================================
284cdf0e10cSrcweir 
285cdf0e10cSrcweir // virtual
286cdf0e10cSrcweir void SAL_CALL HierarchyDataSource::dispose()
287cdf0e10cSrcweir     throw( uno::RuntimeException )
288cdf0e10cSrcweir {
289cdf0e10cSrcweir 	osl::Guard< osl::Mutex > aGuard( m_aMutex );
290cdf0e10cSrcweir 
291cdf0e10cSrcweir     if ( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() )
292cdf0e10cSrcweir 	{
293cdf0e10cSrcweir         lang::EventObject aEvt;
294cdf0e10cSrcweir         aEvt.Source = static_cast< lang::XComponent * >( this );
295cdf0e10cSrcweir         m_pDisposeEventListeners->disposeAndClear( aEvt );
296cdf0e10cSrcweir 	}
297cdf0e10cSrcweir }
298cdf0e10cSrcweir 
299cdf0e10cSrcweir //=========================================================================
300cdf0e10cSrcweir // virtual
301cdf0e10cSrcweir void SAL_CALL HierarchyDataSource::addEventListener(
302cdf0e10cSrcweir                     const uno::Reference< lang::XEventListener > & Listener )
303cdf0e10cSrcweir     throw( uno::RuntimeException )
304cdf0e10cSrcweir {
305cdf0e10cSrcweir 	osl::Guard< osl::Mutex > aGuard( m_aMutex );
306cdf0e10cSrcweir 
307cdf0e10cSrcweir     if ( !m_pDisposeEventListeners )
308cdf0e10cSrcweir         m_pDisposeEventListeners
309cdf0e10cSrcweir             = new cppu::OInterfaceContainerHelper( m_aMutex );
310cdf0e10cSrcweir 
311cdf0e10cSrcweir     m_pDisposeEventListeners->addInterface( Listener );
312cdf0e10cSrcweir }
313cdf0e10cSrcweir 
314cdf0e10cSrcweir //=========================================================================
315cdf0e10cSrcweir // virtual
316cdf0e10cSrcweir void SAL_CALL HierarchyDataSource::removeEventListener(
317cdf0e10cSrcweir                     const uno::Reference< lang::XEventListener > & Listener )
318cdf0e10cSrcweir     throw( uno::RuntimeException )
319cdf0e10cSrcweir {
320cdf0e10cSrcweir 	osl::Guard< osl::Mutex > aGuard( m_aMutex );
321cdf0e10cSrcweir 
322cdf0e10cSrcweir     if ( m_pDisposeEventListeners )
323cdf0e10cSrcweir         m_pDisposeEventListeners->removeInterface( Listener );
324cdf0e10cSrcweir }
325cdf0e10cSrcweir 
326cdf0e10cSrcweir //=========================================================================
327cdf0e10cSrcweir //
328cdf0e10cSrcweir // XMultiServiceFactory methods.
329cdf0e10cSrcweir //
330cdf0e10cSrcweir //=========================================================================
331cdf0e10cSrcweir 
332cdf0e10cSrcweir // virtual
333cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL
334cdf0e10cSrcweir HierarchyDataSource::createInstance( const rtl::OUString & aServiceSpecifier )
335cdf0e10cSrcweir     throw ( uno::Exception, uno::RuntimeException )
336cdf0e10cSrcweir {
337cdf0e10cSrcweir     // Create view to root node.
338cdf0e10cSrcweir 
339cdf0e10cSrcweir     beans::PropertyValue aProp;
340cdf0e10cSrcweir     aProp.Name = rtl::OUString(
341cdf0e10cSrcweir                         RTL_CONSTASCII_USTRINGPARAM( CFGPROPERTY_NODEPATH ) );
342cdf0e10cSrcweir     aProp.Value <<=
343cdf0e10cSrcweir         rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CONFIG_DATA_ROOT_KEY ) );
344cdf0e10cSrcweir 
345cdf0e10cSrcweir     uno::Sequence< uno::Any > aArguments( 1 );
346cdf0e10cSrcweir     aArguments[ 0 ] <<= aProp;
347cdf0e10cSrcweir 
348cdf0e10cSrcweir     return createInstanceWithArguments( aServiceSpecifier, aArguments, false );
349cdf0e10cSrcweir }
350cdf0e10cSrcweir 
351cdf0e10cSrcweir //=========================================================================
352cdf0e10cSrcweir // virtual
353cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL
354cdf0e10cSrcweir HierarchyDataSource::createInstanceWithArguments(
355cdf0e10cSrcweir                                 const rtl::OUString & ServiceSpecifier,
356cdf0e10cSrcweir                                 const uno::Sequence< uno::Any > & Arguments )
357cdf0e10cSrcweir     throw ( uno::Exception, uno::RuntimeException )
358cdf0e10cSrcweir {
359cdf0e10cSrcweir     return createInstanceWithArguments( ServiceSpecifier, Arguments, true );
360cdf0e10cSrcweir }
361cdf0e10cSrcweir 
362cdf0e10cSrcweir //=========================================================================
363cdf0e10cSrcweir // virtual
364cdf0e10cSrcweir uno::Sequence< rtl::OUString > SAL_CALL
365cdf0e10cSrcweir HierarchyDataSource::getAvailableServiceNames()
366cdf0e10cSrcweir     throw ( uno::RuntimeException )
367cdf0e10cSrcweir {
368cdf0e10cSrcweir     uno::Sequence< rtl::OUString > aNames( 2 );
369cdf0e10cSrcweir     aNames[ 0 ] = rtl::OUString(
370cdf0e10cSrcweir                     RTL_CONSTASCII_USTRINGPARAM( READ_SERVICE_NAME ) );
371cdf0e10cSrcweir     aNames[ 1 ] = rtl::OUString(
372cdf0e10cSrcweir                     RTL_CONSTASCII_USTRINGPARAM( READWRITE_SERVICE_NAME ) );
373cdf0e10cSrcweir     return aNames;
374cdf0e10cSrcweir }
375cdf0e10cSrcweir 
376cdf0e10cSrcweir //=========================================================================
377cdf0e10cSrcweir //
378cdf0e10cSrcweir // Non-interface methods
379cdf0e10cSrcweir //
380cdf0e10cSrcweir //=========================================================================
381cdf0e10cSrcweir 
382cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL
383cdf0e10cSrcweir HierarchyDataSource::createInstanceWithArguments(
384cdf0e10cSrcweir                                 const rtl::OUString & ServiceSpecifier,
385cdf0e10cSrcweir                                 const uno::Sequence< uno::Any > & Arguments,
386cdf0e10cSrcweir                                 bool bCheckArgs )
387cdf0e10cSrcweir     throw ( uno::Exception, uno::RuntimeException )
388cdf0e10cSrcweir {
389cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( m_aMutex );
390cdf0e10cSrcweir 
391cdf0e10cSrcweir     // Check service specifier.
392cdf0e10cSrcweir     bool bReadOnly  = !!ServiceSpecifier.equalsAsciiL(
393cdf0e10cSrcweir                         RTL_CONSTASCII_STRINGPARAM( READ_SERVICE_NAME ) );
394cdf0e10cSrcweir     bool bReadWrite = !bReadOnly &&
395cdf0e10cSrcweir                       ServiceSpecifier.equalsAsciiL(
396cdf0e10cSrcweir                         RTL_CONSTASCII_STRINGPARAM( READWRITE_SERVICE_NAME ) );
397cdf0e10cSrcweir 
398cdf0e10cSrcweir     if ( !bReadOnly && !bReadWrite )
399cdf0e10cSrcweir     {
400cdf0e10cSrcweir         OSL_ENSURE( false,
401cdf0e10cSrcweir                     "HierarchyDataSource::createInstanceWithArguments - "
402cdf0e10cSrcweir                     "Unsupported service specifier!" );
403cdf0e10cSrcweir         return uno::Reference< uno::XInterface >();
404cdf0e10cSrcweir     }
405cdf0e10cSrcweir 
406cdf0e10cSrcweir     uno::Sequence< uno::Any > aNewArgs( Arguments );
407cdf0e10cSrcweir 
408cdf0e10cSrcweir     bool bHasLazyWriteProp = bReadOnly; // property must be added only if
409cdf0e10cSrcweir                                         // a writable view is requested.
410cdf0e10cSrcweir     if ( bCheckArgs )
411cdf0e10cSrcweir     {
412cdf0e10cSrcweir         // Check arguments.
413cdf0e10cSrcweir         bool bHasNodePath = false;
414cdf0e10cSrcweir         sal_Int32 nCount = Arguments.getLength();
415cdf0e10cSrcweir         for ( sal_Int32 n = 0; n < nCount; ++n )
416cdf0e10cSrcweir         {
417cdf0e10cSrcweir             beans::PropertyValue aProp;
418cdf0e10cSrcweir             if ( Arguments[ n ] >>= aProp )
419cdf0e10cSrcweir             {
420cdf0e10cSrcweir                 if ( aProp.Name.equalsAsciiL(
421cdf0e10cSrcweir                         RTL_CONSTASCII_STRINGPARAM( CFGPROPERTY_NODEPATH ) ) )
422cdf0e10cSrcweir                 {
423cdf0e10cSrcweir                     rtl::OUString aPath;
424cdf0e10cSrcweir                     if ( aProp.Value >>= aPath )
425cdf0e10cSrcweir                     {
426cdf0e10cSrcweir                         bHasNodePath = true;
427cdf0e10cSrcweir 
428cdf0e10cSrcweir                         // Create path to data inside the configuration.
429cdf0e10cSrcweir                         rtl::OUString aConfigPath;
430cdf0e10cSrcweir                         if ( !createConfigPath( aPath, aConfigPath ) )
431cdf0e10cSrcweir                         {
432cdf0e10cSrcweir                             OSL_ENSURE( false,
433cdf0e10cSrcweir                                 "HierarchyDataSource::"
434cdf0e10cSrcweir                                 "createInstanceWithArguments - "
435cdf0e10cSrcweir                                 "Invalid node path!" );
436cdf0e10cSrcweir                             return uno::Reference< uno::XInterface >();
437cdf0e10cSrcweir                         }
438cdf0e10cSrcweir 
439cdf0e10cSrcweir                         aProp.Value <<= aConfigPath;
440cdf0e10cSrcweir 
441cdf0e10cSrcweir                         // Set new path in arguments.
442cdf0e10cSrcweir                         aNewArgs[ n ] <<= aProp;
443cdf0e10cSrcweir 
444cdf0e10cSrcweir                         if ( bHasLazyWriteProp )
445cdf0e10cSrcweir                             break;
446cdf0e10cSrcweir                     }
447cdf0e10cSrcweir                     else
448cdf0e10cSrcweir                     {
449cdf0e10cSrcweir                         OSL_ENSURE( false,
450cdf0e10cSrcweir                             "HierarchyDataSource::createInstanceWithArguments - "
451cdf0e10cSrcweir                             "Invalid type for property 'nodepath'!" );
452cdf0e10cSrcweir                         return uno::Reference< uno::XInterface >();
453cdf0e10cSrcweir                     }
454cdf0e10cSrcweir                 }
455cdf0e10cSrcweir                 else if ( aProp.Name.equalsAsciiL(
456cdf0e10cSrcweir                             RTL_CONSTASCII_STRINGPARAM(
457cdf0e10cSrcweir                                 CFGPROPERTY_LAZYWRITE ) ) )
458cdf0e10cSrcweir                 {
459cdf0e10cSrcweir                     if ( aProp.Value.getValueType() == getCppuBooleanType() )
460cdf0e10cSrcweir                     {
461cdf0e10cSrcweir                         bHasLazyWriteProp = true;
462cdf0e10cSrcweir 
463cdf0e10cSrcweir                         if ( bHasNodePath )
464cdf0e10cSrcweir                             break;
465cdf0e10cSrcweir                     }
466cdf0e10cSrcweir                     else
467cdf0e10cSrcweir                     {
468cdf0e10cSrcweir                         OSL_ENSURE( false,
469cdf0e10cSrcweir                             "HierarchyDataSource::createInstanceWithArguments - "
470cdf0e10cSrcweir                             "Invalid type for property 'lazywrite'!" );
471cdf0e10cSrcweir                         return uno::Reference< uno::XInterface >();
472cdf0e10cSrcweir                     }
473cdf0e10cSrcweir                 }
474cdf0e10cSrcweir             }
475cdf0e10cSrcweir         }
476cdf0e10cSrcweir 
477cdf0e10cSrcweir         if ( !bHasNodePath )
478cdf0e10cSrcweir         {
479cdf0e10cSrcweir             OSL_ENSURE( false,
480cdf0e10cSrcweir                         "HierarchyDataSource::createInstanceWithArguments - "
481cdf0e10cSrcweir                         "No 'nodepath' property!" );
482cdf0e10cSrcweir             return uno::Reference< uno::XInterface >();
483cdf0e10cSrcweir         }
484cdf0e10cSrcweir     }
485cdf0e10cSrcweir 
486cdf0e10cSrcweir     // Create Configuration Provider.
487cdf0e10cSrcweir     uno::Reference< lang::XMultiServiceFactory > xProv = getConfigProvider();
488cdf0e10cSrcweir     if ( !xProv.is() )
489cdf0e10cSrcweir         return uno::Reference< uno::XInterface >();
490cdf0e10cSrcweir 
491cdf0e10cSrcweir     uno::Reference< uno::XInterface > xConfigAccess;
492cdf0e10cSrcweir     try
493cdf0e10cSrcweir     {
494cdf0e10cSrcweir         if ( bReadOnly )
495cdf0e10cSrcweir         {
496cdf0e10cSrcweir             // Create configuration read-only access object.
497cdf0e10cSrcweir             xConfigAccess = xProv->createInstanceWithArguments(
498cdf0e10cSrcweir                                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
499cdf0e10cSrcweir                                         CONFIG_READ_SERVICE_NAME ) ),
500cdf0e10cSrcweir                                 aNewArgs );
501cdf0e10cSrcweir         }
502cdf0e10cSrcweir         else
503cdf0e10cSrcweir         {
504cdf0e10cSrcweir             // Append 'lazywrite' property value, if not already present.
505cdf0e10cSrcweir             if ( !bHasLazyWriteProp )
506cdf0e10cSrcweir             {
507cdf0e10cSrcweir                 sal_Int32 nLen = aNewArgs.getLength();
508cdf0e10cSrcweir                 aNewArgs.realloc( nLen + 1 );
509cdf0e10cSrcweir 
510cdf0e10cSrcweir                 beans::PropertyValue aProp;
511cdf0e10cSrcweir                 aProp.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
512cdf0e10cSrcweir                                                     CFGPROPERTY_LAZYWRITE ) );
513cdf0e10cSrcweir                 aProp.Value <<= sal_True;
514cdf0e10cSrcweir                 aNewArgs[ nLen ] <<= aProp;
515cdf0e10cSrcweir             }
516cdf0e10cSrcweir 
517cdf0e10cSrcweir             // Create configuration read-write access object.
518cdf0e10cSrcweir             xConfigAccess = xProv->createInstanceWithArguments(
519cdf0e10cSrcweir                                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
520cdf0e10cSrcweir                                         CONFIG_READWRITE_SERVICE_NAME ) ),
521cdf0e10cSrcweir                                 aNewArgs );
522cdf0e10cSrcweir         }
523cdf0e10cSrcweir     }
524cdf0e10cSrcweir     catch ( uno::Exception const & )
525cdf0e10cSrcweir     {
526cdf0e10cSrcweir         OSL_ENSURE( false,
527cdf0e10cSrcweir                     "HierarchyDataSource::createInstanceWithArguments - "
528cdf0e10cSrcweir                     "Cannot instanciate configuration access!" );
529cdf0e10cSrcweir         throw;
530cdf0e10cSrcweir     }
531cdf0e10cSrcweir 
532cdf0e10cSrcweir     if ( !xConfigAccess.is() )
533cdf0e10cSrcweir     {
534cdf0e10cSrcweir         OSL_ENSURE( false,
535cdf0e10cSrcweir                     "HierarchyDataSource::createInstanceWithArguments - "
536cdf0e10cSrcweir                     "Cannot instanciate configuration access!" );
537cdf0e10cSrcweir         return xConfigAccess;
538cdf0e10cSrcweir     }
539cdf0e10cSrcweir 
540cdf0e10cSrcweir     return uno::Reference< uno::XInterface >(
541cdf0e10cSrcweir                 static_cast< cppu::OWeakObject * >(
542cdf0e10cSrcweir                     new HierarchyDataAccess( xConfigAccess, bReadOnly ) ) );
543cdf0e10cSrcweir }
544cdf0e10cSrcweir 
545cdf0e10cSrcweir //=========================================================================
546cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory >
547cdf0e10cSrcweir HierarchyDataSource::getConfigProvider()
548cdf0e10cSrcweir {
549cdf0e10cSrcweir 	if ( !m_xConfigProvider.is() )
550cdf0e10cSrcweir 	{
551cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( m_aMutex );
552cdf0e10cSrcweir 		if ( !m_xConfigProvider.is() )
553cdf0e10cSrcweir 		{
554cdf0e10cSrcweir 			try
555cdf0e10cSrcweir 			{
556cdf0e10cSrcweir                 m_xConfigProvider
557cdf0e10cSrcweir                     = uno::Reference< lang::XMultiServiceFactory >(
558cdf0e10cSrcweir                         m_xSMgr->createInstance(
559cdf0e10cSrcweir                             rtl::OUString(
560cdf0e10cSrcweir                                 RTL_CONSTASCII_USTRINGPARAM(
561cdf0e10cSrcweir                                     CONFIG_PROVIDER_SERVICE_NAME ) ) ),
562cdf0e10cSrcweir                         uno::UNO_QUERY );
563cdf0e10cSrcweir 
564cdf0e10cSrcweir                 OSL_ENSURE( m_xConfigProvider.is(),
565cdf0e10cSrcweir                             "HierarchyDataSource::getConfigProvider - "
566cdf0e10cSrcweir                             "No configuration provider!" );
567cdf0e10cSrcweir 			}
568cdf0e10cSrcweir             catch ( uno::Exception const & )
569cdf0e10cSrcweir 			{
570cdf0e10cSrcweir                 OSL_ENSURE( false,
571cdf0e10cSrcweir                             "HierarchyDataSource::getConfigProvider - "
572cdf0e10cSrcweir 				   			"caught exception!" );
573cdf0e10cSrcweir 			}
574cdf0e10cSrcweir 		}
575cdf0e10cSrcweir 	}
576cdf0e10cSrcweir 
577cdf0e10cSrcweir 	return m_xConfigProvider;
578cdf0e10cSrcweir }
579cdf0e10cSrcweir 
580cdf0e10cSrcweir //=========================================================================
581cdf0e10cSrcweir bool HierarchyDataSource::createConfigPath(
582cdf0e10cSrcweir                 const rtl::OUString & rInPath, rtl::OUString & rOutPath )
583cdf0e10cSrcweir {
584cdf0e10cSrcweir     if ( rInPath.getLength() )
585cdf0e10cSrcweir     {
586cdf0e10cSrcweir         if ( rInPath.indexOf( '/' ) == 0 )
587cdf0e10cSrcweir         {
588cdf0e10cSrcweir             OSL_ENSURE( false,
589cdf0e10cSrcweir                         "HierarchyDataSource::createConfigPath - "
590cdf0e10cSrcweir                         "Leading slash in node path!" );
591cdf0e10cSrcweir             return false;
592cdf0e10cSrcweir         }
593cdf0e10cSrcweir 
594cdf0e10cSrcweir         if ( rInPath.lastIndexOf( '/' ) == rInPath.getLength() - 1 )
595cdf0e10cSrcweir         {
596cdf0e10cSrcweir             OSL_ENSURE( false,
597cdf0e10cSrcweir                         "HierarchyDataSource::createConfigPath - "
598cdf0e10cSrcweir                         "Trailing slash in node path!" );
599cdf0e10cSrcweir             return false;
600cdf0e10cSrcweir         }
601cdf0e10cSrcweir 
602cdf0e10cSrcweir         rtl::OUString aOutPath(
603cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM( CONFIG_DATA_ROOT_KEY "/" ) );
604cdf0e10cSrcweir         aOutPath += rInPath;
605cdf0e10cSrcweir         rOutPath = aOutPath;
606cdf0e10cSrcweir     }
607cdf0e10cSrcweir     else
608cdf0e10cSrcweir     {
609cdf0e10cSrcweir         rOutPath = rtl::OUString(
610cdf0e10cSrcweir                     RTL_CONSTASCII_USTRINGPARAM( CONFIG_DATA_ROOT_KEY ) );
611cdf0e10cSrcweir     }
612cdf0e10cSrcweir 
613cdf0e10cSrcweir     return true;
614cdf0e10cSrcweir }
615cdf0e10cSrcweir 
616cdf0e10cSrcweir //=========================================================================
617cdf0e10cSrcweir //=========================================================================
618cdf0e10cSrcweir //
619cdf0e10cSrcweir // HierarchyDataAccess Implementation.
620cdf0e10cSrcweir //
621cdf0e10cSrcweir //=========================================================================
622cdf0e10cSrcweir //=========================================================================
623cdf0e10cSrcweir 
624cdf0e10cSrcweir #define ENSURE_ORIG_INTERFACE( interface_name, member_name )    \
625cdf0e10cSrcweir     m_xCfg##member_name;                                        \
626cdf0e10cSrcweir     if ( !m_xCfg##member_name.is() )                            \
627cdf0e10cSrcweir     {                                                           \
628cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( m_aMutex );            \
629cdf0e10cSrcweir         if ( !m_xCfg##member_name.is() )                        \
630cdf0e10cSrcweir             m_xCfg##member_name                                 \
631cdf0e10cSrcweir                 = uno::Reference< interface_name >(             \
632cdf0e10cSrcweir                     m_xConfigAccess, uno::UNO_QUERY );          \
633cdf0e10cSrcweir         xOrig = m_xCfg##member_name;                            \
634cdf0e10cSrcweir     }
635cdf0e10cSrcweir 
636cdf0e10cSrcweir //=========================================================================
637cdf0e10cSrcweir HierarchyDataAccess::HierarchyDataAccess( const uno::Reference<
638cdf0e10cSrcweir                                             uno::XInterface > & xConfigAccess,
639cdf0e10cSrcweir                                           bool bReadOnly )
640cdf0e10cSrcweir : m_xConfigAccess( xConfigAccess ),
641cdf0e10cSrcweir   m_bReadOnly( bReadOnly )
642cdf0e10cSrcweir {
643cdf0e10cSrcweir }
644cdf0e10cSrcweir 
645cdf0e10cSrcweir //=========================================================================
646cdf0e10cSrcweir // virtual
647cdf0e10cSrcweir HierarchyDataAccess::~HierarchyDataAccess()
648cdf0e10cSrcweir {
649cdf0e10cSrcweir }
650cdf0e10cSrcweir 
651cdf0e10cSrcweir //=========================================================================
652cdf0e10cSrcweir //
653cdf0e10cSrcweir // XInterface methods.
654cdf0e10cSrcweir //
655cdf0e10cSrcweir //=========================================================================
656cdf0e10cSrcweir 
657cdf0e10cSrcweir XINTERFACE_COMMON_IMPL( HierarchyDataAccess );
658cdf0e10cSrcweir 
659cdf0e10cSrcweir //=========================================================================
660cdf0e10cSrcweir // virtual
661cdf0e10cSrcweir uno::Any SAL_CALL HierarchyDataAccess::queryInterface( const uno::Type & aType )
662cdf0e10cSrcweir     throw ( uno::RuntimeException )
663cdf0e10cSrcweir {
664cdf0e10cSrcweir     // Interfaces supported in read-only and read-write mode.
665cdf0e10cSrcweir     uno::Any aRet = cppu::queryInterface( aType,
666cdf0e10cSrcweir                 static_cast< lang::XTypeProvider * >( this ),
667cdf0e10cSrcweir                 static_cast< lang::XServiceInfo * >( this ),
668cdf0e10cSrcweir                 static_cast< lang::XComponent * >( this ),
669cdf0e10cSrcweir                 static_cast< container::XHierarchicalNameAccess * >( this ),
670cdf0e10cSrcweir                 static_cast< container::XNameAccess * >( this ),
671cdf0e10cSrcweir                 static_cast< container::XElementAccess * >( this ),
672cdf0e10cSrcweir                 static_cast< util::XChangesNotifier * >( this ) );
673cdf0e10cSrcweir 
674cdf0e10cSrcweir     // Interfaces supported only in read-write mode.
675cdf0e10cSrcweir     if ( !aRet.hasValue() && !m_bReadOnly )
676cdf0e10cSrcweir     {
677cdf0e10cSrcweir         aRet = cppu::queryInterface( aType,
678cdf0e10cSrcweir                 static_cast< lang::XSingleServiceFactory * >( this ),
679cdf0e10cSrcweir                 static_cast< container::XNameContainer * >( this ),
680cdf0e10cSrcweir                 static_cast< container::XNameReplace * >( this ),
681cdf0e10cSrcweir                 static_cast< util::XChangesBatch * >( this ) );
682cdf0e10cSrcweir     }
683cdf0e10cSrcweir 
684cdf0e10cSrcweir     return aRet.hasValue() ? aRet : OWeakObject::queryInterface( aType );
685cdf0e10cSrcweir }
686cdf0e10cSrcweir 
687cdf0e10cSrcweir //=========================================================================
688cdf0e10cSrcweir //
689cdf0e10cSrcweir // XTypeProvider methods.
690cdf0e10cSrcweir //
691cdf0e10cSrcweir //=========================================================================
692cdf0e10cSrcweir 
693cdf0e10cSrcweir XTYPEPROVIDER_COMMON_IMPL( HierarchyDataAccess );
694cdf0e10cSrcweir 
695cdf0e10cSrcweir //=========================================================================
696cdf0e10cSrcweir // virtual
697cdf0e10cSrcweir uno::Sequence< uno::Type > SAL_CALL HierarchyDataAccess::getTypes()
698cdf0e10cSrcweir     throw( uno::RuntimeException )
699cdf0e10cSrcweir {
700cdf0e10cSrcweir     cppu::OTypeCollection * pCollection = 0;
701cdf0e10cSrcweir 
702cdf0e10cSrcweir     if ( m_bReadOnly )
703cdf0e10cSrcweir     {
704cdf0e10cSrcweir         static cppu::OTypeCollection* pReadOnlyTypes = 0;
705cdf0e10cSrcweir 
706cdf0e10cSrcweir         pCollection = pReadOnlyTypes;
707cdf0e10cSrcweir         if ( !pCollection )
708cdf0e10cSrcweir         {
709cdf0e10cSrcweir             osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
710cdf0e10cSrcweir 
711cdf0e10cSrcweir             pCollection = pReadOnlyTypes;
712cdf0e10cSrcweir             if ( !pCollection )
713cdf0e10cSrcweir             {
714cdf0e10cSrcweir                 static cppu::OTypeCollection aCollection(
715cdf0e10cSrcweir                     CPPU_TYPE_REF( lang::XTypeProvider ),
716cdf0e10cSrcweir                     CPPU_TYPE_REF( lang::XServiceInfo ),
717cdf0e10cSrcweir                     CPPU_TYPE_REF( lang::XComponent ),
718cdf0e10cSrcweir                     CPPU_TYPE_REF( container::XHierarchicalNameAccess ),
719cdf0e10cSrcweir                     CPPU_TYPE_REF( container::XNameAccess ),
720cdf0e10cSrcweir                     CPPU_TYPE_REF( util::XChangesNotifier ) );
721cdf0e10cSrcweir                 pCollection = &aCollection;
722cdf0e10cSrcweir                 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
723cdf0e10cSrcweir                 pReadOnlyTypes = pCollection;
724cdf0e10cSrcweir             }
725cdf0e10cSrcweir         }
726cdf0e10cSrcweir         else {
727cdf0e10cSrcweir             OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
728cdf0e10cSrcweir         }
729cdf0e10cSrcweir     }
730cdf0e10cSrcweir     else
731cdf0e10cSrcweir     {
732cdf0e10cSrcweir         static cppu::OTypeCollection* pReadWriteTypes = 0;
733cdf0e10cSrcweir 
734cdf0e10cSrcweir         pCollection = pReadWriteTypes;
735cdf0e10cSrcweir         if ( !pCollection )
736cdf0e10cSrcweir         {
737cdf0e10cSrcweir             osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
738cdf0e10cSrcweir 
739cdf0e10cSrcweir             pCollection = pReadWriteTypes;
740cdf0e10cSrcweir             if ( !pCollection )
741cdf0e10cSrcweir             {
742cdf0e10cSrcweir                 static cppu::OTypeCollection aCollection(
743cdf0e10cSrcweir                     CPPU_TYPE_REF( lang::XTypeProvider ),
744cdf0e10cSrcweir                     CPPU_TYPE_REF( lang::XServiceInfo ),
745cdf0e10cSrcweir                     CPPU_TYPE_REF( lang::XComponent ),
746cdf0e10cSrcweir                     CPPU_TYPE_REF( lang::XSingleServiceFactory ),
747cdf0e10cSrcweir                     CPPU_TYPE_REF( container::XHierarchicalNameAccess ),
748cdf0e10cSrcweir                     CPPU_TYPE_REF( container::XNameContainer ),
749cdf0e10cSrcweir                     CPPU_TYPE_REF( util::XChangesBatch ),
750cdf0e10cSrcweir                     CPPU_TYPE_REF( util::XChangesNotifier ) );
751cdf0e10cSrcweir                 pCollection = &aCollection;
752cdf0e10cSrcweir                 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
753cdf0e10cSrcweir                 pReadWriteTypes = pCollection;
754cdf0e10cSrcweir             }
755cdf0e10cSrcweir         }
756cdf0e10cSrcweir         else {
757cdf0e10cSrcweir             OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
758cdf0e10cSrcweir         }
759cdf0e10cSrcweir     }
760cdf0e10cSrcweir 
761cdf0e10cSrcweir     return (*pCollection).getTypes();
762cdf0e10cSrcweir }
763cdf0e10cSrcweir 
764cdf0e10cSrcweir //=========================================================================
765cdf0e10cSrcweir //
766cdf0e10cSrcweir // XServiceInfo methods.
767cdf0e10cSrcweir //
768cdf0e10cSrcweir //=========================================================================
769cdf0e10cSrcweir 
770cdf0e10cSrcweir XSERVICEINFO_NOFACTORY_IMPL_0(
771cdf0e10cSrcweir         HierarchyDataAccess,
772cdf0e10cSrcweir         rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
773cdf0e10cSrcweir                             "com.sun.star.comp.ucb.HierarchyDataAccess" ) ) )
774cdf0e10cSrcweir {
775cdf0e10cSrcweir     uno::Sequence< rtl::OUString > aSNS( 2 );
776cdf0e10cSrcweir     aSNS[ 0 ] = rtl::OUString(
777cdf0e10cSrcweir                         RTL_CONSTASCII_USTRINGPARAM( READ_SERVICE_NAME ) );
778cdf0e10cSrcweir     aSNS[ 1 ] = rtl::OUString(
779cdf0e10cSrcweir                         RTL_CONSTASCII_USTRINGPARAM( READWRITE_SERVICE_NAME ) );
780cdf0e10cSrcweir     return aSNS;
781cdf0e10cSrcweir }
782cdf0e10cSrcweir 
783cdf0e10cSrcweir //=========================================================================
784cdf0e10cSrcweir //
785cdf0e10cSrcweir // XComponent methods.
786cdf0e10cSrcweir //
787cdf0e10cSrcweir //=========================================================================
788cdf0e10cSrcweir 
789cdf0e10cSrcweir // virtual
790cdf0e10cSrcweir void SAL_CALL HierarchyDataAccess::dispose()
791cdf0e10cSrcweir     throw ( uno::RuntimeException )
792cdf0e10cSrcweir {
793cdf0e10cSrcweir     uno::Reference< lang::XComponent > xOrig
794cdf0e10cSrcweir         = ENSURE_ORIG_INTERFACE( lang::XComponent, C );
795cdf0e10cSrcweir 
796cdf0e10cSrcweir     OSL_ENSURE( xOrig.is(),
797cdf0e10cSrcweir                 "HierarchyDataAccess : Data source is not an XComponent!" );
798cdf0e10cSrcweir     xOrig->dispose();
799cdf0e10cSrcweir }
800cdf0e10cSrcweir 
801cdf0e10cSrcweir //=========================================================================
802cdf0e10cSrcweir // virtual
803cdf0e10cSrcweir void SAL_CALL HierarchyDataAccess::addEventListener(
804cdf0e10cSrcweir                     const uno::Reference< lang::XEventListener > & xListener )
805cdf0e10cSrcweir     throw ( uno::RuntimeException )
806cdf0e10cSrcweir {
807cdf0e10cSrcweir     uno::Reference< lang::XComponent > xOrig
808cdf0e10cSrcweir         = ENSURE_ORIG_INTERFACE( lang::XComponent, C );
809cdf0e10cSrcweir 
810cdf0e10cSrcweir     OSL_ENSURE( xOrig.is(),
811cdf0e10cSrcweir                 "HierarchyDataAccess : Data source is not an XComponent!" );
812cdf0e10cSrcweir     xOrig->addEventListener( xListener );
813cdf0e10cSrcweir }
814cdf0e10cSrcweir 
815cdf0e10cSrcweir //=========================================================================
816cdf0e10cSrcweir // virtual
817cdf0e10cSrcweir void SAL_CALL HierarchyDataAccess::removeEventListener(
818cdf0e10cSrcweir                     const uno::Reference< lang::XEventListener > & aListener )
819cdf0e10cSrcweir     throw ( uno::RuntimeException )
820cdf0e10cSrcweir {
821cdf0e10cSrcweir     uno::Reference< lang::XComponent > xOrig
822cdf0e10cSrcweir         = ENSURE_ORIG_INTERFACE( lang::XComponent, C );
823cdf0e10cSrcweir 
824cdf0e10cSrcweir     OSL_ENSURE( xOrig.is(),
825cdf0e10cSrcweir                 "HierarchyDataAccess : Data source is not an XComponent!" );
826cdf0e10cSrcweir     xOrig->removeEventListener( aListener );
827cdf0e10cSrcweir }
828cdf0e10cSrcweir 
829cdf0e10cSrcweir //=========================================================================
830cdf0e10cSrcweir //
831cdf0e10cSrcweir // XHierarchicalNameAccess methods.
832cdf0e10cSrcweir //
833cdf0e10cSrcweir //=========================================================================
834cdf0e10cSrcweir 
835cdf0e10cSrcweir // virtual
836cdf0e10cSrcweir uno::Any SAL_CALL HierarchyDataAccess::getByHierarchicalName(
837cdf0e10cSrcweir                                                 const rtl::OUString & aName )
838cdf0e10cSrcweir     throw ( container::NoSuchElementException, uno::RuntimeException )
839cdf0e10cSrcweir {
840cdf0e10cSrcweir     uno::Reference< container::XHierarchicalNameAccess > xOrig
841cdf0e10cSrcweir         = ENSURE_ORIG_INTERFACE( container::XHierarchicalNameAccess, HNA );
842cdf0e10cSrcweir 
843cdf0e10cSrcweir     OSL_ENSURE( xOrig.is(),
844cdf0e10cSrcweir                 "HierarchyDataAccess : "
845cdf0e10cSrcweir                 "Data source is not an XHierarchicalNameAccess!" );
846cdf0e10cSrcweir     return xOrig->getByHierarchicalName( aName );
847cdf0e10cSrcweir }
848cdf0e10cSrcweir 
849cdf0e10cSrcweir //=========================================================================
850cdf0e10cSrcweir // virtual
851cdf0e10cSrcweir sal_Bool SAL_CALL HierarchyDataAccess::hasByHierarchicalName(
852cdf0e10cSrcweir                                                 const rtl::OUString & aName )
853cdf0e10cSrcweir     throw ( uno::RuntimeException )
854cdf0e10cSrcweir {
855cdf0e10cSrcweir     uno::Reference< container::XHierarchicalNameAccess > xOrig
856cdf0e10cSrcweir         = ENSURE_ORIG_INTERFACE( container::XHierarchicalNameAccess, HNA );
857cdf0e10cSrcweir 
858cdf0e10cSrcweir     OSL_ENSURE( xOrig.is(),
859cdf0e10cSrcweir                 "HierarchyDataAccess : "
860cdf0e10cSrcweir                 "Data source is not an XHierarchicalNameAccess!" );
861cdf0e10cSrcweir     return xOrig->hasByHierarchicalName( aName );
862cdf0e10cSrcweir }
863cdf0e10cSrcweir 
864cdf0e10cSrcweir //=========================================================================
865cdf0e10cSrcweir //
866cdf0e10cSrcweir // XNameAccess methods.
867cdf0e10cSrcweir //
868cdf0e10cSrcweir //=========================================================================
869cdf0e10cSrcweir 
870cdf0e10cSrcweir // virtual
871cdf0e10cSrcweir uno::Any SAL_CALL HierarchyDataAccess::getByName( const rtl::OUString & aName )
872cdf0e10cSrcweir     throw ( container::NoSuchElementException,
873cdf0e10cSrcweir             lang::WrappedTargetException,
874cdf0e10cSrcweir             uno::RuntimeException )
875cdf0e10cSrcweir {
876cdf0e10cSrcweir     uno::Reference< container::XNameAccess > xOrig
877cdf0e10cSrcweir         = ENSURE_ORIG_INTERFACE( container::XNameAccess, NA );
878cdf0e10cSrcweir 
879cdf0e10cSrcweir     OSL_ENSURE( xOrig.is(),
880cdf0e10cSrcweir                 "HierarchyDataAccess : Data source is not an XNameAccess!" );
881cdf0e10cSrcweir     return xOrig->getByName( aName );
882cdf0e10cSrcweir }
883cdf0e10cSrcweir 
884cdf0e10cSrcweir //=========================================================================
885cdf0e10cSrcweir // virtual
886cdf0e10cSrcweir uno::Sequence< rtl::OUString > SAL_CALL HierarchyDataAccess::getElementNames()
887cdf0e10cSrcweir     throw ( uno::RuntimeException )
888cdf0e10cSrcweir {
889cdf0e10cSrcweir     uno::Reference< container::XNameAccess > xOrig
890cdf0e10cSrcweir         = ENSURE_ORIG_INTERFACE( container::XNameAccess, NA );
891cdf0e10cSrcweir 
892cdf0e10cSrcweir     OSL_ENSURE( xOrig.is(),
893cdf0e10cSrcweir                 "HierarchyDataAccess : Data source is not an XNameAccess!" );
894cdf0e10cSrcweir     return xOrig->getElementNames();
895cdf0e10cSrcweir }
896cdf0e10cSrcweir 
897cdf0e10cSrcweir //=========================================================================
898cdf0e10cSrcweir // virtual
899cdf0e10cSrcweir sal_Bool SAL_CALL HierarchyDataAccess::hasByName( const rtl::OUString & aName )
900cdf0e10cSrcweir     throw ( uno::RuntimeException )
901cdf0e10cSrcweir {
902cdf0e10cSrcweir     uno::Reference< container::XNameAccess > xOrig
903cdf0e10cSrcweir         = ENSURE_ORIG_INTERFACE( container::XNameAccess, NA );
904cdf0e10cSrcweir 
905cdf0e10cSrcweir     OSL_ENSURE( xOrig.is(),
906cdf0e10cSrcweir                 "HierarchyDataAccess : Data source is not an XNameAccess!" );
907cdf0e10cSrcweir     return xOrig->hasByName( aName );
908cdf0e10cSrcweir }
909cdf0e10cSrcweir 
910cdf0e10cSrcweir //=========================================================================
911cdf0e10cSrcweir //
912cdf0e10cSrcweir // XElementAccess methods.
913cdf0e10cSrcweir //
914cdf0e10cSrcweir //=========================================================================
915cdf0e10cSrcweir 
916cdf0e10cSrcweir // virtual
917cdf0e10cSrcweir uno::Type SAL_CALL HierarchyDataAccess::getElementType()
918cdf0e10cSrcweir     throw ( uno::RuntimeException )
919cdf0e10cSrcweir {
920cdf0e10cSrcweir     uno::Reference< container::XElementAccess > xOrig
921cdf0e10cSrcweir         = ENSURE_ORIG_INTERFACE( container::XElementAccess, EA );
922cdf0e10cSrcweir 
923cdf0e10cSrcweir     OSL_ENSURE( xOrig.is(),
924cdf0e10cSrcweir                 "HierarchyDataAccess : Data source is not an XElementAccess!" );
925cdf0e10cSrcweir     return xOrig->getElementType();
926cdf0e10cSrcweir }
927cdf0e10cSrcweir 
928cdf0e10cSrcweir //=========================================================================
929cdf0e10cSrcweir // virtual
930cdf0e10cSrcweir sal_Bool SAL_CALL HierarchyDataAccess::hasElements()
931cdf0e10cSrcweir     throw ( uno::RuntimeException )
932cdf0e10cSrcweir {
933cdf0e10cSrcweir     uno::Reference< container::XElementAccess > xOrig
934cdf0e10cSrcweir         = ENSURE_ORIG_INTERFACE( container::XElementAccess, EA );
935cdf0e10cSrcweir 
936cdf0e10cSrcweir     OSL_ENSURE( xOrig.is(),
937cdf0e10cSrcweir                 "HierarchyDataAccess : Data source is not an XElementAccess!" );
938cdf0e10cSrcweir     return xOrig->hasElements();
939cdf0e10cSrcweir }
940cdf0e10cSrcweir 
941cdf0e10cSrcweir //=========================================================================
942cdf0e10cSrcweir //
943cdf0e10cSrcweir // XChangesNotifier methods.
944cdf0e10cSrcweir //
945cdf0e10cSrcweir //=========================================================================
946cdf0e10cSrcweir 
947cdf0e10cSrcweir // virtual
948cdf0e10cSrcweir void SAL_CALL HierarchyDataAccess::addChangesListener(
949cdf0e10cSrcweir                 const uno::Reference< util::XChangesListener > & aListener )
950cdf0e10cSrcweir     throw ( uno::RuntimeException )
951cdf0e10cSrcweir {
952cdf0e10cSrcweir     uno::Reference< util::XChangesNotifier > xOrig
953cdf0e10cSrcweir         = ENSURE_ORIG_INTERFACE( util::XChangesNotifier, CN );
954cdf0e10cSrcweir 
955cdf0e10cSrcweir     OSL_ENSURE( xOrig.is(),
956cdf0e10cSrcweir             "HierarchyDataAccess : Data source is not an XChangesNotifier!" );
957cdf0e10cSrcweir     xOrig->addChangesListener( aListener );
958cdf0e10cSrcweir }
959cdf0e10cSrcweir 
960cdf0e10cSrcweir //=========================================================================
961cdf0e10cSrcweir // virtual
962cdf0e10cSrcweir void SAL_CALL HierarchyDataAccess::removeChangesListener(
963cdf0e10cSrcweir                 const uno::Reference< util::XChangesListener > & aListener )
964cdf0e10cSrcweir     throw ( uno::RuntimeException )
965cdf0e10cSrcweir {
966cdf0e10cSrcweir     uno::Reference< util::XChangesNotifier > xOrig
967cdf0e10cSrcweir         = ENSURE_ORIG_INTERFACE( util::XChangesNotifier, CN );
968cdf0e10cSrcweir 
969cdf0e10cSrcweir     OSL_ENSURE( xOrig.is(),
970cdf0e10cSrcweir             "HierarchyDataAccess : Data source is not an XChangesNotifier!" );
971cdf0e10cSrcweir     xOrig->removeChangesListener( aListener );
972cdf0e10cSrcweir }
973cdf0e10cSrcweir 
974cdf0e10cSrcweir //=========================================================================
975cdf0e10cSrcweir //
976cdf0e10cSrcweir // XSingleServiceFactory methods.
977cdf0e10cSrcweir //
978cdf0e10cSrcweir //=========================================================================
979cdf0e10cSrcweir 
980cdf0e10cSrcweir // virtual
981cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL HierarchyDataAccess::createInstance()
982cdf0e10cSrcweir     throw ( uno::Exception, uno::RuntimeException )
983cdf0e10cSrcweir {
984cdf0e10cSrcweir     uno::Reference< lang::XSingleServiceFactory > xOrig
985cdf0e10cSrcweir         = ENSURE_ORIG_INTERFACE( lang::XSingleServiceFactory, SSF );
986cdf0e10cSrcweir 
987cdf0e10cSrcweir     OSL_ENSURE( xOrig.is(),
988cdf0e10cSrcweir         "HierarchyDataAccess : Data source is not an XSingleServiceFactory!" );
989cdf0e10cSrcweir     return xOrig->createInstance();
990cdf0e10cSrcweir }
991cdf0e10cSrcweir 
992cdf0e10cSrcweir //=========================================================================
993cdf0e10cSrcweir // virtual
994cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL
995cdf0e10cSrcweir HierarchyDataAccess::createInstanceWithArguments(
996cdf0e10cSrcweir                             const uno::Sequence< uno::Any > & aArguments )
997cdf0e10cSrcweir     throw ( uno::Exception, uno::RuntimeException )
998cdf0e10cSrcweir {
999cdf0e10cSrcweir     uno::Reference< lang::XSingleServiceFactory > xOrig
1000cdf0e10cSrcweir         = ENSURE_ORIG_INTERFACE( lang::XSingleServiceFactory, SSF );
1001cdf0e10cSrcweir 
1002cdf0e10cSrcweir     OSL_ENSURE( xOrig.is(),
1003cdf0e10cSrcweir         "HierarchyDataAccess : Data source is not an XSingleServiceFactory!" );
1004cdf0e10cSrcweir     return xOrig->createInstanceWithArguments( aArguments );
1005cdf0e10cSrcweir }
1006cdf0e10cSrcweir 
1007cdf0e10cSrcweir //=========================================================================
1008cdf0e10cSrcweir //
1009cdf0e10cSrcweir // XNameContainer methods.
1010cdf0e10cSrcweir //
1011cdf0e10cSrcweir //=========================================================================
1012cdf0e10cSrcweir 
1013cdf0e10cSrcweir // virtual
1014cdf0e10cSrcweir void SAL_CALL
1015cdf0e10cSrcweir HierarchyDataAccess::insertByName( const rtl::OUString & aName,
1016cdf0e10cSrcweir                                    const uno::Any & aElement )
1017cdf0e10cSrcweir     throw ( lang::IllegalArgumentException,
1018cdf0e10cSrcweir             container::ElementExistException,
1019cdf0e10cSrcweir             lang::WrappedTargetException,
1020cdf0e10cSrcweir             uno::RuntimeException )
1021cdf0e10cSrcweir {
1022cdf0e10cSrcweir     uno::Reference< container::XNameContainer > xOrig
1023cdf0e10cSrcweir         = ENSURE_ORIG_INTERFACE( container::XNameContainer, NC );
1024cdf0e10cSrcweir 
1025cdf0e10cSrcweir     OSL_ENSURE( xOrig.is(),
1026cdf0e10cSrcweir         "HierarchyDataAccess : Data source is not an XNameContainer!" );
1027cdf0e10cSrcweir     xOrig->insertByName( aName, aElement );
1028cdf0e10cSrcweir }
1029cdf0e10cSrcweir 
1030cdf0e10cSrcweir //=========================================================================
1031cdf0e10cSrcweir // virtual
1032cdf0e10cSrcweir void SAL_CALL
1033cdf0e10cSrcweir HierarchyDataAccess::removeByName( const rtl::OUString & Name )
1034cdf0e10cSrcweir     throw ( container::NoSuchElementException,
1035cdf0e10cSrcweir             lang::WrappedTargetException,
1036cdf0e10cSrcweir             uno::RuntimeException )
1037cdf0e10cSrcweir {
1038cdf0e10cSrcweir     uno::Reference< container::XNameContainer > xOrig
1039cdf0e10cSrcweir         = ENSURE_ORIG_INTERFACE( container::XNameContainer, NC );
1040cdf0e10cSrcweir 
1041cdf0e10cSrcweir     OSL_ENSURE( xOrig.is(),
1042cdf0e10cSrcweir         "HierarchyDataAccess : Data source is not an XNameContainer!" );
1043cdf0e10cSrcweir     xOrig->removeByName( Name );
1044cdf0e10cSrcweir }
1045cdf0e10cSrcweir 
1046cdf0e10cSrcweir //=========================================================================
1047cdf0e10cSrcweir //
1048cdf0e10cSrcweir // XNameReplace methods.
1049cdf0e10cSrcweir //
1050cdf0e10cSrcweir //=========================================================================
1051cdf0e10cSrcweir 
1052cdf0e10cSrcweir // virtual
1053cdf0e10cSrcweir void SAL_CALL HierarchyDataAccess::replaceByName( const rtl::OUString & aName,
1054cdf0e10cSrcweir                                                   const uno::Any & aElement )
1055cdf0e10cSrcweir     throw ( lang::IllegalArgumentException,
1056cdf0e10cSrcweir             container::NoSuchElementException,
1057cdf0e10cSrcweir             lang::WrappedTargetException,
1058cdf0e10cSrcweir             uno::RuntimeException )
1059cdf0e10cSrcweir {
1060cdf0e10cSrcweir     uno::Reference< container::XNameReplace > xOrig
1061cdf0e10cSrcweir         = ENSURE_ORIG_INTERFACE( container::XNameReplace, NR );
1062cdf0e10cSrcweir 
1063cdf0e10cSrcweir     OSL_ENSURE( xOrig.is(),
1064cdf0e10cSrcweir         "HierarchyDataAccess : Data source is not an XNameReplace!" );
1065cdf0e10cSrcweir     xOrig->replaceByName( aName, aElement );
1066cdf0e10cSrcweir }
1067cdf0e10cSrcweir 
1068cdf0e10cSrcweir //=========================================================================
1069cdf0e10cSrcweir //
1070cdf0e10cSrcweir // XChangesBatch methods.
1071cdf0e10cSrcweir //
1072cdf0e10cSrcweir //=========================================================================
1073cdf0e10cSrcweir 
1074cdf0e10cSrcweir // virtual
1075cdf0e10cSrcweir void SAL_CALL HierarchyDataAccess::commitChanges()
1076cdf0e10cSrcweir     throw ( lang::WrappedTargetException, uno::RuntimeException )
1077cdf0e10cSrcweir {
1078cdf0e10cSrcweir     uno::Reference< util::XChangesBatch > xOrig
1079cdf0e10cSrcweir         = ENSURE_ORIG_INTERFACE( util::XChangesBatch, CB );
1080cdf0e10cSrcweir 
1081cdf0e10cSrcweir     OSL_ENSURE( xOrig.is(),
1082cdf0e10cSrcweir         "HierarchyDataAccess : Data source is not an XChangesBatch!" );
1083cdf0e10cSrcweir     xOrig->commitChanges();
1084cdf0e10cSrcweir }
1085cdf0e10cSrcweir 
1086cdf0e10cSrcweir //=========================================================================
1087cdf0e10cSrcweir // virtual
1088cdf0e10cSrcweir sal_Bool SAL_CALL HierarchyDataAccess::hasPendingChanges()
1089cdf0e10cSrcweir     throw ( uno::RuntimeException )
1090cdf0e10cSrcweir {
1091cdf0e10cSrcweir     uno::Reference< util::XChangesBatch > xOrig
1092cdf0e10cSrcweir         = ENSURE_ORIG_INTERFACE( util::XChangesBatch, CB );
1093cdf0e10cSrcweir 
1094cdf0e10cSrcweir     OSL_ENSURE( xOrig.is(),
1095cdf0e10cSrcweir         "HierarchyDataAccess : Data source is not an XChangesBatch!" );
1096cdf0e10cSrcweir     return xOrig->hasPendingChanges();
1097cdf0e10cSrcweir }
1098cdf0e10cSrcweir 
1099cdf0e10cSrcweir //=========================================================================
1100cdf0e10cSrcweir // virtual
1101cdf0e10cSrcweir uno::Sequence< util::ElementChange > SAL_CALL
1102cdf0e10cSrcweir HierarchyDataAccess::getPendingChanges()
1103cdf0e10cSrcweir     throw ( uno::RuntimeException )
1104cdf0e10cSrcweir {
1105cdf0e10cSrcweir     uno::Reference< util::XChangesBatch > xOrig
1106cdf0e10cSrcweir         = ENSURE_ORIG_INTERFACE( util::XChangesBatch, CB );
1107cdf0e10cSrcweir 
1108cdf0e10cSrcweir     OSL_ENSURE( xOrig.is(),
1109cdf0e10cSrcweir         "HierarchyDataAccess : Data source is not an XChangesBatch!" );
1110cdf0e10cSrcweir     return xOrig->getPendingChanges();
1111cdf0e10cSrcweir }
1112cdf0e10cSrcweir 
1113