va.util.*;
import java.rmi.*;
public interface VocHome extends javax.ejb.EJBHome
{
public Voc create() throws CreateException, RemoteException;
}
Remote接口:
package cacdsystem;
import javax.ejb.*;
import java.util.*;
import java.rmi.*;
public interface Voc extends javax.ejb.EJBObject
{
public Collection getVocTechnique() throws RemoteException;
}
bean类:
package cacdsystem;
import javax.ejb.*;
import java.util.*;
public class VocBean implements SessionBean
{
SessionContext sessionContext;
TechniquespecHome techniquespecHome;
public void ejbCreate() throws CreateException {}
public void ejbRemove() {}
public void ejbActivate() {}
public void ejbPassivate() {}
public void setSessionContext(SessionContext sessionContext)
{
this.sessionContext = sessionContext;
try
{
javax.naming.Context context = new javax.naming.InitialContext();
techniquespecHome = (TechniquespecHome)context.lookup("Techniquespec");
}
catch (Exception ex)
{
System.out.println("Techniquespecs调用出错!");
throw new EJBException(ex);
}
}
public java.util.Collection getVocTechnique()
{
/**@todo Complete this method*
//*** 获得全部技术需求项函数!*/
System.out.println("调用getVocTechnique()!");
java.util.Collection collection = null;
java.util.List results = new ArrayList();
try
{
collection= techniquespecHome.findByTypes();
if(collection.size() > 0)
{
System.out.println(collection.size());
Iterator iter = collection.iterator();
String tempStr = null;
Techniquespec techniqu = null;
while(iter.hasNext())
{
techniqu = (Techniquespec) iter.next();
tempStr = techniqu.getTechniqueitem();
tempStr = charASC.chinTOISO(tempStr);
results.add(tempStr);
}
}
}
catch (Exception ex)
{
ex.printStackTrace();
throw new EJBException(ex);
}
return results;
}
}
EJB技术之旅(二)(4)
时间:2010-12-10
说明:
(1)我们在Session Bean中添加了一个商务方法,getVocTechnique(),以获得techniqueitem中的全部内容。
(2)setSessionContext中,我们完成了EJB的一些初始化工作。(3) charASC.chinTOISO是用于中文转换的静态方法,代码如下:
package cacdsystem;
public class charASC
{
static private String results = null;
public charASC(){}
static public String chinTOISO(String temp)
{
if(temp == null)
{
results = "";
}
else
{
try
{
results = new String(temp.getBytes("ISO-8859-1"),"gb2312");
results = results.trim();
}
catch(Exception ee)
{
Sys
|