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