1 17 package org.eclipse.emf.ecore.util; 18 19 20 import java.util.Iterator ; 21 import java.util.List ; 22 import java.util.ListIterator ; 23 24 import org.eclipse.emf.common.util.BasicEList; 25 import org.eclipse.emf.ecore.EObject; 26 import org.eclipse.emf.ecore.EReference; 27 import org.eclipse.emf.ecore.EStructuralFeature; 28 import org.eclipse.emf.ecore.impl.EClassImpl; 29 30 31 34 public class ECrossReferenceEList extends EContentsEList 35 { 36 public ECrossReferenceEList(EObject eObject) 37 { 38 super 39 (eObject, 40 ((EClassImpl.FeatureSubsetSupplier)eObject.eClass().getEAllStructuralFeatures()).crossReferences()); 41 } 42 43 protected ECrossReferenceEList(EObject eObject, EStructuralFeature [] eStructuralFeatures) 44 { 45 super(eObject, eStructuralFeatures); 46 } 47 48 public static class FeatureIteratorImpl extends EContentsEList.FeatureIteratorImpl 49 { 50 public FeatureIteratorImpl(EObject eObject) 51 { 52 super(eObject, (EStructuralFeature [])((BasicEList)eObject.eClass().getEAllReferences()).data()); 53 } 54 55 public FeatureIteratorImpl(EObject eObject, EStructuralFeature [] eStructuralFeatures) 56 { 57 super(eObject, eStructuralFeatures); 58 } 59 60 protected boolean isIncluded(EStructuralFeature eStructuralFeature) 61 { 62 if (FeatureMapUtil.isFeatureMap(eStructuralFeature)) 63 { 64 return true; 65 } 66 else 67 { 68 EReference eReference = (EReference)eStructuralFeature; 69 return !eReference.isContainment() && !eReference.isContainer(); 70 } 71 } 72 73 protected boolean isIncludedEntry(EStructuralFeature eStructuralFeature) 74 { 75 if (eStructuralFeature instanceof EReference) 76 { 77 EReference eReference = (EReference)eStructuralFeature; 78 return !eReference.isContainment() && !eReference.isContainer(); 79 } 80 else 81 { 82 return false; 83 } 84 } 85 } 86 87 public static class ResolvingFeatureIteratorImpl extends FeatureIteratorImpl 88 { 89 public ResolvingFeatureIteratorImpl(EObject eObject) 90 { 91 super(eObject); 92 } 93 94 public ResolvingFeatureIteratorImpl(EObject eObject, EStructuralFeature [] eStructuralFeatures) 95 { 96 super(eObject, eStructuralFeatures); 97 } 98 99 protected boolean resolve() 100 { 101 return true; 102 } 103 } 104 105 protected boolean isIncluded(EStructuralFeature eStructuralFeature) 106 { 107 if (FeatureMapUtil.isFeatureMap(eStructuralFeature)) 108 { 109 return true; 110 } 111 else 112 { 113 EReference eReference = (EReference)eStructuralFeature; 114 return !eReference.isContainment() && !eReference.isContainer(); 115 } 116 } 117 118 protected boolean isIncludedEntry(EStructuralFeature eStructuralFeature) 119 { 120 if (eStructuralFeature instanceof EReference) 121 { 122 EReference eReference = (EReference)eStructuralFeature; 123 return !eReference.isContainment() && !eReference.isContainer(); 124 } 125 else 126 { 127 return false; 128 } 129 } 130 131 protected ListIterator newListIterator() 132 { 133 return 134 this.resolve() ? 135 new ResolvingFeatureIteratorImpl(eObject, eStructuralFeatures) : 136 new FeatureIteratorImpl(eObject, eStructuralFeatures); 137 } 138 139 public List basicList() 140 { 141 return 142 new ECrossReferenceEList(eObject, eStructuralFeatures) 143 { 144 protected boolean resolve() 145 { 146 return false; 147 } 148 }; 149 } 150 151 public Iterator basicIterator() 152 { 153 if (eStructuralFeatures == null) 154 { 155 return EContentsEList.FeatureIteratorImpl.EMPTY_ITERATOR; 156 } 157 158 return new FeatureIteratorImpl(eObject, eStructuralFeatures); 159 } 160 161 public ListIterator basicListIterator() 162 { 163 if (eStructuralFeatures == null) 164 { 165 return EContentsEList.FeatureIteratorImpl.EMPTY_ITERATOR; 166 } 167 168 return new FeatureIteratorImpl(eObject, eStructuralFeatures); 169 } 170 171 public ListIterator basicListIterator(int index) 172 { 173 if (eStructuralFeatures == null) 174 { 175 if (index < 0 || index > 1) 176 { 177 throw new IndexOutOfBoundsException ("index=" + index + ", size=0"); 178 } 179 180 return EContentsEList.FeatureIteratorImpl.EMPTY_ITERATOR; 181 } 182 183 ListIterator result = new FeatureIteratorImpl(eObject, eStructuralFeatures); 184 for (int i = 0; i < index; ++i) 185 { 186 result.next(); 187 } 188 return result; 189 } 190 } 191 | Popular Tags |