package os2200gencode;
import com.unisys.os2200.connector.*;

import javax.resource.*;
import javax.resource.cci.*;


//
//  This class is generated from the annotations at build time
//  This code cannot be edited.
//
public class %transClassName  {


public %transClassName(){
	_tConn = new %connClassName();
}

public %transClassName(%connClassName tConnect){
	_tConn = tConnect;
}
private String _transName = "%transName";
private %connClassName _tConn;
private String _viewName = "%viewName";

/**
*  This invokes the transaction 
*  It will connect to the host if not already connected
*  Then, it will invoke the transaction with 
*   character buffer provided on the call
*  It will return the character buffer passed back by the transaction.
*/
public String callTrans(String datain)throws ResourceException{
	try{
	// check that the the application is connected to the host
	if (!_tConn.connected()){
	    _tConn.Connect();
	   }
	String returnData = "";
	// create an interaction class
	Interaction tact = _tConn.getNewInteraction();
	// create an interaction specification
	InteractionSpec tSpec = new OS2200InteractionSpec();
	//set the transaction name as the function name
	((OS2200InteractionSpec)tSpec).setFunctionName(_transName);
	OS2200Request recordIn  = new OS2200Request();	// record to be sent to 2200
	OS2200Request recordOut = new OS2200Request();	// record returned from 2200

	// indicate that we will wait for a response
	((OS2200InteractionSpec)tSpec).setInteractionVerb(InteractionSpec.SYNC_SEND_RECEIVE);
	recordIn.setRecordName(_viewName);
	recordIn.setData(datain);
 
	// invoke the transaction
		if (!(tact.execute(tSpec, recordIn, recordOut)))
			logit("ClientNonMgd: OS2200Interaction.execute failed!!!");
		else
			logit("ClientNonMgd: Completed call to ix.execute!!!");
		// to fix the UCF 81038392 :  The method getData() is undefined for the type OS2200Record - ManeyMR
		returnData = ((OS2200Record)recordOut).getRecordName();
		logit("ClientNonMgd: returnData: " + returnData);

// Close the resources
		tact.close();
//		_tConn.closeConnection();
	return returnData;
	}
	 catch (ResourceException re){
		 logit("callTrans",re);
		 throw new ResourceException("Error calling transaction",re.getCause());
	 }
}

public %connClassName getConnection(){
   return _tConn;
   }
   
   
private void logit(String msgIn, Throwable tt){
	System.out.println(msgIn + "\n" + tt.getLocalizedMessage());
	tt.printStackTrace();
}
private void logit(String msgIn ){
	System.out.println(msgIn );
}	
	
}
