1 package org.codehaus.modello.plugin.stax;
2
3 import java.util.ArrayList;
4 import java.util.HashMap;
5 import java.util.LinkedList;
6 import java.util.List;
7 import java.util.Map;
8
9 import org.codehaus.modello.model.ModelAssociation;
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 class GeneratorNode {
34 private final String to;
35
36 private boolean referencableChildren;
37
38 private List<GeneratorNode> children = new LinkedList<GeneratorNode>();
39
40 private ModelAssociation association;
41
42 private boolean referencable;
43
44 private Map<String, GeneratorNode> nodesWithReferencableChildren = new HashMap<String, GeneratorNode>();
45
46 private List<String> chain;
47
48 GeneratorNode(String to, GeneratorNode parent) {
49 this(to, parent, null);
50 }
51
52 GeneratorNode(ModelAssociation association, GeneratorNode parent) {
53 this(association.getTo(), parent, association);
54 }
55
56 private GeneratorNode(String to, GeneratorNode parent, ModelAssociation association) {
57 this.to = to;
58 this.association = association;
59 this.chain = parent != null ? new ArrayList<String>(parent.getChain()) : new ArrayList<String>();
60 this.chain.add(to);
61 }
62
63 public boolean isReferencableChildren() {
64 return referencableChildren;
65 }
66
67 public void setReferencableChildren(boolean referencableChildren) {
68 this.referencableChildren = referencableChildren;
69 }
70
71 public void addChild(GeneratorNode child) {
72 children.add(child);
73 if (child.referencableChildren) {
74 nodesWithReferencableChildren.put(child.to, child);
75 }
76 }
77
78 public List<GeneratorNode> getChildren() {
79 return children;
80 }
81
82 public String toString() {
83 return "to = " + to + "; referencableChildren = " + referencableChildren + "; children = " + children;
84 }
85
86 public String getTo() {
87 return to;
88 }
89
90 public ModelAssociation getAssociation() {
91 return association;
92 }
93
94 public void setAssociation(ModelAssociation association) {
95 this.association = association;
96 }
97
98 public void setReferencable(boolean referencable) {
99 this.referencable = referencable;
100 }
101
102 public boolean isReferencable() {
103 return referencable;
104 }
105
106 public Map<String, GeneratorNode> getNodesWithReferencableChildren() {
107 return nodesWithReferencableChildren;
108 }
109
110 public void addNodesWithReferencableChildren(Map<String, GeneratorNode> allChildNodes) {
111 this.nodesWithReferencableChildren.putAll(allChildNodes);
112 }
113
114 public List<String> getChain() {
115 return chain;
116 }
117 }