1 46 47 package org.mr.core.util; 48 55 import java.util.Hashtable ; 56 import javax.jms.IllegalStateException ; 57 import javax.jms.InvalidDestinationException ; 58 import javax.jms.JMSException ; 59 import javax.jms.MessageEOFException ; 60 import javax.jms.MessageFormatException ; 61 import javax.jms.MessageNotReadableException ; 62 import javax.jms.MessageNotWriteableException ; 63 import javax.jms.TransactionInProgressException ; 64 65 public class ExceptionMonitor { 66 67 private final static int NUMBER_LENGTH = 5; 69 private static ExceptionMonitor instance = null; 71 72 private ExceptionMonitor() { } 74 75 static Hashtable messages; 77 static { 78 messages = new Hashtable (); 79 80 messages.put(new Integer (0),"CONNECTION CAN NOT BE INSTANTIATED WITHOUT A FACTORY"); 82 messages.put(new Integer (1),"CONNECTION COULD NOT BE CLOSED"); 83 messages.put(new Integer (2),"TEMPORARY TOPIC DOES NOT EXIST"); 84 messages.put(new Integer (3),"TEMPORARY DESTINATION DOES NOT EXIST"); 85 messages.put(new Integer (4),"QUEUE DOES NOT EXIST"); 86 messages.put(new Integer (5),"CAN NOT CREATE A SESSION ON A NULL CONNECTION"); 87 messages.put(new Integer (6),"CAN NOT USE A SESSION_TRANSACTED ACK MODE ON A NON-TRANSACTED SESSION"); 88 messages.put(new Integer (7),"DESTINATION DOES NOT EXIST"); 89 messages.put(new Integer (8),"AGENT ERROR ON REGISTRATION"); 90 messages.put(new Integer (9),"OPERATION NOT SUPPORTED"); 91 messages.put(new Integer (10),"CAN NOT CREATE A CONSUMER ON A NULL SESSION"); 92 93 messages.put(new Integer (12),"ILLEGAL DELIVERY MODE SUPPLIED"); 94 messages.put(new Integer (13),"ILLEGAL PRIORITY SUPPLIED"); 95 messages.put(new Integer (14),"MESSAGE TIME TO LIVE MUST NOT BE NEGATIVE"); 96 messages.put(new Integer (15),"CAN NOT DELIVER A NULL MESSAGE"); 97 messages.put(new Integer (16),"LISTENER FOR SERVER SESSION IS NULL"); 98 messages.put(new Integer (17),"METHOD NOT AVAILABLE FOR A SERVER SESSION"); 99 messages.put(new Integer (18),"AN IO ERROR OCCURED"); 100 messages.put(new Integer (19),"CAN NOT DELETE TEMPORARY DESTINATION"); 101 messages.put(new Integer (20),"THE APPLICATION SERVER HAD AN INTERNAL ERROR"); 102 messages.put(new Integer (21),"CAN NOT SEND MESSAGES FROM A CLOSED PRODUCER"); 103 messages.put(new Integer (22),"FAILED TO PRODUCE MESSAGES ON DESTINATION"); 104 messages.put(new Integer (23),"PRIORITY OUT OF VALID RANGE"); 105 106 107 messages.put(new Integer (201),"CAN NOT CHANGE A CLIENT ID. IT IS SYSTEM CONFIGURED"); 109 messages.put(new Integer (202),"ILLEGAL OPERATION - CONNECTION IS CLOSED"); 110 messages.put(new Integer (203),"INVALID ACK MODE SUPPLIED"); 111 messages.put(new Integer (204),"CAN NOT COMMIT A NON-TRANSACTED SESSION"); 112 messages.put(new Integer (205),"CAN NOT ROLLBACK A NON TRANSACTED SESSION"); 113 messages.put(new Integer (206),"CAN NOT RECOVER A TRANSACTED SESSION"); 114 messages.put(new Integer (207),"OPERATION UNALLOWED ON A CLOSED SESSION"); 115 messages.put(new Integer (208),"MESSAGE CAN NOT BE ACKED ON A NULL SESSION"); 116 messages.put(new Integer (209),"MESSAGE WILL NOT BE ACKED - WRONG ACK MODE IN USE"); 117 messages.put(new Integer (210),"CAN NOT CREATE A DURABLE SUBSCRIPTION ON A QUEUE"); 118 messages.put(new Integer (211),"CAN NOT CREATE A TOPIC SUBSCRIBER ON A QUEUE SESSION"); 119 messages.put(new Integer (212),"CAN NOT CREATE A TOPIC FROM A QUEUE SESSION"); 120 messages.put(new Integer (213),"CAN NOT UNSUBSCRIBE OFF A QUEUE SESSION"); 121 messages.put(new Integer (215),"PRODUCER IS CLOSED. OPERATION UNALLOWED"); 122 messages.put(new Integer (216),"CONSUMER IS CLOSED. OPERATION UNALLOWED"); 123 messages.put(new Integer (250),"PROPERTY NAME ILLEGAL (MUST NOT BE NULL OR EMPTY)"); 125 126 messages.put(new Integer (299),"CAN NOT SWITCH DESTINATION ON A FIXED-DESTINATION PRODUCER"); 128 messages.put(new Integer (300),"A NULL DESTINATION WAS SUPPLIED"); 129 messages.put(new Integer (302),"QUEUE DOES NOT EXIST"); 130 messages.put(new Integer (303),"CAN NOT REGISTER QUEUE, TOPIC MIGHT EXIST WITH SAME NAME"); 131 messages.put(new Integer (304),"CAN NOT REGISTER TOPIC, QUEUE MIGHT EXIST WITH SAME NAME"); 132 messages.put(new Integer (305),"CAN NOT PUBLISH TO A QUEUE USING JMS1.0.2 TopicPublisher. DESTINATION NAME IS"); 133 messages.put(new Integer (306),"CAN NOT SEND MESSAGE TO A TOPIC USING JMS1.0.2 QueueSender. DESTINATION NAME IS"); 134 messages.put(new Integer (401),"INVALID OPERATION. MESSAGE IS MARKED AS WRITE-ONLY"); 136 messages.put(new Integer (402),"WRONG MESSAGE FORMAT"); 137 messages.put(new Integer (403),"MESSAGE DOES NOT SUPPORT OBJECT OF TYPE"); 138 139 messages.put(new Integer (454),"THE MESSAGE IS NOT IN A WRITEABLE STATE"); 141 messages.put(new Integer (455),"ERROR IN OBJECT"); 142 messages.put(new Integer (456),"WRONG MESSAGE FORMAT"); 143 messages.put(new Integer (457),"MESSAGE AT END OF STREAM"); 145 146 messages.put(new Integer (458),"CAN NOT CONVERT TO BOOLEAN. SOURCE OBJECT IS"); 148 messages.put(new Integer (459),"CAN NOT CONVERT TO BYTE. SOURCE OBJECT IS"); 149 messages.put(new Integer (460),"CAN NOT CONVERT TO SHORT. SOURCE OBJECT IS"); 150 messages.put(new Integer (461),"CAN NOT CONVERT TO CHAR. SOURCE OBJECT IS"); 151 messages.put(new Integer (462),"CAN NOT CONVERT TO INTEGER. SOURCE OBJECT IS"); 152 messages.put(new Integer (463),"CAN NOT CONVERT TO LONG. SOURCE OBJECT IS"); 153 messages.put(new Integer (464),"CAN NOT CONVERT TO FLOAT. SOURCE OBJECT IS"); 154 messages.put(new Integer (465),"CAN NOT CONVERT TO DOUBLE. SOURCE OBJECT IS"); 155 messages.put(new Integer (466),"CAN NOT CONVERT A BYTE ARRAY TO STRING"); 156 messages.put(new Integer (467),"CAN NOT GET A BYTE ARRAY FROM"); 157 messages.put(new Integer (468),"INVALID OBJECT TYPE SUPPLIED"); 158 messages.put(new Integer (470),"MUST FINISH READING BYTES."); 159 messages.put(new Integer (481),"CAN NOT CALL COMMIT ON AN XA SESSION"); 161 messages.put(new Integer (482),"CAN NOT CALL ROLLBACK ON AN XA SESSION"); 162 163 } 164 165 public synchronized static ExceptionMonitor getInstance() { 167 if (instance == null) { 168 instance = new ExceptionMonitor(); 169 } 170 return instance; 171 172 } 173 174 public void shout(int key, String msg) throws JMSException { 178 179 StringBuffer text = new StringBuffer ((String ) messages.get(new Integer (key))); 180 if (text == null) 181 text = new StringBuffer ("99999E : UNKNOWN ERROR. CONTACT ADMINISTRATOR"); 182 else 183 text = new StringBuffer ("MNTA").append(stringOf(key)).append("E : ").append(text); 184 185 if (msg!=null) 186 text.append(" : <").append(msg).append(">"); 187 if (key<=200) 189 throw new JMSException (text.toString()); 190 else if (key<250) 191 throw new IllegalStateException (text.toString()); 192 else if (key==250) 193 throw new IllegalArgumentException (text.toString()); 194 else if (key<=300) 195 throw new UnsupportedOperationException (text.toString()); 196 else if (key<=400) 197 throw new InvalidDestinationException (text.toString()); 198 else if (key<=450) 199 throw new MessageNotReadableException (text.toString()); 200 else if (key==451) 201 throw new IndexOutOfBoundsException (text.toString()); 202 else if (key==452) 203 throw new NullPointerException (text.toString()); 204 else if (key==453||key==455||key==456) 205 throw new MessageFormatException (text.toString()); 206 else if (key==454) 207 throw new MessageNotWriteableException (text.toString()); 208 else if (key==457) 209 throw new MessageEOFException (text.toString()); 210 else if (key<=480) 211 throw new MessageFormatException (text.toString()); 212 else if (key<=485) 213 throw new TransactionInProgressException (text.toString()); 214 215 216 } 217 218 private StringBuffer stringOf(int key) { 219 220 StringBuffer num = new StringBuffer (String.valueOf(key)); 221 for (int i = num.length();i<NUMBER_LENGTH;i++) 222 num.insert(0,'0'); 223 224 return num; 225 } 226 } 227 228 | Popular Tags |