1 2 23 package org.enhydra.tool.codegen; 24 25 import org.enhydra.tool.common.ResUtil; 27 import java.util.ResourceBundle ; 28 29 34 public class GeneratorOption { 35 static ResourceBundle res = ResourceBundle.getBundle("org.enhydra.tool.codegen.Res"); 37 private String name = new String (); 38 private String value = new String (); 39 private String displayName = new String (); 40 private String description = new String (); 41 private boolean required = false; 42 private boolean persistent = true; 43 private boolean bool = false; 44 45 77 public GeneratorOption(String name, String value, String displayName, 78 String description, boolean required, 79 boolean persistent) throws GeneratorException { 80 if (name == null || name.trim().length() == 0) { 81 throw new GeneratorException(res.getString("Option_name_cannot_be")); 82 } else { 83 this.name = name; 84 this.value = value; 85 this.displayName = displayName; 86 this.description = description; 87 this.required = required; 88 this.persistent = persistent; 89 this.bool = false; 90 } 91 } 92 93 117 public GeneratorOption(String n, boolean v, String desc, 118 boolean persist) throws GeneratorException { 119 this(n, (new Boolean (v)).toString(), new String (), desc, false, 120 persist); 121 this.bool = true; 122 } 123 124 132 public String getName() { 133 return name; 134 } 135 136 142 public String getValue() { 143 return value; 144 } 145 146 157 public void setValue(String value) throws GeneratorException { 158 if (isRequired()) { 159 if (value == null || value.trim().length() == 0) { 160 throw new GeneratorException( 161 ResUtil.format(res.getString("Required_value_cannot"), 162 getDisplayName())); 163 } 164 } 165 this.value = value; 166 } 167 168 174 public void setValue(boolean value) { 175 Boolean b = new Boolean (value); 176 177 this.value = b.toString(); 178 } 179 180 189 public String getDescription() { 190 return description; 191 } 192 193 203 public boolean isRequired() { 204 return required; 205 } 206 207 213 public boolean isPersistent() { 214 return persistent; 215 } 216 217 225 public String getDisplayName() { 226 return displayName; 227 } 228 229 235 public boolean isValue() { 236 Boolean b = Boolean.valueOf(getValue().toLowerCase()); 237 238 return b.booleanValue(); 239 } 240 241 247 public boolean isBoolean() { 248 return bool; 249 } 250 251 public void clearValue() { 252 value = new String (); 253 } 254 255 public boolean isEmpty() { 256 return (value == null || value.trim().length() == 0); 257 } 258 259 } 260 | Popular Tags |