1 28 29 package org.apache.commons.transaction.util.xa; 30 31 import javax.transaction.xa.Xid ; 32 import java.lang.Object ; 33 import java.lang.String ; 35 36 43 public class XidWrapper implements Xid { 44 45 public static final Xid wrap(Xid xid) { 46 return wrap(xid, false); } 48 49 public static final Xid wrap(Xid xid, boolean includeBranch) { 50 return (xid instanceof XidWrapper ? xid : new XidWrapper(xid, includeBranch)); 51 } 52 53 private final Xid xid; 54 private final String asString; 55 private final int hashCode; 56 57 private XidWrapper(Xid xid, boolean includeBranch) { 58 this.xid = xid; 59 StringBuffer b = new StringBuffer (64); 61 b.append(new String (xid.getGlobalTransactionId())); 62 if (includeBranch) { 63 b.append("-").append(new String (xid.getBranchQualifier())); 64 } 65 66 asString = b.toString(); 67 hashCode = asString.hashCode(); 68 } 69 70 public Xid getXid() { 71 return xid; 72 } 73 74 public int getFormatId() { 75 return xid.getFormatId(); 76 } 77 78 public byte[] getGlobalTransactionId() { 79 return xid.getGlobalTransactionId(); 80 } 81 82 public byte[] getBranchQualifier() { 83 return xid.getBranchQualifier(); 84 } 85 86 public boolean equals(Object o) { 87 return (o != null && asString.equals(o.toString())); 88 103 } 104 105 public String toString() { 106 return asString; 107 } 108 109 public int hashCode() { 110 return hashCode; 111 } 112 } 113 | Popular Tags |