1 22 package org.jboss.mq; 23 24 import java.io.Serializable ; 25 import java.util.Arrays ; 26 27 import javax.transaction.xa.Xid ; 28 29 37 public class JBossMQXid implements Serializable , Xid 38 { 39 40 private static final long serialVersionUID = -2227021688745286343L; 41 42 43 private int formatId; 44 45 46 private byte[] globalTransactionId; 47 48 49 private byte[] branchQualifier; 50 51 52 private transient String cachedToString; 53 54 55 private transient int cachedHashCode; 56 57 62 public JBossMQXid(Xid xid) 63 { 64 formatId = xid.getFormatId(); 65 globalTransactionId = xid.getGlobalTransactionId(); 66 branchQualifier = xid.getBranchQualifier(); 67 } 68 69 public int getFormatId() 70 { 71 return formatId; 72 } 73 74 public byte[] getGlobalTransactionId() 75 { 76 return globalTransactionId; 77 } 78 79 public byte[] getBranchQualifier() 80 { 81 return branchQualifier; 82 } 83 84 public boolean equals(Object object) 85 { 86 if (object == null || (object instanceof Xid ) == false) 87 return false; 88 89 Xid other = (Xid ) object; 90 return 91 ( 92 formatId == other.getFormatId() && 93 Arrays.equals(globalTransactionId, other.getGlobalTransactionId()) && 94 Arrays.equals(branchQualifier, other.getBranchQualifier()) 95 ); 96 } 97 98 public int hashCode() 99 { 100 if (cachedHashCode == 0) 101 { 102 cachedHashCode = formatId; 103 for (int i = 0; i < globalTransactionId.length; ++i) 104 cachedHashCode += globalTransactionId[i]; 105 } 106 return cachedHashCode; 107 } 108 109 public String toString() 110 { 111 if (cachedToString == null) 112 { 113 StringBuffer buffer = new StringBuffer (); 114 buffer.append("JBossMQXid[FormatId=").append(getFormatId()); 115 buffer.append(" GlobalId=").append(new String (getGlobalTransactionId()).trim()); 116 byte[] branchQualifer = getBranchQualifier(); 117 buffer.append(" BranchQual="); 118 if (branchQualifer == null) 119 buffer.append("null"); 120 else 121 buffer.append(new String (getBranchQualifier()).trim()); 122 buffer.append(']'); 123 cachedToString = buffer.toString(); 124 } 125 return cachedToString; 126 } 127 } | Popular Tags |