繁体中文
设为首页
加入收藏
当前位置:JSP技术首页 >> J2EE/EJB/服务器 >> 建立ejb各个接口和bean的大致框架的文件

建立ejb各个接口和bean的大致框架的文件

2004-10-01 08:26:10  作者:  来源:互联网  浏览次数:7  文字大小:【】【】【
简介:createfile.jsp <%@page contenttype="text/html;charset=gb2312"%> <%@page import="java.io.*"%> <% try {     String ejb_type=request.getParamet...

createfile.jsp

<%@page contenttype="text/html;charset=gb2312"%>

<%@page import="java.io.*"%>

<%

try

{

String ejb_type=request.getParameter("ejb_type");

String ejb_name=request.getParameter("ejb_name");

String server_type=request.getParameter("server_type");

String package_name=request.getParameter("package_name");

String Home_method=request.getParameter("Home_method").trim();

String Remote_method=request.getParameter("Remote_method").trim();

int location=0;

String temp="";

boolean isSession;

PrintWriter pw_Home=new PrintWriter(new FileWriter(ejb_name+"//"+ejb_name+"Home.java"));

PrintWriter pw_Remote=new PrintWriter(new FileWriter(ejb_name+"//"+ejb_name+"Remote.java"));

PrintWriter pw_EJB=new PrintWriter(new FileWriter(ejb_name+"//"+ejb_name+"EJB.java"));

if (!package_name.equals(""))

{

pw_Home.println("package "+package_name.trim()+";");

pw_Remote.println("package "+package_name.trim()+";");

pw_EJB.println("package "+package_name.trim()+";");

}

//bean接口贯穿于Home与Remote接口中

pw_EJB.println();

if (!ejb_type.equals("entity"))

{

//session

isSession=true;

pw_EJB.println("public class "+ejb_name+"EJB implements javax.ejb.SessionBean");

pw_EJB.println("{");

pw_EJB.println(" public void ejbRemove()");

pw_EJB.println(" {");

pw_EJB.println(" }");

pw_EJB.println();

pw_EJB.println(" public void ejbActivate()");

pw_EJB.println(" {");

pw_EJB.println(" }");

pw_EJB.println();

pw_EJB.println(" public void ejbPassivate()");

pw_EJB.println(" {");

pw_EJB.println(" }");

pw_EJB.println();

pw_EJB.println(" public void setSessionContext(javax.ejb.SessionContext sc)");

pw_EJB.println(" {");

pw_EJB.println(" }");

pw_EJB.println();

}

else

{

//entity

isSession=false;

pw_EJB.println("public class "+ejb_name+"EJB implements javax.ejb.EntityBean");

pw_EJB.println("{");

pw_EJB.println(" public void ejbRemove()");

pw_EJB.println(" {");

pw_EJB.println(" }");

pw_EJB.println();

pw_EJB.println(" public void ejbActivate()");

pw_EJB.println(" {");

pw_EJB.println(" }");

pw_EJB.println();

pw_EJB.println(" public void ejbPassivate()");

pw_EJB.println(" {");

pw_EJB.println(" }");

pw_EJB.println();

pw_EJB.println(" public void ejbLoad()");

pw_EJB.println(" {");

pw_EJB.println(" }");

pw_EJB.println();

pw_EJB.println(" public void ejbStore()");

pw_EJB.println(" {");

pw_EJB.println(" }");

pw_EJB.println();

pw_EJB.println(" public void unsetEntityContext()");

pw_EJB.println(" {");

pw_EJB.println(" }");

pw_EJB.println();

pw_EJB.println(" public void setEntityContext(javax.ejb.EntityContext ec)");

pw_EJB.println(" {");

pw_EJB.println(" }");

pw_EJB.println();

}

//Home interface

pw_Home.println();

pw_Home.println("public interface "+ejb_name+"Home extends javax.ejb.EJBHome");

pw_Home.println("{");

for(int i=0;i

{

if(Home_method.charAt(i)==10 || i==(Home_method.length()-1))

{

temp=Home_method.substring(location,i+1).trim();

//超界则退出

if(temp.length()<=1)break;

int temp_blank=temp.lastIndexOf(" ");

if (temp_blank==-1)

{

/* if(temp.indexOf("(")==-1)

{

pw_Home.print(" public "+ejb_name+"Remote "+temp+"() throws javax.rmi.RemoteException");

}

else

{

pw_Home.print(" public "+ejb_name+"Remote "+temp+" throws javax.rmi.RemoteException");

}

*/

response.sendRedirect("error.jsp");

}

else

{

//bean

if(temp.substring(temp_blank+1).equals(ejb_name+"Remote"))

{

//session 返回void remote 返回主键

if(isSession)

{

pw_EJB.print(" public void ejb"+temp.substring(0,1).toUpperCase()+temp.substring(0,temp_blank).substring(1));

}

else

{

String primaryKey=request.getParameter("primaryKey");

pw_EJB.print(" public "+primaryKey+" ejb"+temp.substring(0,1).toUpperCase()+temp.substring(0,temp_blank).substring(1));

}

}

else

{

pw_EJB.print(" public "+temp.substring(temp_blank+1)+" ejb"+temp.substring(0,1).toUpperCase()+temp.substring(0,temp_blank).substring(1));

}

if(temp.indexOf("(")==-1)

{

pw_Home.print(" public "+temp.substring(temp_blank+1)+" "+temp.substring(0,temp_blank)+"() throws javax.rmi.RemoteException");

pw_EJB.print(" () ");

}

else

{

pw_Home.print(" public "+temp.substring(temp_blank+1)+" "+temp.substring(0,temp_blank)+" throws javax.rmi.RemoteException");

}

}

//exception

if(temp.substring(0,6).equals("create"))

{

pw_Home.print(",javax.ejb.CreateException");

pw_EJB.print(" throws javax.ejb.CreateException");

}

else if(temp.substring(0,4).equals("find"))

{

pw_Home.print(",javax.ejb.FinderException");

pw_EJB.print(" throws javax.ejb.FinderException");

}

pw_Home.println(";");

pw_EJB.println();

pw_EJB.println(" {");

pw_EJB.println(" }");

pw_EJB.println();

location=i+1;

}

}

pw_Home.println("}");

location=0;

//Remote interface

pw_Remote.println();

pw_Remote.println("public interface "+ejb_name+"Remote extends javax.ejb.EJBObject");

pw_Remote.println("{");

for(int i=0;i

{

if(Remote_method.charAt(i)==10 || i==(Remote_method.length()-1))

{

temp=Remote_method.substring(location,i+1).trim();

//超界则退出

if(temp.length()<=1)break;

int temp_blank=temp.lastIndexOf(" ");

if (temp_blank==-1)

{

/* if(temp.indexOf("(")==-1)

{

pw_Remote.print(" public void "+temp+"() throws javax.rmi.RemoteException");

}

else

{

pw_Remote.print(" public void "+temp+" throws javax.rmi.RemoteException");

}

*/

response.sendRedirect("error.jsp");

}

else

{

if(temp.indexOf("(")==-1)

{

pw_Remote.print(" public "+temp.substring(temp_blank+1)+" "+temp.substring(0,temp_blank)+"() throws javax.rmi.RemoteException");

pw_EJB.print(" public "+temp.substring(temp_blank+1)+" "+temp.substring(0,temp_blank)+"()");

}

else

{

pw_Remote.print(" public "+temp.substring(temp_blank+1)+" "+temp.substring(0,temp_blank)+" throws javax.rmi.RemoteException");

pw_EJB.print(" public "+temp.substring(temp_blank+1)+" "+temp.substring(0,temp_blank));

}

}

pw_Remote.println(";");

pw_EJB.println();

pw_EJB.println(" {");

pw_EJB.println(" }");

pw_EJB.println();

location=i+1;

}

}

pw_Remote.println("}");

location=0;

pw_EJB.println("}");

pw_Home.close();

pw_Remote.close();

pw_EJB.close();

%>

现在进行Development Deploy配置(也即.xml的配置)

" method="post" name="form1" onsubmit="return err(form1,'<%=isSession%>','<%=server_type%>')">

<%if (ejb_type.equals("entity"))

{%>

<%}

if(server_type.equals("weblogic"))

{

%>

<%}%>

请选择事务处理的类型:

请选择事务的属性:

请选择持久行的类型:

reentrant:

请输入主键名称:

<%if(isSession)

{%>

请输入在缓存中最大的beans数:

<%}else{%>

请输入在pool池中最大的beans数:

<%}%>

请输入JNDI名称:

">

<%

}

catch(Exception e)

{

out.print(e.getMessage());

}%>

责任编辑:admin
相关文章