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 return eDynamicBasicRemoveFromContainer(msgs); 1009 } 1010 } 1011 return eContainer.eInverseRemove(this, EOPPOSITE_FEATURE_BASE - eContainerFeatureID, null, msgs); 1012 } 1013 1014 1019 public Object eGet(EStructuralFeature eFeature, boolean resolve) 1020 { 1021 switch (eDerivedStructuralFeatureID(eFeature)) 1022 { 1023 case GenModelPackage.GEN_PACKAGE__PREFIX: 1024 return getPrefix(); 1025 case GenModelPackage.GEN_PACKAGE__BASE_PACKAGE: 1026 return getBasePackage(); 1027 case GenModelPackage.GEN_PACKAGE__RESOURCE: 1028 return getResource(); 1029 case GenModelPackage.GEN_PACKAGE__DISPOSABLE_PROVIDER_FACTORY: 1030 return isDisposableProviderFactory() ? Boolean.TRUE : Boolean.FALSE; 1031 case GenModelPackage.GEN_PACKAGE__ADAPTER_FACTORY: 1032 return isAdapterFactory() ? Boolean.TRUE : Boolean.FALSE; 1033 case GenModelPackage.GEN_PACKAGE__LOAD_INITIALIZATION: 1034 return isLoadInitialization() ? Boolean.TRUE : Boolean.FALSE; 1035 case GenModelPackage.GEN_PACKAGE__INTERFACE_PACKAGE_SUFFIX: 1036 return getInterfacePackageSuffix(); 1037 case GenModelPackage.GEN_PACKAGE__CLASS_PACKAGE_SUFFIX: 1038 return getClassPackageSuffix(); 1039 case GenModelPackage.GEN_PACKAGE__UTILITY_PACKAGE_SUFFIX: 1040 return getUtilityPackageSuffix(); 1041 case GenModelPackage.GEN_PACKAGE__PROVIDER_PACKAGE_SUFFIX: 1042 return getProviderPackageSuffix(); 1043 case GenModelPackage.GEN_PACKAGE__PRESENTATION_PACKAGE_SUFFIX: 1044 return getPresentationPackageSuffix(); 1045 case GenModelPackage.GEN_PACKAGE__TESTS_PACKAGE_SUFFIX: 1046 return getTestsPackageSuffix(); 1047 case GenModelPackage.GEN_PACKAGE__GENERATE_EXAMPLE_CLASS: 1048 return isGenerateExampleClass() ? Boolean.TRUE : Boolean.FALSE; 1049 case GenModelPackage.GEN_PACKAGE__ECORE_PACKAGE: 1050 if (resolve) return getEcorePackage(); 1051 return basicGetEcorePackage(); 1052 case GenModelPackage.GEN_PACKAGE__GEN_MODEL: 1053 return getGenModel(); 1054 case GenModelPackage.GEN_PACKAGE__GEN_ENUMS: 1055 return getGenEnums(); 1056 case GenModelPackage.GEN_PACKAGE__GEN_DATA_TYPES: 1057 return getGenDataTypes(); 1058 case GenModelPackage.GEN_PACKAGE__GEN_CLASSES: 1059 return getGenClasses(); 1060 case GenModelPackage.GEN_PACKAGE__NESTED_GEN_PACKAGES: 1061 return getNestedGenPackages(); 1062 case GenModelPackage.GEN_PACKAGE__GEN_CLASSIFIERS: 1063 return getGenClassifiers(); 1064 } 1065 return eDynamicGet(eFeature, resolve); 1066 } 1067 1068 1073 public boolean eIsSet(EStructuralFeature eFeature) 1074 { 1075 switch (eDerivedStructuralFeatureID(eFeature)) 1076 { 1077 case GenModelPackage.GEN_PACKAGE__PREFIX: 1078 return PREFIX_EDEFAULT == null ? prefix != null : !PREFIX_EDEFAULT.equals(prefix); 1079 case GenModelPackage.GEN_PACKAGE__BASE_PACKAGE: 1080 return BASE_PACKAGE_EDEFAULT == null ? basePackage != null : !BASE_PACKAGE_EDEFAULT.equals(basePackage); 1081 case GenModelPackage.GEN_PACKAGE__RESOURCE: 1082 return resource != RESOURCE_EDEFAULT; 1083 case GenModelPackage.GEN_PACKAGE__DISPOSABLE_PROVIDER_FACTORY: 1084 return disposableProviderFactory != DISPOSABLE_PROVIDER_FACTORY_EDEFAULT; 1085 case GenModelPackage.GEN_PACKAGE__ADAPTER_FACTORY: 1086 return adapterFactory != ADAPTER_FACTORY_EDEFAULT; 1087 case GenModelPackage.GEN_PACKAGE__LOAD_INITIALIZATION: 1088 return loadInitialization != LOAD_INITIALIZATION_EDEFAULT; 1089 case GenModelPackage.GEN_PACKAGE__INTERFACE_PACKAGE_SUFFIX: 1090 return INTERFACE_PACKAGE_SUFFIX_EDEFAULT == null ? interfacePackageSuffix != null : !INTERFACE_PACKAGE_SUFFIX_EDEFAULT.equals(interfacePackageSuffix); 1091 case GenModelPackage.GEN_PACKAGE__CLASS_PACKAGE_SUFFIX: 1092 return CLASS_PACKAGE_SUFFIX_EDEFAULT == null ? classPackageSuffix != null : !CLASS_PACKAGE_SUFFIX_EDEFAULT.equals(classPackageSuffix); 1093 case GenModelPackage.GEN_PACKAGE__UTILITY_PACKAGE_SUFFIX: 1094 return UTILITY_PACKAGE_SUFFIX_EDEFAULT == null ? utilityPackageSuffix != null : !UTILITY_PACKAGE_SUFFIX_EDEFAULT.equals(utilityPackageSuffix); 1095 case GenModelPackage.GEN_PACKAGE__PROVIDER_PACKAGE_SUFFIX: 1096 return PROVIDER_PACKAGE_SUFFIX_EDEFAULT == null ? providerPackageSuffix != null : !PROVIDER_PACKAGE_SUFFIX_EDEFAULT.equals(providerPackageSuffix); 1097 case GenModelPackage.GEN_PACKAGE__PRESENTATION_PACKAGE_SUFFIX: 1098 return PRESENTATION_PACKAGE_SUFFIX_EDEFAULT == null ? presentationPackageSuffix != null : !PRESENTATION_PACKAGE_SUFFIX_EDEFAULT.equals(presentationPackageSuffix); 1099 case GenModelPackage.GEN_PACKAGE__TESTS_PACKAGE_SUFFIX: 1100 return TESTS_PACKAGE_SUFFIX_EDEFAULT == null ? testsPackageSuffix != null : !TESTS_PACKAGE_SUFFIX_EDEFAULT.equals(testsPackageSuffix); 1101 case GenModelPackage.GEN_PACKAGE__GENERATE_EXAMPLE_CLASS: 1102 return generateExampleClass != GENERATE_EXAMPLE_CLASS_EDEFAULT; 1103 case GenModelPackage.GEN_PACKAGE__ECORE_PACKAGE: 1104 return ecorePackage != null; 1105 case GenModelPackage.GEN_PACKAGE__GEN_MODEL: 1106 return getGenModel() != null; 1107 case GenModelPackage.GEN_PACKAGE__GEN_ENUMS: 1108 return genEnums != null && !genEnums.isEmpty(); 1109 case GenModelPackage.GEN_PACKAGE__GEN_DATA_TYPES: 1110 return genDataTypes != null && !genDataTypes.isEmpty(); 1111 case GenModelPackage.GEN_PACKAGE__GEN_CLASSES: 1112 return genClasses != null && !genClasses.isEmpty(); 1113 case GenModelPackage.GEN_PACKAGE__NESTED_GEN_PACKAGES: 1114 return nestedGenPackages != null && !nestedGenPackages.isEmpty(); 1115 case GenModelPackage.GEN_PACKAGE__GEN_CLASSIFIERS: 1116 return !getGenClassifiers().isEmpty(); 1117 } 1118 return eDynamicIsSet(eFeature); 1119 } 1120 1121 1126 public void eSet(EStructuralFeature eFeature, Object newValue) 1127 { 1128 switch (eDerivedStructuralFeatureID(eFeature)) 1129 { 1130 case GenModelPackage.GEN_PACKAGE__PREFIX: 1131 setPrefix((String )newValue); 1132 return; 1133 case GenModelPackage.GEN_PACKAGE__BASE_PACKAGE: 1134 setBasePackage((String )newValue); 1135 return; 1136 case GenModelPackage.GEN_PACKAGE__RESOURCE: 1137 setResource((GenResourceKind)newValue); 1138 return; 1139 case GenModelPackage.GEN_PACKAGE__DISPOSABLE_PROVIDER_FACTORY: 1140 setDisposableProviderFactory(((Boolean )newValue).booleanValue()); 1141 return; 1142 case GenModelPackage.GEN_PACKAGE__ADAPTER_FACTORY: 1143 setAdapterFactory(((Boolean )newValue).booleanValue()); 1144 return; 1145 case GenModelPackage.GEN_PACKAGE__LOAD_INITIALIZATION: 1146 setLoadInitialization(((Boolean )newValue).booleanValue()); 1147 return; 1148 case GenModelPackage.GEN_PACKAGE__INTERFACE_PACKAGE_SUFFIX: 1149 setInterfacePackageSuffix((String )newValue); 1150 return; 1151 case GenModelPackage.GEN_PACKAGE__CLASS_PACKAGE_SUFFIX: 1152 setClassPackageSuffix((String )newValue); 1153 return; 1154 case GenModelPackage.GEN_PACKAGE__UTILITY_PACKAGE_SUFFIX: 1155 setUtilityPackageSuffix((String )newValue); 1156 return; 1157 case GenModelPackage.GEN_PACKAGE__PROVIDER_PACKAGE_SUFFIX: 1158 setProviderPackageSuffix((String )newValue); 1159 return; 1160 case GenModelPackage.GEN_PACKAGE__PRESENTATION_PACKAGE_SUFFIX: 1161 setPresentationPackageSuffix((String )newValue); 1162 return; 1163 case GenModelPackage.GEN_PACKAGE__TESTS_PACKAGE_SUFFIX: 1164 setTestsPackageSuffix((String )newValue); 1165 return; 1166 case GenModelPackage.GEN_PACKAGE__GENERATE_EXAMPLE_CLASS: 1167 setGenerateExampleClass(((Boolean )newValue).booleanValue()); 1168 return; 1169 case GenModelPackage.GEN_PACKAGE__ECORE_PACKAGE: 1170 setEcorePackage((EPackage)newValue); 1171 return; 1172 case GenModelPackage.GEN_PACKAGE__GEN_MODEL: 1173 setGenModel((GenModel)newValue); 1174 return; 1175 case GenModelPackage.GEN_PACKAGE__GEN_ENUMS: 1176 getGenEnums().clear(); 1177 getGenEnums().addAll((Collection )newValue); 1178 return; 1179 case GenModelPackage.GEN_PACKAGE__GEN_DATA_TYPES: 1180 getGenDataTypes().clear(); 1181 getGenDataTypes().addAll((Collection )newValue); 1182 return; 1183 case GenModelPackage.GEN_PACKAGE__GEN_CLASSES: 1184 getGenClasses().clear(); 1185 getGenClasses().addAll((Collection )newValue); 1186 return; 1187 case GenModelPackage.GEN_PACKAGE__NESTED_GEN_PACKAGES: 1188 getNestedGenPackages().clear(); 1189 getNestedGenPackages().addAll((Collection )newValue); 1190 return; 1191 } 1192 eDynamicSet(eFeature, newValue); 1193 } 1194 1195 1200 public void eUnset(EStructuralFeature eFeature) 1201 { 1202 switch (eDerivedStructuralFeatureID(eFeature)) 1203 { 1204 case GenModelPackage.GEN_PACKAGE__PREFIX: 1205 setPrefix(PREFIX_EDEFAULT); 1206 return; 1207 case GenModelPackage.GEN_PACKAGE__BASE_PACKAGE: 1208 setBasePackage(BASE_PACKAGE_EDEFAULT); 1209 return; 1210 case GenModelPackage.GEN_PACKAGE__RESOURCE: 1211 setResource(RESOURCE_EDEFAULT); 1212 return; 1213 case GenModelPackage.GEN_PACKAGE__DISPOSABLE_PROVIDER_FACTORY: 1214 setDisposableProviderFactory(DISPOSABLE_PROVIDER_FACTORY_EDEFAULT); 1215 return; 1216 case GenModelPackage.GEN_PACKAGE__ADAPTER_FACTORY: 1217 setAdapterFactory(ADAPTER_FACTORY_EDEFAULT); 1218 return; 1219 case GenModelPackage.GEN_PACKAGE__LOAD_INITIALIZATION: 1220 setLoadInitialization(LOAD_INITIALIZATION_EDEFAULT); 1221 return; 1222 case GenModelPackage.GEN_PACKAGE__INTERFACE_PACKAGE_SUFFIX: 1223 setInterfacePackageSuffix(INTERFACE_PACKAGE_SUFFIX_EDEFAULT); 1224 return; 1225 case GenModelPackage.GEN_PACKAGE__CLASS_PACKAGE_SUFFIX: 1226 setClassPackageSuffix(CLASS_PACKAGE_SUFFIX_EDEFAULT); 1227 return; 1228 case GenModelPackage.GEN_PACKAGE__UTILITY_PACKAGE_SUFFIX: 1229 setUtilityPackageSuffix(UTILITY_PACKAGE_SUFFIX_EDEFAULT); 1230 return; 1231 case GenModelPackage.GEN_PACKAGE__PROVIDER_PACKAGE_SUFFIX: 1232 setProviderPackageSuffix(PROVIDER_PACKAGE_SUFFIX_EDEFAULT); 1233 return; 1234 case GenModelPackage.GEN_PACKAGE__PRESENTATION_PACKAGE_SUFFIX: 1235 setPresentationPackageSuffix(PRESENTATION_PACKAGE_SUFFIX_EDEFAULT); 1236 return; 1237 case GenModelPackage.GEN_PACKAGE__TESTS_PACKAGE_SUFFIX: 1238 setTestsPackageSuffix(TESTS_PACKAGE_SUFFIX_EDEFAULT); 1239 return; 1240 case GenModelPackage.GEN_PACKAGE__GENERATE_EXAMPLE_CLASS: 1241 setGenerateExampleClass(GENERATE_EXAMPLE_CLASS_EDEFAULT); 1242 return; 1243 case GenModelPackage.GEN_PACKAGE__ECORE_PACKAGE: 1244 setEcorePackage((EPackage)null); 1245 return; 1246 case GenModelPackage.GEN_PACKAGE__GEN_MODEL: 1247 setGenModel((GenModel)null); 1248 return; 1249 case GenModelPackage.GEN_PACKAGE__GEN_ENUMS: 1250 getGenEnums().clear(); 1251 return; 1252 case GenModelPackage.GEN_PACKAGE__GEN_DATA_TYPES: 1253 getGenDataTypes().clear(); 1254 return; 1255 case GenModelPackage.GEN_PACKAGE__GEN_CLASSES: 1256 getGenClasses().clear(); 1257 return; 1258 case GenModelPackage.GEN_PACKAGE__NESTED_GEN_PACKAGES: 1259 getNestedGenPackages().clear(); 1260 return; 1261 } 1262 eDynamicUnset(eFeature); 1263 } 1264 1265 1270 public String toString() 1271 { 1272 if (eIsProxy()) return super.toString(); 1273 1274 StringBuffer result = new StringBuffer (super.toString()); 1275 result.append(" (prefix: "); 1276 result.append(prefix); 1277 result.append(", basePackage: "); 1278 result.append(basePackage); 1279 result.append(", resource: "); 1280 result.append(resource); 1281 result.append(", disposableProviderFactory: "); 1282 result.append(disposableProviderFactory); 1283 result.append(", adapterFactory: "); 1284 result.append(adapterFactory); 1285 result.append(", loadInitialization: "); 1286 result.append(loadInitialization); 1287 result.append(", interfacePackageSuffix: "); 1288 result.append(interfacePackageSuffix); 1289 result.append(", classPackageSuffix: "); 1290 result.append(classPackageSuffix); 1291 result.append(", utilityPackageSuffix: "); 1292 result.append(utilityPackageSuffix); 1293 result.append(", providerPackageSuffix: "); 1294 result.append(providerPackageSuffix); 1295 result.append(", presentationPackageSuffix: "); 1296 result.append(presentationPackageSuffix); 1297 result.append(", testsPackageSuffix: "); 1298 result.append(testsPackageSuffix); 1299 result.append(", generateExampleClass: "); 1300 result.append(generateExampleClass); 1301 result.append(')'); 1302 return result.toString(); 1303 } 1304 1305 public String getName() 1306 { 1307 return getPackageName(); 1308 } 1309 1310 public String getPackageName() 1311 { 1312 return getEcorePackage().getName(); 1313 } 1314 1315 public String getInterfacePackageName() 1316 { 1317 return getQualifiedPackageName(getInterfacePackageSuffix()); 1318 } 1319 1320 public String getClassPackageName() 1321 { 1322 return getQualifiedPackageName(getClassPackageSuffix()); 1323 } 1324 1325 public String getUtilitiesPackageName() 1326 { 1327 return getQualifiedPackageName(getUtilityPackageSuffix()); 1328 } 1329 1330 public String getTestsPackageName() 1331 { 1332 return getQualifiedPackageName(getTestsPackageSuffix()); 1333 } 1334 1335 public String getPackageID() 1336 { 1337 return getEcorePackage().getNsPrefix(); 1338 } 1339 1340 public String getNSName() 1341 { 1342 return getEcorePackage().getNsPrefix(); 1343 } 1344 1345 public String getNSURI() 1346 { 1347 return getEcorePackage().getNsURI(); 1348 } 1349 1350 public String getPackageInterfaceName() 1351 { 1352 return getPrefixedName("Package"); 1353 } 1354 1355 public String getQualifiedPackageInterfaceName() 1356 { 1357 return getInterfacePackageName() + "." + getPackageInterfaceName(); 1358 } 1359 1360 public String getImportedPackageInterfaceName() 1361 { 1362 return getGenModel().getImportedName(getQualifiedPackageInterfaceName()); 1363 } 1364 1365 public String getUncapPackageInterfaceName() 1366 { 1367 return uncapPrefixedName(getPackageInterfaceName(), true); 1368 } 1369 1370 public String getPackageClassName() 1371 { 1372 return getImplClassName(getPackageInterfaceName()); 1373 } 1374 1375 public String getQualifiedPackageClassName() 1376 { 1377 return getClassPackageName() + "." + getPackageClassName(); 1378 } 1379 1380 public String getImportedPackageClassName() 1381 { 1382 return getGenModel().getImportedName(getQualifiedPackageClassName()); 1383 } 1384 1385 public String getFactoryInterfaceName() 1386 { 1387 return getPrefixedName("Factory"); 1388 } 1389 1390 public String getQualifiedFactoryInterfaceName() 1391 { 1392 return getInterfacePackageName() + "." + getFactoryInterfaceName(); 1393 } 1394 1395 public String getImportedFactoryInterfaceName() 1396 { 1397 return getGenModel().getImportedName(getQualifiedFactoryInterfaceName()); 1398 } 1399 1400 public String getUncapFactoryInterfaceName() 1401 { 1402 return uncapPrefixedName(getFactoryInterfaceName(), true); 1403 } 1404 1405 public String getFactoryClassName() 1406 { 1407 return getImplClassName(getFactoryInterfaceName()); 1408 } 1409 1410 public String getQualifiedFactoryClassName() 1411 { 1412 return getClassPackageName() + "." + getFactoryClassName(); 1413 } 1414 1415 public String getImportedFactoryClassName() 1416 { 1417 return getGenModel().getImportedName(getQualifiedFactoryClassName()); 1418 } 1419 1420 public String getAdapterFactoryClassName() 1421 { 1422 return getPrefixedName("AdapterFactory"); 1423 } 1424 1425 public String getQualifiedAdapterFactoryClassName() 1426 { 1427 return getUtilitiesPackageName() + "." + getAdapterFactoryClassName(); 1428 } 1429 1430 public String getImportedAdapterFactoryClassName() 1431 { 1432 return getGenModel().getImportedName(getQualifiedAdapterFactoryClassName()); 1433 } 1434 1435 public String getUncapAdapterFactoryClassName() 1436 { 1437 return uncapPrefixedName(getAdapterFactoryClassName(), true); 1438 } 1439 1440 public String getSwitchClassName() 1441 { 1442 return getPrefixedName("Switch"); 1443 } 1444 1445 public String getTestSuiteClassName() 1446 { 1447 return getPrefixedName("Tests"); 1448 } 1449 1450 public String getExampleClassName() 1451 { 1452 return getPrefixedName("Example"); 1453 } 1454 1455 public String getQualifiedTestSuiteClassName() 1456 { 1457 return getTestsPackageName() + "." + getPrefixedName("Tests"); 1458 } 1459 1460 public String getImportedTestSuiteClassName() 1461 { 1462 return getGenModel().getImportedName(getQualifiedTestSuiteClassName()); 1463 } 1464 1465 protected static final boolean NO_CONSTRAINTS = "true".equals(System.getProperty("EMF_NO_CONSTRAINTS")); 1466 1467 public boolean hasConstraints() 1468 { 1469 if (NO_CONSTRAINTS) return false; 1470 for (Iterator i = getGenClassifiers().iterator(); i.hasNext(); ) 1471 { 1472 GenClassifier genClassifier = (GenClassifier)i.next(); 1473 if (!genClassifier.getGenConstraints().isEmpty()) 1474 { 1475 return true; 1476 } 1477 } 1478 return false; 1479 } 1480 1481 public String getValidatorClassName() 1482 { 1483 return getPrefixedName("Validator"); 1484 } 1485 1486 public String getImportedValidatorClassName() 1487 { 1488 return getGenModel().getImportedName(getUtilitiesPackageName() + "." + getPrefixedName("Validator")); 1489 } 1490 1491 protected String getPrefixedName(String name) 1492 { 1493 if (getPrefix() != null) 1494 { 1495 return getPrefix() + name; 1496 } 1497 return name; 1498 } 1499 1500 public List getAllGenDataTypes() 1501 { 1502 List result = new ArrayList (); 1503 result.addAll(getGenEnums()); 1504 result.addAll(getGenDataTypes()); 1505 return result; 1506 } 1507 1508 public List getOrderedGenClasses() 1509 { 1510 List result = new ArrayList (); 1511 Set resultSet = new HashSet (); 1512 1513 for (Iterator iter = getGenClasses().iterator(); iter.hasNext(); ) 1514 { 1515 List extendChain = new LinkedList (); 1516 for (GenClass genClass = (GenClass)iter.next(); genClass != null; genClass = genClass.getBaseGenClass()) 1517 { 1518 if (this == genClass.getGenPackage() && resultSet.add(genClass)) 1519 { 1520 extendChain.add(0, genClass); 1521 } 1522 } 1523 result.addAll(extendChain); 1524 } 1525 return result; 1526 } 1527 1528 public List getOrderedGenClassifiers() 1529 { 1530 List result = new ArrayList (getOrderedGenClasses()); 1531 result.addAll(getGenEnums()); 1532 result.addAll(getGenDataTypes()); 1533 return result; 1534 } 1535 1536 public String getClassifierID(GenClassifier genClassifier) 1537 { 1538 return genClassifier.getClassifierID(); 1539 } 1540 1541 public int getClassifierValue(GenClassifier genClassifier) 1542 { 1543 return getGenClassifiers().indexOf(genClassifier); 1544 } 1545 1546 public int getLocalClassifierIndex(GenClassifier genClassifier) 1547 { 1548 return getEcorePackage().getEClassifiers().indexOf(genClassifier.getEcoreClassifier()); 1549 } 1550 1551 public List getPackageSimpleDependencies() 1552 { 1553 return dependencyHelper.getSimpleDependencies(); 1554 } 1555 1556 public List getPackageInterDependencies() 1557 { 1558 return dependencyHelper.getInterDependencies(); 1559 } 1560 1561 public List getPackageLoadInterDependencies() 1562 { 1563 return dependencyHelper.getLoadInterDependencies(); 1564 } 1565 1566 public List getPackageBuildInterDependencies() 1567 { 1568 return dependencyHelper.getBuildInterDependencies(); 1569 } 1570 1571 public List getPackageInitializationDependencies() 1572 { 1573 return dependencyHelper.getInitializationDependencies(); 1574 } 1575 1576 public String getPackageInstanceVariable(GenPackage genPackage) 1577 { 1578 if (genPackage == this) return "this"; 1579 if (genPackage == ecoreGenPackage) return "ecorePackage"; 1580 1581 return "the" + dependencyHelper.getUniqueName(genPackage); 1582 } 1583 1584 private DependencyHelper dependencyHelper = null; 1585 1586 private class DependencyHelper extends GenBaseImpl.UniqueNameHelper 1587 { 1588 private List simpleDependencies; 1589 private List interDependencies; 1590 private List loadInterDependencies; 1591 private List buildInterDependencies; 1592 private List initializationDependencies; 1593 1594 public DependencyHelper() 1595 { 1596 super(2 * (getGenModel().getGenPackages().size() + getGenModel().getUsedGenPackages().size())); 1597 1598 add(GenPackageImpl.this); 1599 1600 simpleDependencies = new ArrayList (); 1601 collectPackages(simpleDependencies, getGenModel().getUsedGenPackages(), 1); 1602 addAll(simpleDependencies); 1603 1604 interDependencies = new ArrayList (); 1605 collectPackages(interDependencies, getGenModel().getGenPackages(), -1); 1606 interDependencies.remove(GenPackageImpl.this); 1607 addAll(interDependencies); 1608 1609 loadInterDependencies = new ArrayList (); 1610 buildInterDependencies = new ArrayList (); 1611 for (Iterator i = interDependencies.iterator(); i.hasNext(); ) 1612 { 1613 GenPackage genPackage = (GenPackage)i.next(); 1614 if (genPackage.isLoadedInitialization()) 1615 { 1616 loadInterDependencies.add(genPackage); 1617 } 1618 else 1619 { 1620 buildInterDependencies.add(genPackage); 1621 } 1622 } 1623 1624 initializationDependencies = new UniqueEList(); 1625 for (Iterator i = getSubGenPackages().iterator(); i.hasNext(); ) 1626 { 1627 initializationDependencies.add(i.next()); 1628 } 1629 for (Iterator i = getGenClasses().iterator(); i.hasNext(); ) 1630 { 1631 GenClass genClass = (GenClass)i.next(); 1632 for (Iterator j = genClass.getBaseGenClasses().iterator(); j.hasNext(); ) 1633 { 1634 GenClass baseGenClass = (GenClass)j.next(); 1635 initializationDependencies.add(baseGenClass.getGenPackage()); 1636 } 1637 for (Iterator j = genClass.getGenFeatures().iterator(); j.hasNext(); ) 1638 { 1639 GenFeature genFeature = (GenFeature)j.next(); 1640 initializationDependencies.add(genFeature.getTypeGenPackage()); 1641 1642 if (genFeature.isReferenceType()) 1643 { 1644 GenFeature reverseGenFeature = genFeature.getReverse(); 1645 if (reverseGenFeature != null) 1646 { 1647 initializationDependencies.add(reverseGenFeature.getGenPackage()); 1648 } 1649 } 1650 1651 GenFeature delegateFeature = genFeature.getDelegateFeature(); 1652 if (delegateFeature != null) 1653 { 1654 initializationDependencies.add(delegateFeature.getGenPackage()); 1655 } 1656 } 1657 for (Iterator j = genClass.getGenOperations().iterator(); j.hasNext(); ) 1658 { 1659 GenOperation genOperation = (GenOperation)j.next(); 1660 if (!genOperation.isVoid()) 1661 { 1662 initializationDependencies.add(genOperation.getTypeGenPackage()); 1663 } 1664 for (Iterator k = genOperation.getGenParameters().iterator(); k.hasNext(); ) 1665 { 1666 GenParameter genParameter = (GenParameter)k.next(); 1667 initializationDependencies.add(genParameter.getTypeGenPackage()); 1668 } 1669 for (Iterator k = genOperation.getGenExceptions().iterator(); k.hasNext(); ) 1670 { 1671 GenClassifier genClassifier = (GenClassifier)k.next(); 1672 initializationDependencies.add(genClassifier.getGenPackage()); 1673 } 1674 } 1675 } 1676 for (Iterator i = getGenDataTypes().iterator(); i.hasNext(); ) 1677 { 1678 GenDataType genDataType = (GenDataType)i.next(); 1679 GenDataType baseType = genDataType.getBaseType(); 1680 if (baseType != null) 1681 { 1682 initializationDependencies.add(baseType.getGenPackage()); 1683 } 1684 GenDataType itemType = genDataType.getItemType(); 1685 if (itemType != null) 1686 { 1687 initializationDependencies.add(itemType.getGenPackage()); 1688 } 1689 for (Iterator j = genDataType.getMemberTypes().iterator(); j.hasNext(); ) 1690 { 1691 GenDataType memberType = (GenDataType)j.next(); 1692 initializationDependencies.add(memberType.getGenPackage()); 1693 } 1694 } 1695 1696 if (initializationDependencies.contains(xmlTypeGenPackage) && !xmlTypeGenPackage.getNSURI().equals(getNSURI())) 1697 { 1698 simpleDependencies.add(xmlTypeGenPackage); 1699 } 1700 if (initializationDependencies.contains(xmlNamespaceGenPackage)) 1701 { 1702 simpleDependencies.add(xmlNamespaceGenPackage); 1703 } 1704 1705 initializationDependencies.remove(GenPackageImpl.this); 1706 initializationDependencies.remove(findGenPackage(EcorePackage.eINSTANCE)); 1707 } 1708 1709 protected String getName(Object o) 1710 { 1711 return ((GenPackage)o).getPackageInterfaceName(); 1712 } 1713 1714 public List getSimpleDependencies() 1715 { 1716 return simpleDependencies; 1717 } 1718 1719 public List getInterDependencies() 1720 { 1721 return interDependencies; 1722 } 1723 1724 public List getLoadInterDependencies() 1725 { 1726 return loadInterDependencies; 1727 } 1728 1729 public List getBuildInterDependencies() 1730 { 1731 return buildInterDependencies; 1732 } 1733 1734 public List getInitializationDependencies() 1735 { 1736 return initializationDependencies; 1737 } 1738 } 1739 1740 1745 protected void collectPackages(List result, List genPackages, int depth) 1746 { 1747 if (depth == 0) return; 1748 1749 for (Iterator i = genPackages.iterator(); i.hasNext(); ) 1750 { 1751 GenPackage genPackage = (GenPackage)i.next(); 1752 if (genPackage.hasClassifiers()) 1753 { 1754 result.add(genPackage); 1755 collectPackages(result, genPackage.getNestedGenPackages(), depth - 1); 1756 } 1757 else 1758 { 1759 collectPackages(result, genPackage.getNestedGenPackages(), depth); 1760 } 1761 } 1762 } 1763 1764 public List getSubGenPackages() 1765 { 1766 List result = new ArrayList (); 1767 collectPackages(result, getNestedGenPackages(), 1); 1768 return result; 1769 } 1770 1771 public GenPackage getSuperGenPackage() 1772 { 1773 EObject container = eContainer(); 1774 while (container instanceof GenPackage) 1775 { 1776 GenPackage outer = (GenPackage)container; 1777 if (this == outer) 1778 { 1779 throw new RuntimeException ("inheritance loop at " + getPackageName()); 1780 } 1781 1782 if (outer.hasClassifiers()) return outer; 1783 container = outer.eContainer(); 1784 } 1785 return null; 1786 } 1787 1788 public GenPackage getRootGenPackage() 1789 { 1790 GenPackage root = this; 1791 while (true) 1792 { 1793 GenPackage container = root.getSuperGenPackage(); 1794 if (container == null) 1795 { 1796 return root; 1797 } 1798 else if (this == container) 1799 { 1800 throw new RuntimeException ("inheritance loop at " + getPackageName()); 1801 } 1802 root = container; 1803 } 1804 } 1805 1806 public boolean isLoadingInitialization() 1807 { 1808 return getRootGenPackage() == this && needsLoadInitialization(this); 1809 } 1810 1811 public boolean isLoadedInitialization() 1812 { 1813 return needsLoadInitialization(getRootGenPackage()); 1814 } 1815 1816 private boolean needsLoadInitialization(GenPackage genPackage) 1817 { 1818 if (genPackage.isLoadInitialization()) return true; 1819 1820 for (Iterator i = genPackage.getSubGenPackages().iterator(); i.hasNext(); ) 1821 { 1822 if (needsLoadInitialization((GenPackage)i.next())) return true; 1823 } 1824 return false; 1825 } 1826 1827 public boolean isEcorePackage() 1828 { 1829 return (EcorePackage.eNS_URI.equals(getNSURI())); 1830 } 1831 1832 public boolean hasJavaLangConflict() 1833 { 1834 return !getJavaLangConflicts().isEmpty(); 1835 } 1836 1837 public List getJavaLangConflicts() 1838 { 1839 List result = new ArrayList (); 1840 for (Iterator i = getGenClasses().iterator(); i.hasNext(); ) 1841 { 1842 GenClass genClass = (GenClass)i.next(); 1843 String name = genClass.getName(); 1844 if (CodeGenUtil.isJavaDefaultType(name)) 1845 { 1846 result.add(name); 1847 } 1848 } 1849 return result; 1850 } 1851 1852 public boolean hasInterfaceImplConflict() 1853 { 1854 Set names = new HashSet (); 1855 for (Iterator i = getGenClasses().iterator(); i.hasNext(); ) 1856 { 1857 GenClass genClass = (GenClass)i.next(); 1858 names.add(genClass.getName()); 1859 } 1860 1861 for (Iterator i = names.iterator(); i.hasNext(); ) 1862 { 1863 String name = (String )i.next(); 1864 if (names.contains(name + "Impl")) 1865 { 1866 return true; 1867 } 1868 } 1869 1870 return false; 1871 } 1872 1873 public List getAllSwitchGenClasses() 1874 { 1875 if (switchHelper == null) 1876 { 1877 switchHelper = new SwitchHelper(); 1878 } 1879 return switchHelper.getAllGenClasses(); 1880 } 1881 1882 public String getClassUniqueName(GenClass genClass) 1883 { 1884 if (switchHelper == null) 1885 { 1886 switchHelper = new SwitchHelper(); 1887 } 1888 return switchHelper.getUniqueName(genClass); 1889 } 1890 1891 private SwitchHelper switchHelper = null; 1892 1893 private class SwitchHelper extends GenBaseImpl.UniqueNameHelper 1894 { 1895 protected List allGenClasses = new LinkedList (); 1896 protected List allBaseGenPackages = new UniqueEList(); 1897 1898 public SwitchHelper() 1899 { 1900 super(3 * getGenClasses().size()); 1901 initLocal(); 1902 initBases(); 1903 } 1904 1905 protected SwitchHelper(int size) 1906 { 1907 super(size); 1908 } 1909 1910 protected void initLocal() 1911 { 1912 for (Iterator i = getGenClasses().iterator(); i.hasNext(); ) 1915 { 1916 GenClass genClass = (GenClass)i.next(); 1917 1918 if (!genClass.isEObject() && add(genClass)) 1920 { 1921 allGenClasses.add(genClass); 1922 } 1923 } 1924 } 1925 1926 protected void initBases() 1927 { 1928 for (Iterator i = getGenClasses().iterator(); i.hasNext(); ) 1930 { 1931 GenClass genClass = (GenClass)i.next(); 1932 if (genClass.isEObject()) continue; 1933 1934 for (Iterator j = genClass.getEcoreClass().getEAllSuperTypes().iterator(); j.hasNext(); ) 1935 { 1936 EClass base = (EClass)j.next(); 1937 GenClass baseGenClass = findGenClass(base); 1938 if (baseGenClass != null && !baseGenClass.isEObject() && add(baseGenClass)) 1939 { 1940 allGenClasses.add(baseGenClass); 1941 if (baseGenClass.getGenPackage() != GenPackageImpl.this) 1942 { 1943 allBaseGenPackages.add(baseGenClass.getGenPackage()); 1944 } 1945 } 1946 } 1947 } 1948 } 1949 1950 protected String getName(Object o) 1951 { 1952 return ((GenClassifier)o).getName(); 1953 } 1954 1955 protected List getAlternateNames(Object o) 1956 { 1957 GenClassifier genClassifier = (GenClassifier)o; 1958 return Collections.singletonList(genClassifier.getGenPackage().getPrefix() + "_" + genClassifier.getName()); 1959 } 1960 1961 public List getAllGenClasses() 1962 { 1963 return allGenClasses; 1964 } 1965 } 1966 1967 public List getAllValidatorBaseGenPackages() 1968 { 1969 if (validatorHelper == null) 1970 { 1971 validatorHelper = new ValidatorHelper(); 1972 } 1973 return validatorHelper.getAllBaseGenPackages(); 1974 } 1975 1976 public String getValidatorPackageUniqueSafeName(GenPackage genPackage) 1977 { 1978 if (validatorHelper == null) 1979 { 1980 validatorHelper = new ValidatorHelper(); 1981 } 1982 return validatorHelper.getPackageUniqueSafeName(genPackage); 1983 } 1984 1985 private ValidatorHelper validatorHelper = null; 1986 1987 private class ValidatorHelper 1988 { 1989 protected List allBaseGenPackages = new UniqueEList(); 1990 1991 public ValidatorHelper() 1992 { 1993 init(); 1994 } 1995 1996 protected void init() 1997 { 1998 for (Iterator i = getGenClasses().iterator(); i.hasNext(); ) 2000 { 2001 GenClass genClass = (GenClass)i.next(); 2002 if (!genClass.isEObject()) 2003 { 2004 for (Iterator j = genClass.getEcoreClass().getEAllSuperTypes().iterator(); j.hasNext(); ) 2005 { 2006 EClass base = (EClass)j.next(); 2007 GenClass baseGenClass = findGenClass(base); 2008 if (baseGenClass != null && 2009 !baseGenClass.isEObject() && 2010 baseGenClass.getGenPackage() != GenPackageImpl.this && 2011 !baseGenClass.getGenConstraints().isEmpty()) 2012 { 2013 allBaseGenPackages.add(baseGenClass.getGenPackage()); 2014 } 2015 } 2016 } 2017 } 2018 2019 for (Iterator i = getGenDataTypes().iterator(); i.hasNext(); ) 2020 { 2021 GenDataType genDataType = (GenDataType)i.next(); 2022 for (GenDataType baseType = genDataType.getBaseType(); baseType != null; baseType = baseType.getBaseType()) 2023 { 2024 allBaseGenPackages.add(baseType.getGenPackage()); 2025 } 2026 GenDataType itemType = genDataType.getItemType(); 2027 if (itemType != null) 2028 { 2029 allBaseGenPackages.add(itemType.getGenPackage()); 2030 } 2031 for (Iterator j = genDataType.getMemberTypes().iterator(); j.hasNext(); ) 2032 { 2033 GenDataType memberType = (GenDataType)j.next(); 2034 allBaseGenPackages.add(memberType.getGenPackage()); 2035 } 2036 } 2037 2038 allBaseGenPackages.remove(GenPackageImpl.this); 2039 } 2040 2041 public List getAllBaseGenPackages() 2042 { 2043 return allBaseGenPackages; 2044 } 2045 2046 public String getPackageUniqueSafeName(GenPackage genPackage) 2047 { 2048 return safeName(uncapPrefixedName(genPackage.getPrefix())); 2049 } 2050 } 2051 2052 public void initialize(EPackage ePackage) 2053 { 2054 boolean isDifferentPackage = ePackage != getEcorePackage(); 2055 if (isDifferentPackage) 2056 { 2057 setEcorePackage(ePackage); 2058 2059 if (hasExtendedMetaData(ePackage)) 2060 { 2061 setResource(GenResourceKind.XML_LITERAL); 2062 } 2063 setDisposableProviderFactory(true); 2064 } 2065 2066 CLASSIFIER_LOOP: 2067 for (Iterator iter = ePackage.getEClassifiers().iterator(); iter.hasNext(); ) 2068 { 2069 EClassifier eClassifier = (EClassifier)iter.next(); 2070 2071 for (Iterator j = getGenClassifiers().iterator(); j.hasNext(); ) 2072 { 2073 GenClassifier genClassifier = (GenClassifier)j.next(); 2074 if (genClassifier.getEcoreClassifier() == eClassifier) 2075 { 2076 if (eClassifier instanceof EClass) 2077 { 2078 ((GenClass)genClassifier).initialize((EClass)eClassifier); 2079 } 2080 else if (eClassifier instanceof EEnum) 2081 { 2082 ((GenEnum)genClassifier).initialize((EEnum)eClassifier); 2083 } 2084 else if (eClassifier instanceof EDataType) 2085 { 2086 ((GenDataType)genClassifier).initialize((EDataType)eClassifier); 2087 } 2088 2089 continue CLASSIFIER_LOOP; 2090 } 2091 } 2092 2093 if (eClassifier instanceof EClass) 2094 { 2095 EClass eClass = (EClass)eClassifier; 2096 GenClass genClass = getGenModel().createGenClass(); 2097 getGenClasses().add(genClass); 2098 genClass.initialize(eClass); 2099 2100 } 2101 else if (eClassifier instanceof EEnum) 2102 { 2103 EEnum eEnum = (EEnum)eClassifier; 2104 GenEnum genEnum = getGenModel().createGenEnum(); 2105 getGenEnums().add(genEnum); 2106 genEnum.initialize(eEnum); 2107 } 2108 else if (eClassifier instanceof EDataType) 2109 { 2110 EDataType eDataType = (EDataType)eClassifier; 2111 GenDataType genDataType = getGenModel().createGenDataType(); 2112 getGenDataTypes().add(genDataType); 2113 genDataType.initialize(eDataType); 2114 } 2115 } 2116 2117 PACKAGE_LOOP: 2118 for (Iterator iter = ePackage.getESubpackages().iterator(); iter.hasNext(); ) 2119 { 2120 EPackage nestedEPackage = (EPackage)iter.next(); 2121 2122 for (Iterator j = getNestedGenPackages().iterator(); j.hasNext(); ) 2123 { 2124 GenPackage nestedGenPackage = (GenPackage)j.next(); 2125 if (nestedGenPackage.getEcorePackage() == nestedEPackage) 2126 { 2127 nestedGenPackage.initialize(nestedEPackage); 2128 continue PACKAGE_LOOP; 2129 } 2130 } 2131 2132 GenPackage genPackage = getGenModel().createGenPackage(); 2133 getNestedGenPackages().add(genPackage); 2134 genPackage.initialize(nestedEPackage); 2135 } 2136 2137 if (isDifferentPackage) 2138 { 2139 setLoadInitialization(isBigModel()); 2140 } 2141 } 2142 2143 protected boolean hasModelContribution() 2144 { 2145 return hasClassifiers() || !getNestedGenPackages().isEmpty(); 2146 } 2147 2148 public void generate(IProgressMonitor progressMonitor) 2149 { 2150 try 2151 { 2152 if (!canGenerate()) return; 2153 2154 progressMonitor.beginTask("", 2 * getGenClasses().size() + 2 * getGenEnums().size() + 8 + getNestedGenPackages().size()); 2155 progressMonitor.subTask 2156 (CodeGenEcorePlugin.INSTANCE.getString("_UI_GeneratingPackage_message", new Object [] { getPackageInterfaceName() })); 2157 2158 switchHelper = new SwitchHelper(); 2160 validatorHelper = new ValidatorHelper(); 2161 dependencyHelper = new DependencyHelper(); 2162 2163 for (Iterator iter = getGenClasses().iterator(); iter.hasNext(); ) 2164 { 2165 GenClass genClass = (GenClass)iter.next(); 2166 progressMonitor.subTask 2167 (CodeGenEcorePlugin.INSTANCE.getString("_UI_GeneratingModelClass_message", new Object [] { genClass.getFormattedName() })); 2168 genClass.generate(new SubProgressMonitor(progressMonitor, 2)); 2169 } 2170 2171 for (Iterator iter = getGenEnums().iterator(); iter.hasNext(); ) 2172 { 2173 GenEnum genEnum = (GenEnum)iter.next(); 2174 progressMonitor.subTask 2175 (CodeGenEcorePlugin.INSTANCE.getString("_UI_GeneratingModelEnum_message", new Object [] { genEnum.getFormattedName() })); 2176 genEnum.generate(new SubProgressMonitor(progressMonitor, 2)); 2177 } 2178 2179 if (hasClassifiers()) 2180 { 2181 if (getGenModel().isGenerateSchema()) 2182 { 2183 generateSchema(new SubProgressMonitor(progressMonitor, 1)); 2184 } 2185 2186 if (isLoadingInitialization()) 2187 { 2188 generatePackageSerialization(new SubProgressMonitor(progressMonitor, 1)); 2189 } 2190 2191 progressMonitor.subTask 2192 (CodeGenEcorePlugin.INSTANCE.getString 2193 ("_UI_GeneratingJavaInterface_message", new Object [] { getInterfacePackageName() + "." + getPackageInterfaceName() })); 2194 generate 2195 (new SubProgressMonitor(progressMonitor, 1), 2196 Generator.EMF_MODEL_PROJECT_STYLE, 2197 getGenModel().getEffectiveModelPluginVariables(), 2198 getGenModel().getModelDirectory(), 2199 getInterfacePackageName(), 2200 getPackageInterfaceName(), 2201 getGenModel().getPackageInterfaceEmitter()); 2202 2203 progressMonitor.subTask 2204 (CodeGenEcorePlugin.INSTANCE.getString 2205 ("_UI_GeneratingJavaClass_message", new Object [] { getClassPackageName() + "." + getPackageClassName() })); 2206 generate 2207 (new SubProgressMonitor(progressMonitor, 1), 2208 Generator.EMF_MODEL_PROJECT_STYLE, 2209 getGenModel().getEffectiveModelPluginVariables(), 2210 getGenModel().getModelDirectory(), 2211 getClassPackageName(), 2212 getPackageClassName(), 2213 getGenModel().getPackageClassEmitter()); 2214 2215 progressMonitor.subTask 2216 (CodeGenEcorePlugin.INSTANCE.getString 2217 ("_UI_GeneratingJavaInterface_message", new Object [] { getInterfacePackageName() + "." + getFactoryInterfaceName() })); 2218 generate 2219 (new SubProgressMonitor(progressMonitor, 1), 2220 Generator.EMF_MODEL_PROJECT_STYLE, 2221 getGenModel().getEffectiveModelPluginVariables(), 2222 getGenModel().getModelDirectory(), 2223 getInterfacePackageName(), 2224 getFactoryInterfaceName(), 2225 getGenModel().getFactoryInterfaceEmitter()); 2226 2227 progressMonitor.subTask 2228 (CodeGenEcorePlugin.INSTANCE.getString 2229 ("_UI_GeneratingJavaClass_message", new Object [] { getClassPackageName() + "." + getFactoryClassName() })); 2230 generate 2231 (new SubProgressMonitor(progressMonitor, 1), 2232 Generator.EMF_MODEL_PROJECT_STYLE, 2233 getGenModel().getEffectiveModelPluginVariables(), 2234 getGenModel().getModelDirectory(), 2235 getClassPackageName(), 2236 getFactoryClassName(), 2237 getGenModel().getFactoryClassEmitter()); 2238 2239 if (hasConstraints()) 2240 { 2241 progressMonitor.subTask 2242 (CodeGenEcorePlugin.INSTANCE.getString 2243 ("_UI_GeneratingJavaClass_message", new Object [] { getUtilitiesPackageName() + "." + getValidatorClassName() })); 2244 generate 2245 (new SubProgressMonitor(progressMonitor, 1), 2246 Generator.EMF_MODEL_PROJECT_STYLE, 2247 getGenModel().getEffectiveModelPluginVariables(), 2248 getGenModel().getModelDirectory(), 2249 getUtilitiesPackageName(), 2250 getValidatorClassName(), 2251 getGenModel().getValidatorClassEmitter()); 2252 } 2253 2254 if (isAdapterFactory()) 2255 { 2256 progressMonitor.subTask 2257 (CodeGenEcorePlugin.INSTANCE.getString 2258 ("_UI_GeneratingJavaClass_message", new Object [] { getUtilitiesPackageName() + "." + getSwitchClassName() })); 2259 generate 2260 (new SubProgressMonitor(progressMonitor, 1), 2261 Generator.EMF_MODEL_PROJECT_STYLE, 2262 getGenModel().getEffectiveModelPluginVariables(), 2263 getGenModel().getModelDirectory(), 2264 getUtilitiesPackageName(), 2265 getSwitchClassName(), 2266 getGenModel().getSwitchClassEmitter()); 2267 2268 progressMonitor.subTask 2269 (CodeGenEcorePlugin.INSTANCE.getString 2270 ("_UI_GeneratingJavaClass_message", new Object [] { getUtilitiesPackageName() + "." + getAdapterFactoryClassName() })); 2271 generate 2272 (new SubProgressMonitor(progressMonitor, 1), 2273 Generator.EMF_MODEL_PROJECT_STYLE, 2274 getGenModel().getEffectiveModelPluginVariables(), 2275 getGenModel().getModelDirectory(), 2276 getUtilitiesPackageName(), 2277 getAdapterFactoryClassName(), 2278 getGenModel().getAdapterFactoryClassEmitter()); 2279 } 2280 } 2281 2282 if (getResource() != GenResourceKind.NONE_LITERAL) 2283 { 2284 progressMonitor.subTask 2285 (CodeGenEcorePlugin.INSTANCE.getString 2286 ("_UI_GeneratingJavaClass_message", new Object [] { getQualifiedResourceFactoryClassName() })); 2287 generate 2288 (new SubProgressMonitor(progressMonitor, 1), 2289 Generator.EMF_MODEL_PROJECT_STYLE, 2290 getGenModel().getEffectiveModelPluginVariables(), 2291 getGenModel().getModelDirectory(), 2292 getUtilitiesPackageName(), 2293 getResourceFactoryClassName(), 2294 getGenModel().getResourceFactoryClassEmitter()); 2295 2296 progressMonitor.subTask 2297 (CodeGenEcorePlugin.INSTANCE.getString 2298 ("_UI_GeneratingJavaClass_message", new Object [] { getQualifiedResourceFactoryClassName() })); 2299 generate 2300 (new SubProgressMonitor(progressMonitor, 1), 2301 Generator.EMF_MODEL_PROJECT_STYLE, 2302 getGenModel().getEffectiveModelPluginVariables(), 2303 getGenModel().getModelDirectory(), 2304 getUtilitiesPackageName(), 2305 getResourceClassName(), 2306 getGenModel().getResourceClassEmitter()); 2307 } 2308 2309 for (Iterator nestedGenPackages = getNestedGenPackages().iterator(); nestedGenPackages.hasNext(); ) 2310 { 2311 GenPackage nestedGenPackage = (GenPackage)nestedGenPackages.next(); 2312 nestedGenPackage.generate(new SubProgressMonitor(progressMonitor, 1)); 2313 } 2314 } 2315 finally 2316 { 2317 switchHelper = null; 2319 validatorHelper = null; 2320 dependencyHelper = null; 2321 2322 progressMonitor.done(); 2323 } 2324 } 2325 2326 2330 public void generateSchema() 2331 { 2332 generateSchema(new NullProgressMonitor()); 2333 } 2334 2335 public boolean canGenerateSchema() 2336 { 2337 return canGenerate(); 2338 } 2339 2340 public void generateSchema(IProgressMonitor progressMonitor) 2341 { 2342 if (!canGenerateSchema()) return; 2343 2344 if (hasClassifiers()) 2345 { 2346 switch (getResource().getValue()) 2347 { 2348 case GenResourceKind.XML: 2349 { 2350 generateXSD("XML"); 2351 break; 2352 } 2353 case GenResourceKind.NONE: 2354 case GenResourceKind.XMI: 2355 { 2356 generateXSD("XMI"); 2357 break; 2358 } 2359 } 2360 } 2361 2362 for (Iterator i = getNestedGenPackages().iterator(); i.hasNext();) 2363 { 2364 ((GenPackage)i.next()).generateSchema(progressMonitor); 2365 } 2366 } 2367 2368 protected void generateXSD(String type) 2369 { 2370 Bundle xsdPlugin = Platform.getBundle("org.eclipse.xsd"); 2371 if (xsdPlugin != null) 2372 { 2373 try 2374 { 2375 Class theGeneratorClass = 2376 xsdPlugin.loadClass 2377 ("org.eclipse.xsd.ecore.Ecore" + type + "SchemaBuilder"); 2378 2379 try 2380 { 2381 Object generator = theGeneratorClass.newInstance(); 2382 2383 Bundle xsd2ecorePlugin = Platform.getBundle("org.eclipse.emf.mapping.xsd2ecore"); 2386 if (xsd2ecorePlugin != null) 2387 { 2388 try 2389 { 2390 Class theMapperInterface = 2391 xsdPlugin.loadClass 2392 ("org.eclipse.xsd.ecore.MapBuilder$Mapper"); 2393 2394 Class theMapperClass = 2395 xsd2ecorePlugin.loadClass 2396 ("org.eclipse.emf.mapping.xsd2ecore.XSD2EcoreMapper"); 2397 2398 Object mapper = theMapperClass.newInstance(); 2399 2400 theGeneratorClass.getMethod 2401 ("setMapper", 2402 new Class [] { theMapperInterface }).invoke(generator, new Object [] { mapper }); 2403 } 2404 catch (InstantiationException exception) 2405 { 2406 CodeGenEcorePlugin.INSTANCE.log(exception); 2407 } 2408 catch (NoSuchMethodException exception) 2409 { 2410 CodeGenEcorePlugin.INSTANCE.log(exception); 2411 } 2412 catch (IllegalAccessException exception) 2413 { 2414 CodeGenEcorePlugin.INSTANCE.log(exception); 2415 } 2416 catch (InvocationTargetException exception) 2417 { 2418 CodeGenEcorePlugin.INSTANCE.log(exception); 2419 } 2420 catch (ClassNotFoundException exception) 2421 { 2422 } 2424 } 2425 2426 Collection result = 2427 (Collection )theGeneratorClass.getMethod 2428 ("generate", 2429 new Class [] { EPackage.class }).invoke(generator, new Object [] { getEcorePackage() }); 2430 2431 Iterator i = result.iterator(); 2432 Object xsdSchema = i.next(); 2433 2434 ResourceSet resourceSet = new ResourceSetImpl(); 2435 resourceSet.getURIConverter().getURIMap().putAll(EcorePlugin.computePlatformURIMap()); 2436 URI uri = getEcorePackage().eResource().getURI().trimSegments(1).appendSegment(getPrefix() + type + ".xsd"); 2437 Resource xsdSchemaResource = resourceSet.createResource(uri); 2438 xsdSchemaResource.getContents().add(xsdSchema); 2439 try 2440 { 2441 xsdSchemaResource.save(Collections.EMPTY_MAP); 2442 } 2443 catch (IOException exception) 2444 { 2445 CodeGenEcorePlugin.INSTANCE.log(exception); 2446 } 2447 2448 if (i.hasNext()) 2449 { 2450 if (!"XML".equals(type)) 2451 { 2452 Object otherXSDSchema = i.next(); 2453 URI otherURI = getEcorePackage().eResource().getURI().trimSegments(1).appendSegment("XMI.xsd"); 2454 Resource otherXSDSchemaResource = resourceSet.createResource(otherURI); 2455 otherXSDSchemaResource.getContents().add(otherXSDSchema); 2456 try 2457 { 2458 otherXSDSchemaResource.save(Collections.EMPTY_MAP); 2459 } 2460 catch (IOException exception) 2461 { 2462 CodeGenEcorePlugin.INSTANCE.log(exception); 2463 } 2464 } 2465 if (i.hasNext()) 2466 { 2467 Object mappingRoot = i.next(); 2468 URI mappingURI = getEcorePackage().eResource().getURI().trimSegments(1).appendSegment(getPrefix() + type + ".xsd2ecore"); 2469 Resource mappingResource = resourceSet.createResource(mappingURI); 2470 mappingResource.getContents().add(mappingRoot); 2471 try 2472 { 2473 mappingResource.save(Collections.EMPTY_MAP); 2474 } 2475 catch (IOException exception) 2476 { 2477 CodeGenEcorePlugin.INSTANCE.log(exception); 2478 } 2479 } 2480 } 2481 } 2482 catch (InstantiationException exception) 2483 { 2484 CodeGenEcorePlugin.INSTANCE.log(exception); 2485 } 2486 catch (NoSuchMethodException exception) 2487 { 2488 CodeGenEcorePlugin.INSTANCE.log(exception); 2489 } 2490 catch (IllegalAccessException exception) 2491 { 2492 CodeGenEcorePlugin.INSTANCE.log(exception); 2493 } 2494 catch (InvocationTargetException exception) 2495 { 2496 CodeGenEcorePlugin.INSTANCE.log(exception); 2497 } 2498 } 2499 catch (ClassNotFoundException exception) 2500 { 2501 } 2503 } 2504 } 2505 2506 public void generatePackageSerialization(IProgressMonitor progressMonitor) 2507 { 2508 try 2509 { 2510 if (!canGenerate() || !isLoadingInitialization()) return; 2511 2512 String outputFile = getGenModel().getModelDirectory() + "/" + getClassPackageName().replace('.', '/') + "/" + getSerializedPackageFilename(); 2513 2514 progressMonitor.beginTask("", 2); 2515 progressMonitor.subTask(CodeGenEcorePlugin.INSTANCE.getString("_UI_GeneratingPackageSerialization_message", new Object [] { outputFile })); 2516 2517 IPath outputFilePath = new Path(outputFile); 2518 findOrCreateContainer 2519 (new SubProgressMonitor(progressMonitor, 1), 2520 Generator.EMF_MODEL_PROJECT_STYLE, 2521 getGenModel().getEffectiveModelPluginVariables(), 2522 outputFilePath.removeLastSegments(1), 2523 false); 2524 2525 URI outputURI = URI.createPlatformResourceURI(outputFilePath.toString()); 2526 Resource outputResource = getEcorePackage().eResource(); 2527 ResourceSet set = outputResource.getResourceSet(); 2528 2529 Map oldURIs = new HashMap (); 2530 2531 for (Iterator i = set.getResources().iterator(); i.hasNext(); ) 2535 { 2536 Resource resource = (Resource)i.next(); 2537 List contents = resource.getContents(); 2538 2539 if (!contents.isEmpty() && contents.get(0) instanceof EPackage) 2540 { 2541 EPackage ePackage = (EPackage)contents.get(0); 2542 oldURIs.put(resource, resource.getURI()); 2543 resource.setURI(resource == outputResource ? outputURI : URI.createURI(ePackage.getNsURI())); 2544 } 2545 } 2546 2547 try 2548 { 2549 outputResource.save(null); 2550 } 2551 catch (IOException exception) 2552 { 2553 CodeGenEcorePlugin.INSTANCE.log(exception); 2554 } 2555 2556 for (Iterator i = set.getResources().iterator(); i.hasNext(); ) 2559 { 2560 Resource resource = (Resource)i.next(); 2561 List contents = resource.getContents(); 2562 2563 if (!contents.isEmpty() && contents.get(0) instanceof EPackage) 2564 { 2565 resource.setURI((URI)oldURIs.get(resource)); 2566 } 2567 } 2568 2569 progressMonitor.worked(1); 2570 } 2571 finally 2572 { 2573 progressMonitor.done(); 2574 } 2575 } 2576 2577 2581 public String getProviderPackageName() 2582 { 2583 return getQualifiedPackageName(getProviderPackageSuffix()); 2584 } 2585 2586 public String getPresentationPackageName() 2587 { 2588 return getQualifiedPackageName(getPresentationPackageSuffix()); 2589 } 2590 2591 protected String getQualifiedPackageName(String suffix) 2592 { 2593 String name = getQualifiedPackageName(); 2594 return isBlank(suffix) ? name : name + "." + suffix; 2595 } 2596 2597 public String getQualifiedPackageName() 2598 { 2599 String name = safeName(getPackageName()); 2600 if (!isBlank(getBasePackage())) 2601 { 2602 name = getBasePackage() + "." + name; 2603 } 2604 return name; 2605 } 2606 2607 2612 public String getItemProviderAdapterFactoryClassName() 2613 { 2614 return getPrefixedName("ItemProviderAdapterFactory"); 2615 } 2616 2617 public String getQualifiedItemProviderAdapterFactoryClassName() 2618 { 2619 return getProviderPackageName() + "." + getItemProviderAdapterFactoryClassName(); 2620 } 2621 2622 public String getImportedItemProviderAdapterFactoryClassName() 2623 { 2624 return getGenModel().getImportedName(getQualifiedItemProviderAdapterFactoryClassName()); 2625 } 2626 2627 public String getEditorClassName() 2628 { 2629 return getPrefixedName("Editor"); 2630 } 2631 2632 public String getQualifiedEditorClassName() 2633 { 2634 return getPresentationPackageName() + "." + getEditorClassName(); 2635 } 2636 2637 public String getImportedEditorClassName() 2638 { 2639 return getGenModel().getImportedName(getQualifiedEditorClassName()); 2640 } 2641 2642 public String getModelWizardClassName() 2643 { 2644 return getPrefixedName("ModelWizard"); 2645 } 2646 2647 public String getQualifiedModelWizardClassName() 2648 { 2649 return getPresentationPackageName() + "." + getModelWizardClassName(); 2650 } 2651 2652 public String getImportedModelWizardClassName() 2653 { 2654 return getGenModel().getImportedName(getQualifiedModelWizardClassName()); 2655 } 2656 2657 public String getActionBarContributorClassName() 2658 { 2659 return getPrefixedName("ActionBarContributor"); 2660 } 2661 2662 public String getQualifiedActionBarContributorClassName() 2663 { 2664 return getPresentationPackageName() + "." + getActionBarContributorClassName(); 2665 } 2666 2667 public String getImportedActionBarContributorClassName() 2668 { 2669 return getGenModel().getImportedName(getQualifiedActionBarContributorClassName()); 2670 } 2671 2672 public String getAdapterFactoryDelegateName(GenPackage genDelegate) 2673 { 2674 String result = genDelegate.getAdapterFactoryClassName(); 2675 if (!result.equals(genDelegate.getImportedAdapterFactoryClassName())) 2676 { 2677 int count = getAdapterDelegatePackages().indexOf(genDelegate); 2678 result += "_" + count; 2679 } 2680 return result; 2681 } 2682 2683 public String getUncapAdapterFactoryDelegateName(GenPackage genDelegate) 2684 { 2685 return uncapPrefixedName(getAdapterFactoryDelegateName(genDelegate), true); 2686 } 2687 2688 2692 public String getEditPluginClassName() 2693 { 2694 return getGenModel().getEditPluginClassName(); 2696 } 2697 2698 public String getQualifiedEditPluginClassName() 2699 { 2700 return getGenModel().getQualifiedEditPluginClassName(); 2702 } 2703 2704 public String getImportedEditPluginClassName() 2705 { 2706 return getGenModel().getImportedName(getQualifiedEditPluginClassName()); 2707 } 2708 2709 public String getEditorPluginClassName() 2710 { 2711 return getGenModel().getEditorPluginClassName(); 2713 } 2714 2715 public String getQualifiedEditorPluginClassName() 2716 { 2717 return getGenModel().getQualifiedEditorPluginClassName(); 2718 } 2720 2721 public String getImportedEditorPluginClassName() 2722 { 2723 return getGenModel().getImportedName(getQualifiedEditorPluginClassName()); 2724 } 2725 2726 public String getCapPackageID() 2727 { 2728 return capName(getPackageID()); 2729 } 2730 2731 public List getAllGenFeatures() 2732 { 2733 List result = new ArrayList (); 2734 2735 List delegated = new ArrayList (); 2738 2739 for (Iterator iter = getGenClasses().iterator(); iter.hasNext(); ) 2740 { 2741 GenClass genClass = (GenClass)iter.next(); 2742 for (Iterator fIter = genClass.getGenFeatures().iterator(); fIter.hasNext(); ) 2743 { 2744 GenFeature genFeature = (GenFeature)fIter.next(); 2745 result.add(genFeature); 2746 delegated.addAll(genFeature.getDelegatedFeatures()); 2747 } 2748 } 2749 2750 if (!delegated.isEmpty()) 2753 { 2754 addNonDuplicates(result, delegated, null); 2755 } 2756 return result; 2757 } 2758 2759 public List getFilteredAllGenFeatures() 2760 { 2761 ArrayList result = new ArrayList (); 2762 2763 HashSet noDupHash = new HashSet (); 2768 for (Iterator iter = getGenClasses().iterator(); iter.hasNext(); ) 2769 { 2770 GenClass genClass = (GenClass)iter.next(); 2771 for (Iterator fIter = genClass.getGenFeatures().iterator(); fIter.hasNext(); ) 2772 { 2773 GenFeature genFeature = (GenFeature)fIter.next(); 2774 if (noDupHash.add(genFeature.getGenClass().getName() + genFeature.getName())) 2775 { 2776 result.add(genFeature); 2777 } 2778 } 2779 } 2780 2781 return result; 2782 } 2783 2784 public List getAdapterDelegatePackages() 2785 { 2786 List result = new ArrayList (); 2787 2788 2790 return result; 2791 } 2792 2793 public List getAdapterDelegateSuperClasses() 2794 { 2795 List result = new ArrayList (); 2796 2797 2799 return result; 2800 } 2801 2802 public boolean hasStatefulProvider() 2803 { 2804 for (Iterator iter = getGenClasses().iterator(); iter.hasNext(); ) 2805 { 2806 GenClass genClass = (GenClass)iter.next(); 2807 if (!genClass.isAbstract() && genClass.getProvider() == GenProviderKind.STATEFUL_LITERAL) 2808 { 2809 return true; 2810 } 2811 } 2812 return false; 2813 } 2814 2815 public void generateEdit(IProgressMonitor progressMonitor) 2816 { 2817 try 2818 { 2819 if (!canGenerateEdit()) return; 2820 2821 progressMonitor.beginTask("", getGenClasses().size() + getNestedGenPackages().size() + 2); progressMonitor.subTask 2823 (CodeGenEcorePlugin.INSTANCE.getString 2824 ("_UI_GeneratingItemProvidersForPackage_message", new Object [] { getPackageInterfaceName() })); 2825 2826 if (hasClassifiers()) 2827 { 2828 for (Iterator iter = getGenClasses().iterator(); iter.hasNext(); ) 2829 { 2830 GenClass genClass = (GenClass)iter.next(); 2831 if (genClass.getProvider() == GenProviderKind.NONE_LITERAL) continue; 2832 progressMonitor.subTask 2833 (CodeGenEcorePlugin.INSTANCE.getString 2834 ("_UI_GeneratingItemProviderFor_message", new Object [] { genClass.getFormattedName() })); 2835 genClass.generateEdit(new SubProgressMonitor(progressMonitor, 1)); 2836 } 2837 2838 progressMonitor.subTask 2839 (CodeGenEcorePlugin.INSTANCE.getString 2840 ("_UI_GeneratingJavaClass_message", 2841 new Object [] { getProviderPackageName() + "." + getItemProviderAdapterFactoryClassName() })); 2842 generate 2843 (new SubProgressMonitor(progressMonitor, 1), 2844 Generator.EMF_EDIT_PROJECT_STYLE, 2845 getGenModel().getEffectiveModelPluginVariables(), 2846 getGenModel().getEditDirectory(), 2847 getProviderPackageName(), 2848 getItemProviderAdapterFactoryClassName(), 2849 getGenModel().getItemProviderAdapterFactoryEmitter()); 2850 } 2851 2852 for (Iterator nestedGenPackages = getNestedGenPackages().iterator(); nestedGenPackages.hasNext(); ) 2853 { 2854 GenPackage nestedGenPackage = (GenPackage)nestedGenPackages.next(); 2855 nestedGenPackage.generateEdit(new SubProgressMonitor(progressMonitor, 1)); 2856 } 2857 } 2858 finally 2859 { 2860 progressMonitor.done(); 2861 } 2862 } 2863 2864 public void generateEditor(IProgressMonitor progressMonitor) 2865 { 2866 try 2867 { 2868 if (!canGenerateEditor()) return; 2869 2870 progressMonitor.beginTask("", 7); progressMonitor.subTask 2872 (CodeGenEcorePlugin.INSTANCE.getString 2873 ("_UI_GeneratingEditorForPackage_message", new Object [] { getPackageInterfaceName() })); 2874 2875 if (hasClassifiers() && hasConcreteClasses()) 2876 { 2877 progressMonitor.subTask 2878 (CodeGenEcorePlugin.INSTANCE.getString 2879 ("_UI_GeneratingJavaClass_message", new Object [] { getQualifiedEditorClassName() })); 2880 generate 2881 (new SubProgressMonitor(progressMonitor, 1), 2882 Generator.EMF_EDITOR_PROJECT_STYLE, 2883 getGenModel().getEffectiveModelPluginVariables(), 2884 getGenModel().getEditorDirectory(), 2885 getPresentationPackageName(), 2886 getEditorClassName(), 2887 getGenModel().getEditorEmitter()); 2888 2889 progressMonitor.subTask 2890 (CodeGenEcorePlugin.INSTANCE.getString 2891 ("_UI_GeneratingJavaClass_message", new Object [] { getQualifiedModelWizardClassName() })); 2892 generate 2893 (new SubProgressMonitor(progressMonitor, 1), 2894 Generator.EMF_EDITOR_PROJECT_STYLE, 2895 getGenModel().getEffectiveModelPluginVariables(), 2896 getGenModel().getEditorDirectory(), 2897 getPresentationPackageName(), 2898 getModelWizardClassName(), 2899 getGenModel().getModelWizardEmitter()); 2900 2901 progressMonitor.subTask 2902 (CodeGenEcorePlugin.INSTANCE.getString 2903 ("_UI_GeneratingJavaClass_message", new Object [] { getQualifiedActionBarContributorClassName() })); 2904 generate 2905 (new SubProgressMonitor(progressMonitor, 1), 2906 Generator.EMF_EDITOR_PROJECT_STYLE, 2907 getGenModel().getEffectiveModelPluginVariables(), 2908 getGenModel().getEditorDirectory(), 2909 getPresentationPackageName(), 2910 getActionBarContributorClassName(), 2911 getGenModel().getActionBarContributorEmitter()); 2912 2913 progressMonitor.subTask 2914 (CodeGenEcorePlugin.INSTANCE.getString 2915 ("_UI_GeneratingModelIcon_message", new Object [] { getModelIconFileName() })); 2916 generate 2917 (new SubProgressMonitor(progressMonitor, 1), 2918 Generator.EMF_EDIT_PROJECT_STYLE, 2919 getGenModel().getEffectiveModelPluginVariables(), 2920 getModelIconFileName(), 2921 ((GenModelImpl)getGenModel()).getModelGIFEmitter(), 2922 getPrefix()); 2923 2924 progressMonitor.subTask 2925 (CodeGenEcorePlugin.INSTANCE.getString 2926 ("_UI_GeneratingModelWizardIcon_message", new Object [] { getModelWizardIconFileName() })); 2927 generate 2928 (new SubProgressMonitor(progressMonitor, 1), 2929 Generator.EMF_EDIT_PROJECT_STYLE, 2930 getGenModel().getEffectiveModelPluginVariables(), 2931 getModelWizardIconFileName(), 2932 ((GenModelImpl)getGenModel()).getModelWizardGIFEmitter(), 2933 getPrefix()); 2934 } 2935 2936 for (Iterator nestedGenPackages = getNestedGenPackages().iterator(); nestedGenPackages.hasNext(); ) 2937 { 2938 GenPackage nestedGenPackage = (GenPackage)nestedGenPackages.next(); 2939 nestedGenPackage.generateEditor(new SubProgressMonitor(progressMonitor, 1)); 2940 } 2941 } 2942 finally 2943 { 2944 progressMonitor.done(); 2945 } 2946 } 2947 2948 public boolean hasTests() 2949 { 2950 for (Iterator i = getGenClasses().iterator(); i.hasNext();) 2951 { 2952 if (((GenClass)i.next()).hasTests()) 2953 { 2954 return true; 2955 } 2956 } 2957 2958 return false; 2959 } 2960 2961 public boolean canGenerateTests() 2962 { 2963 return getGenModel().canGenerateTests() && hasClassifiers(true); 2964 } 2965 2966 public void generateTests(IProgressMonitor progressMonitor) 2967 { 2968 try 2969 { 2970 if (!canGenerateTests()) 2971 return; 2972 2973 progressMonitor.beginTask("", getGenClasses().size() + getNestedGenPackages().size()); 2974 2975 if (hasClassifiers()) 2976 { 2977 progressMonitor.subTask(CodeGenEcorePlugin.INSTANCE.getString( 2978 "_UI_GeneratingJavaClass_message", 2979 new Object []{ getQualifiedTestSuiteClassName() })); 2980 2981 generate( 2982 new SubProgressMonitor(progressMonitor, 1), 2983 Generator.EMF_TESTS_PROJECT_STYLE, 2984 getGenModel().getEffectiveModelPluginVariables(), 2985 getGenModel().getTestsDirectory(), 2986 getTestsPackageName(), 2987 getTestSuiteClassName(), 2988 getGenModel().getPackageTestSuiteEmitter()); 2989 2990 if (isGenerateExampleClass()) 2991 { 2992 generate( 2993 new SubProgressMonitor(progressMonitor, 1), 2994 Generator.EMF_TESTS_PROJECT_STYLE, 2995 getGenModel().getEffectiveModelPluginVariables(), 2996 getGenModel().getTestsDirectory(), 2997 getTestsPackageName(), 2998 getExampleClassName(), 2999 getGenModel().getPackageExampleEmitter()); 3000 } 3001 3002 for (Iterator genClasses = getGenClasses().iterator(); genClasses.hasNext();) 3003 { 3004 GenClass genClass = (GenClass)genClasses.next(); 3005 progressMonitor.subTask(CodeGenEcorePlugin.INSTANCE.getString( 3006 "_UI_Generating_message", 3007 new Object []{ genClass.getFormattedName() })); 3008 genClass.generateTests(new SubProgressMonitor(progressMonitor, 1)); 3009 } 3010 } 3011 3012 for (Iterator nestedGenPackages = getNestedGenPackages().iterator(); nestedGenPackages.hasNext();) 3013 { 3014 ((GenPackage)nestedGenPackages.next()).generateTests(new SubProgressMonitor(progressMonitor, 1)); 3015 } 3016 } 3017 finally 3018 { 3019 progressMonitor.done(); 3020 } 3021 } 3022 3023 public String getModelIconFileName() 3024 { 3025 return getGenModel().getEditorIconsDirectory() + "/full/obj16/" + getPrefix() + "ModelFile.gif"; 3026 } 3027 3028 public String getModelWizardIconFileName() 3029 { 3030 return getGenModel().getEditorIconsDirectory() + "/full/wizban/New" + getPrefix() + ".gif"; 3031 } 3032 3033 public boolean hasClassifiers() 3034 { 3035 return getGenClasses().size() + getGenEnums().size() + getGenDataTypes().size() != 0; 3036 } 3037 3038 public boolean hasClassifiers(boolean traverseNestedPackages) 3039 { 3040 if (hasClassifiers()) 3041 { 3042 return true; 3043 } 3044 else if (traverseNestedPackages) 3045 { 3046 for (Iterator i = getNestedGenPackages().iterator(); i.hasNext();) 3047 { 3048 GenPackage genPackage = (GenPackage)i.next(); 3049 if(genPackage.hasClassifiers(true)) 3050 { 3051 return true; 3052 } 3053 } 3054 } 3055 return false; 3056 } 3057 3058 public String getModelInfo() 3059 { 3060 StringBuffer result = new StringBuffer (); 3061 appendModelSetting(result, "kind", "package"); 3062 return result.toString().trim(); 3063 } 3064 3065 public boolean reconcile(GenPackage oldGenPackageVersion) 3066 { 3067 if (getEcorePackage().getNsURI() == null ? 3068 getEcorePackage().getName().equals(oldGenPackageVersion.getEcorePackage().getName()) : 3069 getEcorePackage().getNsURI().equals(oldGenPackageVersion.getEcorePackage().getNsURI())) 3070 { 3071 for (Iterator i = getGenClassifiers().iterator(); i.hasNext(); ) 3072 { 3073 GenClassifier genClassifier = (GenClassifier)i.next(); 3074 for (Iterator j = oldGenPackageVersion.getGenClassifiers().iterator(); j.hasNext(); ) 3075 { 3076 GenClassifier oldGenClassifierVersion = (GenClassifier)j.next(); 3077 if (genClassifier instanceof GenEnum) 3078 { 3079 if (oldGenClassifierVersion instanceof GenEnum && 3080 ((GenEnum)genClassifier).reconcile((GenEnum)oldGenClassifierVersion)) 3081 { 3082 break; 3083 } 3084 } 3085 else if (genClassifier instanceof GenDataType) 3086 { 3087 if (oldGenClassifierVersion instanceof GenDataType && 3088 !(oldGenClassifierVersion instanceof GenEnum) && 3089 ((GenDataType)genClassifier).reconcile((GenDataType)oldGenClassifierVersion)) 3090 { 3091 break; 3092 } 3093 } 3094 else if (genClassifier instanceof GenClass) 3095 { 3096 if (oldGenClassifierVersion instanceof GenClass && 3097 ((GenClass)genClassifier).reconcile((GenClass)oldGenClassifierVersion)) 3098 { 3099 break; 3100 } 3101 } 3102 } 3103 } 3104 3105 for (Iterator i = getNestedGenPackages().iterator(); i.hasNext(); ) 3106 { 3107 GenPackage nestedGenPackage = (GenPackage)i.next(); 3108 for (Iterator j = oldGenPackageVersion.getNestedGenPackages().iterator(); j.hasNext(); ) 3109 { 3110 GenPackage oldNestedGenPackageVersion = (GenPackage)j.next(); 3111 if (nestedGenPackage.reconcile(oldNestedGenPackageVersion)) 3112 { 3113 break; 3114 } 3115 } 3116 } 3117 3118 reconcileSettings(oldGenPackageVersion); 3119 return true; 3120 } 3121 else 3122 { 3123 return false; 3124 } 3125 } 3126 3127 protected void reconcileSettings(GenPackage oldGenPackageVersion) 3128 { 3129 setPrefix(oldGenPackageVersion.getPrefix()); 3130 setBasePackage(oldGenPackageVersion.getBasePackage()); 3131 setResource(oldGenPackageVersion.getResource()); 3132 setAdapterFactory(oldGenPackageVersion.isAdapterFactory()); 3133 setLoadInitialization(oldGenPackageVersion.isLoadInitialization()); 3134 setDisposableProviderFactory(oldGenPackageVersion.isDisposableProviderFactory()); 3135 3136 setInterfacePackageSuffix(oldGenPackageVersion.getInterfacePackageSuffix()); 3137 setClassPackageSuffix(oldGenPackageVersion.getClassPackageSuffix()); 3138 setUtilityPackageSuffix(oldGenPackageVersion.getUtilityPackageSuffix()); 3139 setProviderPackageSuffix(oldGenPackageVersion.getProviderPackageSuffix()); 3140 setPresentationPackageSuffix(oldGenPackageVersion.getPresentationPackageSuffix()); 3141 setTestsPackageSuffix(oldGenPackageVersion.getTestsPackageSuffix()); 3142 setGenerateExampleClass(oldGenPackageVersion.isGenerateExampleClass()); 3143 } 3144 3145 public boolean reconcile() 3146 { 3147 EPackage ePackage = getEcorePackage(); 3148 if (ePackage == null || ePackage.eIsProxy() || ePackage.eResource() == null) 3149 { 3150 return false; 3151 } 3152 else 3153 { 3154 for (Iterator i = getGenClassifiers().iterator(); i.hasNext(); ) 3155 { 3156 GenClassifier genClassifier = (GenClassifier)i.next(); 3157 if (!genClassifier.reconcile()) 3158 { 3159 i.remove(); 3160 } 3161 } 3162 3163 for (Iterator i = getNestedGenPackages().iterator(); i.hasNext(); ) 3164 { 3165 GenPackage nestedGenPackage = (GenPackage)i.next(); 3166 if (!nestedGenPackage.reconcile()) 3167 { 3168 i.remove(); 3169 } 3170 } 3171 3172 initialize(ePackage); 3173 return true; 3174 } 3175 } 3176 3177 public List getAnnotationSources() 3178 { 3179 List result = new UniqueEList(); 3180 EPackage ePackage = getEcorePackage(); 3181 for (TreeIterator i = ePackage.eAllContents(); i.hasNext(); ) 3182 { 3183 Object object = i.next(); 3184 if (object instanceof EPackage) 3185 { 3186 i.prune(); 3187 } 3188 else if (object instanceof EAnnotation) 3189 { 3190 EAnnotation eAnnotation = (EAnnotation)object; 3191 String source = eAnnotation.getSource(); 3192 3193 if (source == null || !source.equals(GenModelPackage.eNS_URI) || eAnnotation.getDetails().containsKey("body")) 3196 { 3197 result.add(source); 3198 } 3199 } 3200 } 3201 return result; 3202 } 3203 3204 public String getAnnotationSourceIdentifier(String annotationSource) 3205 { 3206 String result = annotationSource; 3207 if (annotationSource == null) 3208 { 3209 return "Null"; 3210 } 3211 else 3212 { 3213 int index = result.lastIndexOf("/"); 3214 if (index == result.length() - 1) 3215 { 3216 result = result.substring(0, index); 3217 index = result.lastIndexOf("/"); 3218 } 3219 if (index != -1) 3220 { 3221 result = result.substring(index + 1); 3222 } 3223 index = result.indexOf("."); 3224 if (index != -1) 3225 { 3226 result = result.substring(0, index); 3227 } 3228 return capName(result); 3229 } 3230 } 3231 3232 public List getAllAnnotations() 3233 { 3234 List result = new UniqueEList(); 3235 EPackage ePackage = getEcorePackage(); 3236 for (TreeIterator i = ePackage.eAllContents(); i.hasNext(); ) 3237 { 3238 Object object = i.next(); 3239 if (object instanceof EPackage) 3240 { 3241 i.prune(); 3242 } 3243 else if (object instanceof EAnnotation) 3244 { 3245 result.add(object); 3246 i.prune(); 3247 } 3248 } 3249 return result; 3250 } 3251 3252 public String getAnnotatedModelElementAccessor(EAnnotation eAnnotation) 3253 { 3254 EModelElement eModelElement = eAnnotation.getEModelElement(); 3255 String result = 3256 (String ) 3257 new EcoreSwitch() 3258 { 3259 public Object caseEPackage(EPackage ePackage) 3260 { 3261 return "this"; 3262 } 3263 3264 public Object caseEClassifier(EClassifier eClassifier) 3265 { 3266 return findGenClassifier(eClassifier).getClassifierInstanceName(); 3267 } 3268 3269 public Object caseEStructuralFeature(EStructuralFeature eStructuralFeature) 3270 { 3271 return "get" + findGenFeature(eStructuralFeature).getFeatureAccessorName() + "()"; 3272 } 3273 3274 public Object caseEOperation(EOperation eOperation) 3275 { 3276 EClass eClass = eOperation.getEContainingClass(); 3277 return 3278 "(" + 3279 getGenModel().getImportedName("org.eclipse.emf.ecore.EOperation") + 3280 ")" + 3281 caseEClassifier(eClass) + 3282 ".getEOperations().get(" + 3283 eClass.getEOperations().indexOf(eOperation) + 3284 ")"; 3285 } 3286 public Object caseEEnumLiteral(EEnumLiteral eEnumLiteral) 3287 { 3288 EEnum eEnum = eEnumLiteral.getEEnum(); 3289 return 3290 "(" + 3291 getGenModel().getImportedName("org.eclipse.emf.ecore.EEnumLiteral") + 3292 ")" + 3293 caseEClassifier(eEnum) + 3294 ".getELiterals().get(" + 3295 eEnum.getELiterals().indexOf(eEnumLiteral) + 3296 ")"; 3297 } 3298 3299 public Object caseEParameter(EParameter eParameter) 3300 { 3301 EOperation eOperation = eParameter.getEOperation(); 3302 return 3303 "(" + 3304 getGenModel().getImportedName("org.eclipse.emf.ecore.EParameter") + 3305 ")(" + 3306 caseEOperation(eOperation) + 3307 ").getEParameters().get(" + 3308 eOperation.getEParameters().indexOf(eParameter) + 3309 ")"; 3310 } 3311 }.doSwitch(eModelElement); 3312 3313 return result; 3314 } 3315 3316 public String getResourceClassName() 3317 { 3318 return getPrefix() + "ResourceImpl"; 3319 } 3320 3321 public String getQualifiedResourceClassName() 3322 { 3323 return getUtilitiesPackageName() + "." + getResourceClassName(); 3324 } 3325 3326 public String getImportedResourceClassName() 3327 { 3328 return getGenModel().getImportedName(getQualifiedResourceClassName()); 3329 } 3330 3331 public String getImportedResourceBaseClassName() 3332 { 3333 switch (getResource().getValue()) 3334 { 3335 case GenResourceKind.XML: 3336 return getGenModel().getImportedName("org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl"); 3337 case GenResourceKind.XMI: 3338 return getGenModel().getImportedName("org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl"); 3339 default: 3340 return getGenModel().getImportedName("org.eclipse.emf.ecore.resource.impl.ResourceImpl"); 3341 } 3342 } 3343 3344 public String getResourceFactoryClassName() 3345 { 3346 return getPrefix() + "ResourceFactoryImpl"; 3347 } 3348 3349 public String getQualifiedResourceFactoryClassName() 3350 { 3351 return getUtilitiesPackageName() + "." + getResourceFactoryClassName(); 3352 } 3353 3354 public String getImportedResourceFactoryClassName() 3355 { 3356 return getGenModel().getImportedName(getQualifiedResourceFactoryClassName()); 3357 } 3358 3359 public String getImportedResourceFactoryBaseClassName() 3360 { 3361 return getGenModel().getImportedName("org.eclipse.emf.ecore.resource.impl.ResourceFactoryImpl"); 3362 } 3363 3364 public boolean hasDocumentRoot() 3365 { 3366 if (getResource() != GenResourceKind.XML_LITERAL) 3367 { 3368 return false; 3369 } 3370 3371 return getExtendedMetaData().getDocumentRoot(getEcorePackage()) != null; 3372 } 3373 3374 public boolean hasExtendedMetaData() 3375 { 3376 if (getResource() != GenResourceKind.XML_LITERAL) 3377 { 3378 return false; 3379 } 3380 return hasExtendedMetaData(getEcorePackage()); 3381 } 3382 3383 protected static boolean hasExtendedMetaData(EPackage ePackage) 3384 { 3385 for (TreeIterator i = ePackage.eAllContents(); i.hasNext(); ) 3386 { 3387 Object object = i.next(); 3388 if (object instanceof EPackage) 3389 { 3390 i.prune(); 3391 } 3392 else if (object instanceof EAnnotation) 3393 { 3394 EAnnotation eAnnotation = (EAnnotation)object; 3395 String source = eAnnotation.getSource(); 3396 if (ExtendedMetaData.ANNOTATION_URI.equals(source)) 3397 { 3398 return true; 3399 } 3400 } 3401 } 3402 3403 return false; 3404 } 3405 3406 public boolean hasXMLMap() 3407 { 3408 if (getResource() != GenResourceKind.XML_LITERAL) 3409 { 3410 return false; 3411 } 3412 3413 EAnnotation eAnnotation = getEcorePackage().getEAnnotation(XSD2ECORE_URI); 3414 return eAnnotation != null; 3415 } 3416 3417 public boolean hasTargetNamespace() 3418 { 3419 if (hasExtendedMetaData()) 3420 { 3421 return getExtendedMetaData().getNamespace(getEcorePackage()) != null; 3422 } 3423 3424 EAnnotation eAnnotation = getEcorePackage().getEAnnotation(XSD2ECORE_URI); 3425 return eAnnotation == null || eAnnotation.getDetails().get("targetNamespace") != null; 3426 } 3427 3428 public String getSerializedPackageFilename() 3429 { 3430 return getName() + ".ecore"; 3431 } 3432 3433 protected boolean isBigModel() 3434 { 3435 int classes = getGenClasses().size(); 3436 int supers = 0; 3437 int features = 0; 3438 int operations = 0; 3439 int parameters = 0; 3440 int exceptions = 0; 3441 3442 for (Iterator i = getGenClasses().iterator(); i.hasNext(); ) 3443 { 3444 GenClass genClass = (GenClass)i.next(); 3445 supers += genClass.getEcoreClass().getESuperTypes().size(); 3446 features += genClass.getGenFeatures().size(); 3447 operations += genClass.getGenOperations().size(); 3448 3449 for (Iterator j = genClass.getGenOperations().iterator(); j.hasNext(); ) 3450 { 3451 GenOperation genOperation = (GenOperation)j.next(); 3452 parameters += genOperation.getGenParameters().size(); 3453 exceptions += genOperation.getEcoreOperation().getEExceptions().size(); 3454 } 3455 } 3456 3457 int enums = getGenEnums().size(); 3458 int literals = 0; 3459 3460 for (Iterator i = getGenEnums().iterator(); i.hasNext(); ) 3461 { 3462 GenEnum genEnum = (GenEnum)i.next(); 3463 literals += genEnum.getGenEnumLiterals().size(); 3464 } 3465 3466 int datatypes = getGenDataTypes().size(); 3467 3468 return (classes + supers + features + operations + parameters + exceptions + enums + literals + datatypes) > 500; 3469 } 3470 3471 public List getProviderSupportedTypes() 3472 { 3473 List result = new ArrayList (); 3474 result.add("org.eclipse.emf.edit.provider.IEditingDomainItemProvider"); 3475 result.add("org.eclipse.emf.edit.provider.IStructuredItemContentProvider"); 3476 result.add("org.eclipse.emf.edit.provider.ITreeItemContentProvider"); 3477 result.add("org.eclipse.emf.edit.provider.IItemLabelProvider"); 3478 result.add("org.eclipse.emf.edit.provider.IItemPropertySource"); 3479 return result; 3480 } 3481 3482 public GenClass getRootClass() 3483 { 3484 GenFeature rootFeature = getRootFeature(); 3485 if (rootFeature == null) 3486 { 3487 for (Iterator i = getGenClasses().iterator(); i.hasNext();) 3488 { 3489 GenClass genClass = (GenClass)i.next(); 3490 if (!genClass.isAbstract()) 3491 { 3492 return genClass; 3493 } 3494 } 3495 return null; 3496 } 3497 else 3498 { 3499 return rootFeature.getTypeGenClass(); 3500 } 3501 } 3502 3503 public GenFeature getRootFeature() 3504 { 3505 EClass documentRoot = getExtendedMetaData().getDocumentRoot(getEcorePackage()); 3506 if (documentRoot != null) 3507 { 3508 for (Iterator i = getExtendedMetaData().getAllElements(documentRoot).iterator(); i.hasNext();) 3509 { 3510 EStructuralFeature eStructuralFeature = (EStructuralFeature)i.next(); 3511 if (eStructuralFeature instanceof EReference && !((EClass)eStructuralFeature.getEType()).isAbstract()) 3512 { 3513 return findGenFeature(eStructuralFeature); 3514 } 3515 } 3516 } 3517 return null; 3518 } 3519 3520 public boolean hasConcreteClasses() 3521 { 3522 for (Iterator i = getGenClasses().iterator(); i.hasNext(); ) 3523 { 3524 GenClass genClass = (GenClass)i.next(); 3525 if (!genClass.isAbstract()) 3526 { 3527 return true; 3528 } 3529 } 3530 return false; 3531 } 3532} | Popular Tags |