001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License on
007: * the Enhydra web site ( http://www.enhydra.org/ ).
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011: * the License for the specific terms governing rights and limitations
012: * under the License.
013: *
014: * The Initial Developer of the Enhydra Application Server is Lutris
015: * Technologies, Inc. The Enhydra Application Server and portions created
016: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017: * All Rights Reserved.
018: *
019: * Contributor(s):
020: * Paul Mahar
021: *
022: */
023: package org.enhydra.tool.codegen;
024:
025: // ToolBox imports
026:
027: import org.enhydra.tool.ToolBoxInfo;
028:
029: // Standard imports
030:
031: import java.io.File;
032: import java.util.StringTokenizer;
033: import java.util.ResourceBundle;
034:
035: /**
036: * This class instantiates a set of default GeneratorOptions during
037: * initialization. The default options include: project, d, package
038: * copywrite, copywritefile, make, script, j2ee and overwrite.
039: */
040: abstract public class ProjectOptionSet extends OptionSet implements
041: Constants {
042:
043: /**
044: * Property name for the project name option.
045: */
046: public static final String PROJECT = "project"; // nores
047:
048: /**
049: * Property name for the destintation option
050: */
051: public static final String ROOT = "root"; // nores
052:
053: /**
054: * Property name for the package option.
055: */
056: public static final String PACKAGE = "package"; // nores
057:
058: /**
059: * Property name for the copyright option.
060: */
061: public static final String COPYRIGHT = "copyright"; // nores
062:
063: /**
064: * Property name for the copyright file option.
065: */
066: public static final String COPYRIGHTFILE = "copyrightfile"; // nores
067:
068: /**
069: * Property name for the script option.
070: */
071: public static final String NOCLI = "nocli"; // nores
072:
073: /**
074: * Property name for the overwrite option.
075: */
076: public static final String OVERWRITE = "overwrite"; // nores
077:
078: //
079:
080: private final String DEF_PROJECT = "untitled1"; // nores
081: private final String DEF_PACKAGE = "untitled"; // nores
082:
083: /**
084: * Create a default set of options. This is a convenience class that
085: * can be used as the basis for building custom option set within
086: * a generator.
087: */
088: public ProjectOptionSet() {
089:
090: try {
091: add(new GeneratorOption(PROJECT, DEF_PROJECT, res
092: .getString("PROJECT"), res
093: .getString("PROJECT_Instruct"), true, true));
094: add(new GeneratorOption(PACKAGE, DEF_PACKAGE, res
095: .getString("PACKAGE"), res
096: .getString("PACKAGE_Instruct"), true, true));
097: add(new GeneratorOption(ROOT, getDefaultRoot(), res
098: .getString("ROOT"), res.getString("ROOT_Instruct"),
099: true, true));
100: add(new GeneratorOption(COPYRIGHT, new String(), res
101: .getString("STRING"), res
102: .getString("STRING instruct"), false, true));
103: add(new GeneratorOption(COPYRIGHTFILE, new String(), res
104: .getString("FILE"), res.getString("FILE_instruct"),
105: false, true));
106: add(new GeneratorOption(NOCLI, false, res
107: .getString("Suppress_CLI"), true));
108: add(new GeneratorOption(OVERWRITE, false, res
109: .getString("OK_to_overwrite"), false));
110: } catch (GeneratorException e) {
111: e.printStackTrace();
112: }
113: }
114:
115: /**
116: * Method declaration
117: *
118: *
119: * @return
120: */
121: private String getDefaultRoot() {
122: final String DIR_ENHYDRA_APPS = "myProjects"; // nores
123: StringBuffer buf = new StringBuffer();
124: String userHome = new String();
125: File file = null;
126:
127: userHome = System.getProperties().getProperty(SYS_USER_HOME);
128:
129: buf.append(userHome);
130: buf.append(File.separator);
131: buf.append(DIR_ENHYDRA_APPS);
132:
133: file = new File(buf.toString());
134:
135: if (!file.exists()) {
136: file.mkdirs();
137: }
138:
139: if (!file.isDirectory()) {
140: buf.setLength(0);
141: buf.append(userHome);
142: }
143:
144: return buf.toString();
145: }
146:
147: }
|