01: package com.teamkonzept.lib;
02:
03: import java.util.*;
04:
05: public class TKVectorIteratorPlugin extends TKIteratorPlugin {
06:
07: private String itemName;
08: private boolean doSort;
09: private TKHashtable subPlugins = new TKHashtable();
10:
11: public TKVectorIteratorPlugin(String listName, String itemName,
12: TKVector vec, boolean doSort) {
13:
14: super (vec, listName, doSort);
15:
16: this .itemName = itemName;
17: this .doSort = doSort;
18: }
19:
20: public boolean applyThis(Object item, TKTemplate template,
21: String path) {
22: Integer idx = (Integer) template.getEnumerationContext(name);
23: TKHashtable subs = (TKHashtable) subPlugins.get(idx);
24: if (subs == null) {
25: subs = new TKHashtable();
26: subPlugins.put(idx, subs);
27: }
28: template.set("ITERATOR_PATH", path);
29: if (item instanceof TKHashtable) {
30: subs.put(name + ".SUB", new TKHashtableIteratorPlugin(name
31: + ".SUB", itemName, (TKHashtable) item, true));
32: template.set(name + ".SUB.LEN", new Integer(
33: ((TKHashtable) item).size()));
34:
35: TKHashtableIteratorPlugin.applyTable(name, template,
36: (TKHashtable) item, itemName, subs, path);
37: return true;
38:
39: } else if (item instanceof TKVector) {
40: subs.put(name + ".SUB", new TKVectorIteratorPlugin(name
41: + ".SUB", itemName, (TKVector) item, doSort));
42: template.set(name + ".SUB.LEN", new Integer(
43: ((TKVector) item).size()));
44: return true;
45:
46: } else if (item instanceof TKHashable) {
47: TKHashtable sub = ((TKHashable) item).toHashtable();
48: subs.put(name + ".SUB", new TKHashtableIteratorPlugin(name
49: + ".SUB", itemName, sub, true));
50: template.set(name + ".SUB.LEN", new Integer(sub.size()));
51:
52: TKHashtableIteratorPlugin.applyTable(name, template,
53: ((TKHashable) item).toHashtable(), itemName, subs,
54: path);
55: return true;
56:
57: } else if (item instanceof TKVectorizable) {
58: TKVector sub = ((TKVectorizable) item).toVector();
59: subs.put(name + ".SUB", new TKVectorIteratorPlugin(name
60: + ".SUB", itemName, sub, doSort));
61: template.set(name + ".SUB.LEN", new Integer(sub.size()));
62: return true;
63: }
64:
65: if (itemName == null)
66: itemName = "ITEM_VALUE";
67: else
68: template.set(itemName, item.toString());
69:
70: template.set(itemName, item.toString());
71: template.set("ITEM_NAME", itemName);
72: template.set("ITEM_VALUE", item.toString());
73:
74: return true;
75: }
76:
77: public boolean applyChilds(TKTemplate template, int i,
78: String currListName, String path) {
79: if (subPlugins == null)
80: return false;
81: Integer idx = (Integer) template.getEnumerationContext(name);
82: if (idx == null)
83: return false;
84: TKHashtable subs = (TKHashtable) subPlugins.get(idx);
85: if (subs == null)
86: return false;
87:
88: Enumeration e = subs.elements();
89: while (e.hasMoreElements()) {
90: TKIteratorPlugin plugin = (TKIteratorPlugin) e
91: .nextElement();
92: if (plugin.apply(template, i, currListName, null))
93: return true;
94: }
95:
96: return false;
97: }
98: }
|