xref: /trunk/main/dbaccess/source/ui/uno/dbinteraction.hxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
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 #ifndef _DBAUI_INTERACTION_HXX_
29 #define _DBAUI_INTERACTION_HXX_
30 
31 #ifndef _CPPUHELPER_IMPLBASE2_HXX_
32 #include <cppuhelper/implbase2.hxx>
33 #endif
34 
35 #include "moduledbu.hxx"
36 #include "apitools.hxx"
37 
38 /** === begin UNO includes === **/
39 #include <com/sun/star/lang/XServiceInfo.hpp>
40 #include <com/sun/star/task/XInteractionHandler2.hpp>
41 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
42 #include <com/sun/star/ucb/AuthenticationRequest.hpp>
43 #include <com/sun/star/sdb/ParametersRequest.hpp>
44 #include <com/sun/star/sdb/DocumentSaveRequest.hpp>
45 /** === end UNO includes === **/
46 
47 namespace dbtools
48 {
49     class SQLExceptionInfo;
50 }
51 
52 //.........................................................................
53 namespace dbaui
54 {
55 //.........................................................................
56 
57     //=========================================================================
58     //= BasicInteractionHandler
59     //=========================================================================
60     typedef ::cppu::WeakImplHelper2 <   ::com::sun::star::lang::XServiceInfo
61                                     ,   ::com::sun::star::task::XInteractionHandler2
62                                     >   BasicInteractionHandler_Base;
63     /** implements an <type scope="com.sun.star.task">XInteractionHandler</type> for
64         database related interaction requests.
65         <p/>
66         Supported interaction requests by now (specified by an exception: The appropriate exception
67         has to be returned by the getRequest method of the object implementing the
68         <type scope="com.sun.star.task">XInteractionRequest</type> interface.
69             <ul>
70                 <li><b><type scope="com.sun.star.sdbc">SQLException</type></b>: requests to display a
71                     standard error dialog for the (maybe chained) exception given</li>
72             </ul>
73     */
74     class BasicInteractionHandler
75                 :public BasicInteractionHandler_Base
76     {
77         const OModuleClient m_aModuleClient;
78         const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >
79                             m_xORB;
80         const bool          m_bFallbackToGeneric;
81 
82     public:
83         BasicInteractionHandler(
84             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& i_rORB,
85             const bool i_bFallbackToGeneric
86         );
87 
88         // XInteractionHandler2
89         virtual ::sal_Bool SAL_CALL handleInteractionRequest( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& Request ) throw (::com::sun::star::uno::RuntimeException);
90 
91         // XInteractionHandler
92         virtual void SAL_CALL handle( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& Request ) throw(::com::sun::star::uno::RuntimeException);
93 
94     protected:
95         sal_Bool
96                 impl_handle_throw( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& i_Request );
97 
98         /// handle SQLExceptions (and derived classes)
99         void    implHandle(
100                     const ::dbtools::SQLExceptionInfo& _rSqlInfo,
101                     const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > >& _rContinuations);
102 
103         /// handle parameter requests
104         void    implHandle(
105                     const ::com::sun::star::sdb::ParametersRequest& _rParamRequest,
106                     const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > >& _rContinuations);
107 
108         /// handle document save requests
109         void    implHandle(
110                     const ::com::sun::star::sdb::DocumentSaveRequest& _rParamRequest,
111                     const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > >& _rContinuations);
112 
113         /// handles requests which are not SDB-specific
114         bool    implHandleUnknown(
115                     const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& _rxRequest );
116 
117         /// known continuation types
118         enum Continuation
119         {
120             APPROVE,
121             DISAPPROVE,
122             RETRY,
123             ABORT,
124             SUPPLY_PARAMETERS,
125             SUPPLY_DOCUMENTSAVE
126         };
127         /** check if a given continuation sequence contains a given continuation type<p/>
128             @return     the index within <arg>_rContinuations</arg> of the first occurence of a continuation
129                         of the requested type, -1 of no such continuation exists
130         */
131         sal_Int32 getContinuation(
132             Continuation _eCont,
133             const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > >& _rContinuations);
134     };
135 
136     //=========================================================================
137     //= SQLExceptionInteractionHandler
138     //=========================================================================
139     class SQLExceptionInteractionHandler : public BasicInteractionHandler
140     {
141     public:
142         SQLExceptionInteractionHandler(
143                 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& i_rORB
144             )
145             :BasicInteractionHandler( i_rORB, false )
146         {
147         }
148 
149         // XServiceInfo
150         DECLARE_SERVICE_INFO_STATIC();
151     };
152 
153     //=========================================================================
154     //= SQLExceptionInteractionHandler
155     //=========================================================================
156     /** an implementation for the legacy css.sdb.InteractionHandler
157 
158         css.sdb.InteractionHandler is deprecated, as it does not only handle database related interactions,
159         but also delegates all kind of unknown requests to a css.task.InteractionHandler.
160 
161         In today's architecture, there's only one central css.task.InteractionHandler, which is to be used
162         for all requests. Depending on configuration information, it decides which handler implementation
163         to delegate a request to.
164 
165         SQLExceptionInteractionHandler is the delegatee which handles only database related interactions.
166         LegacyInteractionHandler is the version which first checks for a database related interaction, and
167         forwards everything else to the css.task.InteractionHandler.
168     */
169     class LegacyInteractionHandler : public BasicInteractionHandler
170     {
171     public:
172         LegacyInteractionHandler(
173                 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& i_rORB
174             )
175             :BasicInteractionHandler( i_rORB, true )
176         {
177         }
178 
179         // XServiceInfo
180         DECLARE_SERVICE_INFO_STATIC();
181     };
182 
183 //.........................................................................
184 }   // namespace dbaui
185 //.........................................................................
186 
187 #endif // _DBAUI_INTERACTION_HXX_
188 
189