package com.eactive.eai.control;
//package com.eactive.eai.control;
//
//import javax.naming.Context;
//import javax.naming.InitialContext;
//import javax.naming.NamingException;
//import javax.transaction.Transaction;
//import javax.transaction.TransactionManager;
//import weblogic.transaction.TxHelper;
//
//import weblogic.wtc.jatmi.TPException;
//import weblogic.wtc.jatmi.TPReplyException;
//import weblogic.wtc.jatmi.Reply;
//import weblogic.wtc.jatmi.TypedString;
//import weblogic.wtc.gwt.TuxedoConnectionFactory;
//import weblogic.wtc.gwt.TuxedoConnection;
//import weblogic.wtc.jatmi.ApplicationToMonitorInterface;
//
//public class TuxedoStringSender {
//	private static final long serialVersionUID = 1L;
//	private int tpurcode;
//    private int tperrno;
//    
//	public int gettpurcode() {
//        return tpurcode;
//    }
//  
//    public int gettperrno() {
//        return tperrno;
//    }
//    
//	public byte[] service(String svcName, boolean isSync, boolean isXA, byte[] request)
//    throws TPException, TPReplyException {
//		Context ctx;
//		TuxedoConnectionFactory tcf = null;
//		TuxedoConnection tc = null;
//		TypedString tString;
//		Reply reply;
//		
//        //-----------------------------------------------------------------
//        // 1. Tuxedo의 TuxedoConnectionFactory를 생성한다.
//        //-----------------------------------------------------------------
//        try {
//			ctx = new InitialContext();
//			tcf = (TuxedoConnectionFactory)ctx.lookup("tuxedo.services.TuxedoConnection");
//		} catch (NamingException ne) {
//			// Could not get the tuxedo object, throw TPENOENT
//			throw new TPException(TPException.TPENOENT, 
//					"Could not get TuxedoConnectionFactory : " + ne);
//		}
//	
//		Transaction tx = null;
//        
//        TransactionManager tm = null;
//        try {
//            //-----------------------------------------------------------------
//            // 1. TX Begin.
//            //-----------------------------------------------------------------				
//		    // Suspend Orginal transaction
//            tx = TxHelper.getTransactionManager().suspend();
//            if(isXA) {
//                tm = (javax.transaction.TransactionManager)
//                    ctx.lookup("javax.transaction.TransactionManager");
//                tm.begin();
//            }
//                
//			//-----------------------------------------------------------------
//            // 2. TUXEDO 서비스를 호출한다.
//            // 3. tpurcode를 확인해서 commit/rollback 한다.
//            //-----------------------------------------------------------------	
//            tc = tcf.getTuxedoConnection();
//            
//            tString = new TypedString(new String(request));
//            if(isSync) {
//                reply = tc.tpcall(svcName, tString, ApplicationToMonitorInterface.TPNOTRAN);
//                tString = (TypedString)reply.getReplyBuffer();
//                if(tm != null) tm.commit();
//                String sMsg = tString.getStringBuffer().toString();
//                return (sMsg.getBytes());
//            }
//            else {
//                tc.tpacall(svcName, tString, ApplicationToMonitorInterface.TPNOREPLY);
//                return null;
//            }
//            
//		} catch (NamingException ne) {
//			try { if(tm != null) tm.rollback(); } catch(Exception e) { }
//            ne.printStackTrace();
//            throw new TPException(TPException.TPENOENT, 
//		    	"Could not get TuxedoConnectionFactory : " + ne);                
//		} catch (TPReplyException tre) {
//            try { if(tm != null) tm.rollback(); } catch(Exception e) { }
//            tperrno = tre.gettperrno();
//            tre.printStackTrace();
//			throw tre;
//		} catch (TPException te) {
//            try { if(tm != null) tm.rollback(); } catch(Exception e) { }
//            tperrno = te.gettperrno();
//            te.printStackTrace();
//            throw te;
//        } catch (Exception ex) {
//            try { if(tm != null) tm.rollback(); } catch(Exception e) { }
//            ex.printStackTrace();
//            throw new TPException(TPException.TPESYSTEM, "Exception: " + ex);
//		}
//        finally {
//            // Closing the association with Tuxedo			
//			if(tc != null) tc.tpterm();  
//            
//            if(tx != null) {
//                try {
//                    TxHelper.getTransactionManager().resume(tx);
//                } catch(Exception e) {   
//                }   
//            }
//        }
//	}
//    
//}
