View Javadoc

1   package org.codehaus.modello.plugin.stax;
2   
3   import org.codehaus.modello.model.ModelAssociation;
4   
5   import java.util.ArrayList;
6   import java.util.HashMap;
7   import java.util.LinkedList;
8   import java.util.List;
9   import java.util.Map;
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  {
35      private final String to;
36  
37      private boolean referencableChildren;
38  
39      private List<GeneratorNode> children = new LinkedList<GeneratorNode>();
40  
41      private ModelAssociation association;
42  
43      private boolean referencable;
44  
45      private Map<String, GeneratorNode> nodesWithReferencableChildren = new HashMap<String, GeneratorNode>();
46  
47      private List<String> chain;
48  
49      GeneratorNode( String to, GeneratorNode parent )
50      {
51          this( to, parent, null );
52      }
53  
54      GeneratorNode( ModelAssociation association, GeneratorNode parent )
55      {
56          this( association.getTo(), parent, association );
57      }
58  
59      private GeneratorNode( String to, GeneratorNode parent, ModelAssociation association )
60      {
61          this.to = to;
62          this.association = association;
63          this.chain = parent != null ? new ArrayList<String>( parent.getChain() ) : new ArrayList<String>();
64          this.chain.add( to );
65      }
66  
67      public boolean isReferencableChildren()
68      {
69          return referencableChildren;
70      }
71  
72      public void setReferencableChildren( boolean referencableChildren )
73      {
74          this.referencableChildren = referencableChildren;
75      }
76  
77      public void addChild( GeneratorNode child )
78      {
79          children.add( child );
80          if ( child.referencableChildren )
81          {
82              nodesWithReferencableChildren.put( child.to, child );
83          }
84      }
85  
86      public List<GeneratorNode> getChildren()
87      {
88          return children;
89      }
90  
91      public String toString()
92      {
93          return "to = " + to + "; referencableChildren = " + referencableChildren + "; children = " + children;
94      }
95  
96      public String getTo()
97      {
98          return to;
99      }
100 
101     public ModelAssociation getAssociation()
102     {
103         return association;
104     }
105 
106     public void setAssociation( ModelAssociation association )
107     {
108         this.association = association;
109     }
110 
111     public void setReferencable( boolean referencable )
112     {
113         this.referencable = referencable;
114     }
115 
116     public boolean isReferencable()
117     {
118         return referencable;
119     }
120 
121     public Map<String, GeneratorNode> getNodesWithReferencableChildren()
122     {
123         return nodesWithReferencableChildren;
124     }
125 
126     public void addNodesWithReferencableChildren( Map<String, GeneratorNode> allChildNodes )
127     {
128         this.nodesWithReferencableChildren.putAll( allChildNodes );
129     }
130 
131     public List<String> getChain()
132     {
133         return chain;
134     }
135 }