LibreOffice Module ucb (master)  1
ucbstore.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #pragma once
21 
22 #include <com/sun/star/lang/XServiceInfo.hpp>
23 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
24 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
25 #include <com/sun/star/container/XNamed.hpp>
26 #include <com/sun/star/container/XNameAccess.hpp>
27 #include <com/sun/star/ucb/XPropertySetRegistryFactory.hpp>
28 #include <com/sun/star/ucb/XPropertySetRegistry.hpp>
29 #include <com/sun/star/ucb/XPersistentPropertySet.hpp>
30 #include <com/sun/star/uno/XComponentContext.hpp>
31 #include <com/sun/star/beans/XPropertyContainer.hpp>
32 #include <com/sun/star/beans/XPropertySetInfoChangeNotifier.hpp>
33 #include <com/sun/star/beans/XPropertyAccess.hpp>
34 #include <com/sun/star/lang/XComponent.hpp>
35 #include <com/sun/star/lang/XInitialization.hpp>
37 #include <cppuhelper/compbase.hxx>
38 #include <cppuhelper/basemutex.hxx>
39 #include <unordered_map>
40 
41 
42 using UcbStore_Base = cppu::WeakComponentImplHelper <
43  css::lang::XServiceInfo,
44  css::ucb::XPropertySetRegistryFactory,
45  css::lang::XInitialization >;
46 
47 class UcbStore : public cppu::BaseMutex, public UcbStore_Base
48 {
49  css::uno::Reference< css::uno::XComponentContext > m_xContext;
50  css::uno::Sequence< css::uno::Any > m_aInitArgs;
51  css::uno::Reference< css::ucb::XPropertySetRegistry > m_xTheRegistry;
52 
53 public:
54  explicit UcbStore( const css::uno::Reference< css::uno::XComponentContext >& xContext );
55  virtual ~UcbStore() override;
56 
57  // XServiceInfo
58  virtual OUString SAL_CALL getImplementationName() override;
59  virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
60  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
61 
62  // XPropertySetRegistryFactory
63  virtual css::uno::Reference< css::ucb::XPropertySetRegistry > SAL_CALL
64  createPropertySetRegistry( const OUString& URL ) override;
65 
66  // XInitialization
67  virtual void SAL_CALL
68  initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
69 };
70 
71 
73 
74 // PropertySetMap_Impl.
75 typedef std::unordered_map< OUString, PersistentPropertySet*> PropertySetMap_Impl;
76 
77 class PropertySetRegistry : public cppu::WeakImplHelper <
78  css::lang::XServiceInfo,
79  css::ucb::XPropertySetRegistry,
80  css::container::XNameAccess >
81 {
82  friend class PersistentPropertySet;
83 
84  css::uno::Reference< css::uno::XComponentContext > m_xContext;
85  const css::uno::Sequence< css::uno::Any > m_aInitArgs;
87  css::uno::Reference< css::lang::XMultiServiceFactory > m_xConfigProvider;
88  css::uno::Reference< css::uno::XInterface > m_xRootReadAccess;
89  css::uno::Reference< css::uno::XInterface > m_xRootWriteAccess;
90  osl::Mutex m_aMutex;
93 
94 private:
95  css::uno::Reference< css::lang::XMultiServiceFactory >
97 
98  void add ( PersistentPropertySet* pSet );
99  void remove( PersistentPropertySet* pSet );
100 
101  void renamePropertySet( const OUString& rOldKey,
102  const OUString& rNewKey );
103 
104 public:
106  const css::uno::Reference< css::uno::XComponentContext >& xContext,
107  const css::uno::Sequence< css::uno::Any >& rInitArgs);
108  virtual ~PropertySetRegistry() override;
109 
110 
111  // XServiceInfo
112  virtual OUString SAL_CALL getImplementationName() override;
113  virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
114  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
115 
116  // XPropertySetRegistry
117  virtual css::uno::Reference< css::ucb::XPersistentPropertySet > SAL_CALL
118  openPropertySet( const OUString& key, sal_Bool create ) override;
119  virtual void SAL_CALL
120  removePropertySet( const OUString& key ) override;
121 
122  // XElementAccess ( XNameAccess is derived from it )
123  virtual css::uno::Type SAL_CALL
124  getElementType() override;
125  virtual sal_Bool SAL_CALL
126  hasElements() override;
127 
128  // XNameAccess
129  virtual css::uno::Any SAL_CALL
130  getByName( const OUString& aName ) override;
131  virtual css::uno::Sequence< OUString > SAL_CALL
132  getElementNames() override;
133  virtual sal_Bool SAL_CALL
134  hasByName( const OUString& aName ) override;
135 
136  // Non-interface methods
137  css::uno::Reference< css::uno::XInterface >
139  css::uno::Reference< css::uno::XInterface >
140  getConfigWriteAccess( const OUString& rPath );
141 };
142 
143 
146 
147 class PersistentPropertySet : public cppu::WeakImplHelper <
148  css::lang::XServiceInfo,
149  css::lang::XComponent,
150  css::ucb::XPersistentPropertySet,
151  css::container::XNamed,
152  css::beans::XPropertyContainer,
153  css::beans::XPropertySetInfoChangeNotifier,
154  css::beans::XPropertyAccess >
155 {
158  OUString m_aKey;
159  OUString m_aFullKey;
160  osl::Mutex m_aMutex;
161  std::unique_ptr<comphelper::OInterfaceContainerHelper2> m_pDisposeEventListeners;
162  std::unique_ptr<comphelper::OInterfaceContainerHelper2> m_pPropSetChangeListeners;
163  std::unique_ptr<PropertyListeners_Impl> m_pPropertyChangeListeners;
164 
165 private:
167  const css::beans::PropertyChangeEvent& rEvent ) const;
169  const css::beans::PropertySetInfoChangeEvent& evt ) const;
170 
171 public:
173  PropertySetRegistry& rCreator,
174  const OUString& rKey );
175  virtual ~PersistentPropertySet() override;
176 
177  // XServiceInfo
178  virtual OUString SAL_CALL getImplementationName() override;
179  virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
180  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
181 
182  // XComponent
183  virtual void SAL_CALL
184  dispose() override;
185  virtual void SAL_CALL
186  addEventListener( const css::uno::Reference< css::lang::XEventListener >& Listener ) override;
187  virtual void SAL_CALL
188  removeEventListener( const css::uno::Reference< css::lang::XEventListener >& Listener ) override;
189 
190  // XPropertySet
191  virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL
192  getPropertySetInfo() override;
193  virtual void SAL_CALL
194  setPropertyValue( const OUString& aPropertyName,
195  const css::uno::Any& aValue ) override;
196  virtual css::uno::Any SAL_CALL
197  getPropertyValue( const OUString& PropertyName ) override;
198  virtual void SAL_CALL
199  addPropertyChangeListener( const OUString& aPropertyName,
200  const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) override;
201  virtual void SAL_CALL
202  removePropertyChangeListener( const OUString& aPropertyName,
203  const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override;
204  virtual void SAL_CALL
205  addVetoableChangeListener( const OUString& PropertyName,
206  const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
207  virtual void SAL_CALL
208  removeVetoableChangeListener( const OUString& PropertyName,
209  const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
210 
211  // XPersistentPropertySet
212  virtual css::uno::Reference< css::ucb::XPropertySetRegistry > SAL_CALL
213  getRegistry() override;
214  virtual OUString SAL_CALL
215  getKey() override;
216 
217  // XNamed
218  virtual OUString SAL_CALL
219  getName() override;
220  virtual void SAL_CALL
221  setName( const OUString& aName ) override;
222 
223  // XPropertyContainer
224  virtual void SAL_CALL
225  addProperty( const OUString& Name,
226  sal_Int16 Attributes,
227  const css::uno::Any& DefaultValue ) override;
228  virtual void SAL_CALL
229  removeProperty( const OUString& Name ) override;
230 
231  // XPropertySetInfoChangeNotifier
232  virtual void SAL_CALL
233  addPropertySetInfoChangeListener( const css::uno::Reference< css::beans::XPropertySetInfoChangeListener >& Listener ) override;
234  virtual void SAL_CALL
235  removePropertySetInfoChangeListener( const css::uno::Reference< css::beans::XPropertySetInfoChangeListener >& Listener ) override;
236 
237  // XPropertyAccess
238  virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL
239  getPropertyValues() override;
240  virtual void SAL_CALL
241  setPropertyValues( const css::uno::Sequence< css::beans::PropertyValue >& aProps ) override;
242 
243  // Non-interface methods.
245  const OUString& getFullKey();
246 };
247 
248 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual OUString SAL_CALL getImplementationName() override
Definition: ucbstore.cxx:142
css::uno::Reference< css::uno::XInterface > m_xRootWriteAccess
Definition: ucbstore.hxx:89
virtual OUString SAL_CALL getName() override
Definition: ucbstore.cxx:1315
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
Definition: ucbstore.cxx:477
rtl::Reference< PropertySetInfo_Impl > m_pInfo
Definition: ucbstore.hxx:157
virtual void SAL_CALL addVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
Definition: ucbstore.cxx:1275
PropertySetRegistry(const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Sequence< css::uno::Any > &rInitArgs)
Definition: ucbstore.cxx:201
virtual css::uno::Reference< css::ucb::XPropertySetRegistry > SAL_CALL getRegistry() override
Definition: ucbstore.cxx:1298
virtual css::uno::Type SAL_CALL getElementType() override
Definition: ucbstore.cxx:425
css::uno::Reference< css::ucb::XPropertySetRegistry > m_xTheRegistry
Definition: ucbstore.hxx:51
PersistentPropertySet(PropertySetRegistry &rCreator, const OUString &rKey)
Definition: ucbstore.cxx:1017
virtual ~PropertySetRegistry() override
Definition: ucbstore.cxx:213
virtual OUString SAL_CALL getImplementationName() override
Definition: ucbstore.cxx:1036
std::unique_ptr< comphelper::OInterfaceContainerHelper2 > m_pPropSetChangeListeners
Definition: ucbstore.hxx:162
bool m_bTriedToGetRootWriteAccess
Definition: ucbstore.hxx:92
void renamePropertySet(const OUString &rOldKey, const OUString &rNewKey)
Definition: ucbstore.cxx:539
virtual void SAL_CALL removePropertySet(const OUString &key) override
Definition: ucbstore.cxx:366
virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getPropertyValues() override
Definition: ucbstore.cxx:1658
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
Definition: ucbstore.cxx:1123
virtual ~PersistentPropertySet() override
Definition: ucbstore.cxx:1028
virtual OUString SAL_CALL getImplementationName() override
Definition: ucbstore.cxx:221
css::uno::Reference< css::uno::XComponentContext > m_xContext
Definition: ucbstore.hxx:49
css::uno::Reference< css::uno::XInterface > getConfigWriteAccess(const OUString &rPath)
Definition: ucbstore.cxx:931
UcbStore(const css::uno::Reference< css::uno::XComponentContext > &xContext)
Definition: ucbstore.cxx:130
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: ucbstore.cxx:1046
virtual ~UcbStore() override
Definition: ucbstore.cxx:138
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: ucbstore.cxx:1041
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
Definition: ucbstore.cxx:190
virtual sal_Bool SAL_CALL hasElements() override
Definition: ucbstore.cxx:432
const css::uno::Sequence< css::uno::Any > m_aInitArgs
Definition: ucbstore.hxx:85
virtual void SAL_CALL removePropertySetInfoChangeListener(const css::uno::Reference< css::beans::XPropertySetInfoChangeListener > &Listener) override
Definition: ucbstore.cxx:1646
rtl::Reference< PropertySetRegistry > m_pCreator
Definition: ucbstore.hxx:156
PropertySetMap_Impl m_aPropSets
Definition: ucbstore.hxx:86
virtual void SAL_CALL addPropertySetInfoChangeListener(const css::uno::Reference< css::beans::XPropertySetInfoChangeListener > &Listener) override
Definition: ucbstore.cxx:1634
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: ucbstore.cxx:231
void add(PersistentPropertySet *pSet)
Definition: ucbstore.cxx:507
void notifyPropertySetInfoChange(const css::beans::PropertySetInfoChangeEvent &evt) const
Definition: ucbstore.cxx:1938
const OUString & getFullKey()
Definition: ucbstore.cxx:1957
unsigned char sal_Bool
virtual css::uno::Any SAL_CALL getByName(const OUString &aName) override
Definition: ucbstore.cxx:449
std::unique_ptr< comphelper::OInterfaceContainerHelper2 > m_pDisposeEventListeners
Definition: ucbstore.hxx:161
virtual void SAL_CALL removeVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
Definition: ucbstore.cxx:1285
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: ucbstore.cxx:226
css::uno::Reference< css::uno::XInterface > getRootConfigReadAccess()
Definition: ucbstore.cxx:876
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &Listener) override
Definition: ucbstore.cxx:1084
virtual void SAL_CALL dispose() override
Definition: ucbstore.cxx:1056
bool m_bTriedToGetRootReadAccess
Definition: ucbstore.hxx:91
css::uno::Reference< css::lang::XMultiServiceFactory > m_xConfigProvider
Definition: ucbstore.hxx:87
css::uno::Reference< css::lang::XMultiServiceFactory > getConfigProvider()
Definition: ucbstore.cxx:840
virtual void SAL_CALL setName(const OUString &aName) override
Definition: ucbstore.cxx:1323
osl::Mutex m_aMutex
Definition: ucbstore.hxx:90
virtual sal_Bool SAL_CALL hasByName(const OUString &aName) override
Definition: ucbstore.cxx:492
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: ucbstore.cxx:146
void notifyPropertyChangeEvent(const css::beans::PropertyChangeEvent &rEvent) const
Definition: ucbstore.cxx:1900
virtual void SAL_CALL removePropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) override
Definition: ucbstore.cxx:1260
virtual css::uno::Reference< css::ucb::XPersistentPropertySet > SAL_CALL openPropertySet(const OUString &key, sal_Bool create) override
Definition: ucbstore.cxx:242
std::unique_ptr< PropertyListeners_Impl > m_pPropertyChangeListeners
Definition: ucbstore.hxx:163
cppu::OMultiTypeInterfaceContainerHelperVar< OUString > PropertyListeners_Impl
Definition: ucbstore.hxx:144
virtual void SAL_CALL setPropertyValues(const css::uno::Sequence< css::beans::PropertyValue > &aProps) override
Definition: ucbstore.cxx:1786
virtual void SAL_CALL removeProperty(const OUString &Name) override
Definition: ucbstore.cxx:1493
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: ucbstore.cxx:150
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: ucbstore.cxx:1110
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
Definition: ucbstore.cxx:1218
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &Listener) override
Definition: ucbstore.cxx:1096
virtual OUString SAL_CALL getKey() override
Definition: ucbstore.cxx:1305
css::uno::Reference< css::uno::XComponentContext > m_xContext
Definition: ucbstore.hxx:84
virtual void SAL_CALL addPropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
Definition: ucbstore.cxx:1244
css::uno::Sequence< css::uno::Any > m_aInitArgs
Definition: ucbstore.hxx:50
std::unordered_map< OUString, PersistentPropertySet * > PropertySetMap_Impl
Definition: ucbstore.hxx:72
virtual css::uno::Reference< css::ucb::XPropertySetRegistry > SAL_CALL createPropertySetRegistry(const OUString &URL) override
Definition: ucbstore.cxx:170
css::uno::Reference< css::uno::XInterface > m_xRootReadAccess
Definition: ucbstore.hxx:88
cppu::WeakComponentImplHelper< css::lang::XServiceInfo, css::ucb::XPropertySetRegistryFactory, css::lang::XInitialization > UcbStore_Base
Definition: ucbstore.hxx:45
PropertySetRegistry & getPropertySetRegistry()
Definition: ucbstore.cxx:1973
virtual void SAL_CALL addProperty(const OUString &Name, sal_Int16 Attributes, const css::uno::Any &DefaultValue) override
Definition: ucbstore.cxx:1334