1*2e2212a7SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2e2212a7SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2e2212a7SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2e2212a7SAndrew Rist  * distributed with this work for additional information
6*2e2212a7SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2e2212a7SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2e2212a7SAndrew Rist  * "License"); you may not use this file except in compliance
9*2e2212a7SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2e2212a7SAndrew Rist  *
11*2e2212a7SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2e2212a7SAndrew Rist  *
13*2e2212a7SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2e2212a7SAndrew Rist  * software distributed under the License is distributed on an
15*2e2212a7SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2e2212a7SAndrew Rist  * KIND, either express or implied.  See the License for the
17*2e2212a7SAndrew Rist  * specific language governing permissions and limitations
18*2e2212a7SAndrew Rist  * under the License.
19*2e2212a7SAndrew Rist  *
20*2e2212a7SAndrew Rist  *************************************************************/
21*2e2212a7SAndrew Rist 
22*2e2212a7SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _DBAUI_INTERACTION_HXX_
25cdf0e10cSrcweir #define _DBAUI_INTERACTION_HXX_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #ifndef _CPPUHELPER_IMPLBASE2_HXX_
28cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx>
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include "moduledbu.hxx"
32cdf0e10cSrcweir #include "apitools.hxx"
33cdf0e10cSrcweir 
34cdf0e10cSrcweir /** === begin UNO includes === **/
35cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
36cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler2.hpp>
37cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38cdf0e10cSrcweir #include <com/sun/star/ucb/AuthenticationRequest.hpp>
39cdf0e10cSrcweir #include <com/sun/star/sdb/ParametersRequest.hpp>
40cdf0e10cSrcweir #include <com/sun/star/sdb/DocumentSaveRequest.hpp>
41cdf0e10cSrcweir /** === end UNO includes === **/
42cdf0e10cSrcweir 
43cdf0e10cSrcweir namespace dbtools
44cdf0e10cSrcweir {
45cdf0e10cSrcweir 	class SQLExceptionInfo;
46cdf0e10cSrcweir }
47cdf0e10cSrcweir 
48cdf0e10cSrcweir //.........................................................................
49cdf0e10cSrcweir namespace dbaui
50cdf0e10cSrcweir {
51cdf0e10cSrcweir //.........................................................................
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 	//=========================================================================
54cdf0e10cSrcweir 	//= BasicInteractionHandler
55cdf0e10cSrcweir 	//=========================================================================
56cdf0e10cSrcweir 	typedef ::cppu::WeakImplHelper2	<	::com::sun::star::lang::XServiceInfo
57cdf0e10cSrcweir 									,	::com::sun::star::task::XInteractionHandler2
58cdf0e10cSrcweir 									>	BasicInteractionHandler_Base;
59cdf0e10cSrcweir 	/** implements an <type scope="com.sun.star.task">XInteractionHandler</type> for
60cdf0e10cSrcweir 		database related interaction requests.
61cdf0e10cSrcweir 		<p/>
62cdf0e10cSrcweir 		Supported interaction requests by now (specified by an exception: The appropriate exception
63cdf0e10cSrcweir 		has to be returned by the getRequest method of the object implementing the
64cdf0e10cSrcweir 		<type scope="com.sun.star.task">XInteractionRequest</type> interface.
65cdf0e10cSrcweir 			<ul>
66cdf0e10cSrcweir 				<li><b><type scope="com.sun.star.sdbc">SQLException</type></b>: requests to display a
67cdf0e10cSrcweir 					standard error dialog for the (maybe chained) exception given</li>
68cdf0e10cSrcweir 			</ul>
69cdf0e10cSrcweir 	*/
70cdf0e10cSrcweir 	class BasicInteractionHandler
71cdf0e10cSrcweir 				:public BasicInteractionHandler_Base
72cdf0e10cSrcweir 	{
73cdf0e10cSrcweir 		const OModuleClient m_aModuleClient;
74cdf0e10cSrcweir 		const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >
75cdf0e10cSrcweir 				            m_xORB;
76cdf0e10cSrcweir         const bool          m_bFallbackToGeneric;
77cdf0e10cSrcweir 
78cdf0e10cSrcweir     public:
79cdf0e10cSrcweir 		BasicInteractionHandler(
80cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& i_rORB,
81cdf0e10cSrcweir             const bool i_bFallbackToGeneric
82cdf0e10cSrcweir         );
83cdf0e10cSrcweir 
84cdf0e10cSrcweir         // XInteractionHandler2
85cdf0e10cSrcweir         virtual ::sal_Bool SAL_CALL handleInteractionRequest( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& Request ) throw (::com::sun::star::uno::RuntimeException);
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 	    // XInteractionHandler
88cdf0e10cSrcweir 		virtual void SAL_CALL handle( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& Request ) throw(::com::sun::star::uno::RuntimeException);
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 	protected:
91cdf0e10cSrcweir         sal_Bool
92cdf0e10cSrcweir                 impl_handle_throw( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& i_Request );
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 		/// handle SQLExceptions (and derived classes)
95cdf0e10cSrcweir 		void	implHandle(
96cdf0e10cSrcweir 					const ::dbtools::SQLExceptionInfo& _rSqlInfo,
97cdf0e10cSrcweir 					const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > >& _rContinuations);
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 		/// handle parameter requests
100cdf0e10cSrcweir 		void	implHandle(
101cdf0e10cSrcweir 					const ::com::sun::star::sdb::ParametersRequest& _rParamRequest,
102cdf0e10cSrcweir 					const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > >& _rContinuations);
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 		/// handle document save requests
105cdf0e10cSrcweir 		void	implHandle(
106cdf0e10cSrcweir 					const ::com::sun::star::sdb::DocumentSaveRequest& _rParamRequest,
107cdf0e10cSrcweir 					const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > >& _rContinuations);
108cdf0e10cSrcweir 
109cdf0e10cSrcweir         /// handles requests which are not SDB-specific
110cdf0e10cSrcweir         bool    implHandleUnknown(
111cdf0e10cSrcweir                     const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& _rxRequest );
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 		/// known continuation types
114cdf0e10cSrcweir 		enum Continuation
115cdf0e10cSrcweir 		{
116cdf0e10cSrcweir 			APPROVE,
117cdf0e10cSrcweir 			DISAPPROVE,
118cdf0e10cSrcweir 			RETRY,
119cdf0e10cSrcweir 			ABORT,
120cdf0e10cSrcweir 			SUPPLY_PARAMETERS,
121cdf0e10cSrcweir 			SUPPLY_DOCUMENTSAVE
122cdf0e10cSrcweir 		};
123cdf0e10cSrcweir 		/** check if a given continuation sequence contains a given continuation type<p/>
124cdf0e10cSrcweir 			@return		the index within <arg>_rContinuations</arg> of the first occurence of a continuation
125cdf0e10cSrcweir 						of the requested type, -1 of no such continuation exists
126cdf0e10cSrcweir 		*/
127cdf0e10cSrcweir 		sal_Int32 getContinuation(
128cdf0e10cSrcweir 			Continuation _eCont,
129cdf0e10cSrcweir 			const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > >& _rContinuations);
130cdf0e10cSrcweir 	};
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 	//=========================================================================
133cdf0e10cSrcweir 	//= SQLExceptionInteractionHandler
134cdf0e10cSrcweir 	//=========================================================================
135cdf0e10cSrcweir     class SQLExceptionInteractionHandler : public BasicInteractionHandler
136cdf0e10cSrcweir     {
137cdf0e10cSrcweir     public:
SQLExceptionInteractionHandler(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & i_rORB)138cdf0e10cSrcweir         SQLExceptionInteractionHandler(
139cdf0e10cSrcweir                 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& i_rORB
140cdf0e10cSrcweir             )
141cdf0e10cSrcweir             :BasicInteractionHandler( i_rORB, false )
142cdf0e10cSrcweir         {
143cdf0e10cSrcweir         }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir         // XServiceInfo
146cdf0e10cSrcweir 		DECLARE_SERVICE_INFO_STATIC();
147cdf0e10cSrcweir     };
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 	//=========================================================================
150cdf0e10cSrcweir 	//= SQLExceptionInteractionHandler
151cdf0e10cSrcweir 	//=========================================================================
152cdf0e10cSrcweir     /** an implementation for the legacy css.sdb.InteractionHandler
153cdf0e10cSrcweir 
154cdf0e10cSrcweir         css.sdb.InteractionHandler is deprecated, as it does not only handle database related interactions,
155cdf0e10cSrcweir         but also delegates all kind of unknown requests to a css.task.InteractionHandler.
156cdf0e10cSrcweir 
157cdf0e10cSrcweir         In today's architecture, there's only one central css.task.InteractionHandler, which is to be used
158cdf0e10cSrcweir         for all requests. Depending on configuration information, it decides which handler implementation
159cdf0e10cSrcweir         to delegate a request to.
160cdf0e10cSrcweir 
161cdf0e10cSrcweir         SQLExceptionInteractionHandler is the delegatee which handles only database related interactions.
162cdf0e10cSrcweir         LegacyInteractionHandler is the version which first checks for a database related interaction, and
163cdf0e10cSrcweir         forwards everything else to the css.task.InteractionHandler.
164cdf0e10cSrcweir     */
165cdf0e10cSrcweir     class LegacyInteractionHandler : public BasicInteractionHandler
166cdf0e10cSrcweir     {
167cdf0e10cSrcweir     public:
LegacyInteractionHandler(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & i_rORB)168cdf0e10cSrcweir         LegacyInteractionHandler(
169cdf0e10cSrcweir                 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& i_rORB
170cdf0e10cSrcweir             )
171cdf0e10cSrcweir             :BasicInteractionHandler( i_rORB, true )
172cdf0e10cSrcweir         {
173cdf0e10cSrcweir         }
174cdf0e10cSrcweir 
175cdf0e10cSrcweir         // XServiceInfo
176cdf0e10cSrcweir 		DECLARE_SERVICE_INFO_STATIC();
177cdf0e10cSrcweir     };
178cdf0e10cSrcweir 
179cdf0e10cSrcweir //.........................................................................
180cdf0e10cSrcweir }	// namespace dbaui
181cdf0e10cSrcweir //.........................................................................
182cdf0e10cSrcweir 
183cdf0e10cSrcweir #endif // _DBAUI_INTERACTION_HXX_
184cdf0e10cSrcweir 
185