1 17 package org.eclipse.emf.ecore.change.impl; 18 19 20 import java.util.Map ; 21 22 import org.eclipse.emf.common.notify.Notification; 23 import org.eclipse.emf.common.util.EList; 24 import org.eclipse.emf.ecore.EAttribute; 25 import org.eclipse.emf.ecore.EClass; 26 import org.eclipse.emf.ecore.EDataType; 27 import org.eclipse.emf.ecore.EObject; 28 import org.eclipse.emf.ecore.EReference; 29 import org.eclipse.emf.ecore.EStructuralFeature; 30 import org.eclipse.emf.ecore.change.ChangeFactory; 31 import org.eclipse.emf.ecore.change.ChangeKind; 32 import org.eclipse.emf.ecore.change.ChangePackage; 33 import org.eclipse.emf.ecore.change.FeatureMapEntry; 34 import org.eclipse.emf.ecore.change.ListChange; 35 import org.eclipse.emf.ecore.impl.ENotificationImpl; 36 import org.eclipse.emf.ecore.impl.EObjectImpl; 37 import org.eclipse.emf.ecore.util.EcoreUtil; 38 import org.eclipse.emf.ecore.util.FeatureMap; 39 41 42 60 public class FeatureMapEntryImpl extends EObjectImpl implements FeatureMapEntry, FeatureMap.Entry 61 { 62 65 protected static final int EPROXY_FEATURECHANGE = ELAST_EOBJECT_FLAG << 1; 66 67 75 protected static final String FEATURE_NAME_EDEFAULT = null; 76 77 85 protected static final String DATA_VALUE_EDEFAULT = null; 86 87 95 protected static final Object VALUE_EDEFAULT = null; 96 97 protected EStructuralFeature feature = null; 98 99 protected String featureName = null; 100 101 protected Object value = null; 102 103 protected String valueString = null; 104 105 110 protected FeatureMapEntryImpl() 111 { 112 super(); 113 } 114 115 protected FeatureMapEntryImpl(EStructuralFeature feature, Object value) 116 { 117 this(); 118 this.feature = feature; 119 setValue(value); 120 } 121 122 127 protected EClass eStaticClass() 128 { 129 return ChangePackage.eINSTANCE.getFeatureMapEntry(); 130 } 131 132 137 public String getFeatureName() 138 { 139 return feature == null ? featureName : feature.getName(); 140 } 141 142 147 public void setFeatureName(String newFeatureName) 148 { 149 featureName = newFeatureName; 150 feature = null; 151 eFlags &= ~EPROXY_FEATURECHANGE; 152 } 153 154 159 public void unsetFeatureName() 160 { 161 setFeatureName(null); 162 } 163 164 169 public boolean isSetFeatureName() 170 { 171 return (feature != null || featureName != null) && getGreatGrandParent() instanceof EObjectToChangesMapEntryImpl; 172 } 173 174 protected EObject getGreatGrandParent() 175 { 176 EObject container = eContainer(); 177 if (container != null) 178 { 179 container = container.eContainer(); 180 if (container != null) 181 { 182 return container.eContainer(); 183 } 184 } 185 return null; 186 } 187 188 193 public String getDataValue() 194 { 195 if (valueString == null) 196 { 197 EStructuralFeature feature = getFeature(); 198 if (feature instanceof EAttribute) 199 { 200 EDataType type = (EDataType)feature.getEType(); 201 valueString = EcoreUtil.convertToString(type, value); 202 } 203 } 204 return valueString; 205 } 206 207 212 public void setDataValue(String newDataValue) 213 { 214 String oldDataValue = getDataValue(); 215 valueString = newDataValue; 216 value = null; 217 if (eNotificationRequired()) 218 eNotify(new ENotificationImpl(this, Notification.SET, ChangePackage.FEATURE_CHANGE__DATA_VALUE, oldDataValue, newDataValue)); 219 } 220 221 public EStructuralFeature getEStructuralFeature() 222 { 223 return getFeature(); 224 } 225 226 231 public EStructuralFeature getFeature() 232 { 233 if (feature == null) 234 { 235 EObject greatGrandParent = getGreatGrandParent(); 236 if (greatGrandParent instanceof EObjectToChangesMapEntryImpl) 237 { 238 feature = ((EObject)((Map.Entry )greatGrandParent).getKey()).eClass().getEStructuralFeature(featureName); 239 } 240 } 241 else if ((eFlags & EPROXY_FEATURECHANGE) !=0) 242 { 243 EStructuralFeature oldFeature = feature; 244 feature = (EStructuralFeature)EcoreUtil.resolve(feature, this); 245 if (feature != oldFeature) 246 { 247 if (eNotificationRequired()) 248 eNotify(new ENotificationImpl(this, Notification.RESOLVE, ChangePackage.FEATURE_CHANGE__FEATURE, oldFeature, feature)); 249 } 250 eFlags &= ~ EPROXY_FEATURECHANGE; 251 } 252 return feature; 253 } 254 255 260 public EStructuralFeature basicGetFeature() 261 { 262 return feature; 263 } 264 265 270 public void setFeature(EStructuralFeature newFeature) 271 { 272 EStructuralFeature oldFeature = basicGetFeature(); 273 feature = newFeature; 274 featureName = null; 275 if (feature != null && feature.eIsProxy()) 276 eFlags |= EPROXY_FEATURECHANGE; 277 else 278 eFlags &= ~EPROXY_FEATURECHANGE; 279 if (eNotificationRequired()) 280 eNotify(new ENotificationImpl(this, Notification.SET, ChangePackage.FEATURE_CHANGE__FEATURE, oldFeature, newFeature)); 281 } 282 283 288 public void unsetFeature() 289 { 290 setFeature(null); 291 } 292 293 298 public boolean isSetFeature() 299 { 300 return feature != null && !(getGreatGrandParent() instanceof EObjectToChangesMapEntryImpl); 301 } 302 303 308 public EObject getReferenceValue() 309 { 310 EObject referenceValue = basicGetReferenceValue(); 311 if (referenceValue != null && referenceValue.eIsProxy()) 312 { 313 EObject oldReferenceValue = referenceValue; 314 referenceValue = EcoreUtil.resolve(referenceValue, this); 315 if (referenceValue != oldReferenceValue) 316 { 317 if (eNotificationRequired()) 318 eNotify(new ENotificationImpl(this, Notification.RESOLVE, ChangePackage.FEATURE_CHANGE__REFERENCE_VALUE, oldReferenceValue, referenceValue)); 319 } 320 } 321 return referenceValue; 322 } 323 324 329 public EObject basicGetReferenceValue() 330 { 331 return feature instanceof EReference ? (EObject)value : null; 332 } 333 334 339 public void setReferenceValue(EObject newReferenceValue) 340 { 341 EObject oldReferenceValue = basicGetReferenceValue(); 342 value = newReferenceValue; 343 valueString = null; 344 if (eNotificationRequired()) 345 eNotify(new ENotificationImpl(this, Notification.SET, ChangePackage.FEATURE_CHANGE__REFERENCE_VALUE, oldReferenceValue, newReferenceValue)); 346 } 347 348 353 public Object getValue() 354 { 355 EStructuralFeature feature = getFeature(); 356 if (feature instanceof EReference) 357 { 358 return getReferenceValue(); 359 } 360 else if (value == null) { 362 EDataType type = (EDataType)feature.getEType(); 363 value = EcoreUtil.createFromString(type, valueString); 364 } 365 return value; 366 } 367 368 protected void setValue(Object value) 369 { 370 EStructuralFeature feature = getFeature(); 371 if (!eNotificationRequired()) 372 { 373 valueString = null; 374 this.value = value; 375 } 376 else 377 { 378 if (feature instanceof EAttribute) 379 { 380 EDataType type = (EDataType)feature.getEType(); 381 setDataValue(valueString = EcoreUtil.convertToString(type, value)); 382 this.value = value; 383 } 384 else 385 { 386 setReferenceValue((EObject)value); 387 } 388 } 389 } 390 391 396 public Object eGet(EStructuralFeature eFeature, boolean resolve) 397 { 398 switch (eDerivedStructuralFeatureID(eFeature)) 399 { 400 case ChangePackage.FEATURE_MAP_ENTRY__FEATURE_NAME: 401 return getFeatureName(); 402 case ChangePackage.FEATURE_MAP_ENTRY__DATA_VALUE: 403 return getDataValue(); 404 case ChangePackage.FEATURE_MAP_ENTRY__VALUE: 405 return getValue(); 406 case ChangePackage.FEATURE_MAP_ENTRY__FEATURE: 407 if (resolve) return getFeature(); 408 return basicGetFeature(); 409 case ChangePackage.FEATURE_MAP_ENTRY__REFERENCE_VALUE: 410 if (resolve) return getReferenceValue(); 411 return basicGetReferenceValue(); 412 } 413 return eDynamicGet(eFeature, resolve); 414 } 415 416 421 public void eSet(EStructuralFeature eFeature, Object newValue) 422 { 423 switch (eDerivedStructuralFeatureID(eFeature)) 424 { 425 case ChangePackage.FEATURE_MAP_ENTRY__FEATURE_NAME: 426 setFeatureName((String )newValue); 427 return; 428 case ChangePackage.FEATURE_MAP_ENTRY__DATA_VALUE: 429 setDataValue((String )newValue); 430 return; 431 case ChangePackage.FEATURE_MAP_ENTRY__FEATURE: 432 setFeature((EStructuralFeature)newValue); 433 return; 434 case ChangePackage.FEATURE_MAP_ENTRY__REFERENCE_VALUE: 435 setReferenceValue((EObject)newValue); 436 return; 437 } 438 eDynamicSet(eFeature, newValue); 439 } 440 441 446 public void eUnset(EStructuralFeature eFeature) 447 { 448 switch (eDerivedStructuralFeatureID(eFeature)) 449 { 450 case ChangePackage.FEATURE_MAP_ENTRY__FEATURE_NAME: 451 unsetFeatureName(); 452 return; 453 case ChangePackage.FEATURE_MAP_ENTRY__DATA_VALUE: 454 setDataValue(DATA_VALUE_EDEFAULT); 455 return; 456 case ChangePackage.FEATURE_MAP_ENTRY__FEATURE: 457 unsetFeature(); 458 return; 459 case ChangePackage.FEATURE_MAP_ENTRY__REFERENCE_VALUE: 460 setReferenceValue((EObject)null); 461 return; 462 } 463 eDynamicUnset(eFeature); 464 } 465 466 471 public boolean eIsSet(EStructuralFeature eFeature) 472 { 473 switch (eDerivedStructuralFeatureID(eFeature)) 474 { 475 case ChangePackage.FEATURE_MAP_ENTRY__FEATURE_NAME: 476 return isSetFeatureName(); 477 case ChangePackage.FEATURE_MAP_ENTRY__DATA_VALUE: 478 return DATA_VALUE_EDEFAULT == null ? getDataValue() != null : !DATA_VALUE_EDEFAULT.equals(getDataValue()); 479 case ChangePackage.FEATURE_MAP_ENTRY__VALUE: 480 return VALUE_EDEFAULT == null ? getValue() != null : !VALUE_EDEFAULT.equals(getValue()); 481 case ChangePackage.FEATURE_MAP_ENTRY__FEATURE: 482 return isSetFeature(); 483 case ChangePackage.FEATURE_MAP_ENTRY__REFERENCE_VALUE: 484 return basicGetReferenceValue() != null; 485 } 486 return eDynamicIsSet(eFeature); 487 } 488 489 protected ListChange createListChange(EList changesList, ChangeKind kind, int index) 490 { 491 ListChange listChange = ChangeFactory.eINSTANCE.createListChange(); 492 listChange.setKind(kind); 493 listChange.setIndex(index); 494 changesList.add(listChange); 495 return listChange; 496 } 497 } | Popular Tags |