1 17 package org.eclipse.emf.ecore.impl; 18 19 20 import java.lang.reflect.Method ; 21 import java.util.Collection ; 22 import java.util.HashMap ; 23 import java.util.Iterator ; 24 import java.util.List ; 25 import java.util.Map ; 26 27 import org.eclipse.emf.common.notify.Notification; 28 import org.eclipse.emf.common.notify.NotificationChain; 29 import org.eclipse.emf.common.util.EList; 30 import org.eclipse.emf.common.util.EMap; 31 import org.eclipse.emf.common.util.Enumerator; 32 import org.eclipse.emf.common.util.URI; 33 import org.eclipse.emf.ecore.EAnnotation; 34 import org.eclipse.emf.ecore.EAttribute; 35 import org.eclipse.emf.ecore.EClass; 36 import org.eclipse.emf.ecore.EClassifier; 37 import org.eclipse.emf.ecore.EDataType; 38 import org.eclipse.emf.ecore.EEnum; 39 import org.eclipse.emf.ecore.EEnumLiteral; 40 import org.eclipse.emf.ecore.EFactory; 41 import org.eclipse.emf.ecore.ENamedElement; 42 import org.eclipse.emf.ecore.EOperation; 43 import org.eclipse.emf.ecore.EPackage; 44 import org.eclipse.emf.ecore.EParameter; 45 import org.eclipse.emf.ecore.EReference; 46 import org.eclipse.emf.ecore.EStructuralFeature; 47 import org.eclipse.emf.ecore.EcoreFactory; 48 import org.eclipse.emf.ecore.EcorePackage; 49 import org.eclipse.emf.ecore.InternalEObject; 50 import org.eclipse.emf.ecore.resource.Resource; 51 import org.eclipse.emf.ecore.resource.impl.ResourceImpl; 52 import org.eclipse.emf.ecore.util.BasicExtendedMetaData; 53 import org.eclipse.emf.ecore.util.ExtendedMetaData; 54 import org.eclipse.emf.ecore.util.EObjectContainmentWithInverseEList; 55 import org.eclipse.emf.ecore.util.InternalEList; 56 57 58 77 public class EPackageImpl extends ENamedElementImpl implements EPackage, BasicExtendedMetaData.EPackageExtendedMetaData.Holder 78 { 79 87 protected static final String NS_URI_EDEFAULT = null; 88 89 92 protected EcoreFactory ecoreFactory = null; 93 94 97 protected EcorePackage ecorePackage = null; 98 99 102 protected Map eNameToEClassifierMap; 103 104 110 protected EPackageImpl() 111 { 112 super(); 113 114 setEFactoryInstance(new EFactoryImpl()); 115 116 ecorePackage = EcorePackage.eINSTANCE; 117 ecoreFactory = EcoreFactory.eINSTANCE; 118 } 119 120 124 protected EPackageImpl(EFactory eFactory) 125 { 126 super(); 127 128 setEFactoryInstance(eFactory); 129 130 ecorePackage = EcorePackage.eINSTANCE; 131 ecoreFactory = EcoreFactory.eINSTANCE; 132 } 133 134 138 protected EPackageImpl(String packageURI) 139 { 140 this(packageURI, new EFactoryImpl()); 141 } 142 143 148 protected EPackageImpl(String packageURI, EFactory factory) 149 { 150 super(); 151 152 Registry.INSTANCE.put(packageURI, this); 153 154 setEFactoryInstance(factory); 155 156 if (factory == EcoreFactory.eINSTANCE) 157 { 158 ecorePackage = (EcorePackage)this; 159 ecoreFactory = (EcoreFactory)factory; 160 } 161 else 162 { 163 ecorePackage = EcorePackage.eINSTANCE; 164 ecoreFactory = EcoreFactory.eINSTANCE; 165 } 166 } 167 168 public void freeze() 169 { 170 super.freeze(); 171 } 172 173 178 protected EClass eStaticClass() 179 { 180 return EcorePackage.eINSTANCE.getEPackage(); 181 } 182 183 186 public void setNamespaceURI(String nsURI) 187 { 188 } 189 190 195 public Object eGet(EStructuralFeature eFeature, boolean resolve) 196 { 197 switch (eDerivedStructuralFeatureID(eFeature)) 198 { 199 case EcorePackage.EPACKAGE__EANNOTATIONS: 200 return getEAnnotations(); 201 case EcorePackage.EPACKAGE__NAME: 202 return getName(); 203 case EcorePackage.EPACKAGE__NS_URI: 204 return getNsURI(); 205 case EcorePackage.EPACKAGE__NS_PREFIX: 206 return getNsPrefix(); 207 case EcorePackage.EPACKAGE__EFACTORY_INSTANCE: 208 return getEFactoryInstance(); 209 case EcorePackage.EPACKAGE__ECLASSIFIERS: 210 return getEClassifiers(); 211 case EcorePackage.EPACKAGE__ESUBPACKAGES: 212 return getESubpackages(); 213 case EcorePackage.EPACKAGE__ESUPER_PACKAGE: 214 return getESuperPackage(); 215 } 216 return eDynamicGet(eFeature, resolve); 217 } 218 219 224 public boolean eIsSet(EStructuralFeature eFeature) 225 { 226 switch (eDerivedStructuralFeatureID(eFeature)) 227 { 228 case EcorePackage.EPACKAGE__EANNOTATIONS: 229 return eAnnotations != null && !eAnnotations.isEmpty(); 230 case EcorePackage.EPACKAGE__NAME: 231 return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name); 232 case EcorePackage.EPACKAGE__NS_URI: 233 return NS_URI_EDEFAULT == null ? nsURI != null : !NS_URI_EDEFAULT.equals(nsURI); 234 case EcorePackage.EPACKAGE__NS_PREFIX: 235 return NS_PREFIX_EDEFAULT == null ? nsPrefix != null : !NS_PREFIX_EDEFAULT.equals(nsPrefix); 236 case EcorePackage.EPACKAGE__EFACTORY_INSTANCE: 237 return eFactoryInstance != null; 238 case EcorePackage.EPACKAGE__ECLASSIFIERS: 239 return eClassifiers != null && !eClassifiers.isEmpty(); 240 case EcorePackage.EPACKAGE__ESUBPACKAGES: 241 return eSubpackages != null && !eSubpackages.isEmpty(); 242 case EcorePackage.EPACKAGE__ESUPER_PACKAGE: 243 return getESuperPackage() != null; 244 } 245 return eDynamicIsSet(eFeature); 246 } 247 248 253 public void eSet(EStructuralFeature eFeature, Object newValue) 254 { 255 switch (eDerivedStructuralFeatureID(eFeature)) 256 { 257 case EcorePackage.EPACKAGE__EANNOTATIONS: 258 getEAnnotations().clear(); 259 getEAnnotations().addAll((Collection )newValue); 260 return; 261 case EcorePackage.EPACKAGE__NAME: 262 setName((String )newValue); 263 return; 264 case EcorePackage.EPACKAGE__NS_URI: 265 setNsURI((String )newValue); 266 return; 267 case EcorePackage.EPACKAGE__NS_PREFIX: 268 setNsPrefix((String )newValue); 269 return; 270 case EcorePackage.EPACKAGE__EFACTORY_INSTANCE: 271 setEFactoryInstance((EFactory)newValue); 272 return; 273 case EcorePackage.EPACKAGE__ECLASSIFIERS: 274 getEClassifiers().clear(); 275 getEClassifiers().addAll((Collection )newValue); 276 return; 277 case EcorePackage.EPACKAGE__ESUBPACKAGES: 278 getESubpackages().clear(); 279 getESubpackages().addAll((Collection )newValue); 280 return; 281 } 282 eDynamicSet(eFeature, newValue); 283 } 284 285 290 public void eUnset(EStructuralFeature eFeature) 291 { 292 switch (eDerivedStructuralFeatureID(eFeature)) 293 { 294 case EcorePackage.EPACKAGE__EANNOTATIONS: 295 getEAnnotations().clear(); 296 return; 297 case EcorePackage.EPACKAGE__NAME: 298 setName(NAME_EDEFAULT); 299 return; 300 case EcorePackage.EPACKAGE__NS_URI: 301 setNsURI(NS_URI_EDEFAULT); 302 return; 303 case EcorePackage.EPACKAGE__NS_PREFIX: 304 setNsPrefix(NS_PREFIX_EDEFAULT); 305 return; 306 case EcorePackage.EPACKAGE__EFACTORY_INSTANCE: 307 setEFactoryInstance((EFactory)null); 308 return; 309 case EcorePackage.EPACKAGE__ECLASSIFIERS: 310 getEClassifiers().clear(); 311 return; 312 case EcorePackage.EPACKAGE__ESUBPACKAGES: 313 getESubpackages().clear(); 314 return; 315 } 316 eDynamicUnset(eFeature); 317 } 318 319 327 protected String nsURI = NS_URI_EDEFAULT; 328 329 337 protected static final String NS_PREFIX_EDEFAULT = null; 338 339 347 protected String nsPrefix = NS_PREFIX_EDEFAULT; 348 349 357 protected EFactory eFactoryInstance = null; 358 359 367 protected EList eClassifiers = null; 368 369 377 protected EList eSubpackages = null; 378 379 384 public String getNsURI() 385 { 386 return nsURI; 387 } 388 389 394 public void setNsURI(String newNsURI) 395 { 396 String oldNsURI = nsURI; 397 nsURI = newNsURI; 398 if (eNotificationRequired()) 399 eNotify(new ENotificationImpl(this, Notification.SET, EcorePackage.EPACKAGE__NS_URI, oldNsURI, nsURI)); 400 } 401 402 407 public String getNsPrefix() 408 { 409 return nsPrefix; 410 } 411 412 417 public void setNsPrefix(String newNsPrefix) 418 { 419 String oldNsPrefix = nsPrefix; 420 nsPrefix = newNsPrefix; 421 if (eNotificationRequired()) 422 eNotify(new ENotificationImpl(this, Notification.SET, EcorePackage.EPACKAGE__NS_PREFIX, oldNsPrefix, nsPrefix)); 423 } 424 425 430 public EFactory getEFactoryInstance() 431 { 432 return eFactoryInstance; 433 } 434 435 440 public void setEFactoryInstance(EFactory newEFactoryInstance) 441 { 442 if (newEFactoryInstance != eFactoryInstance) 443 { 444 NotificationChain msgs = null; 445 if (eFactoryInstance != null) 446 msgs = ((InternalEObject)eFactoryInstance).eInverseRemove(this, EcorePackage.EFACTORY__EPACKAGE, EFactory.class, msgs); 447 if (newEFactoryInstance != null) 448 msgs = ((InternalEObject)newEFactoryInstance).eInverseAdd(this, EcorePackage.EFACTORY__EPACKAGE, EFactory.class, msgs); 449 msgs = basicSetEFactoryInstance(newEFactoryInstance, msgs); 450 if (msgs != null) msgs.dispatch(); 451 } 452 else if (eNotificationRequired()) 453 eNotify(new ENotificationImpl(this, Notification.SET, EcorePackage.EPACKAGE__EFACTORY_INSTANCE, newEFactoryInstance, newEFactoryInstance)); 454 } 455 456 461 public NotificationChain basicSetEFactoryInstance(EFactory newEFactoryInstance, NotificationChain msgs) 462 { 463 EFactory oldEFactoryInstance = eFactoryInstance; 464 eFactoryInstance = newEFactoryInstance; 465 if (eNotificationRequired()) 466 { 467 ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, EcorePackage.EPACKAGE__EFACTORY_INSTANCE, oldEFactoryInstance, newEFactoryInstance); 468 if (msgs == null) msgs = notification; else msgs.add(notification); 469 } 470 return msgs; 471 } 472 473 478 public EList getEClassifiers() 479 { 480 if (eClassifiers == null) 481 { 482 eClassifiers = 483 new EObjectContainmentWithInverseEList(EClassifier.class, this, EcorePackage.EPACKAGE__ECLASSIFIERS, EcorePackage.ECLASSIFIER__EPACKAGE) 484 { 485 protected void didChange() 486 { 487 eNameToEClassifierMap = null; 488 } 489 }; 490 } 491 return eClassifiers; 492 } 493 494 497 public EClassifier getEClassifier(String name) 498 { 499 if (eNameToEClassifierMap == null) 500 { 501 List eClassifiers = getEClassifiers(); 502 Map result = new HashMap (eClassifiers.size()); 503 for (Iterator i = eClassifiers.iterator(); i.hasNext(); ) 504 { 505 EClassifier eClassifier = (EClassifier)i.next(); 506 result.put(eClassifier.getName(), eClassifier); 507 } 508 eNameToEClassifierMap = result; 509 } 510 511 return (EClassifier)eNameToEClassifierMap.get(name); 512 } 513 514 519 public EList getESubpackages() 520 { 521 if (eSubpackages == null) 522 { 523 eSubpackages = new EObjectContainmentWithInverseEList(EPackage.class, this, EcorePackage.EPACKAGE__ESUBPACKAGES, EcorePackage.EPACKAGE__ESUPER_PACKAGE); 524 } 525 return eSubpackages; 526 } 527 528 533 public EPackage getESuperPackage() 534 { 535 return (eContainerFeatureID == EcorePackage.EPACKAGE__ESUPER_PACKAGE) ? (EPackage)eContainer : null; 536 } 537 538 539 544 public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, Class baseClass, NotificationChain msgs) 545 { 546 if (featureID >= 0) 547 { 548 switch (eDerivedStructuralFeatureID(featureID, baseClass)) 549 { 550 case EcorePackage.EPACKAGE__EANNOTATIONS: 551 return ((InternalEList)getEAnnotations()).basicAdd(otherEnd, msgs); 552 case EcorePackage.EPACKAGE__EFACTORY_INSTANCE: 553 if (eFactoryInstance != null) 554 msgs = ((InternalEObject)eFactoryInstance).eInverseRemove(this, EcorePackage.EFACTORY__EPACKAGE, EFactory.class, msgs); 555 return basicSetEFactoryInstance((EFactory)otherEnd, msgs); 556 case EcorePackage.EPACKAGE__ECLASSIFIERS: 557 return ((InternalEList)getEClassifiers()).basicAdd(otherEnd, msgs); 558 case EcorePackage.EPACKAGE__ESUBPACKAGES: 559 return ((InternalEList)getESubpackages()).basicAdd(otherEnd, msgs); 560 case EcorePackage.EPACKAGE__ESUPER_PACKAGE: 561 if (eContainer != null) 562 msgs = eBasicRemoveFromContainer(msgs); 563 return eBasicSetContainer(otherEnd, EcorePackage.EPACKAGE__ESUPER_PACKAGE, msgs); 564 default: 565 return eDynamicInverseAdd(otherEnd, featureID, baseClass, msgs); 566 } 567 } 568 if (eContainer != null) 569 msgs = eBasicRemoveFromContainer(msgs); 570 return eBasicSetContainer(otherEnd, featureID, msgs); 571 } 572 573 578 public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class baseClass, NotificationChain msgs) 579 { 580 if (featureID >= 0) 581 { 582 switch (eDerivedStructuralFeatureID(featureID, baseClass)) 583 { 584 case EcorePackage.EPACKAGE__EANNOTATIONS: 585 return ((InternalEList)getEAnnotations()).basicRemove(otherEnd, msgs); 586 case EcorePackage.EPACKAGE__EFACTORY_INSTANCE: 587 return basicSetEFactoryInstance(null, msgs); 588 case EcorePackage.EPACKAGE__ECLASSIFIERS: 589 return ((InternalEList)getEClassifiers()).basicRemove(otherEnd, msgs); 590 case EcorePackage.EPACKAGE__ESUBPACKAGES: 591 return ((InternalEList)getESubpackages()).basicRemove(otherEnd, msgs); 592 case EcorePackage.EPACKAGE__ESUPER_PACKAGE: 593 return eBasicSetContainer(null, EcorePackage.EPACKAGE__ESUPER_PACKAGE, msgs); 594 default: 595 return eDynamicInverseRemove(otherEnd, featureID, baseClass, msgs); 596 } 597 } 598 return eBasicSetContainer(null, featureID, msgs); 599 } 600 601 606 public NotificationChain eBasicRemoveFromContainer(NotificationChain msgs) 607 { 608 if (eContainerFeatureID >= 0) 609 { 610 switch (eContainerFeatureID) 611 { 612 case EcorePackage.EPACKAGE__ESUPER_PACKAGE: 613 return eContainer.eInverseRemove(this, EcorePackage.EPACKAGE__ESUBPACKAGES, EPackage.class, msgs); 614 default: 615 return eDynamicBasicRemoveFromContainer(msgs); 616 } 617 } 618 return eContainer.eInverseRemove(this, EOPPOSITE_FEATURE_BASE - eContainerFeatureID, null, msgs); 619 } 620 621 626 public String toString() 627 { 628 if (eIsProxy()) return super.toString(); 629 630 StringBuffer result = new StringBuffer (super.toString()); 631 result.append(" (nsURI: "); 632 result.append(nsURI); 633 result.append(", nsPrefix: "); 634 result.append(nsPrefix); 635 result.append(')'); 636 return result.toString(); 637 } 638 639 protected Resource createResource(String uri) 640 { 641 Resource resource = eResource(); 642 if (resource == null) 643 { 644 URI actualURI = URI.createURI(uri); 645 resource = new ResourceImpl(actualURI); 646 resource.getContents().add(this); 647 } 648 return resource; 649 } 650 651 protected EClass createEClass(int id) 652 { 653 EClassImpl c = (EClassImpl)ecoreFactory.createEClass(); 654 c.setClassifierID(id); 655 getEClassifiers().add(c); 656 return c; 657 } 658 659 protected EEnum createEEnum(int id) 660 { 661 EEnumImpl e = (EEnumImpl)ecoreFactory.createEEnum(); 662 e.setClassifierID(id); 663 getEClassifiers().add(e); 664 return e; 665 } 666 667 protected EDataType createEDataType(int id) 668 { 669 EDataTypeImpl d = (EDataTypeImpl)ecoreFactory.createEDataType(); 670 d.setClassifierID(id); 671 getEClassifiers().add(d); 672 return d; 673 } 674 675 protected void createEAttribute(EClass owner, int id) 676 { 677 EAttributeImpl a = (EAttributeImpl)ecoreFactory.createEAttribute(); 678 a.setFeatureID(id); 679 owner.getEStructuralFeatures().add(a); 680 } 681 682 protected void createEReference(EClass owner, int id) 683 { 684 EReferenceImpl r = (EReferenceImpl)ecoreFactory.createEReference(); 685 r.setFeatureID(id); 686 owner.getEStructuralFeatures().add(r); 687 } 688 689 final static protected boolean IS_ABSTRACT = true; 690 final static protected boolean IS_INTERFACE = true; 691 final static protected boolean IS_GENERATED_INSTANCE_CLASS = true; 692 693 protected EClass initEClass(EClass c, Class instanceClass, String name, boolean isAbstract, boolean isInterface) 694 { 695 initEClassifier(c, ecorePackage.getEClass(), instanceClass, name); 696 c.setAbstract(isAbstract); 697 c.setInterface(isInterface); 698 return c; 699 } 700 701 protected EClass initEClass(EClass c, Class instanceClass, String name, boolean isAbstract, boolean isInterface, boolean isGenerated) 702 { 703 initEClassifier(c, ecorePackage.getEClass(), instanceClass, name, isGenerated); 704 c.setAbstract(isAbstract); 705 c.setInterface(isInterface); 706 return c; 707 } 708 709 protected EEnum initEEnum(EEnum e, Class instanceClass, String name) 710 { 711 initEClassifier(e, ecorePackage.getEEnum(), instanceClass, name, true); 712 return e; 713 } 714 715 final static protected boolean IS_SERIALIZABLE = true; 716 717 protected EDataType initEDataType(EDataType d, Class instanceClass, String name, boolean isSerializable) 718 { 719 initEClassifier(d, ecorePackage.getEDataType(), instanceClass, name, false); 720 d.setSerializable(isSerializable); 721 return d; 722 } 723 724 protected EDataType initEDataType(EDataType d, Class instanceClass, String name, boolean isSerializable, boolean isGenerated) 725 { 726 initEClassifier(d, ecorePackage.getEDataType(), instanceClass, name, isGenerated); 727 d.setSerializable(isSerializable); 728 return d; 729 } 730 731 private void initEClassifier(EClassifier o, EClass metaObject, Class instanceClass, String name) 732 { 733 o.setName(name); 734 if (instanceClass != null) 735 { 736 o.setInstanceClass(instanceClass); 737 } 738 } 739 740 private void initEClassifier(EClassifier o, EClass metaObject, Class instanceClass, String name, boolean isGenerated) 741 { 742 o.setName(name); 743 if (instanceClass != null) 744 { 745 o.setInstanceClass(instanceClass); 746 } 747 if (isGenerated) 748 { 749 setGeneratedClassName(o); 750 } 751 } 752 753 protected void setGeneratedClassName(EClassifier eClassifier) 754 { 755 ((EClassifierImpl)eClassifier).setGeneratedInstanceClass(true); 756 } 757 758 protected static final boolean IS_DERIVED = true; 759 protected static final boolean IS_TRANSIENT = true; 760 protected static final boolean IS_VOLATILE = true; 761 protected static final boolean IS_CHANGEABLE = true; 762 protected static final boolean IS_UNSETTABLE = true; 763 protected static final boolean IS_UNIQUE = true; 764 protected static final boolean IS_ID = true; 765 protected static final boolean IS_ORDERED = true; 766 767 770 protected EAttribute initEAttribute 771 (EAttribute a, 772 EClassifier type, 773 String name, 774 String defaultValue, 775 int lowerBound, 776 int upperBound, 777 boolean isTransient, 778 boolean isVolatile, 779 boolean isChangeable, 780 boolean isUnsettable) 781 { 782 return 783 initEAttribute 784 (a, type, name, defaultValue, lowerBound, upperBound, isTransient, isVolatile, isChangeable, isUnsettable, false, true); 785 } 786 787 790 protected EAttribute initEAttribute 791 (EAttribute a, 792 EClassifier type, 793 String name, 794 String defaultValue, 795 int lowerBound, 796 int upperBound, 797 boolean isTransient, 798 boolean isVolatile, 799 boolean isChangeable, 800 boolean isUnsettable, 801 boolean isID) 802 { 803 return 804 initEAttribute 805 (a, type, name, defaultValue, lowerBound, upperBound, isTransient, isVolatile, isChangeable, isUnsettable, isID, true); 806 } 807 808 811 protected EAttribute initEAttribute 812 (EAttribute a, 813 EClassifier type, 814 String name, 815 String defaultValue, 816 int lowerBound, 817 int upperBound, 818 boolean isTransient, 819 boolean isVolatile, 820 boolean isChangeable, 821 boolean isUnsettable, 822 boolean isID, 823 boolean isUnique) 824 { 825 return 826 initEAttribute 827 (a, type, name, defaultValue, lowerBound, upperBound, isTransient, isVolatile, isChangeable, isUnsettable, isID, isUnique, false); 828 } 829 830 protected EAttribute initEAttribute 831 (EAttribute a, 832 EClassifier type, 833 String name, 834 String defaultValue, 835 int lowerBound, 836 int upperBound, 837 boolean isTransient, 838 boolean isVolatile, 839 boolean isChangeable, 840 boolean isUnsettable, 841 boolean isID, 842 boolean isUnique, 843 boolean isDerived) 844 { 845 return 846 initEAttribute 847 (a, 848 type, 849 name, 850 defaultValue, 851 lowerBound, 852 upperBound, 853 isTransient, 854 isVolatile, 855 isChangeable, 856 isUnsettable, 857 isID, 858 isUnique, 859 isDerived, 860 true); 861 } 862 863 protected EAttribute initEAttribute 864 (EAttribute a, 865 EClassifier type, 866 String name, 867 String defaultValue, 868 int lowerBound, 869 int upperBound, 870 boolean isTransient, 871 boolean isVolatile, 872 boolean isChangeable, 873 boolean isUnsettable, 874 boolean isID, 875 boolean isUnique, 876 boolean isDerived, 877 boolean isOrdered) 878 { 879 initEAttribute 880 (a, 881 type, 882 name, 883 defaultValue, 884 lowerBound, 885 upperBound, 886 ((EClassifier)a.eContainer()).getInstanceClass(), 887 isTransient, 888 isVolatile, 889 isChangeable, 890 isUnsettable, 891 isID, 892 isUnique, 893 isDerived, 894 isOrdered); 895 return a; 896 } 897 898 protected EAttribute initEAttribute 899 (EAttribute a, 900 EClassifier type, 901 String name, 902 String defaultValue, 903 int lowerBound, 904 int upperBound, 905 Class containerClass, 906 boolean isTransient, 907 boolean isVolatile, 908 boolean isChangeable, 909 boolean isUnsettable, 910 boolean isID, 911 boolean isUnique, 912 boolean isDerived, 913 boolean isOrdered) 914 { 915 initEStructuralFeature 916 (a, 917 type, 918 name, 919 defaultValue, 920 lowerBound, 921 upperBound, 922 containerClass, 923 isTransient, 924 isVolatile, 925 isChangeable, 926 isUnsettable, 927 isUnique, 928 isDerived, 929 isOrdered); 930 a.setID(isID); 931 return a; 932 } 933 934 final static protected boolean IS_COMPOSITE = true; 935 final static protected boolean IS_RESOLVE_PROXIES = true; 936 final static protected boolean IS_RESOLVABLE = true; 937 938 941 protected EReference initEReference 942 (EReference r, 943 EClassifier type, 944 EReference otherEnd, 945 String name, 946 String defaultValue, 947 int lowerBound, 948 int upperBound, 949 boolean isTransient, 950 boolean isVolatile, 951 boolean isChangeable, 952 boolean isContainment, 953 boolean isResolveProxies) 954 { 955 initEReference 956 (r, 957 type, 958 otherEnd, 959 name, 960 defaultValue, 961 lowerBound, 962 upperBound, 963 isTransient, 964 isVolatile, 965 isChangeable, 966 isContainment, 967 isResolveProxies, 968 false, 969 true); 970 return r; 971 } 972 973 976 protected EReference initEReference 977 (EReference r, 978 EClassifier type, 979 EReference otherEnd, 980 String name, 981 String defaultValue, 982 int lowerBound, 983 int upperBound, 984 boolean isTransient, 985 boolean isVolatile, 986 boolean isChangeable, 987 boolean isContainment, 988 boolean isResolveProxies, 989 boolean isUnsettable) 990 { 991 initEReference 992 (r, 993 type, 994 otherEnd, 995 name, 996 defaultValue, 997 lowerBound, 998 upperBound, 999 isTransient, 1000 isVolatile, 1001 isChangeable, 1002 isContainment, 1003 isResolveProxies, 1004 isUnsettable, 1005 true); 1006 return r; 1007 } 1008 1009 1012 protected EReference initEReference 1013 (EReference r, 1014 EClassifier type, 1015 EReference otherEnd, 1016 String name, 1017 String defaultValue, 1018 int lowerBound, 1019 int upperBound, 1020 boolean isTransient, 1021 boolean isVolatile, 1022 boolean isChangeable, 1023 boolean isContainment, 1024 boolean isResolveProxies, 1025 boolean isUnsettable, 1026 boolean isUnique) 1027 { 1028 initEReference 1029 (r, 1030 type, 1031 otherEnd, 1032 name, 1033 defaultValue, 1034 lowerBound, 1035 upperBound, 1036 isTransient, 1037 isVolatile, 1038 isChangeable, 1039 isContainment, 1040 isResolveProxies, 1041 isUnsettable, 1042 isUnique, 1043 false); 1044 return r; 1045 } 1046 1047 protected EReference initEReference 1048 (EReference r, 1049 EClassifier type, 1050 EReference otherEnd, 1051 String name, 1052 String defaultValue, 1053 int lowerBound, 1054 int upperBound, 1055 boolean isTransient, 1056 boolean isVolatile, 1057 boolean isChangeable, 1058 boolean isContainment, 1059 boolean isResolveProxies, 1060 boolean isUnsettable, 1061 boolean isUnique, 1062 boolean isDerived) 1063 { 1064 initEReference 1065 (r, 1066 type, 1067 otherEnd, 1068 name, 1069 defaultValue, 1070 lowerBound, 1071 upperBound, 1072 isTransient, 1073 isVolatile, 1074 isChangeable, 1075 isContainment, 1076 isResolveProxies, 1077 isUnsettable, 1078 isUnique, 1079 isDerived, 1080 true); 1081 return r; 1082 } 1083 1084 protected EReference initEReference 1085 (EReference r, 1086 EClassifier type, 1087 EReference otherEnd, 1088 String name, 1089 String defaultValue, 1090 int lowerBound, 1091 int upperBound, 1092 boolean isTransient, 1093 boolean isVolatile, 1094 boolean isChangeable, 1095 boolean isContainment, 1096 boolean isResolveProxies, 1097 boolean isUnsettable, 1098 boolean isUnique, 1099 boolean isDerived, 1100 boolean isOrdered) 1101 { 1102 initEReference 1103 (r, 1104 type, 1105 otherEnd, 1106 name, 1107 defaultValue, 1108 lowerBound, 1109 upperBound, 1110 ((EClassifier)r.eContainer()).getInstanceClass(), 1111 isTransient, 1112 isVolatile, 1113 isChangeable, 1114 isContainment, 1115 isResolveProxies, 1116 isUnsettable, 1117 isUnique, 1118 isDerived, 1119 isOrdered); 1120 return r; 1121 } 1122 1123 protected EReference initEReference 1124 (EReference r, 1125 EClassifier type, 1126 EReference otherEnd, 1127 String name, 1128 String defaultValue, 1129 int lowerBound, 1130 int upperBound, 1131 Class containerClass, 1132 boolean isTransient, 1133 boolean isVolatile, 1134 boolean isChangeable, 1135 boolean isContainment, 1136 boolean isResolveProxies, 1137 boolean isUnsettable, 1138 boolean isUnique, 1139 boolean isDerived, 1140 boolean isOrdered) 1141 { 1142 initEStructuralFeature 1143 (r, 1144 type, 1145 name, 1146 defaultValue, 1147 lowerBound, 1148 upperBound, 1149 containerClass, 1150 isTransient, 1151 isVolatile, 1152 isChangeable, 1153 isUnsettable, 1154 isUnique, 1155 isDerived, 1156 isOrdered); 1157 r.setContainment(isContainment); 1158 if (otherEnd != null) 1159 { 1160 r.setEOpposite(otherEnd); 1161 } 1162 r.setResolveProxies(isResolveProxies); 1163 return r; 1164 } 1165 1166 private void initEStructuralFeature 1167 (EStructuralFeature s, 1168 EClassifier type, 1169 String name, 1170 String defaultValue, 1171 int lowerBound, 1172 int upperBound, 1173 Class containerClass, 1174 boolean isTransient, 1175 boolean isVolatile, 1176 boolean isChangeable, 1177 boolean isUnsettable, 1178 boolean isUnique, 1179 boolean isDerived, 1180 boolean isOrdered) 1181 { 1182 s.setName(name); 1183 ((EStructuralFeatureImpl)s).setContainerClass(containerClass); 1184 s.setTransient(isTransient); 1185 s.setVolatile(isVolatile); 1186 s.setChangeable(isChangeable); 1187 s.setUnsettable(isUnsettable); 1188 s.setUnique(isUnique); 1189 s.setDerived(isDerived); 1190 s.setOrdered(isOrdered); 1191 s.setLowerBound(lowerBound); 1192 s.setUpperBound(upperBound); 1193 s.setEType(type); 1194 if (defaultValue != null) 1195 { 1196 s.setDefaultValueLiteral(defaultValue); 1197 } 1198 } 1199 1200 protected EOperation addEOperation(EClass owner, EClassifier type, String name) 1201 { 1202 EOperation o = ecoreFactory.createEOperation(); 1203 o.setEType(type); 1204 o.setName(name); 1205 owner.getEOperations().add(o); 1206 return o; 1207 } 1208 1209 protected void addEParameter(EOperation owner, EClassifier type, String name) 1210 { 1211 EParameter p = ecoreFactory.createEParameter(); 1212 p.setEType(type); 1213 p.setName(name); 1214 owner.getEParameters().add(p); 1215 } 1216 1217 protected void addEException(EOperation owner, EClassifier exception) 1218 { 1219 owner.getEExceptions().add(exception); 1220 } 1221 1222 protected void addEEnumLiteral(EEnum owner, Enumerator e) 1223 { 1224 EEnumLiteral l = ecoreFactory.createEEnumLiteral(); 1225 l.setInstance(e); 1226 owner.getELiterals().add(l); 1227 } 1228 1229 protected void addAnnotation(ENamedElement eNamedElement, String source, String [] details) 1230 { 1231 EAnnotation eAnnotation = ecoreFactory.createEAnnotation(); 1232 eAnnotation.setSource(source); 1233 EMap theDetails = eAnnotation.getDetails(); 1234 for (int i = 1; i < details.length; i += 2) 1235 { 1236 theDetails.put(details[i - 1], details[i]); 1237 } 1238 eNamedElement.getEAnnotations().add(eAnnotation); 1239 } 1240 1241 protected void initializeFromLoadedEPackage(EPackage target, EPackage source) 1242 { 1243 target.setName(source.getName()); 1244 target.setNsPrefix(source.getNsPrefix()); 1245 target.setNsURI(source.getNsURI()); 1246 1247 target.getEClassifiers().addAll(source.getEClassifiers()); 1248 target.getEAnnotations().addAll(source.getEAnnotations()); 1249 1250 for (Iterator i = source.getESubpackages().iterator(); i.hasNext(); ) 1251 { 1252 EPackage sourceSubpackage = (EPackage)i.next(); 1253 EPackage targetSubpackage = EPackage.Registry.INSTANCE.getEPackage(sourceSubpackage.getNsURI()); 1254 initializeFromLoadedEPackage(targetSubpackage, sourceSubpackage); 1255 target.getESubpackages().add(targetSubpackage); 1256 } 1257 } 1258 1259 protected void fixEClassifiers() 1260 { 1261 int id = 0; 1262 1263 for (Iterator i = getEClassifiers().iterator(); i.hasNext(); ) 1264 { 1265 EClassifierImpl eClassifier = (EClassifierImpl)i.next(); 1266 if (eClassifier instanceof EClass) 1267 { 1268 eClassifier.setClassifierID(id++); 1269 fixInstanceClass(eClassifier); 1270 fixEStructuralFeatures((EClass)eClassifier); 1271 } 1272 } 1273 1274 for (Iterator i = getEClassifiers().iterator(); i.hasNext(); ) 1275 { 1276 EClassifierImpl eClassifier = (EClassifierImpl)i.next(); 1277 if (eClassifier.getClassifierID() == -1 && eClassifier instanceof EEnum) 1278 { 1279 eClassifier.setClassifierID(id++); 1280 fixInstanceClass(eClassifier); 1281 fixEEnumLiterals((EEnum)eClassifier); 1282 } 1283 } 1284 1285 for (Iterator i = getEClassifiers().iterator(); i.hasNext(); ) 1286 { 1287 EClassifierImpl eClassifier = (EClassifierImpl)i.next(); 1288 if (eClassifier.getClassifierID() == -1 && eClassifier instanceof EDataType) 1289 { 1290 eClassifier.setClassifierID(id++); 1291 if (eClassifier.getInstanceClassName() == "org.eclipse.emf.common.util.AbstractEnumerator") 1292 { 1293 EDataType baseType = ExtendedMetaData.INSTANCE.getBaseType((EDataType)eClassifier); 1294 if (baseType instanceof EEnum) 1295 { 1296 eClassifier.setInstanceClass(baseType.getInstanceClass()); 1297 setGeneratedClassName(eClassifier); 1298 } 1299 } 1300 } 1301 } 1302 } 1303 1304 protected void fixInstanceClass(EClassifier eClassifier) 1305 { 1306 if (eClassifier.getInstanceClassName() == null) 1307 { 1308 String className = getClass().getName(); 1309 int i = className.lastIndexOf('.', className.lastIndexOf('.') - 1); 1310 className = i == -1 ? eClassifier.getName() : className.substring(0, i + 1) + eClassifier.getName(); 1311 eClassifier.setInstanceClassName(className); 1312 setGeneratedClassName(eClassifier); 1313 } 1314 } 1315 1316 protected void fixEStructuralFeatures(EClass eClass) 1317 { 1318 List features = eClass.getEStructuralFeatures(); 1319 if (!features.isEmpty()) 1320 { 1321 Class containerClass = ExtendedMetaData.INSTANCE.getDocumentRoot(this) == eClass ? null : eClass.getInstanceClass(); 1327 1328 int id = eClass.getFeatureID((EStructuralFeature)features.get(0)); 1329 1330 for (Iterator i = features.iterator(); i.hasNext(); ) 1331 { 1332 EStructuralFeatureImpl eStructuralFeature = (EStructuralFeatureImpl)i.next(); 1333 eStructuralFeature.setFeatureID(id++); 1334 eStructuralFeature.setContainerClass(containerClass); 1335 } 1336 } 1337 } 1338 1339 protected void fixEEnumLiterals(EEnum eEnum) 1340 { 1341 Class enumClass = eEnum.getInstanceClass(); 1342 1343 try 1344 { 1345 Method getter = enumClass.getMethod("get", new Class [] { Integer.TYPE }); 1346 1347 for (Iterator i = eEnum.getELiterals().iterator(); i.hasNext(); ) 1348 { 1349 EEnumLiteral eEnumLiteral = (EEnumLiteral)i.next(); 1350 Enumerator instance = (Enumerator)getter.invoke(null, new Object [] { new Integer (eEnumLiteral.getValue()) }); 1351 eEnumLiteral.setInstance(instance); 1352 } 1353 } 1354 catch (Exception e) 1355 { 1356 } 1358 } 1359 1360 protected BasicExtendedMetaData.EPackageExtendedMetaData ePackageExtendedMetaData; 1361 1362 public BasicExtendedMetaData.EPackageExtendedMetaData getExtendedMetaData() 1363 { 1364 return ePackageExtendedMetaData; 1365 } 1366 1367 public void setExtendedMetaData(BasicExtendedMetaData.EPackageExtendedMetaData ePackageExtendedMetaData) 1368 { 1369 this.ePackageExtendedMetaData = ePackageExtendedMetaData; 1370 } 1371} 1372 | Popular Tags |