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.EStructuralFeature; 27 import org.eclipse.emf.ecore.ETypedElement; 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 52 public abstract class ETypedElementImpl extends ENamedElementImpl implements ETypedElement 53 { 54 62 protected static final boolean ORDERED_EDEFAULT = true; 63 64 72 protected static final int ORDERED_EFLAG = 1 << 8; 73 74 82 protected static final boolean UNIQUE_EDEFAULT = true; 83 84 92 protected static final int UNIQUE_EFLAG = 1 << 9; 93 94 102 protected static final int LOWER_BOUND_EDEFAULT = 0; 103 104 112 protected int lowerBound = LOWER_BOUND_EDEFAULT; 113 114 122 protected static final int UPPER_BOUND_EDEFAULT = 1; 123 124 132 protected int upperBound = UPPER_BOUND_EDEFAULT; 133 134 142 protected static final boolean MANY_EDEFAULT = false; 143 144 152 protected static final boolean REQUIRED_EDEFAULT = false; 153 154 162 protected EClassifier eType = null; 163 164 169 protected ETypedElementImpl() 170 { 171 super(); 172 eFlags |= ORDERED_EFLAG; 173 eFlags |= UNIQUE_EFLAG; 174 } 175 176 public void freeze() 177 { 178 getEType(); 179 super.freeze(); 180 } 181 182 187 protected EClass eStaticClass() 188 { 189 return EcorePackage.eINSTANCE.getETypedElement(); 190 } 191 192 197 public boolean isOrdered() 198 { 199 return (eFlags & ORDERED_EFLAG) != 0; 200 } 201 202 207 public void setOrdered(boolean newOrdered) 208 { 209 boolean oldOrdered = (eFlags & ORDERED_EFLAG) != 0; 210 if (newOrdered) eFlags |= ORDERED_EFLAG; else eFlags &= ~ORDERED_EFLAG; 211 if (eNotificationRequired()) 212 eNotify(new ENotificationImpl(this, Notification.SET, EcorePackage.ETYPED_ELEMENT__ORDERED, oldOrdered, newOrdered)); 213 } 214 215 220 public boolean isUnique() 221 { 222 return (eFlags & UNIQUE_EFLAG) != 0; 223 } 224 225 230 public void setUnique(boolean newUnique) 231 { 232 boolean oldUnique = (eFlags & UNIQUE_EFLAG) != 0; 233 if (newUnique) eFlags |= UNIQUE_EFLAG; else eFlags &= ~UNIQUE_EFLAG; 234 if (eNotificationRequired()) 235 eNotify(new ENotificationImpl(this, Notification.SET, EcorePackage.ETYPED_ELEMENT__UNIQUE, oldUnique, newUnique)); 236 } 237 238 243 public int getLowerBound() 244 { 245 return lowerBound; 246 } 247 248 253 public void setLowerBound(int newLowerBound) 254 { 255 int oldLowerBound = lowerBound; 256 lowerBound = newLowerBound; 257 if (eNotificationRequired()) 258 eNotify(new ENotificationImpl(this, Notification.SET, EcorePackage.ETYPED_ELEMENT__LOWER_BOUND, oldLowerBound, lowerBound)); 259 } 260 261 266 public int getUpperBound() 267 { 268 return upperBound; 269 } 270 271 276 public void setUpperBound(int newUpperBound) 277 { 278 int oldUpperBound = upperBound; 279 upperBound = newUpperBound; 280 if (eNotificationRequired()) 281 eNotify(new ENotificationImpl(this, Notification.SET, EcorePackage.ETYPED_ELEMENT__UPPER_BOUND, oldUpperBound, upperBound)); 282 } 283 284 public boolean isMany() 285 { 286 int upper = getUpperBound(); 287 return upper > 1 || upper == UNBOUNDED_MULTIPLICITY; 288 } 289 290 public boolean isRequired() 291 { 292 int lower = getLowerBound(); 293 return lower >= 1; 294 } 295 296 301 public EClassifier getETypeGen() 302 { 303 if (eType != null && eType.eIsProxy()) 304 { 305 EClassifier oldEType = eType; 306 eType = (EClassifier)eResolveProxy((InternalEObject)eType); 307 if (eType != oldEType) 308 { 309 if (eNotificationRequired()) 310 eNotify(new ENotificationImpl(this, Notification.RESOLVE, EcorePackage.ETYPED_ELEMENT__ETYPE, oldEType, eType)); 311 } 312 } 313 return eType; 314 } 315 316 public EClassifier getEType() 317 { 318 return isFrozen() ? eType : getETypeGen(); 319 } 320 321 326 public EClassifier basicGetEType() 327 { 328 return eType; 329 } 330 331 336 public void setEType(EClassifier newEType) 337 { 338 EClassifier oldEType = eType; 339 eType = newEType; 340 if (eNotificationRequired()) 341 eNotify(new ENotificationImpl(this, Notification.SET, EcorePackage.ETYPED_ELEMENT__ETYPE, oldEType, eType)); 342 } 343 344 349 public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, Class baseClass, NotificationChain msgs) 350 { 351 if (featureID >= 0) 352 { 353 switch (eDerivedStructuralFeatureID(featureID, baseClass)) 354 { 355 case EcorePackage.ETYPED_ELEMENT__EANNOTATIONS: 356 return ((InternalEList)getEAnnotations()).basicAdd(otherEnd, msgs); 357 default: 358 return eDynamicInverseAdd(otherEnd, featureID, baseClass, msgs); 359 } 360 } 361 if (eContainer != null) 362 msgs = eBasicRemoveFromContainer(msgs); 363 return eBasicSetContainer(otherEnd, featureID, msgs); 364 } 365 366 371 public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class baseClass, NotificationChain msgs) 372 { 373 if (featureID >= 0) 374 { 375 switch (eDerivedStructuralFeatureID(featureID, baseClass)) 376 { 377 case EcorePackage.ETYPED_ELEMENT__EANNOTATIONS: 378 return ((InternalEList)getEAnnotations()).basicRemove(otherEnd, msgs); 379 default: 380 return eDynamicInverseRemove(otherEnd, featureID, baseClass, msgs); 381 } 382 } 383 return eBasicSetContainer(null, featureID, msgs); 384 } 385 386 391 public Object eGet(EStructuralFeature eFeature, boolean resolve) 392 { 393 switch (eDerivedStructuralFeatureID(eFeature)) 394 { 395 case EcorePackage.ETYPED_ELEMENT__EANNOTATIONS: 396 return getEAnnotations(); 397 case EcorePackage.ETYPED_ELEMENT__NAME: 398 return getName(); 399 case EcorePackage.ETYPED_ELEMENT__ORDERED: 400 return isOrdered() ? Boolean.TRUE : Boolean.FALSE; 401 case EcorePackage.ETYPED_ELEMENT__UNIQUE: 402 return isUnique() ? Boolean.TRUE : Boolean.FALSE; 403 case EcorePackage.ETYPED_ELEMENT__LOWER_BOUND: 404 return new Integer (getLowerBound()); 405 case EcorePackage.ETYPED_ELEMENT__UPPER_BOUND: 406 return new Integer (getUpperBound()); 407 case EcorePackage.ETYPED_ELEMENT__MANY: 408 return isMany() ? Boolean.TRUE : Boolean.FALSE; 409 case EcorePackage.ETYPED_ELEMENT__REQUIRED: 410 return isRequired() ? Boolean.TRUE : Boolean.FALSE; 411 case EcorePackage.ETYPED_ELEMENT__ETYPE: 412 if (resolve) return getEType(); 413 return basicGetEType(); 414 } 415 return eDynamicGet(eFeature, resolve); 416 } 417 418 423 public boolean eIsSet(EStructuralFeature eFeature) 424 { 425 switch (eDerivedStructuralFeatureID(eFeature)) 426 { 427 case EcorePackage.ETYPED_ELEMENT__EANNOTATIONS: 428 return eAnnotations != null && !eAnnotations.isEmpty(); 429 case EcorePackage.ETYPED_ELEMENT__NAME: 430 return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name); 431 case EcorePackage.ETYPED_ELEMENT__ORDERED: 432 return ((eFlags & ORDERED_EFLAG) != 0) != ORDERED_EDEFAULT; 433 case EcorePackage.ETYPED_ELEMENT__UNIQUE: 434 return ((eFlags & UNIQUE_EFLAG) != 0) != UNIQUE_EDEFAULT; 435 case EcorePackage.ETYPED_ELEMENT__LOWER_BOUND: 436 return lowerBound != LOWER_BOUND_EDEFAULT; 437 case EcorePackage.ETYPED_ELEMENT__UPPER_BOUND: 438 return upperBound != UPPER_BOUND_EDEFAULT; 439 case EcorePackage.ETYPED_ELEMENT__MANY: 440 return isMany() != MANY_EDEFAULT; 441 case EcorePackage.ETYPED_ELEMENT__REQUIRED: 442 return isRequired() != REQUIRED_EDEFAULT; 443 case EcorePackage.ETYPED_ELEMENT__ETYPE: 444 return eType != null; 445 } 446 return eDynamicIsSet(eFeature); 447 } 448 449 454 public String toString() 455 { 456 if (eIsProxy()) return super.toString(); 457 458 StringBuffer result = new StringBuffer (super.toString()); 459 result.append(" (ordered: "); 460 result.append((eFlags & ORDERED_EFLAG) != 0); 461 result.append(", unique: "); 462 result.append((eFlags & UNIQUE_EFLAG) != 0); 463 result.append(", lowerBound: "); 464 result.append(lowerBound); 465 result.append(", upperBound: "); 466 result.append(upperBound); 467 result.append(')'); 468 return result.toString(); 469 } 470 471 476 public void eSet(EStructuralFeature eFeature, Object newValue) 477 { 478 switch (eDerivedStructuralFeatureID(eFeature)) 479 { 480 case EcorePackage.ETYPED_ELEMENT__EANNOTATIONS: 481 getEAnnotations().clear(); 482 getEAnnotations().addAll((Collection )newValue); 483 return; 484 case EcorePackage.ETYPED_ELEMENT__NAME: 485 setName((String )newValue); 486 return; 487 case EcorePackage.ETYPED_ELEMENT__ORDERED: 488 setOrdered(((Boolean )newValue).booleanValue()); 489 return; 490 case EcorePackage.ETYPED_ELEMENT__UNIQUE: 491 setUnique(((Boolean )newValue).booleanValue()); 492 return; 493 case EcorePackage.ETYPED_ELEMENT__LOWER_BOUND: 494 setLowerBound(((Integer )newValue).intValue()); 495 return; 496 case EcorePackage.ETYPED_ELEMENT__UPPER_BOUND: 497 setUpperBound(((Integer )newValue).intValue()); 498 return; 499 case EcorePackage.ETYPED_ELEMENT__ETYPE: 500 setEType((EClassifier)newValue); 501 return; 502 } 503 eDynamicSet(eFeature, newValue); 504 } 505 506 511 public void eUnset(EStructuralFeature eFeature) 512 { 513 switch (eDerivedStructuralFeatureID(eFeature)) 514 { 515 case EcorePackage.ETYPED_ELEMENT__EANNOTATIONS: 516 getEAnnotations().clear(); 517 return; 518 case EcorePackage.ETYPED_ELEMENT__NAME: 519 setName(NAME_EDEFAULT); 520 return; 521 case EcorePackage.ETYPED_ELEMENT__ORDERED: 522 setOrdered(ORDERED_EDEFAULT); 523 return; 524 case EcorePackage.ETYPED_ELEMENT__UNIQUE: 525 setUnique(UNIQUE_EDEFAULT); 526 return; 527 case EcorePackage.ETYPED_ELEMENT__LOWER_BOUND: 528 setLowerBound(LOWER_BOUND_EDEFAULT); 529 return; 530 case EcorePackage.ETYPED_ELEMENT__UPPER_BOUND: 531 setUpperBound(UPPER_BOUND_EDEFAULT); 532 return; 533 case EcorePackage.ETYPED_ELEMENT__ETYPE: 534 setEType((EClassifier)null); 535 return; 536 } 537 eDynamicUnset(eFeature); 538 } 539 540 } | Popular Tags |