⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 account.java

📁 BEA WebLogic Server 8.1大全 = BEA webLogic server 8.1 unleashed (美) Mark Artiges等著 袁毅 ... [等] 译 eng
💻 JAVA
字号:
package wlsunleashed.wtc;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import weblogic.wtc.gwt.TuxedoConnection;
import weblogic.wtc.gwt.TuxedoConnectionFactory;
import weblogic.wtc.jatmi.Ferror;
import weblogic.wtc.jatmi.FmlKey;
import weblogic.wtc.jatmi.Reply;
import weblogic.wtc.jatmi.TPException;
import weblogic.wtc.jatmi.TPReplyException;
import weblogic.wtc.jatmi.TypedFML;


public class Account {
	public static final boolean DEBUG = true;

	private int id = 0;

	public String getBalance() throws TPException, TPReplyException {

		String balance = "";
		Context ctx;
		TuxedoConnectionFactory tcf;
		TuxedoConnection myTux;
		TypedFML myData;
		TypedFML myDataBack;
		Reply myRtn;
		int status;

		try {
			ctx = getInitialContext();
			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);
		}
	
		myTux = tcf.getTuxedoConnection();

		myData = new TypedFML(new bankflds());
		;
		try {
			myData.Fchg(bankflds.ACCOUNT_ID,0, new Integer(getId()));
		} catch (Ferror fe) {
			log(
				"An error occured putting data into the FML32 buffer.  The error is "
					+ fe);
		}
		try {
			myRtn = myTux.tpcall("INQUIRY", myData, 0);
		} catch (TPReplyException tre) {
			log("tpcall threw TPReplyExcption " + tre);

			throw tre;
		} catch (TPException te) {
			log("tpcall threw TPException " + te);

			throw te;
		} catch (Exception ee) {
			log("tpcall threw exception: " + ee);

			throw new TPException(TPException.TPESYSTEM, "Exception: " + ee);
		}

		log("INQUIRY tpcall successfull!");

		myDataBack = (TypedFML) myRtn.getReplyBuffer();
		
		try {
			 balance = (String) myDataBack.Fget(bankflds.SBALANCE, 0);
		} catch (Ferror fe) {
			log(
				"An error occured getting data from the FML32 buffer.  The error is "
					+ fe);
		}

		myTux.tpterm(); // Closing the association with Tuxedo

		return balance;

	}

	/**
	 * Returns the id.
	 * @return long
	 */
	public int getId() {
		return id;
	}
	

	/**
	 * Sets the id.
	 * @param id The id to set
	 */
	public void setId(int id) {
		this.id = id;
	}
	private void log(String s) {
		if (DEBUG) {
			System.out.println(s);
		}
	}
	public static void main(String[] args) {
		Account acct = new Account();
		acct.setId(20004);
		try {
			acct.getBalance();
		} catch ( Exception e) {
			e.printStackTrace();
		}
	}
	


  /**
   * Using a Properties object will work on JDK 1.1.x and Java2
   * clients
   */
  private Context getInitialContext() throws NamingException {

    try {

      // Get an InitialContext
      Properties h = new Properties();

      h.put(Context.INITIAL_CONTEXT_FACTORY, 
            "weblogic.jndi.WLInitialContextFactory");
      h.put(Context.PROVIDER_URL, "t3://10.11.30.28:7001");

      return new InitialContext(h);
    } catch (NamingException ne) {
      log("We were unable to get a connection to the WebLogic server at " 
          + "localhost");
      log("Please make sure that the server is running.");

      throw ne;
    } 
  } 


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -