1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.finalist.jaggenerator.template;
18
19 import java.util.HashMap;
20
21
22 /***
23 * This bean represents a single configurable parameter,
24 * as specified in a template's "template.xml".
25 *
26 * @author Michael O'Connor - Finalist IT Group
27 */
28 public class TemplateConfigParameter {
29
30 /***
31 * The 'type' value for a parameter whose value is determined by entering text into an input field.
32 */
33 public static final Type TYPE_TEXT = new Type("text");
34 /***
35 * The 'type' value for a parameter whose value is determined by clicking an on/off checkbox.
36 */
37 public static final Type TYPE_CHECKBOX = new Type("checkbox");
38 /***
39 * The 'type' value for a parameter whose value is determined by selecting an item from a predefined list.
40 */
41 public static final Type TYPE_LIST = new Type("list");
42 /***
43 * The 'type' value for a parameter whose value is determined by either:
44 * <li>selecting an item from a predefined list, or </li>
45 * <li>typing in a 'free text' value</li>
46 */
47 public static final Type TYPE_EDITABLE_LIST = new Type("list-editable");
48
49 private static final HashMap types = new HashMap();
50 static {
51 types.put(TYPE_TEXT.toString(), TYPE_TEXT);
52 types.put(TYPE_CHECKBOX.toString(), TYPE_CHECKBOX);
53 types.put(TYPE_LIST.toString(), TYPE_LIST);
54 types.put(TYPE_EDITABLE_LIST.toString(), TYPE_EDITABLE_LIST);
55 }
56
57 private String id;
58 private String name;
59 private String description;
60 private Type type;
61 private String[] presetValues;
62 private String value;
63
64
65 /***
66 * Gets the id - the unique identifier of this parameter used to access the parameter value
67 * from the templates.
68 *
69 * @return id
70 */
71 public String getId() {
72 return id;
73 }
74
75 /***
76 * Sets the id - the unique identifier of this parameter used to access the parameter value
77 * from the templates. This value should be a String following the same naming conventions
78 * as a Java bean attribute (e.g. no spaces, hyphens, etc.).
79 *
80 * @param id
81 */
82 public void setId(String id) {
83 this.id = id;
84 }
85
86 /***
87 * Gets the name - this is the human-readable short name used to represent this parameter in the GUI.
88 *
89 * @return
90 */
91 public String getName() {
92 return name;
93 }
94
95 /***
96 * Sets the name - this is the human-readable short name used to represent this parameter in the GUI.
97 *
98 * @param name
99 */
100 public void setName(String name) {
101 this.name = name;
102 }
103
104 /***
105 * Gets the description for this parameter - shows up in the GUI as a tooltip.
106 *
107 * @return
108 */
109 public String getDescription() {
110 return description;
111 }
112
113 /***
114 * Sets the description for this parameter - shows up in the GUI as a tooltip.
115 *
116 * @param description
117 */
118 public void setDescription(String description) {
119 this.description = description;
120 }
121
122 /***
123 * Gets the type of this configuration parameter.
124 *
125 * @return one of the TYPE_XXX constants defined in this class.
126 */
127 public TemplateConfigParameter.Type getType() {
128 return type;
129 }
130
131 /***
132 * Sets the type of this configuration parameter.
133 *
134 * @param type - Use one of the TYPE_XXX constants defined in this class.
135 */
136 public void setType(TemplateConfigParameter.Type type) {
137 this.type = type;
138 }
139
140 /***
141 * Gets the preset values for this parameter.
142 *
143 * @return a String[] (may have length zero, never <code>null</code>).
144 */
145 public String[] getPresetValues() {
146 return presetValues;
147 }
148
149 public void setPresetValues(String[] presetValues) {
150 this.presetValues = presetValues;
151 }
152
153 public String getValue() {
154 return value;
155 }
156
157 public void setValue(String value) {
158 this.value = value;
159 }
160
161 /***
162 * Translates a type's name into the corresponding Type object.
163 *
164 * @param name
165 * @return <code>null</code> if the name is not a valid Type.
166 */
167 public static Type getTypeByName(String name) {
168 return (Type) types.get(name);
169 }
170
171
172 /*** Objects of this class are used to determine a TemplateConfigParamater's type */
173 private final static class Type {
174 private String type;
175
176 private Type(String type) {
177 this.type = type;
178 }
179
180 public String toString() {
181 return type;
182 }
183 }
184
185 }