01: package net.sourceforge.cruisecontrol.gendoc;
02:
03: import java.util.List;
04: import java.util.ArrayList;
05:
06: /**
07: * A TreeNode for our plugin tree. The {@link #getMe()} returns a {@link PluginModel} instance.
08: * @author jerome@coffeebreaks.org
09: */
10: public class PluginTreeNodeImpl implements TreeNode {
11: PluginTreeNodeImpl parent;
12: PluginModel me;
13: List children = new ArrayList();
14: List alternatives = new ArrayList();
15:
16: public PluginTreeNodeImpl(PluginTreeNodeImpl parent, PluginModel me) {
17: this .parent = parent;
18: this .me = me;
19: }
20:
21: public void addChild(PluginTreeNodeImpl child) {
22: if (child.parent != this ) {
23: throw new IllegalStateException("parent differ: parent: "
24: + child.parent + " - this: " + this );
25: }
26: children.add(child);
27: }
28:
29: public Object getMe() {
30: return me;
31: }
32:
33: public String getNodeName() {
34: if (me.name != null) {
35: return me.name;
36: }
37: if (me.registryName != null) {
38: return me.registryName;
39: }
40:
41: // System.err.println("NodeName not found. Probably not a real plugin... " + model);
42: // search for a name...
43: if (this .getParent() != null) {
44: PluginModel parentModel = (PluginModel) ((TreeNode) this
45: .getParent()).getMe();
46: for (int i = 0; i < parentModel.children.children.size(); i++) {
47: PluginModel.Child child = (PluginModel.Child) parentModel.children.children
48: .get(i);
49: if (child.type.equals(me.type)) {
50: return child.name;
51: }
52: }
53: }
54: return "FIXME-"
55: + this .me.type
56: .substring(this .me.type.lastIndexOf('.') + 1);
57: }
58:
59: public PluginModel getMeAsPlugin() {
60: return me;
61: }
62:
63: public TreeNode getParent() {
64: return parent;
65: }
66:
67: public List getChildren() {
68: return children;
69: }
70:
71: public List getAlternatives() {
72: return alternatives;
73: }
74:
75: /**
76: * Used to add an alternative (usually an implementation of the current node that is an interface)
77: * @param alternative
78: */
79: public void addAlternative(PluginTreeNodeImpl alternative) {
80: if (!this .me.isInterface()) {
81: throw new IllegalArgumentException(
82: "Alternative can only be added to 'interface' nodes");
83: }
84: if (alternative.parent != this .getParent()) {
85: throw new IllegalStateException("parent differ: parent: "
86: + alternative.parent + " - this: "
87: + this .getParent());
88: }
89: alternatives.add(alternative);
90: }
91:
92: public String toString() {
93: return "Node for - " + me;
94: }
95: }
|