Files
libreoffice/dbaccess/source/core/inc/definitioncontainer.hxx

338 lines
17 KiB
C++
Raw Normal View History

/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
#ifndef _DBA_CORE_DEFINITIONCONTAINER_HXX_
#define _DBA_CORE_DEFINITIONCONTAINER_HXX_
#include <cppuhelper/interfacecontainer.hxx>
#include <cppuhelper/implbase7.hxx>
#include <comphelper/stl_types.hxx>
#include <osl/mutex.hxx>
#include <com/sun/star/container/XChild.hpp>
#include <com/sun/star/container/XNameContainer.hpp>
#include <com/sun/star/container/XContainer.hpp>
#include <com/sun/star/container/XEnumerationAccess.hpp>
#include <com/sun/star/container/XIndexAccess.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/DisposedException.hpp>
#include <com/sun/star/beans/XPropertyChangeListener.hpp>
#include <com/sun/star/beans/XVetoableChangeListener.hpp>
#include <com/sun/star/container/XContainerApproveBroadcaster.hpp>
#include "ContentHelper.hxx"
#include "containerapprove.hxx"
#include <comphelper/uno3.hxx>
#include <rtl/ref.hxx>
#include "apitools.hxx"
//........................................................................
namespace dbaccess
{
//........................................................................
class ODefinitionContainer_Impl : public OContentHelper_Impl
{
public:
typedef ::std::map< ::rtl::OUString, TContentPtr > NamedDefinitions;
typedef NamedDefinitions::iterator iterator;
typedef NamedDefinitions::const_iterator const_iterator;
private:
NamedDefinitions m_aDefinitions;
public:
inline size_t size() const { return m_aDefinitions.size(); }
inline const_iterator begin() const { return m_aDefinitions.begin(); }
inline const_iterator end() const { return m_aDefinitions.end(); }
inline const_iterator find( const ::rtl::OUString& _rName ) const { return m_aDefinitions.find( _rName ); }
const_iterator find( TContentPtr _pDefinition ) const;
inline void erase( const ::rtl::OUString& _rName ) { m_aDefinitions.erase( _rName ); }
void erase( TContentPtr _pDefinition );
inline void insert( const ::rtl::OUString& _rName, TContentPtr _pDefinition )
{
m_aDefinitions.insert( NamedDefinitions::value_type( _rName, _pDefinition ) );
}
private:
iterator find( TContentPtr _pDefinition );
// (for the moment, this is private. Make it public if needed. If really needed.)
};
//==========================================================================
//= ODefinitionContainer - base class of collections of database definition
//= documents
//==========================================================================
typedef ::cppu::ImplHelper7 < ::com::sun::star::container::XIndexAccess
, ::com::sun::star::container::XNameContainer
, ::com::sun::star::container::XEnumerationAccess
, ::com::sun::star::container::XContainer
, ::com::sun::star::container::XContainerApproveBroadcaster
, ::com::sun::star::beans::XPropertyChangeListener
, ::com::sun::star::beans::XVetoableChangeListener
> ODefinitionContainer_Base;
class ODefinitionContainer
:public OContentHelper
,public ODefinitionContainer_Base
{
protected:
DECLARE_STL_USTRINGACCESS_MAP(::com::sun::star::uno::WeakReference< ::com::sun::star::ucb::XContent >, Documents);
DECLARE_STL_VECTOR(Documents::iterator, DocumentsIndexAccess);
enum ContainerOperation
{
E_REPLACED,
E_REMOVED,
E_INSERTED
};
enum ListenerType
{
ApproveListeners,
ContainerListemers
};
private:
PContainerApprove m_pElementApproval;
protected:
// we can't just hold a vector of XContentRefs, as after initialization they're all empty
// cause we load them only on access
DocumentsIndexAccess m_aDocuments; // for a efficient index access
Documents m_aDocumentMap; // for a efficient name access
::cppu::OInterfaceContainerHelper
m_aApproveListeners;
::cppu::OInterfaceContainerHelper
m_aContainerListeners;
sal_Bool m_bInPropertyChange;
CWS-TOOLING: integrate CWS dba31d 2008-12-08 16:22:07 +0100 rt r265005 : Remove DOS lineends 2008-12-05 13:56:24 +0100 fs r264906 : #i10000# removed unreachable statement 2008-11-20 11:41:26 +0100 fs r264037 : merged in the fix for #i95865# (it was wrongly committed to CWS dba32a, should have been here) 2008-11-20 11:34:24 +0100 fs r264036 : line ends 2008-11-14 08:44:50 +0100 lla r263665 : #i10000# comparsion between int and uint fixed 2008-11-13 13:31:12 +0100 lla r263641 : #i10000# build problem fixed 2008-11-13 11:20:01 +0100 lla r263625 : #i96130# hard code name of extension 2008-11-12 11:13:41 +0100 fs r263582 : #i96096# when opening a SRB-report fails due to the missing SRB extension, log this as warning only, and proceed with the migration 2008-11-12 11:11:35 +0100 fs r263581 : #i96096# ContentType handling. Now all contents deliver proper results in XContent::getContentType 2008-11-12 11:10:11 +0100 fs r263580 : #i96096# new ctors taking UNO_QUERY_THROW 2008-11-11 10:10:13 +0100 lla r263546 : CWS-TOOLING: rebase CWS dba31d to trunk@263288 (milestone: DEV300:m35) 2008-11-06 15:55:39 +0100 oj r263393 : #i93452# get field from model fallbackis the name 2008-11-06 15:31:47 +0100 oj r263392 : #i93465# remeber location of floating windows 2008-11-06 13:36:24 +0100 oj r263381 : #i93450# check typemap for null 2008-11-06 13:28:49 +0100 oj r263379 : #i93020# empty column list boxes when new relation should be created 2008-11-06 12:33:53 +0100 oj r263377 : #i93012# set border to default : flat 2008-11-06 12:26:54 +0100 oj r263375 : #i74927# do some less calls for odbc 2008-11-06 09:34:01 +0100 oj r263362 : #i93383# grabFocus in suspend to get allmodified cells 2008-11-03 21:01:39 +0100 oj r263308 : #i86739# check if slash can be valid for tables 2008-11-03 14:40:21 +0100 oj r263287 : #i86739# check if slash can be valid for tables 2008-11-03 14:32:17 +0100 oj r263286 : #i95227# column width 2008-11-03 14:27:26 +0100 oj r263285 : link fwe 2008-11-03 14:24:54 +0100 oj r263284 : #i95235# changed to hold no ref only weak 2008-10-31 11:21:48 +0100 oj r262859 : #i93459# set images add menu entry 2008-10-31 09:06:37 +0100 oj r262851 : #i88629# correct fileopen filter for database odb files 2008-10-30 15:01:04 +0100 oj r262828 : #i95229# set filter at the composer 2008-10-29 15:57:41 +0100 oj r262817 : #i95235# changed to hold no ref only weak 2008-10-29 15:57:19 +0100 oj r262816 : #i95235# changed to hold no ref only weak 2008-10-29 15:57:03 +0100 oj r262815 : #i95235# changed to hold no ref only weak 2008-10-29 15:56:15 +0100 oj r262814 : #i95235# filtermanger changed to hold no ref only weak 2008-10-29 10:32:39 +0100 oj r262773 : #i93474# use correct table name 2008-10-28 13:49:33 +0100 lla r262744 : #i95524# make an Invalidate and refresh on Tables 2008-10-28 10:45:02 +0100 fs r262707 : line ends 2008-10-28 10:34:42 +0100 fs r262706 : #i95522# don't expect the component to live in a TopWindow 2008-10-28 08:30:40 +0100 lla r262696 : #i93176# set preview mode on view 2008-10-28 07:56:57 +0100 oj r262694 : merge cvs svn 2008-10-27 14:13:51 +0100 oj r262673 : #i94129# use dummy data 2008-10-27 12:38:45 +0100 fs r262669 : #i94125# rework ScrollColumns 2008-10-23 15:53:57 +0200 oj r262624 : #i94568# do not load the embeddedobj just copy the storage 2008-10-23 14:39:14 +0200 oj r262622 : #i94129# handle chart correctly 2008-10-22 10:51:19 +0200 lla r262582 : #i94115# problem with left walk chart shape fixed 2008-10-22 07:47:48 +0200 oj r262576 : #i94455# rename now do not use remove insert 2008-10-22 07:47:27 +0200 oj r262575 : #i94455# rename now do not use remove insert 2008-10-21 12:46:26 +0200 lla r262567 : #i93845# extra check if default schema doesn't exists, fix assertion
2008-12-09 07:25:38 +00:00
bool m_bCheckSlash;
protected:
/** Additionally to our own approvals which new elements must pass, derived classes
can specifiy an additional approval instance here.
Every time a new element is inserted into the container (or an element is replaced
with a new one), this new element must pass our own internal approval, plus the approval
given here.
*/
void setElementApproval( PContainerApprove _pElementApproval ) { m_pElementApproval = _pElementApproval; }
PContainerApprove getElementApproval() const { return m_pElementApproval; }
protected:
virtual ~ODefinitionContainer();
inline const ODefinitionContainer_Impl& getDefinitions() const
{
return dynamic_cast< const ODefinitionContainer_Impl& >( *m_pImpl.get() );
}
inline ODefinitionContainer_Impl& getDefinitions()
{
return dynamic_cast< ODefinitionContainer_Impl& >( *m_pImpl.get() );
}
public:
/** constructs the container.
*/
ODefinitionContainer(
const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xORB
, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xParentContainer
CWS-TOOLING: integrate CWS dba31d 2008-12-08 16:22:07 +0100 rt r265005 : Remove DOS lineends 2008-12-05 13:56:24 +0100 fs r264906 : #i10000# removed unreachable statement 2008-11-20 11:41:26 +0100 fs r264037 : merged in the fix for #i95865# (it was wrongly committed to CWS dba32a, should have been here) 2008-11-20 11:34:24 +0100 fs r264036 : line ends 2008-11-14 08:44:50 +0100 lla r263665 : #i10000# comparsion between int and uint fixed 2008-11-13 13:31:12 +0100 lla r263641 : #i10000# build problem fixed 2008-11-13 11:20:01 +0100 lla r263625 : #i96130# hard code name of extension 2008-11-12 11:13:41 +0100 fs r263582 : #i96096# when opening a SRB-report fails due to the missing SRB extension, log this as warning only, and proceed with the migration 2008-11-12 11:11:35 +0100 fs r263581 : #i96096# ContentType handling. Now all contents deliver proper results in XContent::getContentType 2008-11-12 11:10:11 +0100 fs r263580 : #i96096# new ctors taking UNO_QUERY_THROW 2008-11-11 10:10:13 +0100 lla r263546 : CWS-TOOLING: rebase CWS dba31d to trunk@263288 (milestone: DEV300:m35) 2008-11-06 15:55:39 +0100 oj r263393 : #i93452# get field from model fallbackis the name 2008-11-06 15:31:47 +0100 oj r263392 : #i93465# remeber location of floating windows 2008-11-06 13:36:24 +0100 oj r263381 : #i93450# check typemap for null 2008-11-06 13:28:49 +0100 oj r263379 : #i93020# empty column list boxes when new relation should be created 2008-11-06 12:33:53 +0100 oj r263377 : #i93012# set border to default : flat 2008-11-06 12:26:54 +0100 oj r263375 : #i74927# do some less calls for odbc 2008-11-06 09:34:01 +0100 oj r263362 : #i93383# grabFocus in suspend to get allmodified cells 2008-11-03 21:01:39 +0100 oj r263308 : #i86739# check if slash can be valid for tables 2008-11-03 14:40:21 +0100 oj r263287 : #i86739# check if slash can be valid for tables 2008-11-03 14:32:17 +0100 oj r263286 : #i95227# column width 2008-11-03 14:27:26 +0100 oj r263285 : link fwe 2008-11-03 14:24:54 +0100 oj r263284 : #i95235# changed to hold no ref only weak 2008-10-31 11:21:48 +0100 oj r262859 : #i93459# set images add menu entry 2008-10-31 09:06:37 +0100 oj r262851 : #i88629# correct fileopen filter for database odb files 2008-10-30 15:01:04 +0100 oj r262828 : #i95229# set filter at the composer 2008-10-29 15:57:41 +0100 oj r262817 : #i95235# changed to hold no ref only weak 2008-10-29 15:57:19 +0100 oj r262816 : #i95235# changed to hold no ref only weak 2008-10-29 15:57:03 +0100 oj r262815 : #i95235# changed to hold no ref only weak 2008-10-29 15:56:15 +0100 oj r262814 : #i95235# filtermanger changed to hold no ref only weak 2008-10-29 10:32:39 +0100 oj r262773 : #i93474# use correct table name 2008-10-28 13:49:33 +0100 lla r262744 : #i95524# make an Invalidate and refresh on Tables 2008-10-28 10:45:02 +0100 fs r262707 : line ends 2008-10-28 10:34:42 +0100 fs r262706 : #i95522# don't expect the component to live in a TopWindow 2008-10-28 08:30:40 +0100 lla r262696 : #i93176# set preview mode on view 2008-10-28 07:56:57 +0100 oj r262694 : merge cvs svn 2008-10-27 14:13:51 +0100 oj r262673 : #i94129# use dummy data 2008-10-27 12:38:45 +0100 fs r262669 : #i94125# rework ScrollColumns 2008-10-23 15:53:57 +0200 oj r262624 : #i94568# do not load the embeddedobj just copy the storage 2008-10-23 14:39:14 +0200 oj r262622 : #i94129# handle chart correctly 2008-10-22 10:51:19 +0200 lla r262582 : #i94115# problem with left walk chart shape fixed 2008-10-22 07:47:48 +0200 oj r262576 : #i94455# rename now do not use remove insert 2008-10-22 07:47:27 +0200 oj r262575 : #i94455# rename now do not use remove insert 2008-10-21 12:46:26 +0200 lla r262567 : #i93845# extra check if default schema doesn't exists, fix assertion
2008-12-09 07:25:38 +00:00
, const TContentPtr& _pImpl
, bool _bCheckSlash = true
);
// ::com::sun::star::uno::XInterface
DECLARE_XINTERFACE( )
// com::sun::star::lang::XTypeProvider
DECLARE_TYPEPROVIDER( );
// ::com::sun::star::lang::XServiceInfo
virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException);
// ::com::sun::star::container::XElementAccess
virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) throw(::com::sun::star::uno::RuntimeException);
virtual sal_Bool SAL_CALL hasElements( ) throw(::com::sun::star::uno::RuntimeException);
// ::com::sun::star::container::XEnumerationAccess
virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL createEnumeration( ) throw(::com::sun::star::uno::RuntimeException);
// ::com::sun::star::container::XIndexAccess
virtual sal_Int32 SAL_CALL getCount( ) throw(::com::sun::star::uno::RuntimeException);
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);
// ::com::sun::star::container::XNameContainer
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);
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);
// ::com::sun::star::container::XNameReplace
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);
// ::com::sun::star::container::XNameAccess
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);
virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw(::com::sun::star::uno::RuntimeException);
virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw(::com::sun::star::uno::RuntimeException);
// ::com::sun::star::container::XContainer
virtual void SAL_CALL addContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL removeContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
// XContainerApproveBroadcaster
virtual void SAL_CALL addContainerApproveListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerApproveListener >& Listener ) throw (::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL removeContainerApproveListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerApproveListener >& Listener ) throw (::com::sun::star::uno::RuntimeException);
// ::com::sun::star::lang::XEventListener
virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
// XPropertyChangeListener
virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw (::com::sun::star::uno::RuntimeException);
// XVetoableChangeListener
virtual void SAL_CALL vetoableChange( const ::com::sun::star::beans::PropertyChangeEvent& aEvent ) throw (::com::sun::star::beans::PropertyVetoException, ::com::sun::star::uno::RuntimeException);
protected:
// helper
virtual void SAL_CALL disposing();
/** create a object from it's persistent data within the configuration. To be overwritten by derived classes.
@param _rName the name the object has within the container
@return the newly created object or an empty reference if somthing went wrong
*/
virtual ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent > createObject(
const ::rtl::OUString& _rName) = 0;
/** get the object specified by the given name. If desired, the object will be read if not already done so.<BR>
@param _rName the object name
@param _bReadIfNeccessary if sal_True, the object will be created if necessary
@return the property set interface of the object. Usually the return value is not NULL, but
if so, then the object could not be read from the configuration
@throws NoSuchElementException if there is no object with the given name.
@see createObject
*/
virtual ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent >
implGetByName(const ::rtl::OUString& _rName, sal_Bool _bCreateIfNecessary) throw (::com::sun::star::container::NoSuchElementException);
/** quickly checks if there already is an element with a given name. No access to the configuration occures, i.e.
if there is such an object which is not already loaded, it won't be loaded now.
@param _rName the object name to check
@return sal_True if there already exists such an object
*/
virtual sal_Bool checkExistence(const ::rtl::OUString& _rName);
/** append a new object to the container. No plausibility checks are done, e.g. if the object is non-NULL or
if the name is already used by another object or anything like this. This method is for derived classes
which may support different methods to create and/or append objects, and don't want to deal with the
internal structures of this class.<BR>
The old component will not be disposed, this is the callers responsibility, too.
@param _rName the name of the new object
@param _rxNewObject the new object (not surprising, is it ?)
@see createConfigKey
@see implReplace
@see implRemove
*/
void implAppend(
const ::rtl::OUString& _rName,
const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent >& _rxNewObject
);
/** remove all references to an object from the container. No plausibility checks are done, e.g. whether
or not there exists an object with the given name. This is the responsibility of the caller.<BR>
Additionally the node for the given object will be removed from the registry (including all sub nodes).<BR>
The old component will not be disposed, this is the callers responsibility, too.
@param _rName the objects name
@see implReplace
@see implAppend
*/
void implRemove(const ::rtl::OUString& _rName);
/** remove a object in the container. No plausibility checks are done, e.g. whether
or not there exists an object with the given name or the object is non-NULL. This is the responsibility of the caller.<BR>
Additionally all object-related informations within the registry will be deleted. The new object config node,
where the caller may want to store the new objects information, is returned.<BR>
The old component will not be disposed, this is the callers responsibility, too.
@param _rName the objects name
@param _rxNewObject the new object
@param _rNewObjectNode the configuration node where the new object may be stored
@see implAppend
@see implRemove
*/
void implReplace(
const ::rtl::OUString& _rName,
const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent >& _rxNewObject
);
/** notifies our container/approve listeners
*/
void notifyByName(
::osl::ResettableMutexGuard& _rGuard,
const ::rtl::OUString& _rName,
const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent >& _xNewElement,
const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent >& xOldElement,
ContainerOperation _eOperation,
ListenerType _eType
);
inline SAL_CALL operator ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > () const
{
return const_cast< XContainer* >( static_cast< const XContainer* >( this ) );
}
private:
void addObjectListener(const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent >& _xNewObject);
void removeObjectListener(const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent >& _xNewObject);
/** approve that the object given may be inserted into the container. Should be overloaded by derived classes,
the default implementation just checks the object to be non-void.
@throws IllegalArgumentException
if the name or the object are invalid
@throws ElementExistException
if the object already exists in the container, or another object with the same name
already exists
@throws WrappedTargetException
if another error occures which prevents insertion of the object into the container
*/
void approveNewObject(
const ::rtl::OUString& _sName,
const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent >& _rxObject
) const;
inline bool impl_haveAnyListeners_nothrow() const
{
return ( m_aContainerListeners.getLength() > 0 ) || ( m_aApproveListeners.getLength() > 0 );
}
};
//........................................................................
} // namespace dbaccess
//........................................................................
#endif // _DBA_CORE_DEFINITIONCONTAINER_HXX_