InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
DBErrorUtils.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: Roey Horns
6 //
7 // $Author$
8 //
9 // $DateTime$
10 //
11 // $Revision$
12 //
13 // $Change$
14 //
15 // Copyright 1997-2010 Adobe Systems Incorporated. All rights reserved.
16 //
17 // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance
18 // with the terms of the Adobe license agreement accompanying it. If you have received
19 // this file from a source other than Adobe, then your use, modification, or
20 // distribution of it requires the prior written permission of Adobe.
21 //
22 //========================================================================================
23 
24 #ifndef __DBERRORUTILS__
25 #define __DBERRORUTILS__
26 
27 // ----- Interfaces -----
28 
29 #include "IDBErrorInfo.h"
30 #include "IDocument.h"
31 
32 // ----- Includes -----
33 
34 #include "CreateObject.h"
35 #include "InterfacePtr.h"
36 
37 // ----- Utility files -----
38 
39 #include "ErrorUtils.h"
40 #include "PersistUtils.h"
41 
42 // ----- ID.h files -----
43 
44 #include "ShuksanID.h"
45 
46 
48 {
49  // Helper methods to copy the local error of a database to the global error state.
50  // Each method clears the local error of the database.
51 
52  public:
53 
54  static void SetDBError(ErrorCode errCode, IDataBase::DBResultCode dbErr)
55  {
56  if(dbErr == IDataBase::kUserCanceled)
57  {
59  }
60  else
61  {
62  IDBErrorInfo *errInfo = (IDBErrorInfo *)::CreateObject(kDBErrorInfoBoss, IID_IDBERRORINFO);
63 
64  if(errInfo != nil)
65  errInfo->SetInfo(dbErr);
66 
67  ErrorUtils::PMSetGlobalErrorCode(errCode, nil, errInfo);
68 
69  if(errInfo != nil)
70  errInfo->Release();
71  }
72  }
73 
74  static void SetDBError(ErrorCode errCode, IDataBase* db)
75  {
76  if(db && db->GetErrorCode() == IDataBase::kUserCanceled)
77  {
79  }
80  else
81  {
82  IDBErrorInfo *errInfo = (IDBErrorInfo *)::CreateObject(kDBErrorInfoBoss, IID_IDBERRORINFO);
83 
84  if(errInfo != nil)
85  errInfo->SetInfo(db);
86 
87  ErrorUtils::PMSetGlobalErrorCode(errCode, nil, errInfo);
88 
89 
90  if(errInfo != nil)
91  errInfo->Release();
92  }
93  if(db != nil)
94  db->ClearError();
95  }
96 
97  static void SetDBError(ErrorCode errCode, IDocument* doc)
98  {
99  IDataBase *db = ::GetDataBase(doc);
100 
101  if(db && (db->GetErrorCode() == IDataBase::kUserCanceled))
102  {
104  }
105  else
106  {
107  IDBErrorInfo *errInfo = (IDBErrorInfo *)::CreateObject(kDBErrorInfoBoss, IID_IDBERRORINFO);
108 
109  if(errInfo != nil)
110  errInfo->SetInfo(doc);
111 
112  ErrorUtils::PMSetGlobalErrorCode(errCode, nil, errInfo);
113 
114 
115  if(errInfo != nil)
116  errInfo->Release();
117  }
118  if(doc != nil)
119  {
120  if(db != nil)
121  db->ClearError();
122  }
123  }
124 
125  static void SetDBError(ErrorCode errCode, const IDFile *file)
126  {
127  if (file != nil)
128  {
129  InterfacePtr<IDBErrorInfo> errInfo((IDBErrorInfo *)::CreateObject(kDBErrorInfoBoss, IID_IDBERRORINFO));
130  if(errInfo != nil)
131  {
132  errInfo->SetInfo(*file);
133  }
134  ErrorUtils::PMSetGlobalErrorCode(errCode, nil, errInfo);
135  }
136  else
137  {
139  }
140  }
141 };
142 
143 #endif // __DBERRORUTILS__