?? statefulshopbean.java
字號:
package stateful;
import javax.ejb.*;
import java.lang.*;
import java.util.*;
/*
*本類是一個無狀態會話EJB。
*必需實現SessionBean。
*/
public class StatefulShopBean implements SessionBean {
SessionContext sessionContext;
Vector goods;
/*
*方法說明:這個方法與StatefulShopHome.java中的主接口中的create()方法相對應,
*兩個方法的參數相同。當客戶端調用主接口的StatefulShopHome。create()方法是,
*容器將分配一個EJB實例,并調用它的ejbCreate()方法。
* @參數:
* @返回:
* @異常:CreateException 當系統創建EJB出錯時拋出
*/
public void ejbCreate() throws CreateException {
this.goods=new Vector();
}
/*
*方法說明:本方法必需實現,本例中沒有使用到。
*/
public void ejbRemove() {
}
/*
*方法說明:本方法必需實現,本例中沒有使用到。
*/
public void ejbActivate() {
}
/*
*方法說明:本方法必需實現,本例中沒有使用到。
*/
public void ejbPassivate() {
}
/*
*方法說明:設置會話上下文
* @參數:sessionContext
*/
public void setSessionContext(SessionContext sessionContext) {
this.sessionContext = sessionContext;
}
/*
*方法說明:添加商品
* @參數:id 商品id
* @參數:goods 商品名稱
* @參數:value 商品價格
* @返回:
* @異常:Exception 當增加資金為負數時
*/
public void addGoods(int id,String gds,double value) throws Exception {
if (value<0)
throw new Exception("Invalid value");
Vector gdsInfo = new Vector();
gdsInfo.addElement(new Integer(id));
gdsInfo.addElement(gds);
gdsInfo.addElement(new Double(value));
goods.addElement(gdsInfo);
}
/*
*方法說明:移除商品
* @參數:id 商品id
* @返回:
* @異常:Exception 當增加資金為負數和所提取資金超過賬戶上資金時
*/
public void removeGoods(int id) throws Exception {
try{
for(int i=0;i<goods.size();i++){
Vector vTemp = (Vector)goods.elementAt(i);
Object sTemp = vTemp.elementAt(0);
if(sTemp==null) throw new Exception("String is null");
int iTemp = Integer.parseInt(String.valueOf(sTemp));
if(iTemp==id){
goods.remove(i);
}
}
}catch(Exception e){
throw e;
}
}
/*
*方法說明:查詢商品
* @返回:Hashtable 商品信息
*/
public Vector seeGoods() {
return this.goods;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -