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

📄 mybeanimpl.java

📁 weblogic应用全实例
💻 JAVA
字号:
//声明本接口所在的包
package examples.rmi_iiop.ejb.simplified_idl;
//声明本接口引入的其他类
import javax.ejb.CreateException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.naming.InitialContext;
import javax.naming.NamingException;

//MyBean是个EJB的简单实例,这是MyBean实现类
//主要是实现两个远程方法:买进和卖出
public class MyBeanImpl implements SessionBean {

  private static final boolean VERBOSE = true;
  private SessionContext ctx;
  private int tradeLimit;

  // 运行记录的日志输出,也可以考虑使用WebLogic服务器的日志服务
  private void log(String s) {
    if (VERBOSE) System.out.println(s);
  } 
  
  /**
   * 这是SessionBean接口定义的方法,必须实现
   *
   */
  public void ejbActivate() {
    log("ejbActivate called");
  }

  /**
   * 这是SessionBean接口定义的方法,必须实现
   *
   */
  public void ejbRemove() {
    log("ejbRemove called");
  }

  /**
   * 这是SessionBean接口定义的方法,必须实现
   *
   */
  public void ejbPassivate() {
    log("ejbPassivate called");
  }

  /**
   * 设置会话上下文
   *
   * @参数 ctx               SessionContext 会话上下文
   */
  public void setSessionContext(SessionContext ctx) {
    log("setSessionContext called");
    this.ctx = ctx;
  }

  /**
   * 这个方法与接口"MyBeanHome.java"中的create方法相对应。
   * .
   * 当客户端调用MyBeanHome.create()方法时,容器分配一个EJBean的实例并调用ejbCreate()方法。
   *
   * @异常               javax.ejb.CreateException 如果发生通信或系统错误
   */
  public void ejbCreate () throws CreateException {
    log("ejbCreate called");

    tradeLimit = 100;
  }

  /**
   * 买进一定数量的股票.
   *
   * @参数 shares            买进股票的数量
   */
  public void buy(int shares) {

    if (shares > tradeLimit) {
      log("Attempt to buy "+shares+" is greater than limit of "+tradeLimit);
      shares = tradeLimit;
    }

    log("Buying "+shares+" shares");

    return;
  }

  /**
   * 卖出一定数量的股票
   *
   * @参数 shares            卖出股票的数量
   */
  public void sell(int shares) {

    if (shares > tradeLimit) {
      log("Attempt to sell "+shares+" is greater than limit of "+tradeLimit);
      shares = tradeLimit;
    }

    log("Selling "+shares+" shares");

    return;
  }

}








⌨️ 快捷键说明

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