KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openejb > webadmin > ejbgen > BMPBean


1 /**
2  * Redistribution and use of this software and associated documentation
3  * ("Software"), with or without modification, are permitted provided
4  * that the following conditions are met:
5  *
6  * 1. Redistributions of source code must retain copyright
7  * statements and notices. Redistributions must also contain a
8  * copy of this document.
9  *
10  * 2. Redistributions in binary form must reproduce the
11  * above copyright notice, this list of conditions and the
12  * following disclaimer in the documentation and/or other
13  * materials provided with the distribution.
14  *
15  * 3. The name "OpenEJB" must not be used to endorse or promote
16  * products derived from this Software without prior written
17  * permission of The OpenEJB Group. For written permission,
18  * please contact dev@openejb.org.
19  *
20  * 4. Products derived from this Software may not be called "OpenEJB"
21  * nor may "OpenEJB" appear in their names without prior written
22  * permission of The OpenEJB Group. OpenEJB is a registered
23  * trademark of The OpenEJB Group.
24  *
25  * 5. Due credit should be given to the OpenEJB Project
26  * (http://www.openejb.org/).
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
29  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32  * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39  * OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Copyright 2001 (C) The OpenEJB Group. All Rights Reserved.
42  *
43  * $Id: BMPBean.java 1912 2005-06-16 22:29:56Z jlaskowski $
44  */

45 package org.openejb.webadmin.ejbgen;
46
47 /** BMP Entity Bean Template extending EJBTemplate
48  * @author <a HREF="mailto:jcscoobyrs@developerkb.com">Jeremy Whitlock</a>
49  */

50 import java.io.File JavaDoc;
51
52 public class BMPBean extends EJBTemplate
53 {
54     private String JavaDoc ejbname;
55     private String JavaDoc ejbdesc;
56     private String JavaDoc ejbauth;
57     private String JavaDoc ejbpack;
58     private String JavaDoc ejbsloc;
59     private String JavaDoc ejbstyp;
60     private File JavaDoc cdir;
61     private String JavaDoc objcode;
62     private String JavaDoc hmecode;
63     private String JavaDoc bencode;
64     private String JavaDoc ejbcode;
65     private String JavaDoc opecode;
66     private String JavaDoc pkcode;
67     
68     /**Constructor for BMP Entity EJB Bean Template
69      *
70      * @param name Name variable passed from form
71      * @param desc Description variable passed from form
72      * @param auth Author variable passed from form
73      * @param pack Package variable passed from form
74      * @param sloc Save Location variable passed from form
75      * @param styp Save Type variable passed from form
76      */

77     public BMPBean(String JavaDoc name, String JavaDoc desc, String JavaDoc auth, String JavaDoc pack, String JavaDoc sloc, String JavaDoc styp)
78     {
79         ejbname = name;
80         ejbdesc = desc;
81         ejbauth = auth;
82         ejbpack = pack;
83         ejbsloc = sloc;
84         ejbstyp = styp;
85         super.setVars(name,desc,auth,pack,sloc,styp);
86         cdir = new File JavaDoc(sloc);
87         createEJB();
88     }
89     
90     /**This method actually calls all methods to create
91      * the EJB Template
92      */

93     public void createEJB()
94     {
95         if(ejbpack.equals("") != true)
96         {
97             super.createPackage();
98         }
99         
100         super.createClass(ejbname,"Object.java");
101         createObjCode();
102         super.writeClass(ejbname + "Object.java", objcode);
103         super.createClass(ejbname,"Home.java");
104         createHmeCode();
105         super.writeClass(ejbname + "Home.java", hmecode);
106         super.createClass(ejbname,"Bean.java");
107         createBenCode();
108         super.writeClass(ejbname + "Bean.java", bencode);
109         createPKCode();
110         super.writeClass(ejbname + "PK.java", pkcode);
111         createEJBXML();
112         super.createXML("ejb-jar.xml", ejbcode);
113         super.buildZipFile();
114 // createOPEXML();
115
// super.createXML("openejb-jar.xml", opecode);
116
}
117     
118     /** This creates the code for the Remote Interface
119      *
120      */

121     public void createObjCode()
122     {
123         objcode = "/**\n";
124         objcode = objcode + "*@author " + ejbauth + "\n";
125         objcode = objcode + "**/\n\n";
126         objcode = objcode + "package " + ejbpack + ";\n\n";
127         objcode = objcode + "import java.rmi.*;\n";
128         objcode = objcode + "import javax.ejb.*;\n\n";
129         objcode = objcode + "public interface " + ejbname + "Object extends EJBObject\n";
130         objcode = objcode + "{\n\n";
131         objcode = objcode + "\tpublic void setData (String data) throws RemoteException;\n";
132         objcode = objcode + "\tpublic String getData () throws RemoteException;\n";
133         objcode = objcode + "}";
134     }
135     
136     /** This creates the code for the Home Interface
137      *
138      */

139     public void createHmeCode()
140     {
141         hmecode = "/**\n";
142         hmecode = hmecode + "*@author " + ejbauth + "\n";
143         hmecode = hmecode + "**/\n\n";
144         hmecode = hmecode + "package " + ejbpack + ";\n\n";
145         hmecode = hmecode + "import java.rmi.*;\n";
146         hmecode = hmecode + "import java.util.*;\n";
147         hmecode = hmecode + "import javax.ejb.*;\n\n";
148         hmecode = hmecode + "public interface " + ejbname + "Home extends EJBHome\n";
149         hmecode = hmecode + "{\n";
150         hmecode = hmecode + "\tpublic " + ejbname + "Object create() throws RemoteException, CreateException;\n";
151         hmecode = hmecode + "\tpublic " + ejbname + "Object findByPrimaryKey (" + ejbname + "PK pk) throws FinderException, RemoteException;\n";
152         hmecode = hmecode + "\tpublic " + ejbname + "Object remove() throws RemoteException, CreateException;\n";
153         hmecode = hmecode + "}";
154     }
155     
156     /** This creates the code for the Bean
157      *
158      */

159     public void createBenCode()
160     {
161         bencode = "/**\n";
162         bencode = bencode + "*@author " + ejbauth + "\n";
163         bencode = bencode + "**/\n\n";
164         bencode = bencode + "package " + ejbpack + ";\n\n";
165         bencode = bencode + "import java.sql.*;\n";
166         bencode = bencode + "import javax.sql.*;\n";
167         bencode = bencode + "import javax.naming.*;\n";
168         bencode = bencode + "import javax.ejb.*;\n\n";
169         bencode = bencode + "public class " + ejbname + "Bean implements EntityBean\n";
170         bencode = bencode + "{\n";
171         bencode = bencode + "\tprotected EntityContext ctx = null;\n";
172         bencode = bencode + "\tprotected int id;\n";
173         bencode = bencode + "\tprotected String data;\n\n";
174         bencode = bencode + "\tpublic void ejbCreate()\n";
175         bencode = bencode + "\t{\n";
176         bencode = bencode + "\t}\n\n";
177         bencode = bencode + "\tpublic void setData(String data)\n";
178         bencode = bencode + "\t{\n";
179         bencode = bencode + "\t\tthis.data = data;\n";
180         bencode = bencode + "\t}\n\n";
181         bencode = bencode + "\tpublic String getData()\n";
182         bencode = bencode + "\t{\n";
183         bencode = bencode + "\t\treturn this.data;\n";
184         bencode = bencode + "\t}\n\n";
185         bencode = bencode + "\tpublic void setId(int id)\n";
186         bencode = bencode + "\t{\n";
187         bencode = bencode + "\t\tthis.id = id;\n";
188         bencode = bencode + "\t}\n\n";
189         bencode = bencode + "\tpublic int getId()\n";
190         bencode = bencode + "\t{\n";
191         bencode = bencode + "\t\treturn this.id;\n";
192         bencode = bencode + "\t}\n\n";
193         bencode = bencode + "\tpublic void setEntityContext(EntityContext ctx)\n";
194         bencode = bencode + "\t{\n";
195         bencode = bencode + "\t\tthis.ctx = ctx;\n";
196         bencode = bencode + "\t}\n\n";
197         bencode = bencode + "\tpublic void unsetEntityContext()\n";
198         bencode = bencode + "\t{\n";
199         bencode = bencode + "\t\tthis.ctx = null;\n";
200         bencode = bencode + "\t}\n\n";
201         bencode = bencode + "\tpublic EntityContext getEntityContext()\n";
202         bencode = bencode + "\t{\n";
203         bencode = bencode + "\t\treturn this.ctx;\n";
204         bencode = bencode + "\t}\n";
205         bencode = bencode + "\tpublic void ejbActivate()\n";
206         bencode = bencode + "\t{\n";
207         bencode = bencode + "\t}\n\n";
208         bencode = bencode + "\tpublic void ejbPassivate()\n";
209         bencode = bencode + "\t{\n";
210         bencode = bencode + "\t}\n\n";
211         bencode = bencode + "\tpublic void ejbPostCreate()\n";
212         bencode = bencode + "\t{\n";
213         bencode = bencode + "\t}\n\n";
214         bencode = bencode + "\tpublic void ejbLoad()\n";
215         bencode = bencode + "\t{\n";
216         bencode = bencode + "\t}\n\n";
217         bencode = bencode + "\tpublic void ejbStore()\n";
218         bencode = bencode + "\t{\n";
219         bencode = bencode + "\t}\n\n";
220         bencode = bencode + "\tpublic void ejbRemove()\n";
221         bencode = bencode + "\t{\n";
222         bencode = bencode + "\t}\n\n";
223         bencode = bencode + "\tpublic void ejbFindByPrimaryKey()\n";
224         bencode = bencode + "\t{\n";
225         bencode = bencode + "\t}\n";
226         bencode = bencode + "}";
227     }
228     
229     /** This creates the code for the PrimaryKey
230      *
231      */

232     public void createPKCode()
233     {
234         pkcode = "/**\n";
235         pkcode = pkcode + "*@author " + ejbauth + "\n";
236         pkcode = pkcode + "**/\n\n";
237         pkcode = pkcode + "package " + ejbpack + ";\n\n";
238         pkcode = pkcode + "import java.io.*;\n\n";
239         pkcode = pkcode + "public class " + ejbname + "PK implements Serializable\n";
240         pkcode = pkcode + "{\n";
241         pkcode = pkcode + "\tpublic int id;\n\n";
242         pkcode = pkcode + "\tpublic " + ejbname + "PK()\n";
243         pkcode = pkcode + "\t{\n";
244         pkcode = pkcode + "\t\tthis.id = 0;\n";
245         pkcode = pkcode + "\t}\n\n";
246         pkcode = pkcode + "\tpublic " + ejbname + "PK(int id)\n";
247         pkcode = pkcode + "\t{\n";
248         pkcode = pkcode + "\t\tthis.id = id;\n";
249         pkcode = pkcode + "\t}\n\n";
250         pkcode = pkcode + "\tpublic int hashCode()\n";
251         pkcode = pkcode + "\t{\n";
252         pkcode = pkcode + "\t\treturn this.id;\n";
253         pkcode = pkcode + "\t}\n\n";
254         pkcode = pkcode + "\tpublic boolean equals(Object obj)\n";
255         pkcode = pkcode + "\t{\n";
256         pkcode = pkcode + "\t\tif (obj instanceof " + ejbname + "PK)\n";
257         pkcode = pkcode + "\t\t{\n";
258         pkcode = pkcode + "\t\t\treturn (id == ((" + ejbname + "PK)obj).id);\n";
259         pkcode = pkcode + "\t\t}\n";
260         pkcode = pkcode + "\t\treturn false;\n";
261         pkcode = pkcode + "\t}\n";
262         pkcode = pkcode + "}";
263     }
264
265     /** This creates the code for the ejb-xml.jar
266      *
267      */

268     public void createEJBXML()
269     {
270         String JavaDoc ejbstr;
271         
272         ejbstr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
273         ejbstr = ejbstr + "<ejb-jar>\n";
274         ejbstr = ejbstr + "\t<enterprise-beans>\n";
275         ejbstr = ejbstr + "\t\t<entity>\n";
276         ejbstr = ejbstr + "\t\t\t<ejb-name>" + ejbname + "</ejb-name>\n";
277         ejbstr = ejbstr + "\t\t\t<home>" + ejbpack + "." + ejbname + "Home</home>\n";
278         ejbstr = ejbstr + "\t\t\t<remote>" + ejbpack + "." + ejbname + "Object</remote>\n";
279         ejbstr = ejbstr + "\t\t\t<ejb-class>" + ejbpack + "." + ejbname + "Bean</ejb-class>\n";
280         ejbstr = ejbstr + "\t\t\t<persistance-type>Bean</persistance-type>\n";
281         ejbstr = ejbstr + "\t\t\t<prim-key-class>" + ejbpack + "." + ejbname + "PK</prim-key-class>\n";
282         ejbstr = ejbstr + "\t\t\t<reentrant>False</reentrant>\n";
283         ejbstr = ejbstr + "\t\t</entity>\n";
284         ejbstr = ejbstr + "\t</enterprise-beans>\n";
285         ejbstr = ejbstr + "</ejb-jar>";
286     
287         ejbcode = ejbstr;
288     }
289     
290 // public void createOPEXML()
291
// {
292
// }
293
}
294
Popular Tags