1 package com.teamkonzept.field; 2 3 import com.teamkonzept.lib.*; 4 import com.teamkonzept.db.*; 5 import com.teamkonzept.field.db.*; 6 import com.teamkonzept.field.db.queries.*; 7 import de.webman.content.db.queries.*; 8 9 import java.sql.*; 10 11 public class TKContentAttributeOption implements TKSortable { 12 13 public String name; 14 public String typeInfo; 15 public String classname; 16 public int type; 17 public int attributeId; 18 19 static boolean initialized = false; 20 21 static TKHashtable options = null; 22 static TKHashtable ids = null; 23 24 public TKContentAttributeOption () { 25 26 this.name = null; 27 this.typeInfo = null; 28 this.classname = null; 29 this.type = -1; 30 this.attributeId = -1; 31 } 32 33 TKContentAttributeOption (String name, String typeInfo,String classname, int type, int attributeId) { 34 35 this.name = name; 36 this.typeInfo = typeInfo; 37 this.classname = classname; 38 this.type = type; 39 this.attributeId = attributeId; 40 } 41 42 public int cmp (TKSortable other) { 43 44 if (!(other instanceof TKContentAttributeOption)) 45 return toString().compareTo (other.toString()); 46 47 TKContentAttributeOption otherOption = (TKContentAttributeOption) other; 48 49 if ((name == null) && (otherOption.name != null)) return -1; 50 else if ((name != null) && (otherOption.name == null)) return 1; 51 else if ((name == null) && (otherOption.name == null)) return 0; 52 else return name.compareTo (otherOption.name); 53 }; 54 55 public static TKContentAttributeOption getOptionById (int id) { 56 57 setupOptions (); 58 return (TKContentAttributeOption) ids.get(new Integer (id)); 59 } 60 61 public static TKHashtable getOptions () { 62 63 setupOptions (); 64 return options; 65 } 66 67 public static synchronized void setupOptions () { 68 69 if (initialized) return; 70 71 options = new TKHashtable(); 72 ids = new TKHashtable(); 73 74 ResultSet rs; 75 76 try { 77 TKQuery q = TKDBManager.newQuery(TKDBAttributeOptions.class); 78 q.execute(); 79 rs = q.fetchResultSet(); 80 81 while (rs.next()) { 82 83 int attributeId = rs.getInt ("ATTRIBUTE_ID"); 84 String name = rs.getString ("NAME"); 85 String classname = rs.getString("CLASSNAME"); 86 int type = rs.getInt ("TYPE"); 87 String typeInfo = TKContentAttributeTableData.typeInfo(type); 88 89 TKContentAttributeOption option = new TKContentAttributeOption (name,typeInfo,classname,type,attributeId); 90 options.put (name,option); 91 ids.put (new Integer (attributeId),option); 92 } 93 94 } catch (Exception ex) 95 { 96 97 String msg = ex.getMessage(); 98 if (msg == null) msg = "Unbekannter Fehler: "+ex; 99 102 return; 103 } 104 105 initialized = true; 106 } 107 } 108
| Popular Tags
|