001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.xml.ws.tx.common;
038:
039: import com.sun.xml.ws.api.tx.ATTransaction;
040: import com.sun.xml.ws.tx.coordinator.CoordinationContextInterface;
041:
042: import javax.transaction.HeuristicMixedException;
043: import javax.transaction.HeuristicRollbackException;
044: import javax.transaction.InvalidTransactionException;
045: import javax.transaction.NotSupportedException;
046: import javax.transaction.RollbackException;
047: import javax.transaction.SystemException;
048: import javax.transaction.Transaction;
049: import javax.transaction.TransactionManager;
050: import javax.transaction.TransactionSynchronizationRegistry;
051: import java.util.HashMap;
052: import java.util.Map;
053:
054: /**
055: * Inject WS-Coordination/WS-AtomicTransaction support into JTA 1.1 TransactionManager and
056: * TransactionSynchronizationRegistry.
057: * <p/>
058: *
059: * @author jf39279
060: */
061: public class ATTransactionManagerImpl implements TransactionManager {
062:
063: final private static ATTransactionManagerImpl singleton = new ATTransactionManagerImpl();
064: final private TransactionManager javaeeTM;
065: final private TransactionSynchronizationRegistry javaeeSynchReg;
066: final private Map<String, ATTransaction> coordIdTxnMap;
067:
068: static public ATTransactionManagerImpl getInstance() {
069: return singleton;
070: }
071:
072: public ATTransaction getTransaction(final String coordId) {
073: return coordIdTxnMap.get(coordId);
074: }
075:
076: /**
077: * Creates a new instance of TransactionManagerImpl
078: */
079: private ATTransactionManagerImpl() {
080: javaeeTM = TransactionManagerImpl.getInstance();
081: javaeeSynchReg = (TransactionSynchronizationRegistry) javaeeTM;
082: coordIdTxnMap = new HashMap<String, ATTransaction>();
083: }
084:
085: public void begin() throws NotSupportedException, SystemException {
086: javaeeTM.begin();
087: }
088:
089: public void commit() throws RollbackException,
090: HeuristicMixedException, HeuristicRollbackException,
091: SecurityException, IllegalStateException, SystemException {
092: javaeeTM.commit();
093: }
094:
095: public int getStatus() throws SystemException {
096: // TODO return ATCoordinator status mapped to java ee transaction status
097: // return javaeeTM.getStatus();
098: throw new UnsupportedOperationException("Not yet implemented");
099: }
100:
101: public javax.transaction.Transaction getTransaction()
102: throws SystemException {
103: ATTransaction result = null;
104: final Transaction jtaTxn = javaeeTM.getTransaction();
105: if (jtaTxn == null) {
106: return result;
107: }
108: CoordinationContextInterface cc = this .getCoordinationContext();
109: if (cc != null) {
110: result = getTransaction(cc.getIdentifier());
111: if (result == null) {
112: result = new ATTransactionImpl(jtaTxn, cc);
113: coordIdTxnMap.put(cc.getIdentifier(), result);
114: }
115: }
116: return result;
117: }
118:
119: public void resume(final Transaction transaction)
120: throws InvalidTransactionException, IllegalStateException,
121: SystemException {
122: javaeeTM.resume(transaction);
123: }
124:
125: public void rollback() throws IllegalStateException,
126: SecurityException, SystemException {
127: javaeeTM.rollback();
128: }
129:
130: public void setRollbackOnly() throws IllegalStateException {
131: javaeeSynchReg.setRollbackOnly();
132: }
133:
134: public void setTransactionTimeout(final int seconds)
135: throws SystemException {
136: javaeeTM.setTransactionTimeout(seconds);
137: }
138:
139: public Transaction suspend() throws SystemException {
140: return javaeeTM.suspend();
141: }
142:
143: /**
144: * Get the coordination context associated with the current transaction.
145: * <p/>
146: * Returns null if none set.
147: */
148: public CoordinationContextInterface getCoordinationContext() {
149: try {
150: return (CoordinationContextInterface) javaeeSynchReg
151: .getResource("WSCOOR-SUN");
152: } catch (IllegalStateException ise) {
153: return null; // no current JTA transaction, so return null
154: }
155: }
156:
157: /**
158: * Set the coordination context associated with the current transaction.
159: */
160: public void setCoordinationContext(
161: final CoordinationContextInterface coordinationCtx) {
162: javaeeSynchReg.putResource("WSCOOR-SUN", coordinationCtx);
163: }
164:
165: }
|