| 1 17 package org.eclipse.emf.codegen.ecore.genmodel.impl; 18 19 20 import java.io.IOException ; 21 import java.lang.reflect.InvocationTargetException ; 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 import java.util.Collections ; 25 import java.util.HashMap ; 26 import java.util.HashSet ; 27 import java.util.Iterator ; 28 import java.util.LinkedList ; 29 import java.util.List ; 30 import java.util.Map ; 31 import java.util.Set ; 32 33 import org.osgi.framework.Bundle; 34 35 import org.eclipse.core.runtime.IPath; 36 import org.eclipse.core.runtime.IProgressMonitor; 37 import org.eclipse.core.runtime.NullProgressMonitor; 38 import org.eclipse.core.runtime.Path; 39 import org.eclipse.core.runtime.Platform; 40 import org.eclipse.core.runtime.SubProgressMonitor; 41 42 import org.eclipse.emf.codegen.ecore.CodeGenEcorePlugin; 43 import org.eclipse.emf.codegen.ecore.Generator; 44 import org.eclipse.emf.codegen.ecore.genmodel.GenBase; 45 import org.eclipse.emf.codegen.ecore.genmodel.GenClass; 46 import org.eclipse.emf.codegen.ecore.genmodel.GenClassifier; 47 import org.eclipse.emf.codegen.ecore.genmodel.GenDataType; 48 import org.eclipse.emf.codegen.ecore.genmodel.GenEnum; 49 import org.eclipse.emf.codegen.ecore.genmodel.GenFeature; 50 import org.eclipse.emf.codegen.ecore.genmodel.GenModel; 51 import org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage; 52 import org.eclipse.emf.codegen.ecore.genmodel.GenOperation; 53 import org.eclipse.emf.codegen.ecore.genmodel.GenPackage; 54 import org.eclipse.emf.codegen.ecore.genmodel.GenParameter; 55 import org.eclipse.emf.codegen.ecore.genmodel.GenProviderKind; 56 import org.eclipse.emf.codegen.ecore.genmodel.GenResourceKind; 57 import org.eclipse.emf.codegen.util.CodeGenUtil; 58 import org.eclipse.emf.common.notify.Notification; 59 import org.eclipse.emf.common.notify.NotificationChain; 60 import org.eclipse.emf.common.util.BasicEList; 61 import org.eclipse.emf.common.util.EList; 62 import org.eclipse.emf.common.util.TreeIterator; 63 import org.eclipse.emf.common.util.URI; 64 import org.eclipse.emf.common.util.UniqueEList; 65 import org.eclipse.emf.ecore.EAnnotation; 66 import org.eclipse.emf.ecore.EClass; 67 import org.eclipse.emf.ecore.EClassifier; 68 import org.eclipse.emf.ecore.EDataType; 69 import org.eclipse.emf.ecore.EEnum; 70 import org.eclipse.emf.ecore.EEnumLiteral; 71 import org.eclipse.emf.ecore.EModelElement; 72 import org.eclipse.emf.ecore.EObject; 73 import org.eclipse.emf.ecore.EOperation; 74 import org.eclipse.emf.ecore.EPackage; 75 import org.eclipse.emf.ecore.EParameter; 76 import org.eclipse.emf.ecore.EReference; 77 import org.eclipse.emf.ecore.EStructuralFeature; 78 import org.eclipse.emf.ecore.EcorePackage; 79 import org.eclipse.emf.ecore.InternalEObject; 80 import org.eclipse.emf.ecore.impl.ENotificationImpl; 81 import org.eclipse.emf.ecore.plugin.EcorePlugin; 82 import org.eclipse.emf.ecore.resource.Resource; 83 import org.eclipse.emf.ecore.resource.ResourceSet; 84 import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; 85 import org.eclipse.emf.ecore.util.EObjectContainmentEList; 86 import org.eclipse.emf.ecore.util.EcoreSwitch; 87 import org.eclipse.emf.ecore.util.EcoreUtil; 88 import org.eclipse.emf.ecore.util.ExtendedMetaData; 89 import org.eclipse.emf.ecore.util.InternalEList; 90 91 92 124 public class GenPackageImpl extends GenBaseImpl implements GenPackage 125 { 126 protected static final String XSD2ECORE_URI = "http:///org/eclipse/emf/mapping/xsd2ecore/XSD2Ecore"; 127 128 136 protected static final String PREFIX_EDEFAULT = null; 137 138 146 protected String prefix = PREFIX_EDEFAULT; 147 148 156 protected static final String BASE_PACKAGE_EDEFAULT = null; 157 158 166 protected String basePackage = BASE_PACKAGE_EDEFAULT; 167 168 176 protected static final GenResourceKind RESOURCE_EDEFAULT = GenResourceKind.NONE_LITERAL; 177 178 186 protected GenResourceKind resource = RESOURCE_EDEFAULT; 187 188 196 protected static final boolean DISPOSABLE_PROVIDER_FACTORY_EDEFAULT = false; 197 198 206 protected boolean disposableProviderFactory = DISPOSABLE_PROVIDER_FACTORY_EDEFAULT; 207 208 216 protected static final boolean ADAPTER_FACTORY_EDEFAULT = true; 217 218 226 protected boolean adapterFactory = ADAPTER_FACTORY_EDEFAULT; 227 228 236 protected static final boolean LOAD_INITIALIZATION_EDEFAULT = false; 237 238 246 protected boolean loadInitialization = LOAD_INITIALIZATION_EDEFAULT; 247 248 256 protected static final String INTERFACE_PACKAGE_SUFFIX_EDEFAULT = ""; 257 258 266 protected String interfacePackageSuffix = INTERFACE_PACKAGE_SUFFIX_EDEFAULT; 267 268 276 protected static final String CLASS_PACKAGE_SUFFIX_EDEFAULT = "impl"; 277 278 286 protected String classPackageSuffix = CLASS_PACKAGE_SUFFIX_EDEFAULT; 287 288 296 protected static final String UTILITY_PACKAGE_SUFFIX_EDEFAULT = "util"; 297 298 306 protected String utilityPackageSuffix = UTILITY_PACKAGE_SUFFIX_EDEFAULT; 307 308 316 protected static final String PROVIDER_PACKAGE_SUFFIX_EDEFAULT = "provider"; 317 318 326 protected String providerPackageSuffix = PROVIDER_PACKAGE_SUFFIX_EDEFAULT; 327 328 336 protected static final String PRESENTATION_PACKAGE_SUFFIX_EDEFAULT = "presentation"; 337 338 346 protected String presentationPackageSuffix = PRESENTATION_PACKAGE_SUFFIX_EDEFAULT; 347 348 356 protected static final String TESTS_PACKAGE_SUFFIX_EDEFAULT = "tests"; 357 358 366 protected String testsPackageSuffix = TESTS_PACKAGE_SUFFIX_EDEFAULT; 367 368 376 protected static final boolean GENERATE_EXAMPLE_CLASS_EDEFAULT = true; 377 378 386 protected boolean generateExampleClass = GENERATE_EXAMPLE_CLASS_EDEFAULT; 387 388 396 protected EPackage ecorePackage = null; 397 398 406 protected EList genEnums = null; 407 408 416 protected EList genDataTypes = null; 417 418 426 protected EList genClasses = null; 427 428 436 protected EList nestedGenPackages = null; 437 438 443 protected GenPackageImpl() 444 { 445 super(); 446 } 447 448 453 protected EClass eStaticClass() 454 { 455 return GenModelPackage.eINSTANCE.getGenPackage(); 456 } 457 458 463 public String getPrefixGen() 464 { 465 return prefix; 466 } 467 468 public String getPrefix() 469 { 470 if (getPrefixGen() != null) 471 { 472 return getPrefixGen(); 473 } 474 return ""; 475 } 476 477 482 public void setPrefix(String newPrefix) 483 { 484 String oldPrefix = prefix; 485 prefix = newPrefix; 486 if (eNotificationRequired()) 487 eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_PACKAGE__PREFIX, oldPrefix, prefix)); 488 } 489 490 495 public String getBasePackageGen() 496 { 497 return basePackage; 498 } 499 500 public String getBasePackage() 501 { 502 String result = getBasePackageGen(); 505 if (isBlank(result)) 506 { 507 EObject container = eContainer(); 508 result = container instanceof GenPackage ? ((GenPackage)container).getQualifiedPackageName() : null; 509 } 510 return result; 511 } 512 513 518 public void setBasePackage(String newBasePackage) 519 { 520 String oldBasePackage = basePackage; 521 basePackage = newBasePackage; 522 if (eNotificationRequired()) 523 eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_PACKAGE__BASE_PACKAGE, oldBasePackage, basePackage)); 524 } 525 526 531 public GenResourceKind getResource() 532 { 533 return resource; 534 } 535 536 541 public void setResource(GenResourceKind newResource) 542 { 543 GenResourceKind oldResource = resource; 544 resource = newResource == null ? RESOURCE_EDEFAULT : newResource; 545 if (eNotificationRequired()) 546 eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_PACKAGE__RESOURCE, oldResource, resource)); 547 } 548 549 554 public boolean isDisposableProviderFactory() 555 { 556 return disposableProviderFactory; 557 } 558 559 564 public void setDisposableProviderFactory(boolean newDisposableProviderFactory) 565 { 566 boolean oldDisposableProviderFactory = disposableProviderFactory; 567 disposableProviderFactory = newDisposableProviderFactory; 568 if (eNotificationRequired()) 569 eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_PACKAGE__DISPOSABLE_PROVIDER_FACTORY, oldDisposableProviderFactory, disposableProviderFactory)); 570 } 571 572 577 public boolean isAdapterFactory() 578 { 579 return adapterFactory; 580 } 581 582 587 public void setAdapterFactory(boolean newAdapterFactory) 588 { 589 boolean oldAdapterFactory = adapterFactory; 590 adapterFactory = newAdapterFactory; 591 if (eNotificationRequired()) 592 eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_PACKAGE__ADAPTER_FACTORY, oldAdapterFactory, adapterFactory)); 593 } 594 595 600 public boolean isLoadInitialization() 601 { 602 return loadInitialization; 603 } 604 605 610 public void setLoadInitialization(boolean newLoadInitialization) 611 { 612 boolean oldLoadInitialization = loadInitialization; 613 loadInitialization = newLoadInitialization; 614 if (eNotificationRequired()) 615 eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_PACKAGE__LOAD_INITIALIZATION, oldLoadInitialization, loadInitialization)); 616 } 617 618 623 public String getInterfacePackageSuffix() 624 { 625 return interfacePackageSuffix; 626 } 627 628 633 public void setInterfacePackageSuffix(String newInterfacePackageSuffix) 634 { 635 String oldInterfacePackageSuffix = interfacePackageSuffix; 636 interfacePackageSuffix = newInterfacePackageSuffix; 637 if (eNotificationRequired()) 638 eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_PACKAGE__INTERFACE_PACKAGE_SUFFIX, oldInterfacePackageSuffix, interfacePackageSuffix)); 639 } 640 641 646 public String getClassPackageSuffix() 647 { 648 return classPackageSuffix; 649 } 650 651 656 public void setClassPackageSuffix(String newClassPackageSuffix) 657 { 658 String oldClassPackageSuffix = classPackageSuffix; 659 classPackageSuffix = newClassPackageSuffix; 660 if (eNotificationRequired()) 661 eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_PACKAGE__CLASS_PACKAGE_SUFFIX, oldClassPackageSuffix, classPackageSuffix)); 662 } 663 664 669 public String getUtilityPackageSuffix() 670 { 671 return utilityPackageSuffix; 672 } 673 674 679 public void setUtilityPackageSuffix(String newUtilityPackageSuffix) 680 { 681 String oldUtilityPackageSuffix = utilityPackageSuffix; 682 utilityPackageSuffix = newUtilityPackageSuffix; 683 if (eNotificationRequired()) 684 eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_PACKAGE__UTILITY_PACKAGE_SUFFIX, oldUtilityPackageSuffix, utilityPackageSuffix)); 685 } 686 687 692 public String getProviderPackageSuffix() 693 { 694 return providerPackageSuffix; 695 } 696 697 702 public void setProviderPackageSuffix(String newProviderPackageSuffix) 703 { 704 String oldProviderPackageSuffix = providerPackageSuffix; 705 providerPackageSuffix = newProviderPackageSuffix; 706 if (eNotificationRequired()) 707 eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_PACKAGE__PROVIDER_PACKAGE_SUFFIX, oldProviderPackageSuffix, providerPackageSuffix)); 708 } 709 710 715 public String getPresentationPackageSuffix() 716 { 717 return presentationPackageSuffix; 718 } 719 720 725 public void setPresentationPackageSuffix(String newPresentationPackageSuffix) 726 { 727 String oldPresentationPackageSuffix = presentationPackageSuffix; 728 presentationPackageSuffix = newPresentationPackageSuffix; 729 if (eNotificationRequired()) 730 eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_PACKAGE__PRESENTATION_PACKAGE_SUFFIX, oldPresentationPackageSuffix, presentationPackageSuffix)); 731 } 732 733 738 public String getTestsPackageSuffix() 739 { 740 return testsPackageSuffix; 741 } 742 743 748 public void setTestsPackageSuffix(String newTestsPackageSuffix) 749 { 750 String oldTestsPackageSuffix = testsPackageSuffix; 751 testsPackageSuffix = newTestsPackageSuffix; 752 if (eNotificationRequired()) 753 eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_PACKAGE__TESTS_PACKAGE_SUFFIX, oldTestsPackageSuffix, testsPackageSuffix)); 754 } 755 756 761 public boolean isGenerateExampleClass() 762 { 763 return generateExampleClass; 764 } 765 766 771 public void setGenerateExampleClass(boolean newGenerateExampleClass) 772 { 773 boolean oldGenerateExampleClass = generateExampleClass; 774 generateExampleClass = newGenerateExampleClass; 775 if (eNotificationRequired()) 776 eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_PACKAGE__GENERATE_EXAMPLE_CLASS, oldGenerateExampleClass, generateExampleClass)); 777 } 778 779 public EModelElement getEcoreModelElement() 780 { 781 return getEcorePackage(); 782 } 783 784 789 public EPackage getEcorePackage() 790 { 791 if (ecorePackage != null && ecorePackage.eIsProxy()) 792 { 793 EPackage oldEcorePackage = ecorePackage; 794 ecorePackage = (EPackage)eResolveProxy((InternalEObject)ecorePackage); 795 if (ecorePackage != oldEcorePackage) 796 { 797 if (eNotificationRequired()) 798 eNotify(new ENotificationImpl(this, Notification.RESOLVE, GenModelPackage.GEN_PACKAGE__ECORE_PACKAGE, oldEcorePackage, ecorePackage)); 799 } 800 } 801 return ecorePackage; 802 } 803 804 809 public EPackage basicGetEcorePackage() 810 { 811 return ecorePackage; 812 } 813 814 819 public void setEcorePackage(EPackage newEcorePackage) 820 { 821 EPackage oldEcorePackage = ecorePackage; 822 ecorePackage = newEcorePackage; 823 if (eNotificationRequired()) 824 eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_PACKAGE__ECORE_PACKAGE, oldEcorePackage, ecorePackage)); 825 } 826 827 public GenModel getGenModel() 828 { 829 GenModel result = getGenModelGen(); 830 if (result == null && eContainer() != null) 831 { 832 result = ((GenBase)eContainer()).getGenModel(); 833 } 834 835 return result; 836 } 837 838 843 public GenModel getGenModelGen() 844 { 845 if (eContainerFeatureID != GenModelPackage.GEN_PACKAGE__GEN_MODEL) return null; 846 return (GenModel)eContainer; 847 } 848 849 854 public void setGenModel(GenModel newGenModel) 855 { 856 if (newGenModel != eContainer || (eContainerFeatureID != GenModelPackage.GEN_PACKAGE__GEN_MODEL && newGenModel != null)) 857 { 858 if (EcoreUtil.isAncestor(this, newGenModel)) 859 throw new IllegalArgumentException ("Recursive containment not allowed for " + toString()); 860 NotificationChain msgs = null; 861 if (eContainer != null) 862 msgs = eBasicRemoveFromContainer(msgs); 863 if (newGenModel != null) 864 msgs = ((InternalEObject)newGenModel).eInverseAdd(this, GenModelPackage.GEN_MODEL__GEN_PACKAGES, GenModel.class, msgs); 865 msgs = eBasicSetContainer((InternalEObject)newGenModel, GenModelPackage.GEN_PACKAGE__GEN_MODEL, msgs); 866 if (msgs != null) msgs.dispatch(); 867 } 868 else if (eNotificationRequired()) 869 eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_PACKAGE__GEN_MODEL, newGenModel, newGenModel)); 870 } 871 872 877 public EList getGenEnums() 878 { 879 if (genEnums == null) 880 { 881 genEnums = new EObjectContainmentEList(GenEnum.class, this, GenModelPackage.GEN_PACKAGE__GEN_ENUMS); 882 } 883 return genEnums; 884 } 885 886 891 public EList getGenDataTypes() 892 { 893 if (genDataTypes == null) 894 { 895 genDataTypes = new EObjectContainmentEList(GenDataType.class, this, GenModelPackage.GEN_PACKAGE__GEN_DATA_TYPES); 896 } 897 return genDataTypes; 898 } 899 900 905 public EList getGenClasses() 906 { 907 if (genClasses == null) 908 { 909 genClasses = new EObjectContainmentEList(GenClass.class, this, GenModelPackage.GEN_PACKAGE__GEN_CLASSES); 910 } 911 return genClasses; 912 } 913 914 919 public EList getNestedGenPackages() 920 { 921 if (nestedGenPackages == null) 922 { 923 nestedGenPackages = new EObjectContainmentEList(GenPackage.class, this, GenModelPackage.GEN_PACKAGE__NESTED_GEN_PACKAGES); 924 } 925 return nestedGenPackages; 926 } 927 928 933 public EList getGenClassifiers() 934 { 935 EList result = new BasicEList(); 936 result.addAll(getGenClasses()); 937 result.addAll(getGenEnums()); 938 result.addAll(getGenDataTypes()); 939 return result; 940 } 941 942 947 public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, Class baseClass, NotificationChain msgs) 948 { 949 if (featureID >= 0) 950 { 951 switch (eDerivedStructuralFeatureID(featureID, baseClass)) 952 { 953 case GenModelPackage.GEN_PACKAGE__GEN_MODEL: 954 if (eContainer != null) 955 msgs = eBasicRemoveFromContainer(msgs); 956 return eBasicSetContainer(otherEnd, GenModelPackage.GEN_PACKAGE__GEN_MODEL, msgs); 957 default: 958 return eDynamicInverseAdd(otherEnd, featureID, baseClass, msgs); 959 } 960 } 961 if (eContainer != null) 962 msgs = eBasicRemoveFromContainer(msgs); 963 return eBasicSetContainer(otherEnd, featureID, msgs); 964 } 965 966 971 public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class baseClass, NotificationChain msgs) 972 { 973 if (featureID >= 0) 974 { 975 switch (eDerivedStructuralFeatureID(featureID, baseClass)) 976 { 977 case GenModelPackage.GEN_PACKAGE__GEN_MODEL: 978 return eBasicSetContainer(null, GenModelPackage.GEN_PACKAGE__GEN_MODEL, msgs); 979 case GenModelPackage.GEN_PACKAGE__GEN_ENUMS: 980 return ((InternalEList)getGenEnums()).basicRemove(otherEnd, msgs); 981 case GenModelPackage.GEN_PACKAGE__GEN_DATA_TYPES: 982 return ((InternalEList)getGenDataTypes()).basicRemove(otherEnd, msgs); 983 case GenModelPackage.GEN_PACKAGE__GEN_CLASSES: 984 return ((InternalEList)getGenClasses()).basicRemove(otherEnd, msgs); 985 case GenModelPackage.GEN_PACKAGE__NESTED_GEN_PACKAGES: 986 return ((InternalEList)getNestedGenPackages()).basicRemove(otherEnd, msgs); 987 default: 988 return eDynamicInverseRemove(otherEnd, featureID, baseClass, msgs); 989 } 990 } 991 return eBasicSetContainer(null, featureID, msgs); 992 } 993 994 999 public NotificationChain eBasicRemoveFromContainer(NotificationChain msgs) 1000 { 1001 if (eContainerFeatureID >= 0) 1002 { 1003 switch (eContainerFeatureID) 1004 { 1005 case GenModelPackage.GEN_PACKAGE__GEN_MODEL: 1006 return eContainer.eInverseRemove(this, GenModelPackage.GEN_MODEL__GEN_PACKAGES, GenModel.class, msgs); 1007 default: 1008 &nb
|