KickJava   Java API By Example, From Geeks To Geeks.

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


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.Constants;
29 import org.enhydra.tool.codegen.ProjectReplacementSet;
30 import org.enhydra.tool.codegen.GeneratorException;
31 import org.enhydra.tool.common.PathHandle;
32 import org.enhydra.tool.common.Replacement;
33 import org.enhydra.tool.common.ReplacementSet;
34 import org.enhydra.tool.common.ToolException;
35
36 // Standard imports
37
import java.io.File JavaDoc;
38 import java.util.ArrayList JavaDoc;
39 import java.util.Arrays JavaDoc;
40 import java.util.ResourceBundle JavaDoc;
41
42 /**
43  * A generator for a Enhydra 3 presentation object style application. This
44  * creates a set of files that is similar to what was generated from
45  * com.lutris.devsys.LutrisAppTree.
46  */

47 public class Enhydra3AppGenerator extends AppGenerator {
48
49     /**
50      * Name to use specify at the command line.
51      */

52     public static final String JavaDoc COMMAND_NAME = "en3app"; // nores
53

54     /**
55      * Descriptive name for generator.
56      */

57     public static final String JavaDoc displayName = "Enhydra Application";
58     public static final String JavaDoc wizardTitle = "Enhydra Application Wizard";
59
60     /**
61      * Create an instance of the Enhydra 3 style applicition generator.
62      */

63     public Enhydra3AppGenerator() {}
64
65     /**
66      * Implements AppGenerator
67      */

68     public String JavaDoc[] getOutputExcludes() {
69         String JavaDoc[] ex = new String JavaDoc[0];
70         ArrayList JavaDoc list = null;
71
72         list = new ArrayList JavaDoc(Arrays.asList(super.getOutputExcludes()));
73
74         // not to be resourced
75
if (getClient().equalsIgnoreCase("chtml") // nores
76
|| getClient().equalsIgnoreCase("wml")) { // nores
77
list.add("RedirectPresentation.java"); // nores
78
list.add("options.xmlc"); // nores
79
list.add("media" + File.separator + "makefile"); // nores
80
list.add(".gif"); // nores
81
}
82         list.trimToSize();
83         ex = new String JavaDoc[list.size()];
84         ex = (String JavaDoc[]) list.toArray(ex);
85         list.clear();
86         return ex;
87     }
88
89     /**
90      * Overrides AppGenerator
91      */

92     public Replacement[] createReplacementsForDirectory(PathHandle path)
93             throws GeneratorException {
94         Replacement[] reps = new Replacement[0];
95         ArrayList JavaDoc list = null;
96
97         reps = super.createReplacementsForDirectory(path);
98         try {
99             if (path.endsWith("/conf")) { // nores
100
Replacement rep = null;
101                 ReplacementSet set = null;
102                 String JavaDoc url = new String JavaDoc();
103
104                 list = new ArrayList JavaDoc(Arrays.asList(reps));
105                 set = new ReplacementSet(reps);
106                 rep = set.lookup(AppReplacementSet.JAVA_PACKAGE);
107                 url = rep.getReplaceWith()[0].replace('.', '/');
108                 rep = new Replacement("@JAVA_PACKAGE_URL@", url); // nores
109
list.add(rep);
110                 reps = new Replacement[list.size()];
111                 reps = (Replacement[]) list.toArray(reps);
112                 list.clear();
113             } else if (path.endsWith("/presentation")) { // nores
114
String JavaDoc[] targets = new String JavaDoc[1];
115                 String JavaDoc[] rules = new String JavaDoc[1];
116                 Replacement targetRep = null;
117                 Replacement ruleRep = null;
118
119                 targets[0] = new String JavaDoc();
120                 rules[0] = new String JavaDoc();
121                 list = new ArrayList JavaDoc(Arrays.asList(reps));
122
123                 //
124
if (getClient().equalsIgnoreCase("chtml")) { // nores
125

126                     // defaults OK;
127
} else if (getClient().equalsIgnoreCase("wml")) { // nores
128
targets = new String JavaDoc[2];
129                     rules = new String JavaDoc[1];
130                     targets[0] = new String JavaDoc();
131                     targets[1] = "XMLC_" + getClient().toUpperCase() // nores
132
+ "_OPTS_FILE = options.xmlc"; // nores
133
rules[0] = new String JavaDoc();
134                 } else {
135
136                     // HTML 4 Browser
137
targets = new String JavaDoc[4];
138                     rules = new String JavaDoc[1];
139                     targets[0] = "RedirectPresentation"; // nores
140
targets[1] = new String JavaDoc();
141                     targets[2] = "SUBDIRS = media"; // nores
142
targets[3] = "XMLC_" + getClient().toUpperCase() // nores
143
+ "_OPTS_FILE = options.xmlc"; // nores
144
rules[0] = new String JavaDoc();
145                 }
146                 targetRep = new Replacement("@PRESENTATION_TARGETS@", // nores
147
targets);
148                 ruleRep = new Replacement("@PRESENTATION_RULES@",
149                                           rules); // nores
150
list.add(targetRep);
151                 list.add(ruleRep);
152                 reps = new Replacement[list.size()];
153                 reps = (Replacement[]) list.toArray(reps);
154                 list.clear();
155             }
156         } catch (ToolException e) {
157             throw new GeneratorException(e,
158                                          res.getString("Unable_to_create"));
159         }
160         return reps;
161     }
162
163     /**
164      * Get short name used in command line. May also be used
165      * to locate template directory.
166      *
167      * @return
168      * Command line identifier.
169      */

170     public String JavaDoc getCommandName() {
171         return COMMAND_NAME;
172     }
173
174     /**
175      * Name to display in command line messages and in the wizard.
176      *
177      * @return
178      * Display name for generator.
179      */

180     public String JavaDoc getDisplayName() {
181         return Enhydra3AppGenerator.displayName;
182     }
183
184     public String JavaDoc getWizardTitle() {
185         return Enhydra3AppGenerator.wizardTitle;
186     }
187
188     /**
189      * Get text that breifly explains the application that
190      * the generator creates.
191      *
192      * @return
193      * Descriptive text to display in a wizard or in a command
194      * line help response.
195      */

196     public String JavaDoc getDescription() {
197         return res.getString("En3Descript");
198     }
199
200 }
201
Popular Tags