1 package de.webman.form; 2 3 import java.sql.ResultSet ; 4 import com.teamkonzept.db.TKDBManager; 5 import com.teamkonzept.db.TKQuery; 6 import com.teamkonzept.lib.TKException; 7 import com.teamkonzept.webman.mainint.WebmanExceptionHandler; 8 import de.webman.form.db.FieldConstants; 9 import de.webman.form.db.FormConstants; 10 import de.webman.form.db.queries.FormDepends; 11 import de.webman.form.db.queries.SelectFormProperties; 12 13 24 public class Form 25 { 26 27 29 32 private Integer id = null; 33 34 37 private Integer type = null; 38 39 42 private String name = null; 43 44 47 private String description = null; 48 49 50 52 55 public Form () 56 { 57 this(null); 58 } 59 60 65 public Form (Integer id) 66 { 67 if (id == null) 68 { 69 throw new IllegalArgumentException (); 70 } 71 72 this.id = id; 73 } 74 75 76 78 83 public Integer getIdentifier () 84 { 85 return this.id; 86 } 87 88 94 public Integer getType () 95 throws TKException 96 { 97 loadFormProperties(); 98 return this.type; 99 } 100 101 107 public String getName () 108 throws TKException 109 { 110 loadFormProperties(); 111 return this.name; 112 } 113 114 120 public String getDescription () 121 throws TKException 122 { 123 loadFormProperties(); 124 return this.description; 125 } 126 127 128 130 139 public boolean equals (Object object) 140 { 141 if (object == null) 142 { 143 return false; 144 } 145 146 if (object == this) 147 { 148 return true; 149 } 150 151 if (! this.getClass().equals(object.getClass())) 152 { 153 return false; 154 } 155 156 return ((Form) object).getIdentifier().equals(this.id); 157 } 158 159 164 public int hashCode () 165 { 166 return this.id.hashCode(); 167 } 168 169 174 public String toString () 175 { 176 return (new StringBuffer (this.getClass().getName())).append('@') 177 .append(this.id) 178 .toString(); 179 } 180 181 182 184 191 public boolean hasDependencies () 192 throws TKException 193 { 194 try 195 { 196 TKQuery query = TKDBManager.newQuery(FormDepends.class); 197 query.setQueryParams(FormConstants.COLUMN_NAMES[FormConstants.FORM_ID], this.id); 198 query.execute(); 199 200 ResultSet result = query.fetchResultSet(); 201 202 return result.next(); 203 } 204 catch (Exception e) 205 { 206 throw WebmanExceptionHandler.getException(e); 207 } 208 } 209 210 219 public boolean isFormFragment () 220 throws TKException 221 { 222 return FormConstants.FORM_TYPE_FORM_FRAGMENT.equals(getType()); 223 } 224 225 234 public boolean isContentForm () 235 throws TKException 236 { 237 return FormConstants.FORM_TYPE_CONTENT_FORM.equals(getType()); 238 } 239 240 249 public boolean isStructureForm () 250 throws TKException 251 { 252 return FormConstants.FORM_TYPE_STRUCTURE_FORM.equals(getType()); 253 } 254 255 264 public boolean isTemporaryForm () 265 throws TKException 266 { 267 return FormConstants.FORM_TYPE_TEMPORARY_FORM.equals(getType()); 268 } 269 270 275 public int getIdentifierAsInt () 276 { 277 return getIdentifier().intValue(); 278 } 279 280 286 public int getTypeAsInt () 287 throws TKException 288 { 289 return getType().intValue(); 290 } 291 292 293 295 302 private void loadFormProperties () 303 throws TKException 304 { 305 if (this.type != null) 306 { 307 return; 308 } 309 310 try 311 { 312 TKQuery query = TKDBManager.newQuery(SelectFormProperties.class); 313 query.setQueryParams(FormConstants.COLUMN_NAMES[FormConstants.FORM_ID], this.id); 314 query.execute(); 315 316 ResultSet result = query.fetchResultSet(); 317 318 if (result.next()) 319 { 320 this.type = new Integer (result.getInt(FormConstants.COLUMN_NAMES[FormConstants.FORM_TYPE])); 321 this.name = result.getString(FieldConstants.COLUMN_NAMES[FieldConstants.FIELD_NAME]); 322 this.description = result.getString(FieldConstants.COLUMN_NAMES[FieldConstants.FIELD_SHOW_NAME]); 323 } 324 } 325 catch (Exception e) 326 { 327 throw WebmanExceptionHandler.getException(e); 328 } 329 } 330 331 } 332 | Popular Tags |