1 17 package org.eclipse.emf.ecore.impl; 18 19 20 import java.util.Collection ; 21 22 import org.eclipse.emf.common.notify.Notification; 23 import org.eclipse.emf.common.notify.NotificationChain; 24 import org.eclipse.emf.ecore.EClass; 25 import org.eclipse.emf.ecore.EClassifier; 26 import org.eclipse.emf.ecore.EReference; 27 import org.eclipse.emf.ecore.EStructuralFeature; 28 import org.eclipse.emf.ecore.EcorePackage; 29 import org.eclipse.emf.ecore.InternalEObject; 30 import org.eclipse.emf.ecore.util.InternalEList; 31 32 33 50 public class EReferenceImpl extends EStructuralFeatureImpl implements EReference 51 { 52 60 protected static final boolean CONTAINMENT_EDEFAULT = false; 61 62 70 protected static final int CONTAINMENT_EFLAG = 1 << 15; 71 72 80 protected static final boolean CONTAINER_EDEFAULT = false; 81 82 90 protected static final boolean RESOLVE_PROXIES_EDEFAULT = true; 91 92 100 protected static final int RESOLVE_PROXIES_EFLAG = 1 << 16; 101 102 110 protected EReference eOpposite = null; 111 112 117 protected EReferenceImpl() 118 { 119 super(); 120 eFlags |= RESOLVE_PROXIES_EFLAG; 121 } 122 123 128 protected EClass eStaticClass() 129 { 130 return EcorePackage.eINSTANCE.getEReference(); 131 } 132 133 public boolean isBidirectional() 134 { 135 return getEOpposite() != null; 136 } 137 138 139 144 public Object eGet(EStructuralFeature eFeature, boolean resolve) 145 { 146 switch (eDerivedStructuralFeatureID(eFeature)) 147 { 148 case EcorePackage.EREFERENCE__EANNOTATIONS: 149 return getEAnnotations(); 150 case EcorePackage.EREFERENCE__NAME: 151 return getName(); 152 case EcorePackage.EREFERENCE__ORDERED: 153 return isOrdered() ? Boolean.TRUE : Boolean.FALSE; 154 case EcorePackage.EREFERENCE__UNIQUE: 155 return isUnique() ? Boolean.TRUE : Boolean.FALSE; 156 case EcorePackage.EREFERENCE__LOWER_BOUND: 157 return new Integer (getLowerBound()); 158 case EcorePackage.EREFERENCE__UPPER_BOUND: 159 return new Integer (getUpperBound()); 160 case EcorePackage.EREFERENCE__MANY: 161 return isMany() ? Boolean.TRUE : Boolean.FALSE; 162 case EcorePackage.EREFERENCE__REQUIRED: 163 return isRequired() ? Boolean.TRUE : Boolean.FALSE; 164 case EcorePackage.EREFERENCE__ETYPE: 165 if (resolve) return getEType(); 166 return basicGetEType(); 167 case EcorePackage.EREFERENCE__CHANGEABLE: 168 return isChangeable() ? Boolean.TRUE : Boolean.FALSE; 169 case EcorePackage.EREFERENCE__VOLATILE: 170 return isVolatile() ? Boolean.TRUE : Boolean.FALSE; 171 case EcorePackage.EREFERENCE__TRANSIENT: 172 return isTransient() ? Boolean.TRUE : Boolean.FALSE; 173 case EcorePackage.EREFERENCE__DEFAULT_VALUE_LITERAL: 174 return getDefaultValueLiteral(); 175 case EcorePackage.EREFERENCE__DEFAULT_VALUE: 176 return getDefaultValue(); 177 case EcorePackage.EREFERENCE__UNSETTABLE: 178 return isUnsettable() ? Boolean.TRUE : Boolean.FALSE; 179 case EcorePackage.EREFERENCE__DERIVED: 180 return isDerived() ? Boolean.TRUE : Boolean.FALSE; 181 case EcorePackage.EREFERENCE__ECONTAINING_CLASS: 182 return getEContainingClass(); 183 case EcorePackage.EREFERENCE__CONTAINMENT: 184 return isContainment() ? Boolean.TRUE : Boolean.FALSE; 185 case EcorePackage.EREFERENCE__CONTAINER: 186 return isContainer() ? Boolean.TRUE : Boolean.FALSE; 187 case EcorePackage.EREFERENCE__RESOLVE_PROXIES: 188 return isResolveProxies() ? Boolean.TRUE : Boolean.FALSE; 189 case EcorePackage.EREFERENCE__EOPPOSITE: 190 if (resolve) return getEOpposite(); 191 return basicGetEOpposite(); 192 case EcorePackage.EREFERENCE__EREFERENCE_TYPE: 193 if (resolve) return getEReferenceType(); 194 return basicGetEReferenceType(); 195 } 196 return eDynamicGet(eFeature, resolve); 197 } 198 199 204 public boolean eIsSet(EStructuralFeature eFeature) 205 { 206 switch (eDerivedStructuralFeatureID(eFeature)) 207 { 208 case EcorePackage.EREFERENCE__EANNOTATIONS: 209 return eAnnotations != null && !eAnnotations.isEmpty(); 210 case EcorePackage.EREFERENCE__NAME: 211 return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name); 212 case EcorePackage.EREFERENCE__ORDERED: 213 return ((eFlags & ORDERED_EFLAG) != 0) != ORDERED_EDEFAULT; 214 case EcorePackage.EREFERENCE__UNIQUE: 215 return ((eFlags & UNIQUE_EFLAG) != 0) != UNIQUE_EDEFAULT; 216 case EcorePackage.EREFERENCE__LOWER_BOUND: 217 return lowerBound != LOWER_BOUND_EDEFAULT; 218 case EcorePackage.EREFERENCE__UPPER_BOUND: 219 return upperBound != UPPER_BOUND_EDEFAULT; 220 case EcorePackage.EREFERENCE__MANY: 221 return isMany() != MANY_EDEFAULT; 222 case EcorePackage.EREFERENCE__REQUIRED: 223 return isRequired() != REQUIRED_EDEFAULT; 224 case EcorePackage.EREFERENCE__ETYPE: 225 return eType != null; 226 case EcorePackage.EREFERENCE__CHANGEABLE: 227 return ((eFlags & CHANGEABLE_EFLAG) != 0) != CHANGEABLE_EDEFAULT; 228 case EcorePackage.EREFERENCE__VOLATILE: 229 return ((eFlags & VOLATILE_EFLAG) != 0) != VOLATILE_EDEFAULT; 230 case EcorePackage.EREFERENCE__TRANSIENT: 231 return ((eFlags & TRANSIENT_EFLAG) != 0) != TRANSIENT_EDEFAULT; 232 case EcorePackage.EREFERENCE__DEFAULT_VALUE_LITERAL: 233 return DEFAULT_VALUE_LITERAL_EDEFAULT == null ? defaultValueLiteral != null : !DEFAULT_VALUE_LITERAL_EDEFAULT.equals(defaultValueLiteral); 234 case EcorePackage.EREFERENCE__DEFAULT_VALUE: 235 return DEFAULT_VALUE_EDEFAULT == null ? getDefaultValue() != null : !DEFAULT_VALUE_EDEFAULT.equals(getDefaultValue()); 236 case EcorePackage.EREFERENCE__UNSETTABLE: 237 return ((eFlags & UNSETTABLE_EFLAG) != 0) != UNSETTABLE_EDEFAULT; 238 case EcorePackage.EREFERENCE__DERIVED: 239 return ((eFlags & DERIVED_EFLAG) != 0) != DERIVED_EDEFAULT; 240 case EcorePackage.EREFERENCE__ECONTAINING_CLASS: 241 return getEContainingClass() != null; 242 case EcorePackage.EREFERENCE__CONTAINMENT: 243 return ((eFlags & CONTAINMENT_EFLAG) != 0) != CONTAINMENT_EDEFAULT; 244 case EcorePackage.EREFERENCE__CONTAINER: 245 return isContainer() != CONTAINER_EDEFAULT; 246 case EcorePackage.EREFERENCE__RESOLVE_PROXIES: 247 return ((eFlags & RESOLVE_PROXIES_EFLAG) != 0) != RESOLVE_PROXIES_EDEFAULT; 248 case EcorePackage.EREFERENCE__EOPPOSITE: 249 return eOpposite != null; 250 case EcorePackage.EREFERENCE__EREFERENCE_TYPE: 251 return basicGetEReferenceType() != null; 252 } 253 return eDynamicIsSet(eFeature); 254 } 255 256 261 public void eSet(EStructuralFeature eFeature, Object newValue) 262 { 263 switch (eDerivedStructuralFeatureID(eFeature)) 264 { 265 case EcorePackage.EREFERENCE__EANNOTATIONS: 266 getEAnnotations().clear(); 267 getEAnnotations().addAll((Collection )newValue); 268 return; 269 case EcorePackage.EREFERENCE__NAME: 270 setName((String )newValue); 271 return; 272 case EcorePackage.EREFERENCE__ORDERED: 273 setOrdered(((Boolean )newValue).booleanValue()); 274 return; 275 case EcorePackage.EREFERENCE__UNIQUE: 276 setUnique(((Boolean )newValue).booleanValue()); 277 return; 278 case EcorePackage.EREFERENCE__LOWER_BOUND: 279 setLowerBound(((Integer )newValue).intValue()); 280 return; 281 case EcorePackage.EREFERENCE__UPPER_BOUND: 282 setUpperBound(((Integer )newValue).intValue()); 283 return; 284 case EcorePackage.EREFERENCE__ETYPE: 285 setEType((EClassifier)newValue); 286 return; 287 case EcorePackage.EREFERENCE__CHANGEABLE: 288 setChangeable(((Boolean )newValue).booleanValue()); 289 return; 290 case EcorePackage.EREFERENCE__VOLATILE: 291 setVolatile(((Boolean )newValue).booleanValue()); 292 return; 293 case EcorePackage.EREFERENCE__TRANSIENT: 294 setTransient(((Boolean )newValue).booleanValue()); 295 return; 296 case EcorePackage.EREFERENCE__DEFAULT_VALUE_LITERAL: 297 setDefaultValueLiteral((String )newValue); 298 return; 299 case EcorePackage.EREFERENCE__UNSETTABLE: 300 setUnsettable(((Boolean )newValue).booleanValue()); 301 return; 302 case EcorePackage.EREFERENCE__DERIVED: 303 setDerived(((Boolean )newValue).booleanValue()); 304 return; 305 case EcorePackage.EREFERENCE__CONTAINMENT: 306 setContainment(((Boolean )newValue).booleanValue()); 307 return; 308 case EcorePackage.EREFERENCE__RESOLVE_PROXIES: 309 setResolveProxies(((Boolean )newValue).booleanValue()); 310 return; 311 case EcorePackage.EREFERENCE__EOPPOSITE: 312 setEOpposite((EReference)newValue); 313 return; 314 } 315 eDynamicSet(eFeature, newValue); 316 } 317 318 323 public void eUnset(EStructuralFeature eFeature) 324 { 325 switch (eDerivedStructuralFeatureID(eFeature)) 326 { 327 case EcorePackage.EREFERENCE__EANNOTATIONS: 328 getEAnnotations().clear(); 329 return; 330 case EcorePackage.EREFERENCE__NAME: 331 setName(NAME_EDEFAULT); 332 return; 333 case EcorePackage.EREFERENCE__ORDERED: 334 setOrdered(ORDERED_EDEFAULT); 335 return; 336 case EcorePackage.EREFERENCE__UNIQUE: 337 setUnique(UNIQUE_EDEFAULT); 338 return; 339 case EcorePackage.EREFERENCE__LOWER_BOUND: 340 setLowerBound(LOWER_BOUND_EDEFAULT); 341 return; 342 case EcorePackage.EREFERENCE__UPPER_BOUND: 343 setUpperBound(UPPER_BOUND_EDEFAULT); 344 return; 345 case EcorePackage.EREFERENCE__ETYPE: 346 setEType((EClassifier)null); 347 return; 348 case EcorePackage.EREFERENCE__CHANGEABLE: 349 setChangeable(CHANGEABLE_EDEFAULT); 350 return; 351 case EcorePackage.EREFERENCE__VOLATILE: 352 setVolatile(VOLATILE_EDEFAULT); 353 return; 354 case EcorePackage.EREFERENCE__TRANSIENT: 355 setTransient(TRANSIENT_EDEFAULT); 356 return; 357 case EcorePackage.EREFERENCE__DEFAULT_VALUE_LITERAL: 358 setDefaultValueLiteral(DEFAULT_VALUE_LITERAL_EDEFAULT); 359 return; 360 case EcorePackage.EREFERENCE__UNSETTABLE: 361 setUnsettable(UNSETTABLE_EDEFAULT); 362 return; 363 case EcorePackage.EREFERENCE__DERIVED: 364 setDerived(DERIVED_EDEFAULT); 365 return; 366 case EcorePackage.EREFERENCE__CONTAINMENT: 367 setContainment(CONTAINMENT_EDEFAULT); 368 return; 369 case EcorePackage.EREFERENCE__RESOLVE_PROXIES: 370 setResolveProxies(RESOLVE_PROXIES_EDEFAULT); 371 return; 372 case EcorePackage.EREFERENCE__EOPPOSITE: 373 setEOpposite((EReference)null); 374 return; 375 } 376 eDynamicUnset(eFeature); 377 } 378 379 384 public boolean isContainment() 385 { 386 return (eFlags & CONTAINMENT_EFLAG) != 0; 387 } 388 389 394 public void setContainment(boolean newContainment) 395 { 396 boolean oldContainment = (eFlags & CONTAINMENT_EFLAG) != 0; 397 if (newContainment) eFlags |= CONTAINMENT_EFLAG; else eFlags &= ~CONTAINMENT_EFLAG; 398 if (eNotificationRequired()) 399 eNotify(new ENotificationImpl(this, Notification.SET, EcorePackage.EREFERENCE__CONTAINMENT, oldContainment, newContainment)); 400 } 401 402 407 public boolean isContainer() 408 { 409 EReference theOpposite = getEOpposite(); 410 return theOpposite != null && theOpposite.isContainment(); 411 } 412 413 418 public boolean isResolveProxies() 419 { 420 return (eFlags & RESOLVE_PROXIES_EFLAG) != 0; 421 } 422 423 428 public void setResolveProxies(boolean newResolveProxies) 429 { 430 boolean oldResolveProxies = (eFlags & RESOLVE_PROXIES_EFLAG) != 0; 431 if (newResolveProxies) eFlags |= RESOLVE_PROXIES_EFLAG; else eFlags &= ~RESOLVE_PROXIES_EFLAG; 432 if (eNotificationRequired()) 433 eNotify(new ENotificationImpl(this, Notification.SET, EcorePackage.EREFERENCE__RESOLVE_PROXIES, oldResolveProxies, newResolveProxies)); 434 } 435 436 441 public EReference getEOpposite() 442 { 443 if (eOpposite != null && eOpposite.eIsProxy()) 444 { 445 EReference oldEOpposite = eOpposite; 446 eOpposite = (EReference)eResolveProxy((InternalEObject)eOpposite); 447 if (eOpposite != oldEOpposite) 448 { 449 if (eNotificationRequired()) 450 eNotify(new ENotificationImpl(this, Notification.RESOLVE, EcorePackage.EREFERENCE__EOPPOSITE, oldEOpposite, eOpposite)); 451 } 452 } 453 return eOpposite; 454 } 455 456 461 public EReference basicGetEOpposite() 462 { 463 return eOpposite; 464 } 465 466 471 public void setEOpposite(EReference newEOpposite) 472 { 473 EReference oldEOpposite = eOpposite; 474 eOpposite = newEOpposite; 475 if (eNotificationRequired()) 476 eNotify(new ENotificationImpl(this, Notification.SET, EcorePackage.EREFERENCE__EOPPOSITE, oldEOpposite, eOpposite)); 477 } 478 479 484 public EClass getEReferenceType() 485 { 486 return (EClass)getEType(); 487 } 488 489 494 public EClass basicGetEReferenceType() 495 { 496 return (EClass)eType; 497 } 498 499 504 public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, Class baseClass, NotificationChain msgs) 505 { 506 if (featureID >= 0) 507 { 508 switch (eDerivedStructuralFeatureID(featureID, baseClass)) 509 { 510 case EcorePackage.EREFERENCE__EANNOTATIONS: 511 return ((InternalEList)getEAnnotations()).basicAdd(otherEnd, msgs); 512 case EcorePackage.EREFERENCE__ECONTAINING_CLASS: 513 if (eContainer != null) 514 msgs = eBasicRemoveFromContainer(msgs); 515 return eBasicSetContainer(otherEnd, EcorePackage.EREFERENCE__ECONTAINING_CLASS, msgs); 516 default: 517 return eDynamicInverseAdd(otherEnd, featureID, baseClass, msgs); 518 } 519 } 520 if (eContainer != null) 521 msgs = eBasicRemoveFromContainer(msgs); 522 return eBasicSetContainer(otherEnd, featureID, msgs); 523 } 524 525 530 public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class baseClass, NotificationChain msgs) 531 { 532 if (featureID >= 0) 533 { 534 switch (eDerivedStructuralFeatureID(featureID, baseClass)) 535 { 536 case EcorePackage.EREFERENCE__EANNOTATIONS: 537 return ((InternalEList)getEAnnotations()).basicRemove(otherEnd, msgs); 538 case EcorePackage.EREFERENCE__ECONTAINING_CLASS: 539 return eBasicSetContainer(null, EcorePackage.EREFERENCE__ECONTAINING_CLASS, msgs); 540 default: 541 return eDynamicInverseRemove(otherEnd, featureID, baseClass, msgs); 542 } 543 } 544 return eBasicSetContainer(null, featureID, msgs); 545 } 546 547 552 public NotificationChain eBasicRemoveFromContainer(NotificationChain msgs) 553 { 554 if (eContainerFeatureID >= 0) 555 { 556 switch (eContainerFeatureID) 557 { 558 case EcorePackage.EREFERENCE__ECONTAINING_CLASS: 559 return eContainer.eInverseRemove(this, EcorePackage.ECLASS__ESTRUCTURAL_FEATURES, EClass.class, msgs); 560 default: 561 return eDynamicBasicRemoveFromContainer(msgs); 562 } 563 } 564 return eContainer.eInverseRemove(this, EOPPOSITE_FEATURE_BASE - eContainerFeatureID, null, msgs); 565 } 566 567 572 public String toString() 573 { 574 if (eIsProxy()) return super.toString(); 575 576 StringBuffer result = new StringBuffer (super.toString()); 577 result.append(" (containment: "); 578 result.append((eFlags & CONTAINMENT_EFLAG) != 0); 579 result.append(", resolveProxies: "); 580 result.append((eFlags & RESOLVE_PROXIES_EFLAG) != 0); 581 result.append(')'); 582 return result.toString(); 583 } 584 585 } 586 | Popular Tags |