KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openejb > webadmin > main > CMPMappingWriter


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: CMPMappingWriter.java 1912 2005-06-16 22:29:56Z jlaskowski $
44  */

45 package org.openejb.webadmin.main;
46
47 import java.io.PrintWriter JavaDoc;
48
49 import org.exolab.castor.mapping.xml.MappingRoot;
50 import org.openejb.util.HtmlUtilities;
51 import org.openejb.util.StringUtilities;
52
53 /**
54  * @author <a HREF="mailto:tim_urberg@yahoo.com">Tim Urberg</a>
55  */

56 public class CMPMappingWriter {
57     public static final String JavaDoc FORM_FIELD_JDBC_DRIVER = "jdbcDriver";
58     public static final String JavaDoc FORM_FIELD_FILE_NAME = "fileName";
59     public static final String JavaDoc FORM_FIELD_JNDI_NAME = "jndiName";
60     public static final String JavaDoc FORM_FIELD_DB_ENGINE = "dbEngine";
61     public static final String JavaDoc FORM_FIELD_DRIVER_CLASS = "driverClass";
62     public static final String JavaDoc FORM_FIELD_DRIVER_URL = "driverUrl";
63     public static final String JavaDoc FORM_FIELD_USERNAME = "mappingUsername";
64     public static final String JavaDoc FORM_FIELD_PASSWORD = "mappingPassword";
65     public static final String JavaDoc FORM_FIELD_SUBMIT_DB_INFO = "submitDBInfo";
66     public static final String JavaDoc FORM_FIELD_HANDLE_FILE = "handleFile";
67     public static final String JavaDoc FORM_FIELD_CLASS_NAME = "className";
68     public static final String JavaDoc FORM_FIELD_IDENTITY_FIELD = "identityField";
69
70     /**
71      * writes the form for database information to the screen
72      * @param body the PrintWriter to write the information to
73      * @param errorMessage an error message to display
74      * @param databaseData the database information to be printed
75      */

76     public static void printDBInfo(PrintWriter JavaDoc body, String JavaDoc errorMessage, DatabaseData databaseData, String JavaDoc handleFile) {
77         body.println("<form action=\"CMPMapping\" method=\"post\" enctype=\"multipart/form-data\">");
78         body.println("<table border=\"0\" cellspacing=\"1\" cellpadding=\"1\">");
79         body.print("<tr>\n<td colspan=\"2\"><strong>Step 1:</strong> Choose database options.");
80         body.println("The bold fields are required.</td>\n</tr>");
81
82         //if there is an error message, display it here
83
if (!"".equals(errorMessage)) {
84             body.print("<tr>\n<td colspan=\"2\"><font color=\"red\"><b>");
85             body.print(errorMessage);
86             body.println("</b></font></td>\n</tr>");
87         }
88
89         body.println("<tr>\n<td colspan=\"2\">&nbsp;</td>\n</tr>");
90         body.print("<tr>\n<td>JDBC Driver ");
91         body.print(createHelpLink());
92         body.println("</td>\n<td>");
93         body.println(HtmlUtilities.createFileFormField(FORM_FIELD_JDBC_DRIVER, "", 25));
94         body.print("</td>\n</tr>\n<tr>\n<td><b>File Names</b> ");
95         body.print(createHelpLink());
96         body.println("</td>\n<td>");
97         body.println(
98             HtmlUtilities.createTextFormField(
99                 FORM_FIELD_FILE_NAME,
100                 StringUtilities.nullToBlankString(databaseData.getFileName()),
101                 10,
102                 25));
103         body.println(".cmp_local/global_database.xml</td>\n</tr>");
104         body.print("<tr>\n<td><b>DB Engine</b> ");
105         body.print(createHelpLink());
106         body.println("</td>\n<td>");
107         body.println(
108             HtmlUtilities.createTextFormField(
109                 FORM_FIELD_DB_ENGINE,
110                 StringUtilities.nullToBlankString(databaseData.getDbEngine()),
111                 20,
112                 0));
113         body.print("</td>\n</tr>\n<tr>\n<td><b>JNDI Name</b> ");
114         body.print(createHelpLink());
115         body.println("</td>\n<td>");
116         body.println(
117             HtmlUtilities.createTextFormField(
118                 FORM_FIELD_JNDI_NAME,
119                 StringUtilities.nullToBlankString(databaseData.getJndiName()),
120                 20,
121                 0));
122         body.print("</td>\n</tr>\n<tr>\n<td><b>Driver Class</b> ");
123         body.print(createHelpLink());
124         body.println("</td>\n<td>");
125         body.println(
126             HtmlUtilities.createTextFormField(
127                 FORM_FIELD_DRIVER_CLASS,
128                 StringUtilities.nullToBlankString(databaseData.getDriverClass()),
129                 25,
130                 0));
131         body.print("</td>\n</tr>\n<tr>\n<td><b>Driver URL</b> ");
132         body.print(createHelpLink());
133         body.println("</td>\n<td>");
134         body.println(
135             HtmlUtilities.createTextFormField(
136                 FORM_FIELD_DRIVER_URL,
137                 StringUtilities.nullToBlankString(databaseData.getDriverUrl()),
138                 25,
139                 0));
140         body.print("</td>\n</tr>\n<tr>\n<td>Username ");
141         body.print(createHelpLink());
142         body.println("</td>\n<td>");
143         body.println(
144             HtmlUtilities.createTextFormField(
145                 FORM_FIELD_USERNAME,
146                 StringUtilities.nullToBlankString(databaseData.getUsername()),
147                 20,
148                 0));
149         body.print("</td>\n</tr>\n<tr>\n<td>Password ");
150         body.print(createHelpLink());
151         body.println("</td>\n<td>");
152         body.println(
153             HtmlUtilities.createTextFormField(
154                 FORM_FIELD_PASSWORD,
155                 StringUtilities.nullToBlankString(databaseData.getPassword()),
156                 20,
157                 0));
158         body.println("</td>\n</tr>\n<tr>\n<td colspan=\"2\">&nbsp;</td>\n</tr>");
159         body.println("<tr>\n<td colspan=\"2\">");
160         body.println(HtmlUtilities.createSubmitFormButton(FORM_FIELD_SUBMIT_DB_INFO, "Continue"));
161         body.println(HtmlUtilities.createHiddenFormField(FORM_FIELD_HANDLE_FILE, handleFile));
162         body.println("</td>\n</tr>\n</table>\n</form>");
163     }
164     
165     /**
166      * prints out initial html for the mapping section
167      */

168     public static void printMappingInfo(PrintWriter JavaDoc body, String JavaDoc handleFile, MappingRoot mappingRoot) {
169         body.println("Step 2: Map the fields in the database to the fields in your entity bean. ");
170         body.println("Once you map the field, the page will reload and your mapping will appear in");
171         body.println("the table at the bottom of the page. The bold fields are required.");
172         body.println("<form action=\"CMPMapping\" method=\"post\">");
173         body.println("<table border=\"0\" cellspacing=\"1\" cellpadding=\"1\">");
174         
175         body.print("<tr>\n<td><b>Class Name</b> ");
176         body.print(createHelpLink());
177         body.print("</td>\n<td>");
178         body.print(HtmlUtilities.createTextFormField(FORM_FIELD_CLASS_NAME, "", 30, 0));
179         body.print("</td>\n</tr>\n<tr>\n<td><b>Identity Field</b> ");
180         body.print(createHelpLink());
181         body.print("</td>\n<td>");
182         body.print(HtmlUtilities.createTextFormField(FORM_FIELD_IDENTITY_FIELD, "", 20, 0));
183         body.println("</table>\n</form>");
184     }
185     
186     /**
187      * creates a help link for this section
188      * @return the help link
189      */

190     private static String JavaDoc createHelpLink() {
191         return HtmlUtilities.createAnchor(
192             "javascript:popUpHelp('help/mapping/help.html')",
193             "(?)",
194             HtmlUtilities.ANCHOR_HREF_TYPE);
195     }
196
197 }
198
Popular Tags