View Javadoc
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   * Copyright (c) 2006, Codehaus.org
13   *
14   * Permission is hereby granted, free of charge, to any person obtaining a copy of
15   * this software and associated documentation files (the "Software"), to deal in
16   * the Software without restriction, including without limitation the rights to
17   * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
18   * of the Software, and to permit persons to whom the Software is furnished to do
19   * so, subject to the following conditions:
20   *
21   * The above copyright notice and this permission notice shall be included in all
22   * copies or substantial portions of the Software.
23   *
24   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30   * SOFTWARE.
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 }