1 17 package org.eclipse.emf.ecore.impl; 18 19 20 import org.eclipse.emf.common.util.EList; 21 import org.eclipse.emf.ecore.EClass; 22 import org.eclipse.emf.ecore.EObject; 23 import org.eclipse.emf.ecore.EReference; 24 import org.eclipse.emf.ecore.EStructuralFeature; 25 import org.eclipse.emf.ecore.InternalEObject; 26 import org.eclipse.emf.ecore.util.FeatureMap; 27 import org.eclipse.emf.ecore.util.FeatureMapUtil; 28 29 30 33 public class DynamicEStoreEObjectImpl extends DynamicEObjectImpl 34 { 35 protected static final InternalEObject EUNINITIALIZED_CONTAINER = new EObjectImpl(); 36 37 protected InternalEObject.EStore eStore; 38 39 42 public DynamicEStoreEObjectImpl() 43 { 44 super(); 45 eContainer = EUNINITIALIZED_CONTAINER; 46 } 47 48 51 public DynamicEStoreEObjectImpl(InternalEObject.EStore eStore) 52 { 53 super(); 54 eSetStore(eStore); 55 eContainer = EUNINITIALIZED_CONTAINER; 56 } 57 58 61 public DynamicEStoreEObjectImpl(EClass eClass) 62 { 63 super(eClass); 64 eContainer = EUNINITIALIZED_CONTAINER; 65 } 66 67 70 public DynamicEStoreEObjectImpl(EClass eClass, InternalEObject.EStore eStore) 71 { 72 super(eClass); 73 eSetStore(eStore); 74 eContainer = EUNINITIALIZED_CONTAINER; 75 } 76 77 protected boolean eIsCaching() 78 { 79 return true; 80 } 81 82 public Object dynamicGet(int dynamicFeatureID) 83 { 84 Object result = eSettings[dynamicFeatureID]; 85 if (result == null) 86 { 87 EStructuralFeature eStructuralFeature = eDynamicFeature(dynamicFeatureID); 88 if (!eStructuralFeature.isTransient()) 89 { 90 if (FeatureMapUtil.isFeatureMap(eStructuralFeature)) 91 { 92 eSettings[dynamicFeatureID] = result = createFeatureMap(eStructuralFeature); 93 } 94 else if (eStructuralFeature.isMany()) 95 { 96 eSettings[dynamicFeatureID] = result = createList(eStructuralFeature); 97 } 98 else 99 { 100 result = eStore().get(this, eStructuralFeature, InternalEObject.EStore.NO_INDEX); 101 if (eIsCaching()) 102 { 103 eSettings[dynamicFeatureID] = result; 104 } 105 } 106 } 107 } 108 return result; 109 } 110 111 public void dynamicSet(int dynamicFeatureID, Object value) 112 { 113 EStructuralFeature eStructuralFeature = eDynamicFeature(dynamicFeatureID); 114 if (eStructuralFeature.isTransient()) 115 { 116 eSettings[dynamicFeatureID] = value; 117 } 118 else 119 { 120 eStore().set(this, eStructuralFeature, InternalEObject.EStore.NO_INDEX, value == NIL ? null : value); 121 if (eIsCaching()) 122 { 123 eSettings[dynamicFeatureID] = value; 124 } 125 } 126 } 127 128 public void dynamicUnset(int dynamicFeatureID) 129 { 130 eStore().unset(this, eDynamicFeature(dynamicFeatureID)); 131 eSettings[dynamicFeatureID] = null; 132 } 133 134 public boolean eDynamicIsSet(EStructuralFeature eStructuralFeature) 135 { 136 return 137 eStructuralFeature.isTransient() ? 138 super.eDynamicIsSet(eStructuralFeature) : 139 eStore().isSet(this, eStructuralFeature); 140 } 141 142 protected EList createList(EStructuralFeature eStructuralFeature) 143 { 144 return new EStoreEObjectImpl.EStoreEList(this, eStructuralFeature, eStore()); 145 } 146 147 protected FeatureMap createFeatureMap(EStructuralFeature eStructuralFeature) 148 { 149 return new EStoreEObjectImpl.EStoreFeatureMap(this, eStructuralFeature, eStore()); 150 } 151 152 public EObject eContainer() 153 { 154 if (eContainer == EUNINITIALIZED_CONTAINER) 155 { 156 eInitializeContainer(); 157 } 158 159 return eContainer; 160 } 161 162 public int eContainerFeatureID() 163 { 164 if (eContainer == EUNINITIALIZED_CONTAINER) 165 { 166 eInitializeContainer(); 167 } 168 169 return eContainerFeatureID; 170 } 171 172 protected void eInitializeContainer() 173 { 174 eContainer = eStore().getContainer(this); 175 if (eContainer != null) 176 { 177 EStructuralFeature eContainingFeature = eStore().getContainingFeature(this); 178 if (eContainingFeature instanceof EReference) 179 { 180 EReference eContainingReference = (EReference)eContainingFeature; 181 EReference eOpposite = eContainingReference.getEOpposite(); 182 if (eOpposite != null) 183 { 184 eContainerFeatureID = eClass().getFeatureID(eOpposite); 185 return; 186 } 187 } 188 189 eContainerFeatureID = EOPPOSITE_FEATURE_BASE - eContainer.eClass().getFeatureID(eContainingFeature); 190 } 191 } 192 193 public InternalEObject.EStore eStore() 194 { 195 return eStore; 196 } 197 198 public void eSetStore(InternalEObject.EStore store) 199 { 200 this.eStore = store; 201 } 202 203 211 } 212 | Popular Tags |