package org.omg.CosTransactions;

import org.omg.CORBA.BAD_OPERATION;
import org.omg.CORBA.portable.InputStream;
import org.omg.CORBA.portable.OutputStream;
import org.omg.CORBA.portable.InvokeHandler;
import org.omg.CORBA.portable.ResponseHandler;

import org.omg.CORBA.portable.ObjectImpl;


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



public class _ResourceImplBase extends ObjectImpl implements org.omg.CosTransactions.Resource, InvokeHandler {
	ResourceOperations _cont;
	private static String[] _ids = { org.omg.CosTransactions.ResourceHelper.id() };

	public _ResourceImplBase() {
				super();
				_cont = this;
	}

	public _ResourceImplBase(ResourceOperations continuation) {
				super();
				_cont = continuation;
	}


	protected int _getMethodSwitchKey(String _methName) {
				switch(_methName.charAt(0)) {
					case 'p' :  return 0;  //method prepare coded as prepare
					case 'r' :  return 1;  //method rollback coded as rollback
					case 'c' :
						if (_methName.length()==6)   return 2;  //operation commit coded as commit
						else   return 3;  //method commit_one_phase coded as commit_one_phase
					case 'f' :  return 4;  //method forget coded as forget
					default: return -1; // should never occur !!!
				}
	}


	public OutputStream _invoke(String _method,InputStream _istream,ResponseHandler _handler){
			switch(_getMethodSwitchKey(_method)) {
	case 0 : //method : prepare
				{
			//in and inout arguments unmarshaling
			OutputStream _ostream;
			try {
				//operation invocation on the target interface
				org.omg.CosTransactions.Vote _ret;
				_ret = _cont.prepare();
				_ostream = _handler.createReply();
				//out and inout arguments marshaling
				org.omg.CosTransactions.VoteHelper.write(_ostream,_ret);
			} catch (org.omg.CosTransactions.HeuristicMixed _e) {
				_ostream=_handler.createExceptionReply();
				String _eString="IDL:omg.org/CosTransactions/HeuristicMixed:1.0";
				_ostream.write_string(_eString);
				org.omg.CosTransactions.HeuristicMixedHelper.write(_ostream,_e);
			}
			catch (org.omg.CosTransactions.HeuristicHazard _e) {
				_ostream=_handler.createExceptionReply();
				String _eString="IDL:omg.org/CosTransactions/HeuristicHazard:1.0";
				_ostream.write_string(_eString);
				org.omg.CosTransactions.HeuristicHazardHelper.write(_ostream,_e);
			}
				return _ostream;
				}
	case 1 : //method : rollback
				{
			//in and inout arguments unmarshaling
			OutputStream _ostream;
			try {
				//operation invocation on the target interface
				_cont.rollback();
				_ostream = _handler.createReply();
				//out and inout arguments marshaling
			} catch (org.omg.CosTransactions.HeuristicCommit _e) {
				_ostream=_handler.createExceptionReply();
				String _eString="IDL:omg.org/CosTransactions/HeuristicCommit:1.0";
				_ostream.write_string(_eString);
				org.omg.CosTransactions.HeuristicCommitHelper.write(_ostream,_e);
			}
			catch (org.omg.CosTransactions.HeuristicMixed _e) {
				_ostream=_handler.createExceptionReply();
				String _eString="IDL:omg.org/CosTransactions/HeuristicMixed:1.0";
				_ostream.write_string(_eString);
				org.omg.CosTransactions.HeuristicMixedHelper.write(_ostream,_e);
			}
			catch (org.omg.CosTransactions.HeuristicHazard _e) {
				_ostream=_handler.createExceptionReply();
				String _eString="IDL:omg.org/CosTransactions/HeuristicHazard:1.0";
				_ostream.write_string(_eString);
				org.omg.CosTransactions.HeuristicHazardHelper.write(_ostream,_e);
			}
				return _ostream;
				}
	case 2 : //method : commit
				{
			//in and inout arguments unmarshaling
			OutputStream _ostream;
			try {
				//operation invocation on the target interface
				_cont.commit();
				_ostream = _handler.createReply();
				//out and inout arguments marshaling
			} catch (org.omg.CosTransactions.NotPrepared _e) {
				_ostream=_handler.createExceptionReply();
				String _eString="IDL:omg.org/CosTransactions/NotPrepared:1.0";
				_ostream.write_string(_eString);
				org.omg.CosTransactions.NotPreparedHelper.write(_ostream,_e);
			}
			catch (org.omg.CosTransactions.HeuristicRollback _e) {
				_ostream=_handler.createExceptionReply();
				String _eString="IDL:omg.org/CosTransactions/HeuristicRollback:1.0";
				_ostream.write_string(_eString);
				org.omg.CosTransactions.HeuristicRollbackHelper.write(_ostream,_e);
			}
			catch (org.omg.CosTransactions.HeuristicMixed _e) {
				_ostream=_handler.createExceptionReply();
				String _eString="IDL:omg.org/CosTransactions/HeuristicMixed:1.0";
				_ostream.write_string(_eString);
				org.omg.CosTransactions.HeuristicMixedHelper.write(_ostream,_e);
			}
			catch (org.omg.CosTransactions.HeuristicHazard _e) {
				_ostream=_handler.createExceptionReply();
				String _eString="IDL:omg.org/CosTransactions/HeuristicHazard:1.0";
				_ostream.write_string(_eString);
				org.omg.CosTransactions.HeuristicHazardHelper.write(_ostream,_e);
			}
				return _ostream;
				}
	case 3 : //method : commit_one_phase
				{
			//in and inout arguments unmarshaling
			OutputStream _ostream;
			try {
				//operation invocation on the target interface
				_cont.commit_one_phase();
				_ostream = _handler.createReply();
				//out and inout arguments marshaling
			} catch (org.omg.CosTransactions.HeuristicHazard _e) {
				_ostream=_handler.createExceptionReply();
				String _eString="IDL:omg.org/CosTransactions/HeuristicHazard:1.0";
				_ostream.write_string(_eString);
				org.omg.CosTransactions.HeuristicHazardHelper.write(_ostream,_e);
			}
				return _ostream;
				}
	case 4 : //method : forget
				{
			//in and inout arguments unmarshaling
			OutputStream _ostream;
				//operation invocation on the target interface
				_cont.forget();
				_ostream = _handler.createReply();
				//out and inout arguments marshaling
				return _ostream;
				}
	default : // unknown method name
				throw new BAD_OPERATION();
	}

	}
	public org.omg.CosTransactions.Vote prepare() throws org.omg.CosTransactions.HeuristicMixed,org.omg.CosTransactions.HeuristicHazard {
				if (_cont == this) {
				   throw new org.omg.CORBA.NO_IMPLEMENT("Method prepare not implemented by servant.");				}
				return _cont.prepare();
	}

	public void rollback() throws org.omg.CosTransactions.HeuristicCommit,org.omg.CosTransactions.HeuristicMixed,org.omg.CosTransactions.HeuristicHazard {
				if (_cont == this) {
				   throw new org.omg.CORBA.NO_IMPLEMENT("Method rollback not implemented by servant.");				}
				_cont.rollback();
	}

	public void commit() throws org.omg.CosTransactions.NotPrepared,org.omg.CosTransactions.HeuristicRollback,org.omg.CosTransactions.HeuristicMixed,org.omg.CosTransactions.HeuristicHazard {
				if (_cont == this) {
				   throw new org.omg.CORBA.NO_IMPLEMENT("Method commit not implemented by servant.");				}
				_cont.commit();
	}

	public void commit_one_phase() throws org.omg.CosTransactions.HeuristicHazard {
				if (_cont == this) {
				   throw new org.omg.CORBA.NO_IMPLEMENT("Method commit_one_phase not implemented by servant.");				}
				_cont.commit_one_phase();
	}

	public void forget() {
				if (_cont == this) {
				   throw new org.omg.CORBA.NO_IMPLEMENT("Method forget not implemented by servant.");				}
				_cont.forget();
	}

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

	public void _setContinuation(java.lang.Object continuation) {
	_cont = (ResourceOperations) continuation;
	}
}
