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