00001
00002 #include "stdafx.h"
00003 #include "DecoratorError.h"
00004 #include "DecoratorSmart.h"
00005 #include <stdio.h>
00006
00007
00008
00009 hresult_exception::hresult_exception()
00010 {
00011 hr = 0;
00012 }
00013
00014 hresult_exception::hresult_exception(const hresult_exception &e)
00015 {
00016 hr = e.hr;
00017 }
00018
00019 hresult_exception::hresult_exception(HRESULT a)
00020 {
00021 hr = a;
00022 }
00023
00024 hresult_exception &hresult_exception::operator=(const hresult_exception &e)
00025 {
00026 hr = e.hr;
00027 return *this;
00028 }
00029
00030 hresult_exception &hresult_exception::operator=(HRESULT a)
00031 {
00032 hr = a;
00033 return *this;
00034 }
00035
00036 hresult_exception::~hresult_exception()
00037 {
00038 }
00039
00040 const char *hresult_exception::what() const
00041 {
00042 static char message[80];
00043 sprintf(message, "HRESULT (0x%08lx) exception", hr);
00044 return message;
00045 }
00046
00047
00048
00049 LPOLESTR common_descs[] =
00050 {
00051 OLESTR("Improper use of object"),
00052 OLESTR("Unknown exception"),
00053 OLESTR("Data conversion has failed"),
00054 OLESTR("Requested != count in GetAll"),
00055 OLESTR("[out] parameter is not empty"),
00056 OLESTR("Passed interface is not from the same project"),
00057 OLESTR("Object was not found"),
00058 OLESTR("File could not be opened"),
00059 OLESTR("VERIFY has failed"),
00060 OLESTR("COMTHROW test exception throwed"),
00061 };
00062
00063 LPOLESTR core_descs[] =
00064 {
00065 OLESTR("Object is locked by another Core component"),
00066 OLESTR("Lock value in Storage is invalid"),
00067 OLESTR("Attribute is not found"),
00068 OLESTR("Meta object is not found"),
00069 OLESTR("Meta project is invalid"),
00070 OLESTR("Invalid response from Repository"),
00071 OLESTR("CoreProject - CoreMetaProject mismatch"),
00072 OLESTR("Object is deleted or unloaded (zombie)"),
00073 OLESTR("Invalid ValueType"),
00074 OLESTR("No active transaction"),
00075 OLESTR("Object already exists"),
00076 OLESTR("No Territory has been selected"),
00077 OLESTR("Object is not locked"),
00078 OLESTR("Invalid data in Repository"),
00079 OLESTR("Cannot delete Object, has nonempty collection"),
00080 OLESTR("Cannot resolve the connection string"),
00081 OLESTR("Invalid binary file storage"),
00082 OLESTR("Project has no name"),
00083 };
00084
00085 LPOLESTR meta_descs[] =
00086 {
00087 OLESTR("Invalid ATTVAL type"),
00088 OLESTR("MetaProject is not open"),
00089 OLESTR("Invalid Path"),
00090 OLESTR("Invalid MetaRef")
00091 };
00092
00093 LPOLESTR parser_descs[] =
00094 {
00095 OLESTR("Invalid DTD file"),
00096 OLESTR("Invalid GUID"),
00097 OLESTR("Invalid XML filename"),
00098 OLESTR("Invalid MGA object"),
00099 OLESTR("Invalid META object"),
00100 OLESTR("Too many passes while parsing the XML file"),
00101 OLESTR("Invalid long value in XML file")
00102 };
00103
00104 void SetErrorInfo(LPOLESTR desc)
00105 {
00106 ASSERT( desc != NULL );
00107
00108 try
00109 {
00110 CComObjPtr<ICreateErrorInfo> errorinfo;
00111 COMTHROW( CreateErrorInfo(PutOut(errorinfo)) );
00112 COMTHROW( errorinfo->SetDescription(desc) );
00113 COMTHROW( errorinfo->SetSource(OLESTR("GME")) );
00114
00115 CComObjPtr<IErrorInfo> errorinfo2;
00116 COMTHROW( QueryInterface(errorinfo, errorinfo2) );
00117 COMTHROW( SetErrorInfo(0, errorinfo2) );
00118 }
00119 catch(hresult_exception &)
00120 {
00121
00122 }
00123 }
00124
00125 void SetErrorInfo(HRESULT hr, LPOLESTR desc2)
00126 {
00127 ASSERT( sizeof(common_descs)/sizeof(LPOLESTR) == (E_COMMON_LAST-E_COMMON_FIRST+1) );
00128 ASSERT( sizeof(core_descs)/sizeof(LPOLESTR) == (E_CORE_LAST-E_CORE_FIRST+1) );
00129 ASSERT( sizeof(meta_descs)/sizeof(LPOLESTR) == (E_META_LAST-E_META_FIRST+1) );
00130 ASSERT( sizeof(parser_descs)/sizeof(LPOLESTR) == (E_PARSER_LAST-E_PARSER_FIRST+1) );
00131
00132 LPOLESTR desc = NULL;
00133 if( E_COMMON_FIRST <= hr && hr <= E_COMMON_LAST ) desc = common_descs[hr - E_COMMON_FIRST];
00134 else if( E_CORE_FIRST <= hr && hr <= E_CORE_LAST ) desc = core_descs[hr - E_CORE_FIRST];
00135 else if( E_META_FIRST <= hr && hr <= E_META_LAST ) desc = meta_descs[hr - E_META_FIRST];
00136 else if( E_PARSER_FIRST <= hr && hr <= E_PARSER_LAST ) desc = parser_descs[hr - E_PARSER_FIRST];
00137
00138 if( desc2 == NULL )
00139 {
00140 if( desc != NULL )
00141 SetErrorInfo(desc);
00142 }
00143 else
00144 {
00145 CComBSTR d(desc);
00146 if( desc != NULL )
00147 d.Append(OLESTR(" :"));
00148
00149 d.Append(desc2);
00150 SetErrorInfo(d);
00151 }
00152 }
00153
00154 void GetErrorInfo(BSTR *desc)
00155 {
00156 ASSERT( desc != NULL );
00157
00158 try
00159 {
00160 CComObjPtr<IErrorInfo> errinfo;
00161 COMTHROW( GetErrorInfo(0, PutOut(errinfo)) );
00162 ASSERT( errinfo != NULL );
00163
00164 if( errinfo) COMTHROW( errinfo->GetDescription(desc) );
00165 }
00166 catch(hresult_exception &)
00167 {
00168
00169 }
00170 }
00171
00172 void GetErrorInfo(HRESULT hr, BSTR *p)
00173 {
00174 ASSERT( p != NULL );
00175
00176 LPOLESTR desc = NULL;
00177 if( E_COMMON_FIRST <= hr && hr <= E_COMMON_LAST ) desc = common_descs[hr - E_COMMON_FIRST];
00178 else if( E_CORE_FIRST <= hr && hr <= E_CORE_LAST ) desc = core_descs[hr - E_CORE_FIRST];
00179 else if( E_META_FIRST <= hr && hr <= E_META_LAST ) desc = meta_descs[hr - E_META_FIRST];
00180 else if( E_PARSER_FIRST <= hr && hr <= E_PARSER_LAST ) desc = parser_descs[hr - E_PARSER_FIRST];
00181
00182 if( desc != NULL )
00183 {
00184 SysFreeString(*p);
00185 *p = SysAllocString(desc);
00186 }
00187 else
00188 GetErrorInfo(p);
00189 }