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.EAttribute; 25 import org.eclipse.emf.ecore.EClass; 26 import org.eclipse.emf.ecore.EClassifier; 27 import org.eclipse.emf.ecore.EDataType; 28 import org.eclipse.emf.ecore.EStructuralFeature; 29 import org.eclipse.emf.ecore.EcorePackage; 30 import org.eclipse.emf.ecore.InternalEObject; 31 import org.eclipse.emf.ecore.util.InternalEList; 32 import org.eclipse.emf.ecore.util.FeatureMapUtil; 33 34 35 49 public class EAttributeImpl extends EStructuralFeatureImpl implements EAttribute 50 { 51 59 protected static final boolean ID_EDEFAULT = false; 60 61 69 protected static final int ID_EFLAG = 1 << 15; 70 71 76 protected EAttributeImpl() 77 { 78 super(); 79 } 80 81 86 protected EClass eStaticClass() 87 { 88 return EcorePackage.eINSTANCE.getEAttribute(); 89 } 90 91 96 public boolean isID() 97 { 98 return (eFlags & ID_EFLAG) != 0; 99 } 100 101 protected byte effectiveIsMany; 102 103 public boolean isMany() 104 { 105 switch (effectiveIsMany) 106 { 107 case -1: 108 { 109 return true; 110 } 111 case 0: 112 { 113 int upper = getUpperBound(); 114 if (upper > 1 || upper == UNBOUNDED_MULTIPLICITY) 115 { 116 effectiveIsMany = -1; 117 return true; 118 } 119 else 120 { 121 EClassifier eType = getEType(); 122 if (eType != null && FeatureMapUtil.isFeatureMapEntry(eType)) 123 { 124 effectiveIsMany = -1; 125 return true; 126 } 127 else 128 { 129 effectiveIsMany = 1; 130 return false; 131 } 132 } 133 } 134 default: 135 case 1: 136 { 137 return false; 138 } 139 } 140 } 141 142 public void setUpperBound(int upperBound) 143 { 144 effectiveIsMany = 0; 145 super.setUpperBound(upperBound); 146 } 147 148 public void setEType(EClassifier eType) 149 { 150 effectiveIsMany = 0; 151 super.setEType(eType); 152 } 153 154 159 public void setID(boolean newID) 160 { 161 boolean oldID = (eFlags & ID_EFLAG) != 0; 162 if (newID) eFlags |= ID_EFLAG; else eFlags &= ~ID_EFLAG; 163 if (eNotificationRequired()) 164 eNotify(new ENotificationImpl(this, Notification.SET, EcorePackage.EATTRIBUTE__ID, oldID, newID)); 165 } 166 167 172 public EDataType getEAttributeType() 173 { 174 return (EDataType)getEType(); 175 } 176 177 182 public EDataType basicGetEAttributeType() 183 { 184 return (EDataType)eType; 185 } 186 187 192 public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, Class baseClass, NotificationChain msgs) 193 { 194 if (featureID >= 0) 195 { 196 switch (eDerivedStructuralFeatureID(featureID, baseClass)) 197 { 198 case EcorePackage.EATTRIBUTE__EANNOTATIONS: 199 return ((InternalEList)getEAnnotations()).basicAdd(otherEnd, msgs); 200 case EcorePackage.EATTRIBUTE__ECONTAINING_CLASS: 201 if (eContainer != null) 202 msgs = eBasicRemoveFromContainer(msgs); 203 return eBasicSetContainer(otherEnd, EcorePackage.EATTRIBUTE__ECONTAINING_CLASS, msgs); 204 default: 205 return eDynamicInverseAdd(otherEnd, featureID, baseClass, msgs); 206 } 207 } 208 if (eContainer != null) 209 msgs = eBasicRemoveFromContainer(msgs); 210 return eBasicSetContainer(otherEnd, featureID, msgs); 211 } 212 213 218 public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class baseClass, NotificationChain msgs) 219 { 220 if (featureID >= 0) 221 { 222 switch (eDerivedStructuralFeatureID(featureID, baseClass)) 223 { 224 case EcorePackage.EATTRIBUTE__EANNOTATIONS: 225 return ((InternalEList)getEAnnotations()).basicRemove(otherEnd, msgs); 226 case EcorePackage.EATTRIBUTE__ECONTAINING_CLASS: 227 return eBasicSetContainer(null, EcorePackage.EATTRIBUTE__ECONTAINING_CLASS, msgs); 228 default: 229 return eDynamicInverseRemove(otherEnd, featureID, baseClass, msgs); 230 } 231 } 232 return eBasicSetContainer(null, featureID, msgs); 233 } 234 235 240 public NotificationChain eBasicRemoveFromContainer(NotificationChain msgs) 241 { 242 if (eContainerFeatureID >= 0) 243 { 244 switch (eContainerFeatureID) 245 { 246 case EcorePackage.EATTRIBUTE__ECONTAINING_CLASS: 247 return eContainer.eInverseRemove(this, EcorePackage.ECLASS__ESTRUCTURAL_FEATURES, EClass.class, msgs); 248 default: 249 return eDynamicBasicRemoveFromContainer(msgs); 250 } 251 } 252 return eContainer.eInverseRemove(this, EOPPOSITE_FEATURE_BASE - eContainerFeatureID, null, msgs); 253 } 254 255 260 public Object eGet(EStructuralFeature eFeature, boolean resolve) 261 { 262 switch (eDerivedStructuralFeatureID(eFeature)) 263 { 264 case EcorePackage.EATTRIBUTE__EANNOTATIONS: 265 return getEAnnotations(); 266 case EcorePackage.EATTRIBUTE__NAME: 267 return getName(); 268 case EcorePackage.EATTRIBUTE__ORDERED: 269 return isOrdered() ? Boolean.TRUE : Boolean.FALSE; 270 case EcorePackage.EATTRIBUTE__UNIQUE: 271 return isUnique() ? Boolean.TRUE : Boolean.FALSE; 272 case EcorePackage.EATTRIBUTE__LOWER_BOUND: 273 return new Integer (getLowerBound()); 274 case EcorePackage.EATTRIBUTE__UPPER_BOUND: 275 return new Integer (getUpperBound()); 276 case EcorePackage.EATTRIBUTE__MANY: 277 return isMany() ? Boolean.TRUE : Boolean.FALSE; 278 case EcorePackage.EATTRIBUTE__REQUIRED: 279 return isRequired() ? Boolean.TRUE : Boolean.FALSE; 280 case EcorePackage.EATTRIBUTE__ETYPE: 281 if (resolve) return getEType(); 282 return basicGetEType(); 283 case EcorePackage.EATTRIBUTE__CHANGEABLE: 284 return isChangeable() ? Boolean.TRUE : Boolean.FALSE; 285 case EcorePackage.EATTRIBUTE__VOLATILE: 286 return isVolatile() ? Boolean.TRUE : Boolean.FALSE; 287 case EcorePackage.EATTRIBUTE__TRANSIENT: 288 return isTransient() ? Boolean.TRUE : Boolean.FALSE; 289 case EcorePackage.EATTRIBUTE__DEFAULT_VALUE_LITERAL: 290 return getDefaultValueLiteral(); 291 case EcorePackage.EATTRIBUTE__DEFAULT_VALUE: 292 return getDefaultValue(); 293 case EcorePackage.EATTRIBUTE__UNSETTABLE: 294 return isUnsettable() ? Boolean.TRUE : Boolean.FALSE; 295 case EcorePackage.EATTRIBUTE__DERIVED: 296 return isDerived() ? Boolean.TRUE : Boolean.FALSE; 297 case EcorePackage.EATTRIBUTE__ECONTAINING_CLASS: 298 return getEContainingClass(); 299 case EcorePackage.EATTRIBUTE__ID: 300 return isID() ? Boolean.TRUE : Boolean.FALSE; 301 case EcorePackage.EATTRIBUTE__EATTRIBUTE_TYPE: 302 if (resolve) return getEAttributeType(); 303 return basicGetEAttributeType(); 304 } 305 return eDynamicGet(eFeature, resolve); 306 } 307 308 313 public boolean eIsSet(EStructuralFeature eFeature) 314 { 315 switch (eDerivedStructuralFeatureID(eFeature)) 316 { 317 case EcorePackage.EATTRIBUTE__EANNOTATIONS: 318 return eAnnotations != null && !eAnnotations.isEmpty(); 319 case EcorePackage.EATTRIBUTE__NAME: 320 return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name); 321 case EcorePackage.EATTRIBUTE__ORDERED: 322 return ((eFlags & ORDERED_EFLAG) != 0) != ORDERED_EDEFAULT; 323 case EcorePackage.EATTRIBUTE__UNIQUE: 324 return ((eFlags & UNIQUE_EFLAG) != 0) != UNIQUE_EDEFAULT; 325 case EcorePackage.EATTRIBUTE__LOWER_BOUND: 326 return lowerBound != LOWER_BOUND_EDEFAULT; 327 case EcorePackage.EATTRIBUTE__UPPER_BOUND: 328 return upperBound != UPPER_BOUND_EDEFAULT; 329 case EcorePackage.EATTRIBUTE__MANY: 330 return isMany() != MANY_EDEFAULT; 331 case EcorePackage.EATTRIBUTE__REQUIRED: 332 return isRequired() != REQUIRED_EDEFAULT; 333 case EcorePackage.EATTRIBUTE__ETYPE: 334 return eType != null; 335 case EcorePackage.EATTRIBUTE__CHANGEABLE: 336 return ((eFlags & CHANGEABLE_EFLAG) != 0) != CHANGEABLE_EDEFAULT; 337 case EcorePackage.EATTRIBUTE__VOLATILE: 338 return ((eFlags & VOLATILE_EFLAG) != 0) != VOLATILE_EDEFAULT; 339 case EcorePackage.EATTRIBUTE__TRANSIENT: 340 return ((eFlags & TRANSIENT_EFLAG) != 0) != TRANSIENT_EDEFAULT; 341 case EcorePackage.EATTRIBUTE__DEFAULT_VALUE_LITERAL: 342 return DEFAULT_VALUE_LITERAL_EDEFAULT == null ? defaultValueLiteral != null : !DEFAULT_VALUE_LITERAL_EDEFAULT.equals(defaultValueLiteral); 343 case EcorePackage.EATTRIBUTE__DEFAULT_VALUE: 344 return DEFAULT_VALUE_EDEFAULT == null ? getDefaultValue() != null : !DEFAULT_VALUE_EDEFAULT.equals(getDefaultValue()); 345 case EcorePackage.EATTRIBUTE__UNSETTABLE: 346 return ((eFlags & UNSETTABLE_EFLAG) != 0) != UNSETTABLE_EDEFAULT; 347 case EcorePackage.EATTRIBUTE__DERIVED: 348 return ((eFlags & DERIVED_EFLAG) != 0) != DERIVED_EDEFAULT; 349 case EcorePackage.EATTRIBUTE__ECONTAINING_CLASS: 350 return getEContainingClass() != null; 351 case EcorePackage.EATTRIBUTE__ID: 352 return ((eFlags & ID_EFLAG) != 0) != ID_EDEFAULT; 353 case EcorePackage.EATTRIBUTE__EATTRIBUTE_TYPE: 354 return basicGetEAttributeType() != null; 355 } 356 return eDynamicIsSet(eFeature); 357 } 358 359 364 public void eSet(EStructuralFeature eFeature, Object newValue) 365 { 366 switch (eDerivedStructuralFeatureID(eFeature)) 367 { 368 case EcorePackage.EATTRIBUTE__EANNOTATIONS: 369 getEAnnotations().clear(); 370 getEAnnotations().addAll((Collection )newValue); 371 return; 372 case EcorePackage.EATTRIBUTE__NAME: 373 setName((String )newValue); 374 return; 375 case EcorePackage.EATTRIBUTE__ORDERED: 376 setOrdered(((Boolean )newValue).booleanValue()); 377 return; 378 case EcorePackage.EATTRIBUTE__UNIQUE: 379 setUnique(((Boolean )newValue).booleanValue()); 380 return; 381 case EcorePackage.EATTRIBUTE__LOWER_BOUND: 382 setLowerBound(((Integer )newValue).intValue()); 383 return; 384 case EcorePackage.EATTRIBUTE__UPPER_BOUND: 385 setUpperBound(((Integer )newValue).intValue()); 386 return; 387 case EcorePackage.EATTRIBUTE__ETYPE: 388 setEType((EClassifier)newValue); 389 return; 390 case EcorePackage.EATTRIBUTE__CHANGEABLE: 391 setChangeable(((Boolean )newValue).booleanValue()); 392 return; 393 case EcorePackage.EATTRIBUTE__VOLATILE: 394 setVolatile(((Boolean )newValue).booleanValue()); 395 return; 396 case EcorePackage.EATTRIBUTE__TRANSIENT: 397 setTransient(((Boolean )newValue).booleanValue()); 398 return; 399 case EcorePackage.EATTRIBUTE__DEFAULT_VALUE_LITERAL: 400 setDefaultValueLiteral((String )newValue); 401 return; 402 case EcorePackage.EATTRIBUTE__UNSETTABLE: 403 setUnsettable(((Boolean )newValue).booleanValue()); 404 return; 405 case EcorePackage.EATTRIBUTE__DERIVED: 406 setDerived(((Boolean )newValue).booleanValue()); 407 return; 408 case EcorePackage.EATTRIBUTE__ID: 409 setID(((Boolean )newValue).booleanValue()); 410 return; 411 } 412 eDynamicSet(eFeature, newValue); 413 } 414 415 420 public void eUnset(EStructuralFeature eFeature) 421 { 422 switch (eDerivedStructuralFeatureID(eFeature)) 423 { 424 case EcorePackage.EATTRIBUTE__EANNOTATIONS: 425 getEAnnotations().clear(); 426 return; 427 case EcorePackage.EATTRIBUTE__NAME: 428 setName(NAME_EDEFAULT); 429 return; 430 case EcorePackage.EATTRIBUTE__ORDERED: 431 setOrdered(ORDERED_EDEFAULT); 432 return; 433 case EcorePackage.EATTRIBUTE__UNIQUE: 434 setUnique(UNIQUE_EDEFAULT); 435 return; 436 case EcorePackage.EATTRIBUTE__LOWER_BOUND: 437 setLowerBound(LOWER_BOUND_EDEFAULT); 438 return; 439 case EcorePackage.EATTRIBUTE__UPPER_BOUND: 440 setUpperBound(UPPER_BOUND_EDEFAULT); 441 return; 442 case EcorePackage.EATTRIBUTE__ETYPE: 443 setEType((EClassifier)null); 444 return; 445 case EcorePackage.EATTRIBUTE__CHANGEABLE: 446 setChangeable(CHANGEABLE_EDEFAULT); 447 return; 448 case EcorePackage.EATTRIBUTE__VOLATILE: 449 setVolatile(VOLATILE_EDEFAULT); 450 return; 451 case EcorePackage.EATTRIBUTE__TRANSIENT: 452 setTransient(TRANSIENT_EDEFAULT); 453 return; 454 case EcorePackage.EATTRIBUTE__DEFAULT_VALUE_LITERAL: 455 setDefaultValueLiteral(DEFAULT_VALUE_LITERAL_EDEFAULT); 456 return; 457 case EcorePackage.EATTRIBUTE__UNSETTABLE: 458 setUnsettable(UNSETTABLE_EDEFAULT); 459 return; 460 case EcorePackage.EATTRIBUTE__DERIVED: 461 setDerived(DERIVED_EDEFAULT); 462 return; 463 case EcorePackage.EATTRIBUTE__ID: 464 setID(ID_EDEFAULT); 465 return; 466 } 467 eDynamicUnset(eFeature); 468 } 469 470 475 public String toString() 476 { 477 if (eIsProxy()) return super.toString(); 478 479 StringBuffer result = new StringBuffer (super.toString()); 480 result.append(" (iD: "); 481 result.append((eFlags & ID_EFLAG) != 0); 482 result.append(')'); 483 return result.toString(); 484 } 485 486 } 487 | Popular Tags |