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: * @(#)FakeTransactionManager.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: import java.util.Random;
033:
034: import javax.transaction.Transaction;
035: import javax.transaction.TransactionManager;
036:
037: /** Simple utility class that implements a TransactionManager for testing.
038: * binding tests in independent threads.
039: * @author Sun Microsystems, Inc.
040: */
041: public class FakeTransactionManager implements
042: javax.transaction.TransactionManager {
043: private static TransactionManager mTM = new FakeTransactionManager();
044: private HashMap mThread;
045: private Random mRandom;
046:
047: public static TransactionManager getTM() {
048: return (mTM);
049: }
050:
051: private FakeTransactionManager() {
052: mThread = new HashMap();
053: mRandom = new Random();
054:
055: }
056:
057: public void begin() throws javax.transaction.NotSupportedException,
058: javax.transaction.SystemException {
059: Transaction x;
060: byte[] id = new byte[8];
061:
062: mRandom.nextBytes(id);
063: x = new FakeTransaction(this , id);
064: mThread.put(Thread.currentThread(), x);
065: }
066:
067: public void commit() throws javax.transaction.RollbackException,
068: javax.transaction.HeuristicMixedException,
069: javax.transaction.HeuristicRollbackException,
070: java.lang.SecurityException,
071: java.lang.IllegalStateException,
072: javax.transaction.SystemException {
073: Transaction x;
074: x = (Transaction) mThread.get(Thread.currentThread());
075: if (x == null) {
076: throw new javax.transaction.SystemException();
077: }
078: x.commit();
079: }
080:
081: public int getStatus() throws javax.transaction.SystemException {
082: Transaction x;
083: x = (Transaction) mThread.get(Thread.currentThread());
084: if (x == null) {
085: throw new javax.transaction.SystemException();
086: }
087:
088: return (x.getStatus());
089: }
090:
091: public javax.transaction.Transaction getTransaction()
092: throws javax.transaction.SystemException {
093: Transaction x;
094:
095: x = (Transaction) mThread.get(Thread.currentThread());
096: return (x);
097: }
098:
099: public void resume(javax.transaction.Transaction transaction)
100: throws javax.transaction.InvalidTransactionException,
101: java.lang.IllegalStateException,
102: javax.transaction.SystemException {
103: Transaction x;
104: x = (Transaction) mThread.get(Thread.currentThread());
105: if (x != null) {
106: throw new javax.transaction.SystemException();
107: }
108: mThread.put(Thread.currentThread(), transaction);
109: }
110:
111: public void rollback() throws java.lang.IllegalStateException,
112: java.lang.SecurityException,
113: javax.transaction.SystemException {
114: Transaction x;
115: x = (Transaction) mThread.get(Thread.currentThread());
116: if (x == null) {
117: throw new javax.transaction.SystemException();
118: }
119: x.rollback();
120: }
121:
122: public void setRollbackOnly()
123: throws java.lang.IllegalStateException,
124: javax.transaction.SystemException {
125: Transaction x;
126: x = (Transaction) mThread.get(Thread.currentThread());
127: if (x == null) {
128: throw new javax.transaction.SystemException();
129: }
130: x.setRollbackOnly();
131: }
132:
133: public void setTransactionTimeout(int param)
134: throws javax.transaction.SystemException {
135: }
136:
137: public javax.transaction.Transaction suspend()
138: throws javax.transaction.SystemException {
139: Transaction x;
140: x = (Transaction) mThread.get(Thread.currentThread());
141: if (x == null) {
142: throw new javax.transaction.SystemException();
143: }
144: mThread.remove(Thread.currentThread());
145: return (x);
146: }
147: }
|