xref: /trunk/main/framework/inc/loadstate.h (revision 06fea5eb)
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 #ifndef __FRAMEWORK_LOADSTATE_H_
25 #define __FRAMEWORK_LOADSTATE_H_
26 
27 //_________________________________________________________________________________________________________________
28 //	includes
29 //_________________________________________________________________________________________________________________
30 
31 #include <com/sun/star/ucb/InteractiveIOException.hpp>
32 #include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
33 
34 //_________________________________________________________________________________________________________________
35 //	namespace
36 //_________________________________________________________________________________________________________________
37 
38 namespace framework{
39 
40 //_______________________________________________________________________
41 /**
42     These enum values specify all possible results of a load request.
43     It doesn't matter, if this load operation used dispatch() or loadComponentFromURL().
44     The meaning is every time the same.
45  */
46 enum ELoadState
47 {
48     E_UNSPECIFIED   =   0,  // indicates the operation was not already started
49     E_SUCCESS       =   1,  // the load request was successful
50     E_IOERROR       =   2,  // there was an io error internally
51     E_INTERACTION   =   3,  // there was an interaction, which couldn't be handled (doesn't include IO interactions => see E_IOERROR before)
52     E_FAILED        =   4   // for unknown or unspecified errors
53 };
54 
55 //_______________________________________________________________________
56 /**
57     Helper, which provides some functionality to identify the reason for
58     a failed load request and can describe it.
59  */
60 class LoadStateHelper
61 {
62     public:
63 
64         //_________________________________
65         /**
66             @short      checks if the given interaction request was an io error
67             @descr      This information can be used to throw
68                         a suitable IOException. (e.g. loadComponentFromURL())
69 
70             @param      aRequest
71                             the original interaction request, which may produced
72                             the failed load request
73 
74             @param      rReason
75                             in case this Method returns <sal_True/> the referred string object
76                             will be used to set the original message of the
77                             aborted io exception on it.
78                             If method returns <sal_False/> rReason was not used.
79 
80             @return     [boolean]
81                             <sal_True/> in case it was an IO error
82                             <sal_False/> in case it wasn't an IO error or interaction was not used
83         */
wasIOError(const css::uno::Any & aRequest,rtl::OUString & rReason)84         static sal_Bool wasIOError( const css::uno::Any& aRequest ,
85                                           rtl::OUString& rReason  )
86         {
87             if ( ! aRequest.hasValue() )
88                 return sal_False;
89 
90             css::ucb::InteractiveIOException           exIOInteractive ;
91             css::ucb::InteractiveAugmentedIOException  exIOAugmented   ;
92 
93             if (aRequest>>=exIOInteractive)
94             {
95                 rReason = exIOInteractive.Message;
96                 return sal_True;
97             }
98 
99             if (aRequest>>=exIOAugmented)
100             {
101                 rReason = exIOAugmented.Message;
102                 return sal_True;
103             }
104 
105             return sal_False;
106         }
107 };
108 
109 } // namespace framework
110 
111 #endif // #ifndef __FRAMEWORK_LOADSTATE_H_
112