1 45 package org.exolab.jms.message; 46 47 import java.io.Externalizable ; 48 import java.io.IOException ; 49 import java.io.ObjectInput ; 50 import java.io.ObjectOutput ; 51 52 import org.exolab.jms.common.uuid.UUID; 53 54 55 61 final public class MessageId 62 implements Externalizable { 63 64 67 static final long serialVersionUID = 2; 68 69 72 private String _id = null; 73 74 77 public final static String PREFIX = "ID:"; 78 79 82 private static final String NULL_ID = "ID:0"; 83 84 85 88 public MessageId() { 89 } 90 91 96 public MessageId(String id) { 97 _id = id; 98 } 99 100 public String getId() { 101 return _id; 102 } 103 104 public int hashCode() { 106 return _id.hashCode(); 107 } 108 109 public void writeExternal(ObjectOutput out) throws IOException { 111 out.writeLong(serialVersionUID); 112 out.writeUTF(_id); 113 } 114 115 public void readExternal(ObjectInput in) 117 throws IOException , ClassNotFoundException { 118 119 long version = in.readLong(); 122 if (version == serialVersionUID) { 123 _id = in.readUTF(); 124 } else if (version == 1) { 125 long oldID = in.readLong(); String id = (String ) in.readObject(); 128 _id = PREFIX + id; 129 } else { 130 throw new IOException ("Incorrect version enountered: " + 131 version + " This version = " + 132 serialVersionUID); 133 } 134 } 135 136 public String toString() { 138 return _id; 139 } 140 141 public boolean equals(Object object) { 143 boolean equal = (object == this); 144 if (!equal) { 145 if (object instanceof MessageId && 146 ((MessageId) object)._id.equals(_id)) { 147 equal = true; 148 } 149 } 150 151 return equal; 152 } 153 154 159 public static String create() { 160 return UUID.next(PREFIX); 161 } 162 163 170 public static String getNull() { 171 return NULL_ID; 172 } 173 174 } 175 176 | Popular Tags |