Bean是: package warehouse;
import javax.ejb.SessionBean; import javax.ejb.SessionContext; import javax.ejb.CreateException; import java.util.Hashtable;
public class WareHouseBean implements SessionBean { SessionContext sessionContext; Hashtable stocks;
public void ejbCreate() throws CreateException { stocks=new Hashtable(); stocks.put("货物1",new Double(10)); stocks.put("货物2",new Double(60)); stocks.put("货物3",new Double(30)); stocks.put("货物4",new Double(50)); stocks.put("货物5",new Double(20)); }
public void ejbRemove() { }
public void ejbActivate() { }
public void ejbPassivate() { }
public void setSessionContext(SessionContext sessionContext) { this.sessionContext = sessionContext; }
public Hashtable getStocks() { return stocks; }
public void addStock(String stockName,double stockQuantity) throws StockException{ if(stockName.trim().length()==0) throw new StockException("货物的名字为空."); if(stocks.get(stockName)==null){ stocks.put(stockName,new Double(stockQuantity)); //而这里的方法在客户端测试有效. } else{ double oriStockQuantity=((Double)stocks.get(stockName)).doubleValue(); double sum=oriStockQuantity+stockQuantity; // stocks.put(stockName,new Double(sum)); //这里的方法在客户端测试时无效 } }
public void minusStock(String stockName,double stockQuantity) throws StockException{ if(stockName.trim().length()==0) throw new StockException("货物的名字为空."); if(stocks.get(stockName)==null) throw new StockException("找不到该货物."); double oriStockQuantity=((Double)stocks.get(stockName)).doubleValue(); if(stockQuantity>oriStockQuantity){ throw new StockException("该货物的库存不够."); }else{ stocks.put(stockName,new Double(oriStockQuantity-stockQuantity)); }
}
public void removeStock(String stockName) throws StockException{ if(stockName.trim().length()==0) throw new StockException("货物的名字为空."); if(stocks.get(stockName)==null) throw new StockException("找不到该货物."); stocks.remove(stockName); }
public double getStock(String stockName) throws StockException{ if(stockName.trim().length()==0) throw new StockException("货物的名字为空."); if(stocks.get(stockName)==null) throw new StockException("找不到该货物."); double stockQuantity=((Double)stocks.get(stockName)).doubleValue(); return stockQuantity; }
}
----------------解决方案--------------------------------------------------------
用JbuilderX 运行会报以下错误: <The Remote interface method: 'public abstract void warehouse.WareHouse.addStock(java.lang.String,double) throws warehouse.StockException,java.rmi.RemoteException' in EJB 'WareHouse' contains a parameter of type: 'double' which is not Serializable. Though the EJB 'WareHouse' has call-by-reference set to false, The Remote interface method: 'public abstract void warehouse.WareHouse.minusStock(java.lang.String,double) throws warehouse.StockException,java.rmi.RemoteException' in EJB 'WareHouse' contains a parameter of type: 'double' which is not Serializable. Though the EJB 'WareHouse' has call-by-reference set to false, this parameter is not Serializable and hence will be passed by reference. A parameter can be passed using call-by-value only if the parameter type is Serializable. Call-by-reference is not enabled for the EJB 'WareHouse'. The server will have better performance if it is enabled. To enable call-by-reference, set the enable-call-by-reference element to True in the weblogic-ejb-jar.xml deployment descriptor for this EJB
- "WareHouse.jar": [J2EE:160127]ERROR: Could not delete previous archive: C:\Documents and Settings\Administrator.I-ROBOT\jbproject\WareHouse\WareHouse.jar 哪位前辈能帮忙看看啊.感激不尽.
----------------解决方案--------------------------------------------------------