00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _ACTIVEMQ_UTIL_CMSEXCEPTIONSUPPORT_H_
00019 #define _ACTIVEMQ_UTIL_CMSEXCEPTIONSUPPORT_H_
00020
00021 #include <activemq/util/Config.h>
00022
00023 #include <cms/CMSException.h>
00024 #include <cms/CMSSecurityException.h>
00025 #include <cms/MessageEOFException.h>
00026 #include <cms/MessageFormatException.h>
00027 #include <cms/MessageNotReadableException.h>
00028 #include <cms/MessageNotWriteableException.h>
00029 #include <cms/InvalidClientIdException.h>
00030 #include <cms/InvalidDestinationException.h>
00031 #include <cms/InvalidSelectorException.h>
00032 #include <cms/IllegalStateException.h>
00033 #include <cms/ResourceAllocationException.h>
00034 #include <cms/TransactionInProgressException.h>
00035 #include <cms/TransactionRolledBackException.h>
00036 #include <cms/UnsupportedOperationException.h>
00037 #include <cms/XAException.h>
00038
00039 #include <decaf/lang/Exception.h>
00040
00041 #include <string>
00042
00043 namespace activemq {
00044 namespace util {
00045
00046 class AMQCPP_API CMSExceptionSupport {
00047 private:
00048
00049 CMSExceptionSupport();
00050
00051 public:
00052
00053 virtual ~CMSExceptionSupport();
00054
00055 static cms::CMSException create(const std::string& msg, const decaf::lang::Exception& cause);
00056
00057 static cms::CMSException create(const decaf::lang::Exception& cause);
00058
00059 static cms::MessageEOFException createMessageEOFException(const decaf::lang::Exception& cause);
00060
00061 static cms::MessageFormatException createMessageFormatException(const decaf::lang::Exception& cause);
00062
00063 };
00064
00065 }}
00066
00073 #define AMQ_CATCH_ALL_THROW_CMSEXCEPTION() \
00074 catch (cms::CMSSecurityException& ex) { \
00075 ex.setMark(__FILE__, __LINE__); \
00076 throw; \
00077 } catch (cms::IllegalStateException& ex) { \
00078 ex.setMark(__FILE__, __LINE__); \
00079 throw; \
00080 } catch (cms::InvalidClientIdException& ex) { \
00081 ex.setMark(__FILE__, __LINE__); \
00082 throw; \
00083 } catch (cms::InvalidDestinationException& ex) { \
00084 ex.setMark(__FILE__, __LINE__); \
00085 throw; \
00086 } catch (cms::InvalidSelectorException& ex) { \
00087 ex.setMark(__FILE__, __LINE__); \
00088 throw; \
00089 } catch (cms::MessageEOFException& ex) { \
00090 ex.setMark(__FILE__, __LINE__); \
00091 throw; \
00092 } catch (cms::MessageFormatException& ex) { \
00093 ex.setMark(__FILE__, __LINE__); \
00094 throw; \
00095 } catch (cms::MessageNotReadableException& ex) { \
00096 ex.setMark(__FILE__, __LINE__); \
00097 throw; \
00098 } catch (cms::MessageNotWriteableException& ex) { \
00099 ex.setMark(__FILE__, __LINE__); \
00100 throw; \
00101 } catch (cms::ResourceAllocationException& ex) { \
00102 ex.setMark(__FILE__, __LINE__); \
00103 throw; \
00104 } catch (cms::TransactionInProgressException& ex) { \
00105 ex.setMark(__FILE__, __LINE__); \
00106 throw; \
00107 } catch (cms::TransactionRolledBackException& ex) { \
00108 ex.setMark(__FILE__, __LINE__); \
00109 throw; \
00110 } catch (cms::UnsupportedOperationException& ex) { \
00111 ex.setMark(__FILE__, __LINE__); \
00112 throw; \
00113 } catch (cms::XAException& ex) { \
00114 ex.setMark(__FILE__, __LINE__); \
00115 throw; \
00116 } catch (cms::CMSException& ex) { \
00117 ex.setMark(__FILE__, __LINE__); \
00118 throw; \
00119 } catch (activemq::exceptions::ActiveMQException& ex) { \
00120 if (ex.getCause() != NULL) { \
00121 const std::exception* cause = ex.getCause(); \
00122 { \
00123 const cms::CMSSecurityException* exception = \
00124 dynamic_cast<const cms::CMSSecurityException*>(cause); \
00125 if (exception != NULL) { \
00126 throw cms::CMSSecurityException(*exception); \
00127 } \
00128 } \
00129 { \
00130 const cms::IllegalStateException* exception = \
00131 dynamic_cast<const cms::IllegalStateException*>(cause); \
00132 if (exception != NULL) { \
00133 throw cms::IllegalStateException(*exception); \
00134 } \
00135 } \
00136 { \
00137 const cms::InvalidClientIdException* exception = \
00138 dynamic_cast<const cms::InvalidClientIdException*>(cause); \
00139 if (exception != NULL) { \
00140 throw cms::InvalidClientIdException(*exception); \
00141 } \
00142 } \
00143 { \
00144 const cms::InvalidDestinationException* exception = \
00145 dynamic_cast<const cms::InvalidDestinationException*>(cause); \
00146 if (exception != NULL) { \
00147 throw cms::InvalidDestinationException(*exception); \
00148 } \
00149 } \
00150 { \
00151 const cms::InvalidSelectorException* exception = \
00152 dynamic_cast<const cms::InvalidSelectorException*>(cause); \
00153 if (exception != NULL) { \
00154 throw cms::InvalidSelectorException(*exception); \
00155 } \
00156 } \
00157 { \
00158 const cms::MessageEOFException* exception = \
00159 dynamic_cast<const cms::MessageEOFException*>(cause); \
00160 if (exception != NULL) { \
00161 throw cms::MessageEOFException(*exception); \
00162 } \
00163 } \
00164 { \
00165 const cms::MessageFormatException* exception = \
00166 dynamic_cast<const cms::MessageFormatException*>(cause); \
00167 if (exception != NULL) { \
00168 throw cms::MessageFormatException(*exception); \
00169 } \
00170 } \
00171 { \
00172 const cms::MessageNotReadableException* exception = \
00173 dynamic_cast<const cms::MessageNotReadableException*>(cause); \
00174 if (exception != NULL) { \
00175 throw cms::MessageNotReadableException(*exception); \
00176 } \
00177 } \
00178 { \
00179 const cms::MessageNotWriteableException* exception = \
00180 dynamic_cast<const cms::MessageNotWriteableException*>(cause); \
00181 if (exception != NULL) { \
00182 throw cms::MessageNotWriteableException(*exception); \
00183 } \
00184 } \
00185 { \
00186 const cms::ResourceAllocationException* exception = \
00187 dynamic_cast<const cms::ResourceAllocationException*>(cause); \
00188 if (exception != NULL) { \
00189 throw cms::ResourceAllocationException(*exception); \
00190 } \
00191 } \
00192 { \
00193 const cms::TransactionInProgressException* exception = \
00194 dynamic_cast<const cms::TransactionInProgressException*>(cause); \
00195 if (exception != NULL) { \
00196 throw cms::TransactionInProgressException(*exception); \
00197 } \
00198 } \
00199 { \
00200 const cms::TransactionRolledBackException* exception = \
00201 dynamic_cast<const cms::TransactionRolledBackException*>(cause); \
00202 if (exception != NULL) { \
00203 throw cms::TransactionRolledBackException(*exception); \
00204 } \
00205 } \
00206 { \
00207 const cms::UnsupportedOperationException* exception = \
00208 dynamic_cast<const cms::UnsupportedOperationException*>(cause); \
00209 if (exception != NULL) { \
00210 throw cms::UnsupportedOperationException(*exception); \
00211 } \
00212 } \
00213 { \
00214 const cms::XAException* exception = \
00215 dynamic_cast<const cms::XAException*>(cause); \
00216 if (exception != NULL) { \
00217 throw cms::XAException(*exception); \
00218 } \
00219 } \
00220 { \
00221 const cms::CMSException* exception = \
00222 dynamic_cast<const cms::CMSException*>(cause); \
00223 if (exception != NULL) { \
00224 throw cms::CMSException(*exception); \
00225 } \
00226 } \
00227 } \
00228 ex.setMark(__FILE__, __LINE__); \
00229 throw ex.convertToCMSException(); \
00230 } catch(decaf::lang::Exception& ex){ \
00231 ex.setMark(__FILE__, __LINE__); \
00232 activemq::exceptions::ActiveMQException amqEx(ex); \
00233 throw amqEx.convertToCMSException(); \
00234 } catch(std::exception& ex){ \
00235 throw cms::CMSException(ex.what(), NULL); \
00236 } catch(...) { \
00237 throw cms::CMSException("Caught Unknown Exception", NULL); \
00238 }
00239
00240 #endif