KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > teamkonzept > field > TKContentAttributeOption


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 JavaDoc name;
14     public String JavaDoc typeInfo;
15     public String JavaDoc 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 JavaDoc name, String JavaDoc typeInfo,String JavaDoc 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 JavaDoc (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 JavaDoc name = rs.getString ("NAME");
85                 String JavaDoc classname = rs.getString("CLASSNAME");
86                 int type = rs.getInt ("TYPE");
87                 String JavaDoc 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 JavaDoc (attributeId),option);
92             }
93
94         } catch (Exception JavaDoc ex)
95         {
96
97             String JavaDoc msg = ex.getMessage();
98             if (msg == null) msg = "Unbekannter Fehler: "+ex;
99             /*
100             TKLog.println ("TKContentAttributeOption.getOptions() failed: "+msg);
101             ex.printStackTrace (TKLog.log());*/

102             return;
103         }
104
105         initialized = true;
106     }
107 }
108
Free Books   Free Magazines  
Popular Tags