nss: upgrade to release 3.73
[LibreOffice.git] / dbaccess / source / core / inc / definitioncontainer.hxx
blobbcb6bd364470d3361a91393d6bcd17f6f713c13d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #pragma once
22 #include <sal/config.h>
24 #include <map>
25 #include <vector>
27 #include <cppuhelper/implbase7.hxx>
28 #include <osl/mutex.hxx>
29 #include <com/sun/star/container/XNameContainer.hpp>
30 #include <com/sun/star/container/XContainer.hpp>
31 #include <com/sun/star/container/XEnumerationAccess.hpp>
32 #include <com/sun/star/container/XIndexAccess.hpp>
33 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
34 #include <com/sun/star/beans/XVetoableChangeListener.hpp>
35 #include <com/sun/star/container/XContainerApproveBroadcaster.hpp>
36 #include "ContentHelper.hxx"
37 #include "containerapprove.hxx"
38 #include <comphelper/uno3.hxx>
40 namespace dbaccess
43 class ODefinitionContainer_Impl : public OContentHelper_Impl
45 public:
46 typedef std::map< OUString, TContentPtr > NamedDefinitions;
47 typedef NamedDefinitions::iterator iterator;
48 typedef NamedDefinitions::const_iterator const_iterator;
50 private:
51 NamedDefinitions m_aDefinitions;
53 public:
54 size_t size() const { return m_aDefinitions.size(); }
56 const_iterator begin() const { return m_aDefinitions.begin(); }
57 const_iterator end() const { return m_aDefinitions.end(); }
59 const_iterator find( const OUString& _rName ) const { return m_aDefinitions.find( _rName ); }
60 const_iterator find( const TContentPtr& _pDefinition ) const;
62 void erase( const OUString& _rName ) { m_aDefinitions.erase( _rName ); }
63 void erase( const TContentPtr& _pDefinition );
65 void insert( const OUString& _rName, TContentPtr _pDefinition )
67 m_aDefinitions.emplace( _rName, _pDefinition );
70 private:
71 iterator find( const TContentPtr& _pDefinition );
72 // (for the moment, this is private. Make it public if needed. If really needed.)
75 // ODefinitionContainer - base class of collections of database definition
76 // documents
77 typedef ::cppu::ImplHelper7 < css::container::XIndexAccess
78 , css::container::XNameContainer
79 , css::container::XEnumerationAccess
80 , css::container::XContainer
81 , css::container::XContainerApproveBroadcaster
82 , css::beans::XPropertyChangeListener
83 , css::beans::XVetoableChangeListener
84 > ODefinitionContainer_Base;
86 class ODefinitionContainer
87 :public OContentHelper
88 ,public ODefinitionContainer_Base
90 protected:
91 typedef std::map< OUString, css::uno::WeakReference< css::ucb::XContent > > Documents;
93 enum ContainerOperation
95 E_REPLACED,
96 E_REMOVED,
97 E_INSERTED
100 enum ListenerType
102 ApproveListeners,
103 ContainerListemers
106 private:
107 PContainerApprove m_pElementApproval;
109 protected:
110 // we can't just hold a vector of XContentRefs, as after initialization they're all empty
111 // cause we load them only on access
112 std::vector<Documents::iterator>
113 m_aDocuments; // for an efficient index access
114 Documents m_aDocumentMap; // for an efficient name access
116 ::comphelper::OInterfaceContainerHelper2
117 m_aApproveListeners;
118 ::comphelper::OInterfaceContainerHelper2
119 m_aContainerListeners;
121 bool m_bInPropertyChange;
122 bool m_bCheckSlash;
124 protected:
125 /** Additionally to our own approvals which new elements must pass, derived classes
126 can specify an additional approval instance here.
128 Every time a new element is inserted into the container (or an element is replaced
129 with a new one), this new element must pass our own internal approval, plus the approval
130 given here.
132 void setElementApproval( PContainerApprove _pElementApproval ) { m_pElementApproval = _pElementApproval; }
133 const PContainerApprove& getElementApproval() const { return m_pElementApproval; }
135 protected:
136 virtual ~ODefinitionContainer() override;
138 const ODefinitionContainer_Impl& getDefinitions() const
140 return dynamic_cast< const ODefinitionContainer_Impl& >( *m_pImpl );
143 ODefinitionContainer_Impl& getDefinitions()
145 return dynamic_cast< ODefinitionContainer_Impl& >( *m_pImpl );
147 public:
148 /** constructs the container.
150 ODefinitionContainer(
151 const css::uno::Reference< css::uno::XComponentContext >& _xORB
152 , const css::uno::Reference< css::uno::XInterface >& _xParentContainer
153 , const TContentPtr& _pImpl
154 , bool _bCheckSlash = true
157 // css::uno::XInterface
158 DECLARE_XINTERFACE( )
160 virtual css::uno::Sequence<css::uno::Type> SAL_CALL getTypes() override;
161 virtual css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId() override;
163 // css::lang::XServiceInfo
164 virtual OUString SAL_CALL getImplementationName( ) override;
165 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
167 // css::container::XElementAccess
168 virtual css::uno::Type SAL_CALL getElementType( ) override;
169 virtual sal_Bool SAL_CALL hasElements( ) override;
171 // css::container::XEnumerationAccess
172 virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration( ) override;
174 // css::container::XIndexAccess
175 virtual sal_Int32 SAL_CALL getCount( ) override;
176 virtual css::uno::Any SAL_CALL getByIndex( sal_Int32 _nIndex ) override;
178 // css::container::XNameContainer
179 virtual void SAL_CALL insertByName( const OUString& _rName, const css::uno::Any& aElement ) override;
180 virtual void SAL_CALL removeByName( const OUString& _rName ) override;
182 // css::container::XNameReplace
183 virtual void SAL_CALL replaceByName( const OUString& _rName, const css::uno::Any& aElement ) override;
185 // css::container::XNameAccess
186 virtual css::uno::Any SAL_CALL getByName( const OUString& aName ) override;
187 virtual css::uno::Sequence< OUString > SAL_CALL getElementNames( ) override;
188 virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override;
190 // css::container::XContainer
191 virtual void SAL_CALL addContainerListener( const css::uno::Reference< css::container::XContainerListener >& xListener ) override;
192 virtual void SAL_CALL removeContainerListener( const css::uno::Reference< css::container::XContainerListener >& xListener ) override;
194 // XContainerApproveBroadcaster
195 virtual void SAL_CALL addContainerApproveListener( const css::uno::Reference< css::container::XContainerApproveListener >& Listener ) override;
196 virtual void SAL_CALL removeContainerApproveListener( const css::uno::Reference< css::container::XContainerApproveListener >& Listener ) override;
198 // css::lang::XEventListener
199 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
201 // XPropertyChangeListener
202 virtual void SAL_CALL propertyChange( const css::beans::PropertyChangeEvent& evt ) override;
203 // XVetoableChangeListener
204 virtual void SAL_CALL vetoableChange( const css::beans::PropertyChangeEvent& aEvent ) override;
206 protected:
207 // helper
208 virtual void SAL_CALL disposing() override;
210 /** create an object from its persistent data within the configuration. To be overwritten by derived classes.
211 @param _rName the name the object has within the container
212 @return the newly created object or an empty reference if something went wrong
214 virtual css::uno::Reference< css::ucb::XContent > createObject(
215 const OUString& _rName) = 0;
217 /** get the object specified by the given name. If desired, the object will be read if not already done so.<BR>
218 @param _rName the object name
219 @param _bReadIfNecessary if sal_True, the object will be created if necessary
220 @return the property set interface of the object. Usually the return value is not NULL, but
221 if so, then the object could not be read from the configuration
222 @throws NoSuchElementException if there is no object with the given name.
223 @see createObject
225 css::uno::Reference< css::ucb::XContent >
226 implGetByName(const OUString& _rName, bool _bCreateIfNecessary);
228 /** quickly checks if there already is an element with a given name. No access to the configuration occurs, i.e.
229 if there is such an object which is not already loaded, it won't be loaded now.
230 @param _rName the object name to check
231 @return sal_True if there already exists such an object
233 virtual bool checkExistence(const OUString& _rName);
235 /** append a new object to the container. No plausibility checks are done, e.g. if the object is non-NULL or
236 if the name is already used by another object or anything like this. This method is for derived classes
237 which may support different methods to create and/or append objects, and don't want to deal with the
238 internal structures of this class.<BR>
239 The old component will not be disposed, this is the callers responsibility, too.
240 @param _rName the name of the new object
241 @param _rxNewObject the new object (not surprising, is it ?)
242 @see createConfigKey
243 @see implReplace
244 @see implRemove
246 void implAppend(
247 const OUString& _rName,
248 const css::uno::Reference< css::ucb::XContent >& _rxNewObject
251 /** remove all references to an object from the container. No plausibility checks are done, e.g. whether
252 or not there exists an object with the given name. This is the responsibility of the caller.<BR>
253 Additionally the node for the given object will be removed from the registry (including all sub nodes).<BR>
254 The old component will not be disposed, this is the callers responsibility, too.
255 @param _rName the objects name
256 @see implReplace
257 @see implAppend
259 void implRemove(const OUString& _rName);
261 /** remove an object in the container. No plausibility checks are done, e.g. whether
262 or not there exists an object with the given name or the object is non-NULL. This is the responsibility of the caller.<BR>
263 Additionally all object-related information within the registry will be deleted. The new object config node,
264 where the caller may want to store the new objects information, is returned.<BR>
265 The old component will not be disposed, this is the callers responsibility, too.
266 @param _rName the objects name
267 @param _rxNewObject the new object
268 @param _rNewObjectNode the configuration node where the new object may be stored
269 @see implAppend
270 @see implRemove
272 void implReplace(
273 const OUString& _rName,
274 const css::uno::Reference< css::ucb::XContent >& _rxNewObject
277 /** notifies our container/approve listeners
279 void notifyByName(
280 ::osl::ResettableMutexGuard& _rGuard,
281 const OUString& _rName,
282 const css::uno::Reference< css::ucb::XContent >& _xNewElement,
283 const css::uno::Reference< css::ucb::XContent >& xOldElement,
284 ContainerOperation _eOperation,
285 ListenerType _eType
288 operator css::uno::Reference< css::uno::XInterface > () const
290 return const_cast< XContainer* >( static_cast< const XContainer* >( this ) );
293 private:
294 void addObjectListener(const css::uno::Reference< css::ucb::XContent >& _xNewObject);
295 void removeObjectListener(const css::uno::Reference< css::ucb::XContent >& _xNewObject);
297 /** approve that the object given may be inserted into the container.
298 Should be overridden by derived classes,
299 the default implementation just checks the object to be non-void.
301 @throws IllegalArgumentException
302 if the name or the object are invalid
303 @throws ElementExistException
304 if the object already exists in the container, or another object with the same name
305 already exists
306 @throws WrappedTargetException
307 if another error occurs which prevents insertion of the object into the container
309 void approveNewObject(
310 const OUString& _sName,
311 const css::uno::Reference< css::ucb::XContent >& _rxObject
312 ) const;
314 bool impl_haveAnyListeners_nothrow() const
316 return ( m_aContainerListeners.getLength() > 0 ) || ( m_aApproveListeners.getLength() > 0 );
320 } // namespace dbaccess
322 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */