View Javadoc

1   package net.trajano.twiff.renderer;
2   
3   import java.util.Collections;
4   import java.util.LinkedHashMap;
5   import java.util.LinkedList;
6   import java.util.List;
7   import java.util.Map;
8   
9   /***
10   * This is an element that has a component.
11   * 
12   * @author Archimedes Trajano
13   */
14  public class ComponentElement implements CompositePageElement {
15      /***
16       * Attributes used in the element. It is recommended that a
17       * {@link LinkedHashMap} is used to ensure order.
18       */
19      private final Map<String, String> attributes;
20  
21      /***
22       * Element name. Basically the tag.
23       */
24      private final String elementName;
25  
26      /***
27       * List of sub-elements in this component. It it is recommended that a
28       * {@link LinkedList} is used as it would only be read in order.
29       */
30      private final List<PageElement> subElements = new LinkedList<PageElement>();
31  
32      /***
33       * Column number in the document.
34       */
35      private final int columnNumber;
36  
37      /***
38       * Line number in the document.
39       */
40      private final int lineNumber;
41  
42      /***
43       * Constructs the element.
44       * 
45       * @param elementName
46       *            element name.
47       * @param componentName
48       * @param parameters
49       *            parameters.
50       * @param attributes
51       *            attributes in the element.
52       */
53      public ComponentElement(final String elementName, final String componentName, final List<String> parameters, final Map<String, String> attributes) {
54          this.elementName = elementName;
55          this.attributes = attributes;
56          this.componentName = componentName;
57          this.parameters = parameters;
58          this.columnNumber = 0;
59          this.lineNumber = 0;
60      }
61  
62      /***
63       * 
64       */
65      private final String componentName;
66  
67      /***
68       * 
69       */
70      private final List<String> parameters;
71  
72      /***
73       * Accepts a visitor that should visit the page data.
74       * 
75       * @param visitor
76       *            visitor.
77       */
78      public final void accept(final PageElementVisitor visitor) {
79          if (subElements.isEmpty()) {
80              visitor.visitComponentEmptyElement(this, elementName, attributes);
81          } else {
82              visitor.startComponentElement(this, elementName, attributes, subElements);
83              visitor.endComponentElement(this, elementName, attributes, subElements);
84          }
85          
86          //visitor.visitComponentElement(this, componentName, parameters, elementName, attributes, subElements);
87      }
88  
89      /***
90       * Returns the attributes.
91       * 
92       * @return attributes.
93       */
94      public final Map<String, String> getAttributes() {
95          return Collections.unmodifiableMap(attributes);
96      }
97  
98      /***
99       * Returns the sub-elements in the element.
100      * 
101      * @return sub-elements.
102      */
103     public final List<PageElement> getElements() {
104         return Collections.unmodifiableList(subElements);
105     }
106 
107     /***
108      * @return the component name
109      */
110     public final String getComponentName() {
111         return componentName;
112     }
113 
114     /***
115      * @return the element name
116      */
117     public final String getElementName() {
118         return elementName;
119     }
120 
121     /***
122      * @return the parameters of the component.
123      */
124     public final List<String> getParameters() {
125         return parameters;
126     }
127 
128     /***
129      * @see net.trajano.twiff.renderer.CompositePageElement#addElement(net.trajano.twiff.renderer.PageElement)
130      */
131     public final void addElement(final PageElement element) {
132         subElements.add(element);
133     }
134 
135     /***
136      * @see net.trajano.twiff.renderer.PageElement#getColumnNumber()
137      */
138     public int getColumnNumber() {
139         // TODO Auto-generated method stub
140         return 0;
141     }
142 
143     /***
144      * @see net.trajano.twiff.renderer.PageElement#getLineNumber()
145      */
146     public int getLineNumber() {
147         // TODO Auto-generated method stub
148         return 0;
149     }
150 }