KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > tool > codegen > ProjectOptionSet


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;
25
26 // ToolBox imports
27

28 import org.enhydra.tool.ToolBoxInfo;
29
30 // Standard imports
31

32 import java.io.File JavaDoc;
33 import java.util.StringTokenizer JavaDoc;
34 import java.util.ResourceBundle JavaDoc;
35
36 /**
37  * This class instantiates a set of default GeneratorOptions during
38  * initialization. The default options include: project, d, package
39  * copywrite, copywritefile, make, script, j2ee and overwrite.
40  */

41 abstract public class ProjectOptionSet extends OptionSet implements Constants {
42
43     /**
44      * Property name for the project name option.
45      */

46     public static final String JavaDoc PROJECT = "project"; // nores
47

48     /**
49      * Property name for the destintation option
50      */

51     public static final String JavaDoc ROOT = "root"; // nores
52

53     /**
54      * Property name for the package option.
55      */

56     public static final String JavaDoc PACKAGE = "package"; // nores
57

58     /**
59      * Property name for the copyright option.
60      */

61     public static final String JavaDoc COPYRIGHT = "copyright"; // nores
62

63     /**
64      * Property name for the copyright file option.
65      */

66     public static final String JavaDoc COPYRIGHTFILE = "copyrightfile"; // nores
67

68     /**
69      * Property name for the script option.
70      */

71     public static final String JavaDoc NOCLI = "nocli"; // nores
72

73     /**
74      * Property name for the overwrite option.
75      */

76     public static final String JavaDoc OVERWRITE = "overwrite"; // nores
77

78
79     //
80

81     private final String JavaDoc DEF_PROJECT = "untitled1"; // nores
82
private final String JavaDoc DEF_PACKAGE = "untitled"; // nores
83

84     /**
85      * Create a default set of options. This is a convenience class that
86      * can be used as the basis for building custom option set within
87      * a generator.
88      */

89     public ProjectOptionSet() {
90
91
92         try {
93             add (new GeneratorOption (PROJECT, DEF_PROJECT,
94                                            res.getString ("PROJECT"),
95                                            res.getString ("PROJECT_Instruct"),
96                                            true, true));
97             add (new GeneratorOption (PACKAGE, DEF_PACKAGE,
98                                            res.getString ("PACKAGE"),
99                                            res.getString ("PACKAGE_Instruct"),
100                                            true, true));
101             add (new GeneratorOption (ROOT, getDefaultRoot (),
102                                            res.getString ("ROOT"),
103                                            res.getString ("ROOT_Instruct"),
104                                            true, true));
105             add (new GeneratorOption (COPYRIGHT, new String JavaDoc (),
106                                            res.getString ("STRING"),
107                                            res.getString ("STRING instruct"),
108                                            false, true));
109             add (new GeneratorOption (COPYRIGHTFILE, new String JavaDoc (),
110                                            res.getString ("FILE"),
111                                            res.getString ("FILE_instruct"),
112                                            false, true));
113             add (new GeneratorOption (NOCLI, false,
114                                            res.getString ("Suppress_CLI"),
115                                            true));
116             add (new GeneratorOption (OVERWRITE, false,
117                                            res.getString ("OK_to_overwrite"),
118                                            false));
119         } catch (GeneratorException e) {
120             e.printStackTrace ();
121         }
122     }
123
124     /**
125      * Method declaration
126      *
127      *
128      * @return
129      */

130     private String JavaDoc getDefaultRoot () {
131         final String JavaDoc DIR_ENHYDRA_APPS = "myProjects"; // nores
132
StringBuffer JavaDoc buf = new StringBuffer JavaDoc ();
133         String JavaDoc userHome = new String JavaDoc ();
134         File JavaDoc file = null;
135
136         userHome = System.getProperties ().getProperty (SYS_USER_HOME);
137
138         buf.append (userHome);
139         buf.append (File.separator);
140         buf.append (DIR_ENHYDRA_APPS);
141
142         file = new File JavaDoc (buf.toString ());
143
144         if (!file.exists ()) {
145             file.mkdirs ();
146         }
147
148         if (!file.isDirectory ()) {
149             buf.setLength (0);
150             buf.append (userHome);
151         }
152
153         return buf.toString ();
154     }
155
156 }
157
158
Popular Tags