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.common.util.WrappedException; 25 import org.eclipse.emf.ecore.EClass; 26 import org.eclipse.emf.ecore.EClassifier; 27 import org.eclipse.emf.ecore.EObject; 28 import org.eclipse.emf.ecore.EPackage; 29 import org.eclipse.emf.ecore.EStructuralFeature; 30 import org.eclipse.emf.ecore.EcorePackage; 31 import org.eclipse.emf.ecore.InternalEObject; 32 import org.eclipse.emf.ecore.util.BasicExtendedMetaData; 33 import org.eclipse.emf.ecore.util.InternalEList; 34 35 36 53 public abstract class EClassifierImpl extends ENamedElementImpl implements EClassifier, BasicExtendedMetaData.EClassifierExtendedMetaData.Holder 54 { 55 protected int metaObjectID = -1; 56 57 62 protected EClassifierImpl() 63 { 64 super(); 65 } 66 67 72 protected EClass eStaticClass() 73 { 74 return EcorePackage.eINSTANCE.getEClassifier(); 75 } 76 77 82 public int getClassifierID() 83 { 84 return metaObjectID; 85 } 86 87 92 public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, Class baseClass, NotificationChain msgs) 93 { 94 if (featureID >= 0) 95 { 96 switch (eDerivedStructuralFeatureID(featureID, baseClass)) 97 { 98 case EcorePackage.ECLASSIFIER__EANNOTATIONS: 99 return ((InternalEList)getEAnnotations()).basicAdd(otherEnd, msgs); 100 case EcorePackage.ECLASSIFIER__EPACKAGE: 101 if (eContainer != null) 102 msgs = eBasicRemoveFromContainer(msgs); 103 return eBasicSetContainer(otherEnd, EcorePackage.ECLASSIFIER__EPACKAGE, msgs); 104 default: 105 return eDynamicInverseAdd(otherEnd, featureID, baseClass, msgs); 106 } 107 } 108 if (eContainer != null) 109 msgs = eBasicRemoveFromContainer(msgs); 110 return eBasicSetContainer(otherEnd, featureID, msgs); 111 } 112 113 118 public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class baseClass, NotificationChain msgs) 119 { 120 if (featureID >= 0) 121 { 122 switch (eDerivedStructuralFeatureID(featureID, baseClass)) 123 { 124 case EcorePackage.ECLASSIFIER__EANNOTATIONS: 125 return ((InternalEList)getEAnnotations()).basicRemove(otherEnd, msgs); 126 case EcorePackage.ECLASSIFIER__EPACKAGE: 127 return eBasicSetContainer(null, EcorePackage.ECLASSIFIER__EPACKAGE, msgs); 128 default: 129 return eDynamicInverseRemove(otherEnd, featureID, baseClass, msgs); 130 } 131 } 132 return eBasicSetContainer(null, featureID, msgs); 133 } 134 135 public void setClassifierID(int id) 136 { 137 metaObjectID = id; 138 } 139 140 146 public boolean isInstance(Object object) 147 { 148 if (object != null) 149 { 150 Class instanceClass = getInstanceClass(); 151 if (instanceClass != null) 152 { 153 if (instanceClass.isPrimitive()) 154 { 155 if (instanceClass == Boolean.TYPE) 156 { 157 return object instanceof Boolean ; 158 } 159 else if (instanceClass == Integer.TYPE) 160 { 161 return object instanceof Integer ; 162 } 163 else if (instanceClass == Float.TYPE) 164 { 165 return object instanceof Float ; 166 } 167 else if (instanceClass == Byte.TYPE) 168 { 169 return object instanceof Byte ; 170 } 171 else if (instanceClass == Character.TYPE) 172 { 173 return object instanceof Character ; 174 } 175 else if (instanceClass == Double.TYPE) 176 { 177 return object instanceof Double ; 178 } 179 else if (instanceClass == Short.TYPE) 180 { 181 return object instanceof Short ; 182 } 183 else if (instanceClass == Long.TYPE) 184 { 185 return object instanceof Long ; 186 } 187 } 188 else 189 { 190 return instanceClass.isInstance(object); 191 } 192 } 193 else if (object instanceof EObject) 194 { 195 return dynamicIsInstance((EObject)object); 196 } 197 } 198 199 return false; 200 } 201 202 protected boolean dynamicIsInstance(EObject eObject) 203 { 204 return eObject.eClass() == this; 205 } 206 207 212 public Object eGet(EStructuralFeature eFeature, boolean resolve) 213 { 214 switch (eDerivedStructuralFeatureID(eFeature)) 215 { 216 case EcorePackage.ECLASSIFIER__EANNOTATIONS: 217 return getEAnnotations(); 218 case EcorePackage.ECLASSIFIER__NAME: 219 return getName(); 220 case EcorePackage.ECLASSIFIER__INSTANCE_CLASS_NAME: 221 return getInstanceClassName(); 222 case EcorePackage.ECLASSIFIER__INSTANCE_CLASS: 223 return getInstanceClass(); 224 case EcorePackage.ECLASSIFIER__DEFAULT_VALUE: 225 return getDefaultValue(); 226 case EcorePackage.ECLASSIFIER__EPACKAGE: 227 return getEPackage(); 228 } 229 return eDynamicGet(eFeature, resolve); 230 } 231 232 237 public boolean eIsSet(EStructuralFeature eFeature) 238 { 239 switch (eDerivedStructuralFeatureID(eFeature)) 240 { 241 case EcorePackage.ECLASSIFIER__EANNOTATIONS: 242 return eAnnotations != null && !eAnnotations.isEmpty(); 243 case EcorePackage.ECLASSIFIER__NAME: 244 return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name); 245 case EcorePackage.ECLASSIFIER__INSTANCE_CLASS_NAME: 246 return INSTANCE_CLASS_NAME_EDEFAULT == null ? instanceClassName != null : !INSTANCE_CLASS_NAME_EDEFAULT.equals(instanceClassName); 247 case EcorePackage.ECLASSIFIER__INSTANCE_CLASS: 248 return INSTANCE_CLASS_EDEFAULT == null ? getInstanceClass() != null : !INSTANCE_CLASS_EDEFAULT.equals(getInstanceClass()); 249 case EcorePackage.ECLASSIFIER__DEFAULT_VALUE: 250 return DEFAULT_VALUE_EDEFAULT == null ? getDefaultValue() != null : !DEFAULT_VALUE_EDEFAULT.equals(getDefaultValue()); 251 case EcorePackage.ECLASSIFIER__EPACKAGE: 252 return getEPackage() != null; 253 } 254 return eDynamicIsSet(eFeature); 255 } 256 257 262 public void eSet(EStructuralFeature eFeature, Object newValue) 263 { 264 switch (eDerivedStructuralFeatureID(eFeature)) 265 { 266 case EcorePackage.ECLASSIFIER__EANNOTATIONS: 267 getEAnnotations().clear(); 268 getEAnnotations().addAll((Collection )newValue); 269 return; 270 case EcorePackage.ECLASSIFIER__NAME: 271 setName((String )newValue); 272 return; 273 case EcorePackage.ECLASSIFIER__INSTANCE_CLASS_NAME: 274 setInstanceClassName((String )newValue); 275 return; 276 } 277 eDynamicSet(eFeature, newValue); 278 } 279 280 285 public void eUnset(EStructuralFeature eFeature) 286 { 287 switch (eDerivedStructuralFeatureID(eFeature)) 288 { 289 case EcorePackage.ECLASSIFIER__EANNOTATIONS: 290 getEAnnotations().clear(); 291 return; 292 case EcorePackage.ECLASSIFIER__NAME: 293 setName(NAME_EDEFAULT); 294 return; 295 case EcorePackage.ECLASSIFIER__INSTANCE_CLASS_NAME: 296 setInstanceClassName(INSTANCE_CLASS_NAME_EDEFAULT); 297 return; 298 } 299 eDynamicUnset(eFeature); 300 } 301 302 310 protected static final String INSTANCE_CLASS_NAME_EDEFAULT = null; 311 312 320 protected String instanceClassName = INSTANCE_CLASS_NAME_EDEFAULT; 321 322 327 public String getInstanceClassNameGen() 328 { 329 return instanceClassName; 330 } 331 332 public String getInstanceClassName() 333 { 334 return getInstanceClassNameGen() != null ? getInstanceClassNameGen() : generatedInstanceClassName; 335 } 336 337 protected String generatedInstanceClassName; 338 339 public void setGeneratedInstanceClass(boolean isGenerated) 340 { 341 if (isGenerated) 342 { 343 if (generatedInstanceClassName == null) 344 { 345 generatedInstanceClassName = instanceClassName; 346 instanceClassName = null; 347 } 348 } 349 else if (generatedInstanceClassName != null) 350 { 351 instanceClassName = generatedInstanceClassName; 352 generatedInstanceClassName = null; 353 } 354 } 355 356 public void setInstanceClassName(String value) 357 { 358 if (instanceClassName == null && generatedInstanceClassName != null) 359 { 360 instanceClassName = generatedInstanceClassName; 361 generatedInstanceClassName = null; 362 } 363 setInstanceClassNameGen(value == null ? null : value.intern()); 364 if (instanceClass != null) 365 { 366 setInstanceClassGen(null); 367 } 368 } 369 370 375 public void setInstanceClassNameGen(String newInstanceClassName) 376 { 377 String oldInstanceClassName = instanceClassName; 378 instanceClassName = newInstanceClassName; 379 if (eNotificationRequired()) 380 eNotify(new ENotificationImpl(this, Notification.SET, EcorePackage.ECLASSIFIER__INSTANCE_CLASS_NAME, oldInstanceClassName, instanceClassName)); 381 } 382 383 387 protected static final Class INSTANCE_CLASS_EDEFAULT = null; 388 389 397 protected static final Object DEFAULT_VALUE_EDEFAULT = null; 398 399 403 protected Class instanceClass = INSTANCE_CLASS_EDEFAULT; 404 405 public Class getInstanceClass() 406 { 407 if (instanceClass == null && (instanceClassName != null || generatedInstanceClassName != null)) 408 { 409 try 410 { 411 setInstanceClassGen(getClassForName(getInstanceClassName())); 412 } 413 catch (ClassNotFoundException e) 414 { 415 Class primitiveClass = getPrimitiveOrArrayClass(); 416 if (primitiveClass != null) 417 setInstanceClassGen(primitiveClass); 418 else 419 throw new WrappedException(e); 420 } 421 } 422 return getInstanceClassGen(); 423 } 424 425 431 protected Class getClassForName(String name) throws ClassNotFoundException 432 { 433 EPackage p = getEPackage(); 434 return p != null ? Class.forName(name, true, p.getClass().getClassLoader()) : Class.forName(name); 435 } 436 437 protected Class getPrimitiveOrArrayClass() 438 { 439 String className = getInstanceClassName(); 440 int arrayIndex = className.indexOf('['); 441 if (arrayIndex != -1) 442 { 443 String componentClassName = className.substring(0, arrayIndex); 444 StringBuffer result = new StringBuffer (); 445 do result.append('['); while ((arrayIndex = className.indexOf('[', ++arrayIndex)) != -1); 446 if (componentClassName.equals("boolean")) 447 result.append('Z'); 448 else if (componentClassName.equals("byte")) 449 result.append('B'); 450 else if (componentClassName.equals("char")) 451 result.append('C'); 452 else if (componentClassName.equals("double")) 453 result.append('D'); 454 else if (componentClassName.equals("float")) 455 result.append('F'); 456 else if (componentClassName.equals("int")) 457 result.append('I'); 458 else if (componentClassName.equals("long")) 459 result.append('J'); 460 else if (componentClassName.equals("short")) 461 result.append('S'); 462 else { 463 result.append('L'); 464 result.append(componentClassName); 465 result.append(';'); 466 } 467 try 468 { 469 return getClassForName(result.toString()); 470 } 471 catch (ClassNotFoundException e) {} 472 } 473 else 474 { 475 if (className.equals("boolean")) 476 return java.lang.Boolean.TYPE; 477 else if (className.equals("byte")) 478 return java.lang.Byte.TYPE; 479 else if (className.equals("char")) 480 return java.lang.Character.TYPE; 481 else if (className.equals("double")) 482 return java.lang.Double.TYPE; 483 else if (className.equals("float")) 484 return java.lang.Float.TYPE; 485 else if (className.equals("int")) 486 return java.lang.Integer.TYPE; 487 else if (className.equals("long")) 488 return java.lang.Long.TYPE; 489 else if (className.equals("short")) 490 return java.lang.Short.TYPE; 491 } 492 return null; 493 } 494 495 497 public Class getInstanceClassGen() 498 { 499 return instanceClass; 500 } 501 502 public void setInstanceClass(Class value) 503 { 504 if (value == null) 505 { 506 setInstanceClassNameGen(null); 507 } 508 else if (value.isArray()) 509 { 510 String indices = "[]"; 511 for (Class component = value.getComponentType(); ; component = component.getComponentType()) 512 { 513 if (!component.isArray()) 514 { 515 setInstanceClassNameGen((component.getName() + indices).intern()); 516 break; 517 } 518 indices += "[]"; 519 } 520 } 521 else 522 { 523 setInstanceClassNameGen(value.getName().intern()); 524 } 525 526 setInstanceClassGen(value); 527 } 528 529 531 public void setInstanceClassGen(Class newInstanceClass) 532 { 533 instanceClass = newInstanceClass; 534 } 535 536 538 public Object getDefaultValue() 539 { 540 return null; 541 } 542 543 548 public EPackage getEPackage() 549 { 550 return (eContainerFeatureID == EcorePackage.ECLASSIFIER__EPACKAGE) ? (EPackage)eContainer : null; 551 } 552 553 558 public String toString() 559 { 560 if (eIsProxy()) return super.toString(); 561 562 StringBuffer result = new StringBuffer (super.toString()); 563 result.append(" (instanceClassName: "); 564 result.append(instanceClassName); 565 result.append(')'); 566 return result.toString(); 567 } 568 569 574 public NotificationChain eBasicRemoveFromContainer(NotificationChain msgs) 575 { 576 if (eContainerFeatureID >= 0) 577 { 578 switch (eContainerFeatureID) 579 { 580 case EcorePackage.ECLASSIFIER__EPACKAGE: 581 return eContainer.eInverseRemove(this, EcorePackage.EPACKAGE__ECLASSIFIERS, EPackage.class, msgs); 582 default: 583 return eDynamicBasicRemoveFromContainer(msgs); 584 } 585 } 586 return eContainer.eInverseRemove(this, EOPPOSITE_FEATURE_BASE - eContainerFeatureID, null, msgs); 587 } 588 589 protected BasicExtendedMetaData.EClassifierExtendedMetaData eClassifierExtendedMetaData; 590 591 public BasicExtendedMetaData.EClassifierExtendedMetaData getExtendedMetaData() 592 { 593 return eClassifierExtendedMetaData; 594 } 595 596 public void setExtendedMetaData(BasicExtendedMetaData.EClassifierExtendedMetaData eClassifierExtendedMetaData) 597 { 598 this.eClassifierExtendedMetaData = eClassifierExtendedMetaData; 599 } 600 } 601 | Popular Tags |