1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| package org.dom4j.bean; |
11 |
| |
12 |
| import java.util.AbstractList; |
13 |
| |
14 |
| import org.dom4j.Attribute; |
15 |
| import org.dom4j.QName; |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| public class BeanAttributeList extends AbstractList { |
24 |
| |
25 |
| |
26 |
| private BeanElement parent; |
27 |
| |
28 |
| |
29 |
| private BeanMetaData beanMetaData; |
30 |
| |
31 |
| |
32 |
| private BeanAttribute[] attributes; |
33 |
| |
34 |
| |
35 |
0
| public BeanAttributeList(BeanElement parent, BeanMetaData beanMetaData) {
|
36 |
0
| this.parent = parent;
|
37 |
0
| this.beanMetaData = beanMetaData;
|
38 |
0
| this.attributes = new BeanAttribute[ beanMetaData.attributeCount() ];
|
39 |
| } |
40 |
| |
41 |
4
| public BeanAttributeList(BeanElement parent) {
|
42 |
4
| this.parent = parent;
|
43 |
| |
44 |
4
| Object data = parent.getData();
|
45 |
4
| Class beanClass = (data != null) ? data.getClass() : null;
|
46 |
4
| this.beanMetaData = BeanMetaData.get( beanClass );
|
47 |
4
| this.attributes = new BeanAttribute[ beanMetaData.attributeCount() ];
|
48 |
| } |
49 |
| |
50 |
4
| public Attribute attribute(String name) {
|
51 |
4
| int index = beanMetaData.getIndex(name);
|
52 |
4
| return attribute(index);
|
53 |
| } |
54 |
| |
55 |
0
| public Attribute attribute(QName qname) {
|
56 |
0
| int index = beanMetaData.getIndex(qname);
|
57 |
0
| return attribute(index);
|
58 |
| } |
59 |
| |
60 |
4
| public BeanAttribute attribute(int index) {
|
61 |
4
| if ( index >= 0 && index <= attributes.length ) {
|
62 |
4
| BeanAttribute attribute = attributes[index];
|
63 |
4
| if ( attribute == null ) {
|
64 |
4
| attribute = createAttribute( parent, index );
|
65 |
4
| attributes[index] = attribute;
|
66 |
| } |
67 |
4
| return attribute;
|
68 |
| } |
69 |
0
| return null;
|
70 |
| } |
71 |
| |
72 |
0
| public BeanElement getParent() {
|
73 |
0
| return parent;
|
74 |
| } |
75 |
| |
76 |
0
| public QName getQName(int index) {
|
77 |
0
| return beanMetaData.getQName(index);
|
78 |
| } |
79 |
| |
80 |
0
| public Object getData(int index) {
|
81 |
0
| return beanMetaData.getData(index, parent.getData());
|
82 |
| } |
83 |
| |
84 |
4
| public void setData(int index, Object data) {
|
85 |
4
| beanMetaData.setData(index, parent.getData(), data);
|
86 |
| } |
87 |
| |
88 |
| |
89 |
| |
90 |
| |
91 |
0
| public int size() {
|
92 |
0
| return attributes.length;
|
93 |
| } |
94 |
| |
95 |
0
| public Object get(int index) {
|
96 |
0
| BeanAttribute attribute = attributes[index];
|
97 |
0
| if ( attribute == null ) {
|
98 |
0
| attribute = createAttribute( parent, index );
|
99 |
0
| attributes[index] = attribute;
|
100 |
| } |
101 |
0
| return attribute;
|
102 |
| } |
103 |
| |
104 |
0
| public boolean add(Object object) {
|
105 |
0
| throw new UnsupportedOperationException( "add(int, Object) is not supported" );
|
106 |
| } |
107 |
| |
108 |
0
| public void add(int index, Object object) {
|
109 |
0
| throw new UnsupportedOperationException( "add(int, Object) is not supported" );
|
110 |
| } |
111 |
| |
112 |
0
| public Object set(int index, Object object) {
|
113 |
0
| throw new UnsupportedOperationException( "set(int, Object) is not supported" );
|
114 |
| } |
115 |
| |
116 |
0
| public boolean remove(Object object) {
|
117 |
0
| return false;
|
118 |
| } |
119 |
| |
120 |
0
| public Object remove(int index) {
|
121 |
0
| BeanAttribute attribute = (BeanAttribute) get(index);
|
122 |
0
| Object oldValue = attribute.getValue();
|
123 |
0
| attribute.setValue(null);
|
124 |
0
| return oldValue;
|
125 |
| } |
126 |
| |
127 |
0
| public void clear() {
|
128 |
0
| for ( int i = 0, size = attributes.length; i < size; i++ ) {
|
129 |
0
| BeanAttribute attribute = attributes[i];
|
130 |
0
| if ( attribute != null ) {
|
131 |
0
| attribute.setValue( null );
|
132 |
| } |
133 |
| } |
134 |
| } |
135 |
| |
136 |
| |
137 |
| |
138 |
| |
139 |
4
| protected BeanAttribute createAttribute( BeanElement parent, int index ) {
|
140 |
4
| return new BeanAttribute( this, index );
|
141 |
| } |
142 |
| } |
143 |
| |
144 |
| |
145 |
| |
146 |
| |
147 |
| |
148 |
| |
149 |
| |
150 |
| |
151 |
| |
152 |
| |
153 |
| |
154 |
| |
155 |
| |
156 |
| |
157 |
| |
158 |
| |
159 |
| |
160 |
| |
161 |
| |
162 |
| |
163 |
| |
164 |
| |
165 |
| |
166 |
| |
167 |
| |
168 |
| |
169 |
| |
170 |
| |
171 |
| |
172 |
| |
173 |
| |
174 |
| |
175 |
| |
176 |
| |
177 |
| |
178 |
| |
179 |
| |
180 |
| |
181 |
| |
182 |
| |
183 |
| |
184 |
| |
185 |
| |
186 |
| |
187 |
| |
188 |
| |
189 |
| |
190 |
| |