1 19 package org.netbeans.modules.javacore.jmiimpl.javamodel; 20 21 import java.util.*; 22 23 import javax.jmi.reflect.*; 24 import org.netbeans.jmi.javamodel.Element; 25 import org.netbeans.mdr.handlers.BaseObjectHandler; 26 import org.netbeans.mdr.persistence.MOFID; 27 import org.netbeans.mdr.persistence.StorageException; 28 import org.netbeans.mdr.storagemodel.*; 29 import org.netbeans.mdr.util.DebugException; 30 import org.openide.ErrorManager; 31 32 public class DeferredAttrList implements List { 33 34 private List innerList; 35 37 private final StorableFeatured mdrObject; 38 private final MOFID metaMofId; 40 private final boolean isRefObject; 41 42 public DeferredAttrList(StorableFeatured mdrObject, StorableClass.AttributeDescriptor attrDesc, List innerList) { 43 this.mdrObject = mdrObject; 44 this.innerList = innerList; 46 metaMofId = attrDesc.getMofId(); 47 isRefObject = RefObject.class.isAssignableFrom(attrDesc.getType()); 48 49 setInnerList(innerList); 51 } 52 53 public void setInnerList(List innerList) { 54 this.innerList = innerList; 55 } 64 65 67 private void setAttribComposite(RefObject object) { 68 try { 69 StorableObject storable = (StorableObject) ((BaseObjectHandler) object)._getDelegate(); 70 storable.setComposite(mdrObject, storable.getMofId(), metaMofId); 71 } catch (StorageException e) { 72 ErrorManager.getDefault().notify(e); 73 } 74 } 75 76 private void clearAttribComposite(RefObject object) { 77 try { 78 StorableObject storable = (StorableObject) ((BaseObjectHandler) object)._getDelegate(); 79 storable.clearComposite(); 80 } catch (StorageException e) { 81 ErrorManager.getDefault().notify(e); 82 } 83 } 84 85 93 95 public boolean remove(Object obj) { 96 boolean res = innerList.remove(obj); 97 if (res) { 98 if (isRefObject) { 100 clearAttribComposite((RefObject) obj); 101 } 102 } 103 return res; 104 } 105 106 public Object set(int param, Object obj) { 107 Object old = innerList.set(param, obj); 108 if (isRefObject) { 109 clearAttribComposite((RefObject) old); 110 setAttribComposite((RefObject) obj); 111 } 112 return old; 117 } 118 119 public Object remove(int param) { 120 Object old = innerList.remove(param); 121 if (isRefObject) { 122 clearAttribComposite ((RefObject) old); 123 } 124 return old; 126 } 127 128 public void add(int param, Object obj) { 129 innerList.add(param, obj); 130 if (isRefObject) { 131 setAttribComposite((RefObject) obj); 132 } 133 } 137 138 public boolean add(Object obj) { 139 boolean res = innerList.add(obj); 140 if (isRefObject && res) { 141 setAttribComposite((RefObject) obj); 142 } 143 return res; 147 } 148 149 public ListIterator listIterator(int param) { 150 return new DeferredAttrListIterator(innerList.listIterator(param)); 151 } 152 153 public Iterator iterator() { 154 return new DeferredAttrListIterator(innerList.listIterator()); 155 } 156 157 public ListIterator listIterator() { 158 return new DeferredAttrListIterator(innerList.listIterator()); 159 } 160 161 public List subList(int param, int param1) { 162 return innerList.subList(param, param1); 163 } 164 165 public boolean contains(Object obj) { 166 return innerList.contains(obj); 167 } 168 169 public boolean containsAll(Collection collection) { 170 return innerList.containsAll(collection); 171 } 172 173 public boolean addAll(Collection c) { 174 throw new DebugException(); 176 } 177 178 public void clear() { 179 throw new DebugException(); 181 } 182 183 public boolean isEmpty() { 184 return innerList.isEmpty(); 185 } 186 187 public boolean removeAll(Collection c) { 188 throw new DebugException(); 190 } 191 192 public boolean retainAll(Collection c) { 193 throw new DebugException(); 195 } 196 197 public int size() { 198 return innerList.size(); 199 } 200 201 public Object [] toArray() { 202 return innerList.toArray(); 203 } 204 205 public Object [] toArray(Object [] a) { 206 return innerList.toArray(a); 207 } 208 209 public boolean addAll(int index, Collection c) { 210 throw new DebugException(); 212 } 213 214 public Object get(int index) { 215 return innerList.get(index); 216 } 217 218 public int indexOf(Object o) { 219 return innerList.indexOf(o); 220 } 221 222 public int lastIndexOf(Object o) { 223 return innerList.lastIndexOf(o); 224 } 225 226 class DeferredAttrListIterator implements ListIterator { 228 229 private Object lastRead; 230 private ListIterator innerIterator; 231 232 DeferredAttrListIterator(ListIterator iterator) { 233 this.innerIterator = iterator; 234 } 235 236 public void remove() { 237 innerIterator.remove(); 238 if (isRefObject) { 240 clearAttribComposite((RefObject) lastRead); 241 } 242 } 243 244 public void add(Object obj) { 245 innerIterator.add(obj); 246 if (isRefObject) { 250 setAttribComposite((RefObject) obj); 251 } 252 } 253 254 public void set(Object obj) { 255 innerIterator.set(obj); 256 if (isRefObject) { 261 if (((Element) lastRead).isValid()) { 262 clearAttribComposite((RefObject) lastRead); 263 } 264 setAttribComposite((RefObject) obj); 265 } 266 } 267 268 public boolean hasNext() { 269 return innerIterator.hasNext(); 270 } 271 272 public boolean hasPrevious() { 273 return innerIterator.hasPrevious(); 274 } 275 276 public Object next() { 277 return lastRead = innerIterator.next(); 278 } 279 280 public int nextIndex() { 281 return innerIterator.nextIndex(); 282 } 283 284 public Object previous() { 285 return lastRead = innerIterator.previous(); 286 } 287 288 public int previousIndex() { 289 return innerIterator.previousIndex(); 290 } 291 292 } } 294 | Popular Tags |