1 24 package org.objectweb.joram.shared.selectors; 25 26 import org.objectweb.joram.shared.excepts.MessageValueException; 27 import org.objectweb.joram.shared.messages.*; 28 29 import java.util.StringTokenizer ; 30 31 35 class Interpreter 36 { 37 48 static Object interpret(String name, Message message, String syntaxType) 49 { 50 if (syntaxType.equals("JMS")) 51 return jmsInterpret(name, message); 52 else 53 return null; 54 } 55 56 57 public static String wrapToString(Object value) 58 { 59 if (value == null) 60 return null; 61 62 if (value instanceof byte[]) 63 return new String ((byte[]) value); 64 else 65 return value.toString(); 66 } 67 68 74 private static Object jmsInterpret(String name, Message message) 75 { 76 Object value = null; 77 78 if (name.equals("JMSMessageID")) { 80 value = message.id; 81 } else if (name.equals("JMSPriority")) { 82 value = new Integer (message.priority); 83 } else if (name.equals("JMSTimestamp")) { 84 value = new Long (message.timestamp); 85 } else if (name.equals("JMSCorrelationID")) { 86 value = message.correlationId; 87 } else if (name.equals("JMSDeliveryMode")) { 88 if (message.persistent) 89 value = "PERSISTENT"; 90 else 91 value = "NON_PERSISTENT"; 92 } else if (name.equals("JMSType")) { 93 value = wrapToString(message.getOptionalHeader("JMSType")); 94 } else if (name.startsWith("JMSX")) { 95 if (name.equals("JMSXDeliveryCounts")) 96 value = new Integer (message.deliveryCount); 98 else 99 value = message.getOptionalHeader(name); 100 } else if (name.equals("JMS_JORAM_DELETEDDEST")) { 101 value = new Boolean (message.deletedDest); 103 } else if (name.equals("JMS_JORAM_NOTWRITEABLE")) { 104 value = new Boolean (message.notWriteable); 106 } else if (name.equals("JMS_JORAM_EXPIRED")) { 107 value = new Boolean (message.expired); 109 } else if (name.equals("JMS_JORAM_UNDELIVERABLE")) { 110 value = new Boolean (message.undeliverable); 112 } else { 113 value = message.getProperty(name); 115 } 116 117 if (value instanceof String ) { 120 StringTokenizer tokenizer = new StringTokenizer ((String )value, "'"); 121 StringBuffer buff = new StringBuffer (); 122 while (tokenizer.hasMoreTokens()) { 123 buff.append(tokenizer.nextToken()); 124 buff.append("''"); 125 } 126 String s = buff.toString(); 127 value = s.substring(0, s.length() - 2); 128 } 129 else if (value instanceof Number ) 130 value = new Double (((Number ) value).doubleValue()); 131 132 return value; 133 } 134 } 135 | Popular Tags |