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