1 17 package org.eclipse.emf.ecore.util; 18 19 20 import java.util.ArrayList ; 21 import java.util.Collection ; 22 import java.util.Collections ; 23 import java.util.HashMap ; 24 import java.util.Hashtable ; 25 import java.util.List ; 26 import java.util.Map ; 27 import java.util.StringTokenizer ; 28 29 import org.eclipse.emf.common.util.EMap; 30 import org.eclipse.emf.common.util.UniqueEList; 31 import org.eclipse.emf.ecore.EAnnotation; 32 import org.eclipse.emf.ecore.EAttribute; 33 import org.eclipse.emf.ecore.EClass; 34 import org.eclipse.emf.ecore.EClassifier; 35 import org.eclipse.emf.ecore.EDataType; 36 import org.eclipse.emf.ecore.EModelElement; 37 import org.eclipse.emf.ecore.EPackage; 38 import org.eclipse.emf.ecore.EReference; 39 import org.eclipse.emf.ecore.EStructuralFeature; 40 import org.eclipse.emf.ecore.ETypedElement; 41 import org.eclipse.emf.ecore.EcoreFactory; 42 import org.eclipse.emf.ecore.EcorePackage; 43 import org.eclipse.emf.ecore.xml.type.XMLTypePackage; 44 45 46 49 public class BasicExtendedMetaData implements ExtendedMetaData 50 { 51 protected String annotationURI; 52 protected EPackage.Registry registry; 53 protected EPackage.Registry demandRegistry; 54 protected Map extendedMetaDataHolderCache; 55 protected Map annotationMap; 56 57 public BasicExtendedMetaData() 58 { 59 this(ANNOTATION_URI, EPackage.Registry.INSTANCE); 60 } 61 62 public BasicExtendedMetaData(EPackage.Registry registry) 63 { 64 this(ANNOTATION_URI, registry); 65 } 66 67 public BasicExtendedMetaData(String annotationURI, EPackage.Registry registry) 68 { 69 this(annotationURI, registry, null); 70 } 71 72 public BasicExtendedMetaData(String annotationURI, EPackage.Registry registry, Map annotationMap) 73 { 74 this.annotationURI = annotationURI.intern(); 75 this.registry = registry; 76 this.demandRegistry = new org.eclipse.emf.ecore.impl.EPackageRegistryImpl(); 77 this.annotationMap = annotationMap; 78 79 if (annotationURI != ANNOTATION_URI) 80 { 81 extendedMetaDataHolderCache = new HashMap (); 82 } 83 } 84 85 protected EAnnotation getAnnotation(EModelElement eModelElement, boolean demandCreate) 86 { 87 if (annotationMap != null) 88 { 89 EAnnotation result = (EAnnotation)annotationMap.get(eModelElement); 90 if (result == null && demandCreate) 91 { 92 result = EcoreFactory.eINSTANCE.createEAnnotation(); 93 result.setSource(annotationURI); 94 annotationMap.put(eModelElement, result); 95 } 96 return result; 97 } 98 else 99 { 100 EAnnotation result = eModelElement.getEAnnotation(annotationURI); 101 if (result == null && demandCreate) 102 { 103 result = EcoreFactory.eINSTANCE.createEAnnotation(); 104 result.setSource(annotationURI); 105 eModelElement.getEAnnotations().add(result); 106 } 107 return result; 108 } 109 } 110 111 public EClassifier getType(EPackage ePackage, String name) 112 { 113 List eClassifiers = ePackage.getEClassifiers(); 114 for (int i = 0, size = eClassifiers.size(); i < size; ++i) 115 { 116 EClassifier eClassifier = (EClassifier)eClassifiers.get(i); 117 if (name.equals(getName(eClassifier))) 118 { 119 return eClassifier; 120 } 121 } 122 return null; 123 } 124 125 public EPackage getPackage(String namespace) 126 { 127 EPackage ePackage = registry.getEPackage(namespace); 128 134 return ePackage; 135 } 136 137 public void putPackage(String namespace, EPackage ePackage) 138 { 139 registry.put(namespace, ePackage); 140 } 141 142 public EClass getDocumentRoot(EPackage ePackage) 143 { 144 return (EClass)getType(ePackage, ""); 145 } 146 147 public void setDocumentRoot(EClass eClass) 148 { 149 setName(eClass, ""); 150 setContentKind(eClass, MIXED_CONTENT); 151 } 152 153 public EReference getXMLNSPrefixMapFeature(EClass eClass) 154 { 155 if (getContentKind(eClass) == MIXED_CONTENT) 156 { 157 List eAllReferences = eClass.getEAllReferences(); 158 for (int i = 0, size = eAllReferences.size(); i < size; ++i) 159 { 160 EReference eReference = (EReference)eAllReferences.get(i); 161 if ("xmlns:prefix".equals(getName(eReference))) 162 { 163 return eReference; 164 } 165 } 166 } 167 168 return null; 169 } 170 171 public EReference getXSISchemaLocationMapFeature(EClass eClass) 172 { 173 if (getContentKind(eClass) == MIXED_CONTENT) 174 { 175 List eAllReferences = eClass.getEAllReferences(); 176 for (int i = 0, size = eAllReferences.size(); i < size; ++i) 177 { 178 EReference eReference = (EReference)eAllReferences.get(i); 179 if ("xsi:schemaLocation".equals(getName(eReference))) 180 { 181 return eReference; 182 } 183 } 184 } 185 186 return null; 187 } 188 189 public boolean isQualified(EPackage ePackage) 190 { 191 return getExtendedMetaData(ePackage).isQualified(); 192 } 193 194 protected boolean basicIsQualified(EPackage ePackage) 195 { 196 EAnnotation eAnnotation = getAnnotation(ePackage, false); 197 return eAnnotation == null || !"false".equals(eAnnotation.getDetails().get("qualified")); 198 } 199 200 public void setQualified(EPackage ePackage, boolean isQualified) 201 { 202 if (!isQualified) 203 { 204 EAnnotation eAnnotation = getAnnotation(ePackage, true); 205 eAnnotation.getDetails().put("qualified", "false"); 206 } 207 else 208 { 209 EAnnotation eAnnotation = getAnnotation(ePackage, false); 210 if (eAnnotation != null) 211 { 212 eAnnotation.getDetails().remove("qualified"); 213 } 214 } 215 getExtendedMetaData(ePackage).setQualified(isQualified); 216 } 217 218 public String getNamespace(EPackage ePackage) 219 { 220 if (isQualified(ePackage)) 221 { 222 return (ePackage).getNsURI(); 223 } 224 else 225 { 226 return null; 227 } 228 } 229 230 public String getNamespace(EClassifier eClassifier) 231 { 232 return getNamespace(eClassifier.getEPackage()); 233 } 234 235 public String getNamespace(EStructuralFeature eStructuralFeature) 236 { 237 return getExtendedMetaData(eStructuralFeature).getNamespace(); 238 } 239 240 public String basicGetNamespace(EStructuralFeature eStructuralFeature) 241 { 242 EAnnotation eAnnotation = getAnnotation(eStructuralFeature, false); 243 if (eAnnotation == null) 244 { 245 return null; 246 } 247 else 248 { 249 String result = (String )eAnnotation.getDetails().get("namespace"); 250 if ("##targetNamespace".equals(result)) 251 { 252 return getNamespace(eStructuralFeature.getEContainingClass().getEPackage()); 253 } 254 else 255 { 256 return result; 257 } 258 } 259 } 260 261 public void setNamespace(EStructuralFeature eStructuralFeature, String namespace) 262 { 263 String packageNamespace = getNamespace(eStructuralFeature.getEContainingClass().getEPackage()); 264 String convertedNamespace = namespace; 265 if (namespace == null ? packageNamespace == null : namespace.equals(packageNamespace)) 266 { 267 convertedNamespace="##targetNamespace"; 268 } 269 270 if (convertedNamespace != null) 271 { 272 EAnnotation eAnnotation = getAnnotation(eStructuralFeature, true); 273 eAnnotation.getDetails().put("namespace", convertedNamespace); 274 } 275 else 276 { 277 EAnnotation eAnnotation = getAnnotation(eStructuralFeature, false); 278 if (eAnnotation != null) 279 { 280 eAnnotation.getDetails().remove("namespace"); 281 } 282 } 283 getExtendedMetaData(eStructuralFeature).setNamespace(namespace); 284 } 285 286 public String getName(EClassifier eClassifier) 287 { 288 return getExtendedMetaData(eClassifier).getName(); 289 } 290 291 protected String basicGetName(EClassifier eClassifier) 292 { 293 EAnnotation eAnnotation = getAnnotation(eClassifier, false); 294 if (eAnnotation != null) 295 { 296 String result = (String )eAnnotation.getDetails().get("name"); 297 if (result != null) 298 { 299 return result; 300 } 301 } 302 return eClassifier.getName(); 303 } 304 305 public void setName(EClassifier eClassifier, String name) 306 { 307 EAnnotation eAnnotation = getAnnotation(eClassifier, true); 308 eAnnotation.getDetails().put("name", name); 309 getExtendedMetaData(eClassifier).setName(name); 310 } 311 312 public boolean isAnonymous(EClassifier eClassifier) 313 { 314 String name = getExtendedMetaData(eClassifier).getName(); 315 return name.length() == 0 || name.indexOf("_._") != -1; 316 } 317 318 public String getName(EStructuralFeature eStructuralFeature) 319 { 320 return getExtendedMetaData(eStructuralFeature).getName(); 321 } 322 323 protected String basicGetName(EStructuralFeature eStructuralFeature) 324 { 325 EAnnotation eAnnotation = getAnnotation(eStructuralFeature, false); 326 if (eAnnotation != null) 327 { 328 String result = (String )eAnnotation.getDetails().get("name"); 329 if (result != null) 330 { 331 return result; 332 } 333 } 334 return eStructuralFeature.getName(); 335 } 336 337 public void setName(EStructuralFeature eStructuralFeature, String name) 338 { 339 EAnnotation eAnnotation = getAnnotation(eStructuralFeature, true); 340 eAnnotation.getDetails().put("name", name); 341 getExtendedMetaData(eStructuralFeature).setName(name); 342 } 343 344 protected String getQualifiedName(String defaultNamespace, EClassifier eClassifier) 345 { 346 String namespace = getNamespace(eClassifier); 347 String name = getName(eClassifier); 348 if (namespace == null) 349 { 350 return namespace == defaultNamespace ? name : "#" + name; 351 } 352 else 353 { 354 return namespace.equals(defaultNamespace) ? name : namespace + "#" + name; 355 } 356 } 357 358 protected String getQualifiedName(String defaultNamespace, EStructuralFeature eStructuralFeature) 359 { 360 String namespace = getNamespace(eStructuralFeature); 361 String name = getName(eStructuralFeature); 362 if (namespace == null) 363 { 364 return namespace == defaultNamespace ? name : "#" + name; 365 } 366 else 367 { 368 return namespace.equals(defaultNamespace) ? name : namespace + "#" + name; 369 } 370 } 371 372 public EClassifier getType(String namespace, String name) 373 { 374 EPackage ePackage = getPackage(namespace); 375 return ePackage == null ? null : getType(ePackage, name); 376 } 377 378 public EStructuralFeature getAttribute(String namespace, String name) 379 { 380 EPackage ePackage = getPackage(namespace); 381 if (ePackage != null) 382 { 383 EClass documentRoot = getDocumentRoot(ePackage); 384 if (documentRoot != null) 385 { 386 return getLocalAttribute(documentRoot, namespace, name); 387 } 388 } 389 390 return null; 391 } 392 393 public EStructuralFeature getElement(String namespace, String name) 394 { 395 EPackage ePackage = getPackage(namespace); 396 if (ePackage != null) 397 { 398 EClass documentRoot = getDocumentRoot(ePackage); 399 if (documentRoot != null) 400 { 401 return getLocalElement(documentRoot, namespace, name); 402 } 403 } 404 405 return null; 406 } 407 408 public int getFeatureKind(EStructuralFeature eStructuralFeature) 409 { 410 return getExtendedMetaData(eStructuralFeature).getFeatureKind(); 411 } 412 413 protected int basicGetFeatureKind(EStructuralFeature eStructuralFeature) 414 { 415 EAnnotation eAnnotation = getAnnotation(eStructuralFeature, false); 416 if (eAnnotation != null) 417 { 418 Object kind = eAnnotation.getDetails().get("kind"); 419 if (kind != null) 420 { 421 for (int i = 1; i < FEATURE_KINDS.length; ++i) 422 { 423 if (FEATURE_KINDS[i].equals(kind)) 424 { 425 return i; 426 } 427 } 428 } 429 } 430 431 return 0; 432 } 433 434 public void setFeatureKind(EStructuralFeature eStructuralFeature, int kind) 435 { 436 if (kind > 0 && kind < FEATURE_KINDS.length) 437 { 438 EAnnotation eAnnotation = getAnnotation(eStructuralFeature, true); 439 eAnnotation.getDetails().put("kind", FEATURE_KINDS[kind]); 440 } 441 else 442 { 443 EAnnotation eAnnotation = getAnnotation(eStructuralFeature, false); 444 if (eAnnotation != null) 445 { 446 eAnnotation.getDetails().remove("kind"); 447 } 448 } 449 getExtendedMetaData(eStructuralFeature).setFeatureKind(kind); 450 } 451 452 public int getContentKind(EClass eClass) 453 { 454 return getExtendedMetaData(eClass).getContentKind(); 455 } 456 457 protected int basicGetContentKind(EClass eClass) 458 { 459 EAnnotation eAnnotation = getAnnotation(eClass, false); 460 if (eAnnotation != null) 461 { 462 Object kind = eAnnotation.getDetails().get("kind"); 463 if (kind != null) 464 { 465 for (int i = 1; i < CONTENT_KINDS.length; ++i) 466 { 467 if (CONTENT_KINDS[i].equals(kind)) 468 { 469 return i; 470 } 471 } 472 } 473 } 474 475 return 0; 476 } 477 478 public void setContentKind(EClass eClass, int kind) 479 { 480 if (kind > 0 && kind < CONTENT_KINDS.length) 481 { 482 EAnnotation eAnnotation = getAnnotation(eClass, true); 483 eAnnotation.getDetails().put("kind", CONTENT_KINDS[kind]); 484 } 485 else 486 { 487 EAnnotation eAnnotation = getAnnotation(eClass, false); 488 if (eAnnotation != null) 489 { 490 eAnnotation.getDetails().remove("kind"); 491 } 492 } 493 getExtendedMetaData(eClass).setContentKind(kind); 494 } 495 496 public int getDerivationKind(EDataType eDataType) 497 { 498 return getExtendedMetaData(eDataType).getDerivationKind(); 499 } 500 501 protected int basicGetDerivationKind(EClassifier eClassifier) 502 { 503 EAnnotation eAnnotation = getAnnotation(eClassifier, false); 504 if (eAnnotation != null) 505 { 506 EMap details = eAnnotation.getDetails(); 507 Object kind = details.get("restriction"); 508 if (kind != null) 509 { 510 return RESTRICTION_DERIVATION; 511 } 512 kind = details.get("list"); 513 if (kind != null) 514 { 515 return LIST_DERIVATION; 516 } 517 kind = details.get("union"); 518 if (kind != null) 519 { 520 return UNION_DERIVATION; 521 } 522 } 523 524 return 0; 525 } 526 527 public EDataType getBaseType(EDataType eDataType) 528 { 529 return getExtendedMetaData(eDataType).getBaseType(); 530 } 531 532 public EDataType basicGetBaseType(EDataType eDataType) 533 { 534 EAnnotation eAnnotation = getAnnotation(eDataType, false); 535 if (eAnnotation != null) 536 { 537 EMap details = eAnnotation.getDetails(); 538 String baseType = (String )details.get("baseType"); 539 if (baseType != null) 540 { 541 int index = baseType.lastIndexOf("#"); 542 EClassifier type = 543 index == -1 ? 544 getType(eDataType.getEPackage(), baseType) : 545 index == 0 ? 546 getType((String )null, baseType.substring(1)) : 547 getType(baseType.substring(0, index), baseType.substring(index + 1)); 548 if (type instanceof EDataType) 549 { 550 return (EDataType)type; 551 } 552 } 553 } 554 555 return null; 556 } 557 558 public void setBaseType(EDataType eDataType, EDataType baseType) 559 { 560 if (baseType == null) 561 { 562 EAnnotation eAnnotation = getAnnotation(eDataType, false); 563 if (eAnnotation != null) 564 { 565 eAnnotation.getDetails().remove("baseType"); 566 } 567 } 568 else 569 { 570 EAnnotation eAnnotation = getAnnotation(eDataType, true); 571 eAnnotation.getDetails().put("baseType", getQualifiedName(getNamespace(eDataType), baseType)); 572 } 573 getExtendedMetaData(eDataType).setBaseType(baseType); 574 } 575 576 public EDataType getItemType(EDataType eDataType) 577 { 578 return getExtendedMetaData(eDataType).getItemType(); 579 } 580 581 protected EDataType basicGetItemType(EDataType eDataType) 582 { 583 EAnnotation eAnnotation = getAnnotation(eDataType, false); 584 if (eAnnotation != null) 585 { 586 EMap details = eAnnotation.getDetails(); 587 String itemType = (String )details.get("itemType"); 588 if (itemType != null) 589 { 590 int index = itemType.lastIndexOf("#"); 591 EClassifier type = 592 index == -1 ? 593 getType(eDataType.getEPackage(), itemType) : 594 index == 0 ? 595 getType((String )null, itemType.substring(1)) : 596 getType(itemType.substring(0, index), itemType.substring(index + 1)); 597 if (type instanceof EDataType) 598 { 599 return (EDataType)type; 600 } 601 } 602 } 603 604 return null; 605 } 606 607 public void setItemType(EDataType eDataType, EDataType itemType) 608 { 609 if (itemType == null) 610 { 611 EAnnotation eAnnotation = getAnnotation(eDataType, false); 612 if (eAnnotation != null) 613 { 614 eAnnotation.getDetails().remove("itemType"); 615 } 616 } 617 else 618 { 619 EAnnotation eAnnotation = getAnnotation(eDataType, true); 620 eAnnotation.getDetails().put("itemType", getQualifiedName(getNamespace(eDataType), itemType)); 621 } 622 getExtendedMetaData(eDataType).setItemType(itemType); 623 } 624 625 public List getMemberTypes(EDataType eDataType) 626 { 627 return getExtendedMetaData(eDataType).getMemberTypes(); 628 } 629 630 protected List basicGetMemberTypes(EDataType eDataType) 631 { 632 EAnnotation eAnnotation = getAnnotation(eDataType, false); 633 if (eAnnotation != null) 634 { 635 String memberTypes = (String )eAnnotation.getDetails().get("memberTypes"); 636 if (memberTypes != null) 637 { 638 List result = new ArrayList (); 639 for (StringTokenizer stringTokenizer = new StringTokenizer (memberTypes); stringTokenizer.hasMoreTokens(); ) 640 { 641 String member = stringTokenizer.nextToken(); 642 int index = member.lastIndexOf("#"); 643 EClassifier type = 644 index == -1 ? 645 getType(eDataType.getEPackage(), member) : 646 index == 0 ? 647 getType((String )null, member.substring(1)) : 648 getType(member.substring(0, index), member.substring(index + 1)); 649 if (type instanceof EDataType) 650 { 651 result.add(type); 652 } 653 } 654 return result; 655 } 656 } 657 658 return Collections.EMPTY_LIST; 659 } 660 661 public void setMemberTypes(EDataType eDataType, List memberTypes) 662 { 663 if (memberTypes.isEmpty()) 664 { 665 EAnnotation eAnnotation = getAnnotation(eDataType, false); 666 if (eAnnotation != null) 667 { 668 eAnnotation.getDetails().remove("memberTypes"); 669 } 670 } 671 else 672 { 673 EAnnotation eAnnotation = getAnnotation(eDataType, true); 674 String namespace = getNamespace(eDataType); 675 StringBuffer result = new StringBuffer (); 676 for (int i = 0, size = memberTypes.size(); i < size; ++i) 677 { 678 result.append(getQualifiedName(namespace, (EDataType)memberTypes.get(i))); 679 result.append(' '); 680 } 681 eAnnotation.getDetails().put("memberTypes", result.substring(0, result.length() - 1)); 682 } 683 getExtendedMetaData(eDataType).setMemberTypes(memberTypes); 684 } 685 686 protected boolean isFeatureKindSpecific() 687 { 688 return true; 689 } 690 691 public EStructuralFeature getLocalAttribute(EClass eClass, String namespace, String name) 692 { 693 if (isFeatureKindSpecific()) 694 { 695 List allAttributes = getAllAttributes(eClass); 696 for (int i = 0, size = allAttributes.size(); i < size; ++i) 697 { 698 EStructuralFeature eStructuralFeature = (EStructuralFeature)allAttributes.get(i); 699 if (name.equals(getName(eStructuralFeature)) && 700 (namespace == null ? getNamespace(eStructuralFeature) == null : namespace.equals(getNamespace(eStructuralFeature)))) 701 { 702 return eStructuralFeature; 703 } 704 } 705 } 706 else 707 { 708 for (int i = 0, size = eClass.getFeatureCount(); i < size; ++i) 709 { 710 EStructuralFeature eStructuralFeature = eClass.getEStructuralFeature(i); 711 switch (getFeatureKind(eStructuralFeature)) 712 { 713 case UNSPECIFIED_FEATURE: 714 case ATTRIBUTE_FEATURE: 715 { 716 if (name.equals(getName(eStructuralFeature)) && 717 (namespace == null ? getNamespace(eStructuralFeature) == null : namespace.equals(getNamespace(eStructuralFeature)))) 718 { 719 return eStructuralFeature; 720 } 721 break; 722 } 723 } 724 } 725 } 726 727 return null; 728 } 729 730 public EStructuralFeature getAttribute(EClass eClass, String namespace, String name) 731 { 732 EStructuralFeature result = getLocalAttribute(eClass, namespace, name); 733 if (result == null) 734 { 735 result = getAttribute(namespace, name); 736 if (result != null && getAffiliation(eClass, result) == null) 737 { 738 return null; 739 } 740 } 741 return result; 742 } 743 744 protected EStructuralFeature getLocalElement(EClass eClass, String namespace, String name) 745 { 746 if (isFeatureKindSpecific()) 747 { 748 List allElements = getAllElements(eClass); 749 for (int i = 0, size = allElements.size(); i < size; ++i) 750 { 751 EStructuralFeature eStructuralFeature = (EStructuralFeature)allElements.get(i); 752 if (name.equals(getName(eStructuralFeature)) && 753 (namespace == null ? getNamespace(eStructuralFeature) == null : namespace.equals(getNamespace(eStructuralFeature)))) 754 { 755 return eStructuralFeature; 756 } 757 } 758 } 759 else 760 { 761 for (int i = 0, size = eClass.getFeatureCount(); i < size; ++i) 762 { 763 EStructuralFeature eStructuralFeature = eClass.getEStructuralFeature(i); 764 switch (getFeatureKind(eStructuralFeature)) 765 { 766 case UNSPECIFIED_FEATURE: 767 case ELEMENT_FEATURE: 768 { 769 if (name.equals(getName(eStructuralFeature)) && 770 (namespace == null ? getNamespace(eStructuralFeature) == null : namespace.equals(getNamespace(eStructuralFeature)))) 771 { 772 return eStructuralFeature; 773 } 774 break; 775 } 776 } 777 } 778 } 779 780 return null; 781 } 782 783 public EStructuralFeature getElement(EClass eClass, String namespace, String name) 784 { 785 EStructuralFeature result = getLocalElement(eClass, namespace, name); 786 if (result == null) 787 { 788 result = getElement(namespace, name); 789 if (result != null && getAffiliation(eClass, result) == null) 790 { 791 return null; 792 } 793 } 794 return result; 795 } 796 797 public List getAllAttributes(EClass eClass) 798 { 799 List superTypes = eClass.getESuperTypes(); 800 List result = null; 801 boolean changeable = false; 802 for (int i = 0, size = superTypes.size(); i < size; ++i) 803 { 804 EClass eSuperType = (EClass)superTypes.get(i); 805 List allAttributes = getAllAttributes(eSuperType); 806 if (!allAttributes.isEmpty()) 807 { 808 if (result == null) 809 { 810 result = allAttributes; 811 } 812 else 813 { 814 if (!changeable) 815 { 816 changeable = true; 817 result = new UniqueEList(result); 818 } 819 result.addAll(allAttributes); 820 } 821 } 822 } 823 List attributes = getAttributes(eClass); 824 if (!attributes.isEmpty()) 825 { 826 if (result == null) 827 { 828 return attributes; 829 } 830 else 831 { 832 if (!changeable) 833 { 834 result = new UniqueEList(result); 835 } 836 result.addAll(attributes); 837 return result; 838 } 839 } 840 else 841 { 842 return result == null ? Collections.EMPTY_LIST : result; 843 } 844 } 845 846 public List getAllElements(EClass eClass) 847 { 848 List superTypes = eClass.getESuperTypes(); 849 List result = null; 850 boolean changeable = false; 851 for (int i = 0, size = superTypes.size(); i < size; ++i) 852 { 853 EClass eSuperType = (EClass)superTypes.get(i); 854 List allElements = getAllElements(eSuperType); 855 if (!allElements.isEmpty()) 856 { 857 if (result == null) 858 { 859 result = allElements; 860 } 861 else 862 { 863 if (!changeable) 864 { 865 changeable = true; 866 result = new UniqueEList(result); 867 } 868 result.addAll(allElements); 869 } 870 } 871 } 872 List elements = getElements(eClass); 873 if (!elements.isEmpty()) 874 { 875 if (result == null) 876 { 877 return elements; 878 } 879 else 880 { 881 if (!changeable) 882 { 883 result = new UniqueEList(result); 884 } 885 result.addAll(elements); 886 return result; 887 } 888 } 889 else 890 { 891 return result == null ? Collections.EMPTY_LIST : result; 892 } 893 } 894 895 public List getAttributes(EClass eClass) 896 { 897 List eStructuralFeatures = eClass.getEStructuralFeatures(); 898 List result = null; 899 for (int i = 0, size = eStructuralFeatures.size(); i < size; ++i) 900 { 901 EStructuralFeature eStructuralFeature = (EStructuralFeature)eStructuralFeatures.get(i); 902 switch (getFeatureKind(eStructuralFeature)) 903 { 904 case ATTRIBUTE_FEATURE: 905 case ATTRIBUTE_WILDCARD_FEATURE: 906 { 907 if (result == null) 908 { 909 result = new ArrayList (); 910 } 911 result.add(eStructuralFeature); 912 } 913 } 914 } 915 return result == null ? Collections.EMPTY_LIST : result; 916 } 917 918 public List getElements(EClass eClass) 919 { 920 List eStructuralFeatures = eClass.getEStructuralFeatures(); 921 List result = null; 922 for (int i = 0, size = eStructuralFeatures.size(); i < size; ++i) 923 { 924 EStructuralFeature eStructuralFeature = (EStructuralFeature)eStructuralFeatures.get(i); 925 switch (getFeatureKind(eStructuralFeature)) 926 { 927 case ELEMENT_FEATURE: 928 case ELEMENT_WILDCARD_FEATURE: 929 case GROUP_FEATURE: 930 { 931 if (result == null) 932 { 933 result = new ArrayList (); 934 } 935 result.add(eStructuralFeature); 936 break; 937 } 938 } 939 } 940 941 return result == null ? Collections.EMPTY_LIST : result; 942 } 943 944 public EStructuralFeature getSimpleFeature(EClass eClass) 945 { 946 if (getContentKind(eClass) == SIMPLE_CONTENT) 947 { 948 for (int i = 0, size = eClass.getFeatureCount(); i < size; ++i) 949 { 950 EStructuralFeature eStructuralFeature = eClass.getEStructuralFeature(i); 951 if (getFeatureKind(eStructuralFeature) == ExtendedMetaData.SIMPLE_FEATURE) 952 { 953 return eStructuralFeature; 954 } 955 } 956 } 957 958 return null; 959 } 960 961 public EAttribute getMixedFeature(EClass eClass) 962 { 963 switch (getContentKind(eClass)) 964 { 965 case MIXED_CONTENT: 966 case SIMPLE_CONTENT: 967 { 968 List eAllAttributes = eClass.getEAllAttributes(); 969 for (int i = 0, size = eAllAttributes.size(); i < size; ++i) 970 { 971 EAttribute eAttribute = (EAttribute)eAllAttributes.get(i); 972 if (getFeatureKind(eAttribute) == ExtendedMetaData.ELEMENT_WILDCARD_FEATURE) 973 { 974 return eAttribute; 975 } 976 } 977 break; 978 } 979 } 980 981 return null; 982 } 983 984 public List getWildcards(EStructuralFeature eStructuralFeature) 985 { 986 return getExtendedMetaData(eStructuralFeature).getWildcards(); 987 } 988 989 protected List basicGetWildcards(EStructuralFeature eStructuralFeature) 990 { 991 EAnnotation eAnnotation = getAnnotation(eStructuralFeature, false); 992 if (eAnnotation != null) 993 { 994 String wildcards = (String )eAnnotation.getDetails().get("wildcards"); 995 if (wildcards != null) 996 { 997 List result = new ArrayList (); 998 for (StringTokenizer stringTokenizer = new StringTokenizer (wildcards); stringTokenizer.hasMoreTokens(); ) 999 { 1000 String wildcard = stringTokenizer.nextToken(); 1001 if (wildcard.equals("##other")) 1002 { 1003 result.add("!##" + getNamespace(eStructuralFeature.getEContainingClass().getEPackage())); 1004 } 1005 else if (wildcard.equals("##local")) 1006 { 1007 result.add(null); 1008 } 1009 else if (wildcard.equals("##targetNamespace")) 1010 { 1011 result.add(getNamespace(eStructuralFeature.getEContainingClass().getEPackage())); 1012 } 1013 else 1014 { 1015 result.add(wildcard); 1016 } 1017 } 1018 return result; 1019 } 1020 } 1021 1022 return Collections.EMPTY_LIST; 1023 } 1024 1025 public void setWildcards(EStructuralFeature eStructuralFeature, List wildcards) 1026 { 1027 if (wildcards.isEmpty()) 1028 { 1029 EAnnotation eAnnotation = getAnnotation(eStructuralFeature, false); 1030 if (eAnnotation != null) 1031 { 1032 eAnnotation.getDetails().remove("wildcards"); 1033 eAnnotation.getDetails().remove("name"); 1034 } 1035 } 1036 else 1037 { 1038 String namespace = getNamespace(eStructuralFeature.getEContainingClass().getEPackage()); 1039 EAnnotation eAnnotation = getAnnotation(eStructuralFeature, true); 1040 eAnnotation.getDetails().put("wildcards", getEncodedWildcards(namespace, wildcards)); 1041 eAnnotation.getDetails().put("name",""); 1042 } 1043 getExtendedMetaData(eStructuralFeature).setWildcards(wildcards); 1044 } 1045 1046 public static String getEncodedWildcards(String namespace, List wildcards) 1047 { 1048 if (wildcards.isEmpty()) 1049 { 1050 return ""; 1051 } 1052 else 1053 { 1054 StringBuffer value = new StringBuffer (); 1055 for (int i = 0, size = wildcards.size(); i < size; ) 1056 { 1057 String wildcard = (String )wildcards.get(i); 1058 if (wildcard == null) 1059 { 1060 if (namespace == null) 1061 { 1062 value.append("##targetNamespace"); 1063 } 1064 else 1065 { 1066 value.append("##local"); 1067 } 1068 } 1069 else if (wildcard.startsWith("!##")) 1070 { 1071 if (namespace == null ? 1072 wildcard.length() == 3 : 1073 wildcard.endsWith(namespace) && wildcard.length() == namespace.length() + 3) 1074 { 1075 value.append("##other"); 1076 } 1077 else 1078 { 1079 value.append(wildcard); 1080 } 1081 } 1082 else if (wildcard.equals(namespace)) 1083 { 1084 value.append("##targetNamespace"); 1085 } 1086 else 1087 { 1088 value.append(wildcard); 1089 } 1090 1091 if (++i < size) 1092 { 1093 value.append(' '); 1094 } 1095 } 1096 return value.toString(); 1097 } 1098 } 1099 1100 public int getProcessingKind(EStructuralFeature eStructuralFeature) 1101 { 1102 return getExtendedMetaData(eStructuralFeature).getProcessingKind(); 1103 } 1104 1105 protected int basicGetProcessingKind(EStructuralFeature eStructuralFeature) 1106 { 1107 EAnnotation eAnnotation = getAnnotation(eStructuralFeature, false); 1108 if (eAnnotation != null) 1109 { 1110 Object kind = eAnnotation.getDetails().get("processing"); 1111 if (kind != null) 1112 { 1113 for (int i = 1; i < PROCESSING_KINDS.length; ++i) 1114 { 1115 if (PROCESSING_KINDS[i].equals(kind)) 1116 { 1117 return i; 1118 } 1119 } 1120 } 1121 } 1122 1123 return 0; 1124 } 1125 1126 public void setProcessingKind(EStructuralFeature eStructuralFeature, int kind) 1127 { 1128 if (kind > 0 && kind < PROCESSING_KINDS.length) 1129 { 1130 EAnnotation eAnnotation = getAnnotation(eStructuralFeature, true); 1131 eAnnotation.getDetails().put("processing", PROCESSING_KINDS[kind]); 1132 } 1133 else 1134 { 1135 EAnnotation eAnnotation = getAnnotation(eStructuralFeature, false); 1136 if (eAnnotation != null) 1137 { 1138 eAnnotation.getDetails().remove("processing"); 1139 } 1140 } 1141 getExtendedMetaData(eStructuralFeature).setProcessingKind(kind); 1142 } 1143 1144 public EStructuralFeature getGroup(EStructuralFeature eStructuralFeature) 1145 { 1146 return getExtendedMetaData(eStructuralFeature).getGroup(); 1147 } 1148 1149 protected EStructuralFeature basicGetGroup(EStructuralFeature eStructuralFeature) 1150 { 1151 EAnnotation eAnnotation = getAnnotation(eStructuralFeature, false); 1152 if (eAnnotation != null) 1153 { 1154 String qualifiedName = (String )eAnnotation.getDetails().get("group"); 1155 if (qualifiedName != null) 1156 { 1157 int fragmentIndex = qualifiedName.lastIndexOf('#'); 1158 if (fragmentIndex == -1) 1159 { 1160 return 1161 getElement 1162 (eStructuralFeature.getEContainingClass(), 1163 getNamespace(eStructuralFeature.getEContainingClass().getEPackage()), 1164 qualifiedName); 1165 } 1166 else if (fragmentIndex == 0) 1167 { 1168 return 1169 getElement 1170 (eStructuralFeature.getEContainingClass(), 1171 null, 1172 qualifiedName.substring(1)); 1173 } 1174 else 1175 { 1176 return 1177 getElement 1178 (eStructuralFeature.getEContainingClass(), 1179 qualifiedName.substring(0, fragmentIndex), 1180 qualifiedName.substring(fragmentIndex + 1)); 1181 } 1182 } 1183 } 1184 return null; 1185 } 1186 1187 public void setGroup(EStructuralFeature eStructuralFeature, EStructuralFeature group) 1188 { 1189 if (group == null) 1190 { 1191 EAnnotation eAnnotation = getAnnotation(eStructuralFeature, false); 1192 if (eAnnotation != null) 1193 { 1194 eAnnotation.getDetails().remove("group"); 1195 } 1196 } 1197 else 1198 { 1199 EAnnotation eAnnotation = getAnnotation(eStructuralFeature, true); 1200 eAnnotation.getDetails().put 1201 ("group", getQualifiedName(getNamespace(eStructuralFeature.getEContainingClass().getEPackage()), group)); 1202 } 1203 getExtendedMetaData(eStructuralFeature).setGroup(group); 1204 } 1205 1206 public EStructuralFeature getAffiliation(EStructuralFeature eStructuralFeature) 1207 { 1208 return getExtendedMetaData(eStructuralFeature).getAffiliation(); 1209 } 1210 1211 protected EStructuralFeature basicGetAffiliation(EStructuralFeature eStructuralFeature) 1212 { 1213 EAnnotation eAnnotation = getAnnotation(eStructuralFeature, false); 1214 if (eAnnotation != null) 1215 { 1216 String qualifiedName = (String )eAnnotation.getDetails().get("affiliation"); 1217 if (qualifiedName != null) 1218 { 1219 int fragmentIndex = qualifiedName.lastIndexOf('#'); 1220 if (fragmentIndex == -1) 1221 { 1222 return getElement(getNamespace(eStructuralFeature.getEContainingClass().getEPackage()), qualifiedName); 1223 } 1224 else if (fragmentIndex == 0) 1225 { 1226 return getElement(null, qualifiedName.substring(1)); 1227 } 1228 else 1229 { 1230 return getElement(qualifiedName.substring(0, fragmentIndex), qualifiedName.substring(fragmentIndex + 1)); 1231 } 1232 } 1233 } 1234 return null; 1235 } 1236 1237 public void setAffiliation(EStructuralFeature eStructuralFeature, EStructuralFeature affiliation) 1238 { 1239 if (affiliation == null) 1240 { 1241 EAnnotation eAnnotation = getAnnotation(eStructuralFeature, false); 1242 if (eAnnotation != null) 1243 { 1244 eAnnotation.getDetails().remove("affiliation"); 1245 } 1246 } 1247 else 1248 { 1249 EAnnotation eAnnotation = getAnnotation(eStructuralFeature, true); 1250 eAnnotation.getDetails().put 1251 ("affiliation", getQualifiedName(getNamespace(eStructuralFeature.getEContainingClass().getEPackage()), affiliation)); 1252 } 1253 getExtendedMetaData(eStructuralFeature).setAffiliation(affiliation); 1254 } 1255 1256 public EStructuralFeature getAffiliation(EClass eClass, EStructuralFeature eStructuralFeature) 1257 { 1258 if (eClass.getFeatureID(eStructuralFeature) >= 0) 1259 { 1260 return eStructuralFeature; 1261 } 1262 1263 switch (getFeatureKind(eStructuralFeature)) 1264 { 1265 case ATTRIBUTE_FEATURE: 1266 { 1267 String namespace = getNamespace(eStructuralFeature); 1268 String name = getName(eStructuralFeature); 1269 EStructuralFeature result = getLocalAttribute(eClass, namespace, name); 1270 if (result != null) 1271 { 1272 return result; 1273 } 1274 1275 List allAttributes = getAllAttributes(eClass); 1276 for (int i = 0, size = allAttributes.size(); i < size; ++i) 1277 { 1278 result = (EStructuralFeature)allAttributes.get(i); 1279 if (matches(getWildcards(result), namespace)) 1280 { 1281 return result; 1282 } 1283 } 1284 1285 return null; 1286 } 1287 case ELEMENT_FEATURE: 1288 { 1289 for (EStructuralFeature affiliation = eStructuralFeature; affiliation != null; affiliation = getAffiliation(affiliation)) 1290 { 1291 String namespace = getNamespace(affiliation); 1292 String name = getName(affiliation); 1293 EStructuralFeature result = getLocalElement(eClass, namespace, name); 1294 if (result != null) 1295 { 1296 return result; 1297 } 1298 } 1299 1300 String namespace = getNamespace(eStructuralFeature); 1301 if (XMLTypePackage.eNS_URI.equals(namespace)) 1302 { 1303 return getMixedFeature(eClass); 1304 } 1305 else 1306 { 1307 List allElements = getAllElements(eClass); 1308 for (int i = 0, size = allElements.size(); i < size; ++i) 1309 { 1310 EStructuralFeature result = (EStructuralFeature)allElements.get(i); 1311 if (matches(getWildcards(result), namespace)) 1312 { 1313 return result; 1314 } 1315 } 1316 } 1317 return null; 1318 } 1319 default: 1320 { 1321 return null; 1322 } 1323 } 1324 } 1325 1326 public EStructuralFeature getAttributeWildcardAffiliation(EClass eClass, String namespace, String name) 1327 { 1328 List allAttributes = getAllAttributes(eClass); 1329 for (int i = 0, size = allAttributes.size(); i < size; ++i) 1330 { 1331 EStructuralFeature result = (EStructuralFeature)allAttributes.get(i); 1332 if (matches(getWildcards(result), namespace)) 1333 { 1334 return result; 1335 } 1336 } 1337 1338 return null; 1339 } 1340 1341 public EStructuralFeature getElementWildcardAffiliation(EClass eClass, String namespace, String name) 1342 { 1343 List allElements = getAllElements(eClass); 1344 for (int i = 0, size = allElements.size(); i < size; ++i) 1345 { 1346 EStructuralFeature result = (EStructuralFeature)allElements.get(i); 1347 if (matches(getWildcards(result), namespace)) 1348 { 1349 return result; 1350 } 1351 } 1352 1353 return null; 1354 } 1355 1356 public boolean matches(List wildcards, String namespace) 1357 { 1358 if (!wildcards.isEmpty()) 1359 { 1360 for (int i = 0, size = wildcards.size(); i < size; ++i) 1361 { 1362 String wildcard = (String )wildcards.get(i); 1363 if (matches(wildcard, namespace)) 1364 { 1365 return true; 1366 } 1367 } 1368 } 1369 1370 return false; 1371 } 1372 1373 public boolean matches(String wildcard, String namespace) 1374 { 1375 return 1376 wildcard == null ? 1377 namespace == null : 1378 wildcard.startsWith("!##") ? 1379 namespace == null ? 1380 wildcard.length() != 3 : 1381 (!wildcard.endsWith(namespace) || wildcard.length() != namespace.length() + 3) && 1382 !XMLTypePackage.eNS_URI.equals(namespace) : 1383 wildcard.equals("##any") && !XMLTypePackage.eNS_URI.equals(namespace) || wildcard.equals(namespace); 1384 } 1385 1386 public int getWhiteSpaceFacet(EDataType eDataType) 1387 { 1388 return getExtendedMetaData(eDataType).getWhiteSpaceFacet(); 1389 } 1390 1391 protected int basicGetWhiteSpaceFacet(EDataType eDataType) 1392 { 1393 EAnnotation eAnnotation = getAnnotation(eDataType, false); 1394 if (eAnnotation != null) 1395 { 1396 String whiteSpaceLiteral = (String )eAnnotation.getDetails().get("whiteSpace"); 1397 for (int i = 1; i < WHITE_SPACE_KINDS.length; ++i) 1398 { 1399 if (WHITE_SPACE_KINDS[i].equals(whiteSpaceLiteral)) 1400 { 1401 return i; 1402 } 1403 } 1404 } 1405 return UNSPECIFIED_WHITE_SPACE; 1406 } 1407 1408 public void setWhiteSpaceFacet(EDataType eDataType, int whiteSpace) 1409 { 1410 if (whiteSpace == UNSPECIFIED_WHITE_SPACE) 1411 { 1412 EAnnotation eAnnotation = getAnnotation(eDataType, false); 1413 if (eAnnotation != null) 1414 { 1415 eAnnotation.getDetails().remove("whiteSpace"); 1416 } 1417 } 1418 else 1419 { 1420 EAnnotation eAnnotation = getAnnotation(eDataType, true); 1421 eAnnotation.getDetails().put("whiteSpace", WHITE_SPACE_KINDS[whiteSpace]); 1422 } 1423 getExtendedMetaData(eDataType).setWhiteSpaceFacet(whiteSpace); 1424 } 1425 1426 public List getEnumerationFacet(EDataType eDataType) 1427 { 1428 return getExtendedMetaData(eDataType).getEnumerationFacet(); 1429 } 1430 1431 protected List basicGetEnumerationFacet(EDataType eDataType) 1432 { 1433 EAnnotation eAnnotation = getAnnotation(eDataType, false); 1434 if (eAnnotation != null) 1435 { 1436 String enumerationLiteral = (String )eAnnotation.getDetails().get("enumeration"); 1437 if (enumerationLiteral != null) 1438 { 1439 List result = new ArrayList (); 1440 for (StringTokenizer stringTokenizer = new StringTokenizer (enumerationLiteral, " "); stringTokenizer.hasMoreTokens(); ) 1441 { 1442 String enumeration = replace(replace(stringTokenizer.nextToken(), "%20", " "), "%25", "%"); 1443 result.add(enumeration); 1444 } 1445 return result; 1446 } 1447 } 1448 return Collections.EMPTY_LIST; 1449 } 1450 1451 public void setEnumerationFacet(EDataType eDataType, List literals) 1452 { 1453 if (literals.isEmpty()) 1454 { 1455 EAnnotation eAnnotation = getAnnotation(eDataType, false); 1456 if (eAnnotation != null) 1457 { 1458 eAnnotation.getDetails().remove("enumeration"); 1459 } 1460 } 1461 else 1462 { 1463 EAnnotation eAnnotation = getAnnotation(eDataType, true); 1464 StringBuffer result = new StringBuffer (); 1465 for (int i = 0, size = literals.size(); i < size; ++i) 1466 { 1467 result.append(replace(replace(((String )literals.get(i)), "%","%25"), " ", "%20")); 1468 result.append(' '); 1469 } 1470 eAnnotation.getDetails().put("enumeration", result.substring(0, result.length() - 1)); 1471 } 1472 getExtendedMetaData(eDataType).setEnumerationFacet(literals); 1473 } 1474 1475 public List getPatternFacet(EDataType eDataType) 1476 { 1477 return getExtendedMetaData(eDataType).getPatternFacet(); 1478 } 1479 1480 protected List basicGetPatternFacet(EDataType eDataType) 1481 { 1482 EAnnotation eAnnotation = getAnnotation(eDataType, false); 1483 if (eAnnotation != null) 1484 { 1485 String patternLiteral = (String )eAnnotation.getDetails().get("pattern"); 1486 if (patternLiteral != null) 1487 { 1488 List result = new ArrayList (); 1489 for (StringTokenizer stringTokenizer = new StringTokenizer (patternLiteral, " "); stringTokenizer.hasMoreTokens(); ) 1490 { 1491 String pattern = replace(replace(stringTokenizer.nextToken(), "%20", " "), "%25", "%"); 1492 result.add(pattern); 1493 } 1494 return result; 1495 } 1496 } 1497 return Collections.EMPTY_LIST; 1498 } 1499 1500 public void setPatternFacet(EDataType eDataType, List pattern) 1501 { 1502 if (pattern.isEmpty()) 1503 { 1504 EAnnotation eAnnotation = getAnnotation(eDataType, false); 1505 if (eAnnotation != null) 1506 { 1507 eAnnotation.getDetails().remove("pattern"); 1508 } 1509 } 1510 else 1511 { 1512 EAnnotation eAnnotation = getAnnotation(eDataType, true); 1513 StringBuffer result = new StringBuffer (); 1514 for (int i = 0, size = pattern.size(); i < size; ++i) 1515 { 1516 result.append(replace(replace(((String )pattern.get(i)), "%","%25"), " ", "%20")); 1517 result.append(' '); 1518 } 1519 eAnnotation.getDetails().put("pattern", result.substring(0, result.length() - 1)); 1520 } 1521 getExtendedMetaData(eDataType).setPatternFacet(pattern); 1522 } 1523 1524 public int getTotalDigitsFacet(EDataType eDataType) 1525 { 1526 return getExtendedMetaData(eDataType).getTotalDigitsFacet(); 1527 } 1528 1529 protected int basicGetTotalDigitsFacet(EDataType eDataType) 1530 { 1531 EAnnotation eAnnotation = getAnnotation(eDataType, false); 1532 if (eAnnotation != null) 1533 { 1534 String totalDigitsLiteral = (String )eAnnotation.getDetails().get("totalDigits"); 1535 if (totalDigitsLiteral != null) 1536 { 1537 return Integer.parseInt(totalDigitsLiteral); 1538 } 1539 } 1540 return -1; 1541 } 1542 1543 public void setTotalDigitsFacet(EDataType eDataType, int digits) 1544 { 1545 if (digits == -1) 1546 { 1547 EAnnotation eAnnotation = getAnnotation(eDataType, false); 1548 if (eAnnotation != null) 1549 { 1550 eAnnotation.getDetails().remove("totalDigits"); 1551 } 1552 } 1553 else 1554 { 1555 EAnnotation eAnnotation = getAnnotation(eDataType, true); 1556 eAnnotation.getDetails().put("totalDigits", Integer.toString(digits)); 1557 } 1558 getExtendedMetaData(eDataType).setTotalDigitsFacet(digits); 1559 } 1560 1561 public int getFractionDigitsFacet(EDataType eDataType) 1562 { 1563 return getExtendedMetaData(eDataType).getFractionDigitsFacet(); 1564 } 1565 1566 protected int basicGetFractionDigitsFacet(EDataType eDataType) 1567 { 1568 EAnnotation eAnnotation = getAnnotation(eDataType, false); 1569 if (eAnnotation != null) 1570 { 1571 String fractionDigitsLiteral = (String )eAnnotation.getDetails().get("fractionDigits"); 1572 if (fractionDigitsLiteral != null) 1573 { 1574 return Integer.parseInt(fractionDigitsLiteral); 1575 } 1576 } 1577 return -1; 1578 } 1579 1580 public void setFractionDigitsFacet(EDataType eDataType, int digits) 1581 { 1582 if (digits == -1) 1583 { 1584 EAnnotation eAnnotation = getAnnotation(eDataType, false); 1585 if (eAnnotation != null) 1586 { 1587 eAnnotation.getDetails().remove("factionDigits"); 1588 } 1589 } 1590 else 1591 { 1592 EAnnotation eAnnotation = getAnnotation(eDataType, true); 1593 eAnnotation.getDetails().put("fractionDigits", Integer.toString(digits)); 1594 } 1595 getExtendedMetaData(eDataType).setFractionDigitsFacet(digits); 1596 } 1597 1598 public int getLengthFacet(EDataType eDataType) 1599 { 1600 return getExtendedMetaData(eDataType).getLengthFacet(); 1601 } 1602 1603 protected int basicGetLengthFacet(EDataType eDataType) 1604 { 1605 EAnnotation eAnnotation = getAnnotation(eDataType, false); 1606 if (eAnnotation != null) 1607 { 1608 String lengthLiteral = (String )eAnnotation.getDetails().get("length"); 1609 if (lengthLiteral != null) 1610 { 1611 return Integer.parseInt(lengthLiteral); 1612 } 1613 } 1614 return -1; 1615 } 1616 1617 public void setLengthFacet(EDataType eDataType, int length) 1618 { 1619 if (length == -1) 1620 { 1621 EAnnotation eAnnotation = getAnnotation(eDataType, false); 1622 if (eAnnotation != null) 1623 { 1624 eAnnotation.getDetails().remove("length"); 1625 } 1626 } 1627 else 1628 { 1629 EAnnotation eAnnotation = getAnnotation(eDataType, true); 1630 eAnnotation.getDetails().put("length", Integer.toString(length)); 1631 } 1632 getExtendedMetaData(eDataType).setLengthFacet(length); 1633 } 1634 1635 public int getMinLengthFacet(EDataType eDataType) 1636 { 1637 return getExtendedMetaData(eDataType).getMinLengthFacet(); 1638 } 1639 1640 protected int basicGetMinLengthFacet(EDataType eDataType) 1641 { 1642 EAnnotation eAnnotation = getAnnotation(eDataType, false); 1643 if (eAnnotation != null) 1644 { 1645 String minLengthLiteral = (String )eAnnotation.getDetails().get("minLength"); 1646 if (minLengthLiteral != null) 1647 { 1648 return Integer.parseInt(minLengthLiteral); 1649 } 1650 } 1651 return -1; 1652 } 1653 1654 public void setMinLengthFacet(EDataType eDataType, int length) 1655 { 1656 if (length == -1) 1657 { 1658 EAnnotation eAnnotation = getAnnotation(eDataType, false); 1659 if (eAnnotation != null) 1660 { 1661 eAnnotation.getDetails().remove("minLength"); 1662 } 1663 } 1664 else 1665 { 1666 EAnnotation eAnnotation = getAnnotation(eDataType, true); 1667 eAnnotation.getDetails().put("minLength", Integer.toString(length)); 1668 } 1669 getExtendedMetaData(eDataType).setMinLengthFacet(length); 1670 } 1671 1672 public int getMaxLengthFacet(EDataType eDataType) 1673 { 1674 return getExtendedMetaData(eDataType).getMaxLengthFacet(); 1675 } 1676 1677 protected int basicGetMaxLengthFacet(EDataType eDataType) 1678 { 1679 EAnnotation eAnnotation = getAnnotation(eDataType, false); 1680 if (eAnnotation != null) 1681 { 1682 String maxLengthLiteral = (String )eAnnotation.getDetails().get("maxLength"); 1683 if (maxLengthLiteral != null) 1684 { 1685 return Integer.parseInt(maxLengthLiteral); 1686 } 1687 } 1688 return -1; 1689 } 1690 1691 public void setMaxLengthFacet(EDataType eDataType, int length) 1692 { 1693 if (length == -1) 1694 { 1695 EAnnotation eAnnotation = getAnnotation(eDataType, false); 1696 if (eAnnotation != null) 1697 { 1698 eAnnotation.getDetails().remove("maxLength"); 1699 } 1700 } 1701 else 1702 { 1703 EAnnotation eAnnotation = getAnnotation(eDataType, true); 1704 eAnnotation.getDetails().put("maxLength", Integer.toString(length)); 1705 } 1706 getExtendedMetaData(eDataType).setMaxLengthFacet(length); 1707 } 1708 1709 public String getMinExclusiveFacet(EDataType eDataType) 1710 { 1711 return getExtendedMetaData(eDataType).getMinExclusiveFacet(); 1712 } 1713 1714 protected String basicGetMinExclusiveFacet(EDataType eDataType) 1715 { 1716 EAnnotation eAnnotation = getAnnotation(eDataType, false); 1717 return 1718 eAnnotation == null ? 1719 null : 1720 (String )eAnnotation.getDetails().get("minExclusive"); 1721 } 1722 1723 public void setMinExclusiveFacet(EDataType eDataType, String literal) 1724 { 1725 if (literal == null) 1726 { 1727 EAnnotation eAnnotation = getAnnotation(eDataType, false); 1728 if (eAnnotation != null) 1729 { 1730 eAnnotation.getDetails().remove("minExclusive"); 1731 } 1732 } 1733 else 1734 { 1735 EAnnotation eAnnotation = getAnnotation(eDataType, true); 1736 eAnnotation.getDetails().put("minExclusive", literal); 1737 } 1738 getExtendedMetaData(eDataType).setMinExclusiveFacet(literal); 1739 } 1740 1741 public String getMaxExclusiveFacet(EDataType eDataType) 1742 { 1743 return getExtendedMetaData(eDataType).getMaxExclusiveFacet(); 1744 } 1745 1746 protected String basicGetMaxExclusiveFacet(EDataType eDataType) 1747 { 1748 EAnnotation eAnnotation = getAnnotation(eDataType, false); 1749 return 1750 eAnnotation == null ? 1751 null : 1752 (String )eAnnotation.getDetails().get("maxExclusive"); 1753 } 1754 1755 public void setMaxExclusiveFacet(EDataType eDataType, String literal) 1756 { 1757 if (literal == null) 1758 { 1759 EAnnotation eAnnotation = getAnnotation(eDataType, false); 1760 if (eAnnotation != null) 1761 { 1762 eAnnotation.getDetails().remove("maxExclusive"); 1763 } 1764 } 1765 else 1766 { 1767 EAnnotation eAnnotation = getAnnotation(eDataType, true); 1768 eAnnotation.getDetails().put("maxExclusive", literal); 1769 } 1770 getExtendedMetaData(eDataType).setMaxExclusiveFacet(literal); 1771 } 1772 1773 public String getMinInclusiveFacet(EDataType eDataType) 1774 { 1775 return getExtendedMetaData(eDataType).getMinInclusiveFacet(); 1776 } 1777 1778 protected String basicGetMinInclusiveFacet(EDataType eDataType) 1779 { 1780 EAnnotation eAnnotation = getAnnotation(eDataType, false); 1781 return 1782 eAnnotation == null ? 1783 null : 1784 (String )eAnnotation.getDetails().get("minInclusive"); 1785 } 1786 1787 public void setMinInclusiveFacet(EDataType eDataType, String literal) 1788 { 1789 if (literal == null) 1790 { 1791 EAnnotation eAnnotation = getAnnotation(eDataType, false); 1792 if (eAnnotation != null) 1793 { 1794 eAnnotation.getDetails().remove("minInclusive"); 1795 } 1796 } 1797 else 1798 { 1799 EAnnotation eAnnotation = getAnnotation(eDataType, true); 1800 eAnnotation.getDetails().put("minInclusive", literal); 1801 } 1802 getExtendedMetaData(eDataType).setMinInclusiveFacet(literal); 1803 } 1804 1805 public String getMaxInclusiveFacet(EDataType eDataType) 1806 { 1807 return getExtendedMetaData(eDataType).getMaxInclusiveFacet(); 1808 } 1809 1810 protected String basicGetMaxInclusiveFacet(EDataType eDataType) 1811 { 1812 EAnnotation eAnnotation = getAnnotation(eDataType, false); 1813 return 1814 eAnnotation == null ? 1815 null : 1816 (String )eAnnotation.getDetails().get("maxInclusive"); 1817 } 1818 1819 public void setMaxInclusiveFacet(EDataType eDataType, String literal) 1820 { 1821 if (literal == null) 1822 { 1823 EAnnotation eAnnotation = getAnnotation(eDataType, false); 1824 if (eAnnotation != null) 1825 { 1826 eAnnotation.getDetails().remove("maxInclusive"); 1827 } 1828 } 1829 else 1830 { 1831 EAnnotation eAnnotation = getAnnotation(eDataType, true); 1832 eAnnotation.getDetails().put("maxInclusive", literal); 1833 } 1834 getExtendedMetaData(eDataType).setMaxInclusiveFacet(literal); 1835 } 1836 1837 public EPackage demandPackage(String namespace) 1838 { 1839 EPackage ePackage = demandRegistry.getEPackage(namespace); 1840 if (ePackage == null) 1841 { 1842 ePackage = EcoreFactory.eINSTANCE.createEPackage(); 1843 ePackage.setNsURI(namespace); 1844 setQualified(ePackage, namespace != null); 1845 if (namespace != null) 1846 { 1847 ePackage.setNsPrefix 1848 (namespace.equals(ExtendedMetaData.XMLNS_URI) ? 1849 namespace.equals(ExtendedMetaData.XML_URI) ? 1850 "xml" : 1851 "xmlns" : 1852 "_"); 1853 } 1854 demandRegistry.put(namespace, ePackage); 1855 1856 1858 EClass documentRootEClass = EcoreFactory.eINSTANCE.createEClass(); 1859 documentRootEClass.getESuperTypes().add(XMLTypePackage.eINSTANCE.getXMLTypeDocumentRoot()); 1860 documentRootEClass.setName("DocumentRoot"); 1861 ePackage.getEClassifiers().add(documentRootEClass); 1862 setDocumentRoot(documentRootEClass); 1863 } 1864 return ePackage; 1865 } 1866 1867 public EClassifier demandType(String namespace, String name) 1868 { 1869 EPackage ePackage = demandPackage(namespace); 1870 EClassifier eClassifier = getType(ePackage, name); 1871 if (eClassifier != null) 1872 { 1873 return eClassifier; 1874 } 1875 else 1876 { 1877 EClass eClass = EcoreFactory.eINSTANCE.createEClass(); 1878 eClass.setName(name); 1879 eClass.getESuperTypes().add(XMLTypePackage.eINSTANCE.getAnyType()); 1880 setContentKind(eClass, MIXED_CONTENT); 1881 ePackage.getEClassifiers().add(eClass); 1882 return eClass; 1883 } 1884 } 1885 1886 public EStructuralFeature demandFeature(String namespace, String name, boolean isElement) 1887 { 1888 return demandFeature(namespace, name, isElement, isElement); 1889 } 1890 1891 public EStructuralFeature demandFeature(String namespace, String name, boolean isElement, boolean isReference) 1892 { 1893 EPackage ePackage = demandPackage(namespace); 1894 EClass documentRootEClass = getDocumentRoot(ePackage); 1895 EStructuralFeature eStructuralFeature = 1896 isElement ? 1897 getLocalElement(documentRootEClass, namespace, name) : 1898 getLocalAttribute(documentRootEClass, namespace, name); 1899 if (eStructuralFeature != null) 1900 { 1901 return eStructuralFeature; 1902 } 1903 else 1904 { 1905 if (isReference) 1906 { 1907 EReference eReference = EcoreFactory.eINSTANCE.createEReference(); 1908 eReference.setContainment(isElement); 1909 eReference.setEType(EcorePackage.eINSTANCE.getEObject()); 1910 eReference.setName(name); 1911 eReference.setDerived(true); 1912 eReference.setTransient(true); 1913 eReference.setVolatile(true); 1914 documentRootEClass.getEStructuralFeatures().add(eReference); 1915 1916 setFeatureKind(eReference, isElement ? ELEMENT_FEATURE : ATTRIBUTE_FEATURE); 1917 setNamespace(eReference, namespace); 1918 1919 if (isElement) 1923 { 1924 eReference.setUpperBound(ETypedElement.UNSPECIFIED_MULTIPLICITY); 1925 } 1926 1927 return eReference; 1928 } 1929 else 1930 { 1931 EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute(); 1932 eAttribute.setName(name); 1933 eAttribute.setEType(XMLTypePackage.eINSTANCE.getAnySimpleType()); 1934 eAttribute.setDerived(true); 1935 eAttribute.setTransient(true); 1936 eAttribute.setVolatile(true); 1937 documentRootEClass.getEStructuralFeatures().add(eAttribute); 1938 1939 setFeatureKind(eAttribute, isElement ? ELEMENT_FEATURE : ATTRIBUTE_FEATURE); 1940 setNamespace(eAttribute, namespace); 1941 1942 if (isElement) 1946 { 1947 eAttribute.setUpperBound(ETypedElement.UNSPECIFIED_MULTIPLICITY); 1948 } 1949 1950 return eAttribute; 1951 } 1952 } 1953 } 1954 1955 public Collection demandedPackages() 1956 { 1957 return demandRegistry.values(); 1958 } 1959 1960 1961 1962 1963 1964 public static interface EPackageExtendedMetaData 1965 { 1966 interface Holder 1967 { 1968 EPackageExtendedMetaData getExtendedMetaData(); 1969 void setExtendedMetaData(EPackageExtendedMetaData ePackageExtendedMetaData); 1970 } 1971 1972 boolean isQualified(); 1973 void setQualified(boolean isQualified); 1974 } 1975 1976 public class EPackageExtendedMetaDataImpl implements EPackageExtendedMetaData 1977 { 1978 protected EPackage ePackage; 1979 protected boolean isInitialized; 1980 protected boolean isQualified; 1981 1982 public EPackageExtendedMetaDataImpl(EPackage ePackage) 1983 { 1984 this.ePackage = ePackage; 1985 } 1986 1987 public boolean isQualified() 1988 { 1989 if (!isInitialized) 1990 { 1991 setQualified(basicIsQualified(ePackage)); 1992 } 1993 return isQualified; 1994 } 1995 1996 public void setQualified(boolean isQualified) 1997 { 1998 this.isQualified = isQualified; 1999 isInitialized = true; 2000 } 2001 } 2002 2003 protected EPackageExtendedMetaData getExtendedMetaData(EPackage ePackage) 2004 { 2005 if (extendedMetaDataHolderCache != null) 2006 { 2007 EPackageExtendedMetaData result = (EPackageExtendedMetaData)extendedMetaDataHolderCache.get(ePackage); 2008 if (result == null) 2009 { 2010 extendedMetaDataHolderCache.put(ePackage, result = createEPackageExtendedMetaData(ePackage)); 2011 } 2012 return result; 2013 } 2014 else 2015 { 2016 EPackageExtendedMetaData.Holder holder = (EPackageExtendedMetaData.Holder)ePackage; 2017 EPackageExtendedMetaData result = holder.getExtendedMetaData(); 2018 if (result == null) 2019 { 2020 holder.setExtendedMetaData(result = createEPackageExtendedMetaData(ePackage)); 2021 } 2022 return result; 2023 } 2024 } 2025 2026 protected EPackageExtendedMetaData createEPackageExtendedMetaData(EPackage ePackage) 2027 { 2028 return new EPackageExtendedMetaDataImpl(ePackage); 2029 } 2030 2031 2032 protected static final String UNINITIALIZED_STRING = "uninitialized"; 2033 protected static final int UNINITIALIZED_INT = -2; 2034 protected static final EDataType UNINITIALIZED_EDATA_TYPE = EcoreFactory.eINSTANCE.createEDataType(); 2035 protected static final EStructuralFeature UNINITIALIZED_ESTRUCTURAL_FEATURE = EcoreFactory.eINSTANCE.createEAttribute(); 2036 2037 2038 public static interface EClassifierExtendedMetaData 2039 { 2040 interface Holder 2041 { 2042 EClassifierExtendedMetaData getExtendedMetaData(); 2043 void setExtendedMetaData(EClassifierExtendedMetaData eClassifierExtendedMetaData); 2044 } 2045 String getName(); 2046 void setName(String name); 2047 2048 int getContentKind(); 2049 void setContentKind(int kind); 2050 2051 int getDerivationKind(); 2052 2053 EDataType getBaseType(); 2054 void setBaseType(EDataType baseType); 2055 2056 EDataType getItemType(); 2057 void setItemType(EDataType itemType); 2058 2059 List getMemberTypes(); 2060 void setMemberTypes(List memberTypes); 2061 2062 int getWhiteSpaceFacet(); 2063 void setWhiteSpaceFacet(int whiteSpace); 2064 2065 List getEnumerationFacet(); 2066 void setEnumerationFacet(List literals); 2067 2068 List getPatternFacet(); 2069 void setPatternFacet(List literals); 2070 2071 int getTotalDigitsFacet(); 2072 void setTotalDigitsFacet(int digits); 2073 2074 int getFractionDigitsFacet(); 2075 void setFractionDigitsFacet(int digits); 2076 2077 int getLengthFacet(); 2078 void setLengthFacet(int length); 2079 2080 int getMinLengthFacet(); 2081 void setMinLengthFacet(int length); 2082 2083 int getMaxLengthFacet(); 2084 void setMaxLengthFacet(int length); 2085 2086 String getMinExclusiveFacet(); 2087 void setMinExclusiveFacet(String literal); 2088 2089 String getMaxExclusiveFacet(); 2090 void setMaxExclusiveFacet(String literal); 2091 2092 String getMinInclusiveFacet(); 2093 void setMinInclusiveFacet(String literal); 2094 2095 String getMaxInclusiveFacet(); 2096 void setMaxInclusiveFacet(String literal); 2097 } 2098 2099 public class EClassExtendedMetaDataImpl implements EClassifierExtendedMetaData 2100 { 2101 protected EClass eClass; 2102 protected String name = UNINITIALIZED_STRING; 2103 protected int contentKind = UNINITIALIZED_INT; 2104 2105 public EClassExtendedMetaDataImpl(EClass eClass) 2106 { 2107 this.eClass = eClass; 2108 } 2109 2110 public String getName() 2111 { 2112 if (name == UNINITIALIZED_STRING) 2113 { 2114 setName(basicGetName(eClass)); 2115 } 2116 return name; 2117 } 2118 2119 public void setName(String name) 2120 { 2121 this.name = name; 2122 } 2123 2124 public int getContentKind() 2125 { 2126 if (contentKind == UNINITIALIZED_INT) 2127 { 2128 setContentKind(basicGetContentKind(eClass)); 2129 } 2130 return contentKind; 2131 } 2132 2133 public void setContentKind(int kind) 2134 { 2135 this.contentKind = kind; 2136 } 2137 2138 public int getDerivationKind() 2139 { 2140 return 0; 2141 } 2142 2143 public EDataType getBaseType() 2144 { 2145 return null; 2146 } 2147 2148 public void setBaseType(EDataType baseType) 2149 { 2150 throw new UnsupportedOperationException ("Can't set the base type of an EClass"); 2151 } 2152 2153 public EDataType getItemType() 2154 { 2155 return null; 2156 } 2157 2158 public void setItemType(EDataType itemType) 2159 { 2160 throw new UnsupportedOperationException ("Can't set the item type of an EClass"); 2161 } 2162 2163 public List getMemberTypes() 2164 { 2165 return Collections.EMPTY_LIST; 2166 } 2167 2168 public void setMemberTypes(List memberTypes) 2169 { 2170 throw new UnsupportedOperationException ("Can't set the member types of an EClass"); 2171 } 2172 2173 public int getWhiteSpaceFacet() 2174 { 2175 return 0; 2176 } 2177 2178 public void setWhiteSpaceFacet(int whiteSpace) 2179 { 2180 throw new UnsupportedOperationException ("Can't set the white space of an EClass"); 2181 } 2182 2183 public List getEnumerationFacet() 2184 { 2185 return Collections.EMPTY_LIST; 2186 } 2187 2188 public void setEnumerationFacet(List literals) 2189 { 2190 throw new UnsupportedOperationException ("Can't set the enumeration of an EClass"); 2191 } 2192 2193 public List getPatternFacet() 2194 { 2195 return Collections.EMPTY_LIST; 2196 } 2197 2198 public void setPatternFacet(List pattern) 2199 { 2200 throw new UnsupportedOperationException ("Can't set the pattern of an EClass"); 2201 } 2202 2203 public int getTotalDigitsFacet() 2204 { 2205 return -1; 2206 } 2207 2208 public void setTotalDigitsFacet(int digits) 2209 { 2210 throw new UnsupportedOperationException ("Can't set the total digits of an EClass"); 2211 } 2212 2213 public int getFractionDigitsFacet() 2214 { 2215 return -1; 2216 } 2217 2218 public void setFractionDigitsFacet(int digits) 2219 { 2220 throw new UnsupportedOperationException ("Can't set the fraction digits of an EClass"); 2221 } 2222 2223 public int getLengthFacet() 2224 { 2225 return -1; 2226 } 2227 2228 public void setLengthFacet(int length) 2229 { 2230 throw new UnsupportedOperationException ("Can't set the length of an EClass"); 2231 } 2232 2233 public int getMinLengthFacet() 2234 { 2235 return -1; 2236 } 2237 2238 public void setMinLengthFacet(int minLength) 2239 { 2240 throw new UnsupportedOperationException ("Can't set the min length of an EClass"); 2241 } 2242 2243 public int getMaxLengthFacet() 2244 { 2245 return -1; 2246 } 2247 2248 public void setMaxLengthFacet(int maxLength) 2249 { 2250 throw new UnsupportedOperationException ("Can't set the max length of an EClass"); 2251 } 2252 2253 public String getMinExclusiveFacet() 2254 { 2255 return null; 2256 } 2257 2258 public void setMinExclusiveFacet(String literal) 2259 { 2260 throw new UnsupportedOperationException ("Can't set the min exclusive of an EClass"); 2261 } 2262 2263 public String getMaxExclusiveFacet() 2264 { 2265 return null; 2266 } 2267 2268 public void setMaxExclusiveFacet(String literal) 2269 { 2270 throw new UnsupportedOperationException ("Can't set the max exclusive of an EClass"); 2271 } 2272 2273 public String getMinInclusiveFacet() 2274 { 2275 return null; 2276 } 2277 2278 public void setMinInclusiveFacet(String literal) 2279 { 2280 throw new UnsupportedOperationException ("Can't set the min inclusive of an EClass"); 2281 } 2282 2283 public String getMaxInclusiveFacet() 2284 { 2285 return null; 2286 } 2287 2288 public void setMaxInclusiveFacet(String literal) 2289 { 2290 throw new UnsupportedOperationException ("Can't set the max inclusive of an EClass"); 2291 } 2292 } 2293 2294 public class EDataTypeExtendedMetaDataImpl implements EClassifierExtendedMetaData 2295 { 2296 protected EDataType eDataType; 2297 protected String name = UNINITIALIZED_STRING; 2298 protected EDataType baseType = UNINITIALIZED_EDATA_TYPE; 2299 protected EDataType itemType = UNINITIALIZED_EDATA_TYPE; 2300 protected List memberTypes; 2301 protected int derivationKind = UNINITIALIZED_INT; 2302 protected int whiteSpace = UNINITIALIZED_INT; 2303 protected List enumerationLiterals; 2304 protected List pattern; 2305 int totalDigits = UNINITIALIZED_INT; 2306 int fractionDigits = UNINITIALIZED_INT; 2307 int length = UNINITIALIZED_INT; 2308 int minLength = UNINITIALIZED_INT; 2309 int maxLength = UNINITIALIZED_INT; 2310 String minExclusive = UNINITIALIZED_STRING; 2311 String maxExclusive = UNINITIALIZED_STRING; 2312 String minInclusive = UNINITIALIZED_STRING; 2313 String maxInclusive = UNINITIALIZED_STRING; 2314 2315 public EDataTypeExtendedMetaDataImpl(EDataType eDataType) 2316 { 2317 this.eDataType = eDataType; 2318 } 2319 2320 public String getName() 2321 { 2322 if (name == UNINITIALIZED_STRING) 2323 { 2324 setName(basicGetName(eDataType)); 2325 } 2326 return name; 2327 } 2328 2329 public void setName(String name) 2330 { 2331 this.name = name; 2332 } 2333 2334 public int getContentKind() 2335 { 2336 return 0; 2337 } 2338 2339 public void setContentKind(int kind) 2340 { 2341 throw new UnsupportedOperationException ("Can't set the content kind of an EDataType"); 2342 } 2343 2344 public int getDerivationKind() 2345 { 2346 if (derivationKind == UNINITIALIZED_INT) 2347 { 2348 if (getBaseType() != null) 2349 { 2350 derivationKind = RESTRICTION_DERIVATION; 2351 } 2352 else if (getItemType() != null) 2353 { 2354 derivationKind = LIST_DERIVATION; 2355 } 2356 else if (!memberTypes.isEmpty()) 2357 { 2358 derivationKind = UNION_DERIVATION; 2359 } 2360 else 2361 { 2362 derivationKind = 0; 2363 } 2364 } 2365 return derivationKind; 2366 } 2367 2368 public EDataType getBaseType() 2369 { 2370 if (baseType == UNINITIALIZED_EDATA_TYPE) 2371 { 2372 setBaseType(basicGetBaseType(eDataType)); 2373 } 2374 return baseType; 2375 } 2376 2377 public void setBaseType(EDataType baseType) 2378 { 2379 this.baseType = baseType; 2380 derivationKind = UNINITIALIZED_INT; 2381 } 2382 2383 public EDataType getItemType() 2384 { 2385 if (itemType == UNINITIALIZED_EDATA_TYPE) 2386 { 2387 setItemType(basicGetItemType(eDataType)); 2388 } 2389 return itemType; 2390 } 2391 2392 public void setItemType(EDataType itemType) 2393 { 2394 this.itemType = itemType; 2395 derivationKind = UNINITIALIZED_INT; 2396 } 2397 2398 public List getMemberTypes() 2399 { 2400 if (memberTypes == null) 2401 { 2402 setMemberTypes(basicGetMemberTypes(eDataType)); 2403 } 2404 return memberTypes; 2405 } 2406 2407 public void setMemberTypes(List memberTypes) 2408 { 2409 this.memberTypes = memberTypes; 2410 derivationKind = UNINITIALIZED_INT; 2411 } 2412 2413 public int getWhiteSpaceFacet() 2414 { 2415 if (whiteSpace == UNINITIALIZED_INT) 2416 { 2417 setWhiteSpaceFacet(basicGetWhiteSpaceFacet(eDataType)); 2418 } 2419 return whiteSpace; 2420 } 2421 2422 public void setWhiteSpaceFacet(int whiteSpace) 2423 { 2424 this.whiteSpace = whiteSpace; 2425 } 2426 2427 public List getEnumerationFacet() 2428 { 2429 if (enumerationLiterals == null) 2430 { 2431 setEnumerationFacet(basicGetEnumerationFacet(eDataType)); 2432 } 2433 return enumerationLiterals; 2434 } 2435 2436 public void setEnumerationFacet(List literals) 2437 { 2438 this.enumerationLiterals = literals; 2439 } 2440 2441 public List getPatternFacet() 2442 { 2443 if (pattern == null) 2444 { 2445 setPatternFacet(basicGetPatternFacet(eDataType)); 2446 } 2447 return pattern; 2448 } 2449 2450 public void setPatternFacet(List pattern) 2451 { 2452 this.pattern = pattern; 2453 } 2454 2455 public int getTotalDigitsFacet() 2456 { 2457 if (totalDigits == UNINITIALIZED_INT) 2458 { 2459 setTotalDigitsFacet(basicGetTotalDigitsFacet(eDataType)); 2460 } 2461 return totalDigits; 2462 } 2463 2464 public void setTotalDigitsFacet(int digits) 2465 { 2466 this.totalDigits = digits; 2467 } 2468 2469 public int getFractionDigitsFacet() 2470 { 2471 if (fractionDigits == UNINITIALIZED_INT) 2472 { 2473 setFractionDigitsFacet(basicGetFractionDigitsFacet(eDataType)); 2474 } 2475 return fractionDigits; 2476 } 2477 2478 public void setFractionDigitsFacet(int digits) 2479 { 2480 this.fractionDigits = digits; 2481 } 2482 2483 public int getLengthFacet() 2484 { 2485 if (length == UNINITIALIZED_INT) 2486 { 2487 setLengthFacet(basicGetLengthFacet(eDataType)); 2488 } 2489 return length; 2490 } 2491 2492 public void setLengthFacet(int length) 2493 { 2494 this.length = length; 2495 } 2496 2497 public int getMinLengthFacet() 2498 { 2499 if (minLength == UNINITIALIZED_INT) 2500 { 2501 setMinLengthFacet(basicGetMinLengthFacet(eDataType)); 2502 } 2503 return minLength; 2504 } 2505 2506 public void setMinLengthFacet(int minLength) 2507 { 2508 this.minLength = minLength; 2509 } 2510 2511 public int getMaxLengthFacet() 2512 { 2513 if (maxLength == UNINITIALIZED_INT) 2514 { 2515 setMaxLengthFacet(basicGetMaxLengthFacet(eDataType)); 2516 } 2517 return maxLength; 2518 } 2519 2520 public void setMaxLengthFacet(int maxLength) 2521 { 2522 this.maxLength = maxLength; 2523 } 2524 2525 public String getMinExclusiveFacet() 2526 { 2527 if (minExclusive == UNINITIALIZED_STRING) 2528 { 2529 setMinExclusiveFacet(basicGetMinExclusiveFacet(eDataType)); 2530 } 2531 return minExclusive; 2532 } 2533 2534 public void setMinExclusiveFacet(String literal) 2535 { 2536 this.minExclusive = literal; 2537 } 2538 2539 public String getMaxExclusiveFacet() 2540 { 2541 if (maxExclusive == UNINITIALIZED_STRING) 2542 { 2543 setMaxExclusiveFacet(basicGetMaxExclusiveFacet(eDataType)); 2544 } 2545 return maxExclusive; 2546 } 2547 2548 public void setMaxExclusiveFacet(String literal) 2549 { 2550 this.maxExclusive = literal; 2551 } 2552 2553 public String getMinInclusiveFacet() 2554 { 2555 if (minInclusive == UNINITIALIZED_STRING) 2556 { 2557 setMinInclusiveFacet(basicGetMinInclusiveFacet(eDataType)); 2558 } 2559 return minInclusive; 2560 } 2561 2562 public void setMinInclusiveFacet(String literal) 2563 { 2564 this.minInclusive = literal; 2565 } 2566 2567 public String getMaxInclusiveFacet() 2568 { 2569 if (maxInclusive == UNINITIALIZED_STRING) 2570 { 2571 setMaxInclusiveFacet(basicGetMaxInclusiveFacet(eDataType)); 2572 } 2573 return maxInclusive; 2574 } 2575 2576 public void setMaxInclusiveFacet(String literal) 2577 { 2578 this.maxInclusive = literal; 2579 } 2580 } 2581 2582 protected EClassifierExtendedMetaData getExtendedMetaData(EClassifier eClassifier) 2583 { 2584 if (extendedMetaDataHolderCache != null) 2585 { 2586 EClassifierExtendedMetaData result = (EClassifierExtendedMetaData)extendedMetaDataHolderCache.get(eClassifier); 2587 if (result == null) 2588 { 2589 extendedMetaDataHolderCache.put(eClassifier, result = createEClassifierExtendedMetaData(eClassifier)); 2590 } 2591 return result; 2592 } 2593 else 2594 { 2595 EClassifierExtendedMetaData.Holder holder = (EClassifierExtendedMetaData.Holder)eClassifier; 2596 EClassifierExtendedMetaData result = holder.getExtendedMetaData(); 2597 if (result == null) 2598 { 2599 holder.setExtendedMetaData(result = createEClassifierExtendedMetaData(eClassifier)); 2600 } 2601 return result; 2602 } 2603 } 2604 2605 protected EClassifierExtendedMetaData createEClassifierExtendedMetaData(EClassifier eClassifier) 2606 { 2607 if (eClassifier instanceof EClass) 2608 { 2609 return new EClassExtendedMetaDataImpl((EClass)eClassifier); 2610 } 2611 else 2612 { 2613 return new EDataTypeExtendedMetaDataImpl((EDataType)eClassifier); 2614 } 2615 } 2616 2617 public static interface EStructuralFeatureExtendedMetaData 2618 { 2619 interface Holder 2620 { 2621 EStructuralFeatureExtendedMetaData getExtendedMetaData(); 2622 void setExtendedMetaData(EStructuralFeatureExtendedMetaData eStructuralFeatureExtendedMetaData); 2623 } 2624 2625 String getName(); 2626 void setName(String name); 2627 2628 String getNamespace(); 2629 void setNamespace(String namespace); 2630 2631 int getFeatureKind(); 2632 void setFeatureKind(int kind); 2633 2634 List getWildcards(); 2635 void setWildcards(List wildcards); 2636 2637 int getProcessingKind(); 2638 void setProcessingKind(int kind); 2639 2640 EStructuralFeature getGroup(); 2641 void setGroup(EStructuralFeature group); 2642 2643 EStructuralFeature getAffiliation(); 2644 void setAffiliation(EStructuralFeature affiliation); 2645 2646 Map getValidatorMap(); 2647 } 2648 2649 public class EStructuralFeatureExtendedMetaDataImpl implements EStructuralFeatureExtendedMetaData 2650 { 2651 protected EStructuralFeature eStructuralFeature; 2652 protected String name = UNINITIALIZED_STRING; 2653 protected String namespace = UNINITIALIZED_STRING; 2654 protected int featureKind = UNINITIALIZED_INT; 2655 protected List wildcards; 2656 protected int processingKind = UNINITIALIZED_INT; 2657 protected EStructuralFeature group = UNINITIALIZED_ESTRUCTURAL_FEATURE; 2658 protected EStructuralFeature affiliation = UNINITIALIZED_ESTRUCTURAL_FEATURE; 2659 protected Map validatorMap; 2660 2661 public EStructuralFeatureExtendedMetaDataImpl(EStructuralFeature eStructuralFeature) 2662 { 2663 this.eStructuralFeature = eStructuralFeature; 2664 } 2665 2666 public Map getValidatorMap() 2667 { 2668 if (validatorMap == null) 2669 { 2670 validatorMap = new Hashtable (); 2671 } 2672 return validatorMap; 2673 } 2674 2675 public String getName() 2676 { 2677 if (name == UNINITIALIZED_STRING) 2678 { 2679 setName(basicGetName(eStructuralFeature)); 2680 } 2681 return name; 2682 } 2683 2684 public void setName(String name) 2685 { 2686 this.name= name; 2687 } 2688 2689 public String getNamespace() 2690 { 2691 if (namespace == UNINITIALIZED_STRING) 2692 { 2693 setNamespace(basicGetNamespace(eStructuralFeature)); 2694 } 2695 return namespace; 2696 } 2697 2698 public void setNamespace(String namespace) 2699 { 2700 this.namespace = namespace; 2701 } 2702 2703 public int getFeatureKind() 2704 { 2705 if (featureKind == UNINITIALIZED_INT) 2706 { 2707 setFeatureKind(basicGetFeatureKind(eStructuralFeature)); 2708 } 2709 return featureKind; 2710 } 2711 2712 public void setFeatureKind(int kind) 2713 { 2714 this.featureKind = kind; 2715 } 2716 2717 public List getWildcards() 2718 { 2719 if (wildcards == null) 2720 { 2721 setWildcards(basicGetWildcards(eStructuralFeature)); 2722 } 2723 return wildcards; 2724 } 2725 2726 public void setWildcards(List wildcards) 2727 { 2728 this.wildcards = wildcards; 2729 } 2730 2731 public int getProcessingKind() 2732 { 2733 if (processingKind == UNINITIALIZED_INT) 2734 { 2735 setProcessingKind(basicGetProcessingKind(eStructuralFeature)); 2736 } 2737 return processingKind; 2738 } 2739 2740 public void setProcessingKind(int kind) 2741 { 2742 this.processingKind = kind; 2743 } 2744 2745 public EStructuralFeature getGroup() 2746 { 2747 if (group == UNINITIALIZED_ESTRUCTURAL_FEATURE) 2748 { 2749 setGroup(basicGetGroup(eStructuralFeature)); 2750 } 2751 return group; 2752 } 2753 2754 public void setGroup(EStructuralFeature group) 2755 { 2756 this.group = group; 2757 } 2758 2759 public EStructuralFeature getAffiliation() 2760 { 2761 if (affiliation == UNINITIALIZED_ESTRUCTURAL_FEATURE) 2762 { 2763 setAffiliation(basicGetAffiliation(eStructuralFeature)); 2764 } 2765 return affiliation; 2766 } 2767 2768 public void setAffiliation(EStructuralFeature affiliation) 2769 { 2770 this.affiliation = affiliation; 2771 } 2772 } 2773 2774 protected EStructuralFeatureExtendedMetaData getExtendedMetaData(EStructuralFeature eStructuralFeature) 2775 { 2776 if (extendedMetaDataHolderCache != null) 2777 { 2778 EStructuralFeatureExtendedMetaData result = (EStructuralFeatureExtendedMetaData)extendedMetaDataHolderCache.get(eStructuralFeature); 2779 if (result == null) 2780 { 2781 extendedMetaDataHolderCache.put(eStructuralFeature, result = createEStructuralFeatureExtendedMetaData(eStructuralFeature)); 2782 } 2783 return result; 2784 } 2785 else 2786 { 2787 EStructuralFeatureExtendedMetaData.Holder holder = (EStructuralFeatureExtendedMetaData.Holder)eStructuralFeature; 2788 EStructuralFeatureExtendedMetaData result = holder.getExtendedMetaData(); 2789 if (result == null) 2790 { 2791 holder.setExtendedMetaData(result = createEStructuralFeatureExtendedMetaData(eStructuralFeature)); 2792 } 2793 return result; 2794 } 2795 } 2796 2797 protected EStructuralFeatureExtendedMetaData createEStructuralFeatureExtendedMetaData(EStructuralFeature eStructuralFeature) 2798 { 2799 return new EStructuralFeatureExtendedMetaDataImpl(eStructuralFeature); 2800 } 2801 2802 private static String replace(String in, String oldString, String newString) 2803 { 2804 if (in == null || oldString == null) 2805 { 2806 return in; 2807 } 2808 2809 int oldStringLength = oldString.length(); 2810 if (oldStringLength == 0) 2811 { 2812 return in; 2813 } 2814 2815 if (newString == null) 2816 { 2817 newString = ""; 2818 } 2819 int newStringLength = newString.length(); 2820 2821 int index = -newStringLength; 2822 StringBuffer result = new StringBuffer (in); 2823 while((index = indexOf(result, oldString, index + newStringLength)) >= 0) 2824 { 2825 result.replace(index, index + oldStringLength, newString); 2826 } 2827 2828 return result.toString(); 2829 } 2830 2831 private static int indexOf(StringBuffer in, String str, int fromIndex) 2832 { 2833 if (in == null) 2834 { 2835 return -1; 2836 } 2837 2838 if (str == null) 2839 { 2840 str = ""; 2841 } 2842 2843 int lengthIn = in.length(); 2844 int lengthStr = str.length(); 2845 2846 if (lengthIn < lengthStr) 2847 { 2848 return -1; 2849 } 2850 2851 if (fromIndex > lengthIn) 2852 { 2853 if (lengthIn == 0 && fromIndex == 0 && lengthStr == 0) 2854 { 2855 return 0; 2856 } 2857 return -1; 2858 } 2859 2860 if (fromIndex < 0) 2861 { 2862 fromIndex = 0; 2863 } 2864 2865 if (lengthStr == 0) 2866 { 2867 return fromIndex; 2868 } 2869 2870 int strPos = 0; 2871 for (int i = fromIndex; i < lengthIn; i++) 2872 { 2873 if (in.charAt(i) == str.charAt(strPos)) 2874 { 2875 strPos++; 2876 if(strPos == lengthStr) 2877 { 2878 return i - lengthStr + 1; 2879 } 2880 } 2881 else 2882 { 2883 strPos = 0; 2884 } 2885 } 2886 2887 return -1; 2888 } 2889} 2890 | Popular Tags |