| 1 17 package org.eclipse.emf.importer.rose.builder; 18 19 import java.util.ArrayList ; 20 import java.util.Collections ; 21 import java.util.Comparator ; 22 import java.util.HashMap ; 23 import java.util.HashSet ; 24 import java.util.Iterator ; 25 import java.util.List ; 26 import java.util.ListIterator ; 27 import java.util.Map ; 28 import java.util.Set ; 29 import java.util.StringTokenizer ; 30 import java.util.regex.Matcher ; 31 import java.util.regex.Pattern ; 32 33 import org.eclipse.core.runtime.IStatus; 34 import org.eclipse.core.runtime.Status; 35 36 import org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage; 37 import org.eclipse.emf.codegen.util.CodeGenUtil; 38 import org.eclipse.emf.common.util.BasicEList; 39 import org.eclipse.emf.common.util.EList; 40 import org.eclipse.emf.common.util.UniqueEList; 41 import org.eclipse.emf.ecore.EAnnotation; 42 import org.eclipse.emf.ecore.EAttribute; 43 import org.eclipse.emf.ecore.EClass; 44 import org.eclipse.emf.ecore.EClassifier; 45 import org.eclipse.emf.ecore.EDataType; 46 import org.eclipse.emf.ecore.EEnum; 47 import org.eclipse.emf.ecore.EEnumLiteral; 48 import org.eclipse.emf.ecore.EModelElement; 49 import org.eclipse.emf.ecore.ENamedElement; 50 import org.eclipse.emf.ecore.EObject; 51 import org.eclipse.emf.ecore.EOperation; 52 import org.eclipse.emf.ecore.EPackage; 53 import org.eclipse.emf.ecore.EParameter; 54 import org.eclipse.emf.ecore.EReference; 55 import org.eclipse.emf.ecore.EStructuralFeature; 56 import org.eclipse.emf.ecore.ETypedElement; 57 import org.eclipse.emf.ecore.EcoreFactory; 58 import org.eclipse.emf.ecore.EcorePackage; 59 import org.eclipse.emf.ecore.util.EcoreSwitch; 60 import org.eclipse.emf.ecore.util.EcoreUtil; 61 import org.eclipse.emf.ecore.util.ExtendedMetaData; 62 import org.eclipse.emf.importer.rose.RoseImporterPlugin; 63 import org.eclipse.emf.importer.rose.parser.RoseNode; 64 import org.eclipse.emf.importer.rose.parser.Util; 65 66 67 70 public class RoseEcoreBuilder implements RoseVisitor 71 { 72 public boolean noQualify = false; 73 public boolean unsettablePrimitive = "true".equals(System.getProperty("EMF_UNSETTABLE_PRIMITIVE")); 74 75 protected RoseUtil roseUtil; 76 protected EcorePackage ecorePackage; 77 protected EcoreFactory ecoreFactory; 78 protected Set bounded = new HashSet (); 79 80 protected Map eStructuralFeatureToXMLNamespaceMap = new HashMap (); 81 82 protected List eStructuralFeatures = new BasicEList() 83 { 84 protected boolean useEquals() 85 { 86 return false; 87 } 88 }; 89 protected Map eEnums = new HashMap (); 90 protected Map idToParentMap = new HashMap (); 91 92 protected EReference ref1 = null; 93 protected EReference ref2 = null; 94 protected RoseNode role1 = null; 95 protected RoseNode role2 = null; 96 97 public RoseEcoreBuilder(RoseUtil roseUtil) 98 { 99 super(); 100 this.roseUtil = roseUtil; 101 ecorePackage = EcorePackage.eINSTANCE; 102 ecoreFactory = EcoreFactory.eINSTANCE; 103 } 104 105 public void visitList(RoseNode roseNode) 106 { 107 } 108 109 public void visitObject(RoseNode roseNode) 110 { 111 String roseNodeValue = roseNode.getValue(); 112 String objectKey = roseNode.getKey(); 113 String objectType = Util.getType(roseNodeValue); 114 String objectName = Util.getName(roseNodeValue); 115 116 118 RoseNode currentNode = roseNode; 121 Object parent = currentNode.getNode(); 122 while (parent == null) 123 { 124 currentNode = currentNode.getParent(); 125 parent = currentNode.getNode(); 126 } 127 128 visitObject(roseNode, roseNodeValue, objectKey, objectType, objectName, parent); 129 } 130 131 protected void visitObject(RoseNode roseNode, String roseNodeValue, String objectKey, String objectType, String objectName, Object parent) 132 { 133 if (objectKey.equals("") && objectType.equals(RoseStrings.CLASS_CATEGORY)) 134 { 135 visitClassCategory(roseNode, roseNodeValue, objectKey, objectName, parent); 136 } 137 else if (objectType.equals(RoseStrings.CLASS)) 138 { 139 visitClass(roseNode, roseNodeValue, objectKey, objectName, parent); 140 } 141 else if (objectType.equals(RoseStrings.OPERATION)) 142 { 143 visitOperation(roseNode, roseNodeValue, objectKey, objectName, parent); 144 } 145 else if (objectType.equals(RoseStrings.PARAMETER)) 146 { 147 visitParameter(roseNode, roseNodeValue, objectKey, objectName, parent); 148 } 149 else if (objectType.equals(RoseStrings.INHERITANCE_RELATIONSHIP)) 150 { 151 visitInheritanceRelationship(roseNode, roseNodeValue, objectKey, objectName, parent); 152 } 153 else if (objectType.equals(RoseStrings.CLASSATTRIBUTE) && (!roseNode.isDerived() || !"reference".equals(roseNode.getStereotype()))) 154 { 155 visitClassattribute(roseNode, roseNodeValue, objectKey, objectName, parent); 156 } 157 else if (objectType.equals(RoseStrings.ASSOCIATION)) 158 { 159 visitAssociation(roseNode, roseNodeValue, objectKey, objectName, parent); 160 } 161 else if (objectType.equals(RoseStrings.ROLE) && !objectName.startsWith("/")) 162 { 163 visitRole(roseNode, roseNodeValue, objectKey, objectName, parent); 164 } 165 } 166 167 protected void visitClassCategory(RoseNode roseNode, String roseNodeValue, String objectKey, String objectName, Object parent) 168 { 169 if (roseNode.isLoaded()) 172 { 173 String id = roseNode.getRoseId(); 174 if (idToParentMap.containsKey(id)) 175 { 176 parent = idToParentMap.get(id); 177 } 178 EPackage ePackage = ecoreFactory.createEPackage(); 179 if (parent instanceof EPackage) 180 { 181 ((EPackage)parent).getESubpackages().add(ePackage); 184 } 185 else if (parent instanceof EList) 186 { 187 ((EList)parent).add(ePackage); 188 } 189 setEPackageProperties(roseNode, ePackage, objectName.toLowerCase()); 190 } 191 else 192 { 193 idToParentMap.put(roseNode.getRoseId(), parent); 194 } 195 } 196 197 protected void visitClass(RoseNode roseNode, String roseNodeValue, String objectKey, String objectName, Object parent) 198 { 199 if (objectName == null || objectName.length() == 0) 200 { 201 String quid = roseNode.getRoseId(); 202 if (quid != null) 203 { 204 quid = quid.substring(1, quid.length() - 1); 205 } 206 207 objectName = "Unnamed" + quid; 208 error(RoseImporterPlugin.INSTANCE.getString("_UI_UnnamedClass_message", new Object []{ objectName })); 209 } 210 211 RoseNode stereoTypeNode = roseNode.findNodeWithKey(RoseStrings.STEREOTYPE); 215 if (stereoTypeNode != null) 216 { 217 String stereoTypeValue = stereoTypeNode.getValue(); 218 stereoTypeValue = stereoTypeValue.substring(1, stereoTypeValue.length() - 1); 219 if (stereoTypeValue.equals(RoseStrings.INTERFACE)) 220 { 221 EClass eClass = ecoreFactory.createEClass(); 224 String classifierName = roseNode.getClassifierName(); 225 if (classifierName == null || classifierName.length() == 0) 226 { 227 classifierName = validName(upperCaseName(objectName)); 228 } 229 eClass.setName(classifierName); 230 roseNode.setNode(eClass); 231 setEClassProperties(roseNode, eClass); 232 eClass.setInterface(true); 233 eClass.setAbstract(true); 234 build(roseNode, parent, eClass); 235 } 236 else if (stereoTypeValue.equalsIgnoreCase(RoseStrings.ENUMERATION)) 237 { 238 EEnum eEnum = ecoreFactory.createEEnum(); 240 String classifierName = roseNode.getClassifierName(); 241 if (classifierName == null || classifierName.length() == 0) 242 { 243 classifierName = validName(upperCaseName(objectName)); 244 } 245 eEnum.setName(classifierName); 246 roseNode.setNode(eEnum); 247 setEEnumProperties(roseNode, eEnum); 248 build(roseNode, parent, eEnum); 249 } 250 else if (stereoTypeValue.equalsIgnoreCase("datatype") || stereoTypeValue.equalsIgnoreCase("primitive")) 251 { 252 EDataType eDataType = ecoreFactory.createEDataType(); 255 String classifierName = roseNode.getClassifierName(); 256 if (classifierName == null || classifierName.length() == 0) 257 { 258 classifierName = validName(upperCaseName(objectName)); 259 } 260 eDataType.setName(classifierName); 261 roseNode.setNode(eDataType); 262 setEDataTypeProperties(roseNode, eDataType); 263 build(roseNode, parent, eDataType); 264 265 String uml2MOFCorbaType = roseNode.getUML2MOFCorbaType(); 266 if (uml2MOFCorbaType != null) 267 { 268 uml2MOFCorbaType = uml2MOFCorbaType.trim(); 269 int start = uml2MOFCorbaType.indexOf("typedef "); 270 if (start != -1) 271 { 272 uml2MOFCorbaType = uml2MOFCorbaType.substring(8); 273 int end = uml2MOFCorbaType.lastIndexOf(" "); 274 if (end != -1) 275 { 276 uml2MOFCorbaType = uml2MOFCorbaType.substring(0, end); 277 } 278 } 279 280 if (uml2MOFCorbaType != null && uml2MOFCorbaType.length() != 0) 281 { 282 roseUtil.typeTable.put(eDataType, uml2MOFCorbaType); 283 } 284 } 285 286 } 287 else if (stereoTypeValue.equalsIgnoreCase("javatype")) 288 { 289 EDataType eDataType = ecoreFactory.createEDataType(); 292 String classifierName = roseNode.getClassifierName(); 293 if (classifierName == null || classifierName.length() == 0) 294 { 295 int index = objectName.lastIndexOf("."); 296 classifierName = validName(upperCaseName(index == -1 ? objectName : objectName.substring(index + 1))); 297 } 298 int index = objectName.lastIndexOf("."); 299 eDataType.setName(validName(upperCaseName(index == -1 ? objectName : objectName.substring(index + 1)))); 300 eDataType.setInstanceClassName(objectName); 301 roseNode.setNode(eDataType); 302 setEDataTypeProperties(roseNode, eDataType); 303 build(roseNode, parent, eDataType); 304 } 305 else if (stereoTypeValue.equalsIgnoreCase("abstract")) 306 { 307 EClass eClass = ecoreFactory.createEClass(); 310 String classifierName = roseNode.getClassifierName(); 311 if (classifierName == null || classifierName.length() == 0) 312 { 313 classifierName = validName(upperCaseName(objectName)); 314 } 315 eClass.setName(classifierName); 316 roseNode.setNode(eClass); 317 setEClassProperties(roseNode, eClass); 318 build(roseNode, parent, eClass); 319 } 320 else if (stereoTypeValue.equalsIgnoreCase("MapEntry")) 321 { 322 EClass eClass = ecoreFactory.createEClass(); 325 String classifierName = roseNode.getClassifierName(); 326 if (classifierName == null || classifierName.length() == 0) 327 { 328 classifierName = validName(upperCaseName(objectName)); 329 } 330 eClass.setName(classifierName); 331 roseNode.setNode(eClass); 332 setEClassProperties(roseNode, eClass); 333 eClass.setInstanceClassName("java.util.Map$Entry"); 334 build(roseNode, parent, eClass); 335 } 336 else 337 { 338 warning(RoseImporterPlugin.INSTANCE.getString("_UI_UnrecognizedStereotype_message", new Object []{ stereoTypeValue, objectName })); 339 340 EClass eClass = ecoreFactory.createEClass(); 343 String classifierName = roseNode.getClassifierName(); 344 if (classifierName == null || classifierName.length() == 0) 345 { 346 classifierName = validName(upperCaseName(objectName)); 347 } 348 eClass.setName(classifierName); 349 roseNode.setNode(eClass); 350 setEClassProperties(roseNode, eClass); 351 build(roseNode, parent, eClass); 352 } 353 } 354 else 355 { 356 EClass eClass = ecoreFactory.createEClass(); 359 String classifierName = roseNode.getClassifierName(); 360 if (classifierName == null || classifierName.length() == 0) 361 { 362 classifierName = validName(upperCaseName(objectName)); 363 } 364 eClass.setName(classifierName); 365 roseNode.setNode(eClass); 366 setEClassProperties(roseNode, eClass); 367 build(roseNode, parent, eClass); 368 } 369 } 370 371 protected void visitOperation(RoseNode roseNode, String roseNodeValue, String objectKey, String objectName, Object parent) 372 { 373 EOperation eOperation = ecoreFactory.createEOperation(); 375 String operationName = roseNode.getOperationName(); 376 if (operationName == null || operationName.length() == 0) 377 { 378 operationName = validName(objectName); 379 } 380 eOperation.setName(operationName); 381 roseNode.setNode(eOperation); 382 setResultType(roseNode, eOperation); 383 setEOperationProperties(roseNode, eOperation); 384 if (parent instanceof EClass) 385 { 386 ((EClass)parent).getEOperations().add(eOperation); 389 } 390 } 391 392 protected void visitParameter(RoseNode roseNode, String roseNodeValue, String objectKey, String objectName, Object parent) 393 { 394 EParameter eParameter = ecoreFactory.createEParameter(); 397 eParameter.setName(validName(objectName)); 398 roseNode.setNode(eParameter); 399 400 if (parent instanceof EOperation) 403 { 404 ((EOperation)parent).getEParameters().add(eParameter); 405 } 406 setEParameterProperties(roseNode, eParameter); 407 } 408 409 protected void visitInheritanceRelationship(RoseNode roseNode, String roseNodeValue, String objectKey, String objectName, Object parent) 410 { 411 String quidu = roseNode.getRoseRefId(); 412 if (quidu != null && !quidu.equals("")) 413 { 414 quidu = quidu.substring(1, quidu.length() - 1); 415 } 416 List superList = (List )roseUtil.superTable.get(parent); 417 if (superList == null) 418 { 419 superList = new ArrayList (); 420 roseUtil.superTable.put(parent, superList); 421 } 422 superList.add(quidu); 423 superList.add(roseNode.getStereotype()); 424 } 425 426 protected void visitClassattribute(RoseNode roseNode, String roseNodeValue, String objectKey, String objectName, Object parent) 427 { 428 if (parent instanceof EEnum) 431 { 432 EEnumLiteral eEnumLiteral = ((EEnum)parent).getEEnumLiteral(objectName); 433 if (eEnumLiteral == null) 434 { 435 eEnumLiteral = ecoreFactory.createEEnumLiteral(); 436 String literalName = roseNode.getAttributeName(); 437 if (literalName == null || literalName.length() == 0) 438 { 439 literalName = validName(objectName); 440 } 441 eEnumLiteral.setName(literalName); 442 roseNode.setNode(eEnumLiteral); 443 if (!setEEnumLiteralProperties(roseNode, eEnumLiteral)) 444 { 445 if (((EEnum)parent).getELiterals() == null) 446 { 447 eEnumLiteral.setValue(0); 448 } 449 else 450 { 451 eEnumLiteral.setValue(((EEnum)parent).getELiterals().size()); 452 } 453 } 454 ((EEnum)parent).getELiterals().add(eEnumLiteral); 455 } 456 } 457 else if (parent instanceof EClassifier) 458 { 459 String stereoTypeValue = null; 460 RoseNode stereoTypeNode = roseNode.findNodeWithKey(RoseStrings.STEREOTYPE); 461 if (stereoTypeNode != null) 462 { 463 stereoTypeValue = stereoTypeNode.getValue(); 464 stereoTypeValue = stereoTypeValue.substring(1, stereoTypeValue.length() - 1); 465 } 466 467 if ((parent instanceof EDataType || (parent instanceof EClass && ((EClass)parent).isInterface())) 468 && "javaclass".equalsIgnoreCase(stereoTypeValue)) 469 { 470 roseUtil.typeTable.remove(parent); 471 ((EClassifier)parent).setInstanceClassName(objectName); 472 } 473 else if (parent instanceof EClass) 474 { 475 EAttribute eAttribute = ecoreFactory.createEAttribute(); 476 String attributeName = roseNode.getAttributeName(); 477 if (attributeName == null || attributeName.length() == 0) 478 { 479 attributeName = validName(objectName); 480 } 481 482 eAttribute.setName(attributeName); 483 roseNode.setNode(eAttribute); 484 setEAttributeProperties(roseNode, eAttribute); 485 ((EClass)parent).getEStructuralFeatures().add(eAttribute); 486 if (eAttribute.getUpperBound() == 0) 487 { 488 eAttribute.setUpperBound(1); 489 } 490 } 491 } 492 } 493 494 protected void visitAssociation(RoseNode roseNode, String roseNodeValue, String objectKey, String objectName, Object parent) 495 { 496 ref1 = null; 497 ref2 = null; 498 role1 = null; 499 role2 = null; 500 } 501 502 protected void visitRole(RoseNode roseNode, String roseNodeValue, String objectKey, String objectName, Object parent) 503 { 504 EReference ref = ecoreFactory.createEReference(); 507 ref.setUpperBound(0); 508 String referenceName = roseNode.getReferenceName(); 509 if (referenceName == null || referenceName.length() == 0) 510 { 511 referenceName = validName(objectName); 512 } 513 ref.setName(referenceName); 514 roseNode.setNode(ref); 515 setEReferenceProperties(roseNode, ref); 516 if (ref1 == null) 517 { 518 ref1 = ref; 519 } 520 else if (ref2 == null) 521 { 522 ref2 = ref; 523 } 524 if (role1 == null) 525 { 526 role1 = roseNode; 527 } 528 else if (role2 == null) 529 { 530 role2 = roseNode; 531 } 532 if (ref1 != null && ref2 != null && role1 != null && role2 != null) 533 { 534 String ref1Quidu = role1.getRoseRefId(); 535 if (ref1Quidu != null && !ref1Quidu.equals("")) 536 { 537 ref1Quidu = ref1Quidu.substring(1, ref1Quidu.length() - 1); 538 } 539 String ref2Quidu = role2.getRoseRefId(); 540 if (ref2Quidu != null && !ref2Quidu.equals("")) 541 { 542 ref2Quidu = ref2Quidu.substring(1, ref2Quidu.length() - 1); 543 } 544 boolean ref1Navigable = role1.isNavigable(); 545 boolean ref2Navigable = role2.isNavigable(); 546 if (ref1Navigable) 547 { 548 ref2.setEOpposite(ref1); 549 setEReferenceIsContainment(ref1, role1, role2); 550 roseUtil.refTable.put(ref1, ref2Quidu); 551 TableObject obj = (TableObject)roseUtil.quidTable.get(ref1Quidu); 552 if (obj != null) 553 { 554 roseUtil.typeTable.put(ref1, obj.getName()); 555 } 556 else 557 { 558 warning(RoseImporterPlugin.INSTANCE.getString("_UI_UnresolvedTypeNameFor_message", new Object []{ 559 role1.getRoseSupplier(), 560 ref1.getName() })); 561 roseUtil.typeTable.put(ref1, "EObject"); 562 } 563 } 564 if (ref2Navigable) 565 { 566 ref1.setEOpposite(ref2); 567 setEReferenceIsContainment(ref2, role2, role1); 568 roseUtil.refTable.put(ref2, ref1Quidu); 569 TableObject obj = (TableObject)roseUtil.quidTable.get(ref2Quidu); 570 if (obj != null) 571 { 572 roseUtil.typeTable.put(ref2, obj.getName()); 573 } 574 else 575 { 576 warning(RoseImporterPlugin.INSTANCE.getString("_UI_UnresolvedTypeNameFor_message", new Object []{ 577 role2.getRoseSupplier(), 578 ref2.getName() })); 579 roseUtil.typeTable.put(ref2, "EObject"); 580 } 581 } 582 } 583 584 if (ref.getUpperBound() == 0) 585 { 586 setEReferenceDefaultMultiplicity(ref); 587 } 588 } 589 590 protected EList getExtentFromTableObject(RoseNode roseNode) 591 { 592 String quid = roseNode.getRoseId(); 593 if (quid != null) 594 { 595 quid = quid.substring(1, quid.length() - 1); 596 } 597 TableObject obj = (TableObject)roseUtil.quidTable.get(quid); 598 return obj == null ? null : obj.getContainer().getExtent(); 599 } 600 601 protected void setEReferenceIsContainment(EReference ref, RoseNode role1, RoseNode role2) 602 { 603 boolean isAggregate = role2.isAggregate(); 604 String containmentV = role1.getContainment(); 605 if (isAggregate && (containmentV != null && containmentV.equalsIgnoreCase("by value"))) 606 { 607 EReference opposite = ref.getEOpposite(); 608 if (opposite != null) 609 { 610 if (opposite.getUpperBound() != 1) 611 { 612 if (bounded.contains(opposite)) 613 { 614 error(RoseImporterPlugin.INSTANCE.getString("_UI_ContainerRelationUpperBound_message", new Object []{ 615 ref.getName(), 616 ref.getEOpposite().getName() })); 617 } 618 opposite.setUpperBound(1); 619 } 620 } 621 ref.setContainment(true); 622 } 623 } 624 625 protected void setResultType(RoseNode roseNode, EOperation eOperation) 626 { 627 String quid = roseNode.getRoseRefId(); 628 if (quid != null && !quid.equals("")) 629 { 630 quid = quid.substring(1, quid.length() - 1); 631 TableObject tableObj = (TableObject)roseUtil.quidTable.get(quid); 632 if (tableObj != null) 633 { 634 roseUtil.typeTable.put(eOperation, tableObj.getName()); 635 } 636 else 637 { 638 warning(RoseImporterPlugin.INSTANCE.getString("_UI_UnresolvedTypeIDFor_message", new Object []{ quid, eOperation.getName() })); 639 roseUtil.typeTable.put(eOperation, "EString"); 640 } 641 } 642 else 643 { 644 String resultValue = getQualifiedTypeName(eOperation, roseNode.getResult()); 645 if (resultValue != null && !resultValue.equalsIgnoreCase("void")) 646 { 647 if (!resultValue.equals("")) 648 { 649 roseUtil.typeTable.put(eOperation, resultValue); 650 } 651 else 652 { 653 warning(RoseImporterPlugin.INSTANCE.getString("_UI_UnresolvedTypeNameFor_message", new Object []{ 654 roseNode.getRoseSupplier(), 655 eOperation.getName() })); 656 roseUtil.typeTable.put(eOperation, "EString"); 657 } 658 } 659 } 660 } 661 662 protected static final Pattern ANNOTATION_PATTERN = Pattern.compile("\\G\\s*((?>\\\\.|\\S)+)((?:\\s+(?>\\\\.|\\S)+\\s*+=\\s*(['\"])((?>\\\\.|.)*?)\\3)*)"); 663 664 protected static final Pattern ANNOTATION_DETAIL_PATTERN = Pattern.compile("\\s+((?>\\\\.|\\S)+)\\s*+=\\s*((['\"])((?>\\\\.|.)*?)\\3)"); 665 666 protected void setEModelElementProperties(RoseNode roseNode, EModelElement eModelElement) 667 { 668 String annotation = roseNode.getAnnotation(); 669 if (annotation != null) 670 { 671 for (Matcher matcher = ANNOTATION_PATTERN.matcher(annotation); matcher.find();) 672 { 673 EAnnotation eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation(); 674 eAnnotation.setSource(CodeGenUtil.parseString(matcher.group(1))); 675 for (Matcher detailMatcher = ANNOTATION_DETAIL_PATTERN.matcher(matcher.group(2)); detailMatcher.find();) 676 { 677 eAnnotation.getDetails().put(CodeGenUtil.parseString(detailMatcher.group(1)), CodeGenUtil.parseString(detailMatcher.group(4))); 678 } 679 eModelElement.getEAnnotations().add(eAnnotation); 680 } 681 } 682 String documentation = roseNode.getDocumentation(); 683 if (documentation != null) 684 { 685 EcoreUtil.setDocumentation(eModelElement, documentation); 686 } 687 688 String constraints = roseNode.getEcoreConstraints(); 689 if (constraints != null) 690 { 691 List constraintList = new ArrayList (); 692 for (StringTokenizer stringTokenizer = new StringTokenizer (constraints); stringTokenizer.hasMoreTokens();) 693 { 694 String constraint = stringTokenizer.nextToken(); 695 constraintList.add(constraint); 696 } 697 EcoreUtil.setConstraints(eModelElement, constraintList); 698 } 699 } 700 701 protected void setEPackageProperties(RoseNode roseNode, EPackage ePackage, String tentativeName) 702 { 703 roseNode.setNode(ePackage); 704 705 setEModelElementProperties(roseNode, ePackage); 706 707 String packageName = roseNode.getPackageName(); 708 if (packageName == null || packageName.length() == 0) 709 { 710 packageName = validName(tentativeName); 711 } 712 ePackage.setName(packageName); 713 714 String basePackage = roseNode.getBasePackage(); 715 String prefix = validName(upperCaseName(roseNode.getPrefix())); 716 String nsPrefix = roseNode.getNsPrefix() == null || roseNode.getNsPrefix().length() == 0 717 ? (String )roseUtil.packageNameToNSNameMap.get(packageName) : roseNode.getNsPrefix(); 718 if (nsPrefix == null || nsPrefix.length() == 0) 719 { 720 nsPrefix = packageName; 721 EPackage eSuperPackage = ePackage.getESuperPackage(); 722 if (eSuperPackage != null) 723 { 724 nsPrefix = eSuperPackage.getNsPrefix() + "." + nsPrefix; 725 } 726 else if (basePackage != null && basePackage.length() != 0) 727 { 728 nsPrefix = basePackage + "." + nsPrefix; 729 } 730 } 731 ePackage.setNsPrefix(nsPrefix); 732 733 String nsURI = roseNode.getNsURI() == null || roseNode.getNsURI().length() == 0 734 ? (String )roseUtil.packageNameToNSURIMap.get(packageName) : roseNode.getNsURI(); 735 if (nsURI == null || nsURI.length() == 0) 736 { 737 if (noQualify) 738 { 739 nsURI = nsPrefix + ".ecore"; 740 } 741 else 742 { 743 nsURI = "http:///" + nsPrefix.replace('.', '/') + ".ecore"; 744 } 745 } 746 ePackage.setNsURI(nsURI); 747 748 if (prefix != null && prefix.length() == 0) 749 prefix = null; 750 if (basePackage != null && basePackage.length() == 0) 751 basePackage = null; 752 753 if (prefix != null || basePackage != null) 754 { 755 List information = new ArrayList (); 756 information.add(basePackage); 757 information.add(prefix); 758 roseUtil.getEPackageToInformationMap().put(ePackage, information); 759 } 760 } 761 762 protected void setEClassProperties(RoseNode roseNode, EClass eClass) 763 { 764 setEModelElementProperties(roseNode, eClass); 765 String xmlName = roseNode.getXMLName(); 766 if (xmlName != null && xmlName.length() != 0) 767 { 768 ExtendedMetaData.INSTANCE.setName(eClass, xmlName); 769 } 770 int xmlContentKind = roseNode.getXMLContentKind(); 771 if (xmlContentKind != 0) 772 { 773 ExtendedMetaData.INSTANCE.setContentKind(eClass, xmlContentKind); 774 } 775 eClass.setAbstract(roseNode.isAbstract()); 776 } 777 778 protected void setEDataTypeProperties(RoseNode roseNode, EDataType eDataType) 779 { 780 setEModelElementProperties(roseNode, eDataType); 781 eDataType.setSerializable(!roseNode.isAbstract()); 782 } 783 784 protected void setEEnumProperties(RoseNode roseNode, EEnum eEnum) 785 { 786 setEModelElementProperties(roseNode, eEnum); 787 String value = roseNode.getDocumentation(); 788 if (value != null && !value.equals("")) 789 { 790 eEnums.put(eEnum, value); 791 } 792 } 793 794 protected void populateEEnumFromDocumentation(EEnum eEnum, String documentation) 795 { 796 List eLiterals = eEnum.getELiterals(); 799 for (StringTokenizer stringTokenizer = new StringTokenizer (documentation, ", \n\r\t"); stringTokenizer.hasMoreTokens();) 800 { 801 String literalV = stringTokenizer.nextToken(); 802 String name = literalV; 803 String number = ""; 804 int ind = literalV.indexOf("="); 805 if (ind != -1) 806  
|