public ManagedConnection createManagedConnection(Subject subject, ConnectionRequestInfo cri)
      throws javax.resource.ResourceException {
    if (xadsSelector == null) {
      return getXAManagedConnection(subject, cri);
    }

    // try to get a connection as many times as many urls we have in the list
    for (int i = 0; i < xadsSelector.getCustomSortedUrls().size(); ++i) {
      XAData xaData = (XAData) xadsSelector.getUrlObject();

      if (log.isTraceEnabled()) {
        log.trace("Trying to create an XA connection to " + xaData.url);
      }

      try {
        return getXAManagedConnection(subject, cri);
      } catch (ResourceException e) {
        log.warn("Failed to create an XA connection to " + xaData.url + ": " + e.getMessage());
        xadsSelector.failedUrlObject(xaData);
      }
    }

    // we have supposedly tried all the urls
    throw new JBossResourceException(
        "Could not create connection using any of the URLs: " + xadsSelector.getAllUrlObjects());
  }
 /* JSF navigation method (from trade.xhtml) */
 public String disconnect() {
   infoBox = "";
   try {
     connection.close();
     connection = null;
   } catch (ResourceException e) {
     log.info(e.getMessage());
   }
   return "index";
 }
 /* JSF navigation method (from index.xhtml) */
 public String connect() {
   String page = "index";
   if (connection == null) {
     try {
       log.info("[ResourceAccessBean] Getting connection from the RA");
       connection = connectionFactory.getConnection();
       page = "trade";
     } catch (ResourceException e) {
       log.info(e.getMessage());
     }
   }
   return page;
 }
  /*
   * @see com.atomikos.datasource.xa.XATransactionalResource#refreshXAConnection()
   */
  protected XAResource refreshXAConnection() throws ResourceException {
    if (LOGGER.isInfoEnabled()) {
      LOGGER.logInfo("refreshXAConnection() for resource: " + getName());
    }

    XAResource ret = null;
    if (connection != null) {
      try {
        connection.destroy();
      } catch (Exception normal) {
        // this can be expected, since this method is only called
        // if there is a connection problem
      }
    }

    try {

      LOGGER.logInfo("about to block for new connection...");
      // System.out.println ( "ABOUT TO BLOCK FOR NEW CONNECTION");
      connection = mcf.createManagedConnection(null, null);

    } catch (javax.resource.ResourceException e) {
      // ignore and return null: happens if resource is down
      // at this moment
      connection = null;
    } finally {
      // System.out.println ( "BLOCKING DONE");
      if (LOGGER.isInfoEnabled()) {
        LOGGER.logInfo("blocking done.");
      }
    }

    try {
      if (connection != null) ret = connection.getXAResource();
    } catch (javax.resource.ResourceException e) {
      LOGGER.logWarning("error getting XAResource: " + e.getMessage());

      throw new ResourceException("Error in getting XA resource", e);
    }

    LOGGER.logInfo("refreshXAConnection() done.");

    // System.out.println ( "DONE REFRESHXACONNECTION FOR RESOURCE: " +
    // getName() );

    return ret;
  }