Tag: cws_src680_dba24d User: fs Date: 2007-11-14 10:21:10+0000 Modified: dba/dbaccess/source/ui/uno/copytablewizard.cxx
Log: #i81658# consistent interaction handler usage File Changes: Directory: /dba/dbaccess/source/ui/uno/ ======================================= File [changed]: copytablewizard.cxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/ui/uno/copytablewizard.cxx?r1=1.1.2.4&r2=1.1.2.5 Delta lines: +97 -31 --------------------- --- copytablewizard.cxx 2007-11-12 16:14:57+0000 1.1.2.4 +++ copytablewizard.cxx 2007-11-14 10:21:07+0000 1.1.2.5 @@ -4,9 +4,9 @@ * * $RCSfile: copytablewizard.cxx,v $ * - * $Revision: 1.1.2.4 $ + * $Revision: 1.1.2.5 $ * - * last change: $Author: fs $ $Date: 2007/11/12 16:14:57 $ + * last change: $Author: fs $ $Date: 2007/11/14 10:21:07 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -141,6 +141,7 @@ namespace DataType = ::com::sun::star::sdbc::DataType; typedef ::utl::SharedUNOComponent< XConnection > SharedConnection; + typedef Reference< XInteractionHandler > InteractionHandler; //========================================================================= //= CopyTableWizard @@ -223,12 +224,25 @@ impl_getDialog_throw() const; /** ensures the given argument sequence contains a valid data access descriptor at the given position + @param _rAllArgs + the arguments as passed to ->initialize + @param _nArgPos + the position within ->_rAllArgs which contains the data access descriptor + @param _out_rxConnection + will, upon successful return, contain the connection for the data source + @param _out_rxDocInteractionHandler + will, upon successful return, contain the interaction handler which could + be deduced from database document described by the descriptor, if any. + (It is possible that the descriptor does not allow to deduce a database document, + in which case <code>_out_rxDocInteractionHandler</code> will be <NULL/>.) + @return the data access descriptor */ Reference< XPropertySet > impl_ensureDataAccessDescriptor_throw( const Sequence< Any >& _rAllArgs, const sal_Int16 _nArgPos, - SharedConnection& _out_rxConnection + SharedConnection& _out_rxConnection, + InteractionHandler& _out_rxDocInteractionHandler ) const; /** extracts the source object (table or query) described by the given descriptor, @@ -251,15 +265,17 @@ @param _rxDataSourceDescriptor the data access descriptor describing the data source whose connection should be obtained. Must not be <NULL/>. + @param _out_rxDocInteractionHandler + the interaction handler which could be deduced from the descriptor @throws RuntimeException if anything goes seriously wrong. */ - static SharedConnection + SharedConnection impl_extractConnection_throw( - const ::comphelper::ComponentContext& _rContext, - const Reference< XPropertySet >& _rxDataSourceDescriptor - ); + const Reference< XPropertySet >& _rxDataSourceDescriptor, + InteractionHandler& _out_rxDocInteractionHandler + ) const; /** actually copies the table @@ -312,6 +328,8 @@ // destination SharedConnection m_xDestConnection; + // other + InteractionHandler m_xInteractionHandler; ::cppu::OInterfaceContainerHelper m_aCopyTableListeners; }; @@ -546,9 +564,9 @@ if it occures during invoking any of the data source's methods, or if any of the involved components violates its contract by not providing the required interfaces */ - Reference< XInteractionHandler > lcl_getInteractionHandler_throw( const Reference< XDataSource >& _rxDataSource ) + InteractionHandler lcl_getInteractionHandler_throw( const Reference< XDataSource >& _rxDataSource, const InteractionHandler& _rFallback ) { - Reference< XInteractionHandler > xHandler; + InteractionHandler xHandler( _rFallback ); // try to obtain the document model Reference< XModel > xDocumentModel; @@ -575,7 +593,7 @@ if it occures during invoking any of the data source's methods, or if any of the involved components violates its contract by not providing the required interfaces */ - Reference< XInteractionHandler > lcl_getInteractionHandler_throw( const Reference< XConnection >& _rxConnection ) + InteractionHandler lcl_getInteractionHandler_throw( const Reference< XConnection >& _rxConnection, const InteractionHandler& _rFallback ) { // try whether there is a data source which the connection belongs to Reference< XDataSource > xDataSource; @@ -584,15 +602,16 @@ xDataSource = xDataSource.query( xAsChild->getParent() ); if ( xDataSource.is() ) - return lcl_getInteractionHandler_throw( xDataSource ); + return lcl_getInteractionHandler_throw( xDataSource, _rFallback ); - return Reference< XInteractionHandler >(); + return _rFallback; } } //------------------------------------------------------------------------- Reference< XPropertySet > CopyTableWizard::impl_ensureDataAccessDescriptor_throw( - const Sequence< Any >& _rAllArgs, const sal_Int16 _nArgPos, SharedConnection& _out_rxConnection ) const + const Sequence< Any >& _rAllArgs, const sal_Int16 _nArgPos, SharedConnection& _out_rxConnection, + InteractionHandler& _out_rxDocInteractionHandler ) const { Reference< XPropertySet > xDescriptor; _rAllArgs[ _nArgPos ] >>= xDescriptor; @@ -612,7 +631,7 @@ // it must be able to provide a connection if ( bIsValid ) { - _out_rxConnection = impl_extractConnection_throw( m_aContext, xDescriptor ); + _out_rxConnection = impl_extractConnection_throw( xDescriptor, _out_rxDocInteractionHandler ); bIsValid = _out_rxConnection.is(); } @@ -677,7 +696,8 @@ } //------------------------------------------------------------------------- - SharedConnection CopyTableWizard::impl_extractConnection_throw( const ::comphelper::ComponentContext& _rContext, const Reference< XPropertySet >& _rxDataSourceDescriptor ) + SharedConnection CopyTableWizard::impl_extractConnection_throw( const Reference< XPropertySet >& _rxDataSourceDescriptor, + InteractionHandler& _out_rxDocInteractionHandler ) const { SharedConnection xConnection; @@ -685,7 +705,7 @@ if ( !_rxDataSourceDescriptor.is() ) return xConnection; - Reference< XInteractionHandler > xInteractionHandler; + InteractionHandler xInteractionHandler; do { @@ -700,7 +720,8 @@ } if ( xConnection.is() ) { - xInteractionHandler = lcl_getInteractionHandler_throw( xConnection.getTyped() ); + xInteractionHandler = lcl_getInteractionHandler_throw( xConnection.getTyped(), m_xInteractionHandler ); + OSL_POSTCOND( xInteractionHandler.is(), "CopyTableWizard::impl_extractConnection_throw: lcl_getInteractionHandler_throw returned nonsense!" ); break; } @@ -712,7 +733,7 @@ OSL_VERIFY( _rxDataSourceDescriptor->getPropertyValue( PROPERTY_DATABASE_LOCATION ) >>= sDatabaseLocation ); // need a DatabaseContext for loading the data source - Reference< XNameAccess > xDatabaseContext( _rContext.createComponent( "com.sun.star.sdb.DatabaseContext" ), UNO_QUERY_THROW ); + Reference< XNameAccess > xDatabaseContext( m_aContext.createComponent( "com.sun.star.sdb.DatabaseContext" ), UNO_QUERY_THROW ); Reference< XDataSource > xDataSource; if ( sDataSource.getLength() ) xDataSource.set( xDatabaseContext->getByName( sDataSource ), UNO_QUERY_THROW ); @@ -722,7 +743,8 @@ if ( xDataSource.is() ) { // first, try connecting with completion - xInteractionHandler = lcl_getInteractionHandler_throw( xDataSource ); + xInteractionHandler = lcl_getInteractionHandler_throw( xDataSource, m_xInteractionHandler ); + OSL_POSTCOND( xInteractionHandler.is(), "CopyTableWizard::impl_extractConnection_throw: lcl_getInteractionHandler_throw returned nonsense!" ); if ( xInteractionHandler.is() ) { Reference< XCompletedConnection > xInteractiveConnection( xDataSource, UNO_QUERY ); @@ -749,6 +771,9 @@ } while ( false ); + if ( xInteractionHandler != m_xInteractionHandler ) + _out_rxDocInteractionHandler = xInteractionHandler; + return xConnection; } @@ -812,13 +837,20 @@ if ( xComposer.is() ) { xComposer->setQuery( sQueryCommand ); - Reference< XInteractionHandler > xHandler( - m_aContext.createComponent( "com.sun.star.sdb.InteractionHandler" ), UNO_QUERY_THROW ); - // TODO: consistent concept for the interaction handler to use Reference< XParameters > xStatementParams( xStatement, UNO_QUERY ); + OSL_ENSURE( xStatementParams.is(), "CopyTableWizard::impl_createSourceStatement_throw: no access to the statement's parameters!" ); + // the statement should be a css.sdbc.PreparedStatement (this is what + // we created), and a prepared statement is required to support XParameters if ( xStatementParams.is() ) - ::dbtools::askForParameters( xComposer, xStatementParams, m_xSourceConnection, xHandler ); + { + OSL_ENSURE( m_xInteractionHandler.is(), + "CopyTableWizard::impl_createSourceStatement_throw: no interaction handler for the parameters request!" ); + // we should always have an interaction handler - as last fallback, we create an own one in ::initialize + + if ( m_xInteractionHandler.is() ) + ::dbtools::askForParameters( xComposer, xStatementParams, m_xSourceConnection, m_xInteractionHandler ); + } } } break; @@ -937,10 +969,10 @@ xRequest->addContinuation( xYes.get() ); xRequest->addContinuation( new ::comphelper::OInteractionDisapprove ); - Reference< XInteractionHandler > xHandler( - m_aContext.createComponent( "com.sun.star.sdb.InteractionHandler" ), UNO_QUERY_THROW ); - // TODO: consistent concept for the interaction handler to use - xHandler->handle( xRequest.get() ); + OSL_ENSURE( m_xInteractionHandler.is(), + "CopyTableWizard::impl_processCopyError_nothrow: we always should have an interaction handler!" ); + if ( m_xInteractionHandler.is() ) + m_xInteractionHandler->handle( xRequest.get() ); if ( xYes->wasSelected() ) // continue copying @@ -1166,6 +1198,8 @@ //------------------------------------------------------------------------- void CopyTableWizard::impl_doCopy_nothrow() { + Any aError; + try { OCopyTableWizard& rWizard( impl_getDialog_throw() ); @@ -1223,7 +1257,20 @@ } catch( const Exception& ) { - // TODO: interaction handler + aError = ::cppu::getCaughtException(); + } + + if ( aError.hasValue() && m_xInteractionHandler.is() ) + { + try + { + ::rtl::Reference< ::comphelper::OInteractionRequest > xRequest( new ::comphelper::OInteractionRequest( aError ) ); + m_xInteractionHandler->handle( xRequest.get() ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } } } @@ -1234,7 +1281,8 @@ if ( isInitialized() ) throw AlreadyInitializedException( ::rtl::OUString(), *this ); - if ( _rArguments.getLength() != 2 ) + sal_Int32 nArgCount( _rArguments.getLength() ); + if ( ( nArgCount != 2 ) && ( nArgCount != 3 ) ) throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Illegal number of initialization parameters." ) ), // TODO: resource: STR_CTW_ILLEGAL_PARAMETER_COUNT @@ -1244,10 +1292,28 @@ try { - Reference< XPropertySet > xSourceDescriptor( impl_ensureDataAccessDescriptor_throw( _rArguments, 0, m_xSourceConnection ) ); + if ( nArgCount == 3 ) + { // ->createWithInteractionHandler + if ( !( _rArguments[2] >>= m_xInteractionHandler ) ) + throw IllegalArgumentException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "The given interaction handler is invalid." ) ), + // TODO: resource + *this, + 3 + ); + } + if ( !m_xInteractionHandler.is() ) + m_xInteractionHandler.set( m_aContext.createComponent( "com.sun.star.sdb.InteractionHandler" ), UNO_QUERY_THROW ); + + InteractionHandler xSourceDocHandler; + Reference< XPropertySet > xSourceDescriptor( impl_ensureDataAccessDescriptor_throw( _rArguments, 0, m_xSourceConnection, xSourceDocHandler ) ); m_xSourceObject = impl_extractSourceObject_throw( xSourceDescriptor, m_nCommandType ); - impl_ensureDataAccessDescriptor_throw( _rArguments, 1, m_xDestConnection ); + InteractionHandler xDestDocHandler; + impl_ensureDataAccessDescriptor_throw( _rArguments, 1, m_xDestConnection, xDestDocHandler ); + + if ( xDestDocHandler.is() ) + m_xInteractionHandler = xDestDocHandler; } catch( const RuntimeException& ) { throw; } catch( const IllegalArgumentException& ) { throw; } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
