/*
 * JORAM: Java(TM) Open Reliable Asynchronous Messaging
 * Copyright (C) 2001 - 2022 ScalAgent Distributed Technologies
 * Copyright (C) 1996 - 2000 Dyade
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA.
 *
 * Initial developer(s): Frederic Maistre (INRIA)
 * Contributor(s): Nicolas Tachker (Bull SA)
 */
package org.ow2.joram.jakarta.jms;

import jakarta.jms.IllegalStateException;
import jakarta.jms.JMSException;

/**
 * Implements the <code>jakarta.jms.XAQueueConnection</code> interface.
 */
public class XAQueueConnection extends QueueConnection implements jakarta.jms.XAQueueConnection {

  /** Resource manager instance. */
  private XAResourceMngr rm;

  /**
   * Creates an <code>XAQueueConnection</code> instance.
   */
  public XAQueueConnection() {
    super();
    rm = new XAResourceMngr(this);
  }

//TODO (AF): To remove, overridden the method is useless. 
//  /**
//   * API method.
//   * Creates a QueueSession object.
//   * 
//   * @param transacted      indicates whether the session is transacted.
//   * @param acknowledgeMode indicates whether the consumer or the client will acknowledge any
//   *                        messages it receives; ignored if the session is transacted. Legal
//   *                        values are Session.AUTO_ACKNOWLEDGE, Session.CLIENT_ACKNOWLEDGE,
//   *                        and Session.DUPS_OK_ACKNOWLEDGE.
//   * @return A newly created session.
//   * 
//   * @exception IllegalStateException If the connection is closed.
//   * @exception JMSException In case of an invalid acknowledge mode.
//   */
//  @Override
//  public jakarta.jms.QueueSession createQueueSession(boolean transacted,
//                                                   int acknowledgeMode) throws JMSException {
//    return super.createQueueSession(transacted, acknowledgeMode);
//  }

  /**
   * API method.
   * Creates an XAQueueSession object.
   * 
   * @return  A newly created session.
   * 
   * @exception IllegalStateException If the connection is closed.
   */
  @Override
  public jakarta.jms.XAQueueSession createXAQueueSession() throws JMSException {
    checkClosed();
    QueueSession s = new QueueSession(this, true, 0, getRequestMultiplexer());
    XAQueueSession xas = new XAQueueSession(this, s, rm);
    addSession(s);
    return xas;
  }

//TODO (AF): To remove, overridden the method is useless. 
//  /**
//   * Method inherited from interface <code>XAConnection</code>.
//   * 
//   * @exception IllegalStateException If the connection is closed.
//   * @exception JMSException In case of an invalid acknowledge mode.
//   */
//  @Override
//  public jakarta.jms.Session createSession(boolean transacted,
//                                         int acknowledgeMode) throws JMSException {
//    return super.createSession(transacted, acknowledgeMode);
//  }

  /**
   * Method inherited from interface <code>XAConnection</code>.
   * 
   * @exception IllegalStateException If the connection is closed.
   */
  @Override
  public jakarta.jms.XASession createXASession() throws JMSException {
    checkClosed();
    Session s = new Session(this, true, 0, getRequestMultiplexer());
    XASession xas = new XASession(this, s, rm);
    addSession(s);
    return xas;
  }

  /**
   * return XAResourceMngr of this connection. see connector
   */
  public XAResourceMngr getXAResourceMngr() {
    return rm;
  }
}
