001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)FakeXAResource.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.messaging;
030:
031: import java.util.HashMap;
032:
033: import javax.transaction.xa.XAResource;
034:
035: /** Simple utility class that implements a XAResource for testing.
036: * binding tests in independent threads.
037: * @author Sun Microsystems, Inc.
038: */
039: public class FakeXAResource implements XAResource {
040: private HashMap mXIDs;
041: private byte[] mXid;
042: private int mValue;
043:
044: FakeXAResource() {
045: mXIDs = new HashMap();
046: mValue = 0;
047: }
048:
049: public void setValue(Integer value) {
050: if (mXid == null) {
051: throw new java.lang.IllegalStateException();
052: }
053: if (mXIDs.get(mXid) == null) {
054: mXIDs.put(mXid, new Integer(mValue));
055: }
056: mValue = value.intValue();
057: }
058:
059: public int getValue() {
060: return (mValue);
061: }
062:
063: public void commit(javax.transaction.xa.Xid xid, boolean param)
064: throws javax.transaction.xa.XAException {
065: if (mXIDs.get(xid.getGlobalTransactionId()) != null) {
066: mXIDs.remove(xid.getGlobalTransactionId());
067: }
068: }
069:
070: public void end(javax.transaction.xa.Xid xid, int param)
071: throws javax.transaction.xa.XAException {
072: if (xid.getGlobalTransactionId().equals(mXid)) {
073: mXid = null;
074: } else {
075: throw new javax.transaction.xa.XAException();
076: }
077: }
078:
079: public void forget(javax.transaction.xa.Xid xid)
080: throws javax.transaction.xa.XAException {
081: mXIDs.remove(xid.getGlobalTransactionId());
082: }
083:
084: public int getTransactionTimeout()
085: throws javax.transaction.xa.XAException {
086: return (0);
087: }
088:
089: public boolean isSameRM(javax.transaction.xa.XAResource xAResource)
090: throws javax.transaction.xa.XAException {
091: return (true);
092: }
093:
094: public int prepare(javax.transaction.xa.Xid xid)
095: throws javax.transaction.xa.XAException {
096: if (mXIDs.get(xid.getGlobalTransactionId()) == null) {
097: return (XA_RDONLY);
098: }
099: return (XA_OK);
100: }
101:
102: public javax.transaction.xa.Xid[] recover(int param)
103: throws javax.transaction.xa.XAException {
104: return (null);
105: }
106:
107: public void rollback(javax.transaction.xa.Xid xid)
108: throws javax.transaction.xa.XAException {
109: Object o;
110:
111: if ((o = mXIDs.get(xid.getGlobalTransactionId())) != null) {
112: mValue = ((Integer) o).intValue();
113: mXIDs.remove(xid.getGlobalTransactionId());
114: }
115: }
116:
117: public boolean setTransactionTimeout(int param)
118: throws javax.transaction.xa.XAException {
119: return (false);
120: }
121:
122: public void start(javax.transaction.xa.Xid xid, int param)
123: throws javax.transaction.xa.XAException {
124: if (mXid == null) {
125: mXid = xid.getGlobalTransactionId();
126: if (mXIDs.get(mXid) == null) {
127: mXIDs.put(mXid, null);
128: }
129: } else {
130: throw new javax.transaction.xa.XAException();
131: }
132: }
133: }
|