package org.omg.CosTransactions;

import org.omg.CORBA.portable.ObjectImpl;
import org.omg.CORBA.portable.Delegate;
import org.omg.CORBA.portable.OutputStream;
import org.omg.CORBA.portable.InputStream;
import org.omg.CORBA.portable.ServantObject;
import org.omg.CORBA.portable.ApplicationException;
import org.omg.CORBA.portable.RemarshalException;
import org.omg.CORBA.UNKNOWN;

/**
 * org.omg.CosTransactions.Resource Client Stub generated by the Idl2Java Compiler 3.1 of Jonathan
 */



public class _ResourceStub extends ObjectImpl implements Resource {
	private static String[] _ids = { org.omg.CosTransactions.ResourceHelper.id()};
	public _ResourceStub() {}
	public org.omg.CosTransactions.Vote prepare() throws org.omg.CosTransactions.HeuristicMixed,org.omg.CosTransactions.HeuristicHazard	{
		Delegate _d = _get_delegate();
		if (_d.is_local(this)) {
			ServantObject _servant = _d.servant_preinvoke(this,"prepare",ResourceOperations.class);
			if (_servant != null) {
				try {
					return ((ResourceOperations) _servant.servant).prepare();
				} finally {
					_d.servant_postinvoke(this,_servant);
				}
			}
		}
		OutputStream _ostream = _d.request(this,"prepare",true);
		// argument .... marshalling
		//reply
		try {
			InputStream _istream = _d.invoke(this,_ostream);
			org.omg.CosTransactions.Vote _ret;
			_ret =  org.omg.CosTransactions.VoteHelper.read(_istream);
			_d.releaseReply(this,_istream);
			return _ret;
		} catch (ApplicationException _e) {
			InputStream _istream = _e.getInputStream();
			String _id = _istream.read_string();
			if (_id.equals("IDL:omg.org/CosTransactions/HeuristicMixed:1.0")) {
				org.omg.CosTransactions.HeuristicMixed _user_excep;
				_user_excep =  org.omg.CosTransactions.HeuristicMixedHelper.read(_istream);
				_d.releaseReply(this,_istream);
				throw _user_excep;
			}
			else if (_id.equals("IDL:omg.org/CosTransactions/HeuristicHazard:1.0")) {
				org.omg.CosTransactions.HeuristicHazard _user_excep;
				_user_excep =  org.omg.CosTransactions.HeuristicHazardHelper.read(_istream);
				_d.releaseReply(this,_istream);
				throw _user_excep;
			}
			_d.releaseReply(this,_istream);
			throw new org.omg.CORBA.UNKNOWN("Unknown exception identifier");
		} catch (RemarshalException _e) {
			return prepare();
		}
	
}

	public void rollback() throws org.omg.CosTransactions.HeuristicCommit,org.omg.CosTransactions.HeuristicMixed,org.omg.CosTransactions.HeuristicHazard	{
		Delegate _d = _get_delegate();
		if (_d.is_local(this)) {
			ServantObject _servant = _d.servant_preinvoke(this,"rollback",ResourceOperations.class);
			if (_servant != null) {
				try {
					((ResourceOperations) _servant.servant).rollback();
					return;
				} finally {
					_d.servant_postinvoke(this,_servant);
				}
			}
		}
		OutputStream _ostream = _d.request(this,"rollback",true);
		// argument .... marshalling
		//reply
		try {
			InputStream _istream = _d.invoke(this,_ostream);
			_d.releaseReply(this,_istream);
			return ;
		} catch (ApplicationException _e) {
			InputStream _istream = _e.getInputStream();
			String _id = _istream.read_string();
			if (_id.equals("IDL:omg.org/CosTransactions/HeuristicCommit:1.0")) {
				org.omg.CosTransactions.HeuristicCommit _user_excep;
				_user_excep =  org.omg.CosTransactions.HeuristicCommitHelper.read(_istream);
				_d.releaseReply(this,_istream);
				throw _user_excep;
			}
			else if (_id.equals("IDL:omg.org/CosTransactions/HeuristicMixed:1.0")) {
				org.omg.CosTransactions.HeuristicMixed _user_excep;
				_user_excep =  org.omg.CosTransactions.HeuristicMixedHelper.read(_istream);
				_d.releaseReply(this,_istream);
				throw _user_excep;
			}
			else if (_id.equals("IDL:omg.org/CosTransactions/HeuristicHazard:1.0")) {
				org.omg.CosTransactions.HeuristicHazard _user_excep;
				_user_excep =  org.omg.CosTransactions.HeuristicHazardHelper.read(_istream);
				_d.releaseReply(this,_istream);
				throw _user_excep;
			}
			_d.releaseReply(this,_istream);
			throw new org.omg.CORBA.UNKNOWN("Unknown exception identifier");
		} catch (RemarshalException _e) {
			rollback();
		}
	
}

	public void commit() throws org.omg.CosTransactions.NotPrepared,org.omg.CosTransactions.HeuristicRollback,org.omg.CosTransactions.HeuristicMixed,org.omg.CosTransactions.HeuristicHazard	{
		Delegate _d = _get_delegate();
		if (_d.is_local(this)) {
			ServantObject _servant = _d.servant_preinvoke(this,"commit",ResourceOperations.class);
			if (_servant != null) {
				try {
					((ResourceOperations) _servant.servant).commit();
					return;
				} finally {
					_d.servant_postinvoke(this,_servant);
				}
			}
		}
		OutputStream _ostream = _d.request(this,"commit",true);
		// argument .... marshalling
		//reply
		try {
			InputStream _istream = _d.invoke(this,_ostream);
			_d.releaseReply(this,_istream);
			return ;
		} catch (ApplicationException _e) {
			InputStream _istream = _e.getInputStream();
			String _id = _istream.read_string();
			if (_id.equals("IDL:omg.org/CosTransactions/NotPrepared:1.0")) {
				org.omg.CosTransactions.NotPrepared _user_excep;
				_user_excep =  org.omg.CosTransactions.NotPreparedHelper.read(_istream);
				_d.releaseReply(this,_istream);
				throw _user_excep;
			}
			else if (_id.equals("IDL:omg.org/CosTransactions/HeuristicRollback:1.0")) {
				org.omg.CosTransactions.HeuristicRollback _user_excep;
				_user_excep =  org.omg.CosTransactions.HeuristicRollbackHelper.read(_istream);
				_d.releaseReply(this,_istream);
				throw _user_excep;
			}
			else if (_id.equals("IDL:omg.org/CosTransactions/HeuristicMixed:1.0")) {
				org.omg.CosTransactions.HeuristicMixed _user_excep;
				_user_excep =  org.omg.CosTransactions.HeuristicMixedHelper.read(_istream);
				_d.releaseReply(this,_istream);
				throw _user_excep;
			}
			else if (_id.equals("IDL:omg.org/CosTransactions/HeuristicHazard:1.0")) {
				org.omg.CosTransactions.HeuristicHazard _user_excep;
				_user_excep =  org.omg.CosTransactions.HeuristicHazardHelper.read(_istream);
				_d.releaseReply(this,_istream);
				throw _user_excep;
			}
			_d.releaseReply(this,_istream);
			throw new org.omg.CORBA.UNKNOWN("Unknown exception identifier");
		} catch (RemarshalException _e) {
			commit();
		}
	
}

	public void commit_one_phase() throws org.omg.CosTransactions.HeuristicHazard	{
		Delegate _d = _get_delegate();
		if (_d.is_local(this)) {
			ServantObject _servant = _d.servant_preinvoke(this,"commit_one_phase",ResourceOperations.class);
			if (_servant != null) {
				try {
					((ResourceOperations) _servant.servant).commit_one_phase();
					return;
				} finally {
					_d.servant_postinvoke(this,_servant);
				}
			}
		}
		OutputStream _ostream = _d.request(this,"commit_one_phase",true);
		// argument .... marshalling
		//reply
		try {
			InputStream _istream = _d.invoke(this,_ostream);
			_d.releaseReply(this,_istream);
			return ;
		} catch (ApplicationException _e) {
			InputStream _istream = _e.getInputStream();
			String _id = _istream.read_string();
			if (_id.equals("IDL:omg.org/CosTransactions/HeuristicHazard:1.0")) {
				org.omg.CosTransactions.HeuristicHazard _user_excep;
				_user_excep =  org.omg.CosTransactions.HeuristicHazardHelper.read(_istream);
				_d.releaseReply(this,_istream);
				throw _user_excep;
			}
			_d.releaseReply(this,_istream);
			throw new org.omg.CORBA.UNKNOWN("Unknown exception identifier");
		} catch (RemarshalException _e) {
			commit_one_phase();
		}
	
}

	public void forget()	{
		Delegate _d = _get_delegate();
		if (_d.is_local(this)) {
			ServantObject _servant = _d.servant_preinvoke(this,"forget",ResourceOperations.class);
			if (_servant != null) {
				try {
					((ResourceOperations) _servant.servant).forget();
					return;
				} finally {
					_d.servant_postinvoke(this,_servant);
				}
			}
		}
		OutputStream _ostream = _d.request(this,"forget",true);
		// argument .... marshalling
		//reply
		try {
			InputStream _istream = _d.invoke(this,_ostream);
			_d.releaseReply(this,_istream);
			return ;
		} catch (ApplicationException _e) {
			InputStream _istream = _e.getInputStream();
			String _id = _istream.read_string();
			_d.releaseReply(this,_istream);
			throw new org.omg.CORBA.UNKNOWN("Unknown exception identifier");
		} catch (RemarshalException _e) {
			forget();
		}
	
}

	public String[] _ids() {
		return _ids;
	}
}
