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.gwt.TuxedoConnection;
//import weblogic.wtc.gwt.TuxedoConnectionFactory;
//import weblogic.wtc.jatmi.ApplicationToMonitorInterface;
//import weblogic.wtc.jatmi.CallDescriptor;
//import weblogic.wtc.jatmi.Reply;
//import weblogic.wtc.jatmi.TPException;
//import weblogic.wtc.jatmi.TPReplyException;
//import weblogic.wtc.jatmi.TypedFML;
//import weblogic.wtc.jatmi.TypedFML32;
//
//public class TuxedoFmlSender {
//	private static final long serialVersionUID = 1L;
//	private int tpurcode;
//    private int tperrno;
//    
//
//    public int gettpurcode() {
//        return tpurcode;
//    }
//    
//    public int gettperrno() {
//        return tperrno;
//    }
//    
//    public TypedFML32 service(String svcName, boolean isSync, boolean isXA, TypedFML32 infml) throws Exception
//    {
//   
//        Context ctx = null;
//        TuxedoConnectionFactory tcf = null;
//		TuxedoConnection tc = null;
//	     Reply reply;
//        
//        Transaction tx = null;
//        TransactionManager tm = null;
//        
//        try {
//            tx = TxHelper.getTransactionManager().suspend();
//            
//            ctx = new InitialContext(); 
//            
//            //-----------------------------------------------------------------
//            // 0. TX Begin if XA
//            //-----------------------------------------------------------------				
//            if(isXA) {
//	            tm = (javax.transaction.TransactionManager)
//	                ctx.lookup("javax.transaction.TransactionManager");
//				tm.begin();
//            }
//            
//            //-----------------------------------------------------------------
//            // 1. Tuxedo의 TuxedoConnectionFactory를 생성한다.
//            //-----------------------------------------------------------------						
//            tcf = (TuxedoConnectionFactory) ctx.lookup("tuxedo.services.TuxedoConnection");
//            tc = tcf.getTuxedoConnection();		
//            
//            //-----------------------------------------------------------------
//            // 2. TUXEDO 서비스를 호출한다.
//            //-----------------------------------------------------------------						
//	        if(isSync) {
//	        	if(isXA) {
//	            	reply = tc.tpcall(svcName, infml, ApplicationToMonitorInterface.TPTRAN);
//	            }
//	            else {
//	            	reply = tc.tpcall(svcName, infml, ApplicationToMonitorInterface.TPNOTRAN);
//	            }
//	        	tpurcode = reply.gettpurcode();
//	            if(isXA) {
//	            	if(tpurcode  < 0) {
//		                tm.rollback();
//		            }
//		            else {
//		                tm.commit();
//		            }
//	            }
//	            //-----------------------------------------------------------------
//	            // 3. tpurcode를 확인해서 commit/rollback 한다.
//	            //-----------------------------------------------------------------	
//	            
//	            return (TypedFML32)reply.getReplyBuffer();
//	        }
//	        else {
//	        	tc.tpacall(svcName, infml, 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) {   
//                }   
//            }
//        } 
//    }
//
//    public TypedFML32 TPFWDSVCXA(TypedFML32 infml) throws Exception
//    {
//  
//        Context ctx = null;
//        TuxedoConnectionFactory tcf;
//	    TuxedoConnection tuxConnection;
//	     Reply reply;
//        
//        Transaction tx = null;
//        
//        TransactionManager tm = null;
//        try {
//            tx = TxHelper.getTransactionManager().suspend();
//            
//            ctx = new InitialContext();
//            
//            //-----------------------------------------------------------------
//            // 1. Tuxedo의 TuxedoConnectionFactory를 생성한다.
//            //-----------------------------------------------------------------						
//            tcf = (TuxedoConnectionFactory) ctx.lookup("tuxedo.services.TuxedoConnection");
//            tuxConnection = tcf.getTuxedoConnection();		
//            
//            //-----------------------------------------------------------------
//            // 2. TUXEDO 서비스를 호출한다.
//            //-----------------------------------------------------------------						
//            reply = tuxConnection.tpcall("mnEaicomn_ms", infml, ApplicationToMonitorInterface.TPNOTRAN);
//            tuxConnection.tpterm();
//            //-----------------------------------------------------------------
//            // 3. tpurcode를 확인해서 commit/rollback 한다.
//            //-----------------------------------------------------------------	
//            tpurcode = reply.gettpurcode();
////System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"); 
////System.out.println("TuxedoFmlSender] TPFWDSVCXA tpurcode["+tpurcode+"]");           
////System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"); 
//           
//            return (TypedFML32)reply.getReplyBuffer();
//		} catch (NamingException ne) {
//            ne.printStackTrace();
//            throw new TPException(TPException.TPENOENT, 
//		    	"Could not get TuxedoConnectionFactory : " + ne);                
//		} catch (TPReplyException tre) {
//            tperrno = tre.gettperrno();
//            tre.printStackTrace();
//			throw tre;
//		} catch (TPException te) {
//			tperrno = te.gettperrno();
//            te.printStackTrace();
//            throw te;
//        } catch (Exception ex) {
//			ex.printStackTrace();
//            throw new TPException(TPException.TPESYSTEM, "Exception: " + ex);
//		}
//        finally {
//            if(tx!=null) {
//                try {
//                    TxHelper.getTransactionManager().resume(tx);
//                } catch(Exception e) {   
//                }   
//            }
//        } 
//    }
//    
//    public TypedFML32 TPFWDSVCNXA(TypedFML32 infml) throws Exception
//    {
//        Context ctx = null;
//        TuxedoConnectionFactory tcf;
//	    TuxedoConnection tuxConnection;
//	     Reply reply;
//        
//        Transaction tx = null;
//        
//        TransactionManager tm = null;
//        try {
//            tx = TxHelper.getTransactionManager().suspend();
//            
//            ctx = new InitialContext();
//            
//            //-----------------------------------------------------------------
//            // 1. Tuxedo의 TuxedoConnectionFactory를 생성한다.
//            //-----------------------------------------------------------------						
//            tcf = (TuxedoConnectionFactory) ctx.lookup("tuxedo.services.TuxedoConnection");
//            tuxConnection = tcf.getTuxedoConnection();		
//            
//            //-----------------------------------------------------------------
//            // 2. TUXEDO 서비스를 호출한다.
//            //-----------------------------------------------------------------						
//            reply = tuxConnection.tpcall("mnEaicomn_ss", infml, ApplicationToMonitorInterface.TPNOTRAN);
//            tuxConnection.tpterm();
//            //-----------------------------------------------------------------
//            // 3. tpurcode를 확인해서 commit/rollback 한다.
//            //-----------------------------------------------------------------	
//            tpurcode = reply.gettpurcode();
////System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"); 
////System.out.println("TuxedoFmlSender] TPFWDSVCNXA tpurcode["+tpurcode+"]");
////System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"); 
//            return (TypedFML32)reply.getReplyBuffer();
//		} catch (NamingException ne) {
//            ne.printStackTrace();
//            throw new TPException(TPException.TPENOENT, 
//		    	"Could not get TuxedoConnectionFactory : " + ne);                
//		} catch (TPReplyException tre) {
//            tperrno = tre.gettperrno();
//            tre.printStackTrace();
//			throw tre;
//		} catch (TPException te) {
//			tperrno = te.gettperrno();
//            te.printStackTrace();
//            throw te;
//        } catch (Exception ex) {
//			ex.printStackTrace();
//            throw new TPException(TPException.TPESYSTEM, "Exception: " + ex);
//		}
//        finally {
//            if(tx!=null) {
//                try {
//                    TxHelper.getTransactionManager().resume(tx);
//                } catch(Exception e) {   
//                }   
//            }
//        }  
//    }
//}
