/*
 * $Id: Transaction.vm 10787 2008-02-12 18:51:50Z dfeist $
 * --------------------------------------------------------------------------------------
 * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 *
 * The software in this package is published under the terms of the CPAL v1.0
 * license, a copy of which has been included with this distribution in the
 * LICENSE.txt file.
 */

package org.mule.transport.${TransportNameLower};

import org.mule.config.i18n.Message;
import org.mule.transaction.AbstractSingleResourceTransaction;
import org.mule.transaction.IllegalTransactionStateException;
import org.mule.api.TransactionException;


/**
 * <code>${TransportName}Transaction</code> is a wrapper for a
 * ${TransportName} local transaction. This object holds the tx resource and
 * controls the when the transaction committed or rolled back.
 *
 */
public class ${TransportName}Transaction extends AbstractSingleResourceTransaction
{
    /* For general guidelines on writing transports see
       http://mule.mulesource.org/display/MULE/Writing+Transports */

    public void bindResource(Object key, Object resource) throws TransactionException
    {
        /* IMPLEMENTATION NOTE: Validate as necessary, the resource here and
           then pass it to the super class to bind it to the key and also do
           any other specific binding here.  eg.

             try {
                 // TODO Validate Resource state here if necessary

             } catch (XXXException e) {
                 throw new IllegalTransactionStateException(new Message(Messages.TX_CANT_READ_STATE), e);
             }
        */

        super.bindResource(key, resource);
    }

    protected void doBegin() throws TransactionException
    {
        /* IMPLEMENTATION NOTE: Sometimes the resource has already begun the
           transaction when its been made available i.e. A transacted Jms
           Session doesn't have a .begin() method, because initiation is
           handled by the Jms provider.  eg.

             try {
                 // TODO begin transaction - i.e. <resource>.begin();
             } catch (XXXException e) {
                 throw new TransactionException(new Message(Messages.TX_COMMIT_FAILED), e);
             }
        */
    }

    protected void doCommit() throws TransactionException
    {
        /* IMPLEMENTATION NOTE: Commit the transaction here.  Throw an
           appropriate TransactionException on failure.  eg.

             try {
                 // TODO commit transaction - i.e. <resource>.commit();
             } catch (XXXException e) {
                 throw new TransactionException(new Message(Messages.TX_COMMIT_FAILED), e);
             }
        */
    }

    protected void doRollback() throws TransactionException
    {
        /* IMPLEMENTATION NOTE: Rollback the transaction here.  Throw an
           appropriate TransactionException on failure.  eg,

             try {
                 // TODO rollback transaction - i.e. <resource>.rollback();
             } catch (XXXException e) {
                 throw new TransactionException(new Message(Messages.TX_ROLLBACK_FAILED), e);
             }
        */
    }
}
