xref: /trunk/main/forms/source/component/errorbroadcaster.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_forms.hxx"
30 #include "errorbroadcaster.hxx"
31 #include <connectivity/dbtools.hxx>
32 #include <com/sun/star/sdb/SQLContext.hpp>
33 
34 //.........................................................................
35 namespace frm
36 {
37 //.........................................................................
38 
39     using namespace ::com::sun::star::uno;
40     using namespace ::com::sun::star::lang;
41     using namespace ::com::sun::star::sdbc;
42     using namespace ::com::sun::star::sdb;
43     using namespace ::dbtools;
44 
45     //=====================================================================
46     //= OErrorBroadcaster
47     //=====================================================================
48     //---------------------------------------------------------------------
49     OErrorBroadcaster::OErrorBroadcaster( ::cppu::OBroadcastHelper& _rBHelper )
50         :m_rBHelper( _rBHelper )
51         ,m_aErrorListeners( _rBHelper.rMutex )
52     {
53     }
54 
55     //---------------------------------------------------------------------
56     OErrorBroadcaster::~OErrorBroadcaster( )
57     {
58         OSL_ENSURE( m_rBHelper.bDisposed || m_rBHelper.bInDispose,
59             "OErrorBroadcaster::~OErrorBroadcaster: not disposed!" );
60         // herein, we don't have a chance to do the dispose ourself ....
61 
62         OSL_ENSURE( 0 == m_aErrorListeners.getLength(),
63             "OErrorBroadcaster::~OErrorBroadcaster: still have listeners!" );
64         // either we're not disposed, or the derived class did not call our dispose from within their dispose
65     }
66 
67     //---------------------------------------------------------------------
68     void SAL_CALL OErrorBroadcaster::disposing()
69     {
70         EventObject aDisposeEvent( static_cast< XSQLErrorBroadcaster* >( this ) );
71         m_aErrorListeners.disposeAndClear( aDisposeEvent );
72     }
73 
74     //------------------------------------------------------------------------------
75     void SAL_CALL OErrorBroadcaster::onError( const SQLException& _rException, const ::rtl::OUString& _rContextDescription )
76     {
77         Any aError;
78         if ( _rContextDescription.getLength() )
79             aError = makeAny( prependErrorInfo( _rException, static_cast< XSQLErrorBroadcaster* >( this ), _rContextDescription ) );
80         else
81             aError = makeAny( _rException );
82 
83         onError( SQLErrorEvent( static_cast< XSQLErrorBroadcaster* >( this ), aError ) );
84     }
85 
86     //------------------------------------------------------------------------------
87     void SAL_CALL OErrorBroadcaster::onError( const ::com::sun::star::sdb::SQLErrorEvent& _rError )
88     {
89         if ( m_aErrorListeners.getLength() )
90         {
91 
92             ::cppu::OInterfaceIteratorHelper aIter( m_aErrorListeners );
93             while ( aIter.hasMoreElements() )
94                 static_cast< XSQLErrorListener* >( aIter.next() )->errorOccured( _rError );
95         }
96     }
97 
98     //------------------------------------------------------------------------------
99     void SAL_CALL OErrorBroadcaster::addSQLErrorListener( const Reference< XSQLErrorListener >& _rxListener ) throw( RuntimeException )
100     {
101         m_aErrorListeners.addInterface( _rxListener );
102     }
103 
104     //------------------------------------------------------------------------------
105     void SAL_CALL OErrorBroadcaster::removeSQLErrorListener( const Reference< XSQLErrorListener >& _rxListener ) throw( RuntimeException )
106     {
107         m_aErrorListeners.removeInterface( _rxListener );
108     }
109 
110 //.........................................................................
111 }   // namespace frm
112 //.........................................................................
113 
114