1*24acc546SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*24acc546SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*24acc546SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*24acc546SAndrew Rist  * distributed with this work for additional information
6*24acc546SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*24acc546SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*24acc546SAndrew Rist  * "License"); you may not use this file except in compliance
9*24acc546SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*24acc546SAndrew Rist  *
11*24acc546SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*24acc546SAndrew Rist  *
13*24acc546SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*24acc546SAndrew Rist  * software distributed under the License is distributed on an
15*24acc546SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*24acc546SAndrew Rist  * KIND, either express or implied.  See the License for the
17*24acc546SAndrew Rist  * specific language governing permissions and limitations
18*24acc546SAndrew Rist  * under the License.
19*24acc546SAndrew Rist  *
20*24acc546SAndrew Rist  *************************************************************/
21*24acc546SAndrew Rist 
22*24acc546SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_forms.hxx"
26cdf0e10cSrcweir #include "errorbroadcaster.hxx"
27cdf0e10cSrcweir #include <connectivity/dbtools.hxx>
28cdf0e10cSrcweir #include <com/sun/star/sdb/SQLContext.hpp>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir //.........................................................................
31cdf0e10cSrcweir namespace frm
32cdf0e10cSrcweir {
33cdf0e10cSrcweir //.........................................................................
34cdf0e10cSrcweir 
35cdf0e10cSrcweir 	using namespace ::com::sun::star::uno;
36cdf0e10cSrcweir 	using namespace ::com::sun::star::lang;
37cdf0e10cSrcweir 	using namespace ::com::sun::star::sdbc;
38cdf0e10cSrcweir 	using namespace ::com::sun::star::sdb;
39cdf0e10cSrcweir 	using namespace ::dbtools;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir 	//=====================================================================
42cdf0e10cSrcweir 	//= OErrorBroadcaster
43cdf0e10cSrcweir 	//=====================================================================
44cdf0e10cSrcweir 	//---------------------------------------------------------------------
OErrorBroadcaster(::cppu::OBroadcastHelper & _rBHelper)45cdf0e10cSrcweir 	OErrorBroadcaster::OErrorBroadcaster( ::cppu::OBroadcastHelper& _rBHelper )
46cdf0e10cSrcweir 		:m_rBHelper( _rBHelper )
47cdf0e10cSrcweir 		,m_aErrorListeners( _rBHelper.rMutex )
48cdf0e10cSrcweir 	{
49cdf0e10cSrcweir 	}
50cdf0e10cSrcweir 
51cdf0e10cSrcweir 	//---------------------------------------------------------------------
~OErrorBroadcaster()52cdf0e10cSrcweir 	OErrorBroadcaster::~OErrorBroadcaster( )
53cdf0e10cSrcweir 	{
54cdf0e10cSrcweir 		OSL_ENSURE( m_rBHelper.bDisposed || m_rBHelper.bInDispose,
55cdf0e10cSrcweir 			"OErrorBroadcaster::~OErrorBroadcaster: not disposed!" );
56cdf0e10cSrcweir 		// herein, we don't have a chance to do the dispose ourself ....
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 		OSL_ENSURE( 0 == m_aErrorListeners.getLength(),
59cdf0e10cSrcweir 			"OErrorBroadcaster::~OErrorBroadcaster: still have listeners!" );
60cdf0e10cSrcweir 		// either we're not disposed, or the derived class did not call our dispose from within their dispose
61cdf0e10cSrcweir 	}
62cdf0e10cSrcweir 
63cdf0e10cSrcweir 	//---------------------------------------------------------------------
disposing()64cdf0e10cSrcweir 	void SAL_CALL OErrorBroadcaster::disposing()
65cdf0e10cSrcweir 	{
66cdf0e10cSrcweir 	    EventObject aDisposeEvent( static_cast< XSQLErrorBroadcaster* >( this ) );
67cdf0e10cSrcweir 		m_aErrorListeners.disposeAndClear( aDisposeEvent );
68cdf0e10cSrcweir 	}
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 	//------------------------------------------------------------------------------
onError(const SQLException & _rException,const::rtl::OUString & _rContextDescription)71cdf0e10cSrcweir 	void SAL_CALL OErrorBroadcaster::onError( const SQLException& _rException, const ::rtl::OUString& _rContextDescription )
72cdf0e10cSrcweir 	{
73cdf0e10cSrcweir 		Any aError;
74cdf0e10cSrcweir 		if ( _rContextDescription.getLength() )
75cdf0e10cSrcweir 			aError = makeAny( prependErrorInfo( _rException, static_cast< XSQLErrorBroadcaster* >( this ), _rContextDescription ) );
76cdf0e10cSrcweir 		else
77cdf0e10cSrcweir 			aError = makeAny( _rException );
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 		onError( SQLErrorEvent( static_cast< XSQLErrorBroadcaster* >( this ), aError ) );
80cdf0e10cSrcweir 	}
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 	//------------------------------------------------------------------------------
onError(const::com::sun::star::sdb::SQLErrorEvent & _rError)83cdf0e10cSrcweir 	void SAL_CALL OErrorBroadcaster::onError( const ::com::sun::star::sdb::SQLErrorEvent& _rError )
84cdf0e10cSrcweir 	{
85cdf0e10cSrcweir 		if ( m_aErrorListeners.getLength() )
86cdf0e10cSrcweir 		{
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 			::cppu::OInterfaceIteratorHelper aIter( m_aErrorListeners );
89cdf0e10cSrcweir 			while ( aIter.hasMoreElements() )
90cdf0e10cSrcweir 				static_cast< XSQLErrorListener* >( aIter.next() )->errorOccured( _rError );
91cdf0e10cSrcweir 		}
92cdf0e10cSrcweir 	}
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 	//------------------------------------------------------------------------------
addSQLErrorListener(const Reference<XSQLErrorListener> & _rxListener)95cdf0e10cSrcweir 	void SAL_CALL OErrorBroadcaster::addSQLErrorListener( const Reference< XSQLErrorListener >& _rxListener ) throw( RuntimeException )
96cdf0e10cSrcweir 	{
97cdf0e10cSrcweir 		m_aErrorListeners.addInterface( _rxListener );
98cdf0e10cSrcweir 	}
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 	//------------------------------------------------------------------------------
removeSQLErrorListener(const Reference<XSQLErrorListener> & _rxListener)101cdf0e10cSrcweir 	void SAL_CALL OErrorBroadcaster::removeSQLErrorListener( const Reference< XSQLErrorListener >& _rxListener ) throw( RuntimeException )
102cdf0e10cSrcweir 	{
103cdf0e10cSrcweir 		m_aErrorListeners.removeInterface( _rxListener );
104cdf0e10cSrcweir 	}
105cdf0e10cSrcweir 
106cdf0e10cSrcweir //.........................................................................
107cdf0e10cSrcweir }	// namespace frm
108cdf0e10cSrcweir //.........................................................................
109cdf0e10cSrcweir 
110