LibreOffice Module dbaccess (master) 1
definitioncontainer.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 <sal/config.h>
23
24#include <map>
25#include <vector>
26
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
41namespace dbaccess
42{
43
45{
46public:
47 typedef std::map< OUString, TContentPtr > NamedDefinitions;
48 typedef NamedDefinitions::iterator iterator;
49 typedef NamedDefinitions::const_iterator const_iterator;
50
51private:
53
54public:
55 size_t size() const { return m_aDefinitions.size(); }
56
57 const_iterator begin() const { return m_aDefinitions.begin(); }
58 const_iterator end() const { return m_aDefinitions.end(); }
59
60 const_iterator find( const OUString& _rName ) const { return m_aDefinitions.find( _rName ); }
61 const_iterator find( const TContentPtr& _pDefinition ) const;
62
63 void erase( const OUString& _rName ) { m_aDefinitions.erase( _rName ); }
64 void erase( const TContentPtr& _pDefinition );
65
66 void insert( const OUString& _rName, TContentPtr _pDefinition )
67 {
68 m_aDefinitions.emplace( _rName, _pDefinition );
69 }
70
71private:
72 iterator find( const TContentPtr& _pDefinition );
73 // (for the moment, this is private. Make it public if needed. If really needed.)
74};
75
76// ODefinitionContainer - base class of collections of database definition
77// documents
78typedef ::cppu::ImplHelper7 < css::container::XIndexAccess
79 , css::container::XNameContainer
80 , css::container::XEnumerationAccess
81 , css::container::XContainer
82 , css::container::XContainerApproveBroadcaster
83 , css::beans::XPropertyChangeListener
84 , css::beans::XVetoableChangeListener
86
88 :public OContentHelper
90{
91protected:
92 typedef std::map< OUString, css::uno::WeakReference< css::ucb::XContent > > Documents;
93
95 {
99 };
100
102 {
105 };
106
107private:
109
110protected:
111 // we can't just hold a vector of XContentRefs, as after initialization they're all empty
112 // cause we load them only on access
113 std::vector<Documents::iterator>
114 m_aDocuments; // for an efficient index access
115 Documents m_aDocumentMap; // for an efficient name access
116
121
124
125protected:
133 void setElementApproval( PContainerApprove _pElementApproval ) { m_pElementApproval = _pElementApproval; }
135
136protected:
137 virtual ~ODefinitionContainer() override;
138
140 {
141 return dynamic_cast< const ODefinitionContainer_Impl& >( *m_pImpl );
142 }
143
145 {
146 return dynamic_cast< ODefinitionContainer_Impl& >( *m_pImpl );
147 }
148public:
152 const css::uno::Reference< css::uno::XComponentContext >& _xORB
153 , const css::uno::Reference< css::uno::XInterface >& _xParentContainer
154 , const TContentPtr& _pImpl
155 , bool _bCheckSlash = true
156 );
157
158// css::uno::XInterface
160
161 virtual css::uno::Sequence<css::uno::Type> SAL_CALL getTypes() override;
162 virtual css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId() override;
163
164// css::lang::XServiceInfo
165 virtual OUString SAL_CALL getImplementationName( ) override;
166 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
167
168// css::container::XElementAccess
169 virtual css::uno::Type SAL_CALL getElementType( ) override;
170 virtual sal_Bool SAL_CALL hasElements( ) override;
171
172// css::container::XEnumerationAccess
173 virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration( ) override;
174
175// css::container::XIndexAccess
176 virtual sal_Int32 SAL_CALL getCount( ) override;
177 virtual css::uno::Any SAL_CALL getByIndex( sal_Int32 _nIndex ) override;
178
179// css::container::XNameContainer
180 virtual void SAL_CALL insertByName( const OUString& _rName, const css::uno::Any& aElement ) override;
181 virtual void SAL_CALL removeByName( const OUString& _rName ) override;
182
183// css::container::XNameReplace
184 virtual void SAL_CALL replaceByName( const OUString& _rName, const css::uno::Any& aElement ) override;
185
186// css::container::XNameAccess
187 virtual css::uno::Any SAL_CALL getByName( const OUString& aName ) override;
188 virtual css::uno::Sequence< OUString > SAL_CALL getElementNames( ) override;
189 virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override;
190
191// css::container::XContainer
192 virtual void SAL_CALL addContainerListener( const css::uno::Reference< css::container::XContainerListener >& xListener ) override;
193 virtual void SAL_CALL removeContainerListener( const css::uno::Reference< css::container::XContainerListener >& xListener ) override;
194
195 // XContainerApproveBroadcaster
196 virtual void SAL_CALL addContainerApproveListener( const css::uno::Reference< css::container::XContainerApproveListener >& Listener ) override;
197 virtual void SAL_CALL removeContainerApproveListener( const css::uno::Reference< css::container::XContainerApproveListener >& Listener ) override;
198
199// css::lang::XEventListener
200 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
201
202 // XPropertyChangeListener
203 virtual void SAL_CALL propertyChange( const css::beans::PropertyChangeEvent& evt ) override;
204 // XVetoableChangeListener
205 virtual void SAL_CALL vetoableChange( const css::beans::PropertyChangeEvent& aEvent ) override;
206
207protected:
208 // helper
209 virtual void SAL_CALL disposing() override;
210
215 virtual css::uno::Reference< css::ucb::XContent > createObject(
216 const OUString& _rName) = 0;
217
226 css::uno::Reference< css::ucb::XContent >
227 implGetByName(const OUString& _rName, bool _bCreateIfNecessary);
228
234 virtual bool checkExistence(const OUString& _rName);
235
247 void implAppend(
248 const OUString& _rName,
249 const css::uno::Reference< css::ucb::XContent >& _rxNewObject
250 );
251
260 void implRemove(const OUString& _rName);
261
273 void implReplace(
274 const OUString& _rName,
275 const css::uno::Reference< css::ucb::XContent >& _rxNewObject
276 );
277
280 void notifyByName(
281 ::osl::ResettableMutexGuard& _rGuard,
282 const OUString& _rName,
283 const css::uno::Reference< css::ucb::XContent >& _xNewElement,
284 const css::uno::Reference< css::ucb::XContent >& xOldElement,
285 ContainerOperation _eOperation,
286 ListenerType _eType
287 );
288
289 operator css::uno::Reference< css::uno::XInterface > () const
290 {
291 return const_cast< XContainer* >( static_cast< const XContainer* >( this ) );
292 }
293
294private:
295 void addObjectListener(const css::uno::Reference< css::ucb::XContent >& _xNewObject);
296 void removeObjectListener(const css::uno::Reference< css::ucb::XContent >& _xNewObject);
297
310 void approveNewObject(
311 const OUString& _sName,
312 const css::uno::Reference< css::ucb::XContent >& _rxObject
313 ) const;
314
316 {
317 return ( m_aContainerListeners.getLength() > 0 ) || ( m_aApproveListeners.getLength() > 0 );
318 }
319};
320
321} // namespace dbaccess
322
323/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void insert(const OUString &_rName, TContentPtr _pDefinition)
NamedDefinitions::const_iterator const_iterator
std::map< OUString, TContentPtr > NamedDefinitions
const_iterator find(const OUString &_rName) const
void erase(const OUString &_rName)
virtual css::uno::Any SAL_CALL getByName(const OUString &aName) override
virtual void SAL_CALL addContainerApproveListener(const css::uno::Reference< css::container::XContainerApproveListener > &Listener) override
const ODefinitionContainer_Impl & getDefinitions() const
ODefinitionContainer_Impl & getDefinitions()
void implReplace(const OUString &_rName, const css::uno::Reference< css::ucb::XContent > &_rxNewObject)
remove an object in the container.
void implAppend(const OUString &_rName, const css::uno::Reference< css::ucb::XContent > &_rxNewObject)
append a new object to the container.
virtual css::uno::Reference< css::ucb::XContent > createObject(const OUString &_rName)=0
create an object from its persistent data within the configuration.
void removeObjectListener(const css::uno::Reference< css::ucb::XContent > &_xNewObject)
ODefinitionContainer(const css::uno::Reference< css::uno::XComponentContext > &_xORB, const css::uno::Reference< css::uno::XInterface > &_xParentContainer, const TContentPtr &_pImpl, bool _bCheckSlash=true)
constructs the container.
virtual void SAL_CALL replaceByName(const OUString &_rName, const css::uno::Any &aElement) override
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
virtual void SAL_CALL vetoableChange(const css::beans::PropertyChangeEvent &aEvent) override
::comphelper::OInterfaceContainerHelper2 m_aApproveListeners
::comphelper::OInterfaceContainerHelper2 m_aContainerListeners
virtual sal_Int32 SAL_CALL getCount() override
virtual sal_Bool SAL_CALL hasByName(const OUString &aName) override
std::map< OUString, css::uno::WeakReference< css::ucb::XContent > > Documents
void approveNewObject(const OUString &_sName, const css::uno::Reference< css::ucb::XContent > &_rxObject) const
approve that the object given may be inserted into the container.
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
void notifyByName(::osl::ResettableMutexGuard &_rGuard, const OUString &_rName, const css::uno::Reference< css::ucb::XContent > &_xNewElement, const css::uno::Reference< css::ucb::XContent > &xOldElement, ContainerOperation _eOperation, ListenerType _eType)
notifies our container/approve listeners
virtual void SAL_CALL insertByName(const OUString &_rName, const css::uno::Any &aElement) override
virtual void SAL_CALL disposing() override
void implRemove(const OUString &_rName)
remove all references to an object from the container.
virtual void SAL_CALL removeContainerApproveListener(const css::uno::Reference< css::container::XContainerApproveListener > &Listener) override
virtual OUString SAL_CALL getImplementationName() override
virtual sal_Bool SAL_CALL hasElements() override
const PContainerApprove & getElementApproval() const
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 _nIndex) override
virtual void SAL_CALL removeContainerListener(const css::uno::Reference< css::container::XContainerListener > &xListener) override
virtual void SAL_CALL propertyChange(const css::beans::PropertyChangeEvent &evt) override
void addObjectListener(const css::uno::Reference< css::ucb::XContent > &_xNewObject)
virtual void SAL_CALL removeByName(const OUString &_rName) override
virtual void SAL_CALL addContainerListener(const css::uno::Reference< css::container::XContainerListener > &xListener) override
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
css::uno::Reference< css::ucb::XContent > implGetByName(const OUString &_rName, bool _bCreateIfNecessary)
get the object specified by the given name.
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
std::vector< Documents::iterator > m_aDocuments
virtual bool checkExistence(const OUString &_rName)
quickly checks if there already is an element with a given name.
void setElementApproval(PContainerApprove _pElementApproval)
Additionally to our own approvals which new elements must pass, derived classes can specify an additi...
virtual css::uno::Type SAL_CALL getElementType() override
Type
std::shared_ptr< OContentHelper_Impl > TContentPtr
::cppu::ImplHelper7< css::container::XIndexAccess, css::container::XNameContainer, css::container::XEnumerationAccess, css::container::XContainer, css::container::XContainerApproveBroadcaster, css::beans::XPropertyChangeListener, css::beans::XVetoableChangeListener > ODefinitionContainer_Base
std::shared_ptr< IContainerApprove > PContainerApprove
unsigned char sal_Bool
signed char sal_Int8
#define DECLARE_XINTERFACE()