Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "errorbroadcaster.hxx"
21 : #include <connectivity/dbtools.hxx>
22 : #include <com/sun/star/sdb/SQLContext.hpp>
23 :
24 : //.........................................................................
25 : namespace frm
26 : {
27 : //.........................................................................
28 :
29 : using namespace ::com::sun::star::uno;
30 : using namespace ::com::sun::star::lang;
31 : using namespace ::com::sun::star::sdbc;
32 : using namespace ::com::sun::star::sdb;
33 : using namespace ::dbtools;
34 :
35 : //=====================================================================
36 : //= OErrorBroadcaster
37 : //=====================================================================
38 : //---------------------------------------------------------------------
39 0 : OErrorBroadcaster::OErrorBroadcaster( ::cppu::OBroadcastHelper& _rBHelper )
40 : :m_rBHelper( _rBHelper )
41 0 : ,m_aErrorListeners( _rBHelper.rMutex )
42 : {
43 0 : }
44 :
45 : //---------------------------------------------------------------------
46 0 : OErrorBroadcaster::~OErrorBroadcaster( )
47 : {
48 : OSL_ENSURE( m_rBHelper.bDisposed || m_rBHelper.bInDispose,
49 : "OErrorBroadcaster::~OErrorBroadcaster: not disposed!" );
50 : // herein, we don't have a chance to do the dispose ourself ....
51 :
52 : OSL_ENSURE( 0 == m_aErrorListeners.getLength(),
53 : "OErrorBroadcaster::~OErrorBroadcaster: still have listeners!" );
54 : // either we're not disposed, or the derived class did not call our dispose from within their dispose
55 0 : }
56 :
57 : //---------------------------------------------------------------------
58 0 : void SAL_CALL OErrorBroadcaster::disposing()
59 : {
60 0 : EventObject aDisposeEvent( static_cast< XSQLErrorBroadcaster* >( this ) );
61 0 : m_aErrorListeners.disposeAndClear( aDisposeEvent );
62 0 : }
63 :
64 : //------------------------------------------------------------------------------
65 0 : void SAL_CALL OErrorBroadcaster::onError( const SQLException& _rException, const ::rtl::OUString& _rContextDescription )
66 : {
67 0 : Any aError;
68 0 : if ( !_rContextDescription.isEmpty() )
69 0 : aError = makeAny( prependErrorInfo( _rException, static_cast< XSQLErrorBroadcaster* >( this ), _rContextDescription ) );
70 : else
71 0 : aError = makeAny( _rException );
72 :
73 0 : onError( SQLErrorEvent( static_cast< XSQLErrorBroadcaster* >( this ), aError ) );
74 0 : }
75 :
76 : //------------------------------------------------------------------------------
77 0 : void SAL_CALL OErrorBroadcaster::onError( const ::com::sun::star::sdb::SQLErrorEvent& _rError )
78 : {
79 0 : if ( m_aErrorListeners.getLength() )
80 : {
81 :
82 0 : ::cppu::OInterfaceIteratorHelper aIter( m_aErrorListeners );
83 0 : while ( aIter.hasMoreElements() )
84 0 : static_cast< XSQLErrorListener* >( aIter.next() )->errorOccured( _rError );
85 : }
86 0 : }
87 :
88 : //------------------------------------------------------------------------------
89 0 : void SAL_CALL OErrorBroadcaster::addSQLErrorListener( const Reference< XSQLErrorListener >& _rxListener ) throw( RuntimeException )
90 : {
91 0 : m_aErrorListeners.addInterface( _rxListener );
92 0 : }
93 :
94 : //------------------------------------------------------------------------------
95 0 : void SAL_CALL OErrorBroadcaster::removeSQLErrorListener( const Reference< XSQLErrorListener >& _rxListener ) throw( RuntimeException )
96 : {
97 0 : m_aErrorListeners.removeInterface( _rxListener );
98 0 : }
99 :
100 : //.........................................................................
101 : } // namespace frm
102 : //.........................................................................
103 :
104 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|