/*
 * JBoss, Home of Professional Open Source
 * Copyright 2005, JBoss Inc., and individual contributors as indicated
 * by the @authors tag. See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * This 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 (at your option) any later version.
 *
 * This software 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 software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.jboss.tm.plugins.tyrex;

import java.rmi.RemoteException;

import org.omg.CosTransactions.HeuristicCommit;
import org.omg.CosTransactions.HeuristicMixed;
import org.omg.CosTransactions.HeuristicHazard;
import org.omg.CosTransactions.HeuristicRollback;
import org.omg.CosTransactions.NotPrepared;

import org.omg.CosTransactions.Vote;

import org.omg.CosTransactions.Resource;
import org.omg.CosTransactions._ResourceImplBase;


/**
 *   RMI Remote Proxy that enables the Coordinator on the originating
 *   side to control the subordinate transaction
 *
 *   @see ResourceRemoteInterface,  ResourceInvoker, CoordinatorRemote
 *   @author <a href="mailto:akkerman@cs.nyu.edu">Anatoly Akkerman</a>
 *   @version $Revision: 1.2.4.1 $
 */

public class ResourceRemote extends java.rmi.server.UnicastRemoteObject implements ResourceRemoteInterface {

  private _ResourceImplBase localResource;

  protected ResourceRemote(Resource resource) throws RemoteException{
    localResource = (_ResourceImplBase) resource;
  }

  public Vote prepare() throws HeuristicMixed, HeuristicHazard, RemoteException {
    //DEBUG    Logger.debug("ResourceRemote: preparing ...");
    return localResource.prepare();
  }

  public void rollback() throws HeuristicCommit, HeuristicMixed, HeuristicHazard, RemoteException {
    //DEBUG    Logger.debug("ResourceRemote: rolling back ...");
    localResource.rollback();
    //DEBUG    Logger.debug("ResourceRemote: rolled back.");
  }

  public void commit() throws NotPrepared, HeuristicRollback,
                       HeuristicMixed, HeuristicHazard, RemoteException {
    //DEBUG    Logger.debug("ResourceRemote: committing ...");
    localResource.commit();
    //DEBUG    Logger.debug("ResourceRemote: committed.");
  }

  public void commit_one_phase() throws HeuristicHazard, RemoteException {
    //DEBUG    Logger.debug("ResourceRemote: One phase committing ...");
    localResource.commit_one_phase();
    //DEBUG    Logger.debug("ResourceRemote: committed.");
  }

  public void forget() throws RemoteException{
    //DEBUG    Logger.debug("ResourceRemote: forgetting ...");
    localResource.forget();
    //DEBUG    Logger.debug("ResourceRemote: forgot.");
  }
}