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