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.api.tx.Participant;
041: import com.sun.xml.ws.tx.at.ATCoordinator;
042: import com.sun.xml.ws.tx.at.ATParticipant;
043: import com.sun.xml.ws.tx.coordinator.CoordinationContextInterface;
044: import com.sun.xml.ws.tx.coordinator.CoordinationManager;
045: import com.sun.xml.ws.tx.coordinator.Coordinator;
046:
047: import javax.transaction.HeuristicMixedException;
048: import javax.transaction.HeuristicRollbackException;
049: import javax.transaction.RollbackException;
050: import javax.transaction.Synchronization;
051: import javax.transaction.SystemException;
052: import javax.transaction.Transaction;
053: import javax.transaction.xa.XAResource;
054: import java.util.HashMap;
055: import java.util.Map;
056:
057: //import com.sun.xml.ws.tx.webservice.member.at.CompletionInitiatorPortType;
058: //import com.sun.xml.ws.tx.webservice.member.coord.CoordinationContextType;
059:
060: /**
061: * Represents an WS-AT capable Transaction.
062: * <p/>
063: * <p>Also has reference to related Java EE transaction that it is associated with.
064: *
065: * @author jf39279
066: */
067: public class ATTransactionImpl implements ATTransaction {
068: // related Java EE transaction
069: final private Transaction txn;
070:
071: final private CoordinationContextInterface coordCtx;
072: final private ATCoordinator COORDINATOR;
073:
074: private static Map<String, ATTransactionImpl> coordIdATtxnMap = new HashMap<String, ATTransactionImpl>();
075:
076: static public ATTransactionImpl get(final String coordinationId) {
077: return coordIdATtxnMap.get(coordinationId);
078: }
079:
080: public void forget() {
081: coordIdATtxnMap.remove(coordCtx.getIdentifier());
082: }
083:
084: /**
085: * Creates a new instance of ATTransactionImpl
086: */
087: public ATTransactionImpl(Transaction jtaTxn,
088: CoordinationContextInterface coordCtx) {
089: this .txn = jtaTxn;
090: this .coordCtx = coordCtx;
091: COORDINATOR = (ATCoordinator) CoordinationManager.getInstance()
092: .getCoordinator(coordCtx.getIdentifier());
093: }
094:
095: public void commit() throws RollbackException,
096: HeuristicMixedException, HeuristicRollbackException,
097: SecurityException, IllegalStateException, SystemException {
098: //TODO: First pass only.
099: txn.commit();
100: }
101:
102: public boolean delistResource(final XAResource xAResource,
103: final int state) throws IllegalStateException,
104: SystemException {
105: // TODO: First pass only.
106: return txn.delistResource(xAResource, state);
107: }
108:
109: /**
110: * Wrapper XAResource as a participant and enlist with this transaction's coordinator.
111: * <p/>
112: * Contemplating removing this method but leave for now.
113: * <p/>
114: * XAResources from managed connections are automatically enlisted with Java EE transaction.
115: */
116: public boolean enlistResource(final XAResource xaResource)
117: throws RollbackException, IllegalStateException,
118: SystemException {
119: return txn.enlistResource(xaResource);
120:
121: }
122:
123: public boolean enlistParticipant(final Participant participant) {
124: final ATParticipant atParticipant = new ATParticipant(
125: getATCoordinator(), participant);
126: atParticipant.register();
127: return true;
128: }
129:
130: public void registerSynchronization(
131: final Synchronization synchronization)
132: throws RollbackException, IllegalStateException,
133: SystemException {
134: txn.registerSynchronization(synchronization);
135: }
136:
137: public void rollback() throws IllegalStateException,
138: SystemException {
139: txn.rollback();
140: }
141:
142: public void setRollbackOnly() throws IllegalStateException,
143: SystemException {
144: txn.setRollbackOnly();
145: }
146:
147: /**
148: * Get coordinator for this transaction.
149: */
150: private Coordinator getATCoordinator() {
151: return COORDINATOR;
152: }
153:
154: // TODO Support transaction created on remote Coordination Service
155: // Use WSAT Completion Protocol when transaction initiator process remote from coordinator service.
156: // (note: not typical case so not high priority to implement)
157: //private CompletionInitiatorPortType compWS;
158: //private javax.xml.ws.addressing.EndpointReference completionCoordinatorEPR;
159:
160: public int getStatus() throws SystemException {
161: throw new UnsupportedOperationException("Not yet implemented");
162: }
163: }
|