001: package de.webman.content.workflow.db;
002:
003: import com.teamkonzept.db.*;
004: import com.teamkonzept.lib.*;
005: import de.webman.content.workflow.*;
006:
007: import java.util.*;
008: import java.sql.*;
009:
010: /**
011: haelt die Daten einer Transition, Implementierung von TKDBData
012: * @author $Author: doehling $
013: * @version $Revision: 1.2 $
014: */
015: public class VersionStatusTransitionDBData extends TKDBData implements
016: TKHashable {
017:
018: /** Der Event String (prefix) */
019: private static final String EVENT_STRING = "CE_SWITCH_EVENT";
020:
021: /** Ausgangsstatus */
022: public int status_id;
023:
024: /** Zielstatus */
025: public int new_status_id;
026:
027: /** Attribute der transition */
028: public String transition_attributes;
029:
030: /** Ausgangsstatus als String */
031: public String status;
032:
033: /** Zielstatus als String */
034: public String new_status;
035:
036: private String event;
037:
038: /** +,-, ? */
039: public String mode;
040:
041: /** steht fuer das l */
042: public boolean delete;
043:
044: TKHashtable hashed;
045:
046: /** Klasse des Ausgangsstatus */
047: public VersionStatus fromStatus;
048:
049: /** Klasse des Zielstatus */
050: public VersionStatus toStatus;
051:
052: public void init() {
053:
054: status_id = -1;
055: new_status_id = -1;
056: transition_attributes = null;
057:
058: status = null;
059: new_status = null;
060:
061: mode = null;
062: delete = false;
063:
064: hashed = null;
065: fromStatus = null;
066: toStatus = null;
067: event = null;
068: }
069:
070: /**
071: liefert den Event zurueck, der diese
072: Transition ausloest
073: */
074: public String getEvent() {
075: if (event == null) {
076: if (mode != null && mode.equals("+"))
077: event = EVENT_STRING + "_" + status_id + "_"
078: + new_status_id;
079: else
080: event = "";
081: }
082: return event;
083: }
084:
085: public boolean isTransition() {
086: return mode.equals("+");
087: }
088:
089: public VersionStatusTransitionDBData() {
090:
091: this .init();
092: }
093:
094: public VersionStatusTransitionDBData(int status_id,
095: int new_status_id, String transition_attributes) {
096: this .init();
097:
098: this .status_id = status_id;
099: this .new_status_id = new_status_id;
100: this .transition_attributes = transition_attributes;
101:
102: this .scanAttributes();
103: }
104:
105: public VersionStatusTransitionDBData(VersionStatics statics,
106: int status_id, String status, int new_status_id,
107: String new_status, String transition_attributes) {
108: this .status_id = status_id;
109: this .new_status_id = new_status_id;
110: this .transition_attributes = transition_attributes;
111:
112: this .status = status;
113: this .new_status = new_status;
114:
115: resolveStatus(statics);
116: this .scanAttributes();
117: }
118:
119: public VersionStatusTransitionDBData(VersionStatics statics,
120: ResultSet r) {
121: try {
122: this .fill(statics, r);
123: } catch (Exception ex) {
124: this .init();
125: }
126: }
127:
128: public VersionStatusTransitionDBData(ResultSet r) {
129:
130: this (null, r);
131: }
132:
133: public void insertPrimaryIntoQuery(TKQuery query)
134: throws SQLException {
135:
136: query.setQueryParams("STATUS_ID", new Integer(status_id));
137: query.setQueryParams("NEW_STATUS_ID",
138: new Integer(new_status_id));
139: }
140:
141: public void insertInitialIntoQuery(TKQuery query)
142: throws SQLException {
143:
144: query.setQueryParams("TRANSITION_ATTRIBUTES",
145: transition_attributes);
146: }
147:
148: public void insertIntoQuery(TKQuery query) throws SQLException {
149: insertPrimaryIntoQuery(query);
150: insertInitialIntoQuery(query);
151: }
152:
153: public void fill(VersionStatics statics, ResultSet r)
154: throws SQLException {
155: this .status_id = r.getInt("STATUS_ID");
156: this .new_status_id = r.getInt("NEW_STATUS_ID");
157: this .transition_attributes = r
158: .getString("TRANSITION_ATTRIBUTES");
159:
160: this .status = r.getString("STATUS");
161: this .new_status = r.getString("NEW_STATUS");
162:
163: resolveStatus(statics);
164: this .scanAttributes();
165: }
166:
167: public void fill(ResultSet r) throws SQLException {
168: fill(null, r);
169: }
170:
171: public void assembleAttributes() {
172: this .transition_attributes = (this .mode == null ? "?"
173: : this .mode)
174: + ";" + (this .delete ? "delete;" : "");
175: }
176:
177: public void scanAttributes() {
178:
179: mode = "?";
180: delete = false;
181: event = null;
182: if (transition_attributes == null)
183: return;
184:
185: StringTokenizer tokenizer = new StringTokenizer(
186: transition_attributes, ";");
187: while (tokenizer.hasMoreTokens()) {
188: String attr = tokenizer.nextToken();
189: if (attr == null)
190: continue;
191: if (attr.equalsIgnoreCase("?"))
192: mode = attr;
193: else if (attr.equalsIgnoreCase("+"))
194: mode = attr;
195: else if (attr.equalsIgnoreCase("-"))
196: mode = attr;
197: else if (attr.equalsIgnoreCase("delete"))
198: delete = true;
199: }
200: makeHashed();
201: }
202:
203: public void resolveStatus(VersionStatics statics) {
204:
205: if (statics == null)
206: return;
207: fromStatus = (VersionStatus) statics.getStatusPool().get(
208: new Integer(this .status_id));
209: toStatus = (VersionStatus) statics.getStatusPool().get(
210: new Integer(this .new_status_id));
211: rehashStatus();
212: }
213:
214: public void rehashStatus() {
215: if (hashed == null) {
216: makeHashed();
217: return;
218: }
219: if (fromStatus != null)
220: hashed.put("FROM", fromStatus.toHashtable());
221: if (toStatus != null)
222: hashed.put("TO", toStatus.toHashtable());
223: }
224:
225: public void makeHashed() {
226:
227: hashed = new TKHashtable();
228:
229: hashed.put("STATUS_ID", new Integer(status_id));
230: hashed.put("NEW_STATUS_ID", new Integer(new_status_id));
231:
232: if (status != null)
233: hashed.put("STATUS", status);
234: if (new_status != null)
235: hashed.put("NEW_STATUS", new_status);
236:
237: hashed.put("THIS_MODE", mode == null ? "?" : mode);
238: hashed.put("ATTR.L", delete ? "ON" : "OFF");
239: hashed.put("EVENT", getEvent());
240: rehashStatus();
241: }
242:
243: public TKHashtable toHashtable() {
244: if (hashed == null)
245: makeHashed();
246: // TKHashtable hash = new TKHashtable(); alex
247: return hashed;
248: }
249:
250: public String toString() {
251: return "( TRANSITION := " + "(STATUS_ID = "
252: + String.valueOf(status_id) + ", NEW_STATUS_ID = "
253: + String.valueOf(new_status_id)
254: + ", TRANSITION_ATTRIBUTES = " + transition_attributes
255: + ", STATUS = " + status + ", NEW_STATUS = "
256: + new_status + ", MODE = " + mode + ", ATTR.l = "
257: + delete + ")<BR>" + ")<BR>";
258: }
259:
260: public String toSql() {
261: return "INSERT INTO VERSION_STATUS_TRANSITION (STATUS_ID, NEW_STATUS_ID, TRANSITION_ATTRIBUTES) "
262: + "VALUES ("
263: + status_id
264: + ","
265: + new_status_id
266: + ",\""
267: + transition_attributes + "\") ";
268: }
269: }
|