1 49 package org.exolab.jms.tranlog; 50 51 import java.io.Externalizable ; 52 import java.io.IOException ; 53 import java.io.ObjectInput ; 54 import java.io.ObjectOutput ; 55 56 57 68 public final class TransactionState 69 implements Externalizable { 70 71 75 static final long serialVersionUID = 1; 76 77 80 private String _state; 81 82 85 private int _ord; 86 87 88 91 public TransactionState() { 92 } 93 94 101 private TransactionState(String state, int ord) { 102 _state = state; 103 _ord = ord; 104 } 105 106 111 public int getOrd() { 112 return _ord; 113 } 114 115 120 public String toString() { 121 return _state; 122 } 123 124 131 public boolean equals(Object obj) { 132 boolean result = false; 133 134 if ((obj instanceof TransactionState) && 135 ((TransactionState) obj).getOrd() == getOrd()) { 136 result = true; 137 } 138 139 return result; 140 } 141 142 147 public boolean isOpened() { 148 return _ord == OPENED.getOrd(); 149 } 150 151 156 public boolean isPrepared() { 157 return _ord == PREPARED.getOrd(); 158 } 159 160 165 public boolean isClosed() { 166 return _ord == CLOSED.getOrd(); 167 } 168 169 170 public void writeExternal(ObjectOutput stream) 172 throws IOException { 173 stream.writeLong(serialVersionUID); 174 stream.writeObject(_state); 175 stream.writeInt(_ord); 176 } 177 178 public void readExternal(ObjectInput stream) 180 throws IOException , ClassNotFoundException { 181 long version = stream.readLong(); 182 if (version == serialVersionUID) { 183 _state = (String ) stream.readObject(); 184 _ord = stream.readInt(); 185 } else { 186 throw new IOException ("No support for TransactionState " + 187 "with version " + version); 188 } 189 } 190 191 194 public static final int OPENED_ORD = 1; 195 public static final int PREPARED_ORD = 2; 196 public static final int CLOSED_ORD = 3; 197 198 202 public static final TransactionState OPENED = new TransactionState("opened", OPENED_ORD); 203 public static final TransactionState PREPARED = new TransactionState("prepared", PREPARED_ORD); 204 public static final TransactionState CLOSED = new TransactionState("closed", CLOSED_ORD); 205 } 206 | Popular Tags |