diff options
author | Frank Schoenheit [fs] <frank.schoenheit@sun.com> | 2010-02-04 10:38:39 +0100 |
---|---|---|
committer | Frank Schoenheit [fs] <frank.schoenheit@sun.com> | 2010-02-04 10:38:39 +0100 |
commit | 0a88fb0016efcd72134cd12cade01e3b5d8ec397 (patch) | |
tree | 7a8f7179e73fe7402fc277d95e7593684c3cf68f /dbaccess/source/core/dataaccess | |
parent | 37dc6cc75dc3fa9407ee1590a415ca175645d57a (diff) | |
parent | ce662f8d9a756b39911067c75ce234468e5c6a22 (diff) |
autorecovery: commit resolved merge (after rebase to m71)
Diffstat (limited to 'dbaccess/source/core/dataaccess')
18 files changed, 952 insertions, 472 deletions
diff --git a/dbaccess/source/core/dataaccess/ComponentDefinition.cxx b/dbaccess/source/core/dataaccess/ComponentDefinition.cxx index a118a4087..9f3605571 100644 --- a/dbaccess/source/core/dataaccess/ComponentDefinition.cxx +++ b/dbaccess/source/core/dataaccess/ComponentDefinition.cxx @@ -280,14 +280,16 @@ OColumn* OComponentDefinition::createColumn(const ::rtl::OUString& _rName) const if ( aFind != rDefinition.end() ) { aFind->second->addPropertyChangeListener(::rtl::OUString(),m_xColumnPropertyListener.getRef()); - return new OTableColumnWrapper( aFind->second, aFind->second, sal_True ); + return new OTableColumnWrapper( aFind->second, aFind->second, true ); } + OSL_ENSURE( false, "OComponentDefinition::createColumn: is this a valid case?" ); + // This here is the last place creating a OTableColumn, and somehow /me thinks it is not needed ... return new OTableColumn( _rName ); } // ----------------------------------------------------------------------------- Reference< XPropertySet > OComponentDefinition::createColumnDescriptor() { - return new OTableColumnDescriptor(); + return new OTableColumnDescriptor( true ); } // ----------------------------------------------------------------------------- void OComponentDefinition::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue) throw (Exception) @@ -307,7 +309,7 @@ void OComponentDefinition::columnAppended( const Reference< XPropertySet >& _rxS ::rtl::OUString sName; _rxSourceDescriptor->getPropertyValue( PROPERTY_NAME ) >>= sName; - Reference<XPropertySet> xColDesc = new OTableColumnDescriptor(); + Reference<XPropertySet> xColDesc = new OTableColumnDescriptor( true ); ::comphelper::copyProperties( _rxSourceDescriptor, xColDesc ); getDefinition().insert( sName, xColDesc ); diff --git a/dbaccess/source/core/dataaccess/ModelImpl.cxx b/dbaccess/source/core/dataaccess/ModelImpl.cxx index 61fe5d27b..61e43c548 100644 --- a/dbaccess/source/core/dataaccess/ModelImpl.cxx +++ b/dbaccess/source/core/dataaccess/ModelImpl.cxx @@ -546,7 +546,7 @@ void ODatabaseModelImpl::impl_construct_nothrow() Property aProperty( ::rtl::OUString::createFromAscii( pSettings->AsciiName ), -1, - ::getCppuType( static_cast< ::rtl::OUString* >( NULL ) ), + pSettings->ValueType, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT | PropertyAttribute::MAYBEVOID ); xSettingsSet->insert( makeAny( aProperty ) ); @@ -1140,8 +1140,9 @@ const AsciiPropertyValue* ODatabaseModelImpl::getDefaultDataSourceSettings() AsciiPropertyValue( "ParameterNameSubstitution", makeAny( (sal_Bool)sal_False ) ), AsciiPropertyValue( "AddIndexAppendix", makeAny( (sal_Bool)sal_True ) ), AsciiPropertyValue( "IgnoreDriverPrivileges", makeAny( (sal_Bool)sal_True ) ), - AsciiPropertyValue( "ImplicitCatalogRestriction", Any( ) ), - AsciiPropertyValue( "ImplicitSchemaRestriction", Any( ) ), + AsciiPropertyValue( "ImplicitCatalogRestriction", ::cppu::UnoType< ::rtl::OUString >::get() ), + AsciiPropertyValue( "ImplicitSchemaRestriction", ::cppu::UnoType< ::rtl::OUString >::get() ), + AsciiPropertyValue( "PrimaryKeySupport", ::cppu::UnoType< sal_Bool >::get() ), // known SDB level settings AsciiPropertyValue( "NoNameLengthLimit", makeAny( (sal_Bool)sal_False ) ), AsciiPropertyValue( "AppendTableAliasName", makeAny( (sal_Bool)sal_False ) ), @@ -1158,7 +1159,7 @@ const AsciiPropertyValue* ODatabaseModelImpl::getDefaultDataSourceSettings() AsciiPropertyValue( "FormsCheckRequiredFields", makeAny( (sal_Bool)sal_True ) ), AsciiPropertyValue( "EscapeDateTime", makeAny( (sal_Bool)sal_True ) ), - AsciiPropertyValue( NULL, Any() ) + AsciiPropertyValue() }; return aKnownSettings; } diff --git a/dbaccess/source/core/dataaccess/ModelImpl.hxx b/dbaccess/source/core/dataaccess/ModelImpl.hxx index 08adeacb5..654450c56 100644 --- a/dbaccess/source/core/dataaccess/ModelImpl.hxx +++ b/dbaccess/source/core/dataaccess/ModelImpl.hxx @@ -105,13 +105,32 @@ struct AsciiPropertyValue // note: the canonic member order would be AsciiName / DefaultValue, but // this crashes on unxlngi6.pro, since there's a bug which somehow results in // getDefaultDataSourceSettings returning corrupted Any instances then. - ::com::sun::star::uno::Any DefaultValue; - const sal_Char* AsciiName; + ::com::sun::star::uno::Any DefaultValue; + const sal_Char* AsciiName; + const ::com::sun::star::uno::Type& ValueType; + + AsciiPropertyValue() + :DefaultValue( ) + ,AsciiName( NULL ) + ,ValueType( ::cppu::UnoType< ::cppu::UnoVoidType >::get() ) + { + } AsciiPropertyValue( const sal_Char* _pAsciiName, const ::com::sun::star::uno::Any& _rDefaultValue ) :DefaultValue( _rDefaultValue ) ,AsciiName( _pAsciiName ) + ,ValueType( _rDefaultValue.getValueType() ) + { + OSL_ENSURE( ValueType.getTypeClass() != ::com::sun::star::uno::TypeClass_VOID, + "AsciiPropertyValue::AsciiPropertyValue: NULL values not allowed here, use the other CTOR for this!" ); + } + AsciiPropertyValue( const sal_Char* _pAsciiName, const ::com::sun::star::uno::Type& _rValeType ) + :DefaultValue() + ,AsciiName( _pAsciiName ) + ,ValueType( _rValeType ) { + OSL_ENSURE( ValueType.getTypeClass() != ::com::sun::star::uno::TypeClass_VOID, + "AsciiPropertyValue::AsciiPropertyValue: VOID property values not supported!" ); } }; diff --git a/dbaccess/source/core/dataaccess/connection.cxx b/dbaccess/source/core/dataaccess/connection.cxx index 4eded6a82..50fbb2a4f 100644 --- a/dbaccess/source/core/dataaccess/connection.cxx +++ b/dbaccess/source/core/dataaccess/connection.cxx @@ -601,6 +601,17 @@ Reference< XSQLQueryComposer > OConnection::createQueryComposer(void) throw( Ru return xComposer; } // ----------------------------------------------------------------------------- +void OConnection::impl_fillTableFilter() +{ + Reference<XPropertySet> xProp(getParent(),UNO_QUERY); + if ( xProp.is() ) + { + xProp->getPropertyValue(PROPERTY_TABLEFILTER) >>= m_aTableFilter; + xProp->getPropertyValue(PROPERTY_TABLETYPEFILTER) >>= m_aTableTypeFilter; + } +} + +// ----------------------------------------------------------------------------- void OConnection::refresh(const Reference< XNameAccess >& _rToBeRefreshed) { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dataaccess", "Ocke.Janssen@sun.com", "OConnection::refresh" ); @@ -608,6 +619,7 @@ void OConnection::refresh(const Reference< XNameAccess >& _rToBeRefreshed) { if (!m_pTables->isInitialized()) { + impl_fillTableFilter(); // check if our "master connection" can supply tables getMasterTables(); @@ -625,6 +637,7 @@ void OConnection::refresh(const Reference< XNameAccess >& _rToBeRefreshed) { if (!m_pViews->isInitialized()) { + impl_fillTableFilter(); // check if our "master connection" can supply tables Reference< XViewsSupplier > xMaster(getMasterTables(),UNO_QUERY); diff --git a/dbaccess/source/core/dataaccess/connection.hxx b/dbaccess/source/core/dataaccess/connection.hxx index e31674bee..66225cf5a 100644 --- a/dbaccess/source/core/dataaccess/connection.hxx +++ b/dbaccess/source/core/dataaccess/connection.hxx @@ -276,6 +276,10 @@ private: m_xConnectionTools is nol <NULL/> */ void impl_loadConnectionTools_throw(); + + /** reads the table filter and table type filter from the datasourfce + */ + void impl_fillTableFilter(); }; //........................................................................ diff --git a/dbaccess/source/core/dataaccess/databasecontext.cxx b/dbaccess/source/core/dataaccess/databasecontext.cxx index 0d16c12b2..c4e668ffa 100644 --- a/dbaccess/source/core/dataaccess/databasecontext.cxx +++ b/dbaccess/source/core/dataaccess/databasecontext.cxx @@ -36,6 +36,7 @@ #include "core_resource.hxx" #include "databasecontext.hxx" #include "databasedocument.hxx" +#include "databaseregistrations.hxx" #include "datasource.hxx" #include "dbastrings.hrc" #include "module_dba.hxx" @@ -70,7 +71,6 @@ #include <cppuhelper/typeprovider.hxx> #include <cppuhelper/exc_hlp.hxx> #include <svl/filenotation.hxx> -#include <unotools/pathoptions.hxx> #include <tools/debug.hxx> #include <tools/diagnose_ex.h> #include <tools/fsys.hxx> @@ -114,30 +114,6 @@ namespace dbaccess { //........................................................................ - namespace - { - //-------------------------------------------------------------------- - const ::rtl::OUString& getDbRegisteredNamesNodeName() - { - static ::rtl::OUString s_sNodeName = ::rtl::OUString::createFromAscii("org.openoffice.Office.DataAccess/RegisteredNames"); - return s_sNodeName; - } - - //-------------------------------------------------------------------- - const ::rtl::OUString& getDbNameNodeName() - { - static ::rtl::OUString s_sNodeName = ::rtl::OUString::createFromAscii("Name"); - return s_sNodeName; - } - - //-------------------------------------------------------------------- - const ::rtl::OUString& getDbLocationNodeName() - { - static ::rtl::OUString s_sNodeName = ::rtl::OUString::createFromAscii("Location"); - return s_sNodeName; - } - // ----------------------------------------------------------------------------- - } // ............................................................................. typedef ::cppu::WeakImplHelper1 < XTerminateListener > DatabaseDocumentLoader_Base; @@ -224,6 +200,15 @@ ODatabaseContext::ODatabaseContext( const Reference< XComponentContext >& _rxCon { m_pDatabaseDocumentLoader = new DatabaseDocumentLoader( m_aContext ); ::basic::BasicManagerRepository::registerCreationListener( *this ); + + osl_incrementInterlockedCount( &m_refCount ); + { + m_xDBRegistrationAggregate.set( createDataSourceRegistrations( m_aContext ), UNO_SET_THROW ); + m_xDatabaseRegistrations.set( m_xDBRegistrationAggregate, UNO_QUERY_THROW ); + + m_xDBRegistrationAggregate->setDelegator( *this ); + } + osl_decrementInterlockedCount( &m_refCount ); } //-------------------------------------------------------------------------- @@ -232,6 +217,10 @@ ODatabaseContext::~ODatabaseContext() ::basic::BasicManagerRepository::revokeCreationListener( *this ); if ( m_pDatabaseDocumentLoader ) m_pDatabaseDocumentLoader->release(); + + m_xDBRegistrationAggregate->setDelegator( NULL ); + m_xDBRegistrationAggregate.clear(); + m_xDatabaseRegistrations.clear(); } // Helper @@ -327,25 +316,6 @@ void ODatabaseContext::disposing() m_aDatabaseObjects.clear(); } -//------------------------------------------------------------------------------ -bool ODatabaseContext::getURLForRegisteredObject( const ::rtl::OUString& _rRegisteredName, ::rtl::OUString& _rURL ) -{ - if ( !_rRegisteredName.getLength() ) - throw IllegalArgumentException(); - - // the config node where all pooling relevant info are stored under - OConfigurationTreeRoot aDbRegisteredNamesRoot = OConfigurationTreeRoot::createWithServiceFactory( - m_aContext.getLegacyServiceFactory(), getDbRegisteredNamesNodeName(), -1, OConfigurationTreeRoot::CM_READONLY); - if ( aDbRegisteredNamesRoot.isValid() && aDbRegisteredNamesRoot.hasByName( _rRegisteredName ) ) - { - OConfigurationNode aRegisterObj = aDbRegisteredNamesRoot.openNode( _rRegisteredName ); - aRegisterObj.getNodeValue(getDbLocationNodeName()) >>= _rURL; - _rURL = SvtPathOptions().SubstituteVariable( _rURL ); - return true; - } - return false; -} - // XNamingService //------------------------------------------------------------------------------ Reference< XInterface > ODatabaseContext::getRegisteredObject(const rtl::OUString& _rName) throw( Exception, RuntimeException ) @@ -353,9 +323,7 @@ Reference< XInterface > ODatabaseContext::getRegisteredObject(const rtl::OUStri MutexGuard aGuard(m_aMutex); ::connectivity::checkDisposed(DatabaseAccessContext_Base::rBHelper.bDisposed); - ::rtl::OUString sURL; - if ( !getURLForRegisteredObject( _rName, sURL ) ) - throw NoSuchElementException(_rName, *this); + ::rtl::OUString sURL( getDatabaseLocation( _rName ) ); if ( !sURL.getLength() ) // there is a registration for this name, but no URL @@ -493,23 +461,7 @@ void ODatabaseContext::registerObject(const rtl::OUString& _rName, const Referen if ( !sURL.getLength() ) throw IllegalArgumentException( DBACORE_RESSTRING( RID_STR_DATASOURCE_NOT_STORED ), *this, 2 ); - OConfigurationTreeRoot aDbRegisteredNamesRoot = OConfigurationTreeRoot::createWithServiceFactory( - ::comphelper::getProcessServiceFactory(), getDbRegisteredNamesNodeName(), -1, OConfigurationTreeRoot::CM_UPDATABLE); - - if ( aDbRegisteredNamesRoot.isValid() ) - { - OConfigurationNode oDataSourceRegistration; - // the sub-node for the concrete registration - if (aDbRegisteredNamesRoot.hasByName(_rName)) - oDataSourceRegistration = aDbRegisteredNamesRoot.openNode(_rName); - else - oDataSourceRegistration = aDbRegisteredNamesRoot.createNode(_rName); - - // set the values - oDataSourceRegistration.setNodeValue(getDbNameNodeName(), makeAny(_rName)); - oDataSourceRegistration.setNodeValue(getDbLocationNodeName(), makeAny(sURL)); - aDbRegisteredNamesRoot.commit(); - } + registerDatabaseLocation( _rName, sURL ); ODatabaseSource::setName( xDocDataSource, _rName, ODatabaseSource::DBContextAccess() ); @@ -594,22 +546,20 @@ void ODatabaseContext::revokeObject(const rtl::OUString& _rName) throw( Exceptio ClearableMutexGuard aGuard(m_aMutex); ::connectivity::checkDisposed(DatabaseAccessContext_Base::rBHelper.bDisposed); - ::rtl::OUString sURL; - if ( !getURLForRegisteredObject( _rName, sURL ) ) - throw NoSuchElementException( _rName, *this ); + ::rtl::OUString sURL = getDatabaseLocation( _rName ); + + revokeDatabaseLocation( _rName ); + // will throw if something goes wrong if ( m_aDatabaseObjects.find( _rName ) != m_aDatabaseObjects.end() ) { - OSL_ENSURE( false, "ODatabaseContext::revokeObject: a database document register by name? This shouldn't happen anymore!" ); - // all the code should have been changed so that registration is by URL only m_aDatasourceProperties[ sURL ] = m_aDatasourceProperties[ _rName ]; } - OConfigurationTreeRoot aDbRegisteredNamesRoot = OConfigurationTreeRoot::createWithServiceFactory( - ::comphelper::getProcessServiceFactory(), getDbRegisteredNamesNodeName(), -1, OConfigurationTreeRoot::CM_UPDATABLE ); - if ( !aDbRegisteredNamesRoot.removeNode( _rName ) ) - throw Exception( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "An unexpected und unknown error occured." ) ), *this ); - aDbRegisteredNamesRoot.commit(); + // check if URL is already loaded + ObjectCacheIterator aExistent = m_aDatabaseObjects.find( sURL ); + if ( aExistent != m_aDatabaseObjects.end() ) + m_aDatabaseObjects.erase( aExistent ); // notify our container listeners ContainerEvent aEvent( *this, makeAny( _rName ), Any(), Any() ); @@ -617,6 +567,60 @@ void ODatabaseContext::revokeObject(const rtl::OUString& _rName) throw( Exceptio m_aContainerListeners.notifyEach( &XContainerListener::elementRemoved, aEvent ); } +//------------------------------------------------------------------------------ +::sal_Bool SAL_CALL ODatabaseContext::hasRegisteredDatabase( const ::rtl::OUString& _Name ) throw (IllegalArgumentException, RuntimeException) +{ + return m_xDatabaseRegistrations->hasRegisteredDatabase( _Name ); +} + +//------------------------------------------------------------------------------ +Sequence< ::rtl::OUString > SAL_CALL ODatabaseContext::getRegistrationNames() throw (RuntimeException) +{ + return m_xDatabaseRegistrations->getRegistrationNames(); +} + +//------------------------------------------------------------------------------ +::rtl::OUString SAL_CALL ODatabaseContext::getDatabaseLocation( const ::rtl::OUString& _Name ) throw (IllegalArgumentException, NoSuchElementException, RuntimeException) +{ + return m_xDatabaseRegistrations->getDatabaseLocation( _Name ); +} + +//------------------------------------------------------------------------------ +void SAL_CALL ODatabaseContext::registerDatabaseLocation( const ::rtl::OUString& _Name, const ::rtl::OUString& _Location ) throw (IllegalArgumentException, ElementExistException, RuntimeException) +{ + m_xDatabaseRegistrations->registerDatabaseLocation( _Name, _Location ); +} + +//------------------------------------------------------------------------------ +void SAL_CALL ODatabaseContext::revokeDatabaseLocation( const ::rtl::OUString& _Name ) throw (IllegalArgumentException, NoSuchElementException, IllegalAccessException, RuntimeException) +{ + m_xDatabaseRegistrations->revokeDatabaseLocation( _Name ); +} + +//------------------------------------------------------------------------------ +void SAL_CALL ODatabaseContext::changeDatabaseLocation( const ::rtl::OUString& _Name, const ::rtl::OUString& _NewLocation ) throw (IllegalArgumentException, NoSuchElementException, IllegalAccessException, RuntimeException) +{ + m_xDatabaseRegistrations->changeDatabaseLocation( _Name, _NewLocation ); +} + +//------------------------------------------------------------------------------ +::sal_Bool SAL_CALL ODatabaseContext::isDatabaseRegistrationReadOnly( const ::rtl::OUString& _Name ) throw (IllegalArgumentException, NoSuchElementException, RuntimeException) +{ + return m_xDatabaseRegistrations->isDatabaseRegistrationReadOnly( _Name ); +} + +//------------------------------------------------------------------------------ +void SAL_CALL ODatabaseContext::addDatabaseRegistrationsListener( const Reference< XDatabaseRegistrationsListener >& _Listener ) throw (RuntimeException) +{ + m_xDatabaseRegistrations->addDatabaseRegistrationsListener( _Listener ); +} + +//------------------------------------------------------------------------------ +void SAL_CALL ODatabaseContext::removeDatabaseRegistrationsListener( const Reference< XDatabaseRegistrationsListener >& _Listener ) throw (RuntimeException) +{ + m_xDatabaseRegistrations->removeDatabaseRegistrationsListener( _Listener ); +} + // ::com::sun::star::container::XElementAccess //------------------------------------------------------------------------------ Type ODatabaseContext::getElementType( ) throw(RuntimeException) @@ -659,8 +663,9 @@ Any ODatabaseContext::getByName(const rtl::OUString& _rName) throw( NoSuchElemen // see whether this is an registered name ::rtl::OUString sURL; - if ( getURLForRegisteredObject( _rName, sURL ) ) + if ( hasRegisteredDatabase( _rName ) ) { + sURL = getDatabaseLocation( _rName ); // is the object cached under its URL? xExistent = getObject( sURL ); } @@ -687,7 +692,8 @@ Any ODatabaseContext::getByName(const rtl::OUString& _rName) throw( NoSuchElemen } catch (Exception& e) { // exceptions other than the speciafied ones -> wrap - throw WrappedTargetException(_rName, *this, makeAny( e ) ); + Any aError = ::cppu::getCaughtException(); + throw WrappedTargetException(_rName, *this, aError ); } } @@ -697,19 +703,7 @@ Sequence< rtl::OUString > ODatabaseContext::getElementNames(void) throw( Runtime MutexGuard aGuard(m_aMutex); ::connectivity::checkDisposed(DatabaseAccessContext_Base::rBHelper.bDisposed); - DECLARE_STL_USTRINGACCESS_MAP( bool , TNameMap); - TNameMap aRet; - - OConfigurationTreeRoot aDbRegisteredNamesRoot = OConfigurationTreeRoot::createWithServiceFactory( - m_aContext.getLegacyServiceFactory(), getDbRegisteredNamesNodeName(), -1, OConfigurationTreeRoot::CM_READONLY); - - Sequence< ::rtl::OUString> aSeq; - if ( aDbRegisteredNamesRoot.isValid() ) - { - aSeq = aDbRegisteredNamesRoot.getNodeNames(); - } // if ( aDbRegisteredNamesRoot.isValid() ) - - return aSeq; + return getRegistrationNames(); } //------------------------------------------------------------------------------ @@ -718,11 +712,9 @@ sal_Bool ODatabaseContext::hasByName(const rtl::OUString& _rName) throw( Runtime MutexGuard aGuard(m_aMutex); ::connectivity::checkDisposed(DatabaseAccessContext_Base::rBHelper.bDisposed); - OConfigurationTreeRoot aDbRegisteredNamesRoot = OConfigurationTreeRoot::createWithServiceFactory( - m_aContext.getLegacyServiceFactory(), getDbRegisteredNamesNodeName(), -1, OConfigurationTreeRoot::CM_READONLY); - - return aDbRegisteredNamesRoot.isValid() && aDbRegisteredNamesRoot.hasByName(_rName); + return hasRegisteredDatabase( _rName ); } + // ----------------------------------------------------------------------------- Reference< XInterface > ODatabaseContext::getObject( const ::rtl::OUString& _rURL ) { diff --git a/dbaccess/source/core/dataaccess/databasecontext.hxx b/dbaccess/source/core/dataaccess/databasecontext.hxx index 48d455f85..e0d3a39e9 100644 --- a/dbaccess/source/core/dataaccess/databasecontext.hxx +++ b/dbaccess/source/core/dataaccess/databasecontext.hxx @@ -31,57 +31,29 @@ #ifndef _DBA_COREDATAACCESS_DATABASECONTEXT_HXX_ #define _DBA_COREDATAACCESS_DATABASECONTEXT_HXX_ -#ifndef _COM_SUN_STAR_CONTAINER_XENUMERATIONACCESS_HPP_ +#include "ModelImpl.hxx" + +/** === begin UNO includes === **/ +#include <com/sun/star/container/ElementExistException.hpp> +#include <com/sun/star/container/XContainer.hpp> #include <com/sun/star/container/XEnumerationAccess.hpp> -#endif -#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_ +#include <com/sun/star/container/XHierarchicalNameAccess.hpp> #include <com/sun/star/container/XNameAccess.hpp> -#endif -#ifndef _COM_SUN_STAR_UNO_XNAMINGSERVICE_HPP_ -#include <com/sun/star/uno/XNamingService.hpp> -#endif -#ifndef _COM_SUN_STAR_LANG_XUNOTUNNEL_HPP_ -#include <com/sun/star/lang/XUnoTunnel.hpp> -#endif -#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_ +#include <com/sun/star/lang/XEventListener.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> -#endif -#ifndef _COM_SUN_STAR_SDB_XDATABASEENVIRONMENT_HPP_ +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#include <com/sun/star/lang/XUnoTunnel.hpp> #include <com/sun/star/sdb/XDatabaseEnvironment.hpp> -#endif -#ifndef _COM_SUN_STAR_CONTAINER_XHIERARCHICALNAMEACCESS_HPP_ -#include <com/sun/star/container/XHierarchicalNameAccess.hpp> -#endif -#ifndef _COM_SUN_STAR_CONTAINER_XCONTAINER_HPP_ -#include <com/sun/star/container/XContainer.hpp> -#endif -#ifndef _CPPUHELPER_COMPBASE7_HXX_ -#include <cppuhelper/compbase7.hxx> -#endif -#ifndef _COMPHELPER_STLTYPES_HXX_ -#include <comphelper/stl_types.hxx> -#endif -#ifndef COMPHELPER_COMPONENTCONTEXT_HXX +#include <com/sun/star/sdb/XDatabaseRegistrations.hpp> +#include <com/sun/star/uno/XNamingService.hpp> +#include <com/sun/star/uno/XAggregation.hpp> +/** === end UNO includes === **/ + +#include <basic/basicmanagerrepository.hxx> #include <comphelper/componentcontext.hxx> -#endif -#ifndef _CPPUHELPER_INTERFACECONTAINER_HXX_ +#include <comphelper/stl_types.hxx> +#include <cppuhelper/compbase8.hxx> #include <cppuhelper/interfacecontainer.hxx> -#endif -#ifndef _COM_SUN_STAR_CONTAINER_ELEMENTEXISTEXCEPTION_HPP_ -#include <com/sun/star/container/ElementExistException.hpp> -#endif -#ifndef _COM_SUN_STAR_LANG_XEVENTLISTENER_HPP_ -#include <com/sun/star/lang/XEventListener.hpp> -#endif -#ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_ -#include <com/sun/star/lang/XSingleServiceFactory.hpp> -#endif -#ifndef _DBA_COREDATAACCESS_MODELIMPL_HXX_ -#include "ModelImpl.hxx" -#endif -#ifndef BASICMANAGERREPOSITORY_HXX -#include <basic/basicmanagerrepository.hxx> -#endif #include <boost/shared_ptr.hpp> @@ -105,13 +77,14 @@ class DatabaseDocumentLoader; ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > ODatabaseContext_CreateInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&); -typedef ::cppu::WeakComponentImplHelper7 < ::com::sun::star::lang::XServiceInfo +typedef ::cppu::WeakComponentImplHelper8 < ::com::sun::star::lang::XServiceInfo , ::com::sun::star::container::XEnumerationAccess , ::com::sun::star::container::XNameAccess , ::com::sun::star::uno::XNamingService , ::com::sun::star::container::XContainer , ::com::sun::star::lang::XSingleServiceFactory , ::com::sun::star::lang::XUnoTunnel + , ::com::sun::star::sdb::XDatabaseRegistrations > DatabaseAccessContext_Base; class ODatabaseContext :public DatabaseAccessContext_Base @@ -126,12 +99,6 @@ private: ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > loadObjectFromURL(const ::rtl::OUString& _rName,const ::rtl::OUString& _sURL); ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > getObject( const ::rtl::OUString& _rURL ); - /** retrieves the URL for a given registration name, if any - @returns <FALSE/> if and only if there exists a registration for the given name - @throws IllegalArgumentException if the name is empty - */ - bool getURLForRegisteredObject( const ::rtl::OUString& _rRegisteredName, ::rtl::OUString& _rURL ); - /** sets all properties which were transient at the data source. e.g. password @param _sURL The file URL of the data source @param _xObject The data source itself. @@ -147,6 +114,11 @@ protected: ::osl::Mutex m_aMutex; ::comphelper::ComponentContext m_aContext; + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XAggregation > + m_xDBRegistrationAggregate; + ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XDatabaseRegistrations > + m_xDatabaseRegistrations; + DECLARE_STL_USTRINGACCESS_MAP( ODatabaseModelImpl*, ObjectCache ); ObjectCache m_aDatabaseObjects; @@ -166,42 +138,53 @@ public: virtual ~ODatabaseContext(); -// OComponentHelper + // OComponentHelper virtual void SAL_CALL disposing(void); -// ::com::sun::star::lang::XSingleServiceFactory + // XSingleServiceFactory virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstance( ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstanceWithArguments( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& _rArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); -// ::com::sun::star::lang::XServiceInfo + // XServiceInfo virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException); virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) 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::lang::XServiceInfo - static methods + // XServiceInfo - static methods static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_static(void) throw( ::com::sun::star::uno::RuntimeException ); static ::rtl::OUString getImplementationName_static(void) throw( ::com::sun::star::uno::RuntimeException ); static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >&); -// ::com::sun::star::container::XElementAccess + // 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 + // 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::XNameAccess + // 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::uno::XNamingService + // XNamingService virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getRegisteredObject( const ::rtl::OUString& Name ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); virtual void SAL_CALL registerObject( const ::rtl::OUString& Name, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& Object ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); virtual void SAL_CALL revokeObject( const ::rtl::OUString& Name ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); -// ::com::sun::star::container::XContainer + // XDatabaseRegistrations + virtual ::sal_Bool SAL_CALL hasRegisteredDatabase( const ::rtl::OUString& Name ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getRegistrationNames() throw (::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getDatabaseLocation( const ::rtl::OUString& Name ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL registerDatabaseLocation( const ::rtl::OUString& Name, const ::rtl::OUString& Location ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL revokeDatabaseLocation( const ::rtl::OUString& Name ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::IllegalAccessException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL changeDatabaseLocation( const ::rtl::OUString& Name, const ::rtl::OUString& NewLocation ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::IllegalAccessException, ::com::sun::star::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL isDatabaseRegistrationReadOnly( const ::rtl::OUString& Name ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addDatabaseRegistrationsListener( const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XDatabaseRegistrationsListener >& Listener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeDatabaseRegistrationsListener( const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XDatabaseRegistrationsListener >& Listener ) throw (::com::sun::star::uno::RuntimeException); + + // 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); diff --git a/dbaccess/source/core/dataaccess/databasedocument.cxx b/dbaccess/source/core/dataaccess/databasedocument.cxx index 88f822796..ca84bacec 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.cxx +++ b/dbaccess/source/core/dataaccess/databasedocument.cxx @@ -54,10 +54,13 @@ #include <com/sun/star/embed/XTransactionBroadcaster.hpp> #include <com/sun/star/io/XActiveDataSource.hpp> #include <com/sun/star/io/XSeekable.hpp> +#include <com/sun/star/io/XOutputStream.hpp> +#include <com/sun/star/io/XTruncate.hpp> #include <com/sun/star/script/provider/XScriptProviderFactory.hpp> #include <com/sun/star/task/ErrorCodeIOException.hpp> #include <com/sun/star/task/XStatusIndicator.hpp> #include <com/sun/star/task/XStatusIndicatorFactory.hpp> +#include <com/sun/star/ucb/XSimpleFileAccess.hpp> #include <com/sun/star/ui/XUIConfigurationStorage.hpp> #include <com/sun/star/view/XSelectionSupplier.hpp> #include <com/sun/star/xml/sax/XDocumentHandler.hpp> @@ -1067,8 +1070,16 @@ void ODatabaseDocument::impl_storeAs_throw( const ::rtl::OUString& _rURL, const // ----------------------------------------------------------------------------- Reference< XStorage > ODatabaseDocument::impl_createStorageFor_throw( const ::rtl::OUString& _rURL ) const { + Reference < ::com::sun::star::ucb::XSimpleFileAccess > xTempAccess; + m_pImpl->m_aContext.createComponent( ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ,xTempAccess); + Reference< io::XStream > xStream = xTempAccess->openFileReadWrite( _rURL ); + Reference< io::XTruncate > xTruncate(xStream,UNO_QUERY); + if ( xTruncate.is() ) + { + xTruncate->truncate(); + } Sequence<Any> aParam(2); - aParam[0] <<= _rURL; + aParam[0] <<= xStream; aParam[1] <<= ElementModes::READWRITE | ElementModes::TRUNCATE; Reference< XSingleServiceFactory > xStorageFactory( m_pImpl->createStorageFactory(), UNO_SET_THROW ); @@ -1822,8 +1833,7 @@ void SAL_CALL ODatabaseDocument::loadFromStorage( const Reference< XStorage >& / DocumentGuard aGuard( *this ); throw Exception( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Embedding of database documents is not supported." ) ), - // TODO: resource + DBACORE_RESSTRING( RID_STR_NO_EMBEDDING ), *this ); } diff --git a/dbaccess/source/core/dataaccess/databaseregistrations.cxx b/dbaccess/source/core/dataaccess/databaseregistrations.cxx new file mode 100644 index 000000000..8f470c45a --- /dev/null +++ b/dbaccess/source/core/dataaccess/databaseregistrations.cxx @@ -0,0 +1,398 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2009 by Sun Microsystems, Inc. +* +* 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. +************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_dbaccess.hxx" + +/** === begin UNO includes === **/ +#include <com/sun/star/sdb/XDatabaseRegistrations.hpp> +/** === end UNO includes === **/ + +#include <comphelper/componentcontext.hxx> +#include <cppuhelper/basemutex.hxx> +#include <cppuhelper/interfacecontainer.hxx> +#include <cppuhelper/implbase1.hxx> +#include <rtl/ustrbuf.hxx> +#include <unotools/pathoptions.hxx> +#include <tools/urlobj.hxx> +#include <unotools/confignode.hxx> + +//........................................................................ +namespace dbaccess +{ +//........................................................................ + + /** === begin UNO using === **/ + using ::com::sun::star::uno::Reference; + using ::com::sun::star::uno::XInterface; + using ::com::sun::star::uno::UNO_QUERY; + using ::com::sun::star::uno::UNO_QUERY_THROW; + using ::com::sun::star::uno::UNO_SET_THROW; + using ::com::sun::star::uno::Exception; + using ::com::sun::star::uno::RuntimeException; + using ::com::sun::star::uno::Any; + using ::com::sun::star::uno::makeAny; + using ::com::sun::star::uno::Sequence; + using ::com::sun::star::uno::Type; + using ::com::sun::star::container::NoSuchElementException; + using ::com::sun::star::lang::IllegalArgumentException; + using ::com::sun::star::lang::IllegalAccessException; + using ::com::sun::star::container::ElementExistException; + using ::com::sun::star::sdb::XDatabaseRegistrations; + using ::com::sun::star::sdb::XDatabaseRegistrationsListener; + using ::com::sun::star::sdb::DatabaseRegistrationEvent; + using ::com::sun::star::uno::XAggregation; + /** === end UNO using === **/ + + //-------------------------------------------------------------------- + static const ::rtl::OUString& getConfigurationRootPath() + { + static ::rtl::OUString s_sNodeName = ::rtl::OUString::createFromAscii("org.openoffice.Office.DataAccess/RegisteredNames"); + return s_sNodeName; + } + + //-------------------------------------------------------------------- + const ::rtl::OUString& getLocationNodeName() + { + static ::rtl::OUString s_sNodeName = ::rtl::OUString::createFromAscii( "Location" ); + return s_sNodeName; + } + + //-------------------------------------------------------------------- + const ::rtl::OUString& getNameNodeName() + { + static ::rtl::OUString s_sNodeName = ::rtl::OUString::createFromAscii( "Name" ); + return s_sNodeName; + } + + //==================================================================== + //= DatabaseRegistrations - declaration + //==================================================================== + typedef ::cppu::WeakAggImplHelper1 < XDatabaseRegistrations + > DatabaseRegistrations_Base; + class DatabaseRegistrations :public ::cppu::BaseMutex + ,public DatabaseRegistrations_Base + { + public: + DatabaseRegistrations( const ::comphelper::ComponentContext& _rxContext ); + + protected: + ~DatabaseRegistrations(); + + public: + virtual ::sal_Bool SAL_CALL hasRegisteredDatabase( const ::rtl::OUString& _Name ) throw (IllegalArgumentException, RuntimeException); + virtual Sequence< ::rtl::OUString > SAL_CALL getRegistrationNames() throw (RuntimeException); + virtual ::rtl::OUString SAL_CALL getDatabaseLocation( const ::rtl::OUString& _Name ) throw (IllegalArgumentException, NoSuchElementException, RuntimeException); + virtual void SAL_CALL registerDatabaseLocation( const ::rtl::OUString& _Name, const ::rtl::OUString& _Location ) throw (IllegalArgumentException, ElementExistException, RuntimeException); + virtual void SAL_CALL revokeDatabaseLocation( const ::rtl::OUString& _Name ) throw (IllegalArgumentException, NoSuchElementException, IllegalAccessException, RuntimeException); + virtual void SAL_CALL changeDatabaseLocation( const ::rtl::OUString& Name, const ::rtl::OUString& NewLocation ) throw (IllegalArgumentException, NoSuchElementException, IllegalAccessException, RuntimeException); + virtual ::sal_Bool SAL_CALL isDatabaseRegistrationReadOnly( const ::rtl::OUString& _Name ) throw (IllegalArgumentException, NoSuchElementException, RuntimeException); + virtual void SAL_CALL addDatabaseRegistrationsListener( const Reference< XDatabaseRegistrationsListener >& Listener ) throw (RuntimeException); + virtual void SAL_CALL removeDatabaseRegistrationsListener( const Reference< XDatabaseRegistrationsListener >& Listener ) throw (RuntimeException); + + private: + ::utl::OConfigurationNode + impl_checkValidName_throw( const ::rtl::OUString& _rName, const bool _bMustExist ); + + void impl_checkValidLocation_throw( const ::rtl::OUString& _rLocation ); + + /** retrieves the configuration node whose "Name" sub node has the given value + + Since we separated the name of the registration node from the "Name" value of the registration, we cannot + simply do a "getByName" (equivalent) when we want to retrieve the node for a given registration name. + Instead, we must search all nodes. + + If _bMustExist is <TRUE/>, and a node with the given display name does not exist, then a NoSuchElementException + is thrown. + + If _bMustExist is <FALSE/>, and a node with the given name already exists, then a ElementExistException is + thrown. + + In either case, if no exception is thrown, then a valid node is returned: If the node existed and was allowed + to exist, it is returned, if the node did not yet exist, and was required to not exist, a new node is created. + However, in this case the root node is not yet committed. + */ + ::utl::OConfigurationNode + impl_getNodeForName_throw( const ::rtl::OUString& _rName, const bool _bMustExist ); + + ::utl::OConfigurationNode + impl_getNodeForName_nothrow( const ::rtl::OUString& _rName ); + + private: + ::comphelper::ComponentContext m_aContext; + ::utl::OConfigurationTreeRoot m_aConfigurationRoot; + ::cppu::OInterfaceContainerHelper m_aRegistrationListeners; + }; + + //==================================================================== + //= DatabaseRegistrations - implementation + //==================================================================== + //-------------------------------------------------------------------- + DatabaseRegistrations::DatabaseRegistrations( const ::comphelper::ComponentContext& _rxContext ) + :m_aContext( _rxContext ) + ,m_aConfigurationRoot() + ,m_aRegistrationListeners( m_aMutex ) + { + m_aConfigurationRoot = ::utl::OConfigurationTreeRoot::createWithServiceFactory( + m_aContext.getLegacyServiceFactory(), getConfigurationRootPath(), -1, ::utl::OConfigurationTreeRoot::CM_UPDATABLE ); + } + + //-------------------------------------------------------------------- + DatabaseRegistrations::~DatabaseRegistrations() + { + } + + //-------------------------------------------------------------------- + ::utl::OConfigurationNode DatabaseRegistrations::impl_getNodeForName_nothrow( const ::rtl::OUString& _rName ) + { + Sequence< ::rtl::OUString > aNames( m_aConfigurationRoot.getNodeNames() ); + for ( const ::rtl::OUString* pName = aNames.getConstArray(); + pName != aNames.getConstArray() + aNames.getLength(); + ++pName + ) + { + ::utl::OConfigurationNode aNodeForName = m_aConfigurationRoot.openNode( *pName ); + + ::rtl::OUString sTestName; + OSL_VERIFY( aNodeForName.getNodeValue( getNameNodeName() ) >>= sTestName ); + if ( sTestName == _rName ) + return aNodeForName; + } + return ::utl::OConfigurationNode(); + } + + //-------------------------------------------------------------------- + ::utl::OConfigurationNode DatabaseRegistrations::impl_getNodeForName_throw( const ::rtl::OUString& _rName, const bool _bMustExist ) + { + ::utl::OConfigurationNode aNodeForName( impl_getNodeForName_nothrow( _rName ) ); + + if ( aNodeForName.isValid() ) + { + if ( !_bMustExist ) + throw ElementExistException( _rName, *this ); + + return aNodeForName; + } + + if ( _bMustExist ) + throw NoSuchElementException( _rName, *this ); + + ::rtl::OUString sNewNodeName; + { + ::rtl::OUStringBuffer aNewNodeName; + aNewNodeName.appendAscii( "org.openoffice." ); + aNewNodeName.append( _rName ); + + // make unique + ::rtl::OUStringBuffer aReset( aNewNodeName ); + sNewNodeName = aNewNodeName.makeStringAndClear(); + sal_Int32 i=2; + while ( m_aConfigurationRoot.hasByName( sNewNodeName ) ) + { + aNewNodeName = aReset; + aNewNodeName.appendAscii( " " ); + aNewNodeName.append( i ); + sNewNodeName = aNewNodeName.makeStringAndClear(); + } + } + + ::utl::OConfigurationNode aNewNode( m_aConfigurationRoot.createNode( sNewNodeName ) ); + aNewNode.setNodeValue( getNameNodeName(), makeAny( _rName ) ); + return aNewNode; + } + + //-------------------------------------------------------------------- + ::utl::OConfigurationNode DatabaseRegistrations::impl_checkValidName_throw( const ::rtl::OUString& _rName, const bool _bMustExist ) + { + if ( !m_aConfigurationRoot.isValid() ) + throw RuntimeException( ::rtl::OUString(), *this ); + + if ( !_rName.getLength() ) + throw IllegalArgumentException( ::rtl::OUString(), *this, 1 ); + + return impl_getNodeForName_throw( _rName, _bMustExist ); + } + + //-------------------------------------------------------------------- + void DatabaseRegistrations::impl_checkValidLocation_throw( const ::rtl::OUString& _rLocation ) + { + if ( !_rLocation.getLength() ) + throw IllegalArgumentException( ::rtl::OUString(), *this, 2 ); + + INetURLObject aURL( _rLocation ); + if ( aURL.GetProtocol() == INET_PROT_NOT_VALID ) + throw IllegalArgumentException( ::rtl::OUString(), *this, 2 ); + } + + //-------------------------------------------------------------------- + ::sal_Bool SAL_CALL DatabaseRegistrations::hasRegisteredDatabase( const ::rtl::OUString& _Name ) throw (IllegalArgumentException, RuntimeException) + { + ::osl::MutexGuard aGuard( m_aMutex ); + ::utl::OConfigurationNode aNodeForName = impl_getNodeForName_nothrow( _Name ); + return aNodeForName.isValid(); + } + + //------------------------------------------------------------------------------ + Sequence< ::rtl::OUString > SAL_CALL DatabaseRegistrations::getRegistrationNames() throw (RuntimeException) + { + ::osl::MutexGuard aGuard( m_aMutex ); + if ( !m_aConfigurationRoot.isValid() ) + throw RuntimeException( ::rtl::OUString(), *this ); + + Sequence< ::rtl::OUString > aProgrammaticNames( m_aConfigurationRoot.getNodeNames() ); + Sequence< ::rtl::OUString > aDisplayNames( aProgrammaticNames.getLength() ); + ::rtl::OUString* pDisplayName = aDisplayNames.getArray(); + + for ( const ::rtl::OUString* pName = aProgrammaticNames.getConstArray(); + pName != aProgrammaticNames.getConstArray() + aProgrammaticNames.getLength(); + ++pName, ++pDisplayName + ) + { + ::utl::OConfigurationNode aRegistrationNode = m_aConfigurationRoot.openNode( *pName ); + OSL_VERIFY( aRegistrationNode.getNodeValue( getNameNodeName() ) >>= *pDisplayName ); + + } + + return aDisplayNames; + } + + //-------------------------------------------------------------------- + ::rtl::OUString SAL_CALL DatabaseRegistrations::getDatabaseLocation( const ::rtl::OUString& _Name ) throw (IllegalArgumentException, NoSuchElementException, RuntimeException) + { + ::osl::MutexGuard aGuard( m_aMutex ); + + ::utl::OConfigurationNode aNodeForName = impl_checkValidName_throw( _Name, true ); + + ::rtl::OUString sLocation; + OSL_VERIFY( aNodeForName.getNodeValue( getLocationNodeName() ) >>= sLocation ); + sLocation = SvtPathOptions().SubstituteVariable( sLocation ); + + return sLocation; + } + + //-------------------------------------------------------------------- + void SAL_CALL DatabaseRegistrations::registerDatabaseLocation( const ::rtl::OUString& _Name, const ::rtl::OUString& _Location ) throw (IllegalArgumentException, ElementExistException, RuntimeException) + { + ::osl::ClearableMutexGuard aGuard( m_aMutex ); + + // check + impl_checkValidLocation_throw( _Location ); + ::utl::OConfigurationNode aDataSourceRegistration = impl_checkValidName_throw( _Name, false ); + + // register + aDataSourceRegistration.setNodeValue( getLocationNodeName(), makeAny( _Location ) ); + m_aConfigurationRoot.commit(); + + // notify + DatabaseRegistrationEvent aEvent( *this, _Name, ::rtl::OUString(), _Location ); + aGuard.clear(); + m_aRegistrationListeners.notifyEach( &XDatabaseRegistrationsListener::registeredDatabaseLocation, aEvent ); + } + + //-------------------------------------------------------------------- + void SAL_CALL DatabaseRegistrations::revokeDatabaseLocation( const ::rtl::OUString& _Name ) throw (IllegalArgumentException, NoSuchElementException, IllegalAccessException, RuntimeException) + { + ::osl::ClearableMutexGuard aGuard( m_aMutex ); + + // check + ::utl::OConfigurationNode aNodeForName = impl_checkValidName_throw( _Name, true ); + + // obtain properties for notification + ::rtl::OUString sLocation; + OSL_VERIFY( aNodeForName.getNodeValue( getLocationNodeName() ) >>= sLocation ); + + // revoke + if ( aNodeForName.isReadonly() + || !m_aConfigurationRoot.removeNode( aNodeForName.getLocalName() ) + ) + throw IllegalAccessException( ::rtl::OUString(), *this ); + + m_aConfigurationRoot.commit(); + + // notify + DatabaseRegistrationEvent aEvent( *this, _Name, sLocation, ::rtl::OUString() ); + aGuard.clear(); + m_aRegistrationListeners.notifyEach( &XDatabaseRegistrationsListener::revokedDatabaseLocation, aEvent ); + } + + //-------------------------------------------------------------------- + void SAL_CALL DatabaseRegistrations::changeDatabaseLocation( const ::rtl::OUString& _Name, const ::rtl::OUString& _NewLocation ) throw (IllegalArgumentException, NoSuchElementException, IllegalAccessException, RuntimeException) + { + ::osl::ClearableMutexGuard aGuard( m_aMutex ); + + // check + impl_checkValidLocation_throw( _NewLocation ); + ::utl::OConfigurationNode aDataSourceRegistration = impl_checkValidName_throw( _Name, true ); + + if ( aDataSourceRegistration.isReadonly() ) + throw IllegalAccessException( ::rtl::OUString(), *this ); + + // obtain properties for notification + ::rtl::OUString sOldLocation; + OSL_VERIFY( aDataSourceRegistration.getNodeValue( getLocationNodeName() ) >>= sOldLocation ); + + // change + aDataSourceRegistration.setNodeValue( getLocationNodeName(), makeAny( _NewLocation ) ); + m_aConfigurationRoot.commit(); + + // notify + DatabaseRegistrationEvent aEvent( *this, _Name, sOldLocation, _NewLocation ); + aGuard.clear(); + m_aRegistrationListeners.notifyEach( &XDatabaseRegistrationsListener::changedDatabaseLocation, aEvent ); + } + + //-------------------------------------------------------------------- + ::sal_Bool SAL_CALL DatabaseRegistrations::isDatabaseRegistrationReadOnly( const ::rtl::OUString& _Name ) throw (IllegalArgumentException, NoSuchElementException, RuntimeException) + { + ::osl::MutexGuard aGuard( m_aMutex ); + ::utl::OConfigurationNode aDataSourceRegistration = impl_checkValidName_throw( _Name, true ); + return aDataSourceRegistration.isReadonly(); + } + + //-------------------------------------------------------------------- + void SAL_CALL DatabaseRegistrations::addDatabaseRegistrationsListener( const Reference< XDatabaseRegistrationsListener >& _Listener ) throw (RuntimeException) + { + if ( _Listener.is() ) + m_aRegistrationListeners.addInterface( _Listener ); + } + + //-------------------------------------------------------------------- + void SAL_CALL DatabaseRegistrations::removeDatabaseRegistrationsListener( const Reference< XDatabaseRegistrationsListener >& _Listener ) throw (RuntimeException) + { + if ( _Listener.is() ) + m_aRegistrationListeners.removeInterface( _Listener ); + } + + //==================================================================== + //= DatabaseRegistrations - factory + //==================================================================== + Reference< XAggregation > createDataSourceRegistrations( const ::comphelper::ComponentContext& _rxContext ) + { + return new DatabaseRegistrations( _rxContext ); + } + +//........................................................................ +} // namespace dbaccess +//........................................................................ diff --git a/dbaccess/source/core/dataaccess/databaseregistrations.hxx b/dbaccess/source/core/dataaccess/databaseregistrations.hxx new file mode 100644 index 000000000..0c9f39f50 --- /dev/null +++ b/dbaccess/source/core/dataaccess/databaseregistrations.hxx @@ -0,0 +1,50 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2009 by Sun Microsystems, Inc. +* +* 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 OOO_DATASOURCEREGISTRATIONS_HXX +#define OOO_DATASOURCEREGISTRATIONS_HXX + +/** === begin UNO includes === **/ +#include <com/sun/star/uno/XAggregation.hpp> +/** === end UNO includes === **/ + +namespace comphelper +{ + class ComponentContext; +} + +//........................................................................ +namespace dbaccess +{ +//........................................................................ + + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XAggregation > + createDataSourceRegistrations( const ::comphelper::ComponentContext& _rxContext ); + +//........................................................................ +} // namespace dbaccess +//........................................................................ + +#endif // OOO_DATASOURCEREGISTRATIONS_HXX diff --git a/dbaccess/source/core/dataaccess/datasource.cxx b/dbaccess/source/core/dataaccess/datasource.cxx index d823e0bce..aafd89128 100644 --- a/dbaccess/source/core/dataaccess/datasource.cxx +++ b/dbaccess/source/core/dataaccess/datasource.cxx @@ -68,9 +68,9 @@ #include <comphelper/property.hxx> #include <comphelper/seqstream.hxx> #include <comphelper/sequence.hxx> +#include <comphelper/string.hxx> #include <connectivity/dbexception.hxx> #include <cppuhelper/typeprovider.hxx> -#include <rtl/digest.h> #include <tools/debug.hxx> #include <tools/diagnose_ex.h> #include <tools/urlobj.hxx> @@ -78,6 +78,7 @@ #include <unotools/confignode.hxx> #include <unotools/sharedunocomponent.hxx> #include <rtl/logfile.hxx> +#include <rtl/digest.h> #include <algorithm> using namespace ::com::sun::star::sdbc; @@ -782,8 +783,6 @@ Reference< XConnection > ODatabaseSource::buildLowLevelConnection(const ::rtl::O m_pImpl->getDefaultDataSourceSettings() ); - impl_insertJavaDriverClassPath_nothrow(aDriverInfo); - if ( m_pImpl->isEmbeddedDatabase() ) { sal_Int32 nCount = aDriverInfo.getLength(); @@ -817,9 +816,8 @@ Reference< XConnection > ODatabaseSource::buildLowLevelConnection(const ::rtl::O ::rtl::OUString sMessage = DBACORE_RESSTRING( nExceptionMessageId ); SQLContext aContext; - aContext.Message = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "A connection for the following URL was requested: " ) ); - // TODO: resource - aContext.Message += m_pImpl->m_sConnectURL; + aContext.Message = DBACORE_RESSTRING( RID_STR_CONNECTION_REQUEST ); + ::comphelper::string::searchAndReplaceAsciiI( aContext.Message, "$name$", m_pImpl->m_sConnectURL ); throwGenericSQLException( sMessage, static_cast< XDataSource* >( this ), makeAny( aContext ) ); } @@ -1485,29 +1483,6 @@ Reference< XInterface > ODatabaseSource::getThis() const return *const_cast< ODatabaseSource* >( this ); } // ----------------------------------------------------------------------------- -void ODatabaseSource::impl_insertJavaDriverClassPath_nothrow(Sequence< PropertyValue >& _rDriverInfo) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dataaccess", "Ocke.Janssen@sun.com", "ODatabaseSource::impl_insertJavaDriverClassPath_nothrow" ); - Reference< XPropertySet > xPropertySet( m_pImpl->m_xSettings, UNO_QUERY_THROW ); - ::rtl::OUString sJavaDriverClass; - xPropertySet->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JavaDriverClass"))) >>= sJavaDriverClass; - if ( sJavaDriverClass.getLength() ) - { - static const ::rtl::OUString s_sNodeName(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Office.DataAccess/JDBC/DriverClassPaths")); - ::utl::OConfigurationTreeRoot aNamesRoot = ::utl::OConfigurationTreeRoot::createWithServiceFactory( - m_pImpl->m_aContext.getLegacyServiceFactory(), s_sNodeName, -1, ::utl::OConfigurationTreeRoot::CM_READONLY); - if ( aNamesRoot.isValid() && aNamesRoot.hasByName( sJavaDriverClass ) ) - { - ::utl::OConfigurationNode aRegisterObj = aNamesRoot.openNode( sJavaDriverClass ); - ::rtl::OUString sURL; - OSL_VERIFY( aRegisterObj.getNodeValue( "Path" ) >>= sURL ); - - ::comphelper::NamedValueCollection aDriverSettings( _rDriverInfo ); - aDriverSettings.put( "JavaDriverClassPath", sURL ); - aDriverSettings >>= _rDriverInfo; - } - } -} //........................................................................ } // namespace dbaccess //........................................................................ diff --git a/dbaccess/source/core/dataaccess/datasource.hxx b/dbaccess/source/core/dataaccess/datasource.hxx index 6ee12253a..e6fb11576 100644 --- a/dbaccess/source/core/dataaccess/datasource.hxx +++ b/dbaccess/source/core/dataaccess/datasource.hxx @@ -295,8 +295,6 @@ private: void clearConnections(); - void impl_insertJavaDriverClassPath_nothrow(::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rDriverInfo); - protected: using ::cppu::OPropertySetHelper::getFastPropertyValue; }; diff --git a/dbaccess/source/core/dataaccess/definitioncontainer.cxx b/dbaccess/source/core/dataaccess/definitioncontainer.cxx index 808178015..87de5935d 100644 --- a/dbaccess/source/core/dataaccess/definitioncontainer.cxx +++ b/dbaccess/source/core/dataaccess/definitioncontainer.cxx @@ -727,23 +727,16 @@ void ODefinitionContainer::addObjectListener(const Reference< XContent >& _xNewO { xProp->addPropertyChangeListener(PROPERTY_NAME, this); xProp->addVetoableChangeListener(PROPERTY_NAME, this); - //::rtl::OUString sTitle(RTL_CONSTASCII_USTRINGPARAM( "Title" )); - //xProp->addPropertyChangeListener(sTitle, this); - //xProp->addVetoableChangeListener(sTitle, this); - } // if ( xProp.is() ) + } } // ----------------------------------------------------------------------------- void ODefinitionContainer::removeObjectListener(const Reference< XContent >& _xNewObject) { - OSL_ENSURE(_xNewObject.is(),"ODefinitionContainer::addObjectListener: Object is null!"); Reference<XPropertySet> xProp(_xNewObject,UNO_QUERY); if ( xProp.is() ) { xProp->removePropertyChangeListener(PROPERTY_NAME, this); xProp->removeVetoableChangeListener(PROPERTY_NAME, this); - //::rtl::OUString sTitle(RTL_CONSTASCII_USTRINGPARAM( "Title" )); - //xProp->removePropertyChangeListener(sTitle, this); - //xProp->removeVetoableChangeListener(sTitle, this); } } // ----------------------------------------------------------------------------- diff --git a/dbaccess/source/core/dataaccess/documentcontainer.cxx b/dbaccess/source/core/dataaccess/documentcontainer.cxx index 7846afdba..92d00f5d9 100644 --- a/dbaccess/source/core/dataaccess/documentcontainer.cxx +++ b/dbaccess/source/core/dataaccess/documentcontainer.cxx @@ -89,6 +89,7 @@ #include <vcl/svapp.hxx> #include <vos/mutex.hxx> +#include <comphelper/namedvaluecollection.hxx> using namespace ::com::sun::star::uno; using namespace ::com::sun::star::lang; @@ -229,7 +230,7 @@ Reference< XInterface > SAL_CALL ODocumentContainer::createInstanceWithArguments MutexGuard aGuard(m_aMutex); // extrat known arguments - ::rtl::OUString sName, sPersistentName, sURL; + ::rtl::OUString sName, sPersistentName, sURL, sMediaType; Reference< XCommandProcessor > xCopyFrom; Reference< XConnection > xConnection; sal_Bool bAsTemplate; @@ -242,6 +243,7 @@ Reference< XInterface > SAL_CALL ODocumentContainer::createInstanceWithArguments lcl_extractAndRemove( aArgs, PROPERTY_EMBEDDEDOBJECT, xCopyFrom ); lcl_extractAndRemove( aArgs, PROPERTY_ACTIVE_CONNECTION, xConnection ); lcl_extractAndRemove( aArgs, PROPERTY_AS_TEMPLATE, bAsTemplate ); + lcl_extractAndRemove( aArgs, INFO_MEDIATYPE, sMediaType ); // ClassID has two allowed types, so a special treatment here Any aClassIDArg = aArgs.get( "ClassID" ); @@ -278,6 +280,7 @@ Reference< XInterface > SAL_CALL ODocumentContainer::createInstanceWithArguments if ( xElements.is() ) sPersistentName = ::dbtools::createUniqueName(xElements,sPersistentName); + const bool bNeedClassID = ( aClassID.getLength() == 0 ) && ( 0 == sURL.getLength() ); if ( xCopyFrom.is() ) { Sequence<Any> aIni(2); @@ -291,10 +294,16 @@ Reference< XInterface > SAL_CALL ODocumentContainer::createInstanceWithArguments Reference<XPropertySet> xProp(xCopyFrom,UNO_QUERY); if ( xProp.is() && xProp->getPropertySetInfo().is() && xProp->getPropertySetInfo()->hasPropertyByName(PROPERTY_AS_TEMPLATE) ) xProp->getPropertyValue(PROPERTY_AS_TEMPLATE) >>= bAsTemplate; - } - if ( ( aClassID.getLength() == 0 ) && ( 0 == sURL.getLength() ) ) - ODocumentDefinition::GetDocumentServiceFromMediaType( getContainerStorage(), sPersistentName, m_aContext, aClassID ); + // if we do not have an own class ID, see if we can determine one from the copy we just created + if ( bNeedClassID ) + ODocumentDefinition::GetDocumentServiceFromMediaType( getContainerStorage(), sPersistentName, m_aContext, aClassID ); + } + else + { + if ( bNeedClassID && sMediaType.getLength() ) + ODocumentDefinition::GetDocumentServiceFromMediaType( sMediaType, m_aContext, aClassID ); + } } ODefinitionContainer_Impl::const_iterator aFind = rDefinitions.find( sName ); @@ -405,9 +414,12 @@ Reference< XInterface > SAL_CALL ODocumentContainer::createInstanceWithArguments ::rtl::OUString sServiceName; if ( Reference< XNameAccess >( xObjectToCopy, UNO_QUERY ).is() ) + { if ( m_bFormsContainer ) sServiceName = SERVICE_NAME_FORM_COLLECTION; - else sServiceName = SERVICE_NAME_REPORT_COLLECTION; + else + sServiceName = SERVICE_NAME_REPORT_COLLECTION; + } else sServiceName = SERVICE_SDB_DOCUMENTDEFINITION; @@ -528,7 +540,7 @@ namespace if ( bRet ) { _rRet = _xNameContainer->getByName(_sSimpleName = sName); - while ( nIndex != -1 ) + while ( nIndex != -1 && bRet ) { sName = _sName.getToken(0,'/',nIndex); _xNameContainer.set(_rRet,UNO_QUERY); @@ -542,8 +554,10 @@ namespace } } } - else if ( nIndex == -1 ) - _sSimpleName = sName; // a content on the root content + if ( nIndex == -1 ) + _sSimpleName = sName; // a content + else + _xNameContainer.clear(); // a sub folder doesn't exist return bRet; } } @@ -565,7 +579,6 @@ Reference< XComponent > SAL_CALL ODocumentContainer::loadComponentFromURL( const if ( !lcl_queryContent(_sURL,xNameContainer,aContent,sName) ) { ::rtl::OUString sMessage( DBA_RES( RID_STR_NAME_NOT_FOUND ) ); - // TODO: resource ::comphelper::string::searchAndReplaceAsciiI( sMessage, "$name$", _sURL ); throw IllegalArgumentException( sMessage, *this, 1 ); } @@ -622,15 +635,24 @@ sal_Bool SAL_CALL ODocumentContainer::hasByHierarchicalName( const ::rtl::OUStri // XHierarchicalNameContainer void SAL_CALL ODocumentContainer::insertByHierarchicalName( const ::rtl::OUString& _sName, const Any& _aElement ) throw (IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException) { + Reference< XContent > xContent(_aElement,UNO_QUERY); + if ( !xContent.is() ) + throw IllegalArgumentException(); + ClearableMutexGuard aGuard(m_aMutex); Any aContent; Reference< XNameContainer > xNameContainer(this); ::rtl::OUString sName; if ( lcl_queryContent(_sName,xNameContainer,aContent,sName) ) throw ElementExistException(_sName,*this); - Reference< XContent > xContent(_aElement,UNO_QUERY); - if ( !xContent.is() ) - throw IllegalArgumentException(); + + if ( !xNameContainer.is() ) + { + ::rtl::OUString sMessage( DBA_RES( RID_STR_NO_SUB_FOLDER ) ); + sal_Int32 index = sName.getLength(); + ::comphelper::string::searchAndReplaceAsciiI( sMessage, "$folder$", _sName.getToken(0,'/',index) ); + throw IllegalArgumentException( sMessage, *this, 1 ); + } xNameContainer->insertByName(sName,_aElement); } diff --git a/dbaccess/source/core/dataaccess/documentdefinition.cxx b/dbaccess/source/core/dataaccess/documentdefinition.cxx index 10b2d49fb..171eaa9a3 100644 --- a/dbaccess/source/core/dataaccess/documentdefinition.cxx +++ b/dbaccess/source/core/dataaccess/documentdefinition.cxx @@ -457,7 +457,7 @@ namespace dbaccess //================================================================== typedef ::cppu::WeakImplHelper1 < css::lang::XEventListener > LifetimeCoupler_Base; - /** helper class which couples the lifetime of a component to the lifetim + /** helper class which couples the lifetime of a component to the lifetime of another component Instances of this class are constructed with two components. The first is @@ -657,13 +657,12 @@ void SAL_CALL ODocumentDefinition::disposing() ::osl::MutexGuard aGuard(m_aMutex); closeObject(); ::comphelper::disposeComponent(m_xListener); - if ( m_bRemoveListener && m_xDesktop.is() ) + if ( m_bRemoveListener ) { Reference<util::XCloseable> xCloseable(m_pImpl->m_pDataSource->getModel_noCreate(),UNO_QUERY); if ( xCloseable.is() ) xCloseable->removeCloseListener(this); } - m_xDesktop = NULL; } // ----------------------------------------------------------------------------- IMPLEMENT_TYPEPROVIDER3(ODocumentDefinition,OContentHelper,OPropertyStateContainer,ODocumentDefinition_Base); @@ -766,17 +765,15 @@ namespace } // ----------------------------------------------------------------------------- -void ODocumentDefinition::impl_removeFrameFromDesktop_throw( const Reference< XFrame >& _rxFrame ) +void ODocumentDefinition::impl_removeFrameFromDesktop_throw( const ::comphelper::ComponentContext& _rContxt, const Reference< XFrame >& _rxFrame ) { - if ( !m_xDesktop.is() ) - m_xDesktop.set( m_aContext.createComponent( (::rtl::OUString)SERVICE_FRAME_DESKTOP ), UNO_QUERY_THROW ); - - Reference< XFrames > xFrames( m_xDesktop->getFrames(), UNO_QUERY_THROW ); + Reference< XFramesSupplier > xDesktop( _rContxt.createComponent( (::rtl::OUString)SERVICE_FRAME_DESKTOP ), UNO_QUERY_THROW ); + Reference< XFrames > xFrames( xDesktop->getFrames(), UNO_QUERY_THROW ); xFrames->remove( _rxFrame ); } // ----------------------------------------------------------------------------- -void ODocumentDefinition::impl_onActivateEmbeddedObject( const bool i_bReactivated ) +void ODocumentDefinition::impl_onActivateEmbeddedObject_nothrow( const bool i_bReactivated ) { try { @@ -788,26 +785,23 @@ void ODocumentDefinition::impl_onActivateEmbeddedObject( const bool i_bReactivat if ( !m_xListener.is() ) // it's the first time the embedded object has been activated // create an OEmbedObjectHolder - m_xListener = new OEmbedObjectHolder(m_xEmbeddedObject,this); + m_xListener = new OEmbedObjectHolder( m_xEmbeddedObject, this ); - Reference< XFrame > xFrame( xController->getFrame() ); - if ( xFrame.is() ) - { - // raise the window to top (especially necessary if this is not the first activation) - Reference< XTopWindow > xTopWindow( xFrame->getContainerWindow(), UNO_QUERY_THROW ); - xTopWindow->toFront(); + // raise the window to top (especially necessary if this is not the first activation) + Reference< XFrame > xFrame( xController->getFrame(), UNO_SET_THROW ); + Reference< XTopWindow > xTopWindow( xFrame->getContainerWindow(), UNO_QUERY_THROW ); + xTopWindow->toFront(); - // remove the frame from the desktop's frame collection because we need full control of it. - impl_removeFrameFromDesktop_throw( xFrame ); - } + // remove the frame from the desktop's frame collection because we need full control of it. + impl_removeFrameFromDesktop_throw( m_aContext, xFrame ); // ensure that we ourself are kept alive as long as the embedded object's frame is // opened LifetimeCoupler::couple( *this, Reference< XComponent >( xFrame, UNO_QUERY_THROW ) ); // init the edit view - if ( m_bOpenInDesign && !i_bReactivated ) - impl_initObjectEditView( xController ); + if ( m_bForm && m_bOpenInDesign && !i_bReactivated ) + impl_initFormEditView( xController ); } catch( const RuntimeException& ) { @@ -909,12 +903,8 @@ namespace } // ----------------------------------------------------------------------------- -void ODocumentDefinition::impl_initObjectEditView( const Reference< XController >& _rxController ) +void ODocumentDefinition::impl_initFormEditView( const Reference< XController >& _rxController ) { - if ( !m_bForm ) - // currently, only forms need to be initialized - return; - try { Reference< XViewSettingsSupplier > xSettingsSupplier( _rxController, UNO_QUERY_THROW ); @@ -981,10 +971,10 @@ void ODocumentDefinition::impl_showOrHideComponent_throw( const bool i_bShow ) } // ----------------------------------------------------------------------------- -void ODocumentDefinition::onCommandOpenSomething( const Any& _rOpenArgument, const bool _bActivate, - const Reference< XCommandEnvironment >& _rxEnvironment, Any& _out_rComponent, ::osl::ClearableMutexGuard & _aGuard ) +Any ODocumentDefinition::onCommandOpenSomething( const Any& _rOpenArgument, const bool _bActivate, + const Reference< XCommandEnvironment >& _rxEnvironment ) { - OExecuteImpl aExecuteGuard(m_bInExecute); + OExecuteImpl aExecuteGuard( m_bInExecute ); Reference< XConnection > xConnection; sal_Int32 nOpenMode = OpenMode::DOCUMENT; @@ -994,7 +984,9 @@ void ODocumentDefinition::onCommandOpenSomething( const Any& _rOpenArgument, con // for the document, default to the interaction handler as used for loading the DB doc // This might be overwritten below, when examining _rOpenArgument. const ::comphelper::NamedValueCollection& aDBDocArgs( m_pImpl->m_pDataSource->getMediaDescriptor() ); - aDocumentArgs.put( "InteractionHandler", aDBDocArgs.getOrDefault( "InteractionHandler", Reference< XInteractionHandler >() ) ); + Reference< XInteractionHandler > xHandler( aDBDocArgs.getOrDefault( "InteractionHandler", Reference< XInteractionHandler >() ) ); + if ( xHandler.is() ) + aDocumentArgs.put( "InteractionHandler", xHandler ); ::boost::optional< sal_Int16 > aDocumentMacroMode; @@ -1108,7 +1100,7 @@ void ODocumentDefinition::onCommandOpenSomething( const Any& _rOpenArgument, con OSL_ENSURE( m_pImpl->m_aProps.sPersistentName.getLength(), "ODocumentDefinition::onCommandOpenSomething: no persistent name - cannot load!" ); if ( !m_pImpl->m_aProps.sPersistentName.getLength() ) - return; + return Any(); // embedded objects themself do not support the hidden flag. We implement support for // it by changing the STATE to RUNNING only, instead of ACTIVE. @@ -1118,7 +1110,7 @@ void ODocumentDefinition::onCommandOpenSomething( const Any& _rOpenArgument, con loadEmbeddedObject( xConnection, Sequence< sal_Int8 >(), aDocumentArgs.getPropertyValues(), false, !m_bOpenInDesign ); OSL_ENSURE( m_xEmbeddedObject.is(), "ODocumentDefinition::onCommandOpenSomething: what's this?" ); if ( !m_xEmbeddedObject.is() ) - return; + return Any(); Reference< XModel > xModel( getComponent(), UNO_QUERY ); Reference< report::XReportDefinition > xReportDefinition(xModel,UNO_QUERY); @@ -1144,157 +1136,171 @@ void ODocumentDefinition::onCommandOpenSomething( const Any& _rOpenArgument, con xReportEngine->setReportDefinition(xReportDefinition); xReportEngine->setActiveConnection(m_xLastKnownConnection); if ( bOpenHidden ) - _out_rComponent <<= xReportEngine->createDocumentModel( ); - else - _out_rComponent <<= xReportEngine->createDocumentAlive(NULL); - return; + return makeAny( xReportEngine->createDocumentModel() ); + return makeAny( xReportEngine->createDocumentAlive( NULL ) ); } if ( _bActivate && !bOpenHidden ) { LockModifiable aLockModify( impl_getComponent_throw() ); m_xEmbeddedObject->changeState( EmbedStates::ACTIVE ); - impl_onActivateEmbeddedObject( false ); + ODocumentDefinition::impl_onActivateEmbeddedObject_nothrow( false ); } - // LLA: Alle fillReportData() calls prfen, sollte es welche geben, die danach noch viel machen - // LLA: sollten wir einen _aGuard Pointer bergeben, sonst erstmal als Referenz - fillReportData(_aGuard); - _out_rComponent <<= xModel; + if ( !m_bForm && m_pImpl->m_aProps.bAsTemplate && !m_bOpenInDesign ) + ODocumentDefinition::fillReportData( m_aContext, getComponent(), xConnection ); + + return makeAny( xModel ); } // ----------------------------------------------------------------------------- Any SAL_CALL ODocumentDefinition::execute( const Command& aCommand, sal_Int32 CommandId, const Reference< XCommandEnvironment >& Environment ) throw (Exception, CommandAbortedException, RuntimeException) { Any aRet; - ::osl::ClearableMutexGuard aGuard(m_aMutex); - if ( !m_bInExecute ) - { - sal_Bool bOpen = aCommand.Name.equalsAscii( "open" ); - sal_Bool bOpenInDesign = aCommand.Name.equalsAscii( "openDesign" ); - sal_Bool bOpenForMail = aCommand.Name.equalsAscii( "openForMail" ); - if ( bOpen || bOpenInDesign || bOpenForMail ) + + sal_Bool bOpen = aCommand.Name.equalsAscii( "open" ); + sal_Bool bOpenInDesign = aCommand.Name.equalsAscii( "openDesign" ); + sal_Bool bOpenForMail = aCommand.Name.equalsAscii( "openForMail" ); + if ( bOpen || bOpenInDesign || bOpenForMail ) + { + // opening the document involves a lot of VCL code, which is not thread-safe, but needs the SolarMutex locked. + // Unfortunately, the DocumentDefinition, as well as the EmbeddedObject implementation, calls into VCL-dependent + // components *without* releasing the own mutex, which is a guaranteed recipe for deadlocks. + // We have control over this implementation here, and in modifying it to release the own mutex before calling into + // the VCL-dependent components is not too difficult (was there, seen it). + // However, we do /not/ have control over the EmbeddedObject implementation, and from a first look, it seems as + // making it release the own mutex before calling SolarMutex-code is ... difficult, at least. + // So, to be on the same side, we lock the SolarMutex here. Yes, it sucks. + ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + ::osl::ClearableMutexGuard aGuard(m_aMutex); + if ( m_bInExecute ) + return aRet; + + bool bActivateObject = true; + if ( bOpenForMail ) { - bool bActivateObject = true; - if ( bOpenForMail ) - { - OSL_ENSURE( false, "ODocumentDefinition::execute: 'openForMail' should not be used anymore - use the 'Hidden' parameter instead!" ); - bActivateObject = false; - } + OSL_ENSURE( false, "ODocumentDefinition::execute: 'openForMail' should not be used anymore - use the 'Hidden' parameter instead!" ); + bActivateObject = false; + } - // if the object is already opened, do nothing - // #i89509# / 2008-05-22 / frank.schoenheit@sun.com - if ( m_xEmbeddedObject.is() ) + // if the object is already opened, do nothing + // #i89509# / 2008-05-22 / frank.schoenheit@sun.com + if ( m_xEmbeddedObject.is() ) + { + sal_Int32 nCurrentState = m_xEmbeddedObject->getCurrentState(); + bool bIsActive = ( nCurrentState == EmbedStates::ACTIVE ); + + if ( bIsActive ) { - sal_Int32 nCurrentState = m_xEmbeddedObject->getCurrentState(); - bool bIsActive = ( nCurrentState == EmbedStates::ACTIVE ); + // exception: new-style reports always create a new document when "open" is executed + Reference< report::XReportDefinition > xReportDefinition( impl_getComponent_throw( false ), UNO_QUERY ); + bool bIsAliveNewStyleReport = ( xReportDefinition.is() && ( bOpen || bOpenForMail ) ); - if ( bIsActive ) + if ( !bIsAliveNewStyleReport ) { - // exception: new-style reports always create a new document when "open" is executed - Reference< report::XReportDefinition > xReportDefinition( impl_getComponent_throw( false ), UNO_QUERY ); - bool bIsAliveNewStyleReport = ( xReportDefinition.is() && ( bOpen || bOpenForMail ) ); - - if ( !bIsAliveNewStyleReport ) - { - impl_onActivateEmbeddedObject( true ); - return makeAny( getComponent() ); - } + impl_onActivateEmbeddedObject( true ); + return makeAny( getComponent() ); } } - - m_bOpenInDesign = bOpenInDesign || bOpenForMail; - onCommandOpenSomething( aCommand.Argument, bActivateObject, Environment, aRet, aGuard ); - } - else if ( aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "show" ) ) ) - { - impl_showOrHideComponent_throw( true ); - } - else if ( aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "hide" ) ) ) - { - impl_showOrHideComponent_throw( false ); - } - else if ( aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "copyTo" ) ) ) - { - Sequence<Any> aIni; - aCommand.Argument >>= aIni; - if ( aIni.getLength() != 2 ) - { - OSL_ENSURE( sal_False, "Wrong argument type!" ); - ucbhelper::cancelCommandExecution( - makeAny( IllegalArgumentException( - rtl::OUString(), - static_cast< cppu::OWeakObject * >( this ), - -1 ) ), - Environment ); - // Unreachable - } - Reference< XStorage> xDest(aIni[0],UNO_QUERY); - ::rtl::OUString sPersistentName; - aIni[1] >>= sPersistentName; - Reference< XStorage> xStorage = getContainerStorage(); - // ----------------------------------------------------------------------------- - xStorage->copyElementTo(m_pImpl->m_aProps.sPersistentName,xDest,sPersistentName); - } - else if ( aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "preview" ) ) ) - { - onCommandPreview(aRet); } - else if ( aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "insert" ) ) ) - { - Sequence<Any> aIni; - aCommand.Argument >>= aIni; - if ( aIni.getLength() > 0 && aIni.getLength() < 2 ) - { - OSL_ENSURE( sal_False, "Wrong argument type!" ); - ucbhelper::cancelCommandExecution( - makeAny( IllegalArgumentException( - rtl::OUString(), - static_cast< cppu::OWeakObject * >( this ), - -1 ) ), - Environment ); - // Unreachable - } - ::rtl::OUString sURL; - aIni[0] >>= sURL; - onCommandInsert( sURL, Environment ); - } - else if ( aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "getdocumentinfo" ) ) // compatibility - || aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "getDocumentInfo" ) ) - ) - { - onCommandGetDocumentProperties( aRet ); - } - else if ( aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "delete" ) ) ) - { - ////////////////////////////////////////////////////////////////// - // delete - ////////////////////////////////////////////////////////////////// - closeObject(); - Reference< XStorage> xStorage = getContainerStorage(); - if ( xStorage.is() ) - xStorage->removeElement(m_pImpl->m_aProps.sPersistentName); - dispose(); + m_bOpenInDesign = bOpenInDesign || bOpenForMail; + return onCommandOpenSomething( aCommand.Argument, bActivateObject, Environment ); + } - } - else if ( ( aCommand.Name.compareToAscii( "storeOwn" ) == 0 ) // compatibility - || ( aCommand.Name.compareToAscii( "store" ) == 0 ) - ) - { - impl_store_throw(); - } - else if ( ( aCommand.Name.compareToAscii( "shutdown" ) == 0 ) // compatibility - || ( aCommand.Name.compareToAscii( "close" ) == 0 ) - ) + ::osl::ClearableMutexGuard aGuard(m_aMutex); + if ( m_bInExecute ) + return aRet; + + if ( aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "copyTo" ) ) ) + { + Sequence<Any> aIni; + aCommand.Argument >>= aIni; + if ( aIni.getLength() != 2 ) { - aRet <<= impl_close_throw(); + OSL_ENSURE( sal_False, "Wrong argument type!" ); + ucbhelper::cancelCommandExecution( + makeAny( IllegalArgumentException( + rtl::OUString(), + static_cast< cppu::OWeakObject * >( this ), + -1 ) ), + Environment ); + // Unreachable } - else + Reference< XStorage> xDest(aIni[0],UNO_QUERY); + ::rtl::OUString sPersistentName; + aIni[1] >>= sPersistentName; + Reference< XStorage> xStorage = getContainerStorage(); + // ----------------------------------------------------------------------------- + xStorage->copyElementTo(m_pImpl->m_aProps.sPersistentName,xDest,sPersistentName); + } + else if ( aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "preview" ) ) ) + { + onCommandPreview(aRet); + } + else if ( aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "insert" ) ) ) + { + Sequence<Any> aIni; + aCommand.Argument >>= aIni; + if ( !aIni.getLength() ) { - aRet = OContentHelper::execute(aCommand,CommandId,Environment); + OSL_ENSURE( sal_False, "Wrong argument count!" ); + ucbhelper::cancelCommandExecution( + makeAny( IllegalArgumentException( + rtl::OUString(), + static_cast< cppu::OWeakObject * >( this ), + -1 ) ), + Environment ); + // Unreachable } + ::rtl::OUString sURL; + aIni[0] >>= sURL; + onCommandInsert( sURL, Environment ); } + else if ( aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "getdocumentinfo" ) ) // compatibility + || aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "getDocumentInfo" ) ) + ) + { + onCommandGetDocumentProperties( aRet ); + } + else if ( aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "delete" ) ) ) + { + ////////////////////////////////////////////////////////////////// + // delete + ////////////////////////////////////////////////////////////////// + closeObject(); + Reference< XStorage> xStorage = getContainerStorage(); + if ( xStorage.is() ) + xStorage->removeElement(m_pImpl->m_aProps.sPersistentName); + + dispose(); + + } + else if ( ( aCommand.Name.compareToAscii( "storeOwn" ) == 0 ) // compatibility + || ( aCommand.Name.compareToAscii( "store" ) == 0 ) + ) + { + impl_store_throw(); + } + else if ( ( aCommand.Name.compareToAscii( "shutdown" ) == 0 ) // compatibility + || ( aCommand.Name.compareToAscii( "close" ) == 0 ) + ) + { + aRet <<= impl_close_throw(); + } + else if ( aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "show" ) ) ) + { + impl_showOrHideComponent_throw( true ); + } + else if ( aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "hide" ) ) ) + { + impl_showOrHideComponent_throw( false ); + } + else + { + aRet = OContentHelper::execute(aCommand,CommandId,Environment); + } + return aRet; } // ----------------------------------------------------------------------------- @@ -1741,9 +1747,8 @@ Sequence< PropertyValue > ODocumentDefinition::fillLoadArgs( const Reference< XC xParentFrame = lcl_getDatabaseDocumentFrame( *m_pImpl->m_pDataSource ); if ( !xParentFrame.is() ) { // i87957 we need a parent frame - if ( !m_xDesktop.is() ) - m_xDesktop.set( m_aContext.createComponent( (::rtl::OUString)SERVICE_FRAME_DESKTOP ), UNO_QUERY_THROW ); - xParentFrame.set(m_xDesktop,uno::UNO_QUERY); + Reference< XComponentLoader > xDesktop( m_aContext.createComponent( (::rtl::OUString)SERVICE_FRAME_DESKTOP ), UNO_QUERY_THROW ); + xParentFrame.set( xDesktop, UNO_QUERY ); if ( xParentFrame.is() ) { Reference<util::XCloseable> xCloseable(m_pImpl->m_pDataSource->getModel_noCreate(),UNO_QUERY); @@ -1827,8 +1832,7 @@ void ODocumentDefinition::loadEmbeddedObject( const Reference< XConnection >& _x if ( !xEnumDrivers.is() || !xEnumDrivers->hasMoreElements() ) { com::sun::star::io::WrongFormatException aWFE; - aWFE.Message = ::rtl::OUString::createFromAscii("Extension not present."); - // TODO: resource + aWFE.Message = DBACORE_RESSTRING( RID_STR_MISSING_EXTENSION ); throw aWFE; } } @@ -2065,10 +2069,8 @@ Reference< XComponent > ODocumentDefinition::impl_openUI_nolck_throw( bool _bFor { // no XDatabaseDocumentUI -> just execute the respective command m_bOpenInDesign = _bForEditing; - Any aComponent; - onCommandOpenSomething( Any(), true, NULL, aComponent, aGuard ); - Reference< XComponent > xComponent; - OSL_VERIFY( aComponent >>= xComponent ); + Reference< XComponent > xComponent( onCommandOpenSomething( Any(), true, NULL ), UNO_QUERY ); + OSL_ENSURE( xComponent.is(), "ODocumentDefinition::impl_openUI_nolck_throw: opening the thingie failed." ); return xComponent; } @@ -2282,26 +2284,29 @@ bool ODocumentDefinition::prepareClose() return true; } // ----------------------------------------------------------------------------- -void ODocumentDefinition::fillReportData(::osl::ClearableMutexGuard & _aGuard) +void ODocumentDefinition::fillReportData( const ::comphelper::ComponentContext& _rContext, + const Reference< util::XCloseable >& _rxComponent, + const Reference< XConnection >& _rxActiveConnection ) { - if ( !m_bForm && m_pImpl->m_aProps.bAsTemplate && !m_bOpenInDesign ) // open a report in alive mode, so we need to fill it - { - Sequence<Any> aArgs(2); - PropertyValue aValue; - aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TextDocument")); - aValue.Value <<= getComponent(); - aArgs[0] <<= aValue; - aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ActiveConnection")); - aValue.Value <<= m_xLastKnownConnection; - aArgs[1] <<= aValue; - - Reference< XJobExecutor > xExecuteable( m_aContext.createComponentWithArguments( "com.sun.star.wizards.report.CallReportWizard", aArgs ), UNO_QUERY ); - if ( xExecuteable.is() ) - { - _aGuard.clear(); - xExecuteable->trigger(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("fill"))); + Sequence< Any > aArgs(2); + PropertyValue aValue; + aValue.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "TextDocument" ) ); + aValue.Value <<= _rxComponent; + aArgs[0] <<= aValue; + aValue.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ActiveConnection" ) ); + aValue.Value <<= _rxActiveConnection; + aArgs[1] <<= aValue; + + try + { + Reference< XJobExecutor > xExecuteable( + _rContext.createComponentWithArguments( "com.sun.star.wizards.report.CallReportWizard", aArgs ), UNO_QUERY_THROW ); + xExecuteable->trigger( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "fill" ) ) ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); } -} } // ----------------------------------------------------------------------------- void ODocumentDefinition::updateDocumentTitle() diff --git a/dbaccess/source/core/dataaccess/documentdefinition.hxx b/dbaccess/source/core/dataaccess/documentdefinition.hxx index 014fed554..a754327dd 100644 --- a/dbaccess/source/core/dataaccess/documentdefinition.hxx +++ b/dbaccess/source/core/dataaccess/documentdefinition.hxx @@ -99,7 +99,6 @@ class ODocumentDefinition { ::com::sun::star::uno::Reference< ::com::sun::star::embed::XEmbeddedObject> m_xEmbeddedObject; ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStateChangeListener > m_xListener; - ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFramesSupplier > m_xDesktop; ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > m_xLastKnownConnection; OInterceptor* m_pInterceptor; @@ -184,9 +183,17 @@ public: sal_Bool saveAs(); void closeObject(); sal_Bool isModified(); - void fillReportData(::osl::ClearableMutexGuard & _aGuard); inline sal_Bool isNewReport() const { return !m_bForm && !m_pImpl->m_aProps.bAsTemplate; } + static void fillReportData( + const ::comphelper::ComponentContext& _rContext, + const ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloseable >& _rxComponent, + const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxActiveConnection + ); + + const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& + getConnection() const { return m_xLastKnownConnection; } + /** prepares closing the document component The method suspends the controller associated with the document, and saves the document @@ -224,9 +231,9 @@ public: private: /** does necessary initializations after our embedded object has been switched to ACTIVE */ - void impl_onActivateEmbeddedObject( const bool i_bReactivated ); + void impl_onActivateEmbeddedObject_nothrow( const bool i_bReactivated ); - /** initializes a newly created view/controller which is displaying our embedded object + /** initializes a newly created view/controller of a form which is displaying our embedded object Has only to be called if the respective embedded object has been loaded for design (and not for data entry) @@ -234,12 +241,15 @@ private: @param _rxController the controller which belongs to the XModel of our (active) embedded object */ - void impl_initObjectEditView( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& _rxController ); + static void impl_initFormEditView( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& _rxController ); /** removes the given frame from the desktop's frame collection @raises ::com::sun::star::uno::RuntimeException */ - void impl_removeFrameFromDesktop_throw( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _rxFrame ); + static void impl_removeFrameFromDesktop_throw( + const ::comphelper::ComponentContext& _rContxt, + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _rxFrame + ); /** opens the UI for this sub document */ @@ -366,10 +376,12 @@ private: void onCommandGetDocumentProperties( ::com::sun::star::uno::Any& _rProps ); void onCommandInsert( const ::rtl::OUString& _sURL, const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >& Environment ) throw( ::com::sun::star::uno::Exception ); void onCommandPreview( ::com::sun::star::uno::Any& _rImage ); - void onCommandOpenSomething( const ::com::sun::star::uno::Any& _rArgument, const bool _bActivate, - const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >& _rxEnvironment, - ::com::sun::star::uno::Any& _out_rComponent, - ::osl::ClearableMutexGuard & _aClearableGuard); + ::com::sun::star::uno::Any + onCommandOpenSomething( + const ::com::sun::star::uno::Any& _rArgument, + const bool _bActivate, + const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >& _rxEnvironment + ); }; class NameChangeNotifier diff --git a/dbaccess/source/core/dataaccess/intercept.cxx b/dbaccess/source/core/dataaccess/intercept.cxx index 50e407f25..37abdef73 100644 --- a/dbaccess/source/core/dataaccess/intercept.cxx +++ b/dbaccess/source/core/dataaccess/intercept.cxx @@ -31,28 +31,17 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_dbaccess.hxx" -#ifndef _COM_SUN_STAR_EMBED_EMBEDSTATES_HPP_ +#include "intercept.hxx" +#include "dbastrings.hrc" + #include <com/sun/star/embed/EmbedStates.hpp> -#endif -#ifndef _COM_SUN_STAR_DOCUMENT_XEVENTBROADCASTER_HPP_ #include <com/sun/star/document/XEventBroadcaster.hpp> -#endif -#ifndef _COM_SUN_STAR_UTIL_XMODIFIABLE_HPP_ #include <com/sun/star/util/XModifiable.hpp> -#endif -#ifndef _CPPUHELPER_WEAK_HXX_ #include <cppuhelper/weak.hxx> -#endif -#ifndef _COMPHELPER_TYPES_HXX_ + #include <comphelper/types.hxx> -#endif -#ifndef DBA_INTERCEPT_HXX -#include "intercept.hxx" -#endif -#include "dbastrings.hrc" -#ifndef _TOOLS_DEBUG_HXX #include <tools/debug.hxx> -#endif +#include <tools/diagnose_ex.h> namespace dbaccess @@ -140,66 +129,78 @@ struct DispatchHelper //XDispatch void SAL_CALL OInterceptor::dispatch( const URL& _URL,const Sequence<PropertyValue >& Arguments ) throw (RuntimeException) { - osl::ClearableMutexGuard aClearableGuard(m_aMutex); - if( m_pContentHolder ) + ::osl::MutexGuard aGuard( m_aMutex ); + if ( !m_pContentHolder ) + return; + + if ( _URL.Complete == m_aInterceptedURL[ DISPATCH_SAVE ] ) { - if( _URL.Complete == m_aInterceptedURL[DISPATCH_SAVE] ) - { - m_pContentHolder->save(sal_False); - } - else if( _URL.Complete == m_aInterceptedURL[DISPATCH_RELOAD] ) + m_pContentHolder->save( sal_False ); + return; + } + + if ( _URL.Complete == m_aInterceptedURL[ DISPATCH_RELOAD ] ) + { + ODocumentDefinition::fillReportData( + m_pContentHolder->getContext(), + m_pContentHolder->getComponent(), + m_pContentHolder->getConnection() + ); + return; + } + + if( _URL.Complete == m_aInterceptedURL[ DISPATCH_SAVEAS ] ) + { + if ( m_pContentHolder->isNewReport() ) { - m_pContentHolder->fillReportData(aClearableGuard); - // IMPORTANT: m_aMutex is cleared! + m_pContentHolder->saveAs(); } - else if( _URL.Complete == m_aInterceptedURL[DISPATCH_SAVEAS] ) + else if ( m_xSlaveDispatchProvider.is() ) { - if ( m_pContentHolder->isNewReport() ) - { - m_pContentHolder->saveAs(); - } - else if ( m_xSlaveDispatchProvider.is() ) - { - Sequence< PropertyValue > aNewArgs = Arguments; - sal_Int32 nInd = 0; + Sequence< PropertyValue > aNewArgs = Arguments; + sal_Int32 nInd = 0; - while( nInd < aNewArgs.getLength() ) - { - if ( aNewArgs[nInd].Name.equalsAscii( "SaveTo" ) ) - { - aNewArgs[nInd].Value <<= sal_True; - break; - } - nInd++; - } - - if ( nInd == aNewArgs.getLength() ) + while( nInd < aNewArgs.getLength() ) + { + if ( aNewArgs[nInd].Name.equalsAscii( "SaveTo" ) ) { - aNewArgs.realloc( nInd + 1 ); - aNewArgs[nInd].Name = ::rtl::OUString::createFromAscii( "SaveTo" ); aNewArgs[nInd].Value <<= sal_True; + break; } + nInd++; + } - Reference< XDispatch > xDispatch = m_xSlaveDispatchProvider->queryDispatch( - _URL, ::rtl::OUString::createFromAscii( "_self" ), 0 ); - if ( xDispatch.is() ) - xDispatch->dispatch( _URL, aNewArgs ); + if ( nInd == aNewArgs.getLength() ) + { + aNewArgs.realloc( nInd + 1 ); + aNewArgs[nInd].Name = ::rtl::OUString::createFromAscii( "SaveTo" ); + aNewArgs[nInd].Value <<= sal_True; } + + Reference< XDispatch > xDispatch = m_xSlaveDispatchProvider->queryDispatch( + _URL, ::rtl::OUString::createFromAscii( "_self" ), 0 ); + if ( xDispatch.is() ) + xDispatch->dispatch( _URL, aNewArgs ); } - else if ( _URL.Complete == m_aInterceptedURL[DISPATCH_CLOSEDOC] - || _URL.Complete == m_aInterceptedURL[DISPATCH_CLOSEWIN] - || _URL.Complete == m_aInterceptedURL[DISPATCH_CLOSEFRAME]) - { - DispatchHelper* pHelper = new DispatchHelper; - pHelper->aArguments = Arguments; - pHelper->aURL = _URL; - Application::PostUserEvent(LINK(this, OInterceptor, OnDispatch),reinterpret_cast<void*>(pHelper) ); - } + return; + } + + if ( _URL.Complete == m_aInterceptedURL[ DISPATCH_CLOSEDOC ] + || _URL.Complete == m_aInterceptedURL[ DISPATCH_CLOSEWIN ] + || _URL.Complete == m_aInterceptedURL[ DISPATCH_CLOSEFRAME ] + ) + { + DispatchHelper* pHelper = new DispatchHelper; + pHelper->aArguments = Arguments; + pHelper->aURL = _URL; + Application::PostUserEvent( LINK( this, OInterceptor, OnDispatch ), reinterpret_cast< void* >( pHelper ) ); + return; } } -IMPL_LINK( OInterceptor, OnDispatch, void*, _nId) + +IMPL_LINK( OInterceptor, OnDispatch, void*, _pDispatcher ) { - ::std::auto_ptr<DispatchHelper> pHelper(reinterpret_cast<DispatchHelper*>(_nId)); + ::std::auto_ptr<DispatchHelper> pHelper( reinterpret_cast< DispatchHelper* >( _pDispatcher ) ); try { if ( m_pContentHolder && m_pContentHolder->prepareClose() && m_xSlaveDispatchProvider.is() ) @@ -217,10 +218,11 @@ IMPL_LINK( OInterceptor, OnDispatch, void*, _nId) } } } - catch(const Exception&) + catch ( const Exception& ) { - OSL_ENSURE(sal_False, "caught an exception while starting the table wizard!"); + DBG_UNHANDLED_EXCEPTION(); } + return 0L; } diff --git a/dbaccess/source/core/dataaccess/makefile.mk b/dbaccess/source/core/dataaccess/makefile.mk index c48056ea8..a50654d20 100644 --- a/dbaccess/source/core/dataaccess/makefile.mk +++ b/dbaccess/source/core/dataaccess/makefile.mk @@ -56,6 +56,7 @@ SLOFILES= \ $(SLO)$/databasecontext.obj \ $(SLO)$/connection.obj \ $(SLO)$/datasource.obj \ + $(SLO)$/databaseregistrations.obj \ $(SLO)$/intercept.obj \ $(SLO)$/myucp_datasupplier.obj \ $(SLO)$/myucp_resultset.obj \ |