1 22 package org.jboss.mq; 23 24 import java.io.IOException ; 25 import java.io.ObjectInput ; 26 import java.io.ObjectOutput ; 27 import java.io.Serializable ; 28 29 import javax.jms.Destination ; 30 31 40 public class SpyDestination implements Destination , Serializable 41 { 42 44 45 static final long serialVersionUID = -451227938651163471L; 46 47 48 protected final static int NULL = 0; 49 50 protected final static int OBJECT = 1; 51 52 protected final static int SPY_QUEUE = 2; 53 54 protected final static int SPY_TOPIC = 3; 55 56 protected final static int SPY_TEMP_QUEUE = 4; 57 58 protected final static int SPY_TEMP_TOPIC = 5; 59 60 62 63 protected String name; 64 65 66 protected int hash; 67 68 70 77 public static void writeDest(ObjectOutput out, Destination dest) throws IOException 78 { 79 if (dest == null) 80 out.writeByte(NULL); 81 else if (dest instanceof SpyTemporaryQueue) 82 { 83 out.writeByte(SPY_TEMP_QUEUE); 84 out.writeUTF(((SpyTemporaryQueue) dest).getName()); 85 } 86 else if (dest instanceof SpyTemporaryTopic) 87 { 88 out.writeByte(SPY_TEMP_TOPIC); 89 out.writeUTF(((SpyTemporaryTopic) dest).getName()); 90 } 91 else if (dest instanceof SpyQueue) 92 { 93 out.writeByte(SPY_QUEUE); 94 out.writeUTF(((SpyQueue) dest).getName()); 95 } 96 else if (dest instanceof SpyTopic) 97 { 98 out.writeByte(SPY_TOPIC); 99 out.writeUTF(((SpyTopic) dest).getName()); 100 DurableSubscriptionID id = ((SpyTopic) dest).durableSubscriptionID; 101 if (id == null) 102 { 103 out.writeByte(NULL); 104 } 105 else 106 { 107 out.writeByte(OBJECT); 108 writeString(out, id.getClientID()); 109 writeString(out, id.getSubscriptionName()); 110 writeString(out, id.getSelector()); 111 } 112 } 113 else 114 { 115 out.writeByte(OBJECT); 116 out.writeObject(dest); 117 } 118 } 119 120 127 public static Destination readDest(ObjectInput in) throws IOException 128 { 129 byte destType = in.readByte(); 130 if (destType == NULL) 131 return null; 132 else if (destType == SPY_TEMP_QUEUE) 133 return new SpyTemporaryQueue(in.readUTF(), null); 134 else if (destType == SPY_TEMP_TOPIC) 135 return new SpyTemporaryTopic(in.readUTF(), null); 136 else if (destType == SPY_QUEUE) 137 return new SpyQueue(in.readUTF()); 138 else if (destType == SPY_TOPIC) 139 { 140 String name = in.readUTF(); 141 destType = in.readByte(); 142 if (destType == NULL) 143 return new SpyTopic(name); 144 else 145 { 146 String clientId = readString(in); 147 String subName = readString(in); 148 String selector = readString(in); 149 return new SpyTopic(new SpyTopic(name), clientId, subName, selector); 150 } 151 } 152 else 153 { 154 try 155 { 156 return (Destination ) in.readObject(); 157 } 158 catch (ClassNotFoundException e) 159 { 160 throw new IOException ("Class not found for unknown destination."); 161 } 162 } 163 } 164 165 167 172 SpyDestination(String name) 173 { 174 this.name = name; 175 hash = name.hashCode(); 176 } 177 178 180 185 public String getName() 186 { 187 return name; 188 } 189 190 192 public int hashCode() 193 { 194 return hash; 195 } 196 197 199 201 203 210 private static void writeString(ObjectOutput out, String s) throws IOException 211 { 212 if (s == null) 213 out.writeByte(NULL); 214 else 215 { 216 out.writeByte(OBJECT); 217 out.writeUTF(s); 219 } 220 } 221 222 229 private static String readString(ObjectInput in) throws IOException 230 { 231 byte b = in.readByte(); 232 if (b == NULL) 233 return null; 234 else 235 return in.readUTF(); 236 } 237 238 } | Popular Tags |