Files
libreoffice/dbaccess/source/core/dataaccess/definitioncontainer.cxx

689 lines
23 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2012-06-14 17:39:53 +01:00
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
2000-09-18 23:16:46 +00:00
#include "definitioncontainer.hxx"
2000-10-25 06:42:28 +00:00
#include "dbastrings.hrc"
2000-09-18 23:16:46 +00:00
#include "apitools.hxx"
#include "core_resource.hxx"
#include "core_resource.hrc"
2000-09-18 23:16:46 +00:00
#include <tools/debug.hxx>
#include <tools/diagnose_ex.h>
2011-02-03 00:33:36 +01:00
#include <osl/diagnose.h>
2000-10-11 10:21:40 +00:00
#include <comphelper/sequence.hxx>
#include <comphelper/enumhelper.hxx>
#include <comphelper/extract.hxx>
#include <cppuhelper/exc_hlp.hxx>
2000-09-18 23:16:46 +00:00
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/ucb/CommandInfo.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/sdb/ErrorCondition.hpp>
2000-10-25 06:42:28 +00:00
#include <comphelper/types.hxx>
#include <ucbhelper/contentidentifier.hxx>
2000-09-18 23:16:46 +00:00
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::util;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::sdbcx;
using namespace ::com::sun::star::sdb;
2000-09-18 23:16:46 +00:00
using namespace ::osl;
2000-10-11 10:21:40 +00:00
using namespace ::comphelper;
2000-09-18 23:16:46 +00:00
using namespace ::cppu;
using namespace ::com::sun::star::ucb;
2000-09-18 23:16:46 +00:00
namespace dbaccess
{
// ODefinitionContainer_Impl
void ODefinitionContainer_Impl::erase( TContentPtr _pDefinition )
{
NamedDefinitions::const_iterator aPos = find( _pDefinition );
if ( aPos != end() )
m_aDefinitions.erase( aPos );
}
ODefinitionContainer_Impl::const_iterator ODefinitionContainer_Impl::find( TContentPtr _pDefinition ) const
{
return ::std::find_if(
m_aDefinitions.begin(),
m_aDefinitions.end(),
[&_pDefinition] (const NamedDefinitions::value_type& namedDef) {
return namedDef.second == _pDefinition;
});
}
ODefinitionContainer_Impl::iterator ODefinitionContainer_Impl::find( TContentPtr _pDefinition )
{
return ::std::find_if(
m_aDefinitions.begin(),
m_aDefinitions.end(),
[&_pDefinition] (const NamedDefinitions::value_type& namedDef) {
return namedDef.second == _pDefinition;
});
}
// ODefinitionContainer
ODefinitionContainer::ODefinitionContainer( const Reference< XComponentContext >& _xORB
, const Reference< XInterface >& _xParentContainer
, const TContentPtr& _pImpl
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 _bCheckSlash
)
:OContentHelper(_xORB,_xParentContainer,_pImpl)
,m_aApproveListeners(m_aMutex)
,m_aContainerListeners(m_aMutex)
,m_bInPropertyChange(false)
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
,m_bCheckSlash(_bCheckSlash)
{
m_pImpl->m_aProps.bIsDocument = false;
m_pImpl->m_aProps.bIsFolder = true;
const ODefinitionContainer_Impl& rDefinitions( getDefinitions() );
ODefinitionContainer_Impl::const_iterator aEnd = rDefinitions.end();
for ( ODefinitionContainer_Impl::const_iterator aDefinition = rDefinitions.begin();
aDefinition != aEnd;
++aDefinition
)
m_aDocuments.push_back(
m_aDocumentMap.insert(
Documents::value_type( aDefinition->first, Documents::mapped_type() ) ).first );
2000-09-18 23:16:46 +00:00
}
void SAL_CALL ODefinitionContainer::disposing()
2000-09-18 23:16:46 +00:00
{
OContentHelper::disposing();
2000-09-18 23:16:46 +00:00
MutexGuard aGuard(m_aMutex);
2000-09-18 23:16:46 +00:00
2011-01-09 02:04:00 +09:00
// say goodbye to our listeners
2000-09-18 23:16:46 +00:00
EventObject aEvt(*this);
m_aApproveListeners.disposeAndClear(aEvt);
2000-09-18 23:16:46 +00:00
m_aContainerListeners.disposeAndClear(aEvt);
// dispose our elements
Documents::const_iterator aIter = m_aDocumentMap.begin();
Documents::const_iterator aEnd = m_aDocumentMap.end();
for (; aIter != aEnd; ++aIter)
2000-09-18 23:16:46 +00:00
{
Reference<XContent> xProp = aIter->second;
if ( xProp.is() )
{
removeObjectListener(xProp);
::comphelper::disposeComponent(xProp);
}
2000-09-18 23:16:46 +00:00
}
// remove our elements
m_aDocuments.clear();
// !!! do this before clearing the map which the vector elements refer to !!!
m_aDocumentMap.clear();
2000-09-18 23:16:46 +00:00
}
ODefinitionContainer::~ODefinitionContainer()
{
}
IMPLEMENT_FORWARD_XINTERFACE2( ODefinitionContainer,OContentHelper,ODefinitionContainer_Base)
IMPLEMENT_GETTYPES2(ODefinitionContainer,OContentHelper,ODefinitionContainer_Base);
css::uno::Sequence<sal_Int8> ODefinitionContainer::getImplementationId()
throw (css::uno::RuntimeException, std::exception)
{
return css::uno::Sequence<sal_Int8>();
}
2000-09-18 23:16:46 +00:00
// XServiceInfo
OUString SAL_CALL ODefinitionContainer::getImplementationName( ) throw(RuntimeException, std::exception)
2000-09-18 23:16:46 +00:00
{
return OUString("com.sun.star.sdb.ODefinitionContainer");
2000-09-18 23:16:46 +00:00
}
Sequence< OUString > SAL_CALL ODefinitionContainer::getSupportedServiceNames( ) throw(RuntimeException, std::exception)
2000-09-18 23:16:46 +00:00
{
Sequence< OUString > aReturn(2);
aReturn.getArray()[0] = "com.sun.star.sdb.DefinitionContainer";
aReturn.getArray()[1] = "com.sun.star.ucb.Content";
2000-09-18 23:16:46 +00:00
return aReturn;
}
// XNameContainer
void SAL_CALL ODefinitionContainer::insertByName( const OUString& _rName, const Any& aElement ) throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException, std::exception)
2000-09-18 23:16:46 +00:00
{
ResettableMutexGuard aGuard(m_aMutex);
2000-09-18 23:16:46 +00:00
// approve the new object
Reference< XContent > xNewElement(aElement,UNO_QUERY);
approveNewObject( _rName, xNewElement ); // will throw if necessary
2000-09-18 23:16:46 +00:00
notifyByName( aGuard, _rName, xNewElement, nullptr, E_INSERTED, ApproveListeners );
implAppend( _rName, xNewElement );
notifyByName( aGuard, _rName, xNewElement, nullptr, E_INSERTED, ContainerListemers );
2000-09-18 23:16:46 +00:00
}
void SAL_CALL ODefinitionContainer::removeByName( const OUString& _rName ) throw(NoSuchElementException, WrappedTargetException, RuntimeException, std::exception)
2000-09-18 23:16:46 +00:00
{
ResettableMutexGuard aGuard(m_aMutex);
2000-09-18 23:16:46 +00:00
// check the arguments
if (_rName.isEmpty())
throw IllegalArgumentException();
if (!checkExistence(_rName))
throw NoSuchElementException(_rName,*this);
2000-09-18 23:16:46 +00:00
// the old element (for the notifications)
Reference< XContent > xOldElement = implGetByName( _rName, impl_haveAnyListeners_nothrow() );
2000-09-18 23:16:46 +00:00
// do the removal
notifyByName( aGuard, _rName, nullptr, xOldElement, E_REMOVED, ApproveListeners );
implRemove( _rName );
notifyByName( aGuard, _rName, nullptr, xOldElement, E_REMOVED, ContainerListemers );
2000-09-18 23:16:46 +00:00
removeObjectListener( xOldElement );
disposeComponent(xOldElement);
2000-09-18 23:16:46 +00:00
}
// XNameReplace
void SAL_CALL ODefinitionContainer::replaceByName( const OUString& _rName, const Any& aElement ) throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException, std::exception)
2000-09-18 23:16:46 +00:00
{
ResettableMutexGuard aGuard(m_aMutex);
2000-09-18 23:16:46 +00:00
try
{
// let derived classes approve the new object
Reference< XContent > xNewElement(aElement,UNO_QUERY);
approveNewObject( _rName, xNewElement ); // will throw if necessary
2000-09-18 23:16:46 +00:00
// the old element (for the notifications)
Reference< XContent > xOldElement = implGetByName( _rName, impl_haveAnyListeners_nothrow() );
2000-09-18 23:16:46 +00:00
notifyByName( aGuard, _rName, xNewElement, xOldElement, E_REPLACED, ApproveListeners );
implReplace( _rName, xNewElement );
notifyByName( aGuard, _rName, xNewElement, xOldElement, E_REPLACED, ContainerListemers );
2000-09-18 23:16:46 +00:00
// and dispose it
disposeComponent(xOldElement);
}
catch (const RuntimeException&)
{
throw;
}
catch (const NoSuchElementException&)
{
throw;
}
catch (const WrappedTargetException&)
{
throw;
}
catch (const Exception& e)
{
css::uno::Any a(cppu::getCaughtException());
throw css::lang::WrappedTargetException(
"wrapped Exception " + e.Message,
css::uno::Reference<css::uno::XInterface>(), a);
}
}
namespace
{
typedef Reference< XVeto > ( SAL_CALL XContainerApproveListener::*ContainerApprovalMethod )( const ContainerEvent& );
struct RaiseExceptionFromVeto
2000-09-18 23:16:46 +00:00
{
private:
ContainerApprovalMethod m_pMethod;
const ContainerEvent& m_rEvent;
public:
explicit RaiseExceptionFromVeto( ContainerApprovalMethod _pMethod, const ContainerEvent& _rEvent )
:m_pMethod( _pMethod )
,m_rEvent( _rEvent )
{
}
void operator()( const Reference< XContainerApproveListener >& _Listener ) const
{
Reference< XVeto > xVeto = (_Listener.get()->*m_pMethod)( m_rEvent );
if ( !xVeto.is() )
return;
Any eVetoDetails = xVeto->getDetails();
IllegalArgumentException aIllegalArgumentError;
if ( eVetoDetails >>= aIllegalArgumentError )
throw aIllegalArgumentError;
WrappedTargetException aWrappedError;
if ( eVetoDetails >>= aWrappedError )
throw aWrappedError;
throw WrappedTargetException( xVeto->getReason(), _Listener.get(), eVetoDetails );
}
};
}
void ODefinitionContainer::notifyByName( ResettableMutexGuard& _rGuard, const OUString& _rName,
const Reference< XContent >& _xNewElement, const Reference< XContent >& _xOldElement,
ContainerOperation _eOperation, ListenerType _eType )
{
bool bApprove = ( _eType == ApproveListeners );
::comphelper::OInterfaceContainerHelper2& rContainer( bApprove ? m_aApproveListeners : m_aContainerListeners );
if ( !rContainer.getLength() )
return;
ContainerEvent aEvent( *this, makeAny( _rName ), makeAny( _xNewElement ), makeAny( _xOldElement ) );
_rGuard.clear();
switch ( _eOperation )
{
case E_INSERTED:
if ( bApprove )
rContainer.forEach< XContainerApproveListener, RaiseExceptionFromVeto >(
RaiseExceptionFromVeto( &XContainerApproveListener::approveInsertElement, aEvent ) );
else
rContainer.notifyEach( &XContainerListener::elementInserted, aEvent );
break;
case E_REPLACED:
if ( bApprove )
rContainer.forEach< XContainerApproveListener, RaiseExceptionFromVeto >(
RaiseExceptionFromVeto( &XContainerApproveListener::approveReplaceElement, aEvent ) );
else
rContainer.notifyEach( &XContainerListener::elementReplaced, aEvent );
break;
case E_REMOVED:
if ( bApprove )
rContainer.forEach< XContainerApproveListener, RaiseExceptionFromVeto >(
RaiseExceptionFromVeto( &XContainerApproveListener::approveRemoveElement, aEvent ) );
else
rContainer.notifyEach( &XContainerListener::elementRemoved, aEvent );
break;
2000-09-18 23:16:46 +00:00
}
if ( bApprove )
_rGuard.reset();
2000-09-18 23:16:46 +00:00
}
void SAL_CALL ODefinitionContainer::addContainerListener( const Reference< XContainerListener >& _rxListener ) throw(RuntimeException, std::exception)
2000-09-18 23:16:46 +00:00
{
if (_rxListener.is())
m_aContainerListeners.addInterface(_rxListener);
}
void SAL_CALL ODefinitionContainer::removeContainerListener( const Reference< XContainerListener >& _rxListener ) throw(RuntimeException, std::exception)
2000-09-18 23:16:46 +00:00
{
if (_rxListener.is())
m_aContainerListeners.removeInterface(_rxListener);
}
void SAL_CALL ODefinitionContainer::addContainerApproveListener( const Reference< XContainerApproveListener >& _Listener ) throw (RuntimeException, std::exception)
{
if ( _Listener.is() )
m_aApproveListeners.addInterface( _Listener );
}
void SAL_CALL ODefinitionContainer::removeContainerApproveListener( const Reference< XContainerApproveListener >& _Listener ) throw (RuntimeException, std::exception)
{
if ( _Listener.is() )
m_aApproveListeners.removeInterface( _Listener );
}
2000-09-18 23:16:46 +00:00
// XElementAccess
Type SAL_CALL ODefinitionContainer::getElementType( ) throw (RuntimeException, std::exception)
2000-09-18 23:16:46 +00:00
{
return cppu::UnoType<XContent>::get();
2000-09-18 23:16:46 +00:00
}
sal_Bool SAL_CALL ODefinitionContainer::hasElements( ) throw (RuntimeException, std::exception)
2000-09-18 23:16:46 +00:00
{
MutexGuard aGuard(m_aMutex);
return !m_aDocuments.empty();
2000-09-18 23:16:46 +00:00
}
// XEnumerationAccess
Reference< XEnumeration > SAL_CALL ODefinitionContainer::createEnumeration( ) throw(RuntimeException, std::exception)
2000-09-18 23:16:46 +00:00
{
MutexGuard aGuard(m_aMutex);
2000-10-11 10:21:40 +00:00
return new ::comphelper::OEnumerationByIndex(static_cast<XIndexAccess*>(this));
2000-09-18 23:16:46 +00:00
}
// XIndexAccess
sal_Int32 SAL_CALL ODefinitionContainer::getCount( ) throw(RuntimeException, std::exception)
2000-09-18 23:16:46 +00:00
{
MutexGuard aGuard(m_aMutex);
2000-09-18 23:16:46 +00:00
return m_aDocuments.size();
}
Any SAL_CALL ODefinitionContainer::getByIndex( sal_Int32 _nIndex ) throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception)
2000-09-18 23:16:46 +00:00
{
MutexGuard aGuard(m_aMutex);
2000-09-18 23:16:46 +00:00
if ((_nIndex < 0) || (_nIndex >= (sal_Int32)m_aDocuments.size()))
2000-09-18 23:16:46 +00:00
throw IndexOutOfBoundsException();
Documents::iterator aPos = m_aDocuments[_nIndex];
Reference<XContent> xProp = aPos->second;
if (!xProp.is())
2000-09-18 23:16:46 +00:00
{ // that's the first access to the object
// -> create it
xProp = createObject(aPos->first);
aPos->second = Documents::mapped_type();
2000-09-18 23:16:46 +00:00
// and update the name-access map
}
return makeAny(xProp);
2000-09-18 23:16:46 +00:00
}
Any SAL_CALL ODefinitionContainer::getByName( const OUString& _rName ) throw(NoSuchElementException, WrappedTargetException, RuntimeException, std::exception)
2000-09-18 23:16:46 +00:00
{
MutexGuard aGuard(m_aMutex);
2000-09-18 23:16:46 +00:00
return makeAny( implGetByName( _rName, true ) );
2000-09-18 23:16:46 +00:00
}
Reference< XContent > ODefinitionContainer::implGetByName(const OUString& _rName, bool _bReadIfNecessary) throw (NoSuchElementException)
2000-09-18 23:16:46 +00:00
{
Documents::iterator aMapPos = m_aDocumentMap.find(_rName);
2000-09-18 23:16:46 +00:00
if (aMapPos == m_aDocumentMap.end())
throw NoSuchElementException(_rName,*this);
2000-09-18 23:16:46 +00:00
Reference< XContent > xProp = aMapPos->second;
if (_bReadIfNecessary && !xProp.is())
2000-09-18 23:16:46 +00:00
{ // the object has never been accessed before, so we have to read it now
// (that's the expensive part)
// create the object and insert it into the map
xProp = createObject(_rName);
aMapPos->second = xProp;
addObjectListener(xProp);
2000-09-18 23:16:46 +00:00
}
return xProp;
2000-09-18 23:16:46 +00:00
}
Sequence< OUString > SAL_CALL ODefinitionContainer::getElementNames( ) throw(RuntimeException, std::exception)
2000-09-18 23:16:46 +00:00
{
MutexGuard aGuard(m_aMutex);
2000-09-18 23:16:46 +00:00
Sequence< OUString > aNames(m_aDocumentMap.size());
OUString* pNames = aNames.getArray();
Documents::const_iterator aEnd = m_aDocumentMap.end();
for ( Documents::const_iterator aNameIter = m_aDocumentMap.begin();
aNameIter != aEnd;
2000-09-18 23:16:46 +00:00
++pNames, ++aNameIter
)
{
*pNames = aNameIter->first;
}
return aNames;
}
sal_Bool SAL_CALL ODefinitionContainer::hasByName( const OUString& _rName ) throw(RuntimeException, std::exception)
2000-09-18 23:16:46 +00:00
{
MutexGuard aGuard(m_aMutex);
2000-09-18 23:16:46 +00:00
return checkExistence(_rName);
2000-09-18 23:16:46 +00:00
}
void SAL_CALL ODefinitionContainer::disposing( const EventObject& _rSource ) throw(RuntimeException, std::exception)
2000-09-18 23:16:46 +00:00
{
MutexGuard aGuard(m_aMutex);
Reference< XContent > xSource(_rSource.Source, UNO_QUERY);
2000-09-18 23:16:46 +00:00
// it's one of our documents ....
Documents::iterator aIter = m_aDocumentMap.begin();
Documents::const_iterator aEnd = m_aDocumentMap.end();
for (;aIter != aEnd;++aIter )
2000-09-18 23:16:46 +00:00
{
if ( xSource == aIter->second.get() )
2000-09-18 23:16:46 +00:00
{
removeObjectListener(xSource);
2000-09-18 23:16:46 +00:00
// and clear our document map/vector, so the object will be recreated on next access
aIter->second = Documents::mapped_type();
2000-09-18 23:16:46 +00:00
}
}
}
void ODefinitionContainer::implRemove(const OUString& _rName)
2000-09-18 23:16:46 +00:00
{
// from the object maps
Documents::const_iterator aFind = m_aDocumentMap.find(_rName);
if ( aFind != m_aDocumentMap.end() )
2000-09-18 23:16:46 +00:00
{
m_aDocuments.erase( ::std::find(m_aDocuments.begin(),m_aDocuments.end(),aFind));
m_aDocumentMap.erase(aFind);
2000-09-18 23:16:46 +00:00
getDefinitions().erase( _rName );
notifyDataSourceModified();
}
2000-09-18 23:16:46 +00:00
}
namespace
{
bool lcl_ensureName( const Reference< XContent >& _rxContent, const OUString& _rName )
{
if ( !_rxContent.is() )
return true;
// obtain the current name. If it's the same as the new one,
// don't do anything
try
{
Reference< XPropertySet > xProps( _rxContent, UNO_QUERY );
if ( xProps.is() )
{
OUString sCurrentName;
OSL_VERIFY( xProps->getPropertyValue( PROPERTY_NAME ) >>= sCurrentName );
if ( sCurrentName.equals( _rName ) )
return true;
}
}
catch( const Exception& )
{
OSL_FAIL( "lcl_ensureName: caught an exception while obtaining the current name!" );
}
// set the new name
Reference< XRename > xRename( _rxContent, UNO_QUERY );
OSL_ENSURE( xRename.is(), "lcl_ensureName: invalid content (not renameable)!" );
if ( !xRename.is() )
return false;
try
{
xRename->rename( _rName );
return true;
}
catch( const Exception& )
{
OSL_FAIL( "lcl_ensureName: caught an exception!" );
}
return false;
}
}
void ODefinitionContainer::implAppend(const OUString& _rName, const Reference< XContent >& _rxNewObject)
2000-09-18 23:16:46 +00:00
{
MutexGuard aGuard(m_aMutex);
2000-09-18 23:16:46 +00:00
try
{
Reference<XChild> xChild(_rxNewObject,UNO_QUERY);
if ( xChild.is() )
xChild->setParent(static_cast<OWeakObject*>(this));
ODefinitionContainer_Impl& rDefinitions( getDefinitions() );
ODefinitionContainer_Impl::const_iterator aFind = rDefinitions.find( _rName );
if ( aFind == rDefinitions.end() )
2001-10-30 08:55:07 +00:00
{
// ensure that the new object has the proper name.
// Somebody could create an object with name "foo", and insert it as "bar"
// into a container. In this case, we need to ensure that the object name
// is also "bar"
2011-02-27 22:55:22 +01:00
// #i44786#
lcl_ensureName( _rxNewObject, _rName );
::rtl::Reference< OContentHelper > pContent = OContentHelper::getImplementation( _rxNewObject );
if ( pContent.is() )
{
TContentPtr pImpl = pContent->getImpl();
rDefinitions.erase( pImpl );
pImpl->m_aProps.aTitle = _rName;
rDefinitions.insert( _rName, pImpl );
}
}
m_aDocuments.push_back(m_aDocumentMap.insert(Documents::value_type(_rName,_rxNewObject)).first);
notifyDataSourceModified();
// now update our structures
if ( _rxNewObject.is() )
2001-10-30 08:55:07 +00:00
addObjectListener(_rxNewObject);
2000-09-18 23:16:46 +00:00
}
catch(Exception&)
{
2011-02-25 17:47:41 +01:00
OSL_FAIL("ODefinitionContainer::implAppend: caught something !");
2000-09-18 23:16:46 +00:00
}
}
void ODefinitionContainer::implReplace(const OUString& _rName, const Reference< XContent >& _rxNewObject)
2000-09-18 23:16:46 +00:00
{
2011-02-03 00:33:36 +01:00
OSL_ENSURE(checkExistence(_rName), "ODefinitionContainer::implReplace : invalid name !");
2000-09-18 23:16:46 +00:00
Documents::iterator aFind = m_aDocumentMap.find(_rName);
removeObjectListener(aFind->second);
aFind->second = _rxNewObject;
addObjectListener(aFind->second);
}
void ODefinitionContainer::approveNewObject(const OUString& _sName,const Reference< XContent >& _rxObject) const
{
// check the arguments
if ( _sName.isEmpty() )
throw IllegalArgumentException(
DBA_RES( RID_STR_NAME_MUST_NOT_BE_EMPTY ),
*this,
0 );
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
if ( m_bCheckSlash && _sName.indexOf( '/' ) != -1 )
throw IllegalArgumentException(
m_aErrorHelper.getErrorMessage( ErrorCondition::DB_OBJECT_NAME_WITH_SLASHES ),
*this,
0 );
if ( !_rxObject.is() )
throw IllegalArgumentException(
DBA_RES( RID_STR_NO_NULL_OBJECTS_IN_CONTAINER ),
*this,
0 );
const ODefinitionContainer_Impl& rDefinitions( getDefinitions() );
if ( rDefinitions.find( _sName ) != rDefinitions.end() )
throw ElementExistException(
DBA_RES( RID_STR_NAME_ALREADY_USED ),
*this );
::rtl::Reference< OContentHelper > pContent( OContentHelper::getImplementation( _rxObject ) );
if ( !pContent.is() )
throw IllegalArgumentException(
DBA_RES( RID_STR_OBJECT_CONTAINER_MISMATCH ),
*this,
1 );
if ( rDefinitions.find( pContent->getImpl() ) != rDefinitions.end() )
throw ElementExistException(
DBA_RES( RID_STR_OBJECT_ALREADY_CONTAINED ),
*this );
2000-09-18 23:16:46 +00:00
}
// XPropertyChangeListener
void SAL_CALL ODefinitionContainer::propertyChange( const PropertyChangeEvent& evt ) throw (RuntimeException, std::exception)
{
ClearableMutexGuard aGuard(m_aMutex);
if( evt.PropertyName == PROPERTY_NAME || evt.PropertyName == "Title" )
{
m_bInPropertyChange = true;
try
{
OUString sNewName,sOldName;
evt.OldValue >>= sOldName;
evt.NewValue >>= sNewName;
Reference<XContent> xContent( evt.Source, UNO_QUERY );
removeObjectListener( xContent );
implRemove( sOldName );
implAppend( sNewName, xContent );
}
catch(const Exception&)
{
DBG_UNHANDLED_EXCEPTION();
throw RuntimeException();
}
m_bInPropertyChange = false;
}
}
// XVetoableChangeListener
void SAL_CALL ODefinitionContainer::vetoableChange( const PropertyChangeEvent& aEvent ) throw (PropertyVetoException, RuntimeException, std::exception)
{
MutexGuard aGuard(m_aMutex);
if( aEvent.PropertyName == PROPERTY_NAME || aEvent.PropertyName == "Title" )
{
OUString sNewName;
aEvent.NewValue >>= sNewName;
if(hasByName(sNewName))
throw PropertyVetoException();
}
}
void ODefinitionContainer::addObjectListener(const Reference< XContent >& _xNewObject)
2001-10-30 08:55:07 +00:00
{
OSL_ENSURE(_xNewObject.is(),"ODefinitionContainer::addObjectListener: Object is null!");
Reference<XPropertySet> xProp(_xNewObject,UNO_QUERY);
if ( xProp.is() )
{
xProp->addPropertyChangeListener(PROPERTY_NAME, this);
xProp->addVetoableChangeListener(PROPERTY_NAME, this);
2009-11-02 13:23:27 +01:00
}
2001-10-30 08:55:07 +00:00
}
void ODefinitionContainer::removeObjectListener(const Reference< XContent >& _xNewObject)
2001-10-30 08:55:07 +00:00
{
Reference<XPropertySet> xProp(_xNewObject,UNO_QUERY);
if ( xProp.is() )
{
xProp->removePropertyChangeListener(PROPERTY_NAME, this);
xProp->removeVetoableChangeListener(PROPERTY_NAME, this);
}
2001-10-30 08:55:07 +00:00
}
bool ODefinitionContainer::checkExistence(const OUString& _rName)
{
return m_aDocumentMap.find(_rName) != m_aDocumentMap.end();
}
}
// namespace dbaccess
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */