1 19 package org.netbeans.mdr.storagemodel; 20 21 import java.util.*; 22 import javax.jmi.reflect.*; 23 24 import org.netbeans.mdr.persistence.StorageException; 25 import org.netbeans.mdr.persistence.MOFID; 26 import org.netbeans.mdr.util.DebugException; 27 import org.netbeans.mdr.util.Logger; 28 29 33 public class AttrList extends AttrCollection implements List { 34 protected final List innerList; 35 36 public AttrList() { 37 innerList = (List) inner; 38 } 39 40 AttrList(StorableFeatured mdrObject, StorableClass.AttributeDescriptor desc) throws StorageException { 41 this(mdrObject, desc, null); 42 } 43 44 protected AttrList(StorableFeatured mdrObject, StorableClass.AttributeDescriptor desc, List values) throws StorageException { 45 super(mdrObject, desc, values); 46 innerList = (List) inner; 47 } 48 49 protected AttrList(StorableFeatured mdrObject, List values, int maxSize, Class type, String attrName, boolean isRefObject, MOFID metaMofId) { 50 super(mdrObject, values, maxSize, type, attrName, isRefObject, metaMofId); 51 innerList = values; 52 } 53 54 public void add(int param, Object obj) { 55 checkType(obj); 56 checkMaxSize(1); 57 checkUnwrap(); 58 mdrObject.objectWillChange(); 59 60 if (isIndexed) 61 ((StorableObject) mdrObject).removeFromIndex (metaMofId); 62 innerList.add(param, obj); 63 if (isRefObject) { 64 try { 65 setAttribComposite((RefObject) obj); 66 } catch (StorageException e) { 67 throw (DebugException) Logger.getDefault().annotate(new DebugException(), e); 68 } 69 } 70 71 if (isIndexed) 72 ((StorableObject) mdrObject).addToIndex (metaMofId); 73 74 mdrObject.objectChanged(); 75 } 76 77 public boolean addAll(int param, Collection collection) { 78 throw new DebugException(); 80 } 81 82 public Object get(int param) { 83 checkUnwrap(); 84 return innerList.get(param); 85 } 86 87 public int indexOf(Object obj) { 88 checkUnwrap(); 89 return innerList.indexOf(obj); 90 } 91 92 public int lastIndexOf(Object obj) { 93 checkUnwrap(); 94 return innerList.lastIndexOf(obj); 95 } 96 97 public ListIterator listIterator() { 98 checkUnwrap(); 99 return new AttrListIterator(innerList.listIterator()); 100 } 101 102 public ListIterator listIterator(int param) { 103 checkUnwrap(); 104 return new AttrListIterator(innerList.listIterator(param)); 105 } 106 107 public Object remove(int param) { 108 checkUnwrap(); 109 mdrObject.objectWillChange(); 110 if (isIndexed) 111 ((StorableObject) mdrObject).removeFromIndex (metaMofId); 112 113 Object result = innerList.remove(param); 114 if (isRefObject) { 115 try { 116 clearAttribComposite((RefObject) result); 117 } catch (StorageException e) { 118 throw (DebugException) Logger.getDefault().annotate(new DebugException(), e); 119 } 120 } 121 122 if (isIndexed) 123 ((StorableObject) mdrObject).addToIndex (metaMofId); 124 125 mdrObject.objectChanged(); 126 return result; 127 } 128 129 public Object set(int param, Object obj) { 130 checkType(obj); 131 checkUnwrap(); 132 mdrObject.objectWillChange(); 133 if (isIndexed) 134 ((StorableObject) mdrObject).removeFromIndex (metaMofId); 135 136 Object result = innerList.set(param, obj); 137 if (isRefObject) { 138 try { 139 clearAttribComposite((RefObject) result); 140 setAttribComposite((RefObject) obj); 141 } catch (StorageException e) { 142 throw (DebugException) Logger.getDefault().annotate(new DebugException(), e); 143 } 144 } 145 146 if (isIndexed) 147 ((StorableObject) mdrObject).addToIndex (metaMofId); 148 149 mdrObject.objectChanged(); 150 return result; 151 } 152 153 public List subList(int param, int param1) { 154 checkUnwrap(); 155 return new AttrList(mdrObject, innerList.subList(param, param1), maxSize, type, attrName, isRefObject, metaMofId); 156 } 157 158 protected class AttrListIterator extends AttrIterator implements ListIterator { 159 private final ListIterator innerIterator; 160 161 protected AttrListIterator(ListIterator iterator) { 162 super(iterator); 163 innerIterator = iterator; 164 } 165 166 public void add(Object obj) { 167 checkType(obj); 168 checkMaxSize(1); 169 170 mdrObject.objectWillChange(); 171 172 if (isIndexed) 173 ((StorableObject) mdrObject).removeFromIndex (metaMofId); 174 175 innerIterator.add(obj); 176 if (isRefObject) { 177 try { 178 setAttribComposite((RefObject) obj); 179 } catch (StorageException e) { 180 throw (DebugException) Logger.getDefault().annotate(new DebugException(), e); 181 } 182 } 183 184 if (isIndexed) 185 ((StorableObject) mdrObject).addToIndex (metaMofId); 186 187 mdrObject.objectChanged(); 188 } 189 190 public boolean hasPrevious() { 191 return innerIterator.hasPrevious(); 192 } 193 194 public int nextIndex() { 195 return innerIterator.nextIndex(); 196 } 197 198 public Object previous() { 199 return (lastRead = innerIterator.previous()); 200 } 201 202 public int previousIndex() { 203 return innerIterator.previousIndex(); 204 } 205 206 public void set(Object obj) { 207 checkType(obj); 208 209 mdrObject.objectWillChange(); 210 211 if (isIndexed) 212 ((StorableObject) mdrObject).removeFromIndex (metaMofId); 213 214 innerIterator.set(obj); 215 if (isRefObject) { 216 try { 217 clearAttribComposite((RefObject) lastRead); 218 setAttribComposite((RefObject) obj); 219 } catch (StorageException e) { 220 throw (DebugException) Logger.getDefault().annotate(new DebugException(), e); 221 } 222 } 223 224 if (isIndexed) 225 ((StorableObject) mdrObject).addToIndex (metaMofId); 226 227 mdrObject.objectChanged(); 228 } 229 } 230 } 231 | Popular Tags |