Files
libreoffice/dbaccess/source/core/misc/ContainerMediator.cxx

333 lines
12 KiB
C++
Raw Normal View History

/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2008 by Sun Microsystems, Inc.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: ContainerMediator.cxx,v $
2008-10-01 12:28:29 +00:00
* $Revision: 1.11.42.1 $
*
* 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.
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_dbaccess.hxx"
#ifndef DBA_CONTAINERMEDIATOR_HXX
#include "ContainerMediator.hxx"
#endif
#ifndef DBACCESS_SHARED_DBASTRINGS_HRC
#include "dbastrings.hrc"
#endif
#ifndef DBA_PROPERTYSETFORWARD_HXX
#include "PropertyForward.hxx"
#endif
#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_
#include <com/sun/star/beans/PropertyAttribute.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_
#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_
#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
#endif
#include <com/sun/star/sdbcx/XRename.hpp>
#ifndef _CONNECTIVITY_DBTOOLS_HXX_
#include <connectivity/dbtools.hxx>
#endif
#ifndef _COMPHELPER_PROPERTY_HXX_
#include <comphelper/property.hxx>
#endif
#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif
#ifndef TOOLS_DIAGNOSE_EX_H
#include <tools/diagnose_ex.h>
#endif
//........................................................................
namespace dbaccess
{
//........................................................................
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::sdbcx;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::container;
DBG_NAME(OContainerMediator)
OContainerMediator::OContainerMediator( const Reference< XContainer >& _xContainer, const Reference< XNameAccess >& _xSettings,
const Reference< XConnection >& _rxConnection, ContainerType _eType )
: m_xSettings( _xSettings )
, m_xContainer( _xContainer )
, m_aConnection( _rxConnection )
, m_eType( _eType )
{
DBG_CTOR(OContainerMediator,NULL);
if ( _xSettings.is() && _xContainer.is() )
{
osl_incrementInterlockedCount(&m_refCount);
try
{
m_xContainer->addContainerListener(this);
Reference< XContainer > xContainer(_xSettings, UNO_QUERY);
if ( xContainer.is() )
xContainer->addContainerListener(this);
}
catch(Exception&)
{
OSL_ENSURE(sal_False, "OContainerMediator::OContainerMediator: caught an exception!");
}
osl_decrementInterlockedCount( &m_refCount );
}
else
{
m_xSettings.clear();
m_xContainer.clear();
}
}
// -----------------------------------------------------------------------------
OContainerMediator::~OContainerMediator()
{
DBG_DTOR(OContainerMediator,NULL);
acquire();
impl_cleanup_nothrow();
}
// -----------------------------------------------------------------------------
void OContainerMediator::impl_cleanup_nothrow()
{
try
{
Reference< XContainer > xContainer( m_xSettings, UNO_QUERY );
if ( xContainer.is() )
xContainer->removeContainerListener( this );
m_xSettings.clear();
xContainer = m_xContainer;
if ( xContainer.is() )
xContainer->removeContainerListener( this );
m_xContainer.clear();//WeakReference< XContainer >();
m_aForwardList.clear();
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
}
}
// -----------------------------------------------------------------------------
void SAL_CALL OContainerMediator::elementInserted( const ContainerEvent& _rEvent ) throw(RuntimeException)
{
::osl::MutexGuard aGuard(m_aMutex);
if ( _rEvent.Source == m_xSettings && m_xSettings.is() )
{
::rtl::OUString sElementName;
_rEvent.Accessor >>= sElementName;
PropertyForwardList::iterator aFind = m_aForwardList.find(sElementName);
if ( aFind != m_aForwardList.end() )
{
Reference< XPropertySet> xDest(_rEvent.Element,UNO_QUERY);
aFind->second->setDefinition( xDest );
}
}
}
// -----------------------------------------------------------------------------
void SAL_CALL OContainerMediator::elementRemoved( const ContainerEvent& _rEvent ) throw(RuntimeException)
{
::osl::MutexGuard aGuard(m_aMutex);
Reference< XContainer > xContainer = m_xContainer;
if ( _rEvent.Source == xContainer && xContainer.is() )
{
::rtl::OUString sElementName;
_rEvent.Accessor >>= sElementName;
m_aForwardList.erase(sElementName);
try
{
2008-10-01 12:28:29 +00:00
Reference<XNameContainer> xNameContainer( m_xSettings, UNO_QUERY );
if ( xNameContainer.is() && m_xSettings->hasByName( sElementName ) )
xNameContainer->removeByName( sElementName );
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
}
}
}
// -----------------------------------------------------------------------------
void SAL_CALL OContainerMediator::elementReplaced( const ContainerEvent& _rEvent ) throw(RuntimeException)
{
Reference< XContainer > xContainer = m_xContainer;
if ( _rEvent.Source == xContainer && xContainer.is() )
{
::rtl::OUString sElementName;
_rEvent.ReplacedElement >>= sElementName;
PropertyForwardList::iterator aFind = m_aForwardList.find(sElementName);
if ( aFind != m_aForwardList.end() )
{
::rtl::OUString sNewName;
_rEvent.Accessor >>= sNewName;
try
{
Reference<XNameContainer> xNameContainer( m_xSettings, UNO_QUERY_THROW );
if ( xNameContainer.is() && m_xSettings->hasByName( sElementName ) )
{
Reference<XRename> xSource(m_xSettings->getByName(sElementName),UNO_QUERY_THROW);
xSource->rename(sNewName);
}
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
}
aFind->second->setName(sNewName);
}
}
}
// -----------------------------------------------------------------------------
void SAL_CALL OContainerMediator::disposing( const EventObject& /*Source*/ ) throw(RuntimeException)
{
::osl::MutexGuard aGuard(m_aMutex);
// Reference< XContainer > xContainer = m_xContainer;
// if ( Source.Source == xContainer || Source.Source == m_xSettings )
// this can only be one of them :-) So no check needed here
impl_cleanup_nothrow();
}
// -----------------------------------------------------------------------------
Reference< XPropertySet > OContainerMediator::impl_getSettingsForInitialization_nothrow( const ::rtl::OUString& _rName,
const Reference< XPropertySet >& _rxDestination ) const
{
Reference< XPropertySet > xSettings;
try
{
if ( m_xSettings.is() && m_xSettings->hasByName( _rName ) )
{
OSL_VERIFY( m_xSettings->getByName( _rName ) >>= xSettings );
}
else if ( m_eType == eColumns )
{
do // artifial loop for easier flow control
{
Reference< XConnection > xConnection( m_aConnection );
if ( !xConnection.is() )
break;
Reference< XPropertySetInfo > xPSI( _rxDestination->getPropertySetInfo(), UNO_QUERY_THROW );
if ( !xPSI->hasPropertyByName( PROPERTY_TABLENAME )
|| !xPSI->hasPropertyByName( PROPERTY_REALNAME )
)
break;
// determine the composed table name, plus the column name, as indicated by the
// respective properties at the destination object
::rtl::OUString sCatalog, sSchema, sTable, sColumn;
if ( xPSI->hasPropertyByName( PROPERTY_CATALOGNAME ) )
{
OSL_VERIFY( _rxDestination->getPropertyValue( PROPERTY_CATALOGNAME ) >>= sCatalog );
}
if ( xPSI->hasPropertyByName( PROPERTY_SCHEMANAME ) )
{
OSL_VERIFY( _rxDestination->getPropertyValue( PROPERTY_SCHEMANAME ) >>= sSchema );
}
OSL_VERIFY( _rxDestination->getPropertyValue( PROPERTY_TABLENAME ) >>= sTable );
OSL_VERIFY( _rxDestination->getPropertyValue( PROPERTY_REALNAME ) >>= sColumn );
::rtl::OUString sComposedTableName = ::dbtools::composeTableName(
xConnection->getMetaData(), sCatalog, sSchema, sTable, sal_False, ::dbtools::eComplete );
// retrieve the table in question
Reference< XTablesSupplier > xSuppTables( xConnection, UNO_QUERY_THROW );
Reference< XNameAccess > xTables( xSuppTables->getTables(), UNO_QUERY_THROW );
if ( !xTables->hasByName( sComposedTableName ) )
break;
Reference< XColumnsSupplier > xSuppCols( xTables->getByName( sComposedTableName ), UNO_QUERY_THROW );
Reference< XNameAccess > xColumns( xSuppCols->getColumns(), UNO_QUERY_THROW );
if ( !xColumns->hasByName( sColumn ) )
break;
xSettings.set( xColumns->getByName( sColumn ), UNO_QUERY );
}
while ( false );
}
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
}
return xSettings;
}
// -----------------------------------------------------------------------------
void OContainerMediator::notifyElementCreated(const ::rtl::OUString& _sName,const Reference<XPropertySet>& _xDest)
{
PropertyForwardList::iterator aFind = m_aForwardList.find(_sName);
CWS-TOOLING: integrate CWS dba32f 2009-08-31 10:43:51 +0200 msc r275590 : #no issuezilla available# make the testcase more error proof 2009-08-31 10:43:28 +0200 msc r275589 : #no issuezilla available# make the testcase more error proof 2009-08-31 10:40:33 +0200 msc r275588 : i85993 remove bugid 2009-08-31 10:38:28 +0200 msc r275587 : i100000 2009-08-27 13:27:32 +0200 fs r275476 : #i103882# 2009-08-27 12:47:54 +0200 fs r275474 : #i104544# do not allow re-entrance for impl_ensureControl_nothrow Actually, this is part of the fix only. I also removed the code which triggered this re-entrance (from the grid control implementation), but to ensure it won't happen, again, I added some safety herein. 2009-08-27 12:47:16 +0200 fs r275473 : #i104544# SetState: Do not call Update at the window which we just set text for. It should (sic\!) not be needed, but causes trouble 2009-08-27 10:18:05 +0200 mav r275461 : #i103266# do not allow any stream operation on package streams while commiting the package 2009-08-20 15:25:48 +0200 fs r275184 : #i104362# fall back to a ViewObjectContactOfSdrObj in case we don't have a page view 2009-08-20 15:25:06 +0200 fs r275183 : AUGMENT_LIBRARY_PATH 2009-08-20 15:10:34 +0200 fs r275182 : AUGMENT_LIBRARY_PATH 2009-08-20 09:50:36 +0200 oj r275167 : #i104266# notify propertyforward when new dest was created 2009-08-19 08:01:28 +0200 mav r275133 : #i103266# fix the typo 2009-08-18 22:45:34 +0200 fs r275131 : #i10000# 2009-08-18 13:53:07 +0200 oj r275105 : #i104266# set column settings after alter columns 2009-08-18 13:41:49 +0200 fs r275103 : #i102550# do not interpret names of existing data sources as system path 2009-08-18 13:13:05 +0200 oj r275097 : #i103882# use correct number Format 2009-08-18 12:59:13 +0200 fs r275094 : #i104181# 2009-08-18 09:07:48 +0200 fs r275079 : updated readme to refer to proper 1.1.14 2009-08-18 08:32:31 +0200 oj r275077 : #i104187# wrong default for FirstCellAsLabel corrected 2009-08-18 08:10:00 +0200 oj r275076 : #i104187# dispose status controller to avoid access of dead statusBar in sfx 2009-08-17 21:56:19 +0200 fs r275074 : merge fix for issue #102564# from dba32e 2009-08-17 15:34:40 +0200 fs r275058 : don't set MaxFieldSize to 0 unconditionally 2009-08-17 14:33:57 +0200 oj r275054 : #i103528# patch for bitxtor 2009-08-17 14:12:26 +0200 oj r275051 : #i104160# fix VerticalAlignment 2009-08-17 14:11:47 +0200 oj r275050 : #i104160# fix VerticalAlignment 2009-08-14 15:54:04 +0200 mav r274989 : #i103266# avoid possibility for race condition 2009-08-13 13:52:43 +0200 fs r274939 : improved diagnostics 2009-08-13 13:52:28 +0200 fs r274938 : typo 2009-08-13 12:51:03 +0200 fs r274934 : #i103763# provided by cloph: correct libIDL check when compiling Mozilla 2009-08-13 12:43:23 +0200 fs r274933 : #i103763# provided by cloph: allow to cross-compile prebuilt zips on Mac 2009-08-13 12:41:15 +0200 fs r274932 : #i103371# fire PREPARECLOSEDOC even for embedded objects (why not?) 2009-08-13 12:24:49 +0200 fs r274930 : #i99890# remove 'Insert Control' from the popup menu 2009-08-13 12:23:38 +0200 fs r274929 : #i99890# DoToolboxAction: assert unknown/unimplemented actions 2009-08-13 09:32:07 +0200 fs r274923 : #i103721# 2009-08-13 09:26:32 +0200 fs r274922 : #i99894# provided by dtardon: xforms_nowFunction: use proper memory allocation function 2009-08-13 09:20:21 +0200 fs r274921 : #i103938# provided by cmc: pass proper arguments to OUString::intern 2009-08-12 22:34:28 +0200 fs r274916 : #i104139# when executing a PopupMenu, pass the POPUPMENU_NOMOUSEUPCLOSE flag
2009-09-08 08:54:47 +00:00
if ( (aFind == m_aForwardList.end() || !aFind->second->getDefinition().is() )&& m_xSettings.is() )
{
::std::vector< ::rtl::OUString> aPropertyList;
try
{
// initially copy from the settings object (if existent) to the newly created object
Reference< XPropertySet > xSetting( impl_getSettingsForInitialization_nothrow( _sName, _xDest ) );
if ( xSetting.is() )
::comphelper::copyProperties( xSetting, _xDest );
// collect the to-be-monitored properties
Reference< XPropertySetInfo > xPSI( _xDest->getPropertySetInfo(), UNO_QUERY_THROW );
Sequence< Property > aProperties( xPSI->getProperties() );
const Property* property = aProperties.getConstArray();
const Property* propertyEnd = aProperties.getConstArray() + aProperties.getLength();
for ( ; property != propertyEnd; ++property )
{
if ( ( property->Attributes & PropertyAttribute::READONLY ) != 0 )
continue;
if ( ( property->Attributes & PropertyAttribute::BOUND ) == 0 )
continue;
aPropertyList.push_back( property->Name );
}
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
}
::rtl::Reference< OPropertyForward > pForward( new OPropertyForward( _xDest, m_xSettings, _sName, aPropertyList ) );
CWS-TOOLING: integrate CWS dba32f 2009-08-31 10:43:51 +0200 msc r275590 : #no issuezilla available# make the testcase more error proof 2009-08-31 10:43:28 +0200 msc r275589 : #no issuezilla available# make the testcase more error proof 2009-08-31 10:40:33 +0200 msc r275588 : i85993 remove bugid 2009-08-31 10:38:28 +0200 msc r275587 : i100000 2009-08-27 13:27:32 +0200 fs r275476 : #i103882# 2009-08-27 12:47:54 +0200 fs r275474 : #i104544# do not allow re-entrance for impl_ensureControl_nothrow Actually, this is part of the fix only. I also removed the code which triggered this re-entrance (from the grid control implementation), but to ensure it won't happen, again, I added some safety herein. 2009-08-27 12:47:16 +0200 fs r275473 : #i104544# SetState: Do not call Update at the window which we just set text for. It should (sic\!) not be needed, but causes trouble 2009-08-27 10:18:05 +0200 mav r275461 : #i103266# do not allow any stream operation on package streams while commiting the package 2009-08-20 15:25:48 +0200 fs r275184 : #i104362# fall back to a ViewObjectContactOfSdrObj in case we don't have a page view 2009-08-20 15:25:06 +0200 fs r275183 : AUGMENT_LIBRARY_PATH 2009-08-20 15:10:34 +0200 fs r275182 : AUGMENT_LIBRARY_PATH 2009-08-20 09:50:36 +0200 oj r275167 : #i104266# notify propertyforward when new dest was created 2009-08-19 08:01:28 +0200 mav r275133 : #i103266# fix the typo 2009-08-18 22:45:34 +0200 fs r275131 : #i10000# 2009-08-18 13:53:07 +0200 oj r275105 : #i104266# set column settings after alter columns 2009-08-18 13:41:49 +0200 fs r275103 : #i102550# do not interpret names of existing data sources as system path 2009-08-18 13:13:05 +0200 oj r275097 : #i103882# use correct number Format 2009-08-18 12:59:13 +0200 fs r275094 : #i104181# 2009-08-18 09:07:48 +0200 fs r275079 : updated readme to refer to proper 1.1.14 2009-08-18 08:32:31 +0200 oj r275077 : #i104187# wrong default for FirstCellAsLabel corrected 2009-08-18 08:10:00 +0200 oj r275076 : #i104187# dispose status controller to avoid access of dead statusBar in sfx 2009-08-17 21:56:19 +0200 fs r275074 : merge fix for issue #102564# from dba32e 2009-08-17 15:34:40 +0200 fs r275058 : don't set MaxFieldSize to 0 unconditionally 2009-08-17 14:33:57 +0200 oj r275054 : #i103528# patch for bitxtor 2009-08-17 14:12:26 +0200 oj r275051 : #i104160# fix VerticalAlignment 2009-08-17 14:11:47 +0200 oj r275050 : #i104160# fix VerticalAlignment 2009-08-14 15:54:04 +0200 mav r274989 : #i103266# avoid possibility for race condition 2009-08-13 13:52:43 +0200 fs r274939 : improved diagnostics 2009-08-13 13:52:28 +0200 fs r274938 : typo 2009-08-13 12:51:03 +0200 fs r274934 : #i103763# provided by cloph: correct libIDL check when compiling Mozilla 2009-08-13 12:43:23 +0200 fs r274933 : #i103763# provided by cloph: allow to cross-compile prebuilt zips on Mac 2009-08-13 12:41:15 +0200 fs r274932 : #i103371# fire PREPARECLOSEDOC even for embedded objects (why not?) 2009-08-13 12:24:49 +0200 fs r274930 : #i99890# remove 'Insert Control' from the popup menu 2009-08-13 12:23:38 +0200 fs r274929 : #i99890# DoToolboxAction: assert unknown/unimplemented actions 2009-08-13 09:32:07 +0200 fs r274923 : #i103721# 2009-08-13 09:26:32 +0200 fs r274922 : #i99894# provided by dtardon: xforms_nowFunction: use proper memory allocation function 2009-08-13 09:20:21 +0200 fs r274921 : #i103938# provided by cmc: pass proper arguments to OUString::intern 2009-08-12 22:34:28 +0200 fs r274916 : #i104139# when executing a PopupMenu, pass the POPUPMENU_NOMOUSEUPCLOSE flag
2009-09-08 08:54:47 +00:00
m_aForwardList[_sName] = pForward;
} // if ( aFind == m_aForwardList.end() && m_xSettings.is() )
}
// -----------------------------------------------------------------------------
//........................................................................
} // namespace dbaccess
//........................................................................