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