001: /* Copyright (C) 2003 Finalist IT Group
002: *
003: * This file is part of JAG - the Java J2EE Application Generator
004: *
005: * JAG is free software; you can redistribute it and/or modify
006: * it under the terms of the GNU General Public License as published by
007: * the Free Software Foundation; either version 2 of the License, or
008: * (at your option) any later version.
009: * JAG is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: * You should have received a copy of the GNU General Public License
014: * along with JAG; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
016: */
017: package com.finalist.jaggenerator.template;
018:
019: import java.util.HashMap;
020:
021: /**
022: * This bean represents a single configurable parameter,
023: * as specified in a template's "template.xml".
024: *
025: * @author Michael O'Connor - Finalist IT Group
026: */
027: public class TemplateConfigParameter {
028:
029: /**
030: * The 'type' value for a parameter whose value is determined by entering text into an input field.
031: */
032: public static final Type TYPE_TEXT = new Type("text");
033: /**
034: * The 'type' value for a parameter whose value is determined by clicking an on/off checkbox.
035: */
036: public static final Type TYPE_CHECKBOX = new Type("checkbox");
037: /**
038: * The 'type' value for a parameter whose value is determined by selecting an item from a predefined list.
039: */
040: public static final Type TYPE_LIST = new Type("list");
041: /**
042: * The 'type' value for a parameter whose value is determined by either:
043: * <li>selecting an item from a predefined list, or </li>
044: * <li>typing in a 'free text' value</li>
045: */
046: public static final Type TYPE_EDITABLE_LIST = new Type(
047: "list-editable");
048:
049: private static final HashMap types = new HashMap();
050: static {
051: types.put(TYPE_TEXT.toString(), TYPE_TEXT);
052: types.put(TYPE_CHECKBOX.toString(), TYPE_CHECKBOX);
053: types.put(TYPE_LIST.toString(), TYPE_LIST);
054: types.put(TYPE_EDITABLE_LIST.toString(), TYPE_EDITABLE_LIST);
055: }
056:
057: private String id;
058: private String name;
059: private String description;
060: private Type type;
061: private String[] presetValues;
062: private String value;
063:
064: /**
065: * Gets the id - the unique identifier of this parameter used to access the parameter value
066: * from the templates.
067: *
068: * @return id
069: */
070: public String getId() {
071: return id;
072: }
073:
074: /**
075: * Sets the id - the unique identifier of this parameter used to access the parameter value
076: * from the templates. This value should be a String following the same naming conventions
077: * as a Java bean attribute (e.g. no spaces, hyphens, etc.).
078: *
079: * @param id
080: */
081: public void setId(String id) {
082: this .id = id;
083: }
084:
085: /**
086: * Gets the name - this is the human-readable short name used to represent this parameter in the GUI.
087: *
088: * @return
089: */
090: public String getName() {
091: return name;
092: }
093:
094: /**
095: * Sets the name - this is the human-readable short name used to represent this parameter in the GUI.
096: *
097: * @param name
098: */
099: public void setName(String name) {
100: this .name = name;
101: }
102:
103: /**
104: * Gets the description for this parameter - shows up in the GUI as a tooltip.
105: *
106: * @return
107: */
108: public String getDescription() {
109: return description;
110: }
111:
112: /**
113: * Sets the description for this parameter - shows up in the GUI as a tooltip.
114: *
115: * @param description
116: */
117: public void setDescription(String description) {
118: this .description = description;
119: }
120:
121: /**
122: * Gets the type of this configuration parameter.
123: *
124: * @return one of the TYPE_XXX constants defined in this class.
125: */
126: public TemplateConfigParameter.Type getType() {
127: return type;
128: }
129:
130: /**
131: * Sets the type of this configuration parameter.
132: *
133: * @param type - Use one of the TYPE_XXX constants defined in this class.
134: */
135: public void setType(TemplateConfigParameter.Type type) {
136: this .type = type;
137: }
138:
139: /**
140: * Gets the preset values for this parameter.
141: *
142: * @return a String[] (may have length zero, never <code>null</code>).
143: */
144: public String[] getPresetValues() {
145: return presetValues;
146: }
147:
148: public void setPresetValues(String[] presetValues) {
149: this .presetValues = presetValues;
150: }
151:
152: public String getValue() {
153: return value;
154: }
155:
156: public void setValue(String value) {
157: this .value = value;
158: }
159:
160: /**
161: * Translates a type's name into the corresponding Type object.
162: *
163: * @param name
164: * @return <code>null</code> if the name is not a valid Type.
165: */
166: public static Type getTypeByName(String name) {
167: return (Type) types.get(name);
168: }
169:
170: /** Objects of this class are used to determine a TemplateConfigParamater's type */
171: private final static class Type {
172: private String type;
173:
174: private Type(String type) {
175: this .type = type;
176: }
177:
178: public String toString() {
179: return type;
180: }
181: }
182:
183: }
|