KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > tool > codegen > internal > AppGenerator


1
2 /*
3  * Enhydra Java Application Server Project
4  *
5  * The contents of this file are subject to the Enhydra Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License on
8  * the Enhydra web site ( http://www.enhydra.org/ ).
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific terms governing rights and limitations
13  * under the License.
14  *
15  * The Initial Developer of the Enhydra Application Server is Lutris
16  * Technologies, Inc. The Enhydra Application Server and portions created
17  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
18  * All Rights Reserved.
19  *
20  * Contributor(s):
21  * Paul Mahar
22  *
23  */

24 package org.enhydra.tool.codegen.internal;
25
26 // ToolBox imports
27
import org.enhydra.tool.ToolBoxInfo;
28 import org.enhydra.tool.codegen.ProjectGenerator;
29 import org.enhydra.tool.codegen.GeneratorException;
30 import org.enhydra.tool.codegen.wizard.AppOptionPanel1;
31 import org.enhydra.tool.codegen.wizard.ProjectOptionPanel2;
32 import org.enhydra.tool.codegen.wizard.ProjectOptionPanel3;
33 import org.enhydra.tool.codegen.wizard.CodeGenPanel;
34 import org.enhydra.tool.common.FileUtil;
35 import org.enhydra.tool.common.PathHandle;
36 import org.enhydra.tool.common.Replacement;
37 import org.enhydra.tool.common.ReplacementSet;
38 import org.enhydra.tool.common.ResUtil;
39 import org.enhydra.tool.common.Template;
40 import org.enhydra.tool.common.TemplateFilter;
41 import org.enhydra.tool.common.TemplateTool;
42 import org.enhydra.tool.common.ToolException;
43 import org.enhydra.tool.common.event.TemplateEvent;
44 import org.enhydra.tool.common.event.TemplateListener;
45 import org.enhydra.tool.configure.ConfigTool;
46
47 // Standard imports
48
import java.io.BufferedReader JavaDoc;
49 import java.io.IOException JavaDoc;
50 import java.io.File JavaDoc;
51 import java.io.FileNotFoundException JavaDoc;
52 import java.io.FileReader JavaDoc;
53 import java.io.FileWriter JavaDoc;
54 import java.io.PrintWriter JavaDoc;
55 import java.util.ArrayList JavaDoc;
56 import java.util.Arrays JavaDoc;
57 import java.util.Properties JavaDoc;
58 import java.util.ResourceBundle JavaDoc;
59 import java.util.StringTokenizer JavaDoc;
60 import java.util.Vector JavaDoc;
61
62 //
63
abstract public class AppGenerator extends ProjectGenerator {
64     private String JavaDoc client = null;
65     private String JavaDoc[][] addinMap = null;
66     private CodeGenPanel[] panels = null;
67
68     public AppGenerator() {
69         setReplacementSet(new AppReplacementSet());
70         setOptionSet(new AppOptionSet());
71     }
72
73     // override ProjectGenerator
74
protected String JavaDoc[] getInputIncludes() {
75         ArrayList JavaDoc list = null;
76         String JavaDoc[] includes = new String JavaDoc[0];
77
78         list = new ArrayList JavaDoc(Arrays.asList(super.getInputIncludes()));
79         list.add(getClient());
80         list.trimToSize();
81         includes = new String JavaDoc[list.size()];
82         includes = (String JavaDoc[]) list.toArray(includes);
83         list.clear();
84         return includes;
85     }
86
87     // override ProjectGenerator
88
public void initReplacementSet() throws GeneratorException {
89         super.initReplacementSet();
90         try {
91             String JavaDoc content = null;
92             String JavaDoc app = null;
93             StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
94
95             // client
96
if (getClient().equalsIgnoreCase(TYPE_WML)) {
97                 content = CONTENT_WML;
98             } else {
99
100                 // chtml, html, xhtml, etc.
101
content = CONTENT_HTML;
102             }
103             app =
104                 getReplacementSet().lookup(AppReplacementSet.at_PROJECT_at).getReplaceWith()[0];
105             buf.append(Character.toUpperCase(app.charAt(0)));
106             if (app.length() > 1) {
107                 buf.append(app.substring(1));
108             }
109             app = buf.toString();
110             getReplacementSet().lookup(AppReplacementSet.APP).setReplaceWith(app);
111             getReplacementSet().lookup(AppReplacementSet.CLIENT).setReplaceWith(getClient().toUpperCase());
112             getReplacementSet().lookup(AppReplacementSet.CONTENT_TYPE).setReplaceWith(content);
113             getReplacementSet().lookup(AppReplacementSet.APP).setReplaceWith(app);
114         } catch (ToolException e) {
115             e.printStackTrace();
116             throw new GeneratorException(e,
117                                          res.getString("Unable_to_init_rep"));
118         }
119     }
120
121     /**
122      * Get the default option panels and preset the option set
123      * for each panel.
124      *
125      * @return
126      * An array containing the three default option panels.
127      */

128     public CodeGenPanel[] getWizardPanels() throws GeneratorException {
129
130         // don't initialize until called.
131
if (panels == null && isSwing()) {
132             panels = new CodeGenPanel[3];
133             panels[0] = new AppOptionPanel1();
134             panels[1] = new ProjectOptionPanel2();
135             panels[2] = new ProjectOptionPanel3();
136             for (int i = 0; i < panels.length; i++) {
137                 panels[i].setOptionSet(getOptionSet());
138                 panels[i].readOptionSet();
139             }
140         }
141         return panels;
142     }
143
144     protected String JavaDoc getClient() {
145         if (client == null) {
146             try {
147                 client =
148                     getOptionSet().lookup(AppOptionSet.CLIENT).getValue().toUpperCase();
149             } catch (GeneratorException e) {
150                 e.printStackTrace();
151                 client = null;
152                 return TYPE_HTML;
153             }
154         }
155         return client;
156     }
157
158     /**
159      * Get the default table for mapping directories to
160      * packages that maps resources directory to the
161      * presentaion package and the resource media directory
162      * to the a media package.
163      *
164      * @param appPackage
165      * This is the application package to prefix to each mapped
166      * package name.
167      *
168      * @return
169      * The default package map for template driven generators.
170      */

171     public String JavaDoc[][] expandAddinPackageMap() throws GeneratorException {
172         String JavaDoc[][] exMap = new String JavaDoc[0][0];
173         TemplateTool tool = null;
174
175         tool = new TemplateTool();
176         tool.setReplacements(getReplacementSet().toArray());
177         if (addinMap == null) {
178             initAddinPackageMap();
179         }
180         exMap = new String JavaDoc[addinMap.length][addinMap[0].length];
181         for (int i = 0; i < exMap.length; i++) {
182             for (int j = 0; j < exMap[i].length; j++) {
183                 exMap[i][j] = addinMap[i][j];
184             }
185         }
186         for (int i = 0; i < exMap.length; i++) {
187             for (int j = 0; j < exMap[i].length; j++) {
188                 exMap[i][j] = tool.lineSearchAndReplace(exMap[i][j]);
189             }
190         }
191         return exMap;
192     }
193
194     public String JavaDoc[][] getAddinPackageMap() throws GeneratorException {
195         if (addinMap == null) {
196             initAddinPackageMap();
197         }
198         return addinMap;
199     }
200
201     public void setAddinPackageMap(String JavaDoc[][] m) {
202         addinMap = m;
203     }
204
205     private void initAddinPackageMap() throws GeneratorException {
206         addinMap = new String JavaDoc[2][2];
207         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
208
209         buf.append(getDestination());
210         buf.append(File.separator);
211 // dacha&strale 29.01.2003
212
// buf.append(DIR_SRC);
213
// buf.append(File.separator);
214
// buf.append(DIR_AT_PACKAGE_DIR_AT);
215
// buf.append(File.separator);
216
buf.append(DIR_RESOURCES);
217         addinMap[0][0] = buf.toString();
218         buf.setLength(0);
219         buf.append("@JAVA_PACKAGE@"); // nores
220
buf.append('.');
221         buf.append(DIR_PRESENTATION);
222         addinMap[0][1] = buf.toString();
223         buf.setLength(0);
224         buf.append(getDestination());
225         buf.append(File.separator);
226 // dacha&strale 29.01.2003
227
// buf.append(DIR_SRC);
228
// buf.append(File.separator);
229
// buf.append(DIR_AT_PACKAGE_DIR_AT);
230
// buf.append(File.separator);
231
buf.append(DIR_RESOURCES);
232         buf.append(File.separator);
233         buf.append(DIR_MEDIA);
234         addinMap[1][0] = buf.toString();
235         addinMap[1][1] = DIR_MEDIA;
236     }
237
238     protected String JavaDoc[] getDefaultAddinSteps() {
239         String JavaDoc[] steps = new String JavaDoc[6];
240
241         steps[0] = res.getString("StepsKelp0");
242         steps[1] = res.getString("StepsKelp1");
243         steps[2] = res.getString("StepsKelp2");
244         steps[3] = res.getString("StepsKelp3");
245         steps[4] = res.getString("StepsKelp4");
246         steps[5] = res.getString("StepsKelp5");
247         return steps;
248     }
249
250     protected String JavaDoc[] getDefaultShellSteps() {
251         String JavaDoc[] steps = new String JavaDoc[3];
252         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
253
254         buf.append(res.getString("StepsShell0a"));
255         buf.append(res.getString("StepsShell0b"));
256         buf.append(res.getString("StepsShell0c"));
257         buf.append(res.getString("StepsShell0d"));
258         buf.append(res.getString("StepsShell0e"));
259         buf.append(res.getString("StepsShell0f"));
260         buf.append(res.getString("StepsShell0g"));
261         buf.append(res.getString("StepsShell0h"));
262         steps[0] = buf.toString();
263         steps[1] = res.getString("StepsShell1");
264         buf.setLength(0);
265         buf.append(res.getString("StepsShell2a"));
266         buf.append(res.getString("StepsShell2b"));
267         steps[2] = buf.toString();
268         return steps;
269     }
270
271 }
272
Popular Tags