1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: definitioncontainer.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _DBA_CORE_DEFINITIONCONTAINER_HXX_
32 #define _DBA_CORE_DEFINITIONCONTAINER_HXX_
34 #ifndef _CPPUHELPER_INTERFACECONTAINER_HXX_
35 #include <cppuhelper/interfacecontainer.hxx>
37 #ifndef _CPPUHELPER_IMPLBASE7_HXX_
38 #include <cppuhelper/implbase7.hxx>
40 #ifndef _COMPHELPER_STLTYPES_HXX_
41 #include <comphelper/stl_types.hxx>
43 #ifndef _OSL_MUTEX_HXX_
44 #include <osl/mutex.hxx>
46 #ifndef _COM_SUN_STAR_CONTAINER_XCHILD_HPP_
47 #include <com/sun/star/container/XChild.hpp>
49 #ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_
50 #include <com/sun/star/container/XNameContainer.hpp>
52 #ifndef _COM_SUN_STAR_CONTAINER_XCONTAINER_HPP_
53 #include <com/sun/star/container/XContainer.hpp>
55 #ifndef _COM_SUN_STAR_CONTAINER_XENUMERATIONACCESS_HPP_
56 #include <com/sun/star/container/XEnumerationAccess.hpp>
58 #ifndef _COM_SUN_STAR_CONTAINER_XINDEXACCESS_HPP_
59 #include <com/sun/star/container/XIndexAccess.hpp>
61 #ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_
62 #include <com/sun/star/lang/XServiceInfo.hpp>
64 #ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_
65 #include <com/sun/star/lang/DisposedException.hpp>
67 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYCHANGELISTENER_HPP_
68 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
70 #ifndef _COM_SUN_STAR_BEANS_XVETOABLECHANGELISTENER_HPP_
71 #include <com/sun/star/beans/XVetoableChangeListener.hpp>
73 #ifndef _COM_SUN_STAR_CONTAINER_XCONTAINERAPPROVEBROADCASTER_HPP_
74 #include <com/sun/star/container/XContainerApproveBroadcaster.hpp>
76 #ifndef DBA_CONTENTHELPER_HXX
77 #include "ContentHelper.hxx"
79 #ifndef DBACCESS_CONTAINERAPPROVE_HXX
80 #include "containerapprove.hxx"
82 #ifndef _COMPHELPER_UNO3_HXX_
83 #include <comphelper/uno3.hxx>
86 #include <rtl/ref.hxx>
88 #ifndef _DBASHARED_APITOOLS_HXX_
89 #include "apitools.hxx"
91 //........................................................................
94 //........................................................................
96 class ODefinitionContainer_Impl
: public OContentHelper_Impl
99 typedef ::std::map
< ::rtl::OUString
, TContentPtr
> NamedDefinitions
;
100 typedef NamedDefinitions::iterator iterator
;
101 typedef NamedDefinitions::const_iterator const_iterator
;
104 NamedDefinitions m_aDefinitions
;
107 inline size_t size() const { return m_aDefinitions
.size(); }
109 inline const_iterator
begin() const { return m_aDefinitions
.begin(); }
110 inline const_iterator
end() const { return m_aDefinitions
.end(); }
112 inline const_iterator
find( const ::rtl::OUString
& _rName
) const { return m_aDefinitions
.find( _rName
); }
113 const_iterator
find( TContentPtr _pDefinition
) const;
115 inline void erase( const ::rtl::OUString
& _rName
) { m_aDefinitions
.erase( _rName
); }
116 void erase( TContentPtr _pDefinition
);
118 inline void insert( const ::rtl::OUString
& _rName
, TContentPtr _pDefinition
)
120 m_aDefinitions
.insert( NamedDefinitions::value_type( _rName
, _pDefinition
) );
124 iterator
find( TContentPtr _pDefinition
);
125 // (for the moment, this is private. Make it public if needed. If really needed.)
128 //==========================================================================
129 //= ODefinitionContainer - base class of collections of database definition
131 //==========================================================================
132 typedef ::cppu::ImplHelper7
< ::com::sun::star::container::XIndexAccess
133 , ::com::sun::star::container::XNameContainer
134 , ::com::sun::star::container::XEnumerationAccess
135 , ::com::sun::star::container::XContainer
136 , ::com::sun::star::container::XContainerApproveBroadcaster
137 , ::com::sun::star::beans::XPropertyChangeListener
138 , ::com::sun::star::beans::XVetoableChangeListener
139 > ODefinitionContainer_Base
;
141 class ODefinitionContainer
142 :public OContentHelper
143 ,public ODefinitionContainer_Base
146 DECLARE_STL_USTRINGACCESS_MAP(::com::sun::star::uno::WeakReference
< ::com::sun::star::ucb::XContent
>, Documents
);
147 DECLARE_STL_VECTOR(Documents::iterator
, DocumentsIndexAccess
);
149 enum ContainerOperation
163 PContainerApprove m_pElementApproval
;
166 // we can't just hold a vector of XContentRefs, as after initialization they're all empty
167 // cause we load them only on access
168 DocumentsIndexAccess m_aDocuments
; // for a efficient index access
169 Documents m_aDocumentMap
; // for a efficient name access
171 ::cppu::OInterfaceContainerHelper
173 ::cppu::OInterfaceContainerHelper
174 m_aContainerListeners
;
176 sal_Bool m_bInPropertyChange
;
180 /** Additionally to our own approvals which new elements must pass, derived classes
181 can specifiy an additional approval instance here.
183 Every time a new element is inserted into the container (or an element is replaced
184 with a new one), this new element must pass our own internal approval, plus the approval
187 void setElementApproval( PContainerApprove _pElementApproval
) { m_pElementApproval
= _pElementApproval
; }
188 PContainerApprove
getElementApproval() const { return m_pElementApproval
; }
191 virtual ~ODefinitionContainer();
193 inline const ODefinitionContainer_Impl
& getDefinitions() const
195 return dynamic_cast< const ODefinitionContainer_Impl
& >( *m_pImpl
.get() );
198 inline ODefinitionContainer_Impl
& getDefinitions()
200 return dynamic_cast< ODefinitionContainer_Impl
& >( *m_pImpl
.get() );
203 /** constructs the container.
205 ODefinitionContainer(
206 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _xORB
207 , const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _xParentContainer
208 , const TContentPtr
& _pImpl
209 , bool _bCheckSlash
= true
212 // ::com::sun::star::uno::XInterface
213 DECLARE_XINTERFACE( )
214 // com::sun::star::lang::XTypeProvider
215 DECLARE_TYPEPROVIDER( );
217 // ::com::sun::star::lang::XServiceInfo
218 virtual ::rtl::OUString SAL_CALL
getImplementationName( ) throw(::com::sun::star::uno::RuntimeException
);
219 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException
);
221 // ::com::sun::star::container::XElementAccess
222 virtual ::com::sun::star::uno::Type SAL_CALL
getElementType( ) throw(::com::sun::star::uno::RuntimeException
);
223 virtual sal_Bool SAL_CALL
hasElements( ) throw(::com::sun::star::uno::RuntimeException
);
225 // ::com::sun::star::container::XEnumerationAccess
226 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::container::XEnumeration
> SAL_CALL
createEnumeration( ) throw(::com::sun::star::uno::RuntimeException
);
228 // ::com::sun::star::container::XIndexAccess
229 virtual sal_Int32 SAL_CALL
getCount( ) throw(::com::sun::star::uno::RuntimeException
);
230 virtual ::com::sun::star::uno::Any SAL_CALL
getByIndex( sal_Int32 _nIndex
) throw(::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
);
232 // ::com::sun::star::container::XNameContainer
233 virtual void SAL_CALL
insertByName( const ::rtl::OUString
& _rName
, const ::com::sun::star::uno::Any
& aElement
) throw(::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::container::ElementExistException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
);
234 virtual void SAL_CALL
removeByName( const ::rtl::OUString
& _rName
) throw(::com::sun::star::container::NoSuchElementException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
);
236 // ::com::sun::star::container::XNameReplace
237 virtual void SAL_CALL
replaceByName( const ::rtl::OUString
& _rName
, const ::com::sun::star::uno::Any
& aElement
) throw(::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::container::NoSuchElementException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
);
239 // ::com::sun::star::container::XNameAccess
240 virtual ::com::sun::star::uno::Any SAL_CALL
getByName( const ::rtl::OUString
& aName
) throw(::com::sun::star::container::NoSuchElementException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
);
241 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getElementNames( ) throw(::com::sun::star::uno::RuntimeException
);
242 virtual sal_Bool SAL_CALL
hasByName( const ::rtl::OUString
& aName
) throw(::com::sun::star::uno::RuntimeException
);
244 // ::com::sun::star::container::XContainer
245 virtual void SAL_CALL
addContainerListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XContainerListener
>& xListener
) throw(::com::sun::star::uno::RuntimeException
);
246 virtual void SAL_CALL
removeContainerListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XContainerListener
>& xListener
) throw(::com::sun::star::uno::RuntimeException
);
248 // XContainerApproveBroadcaster
249 virtual void SAL_CALL
addContainerApproveListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XContainerApproveListener
>& Listener
) throw (::com::sun::star::uno::RuntimeException
);
250 virtual void SAL_CALL
removeContainerApproveListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XContainerApproveListener
>& Listener
) throw (::com::sun::star::uno::RuntimeException
);
252 // ::com::sun::star::lang::XEventListener
253 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& Source
) throw(::com::sun::star::uno::RuntimeException
);
255 // XPropertyChangeListener
256 virtual void SAL_CALL
propertyChange( const ::com::sun::star::beans::PropertyChangeEvent
& evt
) throw (::com::sun::star::uno::RuntimeException
);
257 // XVetoableChangeListener
258 virtual void SAL_CALL
vetoableChange( const ::com::sun::star::beans::PropertyChangeEvent
& aEvent
) throw (::com::sun::star::beans::PropertyVetoException
, ::com::sun::star::uno::RuntimeException
);
262 virtual void SAL_CALL
disposing();
264 /** create a object from it's persistent data within the configuration. To be overwritten by derived classes.
265 @param _rName the name the object has within the container
266 @return the newly created object or an empty reference if somthing went wrong
268 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::ucb::XContent
> createObject(
269 const ::rtl::OUString
& _rName
) = 0;
271 /** get the object specified by the given name. If desired, the object will be read if not already done so.<BR>
272 @param _rName the object name
273 @param _bReadIfNeccessary if sal_True, the object will be created if necessary
274 @return the property set interface of the object. Usually the return value is not NULL, but
275 if so, then the object could not be read from the configuration
276 @throws NoSuchElementException if there is no object with the given name.
279 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::ucb::XContent
>
280 implGetByName(const ::rtl::OUString
& _rName
, sal_Bool _bCreateIfNecessary
) throw (::com::sun::star::container::NoSuchElementException
);
282 /** quickly checks if there already is an element with a given name. No access to the configuration occures, i.e.
283 if there is such an object which is not already loaded, it won't be loaded now.
284 @param _rName the object name to check
285 @return sal_True if there already exists such an object
287 virtual sal_Bool
checkExistence(const ::rtl::OUString
& _rName
);
289 /** append a new object to the container. No plausibility checks are done, e.g. if the object is non-NULL or
290 if the name is already used by another object or anything like this. This method is for derived classes
291 which may support different methods to create and/or append objects, and don't want to deal with the
292 internal structures of this class.<BR>
293 The old component will not be disposed, this is the callers responsibility, too.
294 @param _rName the name of the new object
295 @param _rxNewObject the new object (not surprising, is it ?)
301 const ::rtl::OUString
& _rName
,
302 const ::com::sun::star::uno::Reference
< ::com::sun::star::ucb::XContent
>& _rxNewObject
305 /** remove all references to an object from the container. No plausibility checks are done, e.g. whether
306 or not there exists an object with the given name. This is the responsibility of the caller.<BR>
307 Additionally the node for the given object will be removed from the registry (including all sub nodes).<BR>
308 The old component will not be disposed, this is the callers responsibility, too.
309 @param _rName the objects name
313 void implRemove(const ::rtl::OUString
& _rName
);
315 /** remove a object in the container. No plausibility checks are done, e.g. whether
316 or not there exists an object with the given name or the object is non-NULL. This is the responsibility of the caller.<BR>
317 Additionally all object-related informations within the registry will be deleted. The new object config node,
318 where the caller may want to store the new objects information, is returned.<BR>
319 The old component will not be disposed, this is the callers responsibility, too.
320 @param _rName the objects name
321 @param _rxNewObject the new object
322 @param _rNewObjectNode the configuration node where the new object may be stored
327 const ::rtl::OUString
& _rName
,
328 const ::com::sun::star::uno::Reference
< ::com::sun::star::ucb::XContent
>& _rxNewObject
331 /** notifies our container/approve listeners
334 ::osl::ResettableMutexGuard
& _rGuard
,
335 const ::rtl::OUString
& _rName
,
336 const ::com::sun::star::uno::Reference
< ::com::sun::star::ucb::XContent
>& _xNewElement
,
337 const ::com::sun::star::uno::Reference
< ::com::sun::star::ucb::XContent
>& xOldElement
,
338 ContainerOperation _eOperation
,
342 inline SAL_CALL
operator ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> () const
344 return const_cast< XContainer
* >( static_cast< const XContainer
* >( this ) );
348 void addObjectListener(const ::com::sun::star::uno::Reference
< ::com::sun::star::ucb::XContent
>& _xNewObject
);
349 void removeObjectListener(const ::com::sun::star::uno::Reference
< ::com::sun::star::ucb::XContent
>& _xNewObject
);
351 /** approve that the object given may be inserted into the container. Should be overloaded by derived classes,
352 the default implementation just checks the object to be non-void.
354 @throws IllegalArgumentException
355 if the name or the object are invalid
356 @throws ElementExistException
357 if the object already exists in the container, or another object with the same name
359 @throws WrappedTargetException
360 if another error occures which prevents insertion of the object into the container
362 void approveNewObject(
363 const ::rtl::OUString
& _sName
,
364 const ::com::sun::star::uno::Reference
< ::com::sun::star::ucb::XContent
>& _rxObject
367 inline bool impl_haveAnyListeners_nothrow() const
369 return ( m_aContainerListeners
.getLength() > 0 ) || ( m_aApproveListeners
.getLength() > 0 );
373 //........................................................................
374 } // namespace dbaccess
375 //........................................................................
377 #endif // _DBA_CORE_DEFINITIONCONTAINER_HXX_