1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.hivemind.impl; |
16 |
| |
17 |
| import java.util.ArrayList; |
18 |
| import java.util.Collections; |
19 |
| import java.util.HashMap; |
20 |
| import java.util.List; |
21 |
| import java.util.Map; |
22 |
| |
23 |
| import org.apache.hivemind.Attribute; |
24 |
| import org.apache.hivemind.Element; |
25 |
| import org.apache.hivemind.util.ToStringBuilder; |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| public final class ElementImpl extends BaseLocatable implements Element |
33 |
| { |
34 |
| private String _elementName; |
35 |
| private String _content; |
36 |
| private List _elements; |
37 |
| private List _safeElements; |
38 |
| private List _attributes; |
39 |
| private Map _attributesMap; |
40 |
| private List _safeAttributes; |
41 |
| |
42 |
5406
| public void setElementName(String elementName)
|
43 |
| { |
44 |
5406
| _elementName = elementName;
|
45 |
| } |
46 |
| |
47 |
3861
| public String getElementName()
|
48 |
| { |
49 |
3861
| return _elementName;
|
50 |
| } |
51 |
| |
52 |
9293
| public void addAttribute(Attribute attribute)
|
53 |
| { |
54 |
9293
| if (_attributes == null)
|
55 |
| { |
56 |
5245
| _attributes = new ArrayList();
|
57 |
5245
| _attributesMap = new HashMap();
|
58 |
| } |
59 |
| |
60 |
9293
| _attributes.add(attribute);
|
61 |
9293
| _attributesMap.put(attribute.getName(), attribute);
|
62 |
| } |
63 |
| |
64 |
1073
| public void addElement(Element element)
|
65 |
| { |
66 |
1073
| if (_elements == null)
|
67 |
1050
| _elements = new ArrayList();
|
68 |
| |
69 |
1073
| _elements.add(element);
|
70 |
| } |
71 |
| |
72 |
3843
| public synchronized List getAttributes()
|
73 |
| { |
74 |
3843
| if (_attributes == null)
|
75 |
67
| return Collections.EMPTY_LIST;
|
76 |
| |
77 |
3776
| if (_safeAttributes == null)
|
78 |
3776
| _safeAttributes = Collections.unmodifiableList(_attributes);
|
79 |
| |
80 |
3776
| return _safeAttributes;
|
81 |
| } |
82 |
| |
83 |
25
| public String getContent()
|
84 |
| { |
85 |
25
| if (_content == null)
|
86 |
1
| return "";
|
87 |
| |
88 |
24
| return _content;
|
89 |
| } |
90 |
| |
91 |
3841
| public synchronized List getElements()
|
92 |
| { |
93 |
3841
| if (_elements == null)
|
94 |
3362
| return Collections.EMPTY_LIST;
|
95 |
| |
96 |
479
| if (_safeElements == null)
|
97 |
478
| _safeElements = Collections.unmodifiableList(_elements);
|
98 |
| |
99 |
479
| return _safeElements;
|
100 |
| } |
101 |
| |
102 |
12032
| public String getAttributeValue(String attributeName)
|
103 |
| { |
104 |
12032
| if (_attributesMap == null)
|
105 |
3
| return null;
|
106 |
| |
107 |
12029
| Attribute a = (Attribute) _attributesMap.get(attributeName);
|
108 |
| |
109 |
12029
| if (a == null)
|
110 |
5317
| return null;
|
111 |
| |
112 |
6712
| return a.getValue();
|
113 |
| } |
114 |
| |
115 |
0
| public boolean isEmpty()
|
116 |
| { |
117 |
0
| return _elements == null || _elements.size() == 0;
|
118 |
| } |
119 |
| |
120 |
5399
| public void setContent(String string)
|
121 |
| { |
122 |
5399
| _content = string;
|
123 |
| } |
124 |
| |
125 |
209
| public String toString()
|
126 |
| { |
127 |
209
| ToStringBuilder builder = new ToStringBuilder(this);
|
128 |
| |
129 |
209
| builder.append("elementName", _elementName);
|
130 |
209
| builder.append("attributes", _attributes);
|
131 |
209
| builder.append("elements", _elements);
|
132 |
209
| builder.append("content", _content);
|
133 |
| |
134 |
209
| return builder.toString();
|
135 |
| } |
136 |
| } |