创建部署的xml文件和bat文件

发表于:2007-07-01来源:作者:点击数: 标签:
createxml.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)
createxml.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 prim_key_class=request.getParameter("prim_key_class");
    String transaction_type=request.getParameter("transaction_type");
    String trans_attribute=request.getParameter("trans_attribute");
    String package_name=request.getParameter("package_name");

    File myFile=new File(ejb_name+"//ejb-jar.xml");
    myFile.createNewFile();
    PrintWriter pw_jar_xml=new PrintWriter(new FileWriter(myFile));

    pw_jar_xml.println("<?xml version=\"1.0\"?>");
    pw_jar_xml.println("<!DOCTYPE ejb-jar PUBLIC @#-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN@# @#http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd@#>");
    pw_jar_xml.println("<ejb-jar>");
    pw_jar_xml.println("    <enterprise-beans>");
    if(!ejb_type.equals("entity"))
    {
        pw_jar_xml.println("        <session>");
        pw_jar_xml.println("            <ejb-name>"+ejb_name+"</ejb-name>");
        if(package_name.equals(""))
        {
            pw_jar_xml.println("            <home>"+ejb_name+"Home</home>");
            pw_jar_xml.println("            <remote>"+ejb_name+"Remote</remote>");
            pw_jar_xml.println("            <ejb-class>"+ejb_name+"EJB</ejb-class>");
        }
        else
        {
            pw_jar_xml.println("            <home>"+package_name+"."+ejb_name+"Home</home>");
            pw_jar_xml.println("            <remote>"+package_name+"."+ejb_name+"Remote</remote>");
            pw_jar_xml.println("            <ejb-class>"+package_name+"."+ejb_name+"EJB</ejb-class>");
        }
        pw_jar_xml.println("            <session-type>"+ejb_type+"</session-type>");
        pw_jar_xml.println("            <transaction-type>"+transaction_type+"</transaction-type>");
        pw_jar_xml.println("        </session>");
    }
    else
    {
        pw_jar_xml.println("        <entity>");
        pw_jar_xml.println("            <ejb-name>"+ejb_name+"</ejb-name>");
        if(package_name.equals(""))
        {
            pw_jar_xml.println("            <home>"+ejb_name+"Home</home>");
            pw_jar_xml.println("            <remote>"+ejb_name+"Remote</remote>");
            pw_jar_xml.println("            <ejb-class>"+ejb_name+"EJB</ejb-class>");
        }
        else
        {
            pw_jar_xml.println("            <home>"+package_name+"."+ejb_name+"Home</home>");
            pw_jar_xml.println("            <remote>"+package_name+"."+ejb_name+"Remote</remote>");
            pw_jar_xml.println("            <ejb-class>"+package_name+"."+ejb_name+"EJB</ejb-class>");
        }
        
        String persistence_type=request.getParameter("persistence_type");
        String reentrant=request.getParameter("reentrant");
        String primkey_field=request.getParameter("primkey_field");

        pw_jar_xml.println("            <persistence-type>"+persistence_type+"</persistence-type>");
        pw_jar_xml.println("            <prim-key-class>java.lang."+prim_key_class+"</prim-key-class>");
        pw_jar_xml.println("            <reentrant>"+reentrant+"</reentrant>");
        pw_jar_xml.println("            <primkey-field>"+primkey_field+"</primkey-field>");
        pw_jar_xml.println("        </entity>");
    }
    pw_jar_xml.println("    </enterprise-beans>");

    pw_jar_xml.println("    <assembly-descriptor>");
    pw_jar_xml.println("        <container-transaction>");
    pw_jar_xml.println("            <method>");
    pw_jar_xml.println("                <ejb-name>"+ejb_name+"</ejb-name>");
    pw_jar_xml.println("                <method-intf>Remote</method-intf>");
    pw_jar_xml.println("                <method-name>*</method-name>");
    pw_jar_xml.println("            </method>");
    pw_jar_xml.println("            <trans-attribute>"+trans_attribute+"</trans-attribute>");
    pw_jar_xml.println("        </container-transaction>");
    pw_jar_xml.println("    </assembly-descriptor>");
    pw_jar_xml.println("</ejb-jar>");

    pw_jar_xml.close();
    
    if(server_type.equals("weblogic"))
    {
        myFile=new File(ejb_name+"//weblogic-ejb-jar.xml");
        myFile.createNewFile();
        PrintWriter pw_weblogic_xml=new PrintWriter(new FileWriter(myFile));

        pw_weblogic_xml.println("<?xml version=\"1.0\"?>");
        pw_weblogic_xml.println("<!DOCTYPE weblogic-ejb-jar PUBLIC @#-//BEA Systems, Inc.//DTD WebLogic 5.1.0 EJB//EN@# @#http://www.bea.com/servers/wls510/dtd/weblogic-ejb-jar.dtd@#>");
        pw_weblogic_xml.println("<weblogic-ejb-jar>");
        pw_weblogic_xml.println("    <weblogic-enterprise-bean>");
        pw_weblogic_xml.println("        <ejb-name>"+ejb_name+"</ejb-name>");
        pw_weblogic_xml.println("        <caching-descriptor>");

        String max=request.getParameter("max");
        String jndi_name=request.getParameter("jndi_name");

        if(!ejb_type.equals("entity"))
        {
            pw_weblogic_xml.println("            <max-beans-in-cache>"+max+"</max-beans-in-cache>");
        }
        else
        {
            pw_weblogic_xml.println("            <max-beans-in-free-pool>"+max+"</max-beans-in-free-pool>");
        }
        pw_weblogic_xml.println("        </caching-descriptor>");
        pw_weblogic_xml.println("        <jndi-name>"+jndi_name+"</jndi-name>");
        pw_weblogic_xml.println("    </weblogic-enterprise-bean>");
        pw_weblogic_xml.println("</weblogic-ejb-jar>");

        pw_weblogic_xml.close();
    }

    myFile=new File(ejb_name+"//build.bat");
    myFile.createNewFile();
    PrintWriter pw_build=new PrintWriter(new FileWriter(myFile));

    pw_build.println("mkdir build build\\META-INF");
    pw_build.println("copy *.xml build\\META-INF");
    pw_build.println();
    pw_build.println("javac -d build *.java");
    pw_build.println();
    pw_build.println("cd build");
    if(package_name.equals(""))
        pw_build.println("jar cv0f "+ejb_name+"EJB.jar META-INF .");
    else
    {
        int location=package_name.indexOf(".");
        if (location==-1)
            pw_build.println("jar cv0f "+ejb_name+"EJB.jar META-INF "+package_name);
        else
            pw_build.println("jar cv0f "+ejb_name+"EJB.jar META-INF "+package_name.substring(0,location));
    }
    pw_build.println("cd ..");
    pw_build.println();
    pw_build.println("java weblogic.ejbc -compiler javac build\\"+ejb_name+"EJB.jar build\\"+ejb_name+".jar");

    pw_build.close();
%>
<html>
<body>

<script language="javascript">
</script>

<center>
<font size="6" color="red">您要完成的ejb框架已经搭建完毕,所有文件在目录<%=ejb_name+"\\"%>下,填充并修改部分.java文件使其符合您使用的规格,双击build.bat完成ejb的创建<font>
</center>

</body>
</html>
    <%
}
catch(Exception e)
{
    out.print(e.getMessage());
}%>

原文转自:http://www.ltesting.net