001: package com.teamkonzept.field;
002:
003: import com.teamkonzept.lib.*;
004: import com.teamkonzept.db.*;
005: import com.teamkonzept.field.db.*;
006: import com.teamkonzept.field.db.queries.*;
007: import de.webman.content.db.queries.*;
008:
009: import java.sql.*;
010:
011: public class TKContentAttributeOption implements TKSortable {
012:
013: public String name;
014: public String typeInfo;
015: public String classname;
016: public int type;
017: public int attributeId;
018:
019: static boolean initialized = false;
020:
021: static TKHashtable options = null;
022: static TKHashtable ids = null;
023:
024: public TKContentAttributeOption() {
025:
026: this .name = null;
027: this .typeInfo = null;
028: this .classname = null;
029: this .type = -1;
030: this .attributeId = -1;
031: }
032:
033: TKContentAttributeOption(String name, String typeInfo,
034: String classname, int type, int attributeId) {
035:
036: this .name = name;
037: this .typeInfo = typeInfo;
038: this .classname = classname;
039: this .type = type;
040: this .attributeId = attributeId;
041: }
042:
043: public int cmp(TKSortable other) {
044:
045: if (!(other instanceof TKContentAttributeOption))
046: return toString().compareTo(other.toString());
047:
048: TKContentAttributeOption otherOption = (TKContentAttributeOption) other;
049:
050: if ((name == null) && (otherOption.name != null))
051: return -1;
052: else if ((name != null) && (otherOption.name == null))
053: return 1;
054: else if ((name == null) && (otherOption.name == null))
055: return 0;
056: else
057: return name.compareTo(otherOption.name);
058: };
059:
060: public static TKContentAttributeOption getOptionById(int id) {
061:
062: setupOptions();
063: return (TKContentAttributeOption) ids.get(new Integer(id));
064: }
065:
066: public static TKHashtable getOptions() {
067:
068: setupOptions();
069: return options;
070: }
071:
072: public static synchronized void setupOptions() {
073:
074: if (initialized)
075: return;
076:
077: options = new TKHashtable();
078: ids = new TKHashtable();
079:
080: ResultSet rs;
081:
082: try {
083: TKQuery q = TKDBManager
084: .newQuery(TKDBAttributeOptions.class);
085: q.execute();
086: rs = q.fetchResultSet();
087:
088: while (rs.next()) {
089:
090: int attributeId = rs.getInt("ATTRIBUTE_ID");
091: String name = rs.getString("NAME");
092: String classname = rs.getString("CLASSNAME");
093: int type = rs.getInt("TYPE");
094: String typeInfo = TKContentAttributeTableData
095: .typeInfo(type);
096:
097: TKContentAttributeOption option = new TKContentAttributeOption(
098: name, typeInfo, classname, type, attributeId);
099: options.put(name, option);
100: ids.put(new Integer(attributeId), option);
101: }
102:
103: } catch (Exception ex) {
104:
105: String msg = ex.getMessage();
106: if (msg == null)
107: msg = "Unbekannter Fehler: " + ex;
108: /*
109: TKLog.println ("TKContentAttributeOption.getOptions() failed: "+msg);
110: ex.printStackTrace (TKLog.log());*/
111: return;
112: }
113:
114: initialized = true;
115: }
116: }
|