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 { 807 name = literalV.substring(0, ind); 808 number = literalV.substring(ind + 1, literalV.length()); 809 } 810 int numberValue = 0; 811 if (!number.equals("")) 812 { 813 numberValue = new Integer (number).intValue(); 814 } 815 else if (!eLiterals.isEmpty()) 816 { 817 numberValue = ((EEnumLiteral)eLiterals.get(eLiterals.size() - 1)).getValue() + 1; 818 } 819 820 if (!name.equals("")) 821 { 822 EEnumLiteral lit = eEnum.getEEnumLiteral(name); 823 if (lit == null) 824 { 825 lit = ecoreFactory.createEEnumLiteral(); 826 lit.setName(validName(name)); 827 lit.setValue(numberValue); 828 eLiterals.add(lit); 829 } 830 else 831 { 832 lit.setValue(numberValue); 833 } 834 } 835 } 836 } 837 838 protected void setEOperationProperties(RoseNode roseNode, EOperation eOperation) 839 { 840 setETypedElementProperties(roseNode, eOperation); 841 eOperation.setUnique(roseNode.isUnique()); 842 843 String semantics = roseNode.getSemantics(); 844 if (semantics != null) 845 { 846 EAnnotation eAnnotation = eOperation.getEAnnotation(GenModelPackage.eNS_URI); 847 if (eAnnotation == null) 848 { 849 eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation(); 850 eAnnotation.setSource(GenModelPackage.eNS_URI); 851 eOperation.getEAnnotations().add(eAnnotation); 852 } 853 eAnnotation.getDetails().put("body", semantics); 854 } 855 856 String exceptions = roseNode.getExceptions(); 857 if (exceptions != null) 858 { 859 int count = 0; 860 for (StringTokenizer stringTokenizer = new StringTokenizer (exceptions.trim(), ","); stringTokenizer.hasMoreTokens();) 861 { 862 String exception = stringTokenizer.nextToken().trim(); 866 if (exception.indexOf("[") != -1) 867 { 868 exception = exception.substring(0, exception.indexOf("[")); 869 } 870 String exceptionValue = getQualifiedTypeName(eOperation, exception); 871 if (exceptionValue != null && !exceptionValue.equals("")) 872 { 873 EAnnotation eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation(); 874 eAnnotation.getReferences().add(eOperation); 875 eAnnotation.getDetails().put("position", Integer.toString(count++)); 876 roseUtil.typeTable.put(eAnnotation, exceptionValue); 877 } 878 else 879 { 880 warning(RoseImporterPlugin.INSTANCE.getString("_UI_UnresolvedTypeNameFor_message", new Object []{ 881 roseNode.getRoseSupplier(), 882 eOperation.getName() })); 883 } 884 } 885 } 886 887 String stereotype = roseNode.getStereotype(); 888 if (stereotype != null) 889 { 890 if ("inv".equals(stereotype)) 891 { 892 eOperation.setEType(EcorePackage.eINSTANCE.getEBoolean()); 893 894 eOperation.getEParameters().clear(); 895 896 EParameter eParameter = ecoreFactory.createEParameter(); 897 eParameter.setName("diagnostics"); 898 eParameter.setEType(EcorePackage.eINSTANCE.getEDiagnosticChain()); 899 eOperation.getEParameters().add(eParameter); 900 901 eParameter = ecoreFactory.createEParameter(); 902 eParameter.setName("context"); 903 eParameter.setEType(EcorePackage.eINSTANCE.getEMap()); 904 eOperation.getEParameters().add(eParameter); 905 } 906 } 907 } 908 909 protected void setEAttributeProperties(RoseNode roseNode, EAttribute eAttribute) 910 { 911 eStructuralFeatures.add(eAttribute); 912 913 String quid = roseNode.getRoseRefId(); 914 if (quid != null && !quid.equals("")) 915 { 916 quid = quid.substring(1, quid.length() - 1); 917 TableObject tableObj = (TableObject)roseUtil.quidTable.get(quid); 918 if (tableObj != null) 919 { 920 roseUtil.typeTable.put(eAttribute, tableObj.getName()); 921 } 922 else 923 { 924 warning(RoseImporterPlugin.INSTANCE.getString("_UI_UnresolvedTypeIDFor_message", new Object []{ quid, eAttribute.getName() })); 925 roseUtil.typeTable.put(eAttribute, "String"); 926 } 927 } 928 else 929 { 930 String type = getQualifiedTypeName(eAttribute, roseNode.getType()); 931 if (type != null && !type.equals("")) 932 { 933 roseUtil.typeTable.put(eAttribute, type); 934 } 935 else 936 { 937 roseUtil.typeTable.put(eAttribute, "String"); 938 warning(RoseImporterPlugin.INSTANCE.getString("_UI_AttributeDoesNotDefineItsType_message", new Object []{ eAttribute.getName() })); 939 } 940 } 941 942 String initv = roseNode.getInitV(); 945 if (initv != null && initv.length() >= 2) 946 { 947 if (initv.charAt(0) == '\'' && initv.charAt(initv.length() - 1) == '\'') 948 { 949 try 950 { 951 int i = CodeGenUtil.parseChar(initv.substring(1, initv.length() - 1)); 952 initv = Integer.toString(i); 953 } 954 catch (IllegalArgumentException e) 955 { 956 error(RoseImporterPlugin.INSTANCE.getString("_UI_InvalidDefaultValueForAttribute_message", new Object []{ eAttribute.getName() })); 957 initv = null; 958 } 959 } 960 else if (initv.charAt(0) == '\"' && initv.charAt(initv.length() - 1) == '\"') 961 { 962 try 963 { 964 initv = CodeGenUtil.parseString(initv.substring(1, initv.length() - 1)); 965 } 966 catch (IllegalArgumentException e) 967 { 968 error(RoseImporterPlugin.INSTANCE.getString("_UI_InvalidDefaultValueForAttribute_message", new Object []{ eAttribute.getName() })); 969 initv = null; 970 } 971 } 972 } 973 if (initv != null) 974 { 975 eAttribute.setDefaultValueLiteral(initv); 976 } 977 978 setEStructuralFeatureProperties(roseNode, eAttribute); 979 eAttribute.setDerived(roseNode.isDerived()); 980 981 eAttribute.setTransient(roseNode.isTransient()); 982 eAttribute.setVolatile(roseNode.isVolatile()); 983 eAttribute.setChangeable(roseNode.isChangeable()); 984 eAttribute.setUnique(roseNode.isUnique()); 985 eAttribute.setUnsettable(roseNode.isUnsettable()); 986 eAttribute.setID(roseNode.isID()); 987 988 setEStructuralFeatureVisibility(roseNode, eAttribute); 989 } 990 991 protected void setEReferenceProperties(RoseNode roseNode, EReference eReference) 992 { 993 eStructuralFeatures.add(eReference); 994 995 eReference.setDerived(roseNode.getParent().getParent().isDerived()); 996 setEStructuralFeatureProperties(roseNode, eReference); 997 998 eReference.setTransient(roseNode.isTransient()); 1000 eReference.setVolatile(roseNode.isVolatile()); 1001 eReference.setChangeable(roseNode.isChangeable()); 1002 eReference.setResolveProxies(roseNode.isResolveProxies()); 1003 eReference.setUnsettable(roseNode.isUnsettable()); 1004 1005 setEStructuralFeatureVisibility(roseNode, eReference); 1006 } 1007 1008 protected void setEStructuralFeatureProperties(RoseNode roseNode, EStructuralFeature eStructuralFeature) 1009 { 1010 setETypedElementProperties(roseNode, eStructuralFeature); 1011 1012 String xmlName = roseNode.getXMLName(); 1013 if (xmlName != null && xmlName.length() != 0) 1014 { 1015 ExtendedMetaData.INSTANCE.setName(eStructuralFeature, xmlName); 1016 } 1017 int xmlFeatureKind = roseNode.getXMLFeatureKind(); 1018 if (xmlFeatureKind != 0) 1019 { 1020 ExtendedMetaData.INSTANCE.setFeatureKind(eStructuralFeature, xmlFeatureKind); 1021 } 1022 String xmlNamespace = roseNode.getXMLNamespace(); 1023 if (xmlNamespace != null && xmlNamespace.length() != 0) 1024 { 1025 eStructuralFeatureToXMLNamespaceMap.put(eStructuralFeature, xmlNamespace); 1026 } 1027 } 1028 1029 protected void setETypedElementProperties(RoseNode roseNode, ETypedElement eTypedElement) 1030 { 1031 setEModelElementProperties(roseNode, eTypedElement); 1032 1033 String multiplicity = eTypedElement instanceof EReference ? roseNode.getRoleMultiplicity() : roseNode.getStereotype(); 1034 if (multiplicity != null) 1035 { 1036 bounded.add(eTypedElement); 1037 1038 if (multiplicity.length() > 0 && Character.isLetter(multiplicity.charAt(0)) && !"n".equalsIgnoreCase(multiplicity)) 1039 { 1040 return; 1041 } 1042 1043 StringTokenizer stringTokenizer = new StringTokenizer (multiplicity, ". \n\r\t"); 1044 switch (stringTokenizer.countTokens()) 1045 { 1046 case 1: { 1047 String bound = stringTokenizer.nextToken(); 1048 if (bound.equals("*") || bound.equalsIgnoreCase("n")) 1049 { 1050 eTypedElement.setUpperBound(-1); 1051 } 1052 else 1053 { 1054 try 1055 { 1056 int boundValue = Integer.parseInt(bound); 1057 if (boundValue > 0) 1058 { 1059 eTypedElement.setLowerBound(boundValue); 1060 eTypedElement.setUpperBound(boundValue); 1061 } 1062 else 1063 { 1064 warning(RoseImporterPlugin.INSTANCE.getString("_UI_BadMultiplicityFor_message", new Object []{ 1065 multiplicity, 1066 eTypedElement.getName() })); 1067 } 1068 } 1069 catch (NumberFormatException exception) 1070 { 1071 warning(RoseImporterPlugin.INSTANCE.getString("_UI_BadMultiplicityFor_message", new Object []{ 1072 multiplicity, 1073 eTypedElement.getName() })); 1074 } 1075 } 1076 break; 1077 } 1078 case 2: { 1079 String lowerBound = stringTokenizer.nextToken(); 1080 try 1081 { 1082 int lowerBoundValue = Integer.parseInt(lowerBound); 1083 if (lowerBoundValue >= 0) 1084 { 1085 String upperBound = stringTokenizer.nextToken(); 1086 if (upperBound.equals("*") || upperBound.equalsIgnoreCase("n")) 1087 { 1088 eTypedElement.setLowerBound(lowerBoundValue); 1089 eTypedElement.setUpperBound(-1); 1090 } 1091 else 1092 { 1093 int upperBoundValue = Integer.parseInt(upperBound); 1094 if (upperBoundValue <= 0 || lowerBoundValue > upperBoundValue) 1095 { 1096 warning(RoseImporterPlugin.INSTANCE.getString("_UI_BadMultiplicityFor_message", new Object []{ 1097 multiplicity, 1098 eTypedElement.getName() })); 1099 } 1100 else 1101 { 1102 eTypedElement.setLowerBound(lowerBoundValue); 1103 eTypedElement.setUpperBound(upperBoundValue); 1104 } 1105 } 1106 } 1107 else 1108 { 1109 warning(RoseImporterPlugin.INSTANCE.getString("_UI_BadMultiplicityFor_message", new Object []{ 1110 multiplicity, 1111 eTypedElement.getName() })); 1112 } 1113 } 1114 catch (NumberFormatException exception) 1115 { 1116 warning(RoseImporterPlugin.INSTANCE.getString("_UI_BadMultiplicityFor_message", new Object []{ 1117 multiplicity, 1118 eTypedElement.getName() })); 1119 } 1120 break; 1121 } 1122 default: { 1123 warning(RoseImporterPlugin.INSTANCE.getString("_UI_BadMultiplicityFor_message", new Object []{ 1124 multiplicity, 1125 eTypedElement.getName() })); 1126 } 1127 } 1128 } 1129 } 1130 1131 1134 protected void setEStructuralFeatureVisibility(RoseNode roseNode, EStructuralFeature eStructuralFeature) 1135 { 1136 switch (roseNode.getVisibility()) 1137 { 1138 case RoseNode.VISIBILITY_NONE: 1139 EcoreUtil.setSuppressedVisibility(eStructuralFeature, EcoreUtil.GET, true); 1140 1141 if (eStructuralFeature.isChangeable() && !eStructuralFeature.isMany()) 1142 { 1143 EcoreUtil.setSuppressedVisibility(eStructuralFeature, EcoreUtil.SET, true); 1144 } 1145 1146 if (eStructuralFeature.isUnsettable()) 1147 { 1148 EcoreUtil.setSuppressedVisibility(eStructuralFeature, EcoreUtil.IS_SET, true); 1149 if (eStructuralFeature.isChangeable()) 1150 { 1151 EcoreUtil.setSuppressedVisibility(eStructuralFeature, EcoreUtil.UNSET, true); 1152 } 1153 } 1154 break; 1155 case RoseNode.VISIBILITY_READ_ONLY: 1156 if (eStructuralFeature.isMany()) 1157 { 1158 warning(RoseImporterPlugin.INSTANCE.getString("_UI_InvalidReadOnlyVisibility_message", new Object []{ eStructuralFeature.getName() })); 1159 } 1160 else if (eStructuralFeature.isChangeable()) 1161 { 1162 EcoreUtil.setSuppressedVisibility(eStructuralFeature, EcoreUtil.SET, true); 1163 } 1164 1165 if (eStructuralFeature.isUnsettable()) 1166 { 1167 EcoreUtil.setSuppressedVisibility(eStructuralFeature, EcoreUtil.IS_SET, true); 1168 if (eStructuralFeature.isChangeable()) 1169 { 1170 EcoreUtil.setSuppressedVisibility(eStructuralFeature, EcoreUtil.UNSET, true); 1171 } 1172 } 1173 break; 1174 case RoseNode.VISIBILITY_READ_WRITE: 1175 if (!eStructuralFeature.isChangeable() && !eStructuralFeature.isMany()) 1176 { 1177 warning(RoseImporterPlugin.INSTANCE.getString( 1178 "_UI_InvalidReadWriteVisibility_message", 1179 new Object []{ eStructuralFeature.getName() })); 1180 } 1181 1182 if (eStructuralFeature.isUnsettable()) 1183 { 1184 EcoreUtil.setSuppressedVisibility(eStructuralFeature, EcoreUtil.IS_SET, true); 1185 if (eStructuralFeature.isChangeable()) 1186 { 1187 EcoreUtil.setSuppressedVisibility(eStructuralFeature, EcoreUtil.UNSET, true); 1188 } 1189 } 1190 break; 1191 case RoseNode.VISIBILITY_READ_ONLY_UNSETTABLE: 1192 if (eStructuralFeature.isMany()) 1193 { 1194 warning(RoseImporterPlugin.INSTANCE.getString("_UI_InvalidReadOnlyVisibility_message", new Object []{ eStructuralFeature.getName() })); 1195 } 1196 else if (eStructuralFeature.isChangeable()) 1197 { 1198 EcoreUtil.setSuppressedVisibility(eStructuralFeature, EcoreUtil.SET, true); 1199 } 1200 1201 if (!eStructuralFeature.isUnsettable()) 1202 { 1203 warning(RoseImporterPlugin.INSTANCE.getString( 1204 "_UI_InvalidUnsettableVisibility_message", 1205 new Object []{ eStructuralFeature.getName() })); 1206 } 1207 else if (eStructuralFeature.isChangeable()) 1208 { 1209 EcoreUtil.setSuppressedVisibility(eStructuralFeature, EcoreUtil.UNSET, true); 1210 } 1211 break; 1212 case RoseNode.VISIBILITY_READ_WRITE_UNSETTABLE: 1213 if (!eStructuralFeature.isChangeable()) 1214 { 1215 warning(RoseImporterPlugin.INSTANCE.getString( 1216 "_UI_InvalidReadWriteVisibility_message", 1217 new Object []{ eStructuralFeature.getName() })); 1218 } 1219 if (!eStructuralFeature.isUnsettable()) 1220 { 1221 warning(RoseImporterPlugin.INSTANCE.getString( 1222 "_UI_InvalidUnsettableVisibility_message", 1223 new Object []{ eStructuralFeature.getName() })); 1224 } 1225 break; 1226 default: 1227 break; 1228 } 1229 } 1230 1231 protected boolean setEEnumLiteralProperties(RoseNode roseNode, EEnumLiteral eEnumLiteral) 1232 { 1233 setEModelElementProperties(roseNode, eEnumLiteral); 1234 String value = roseNode.getInitV(); 1235 if (value != null && !value.equals("")) 1236 { 1237 eEnumLiteral.setValue(Integer.parseInt(value)); 1238 return true; 1239 } 1240 else 1241 { 1242 return false; 1243 } 1244 } 1245 1246 protected void setEParameterProperties(RoseNode roseNode, EParameter eParameter) 1247 { 1248 setEModelElementProperties(roseNode, eParameter); 1249 String quid = roseNode.getRoseRefId(); 1250 if (quid != null && !quid.equals("")) 1251 { 1252 quid = quid.substring(1, quid.length() - 1); 1253 TableObject tableObj = (TableObject)roseUtil.quidTable.get(quid); 1254 1255 if (tableObj != null) 1256 { 1257 roseUtil.typeTable.put(eParameter, tableObj.getName()); 1258 } 1259 else 1260 { 1261 warning(RoseImporterPlugin.INSTANCE.getString("_UI_UnresolvedTypeIDFor_message", new Object []{ 1262 quid, 1263 eParameter.getEOperation().getName() })); 1264 roseUtil.typeTable.put(eParameter, "EObject"); 1265 } 1266 } 1267 else 1268 { 1269 String type = getQualifiedTypeName(eParameter, roseNode.getType()); 1270 if (type != null && !type.equals("")) 1271 { 1272 roseUtil.typeTable.put(eParameter, type); 1273 } 1274 else 1275 { 1276 warning(RoseImporterPlugin.INSTANCE.getString("_UI_UnresolvedTypeNameFor_message", new Object []{ 1277 roseNode.getRoseSupplier(), 1278 eParameter.getEOperation().getName() })); 1279 roseUtil.typeTable.put(eParameter, "EObject"); 1280 } 1281 } 1282 } 1283 1284 protected void setEReferenceDefaultMultiplicity(EReference eReference) 1285 { 1286 if (eReference.getEOpposite() == null || !eReference.getEOpposite().isContainment()) 1287 { 1288 eReference.setLowerBound(0); 1289 eReference.setUpperBound(-1); 1290 } 1291 } 1292 1293 public void setEEnums() 1294 { 1295 for (Iterator i = eEnums.entrySet().iterator(); i.hasNext();) 1296 { 1297 Map.Entry entry = (Map.Entry )i.next(); 1298 EEnum eEnum = (EEnum)entry.getKey(); 1299 if (eEnum.getELiterals().isEmpty()) 1300 { 1301 populateEEnumFromDocumentation(eEnum, (String )entry.getValue()); 1302 } 1303 } 1304 } 1305 1306 protected static Comparator eClassComparator = new Comparator () 1307 { 1308 public int compare(Object o1, Object o2) 1309 { 1310 EClass c1 = (EClass)o1; 1313 EClass c2 = (EClass)o2; 1314 int count1 = c1.getEAllAttributes().size() + c1.getEAllReferences().size(); 1315 int count2 = c2.getEAllAttributes().size() + c2.getEAllReferences().size(); 1316 if (count1 < count2) 1317 return 1; 1318 if (count1 > count2) 1319 return -1; 1320 return c1.getName().compareTo(c2.getName()); 1321 } 1322 }; 1323 1324 public void setSuper() 1325 { 1326 Map superMap = new HashMap (); 1327 1328 for (Iterator i = roseUtil.superTable.keySet().iterator(); i.hasNext();) 1329 { 1330 Object subObject = i.next(); 1331 if (subObject instanceof EClass) 1332 { 1333 EClass eClass = (EClass)subObject; 1334 List extend = new ArrayList (); 1335 List unspecified = new ArrayList (); 1336 List mixin = new ArrayList (); 1337 List nonClass = new ArrayList (); 1338 for (Iterator j = ((List )roseUtil.superTable.get(eClass)).iterator(); j.hasNext();) 1339 { 1340 String quid = (String )j.next(); 1341 String stereotype = (String )j.next(); 1342 TableObject tableObject = (TableObject)roseUtil.quidTable.get(quid); 1343 if (tableObject != null) 1344 { 1345 Object superObject = tableObject.getObject(); 1346 if (superObject instanceof EClass) 1347 { 1348 EClass superClass = (EClass)superObject; 1349 if (!superClass.isInterface()) 1350 { 1351 if ("extend".equals(stereotype)) 1352 { 1353 extend.add(superObject); 1354 } 1355 else if ("mixin".equals(stereotype)) 1356 { 1357 mixin.add(superObject); 1358 } 1359 else 1360 { 1361 unspecified.add(superObject); 1362 } 1363 } 1364 else 1365 { 1366 nonClass.add(superObject); 1367 } 1368 } 1369 else 1370 { 1371 warning(RoseImporterPlugin.INSTANCE.getString("_UI_CannotAddSuperLinkBetween_message", new Object []{ 1372 eClass.getName(), 1373 ((ENamedElement)superObject).getName() })); 1374 } 1375 } 1376 } 1377 1378 if (extend.size() > 1) 1379 { 1380 warning(RoseImporterPlugin.INSTANCE.getString("_UI_CannotSpecifyMoreThanOneExtendFor_message", new Object []{ eClass.getName() })); 1381 } 1382 1383 superMap.put(eClass, new List []{ extend, unspecified, mixin }); 1384 1385 eClass.getESuperTypes().addAll(extend); 1386 eClass.getESuperTypes().addAll(unspecified); 1387 eClass.getESuperTypes().addAll(mixin); 1388 eClass.getESuperTypes().addAll(nonClass); 1389 } 1390 else 1391 { 1392 warning(RoseImporterPlugin.INSTANCE.getString( 1393 "_UI_CannotAddSuperLinkInvolving_message", 1394 new Object []{ ((ENamedElement)subObject).getName() })); 1395 } 1396 } 1397 1398 sortSuper(superMap); 1399 } 1400 1401 protected void sortSuper(Map superMap) 1402 { 1403 for (Iterator entries = superMap.entrySet().iterator(); entries.hasNext();) 1404 { 1405 Map.Entry entry = (Map.Entry )entries.next(); 1406 EClass eClass = (EClass)entry.getKey(); 1407 List [] collections = (List [])entry.getValue(); 1408 Collections.sort(collections[0], eClassComparator); 1409 Collections.sort(collections[1], eClassComparator); 1410 Collections.sort(collections[2], eClassComparator); 1411 List combined = new UniqueEList(collections[0]); 1412 combined.addAll(collections[1]); 1413 combined.addAll(collections[2]); 1414 EList eSuper = eClass.getESuperTypes(); 1415 for (ListIterator ordered = combined.listIterator(); ordered.hasNext();) 1416 { 1417 Object eSuperItem = ordered.next(); 1418 eSuper.move(ordered.previousIndex(), eSuperItem); 1419 } 1420 } 1421 } 1422 1423 public void setIDs(final EObject parent, EObject child) 1424 { 1425 new EcoreSwitch() 1426 { 1427 public Object caseEPackage(EPackage ePackage) 1428 { 1429 return null; 1430 } 1431 1432 public Object caseEClassifier(EClassifier eClassifier) 1433 { 1434 return null; 1435 } 1436 1437 public Object caseEOperation(EOperation eOperation) 1438 { 1439 return null; 1440 } 1441 1442 public Object caseEParameter(EParameter eParameter) 1443 { 1444 return null; 1445 } 1446 1447 public Object caseEStructuralFeature(EStructuralFeature eStructuralFeature) 1448 { 1449 return null; 1450 } 1451 1452 public Object caseEEnumLiteral(EEnumLiteral eEnumLiteral) 1453 { 1454 return null; 1455 } 1456 1457 public Object defaultCase(EObject eObject) 1458 { 1459 for (Iterator i = eObject.eContents().iterator(); i.hasNext();) 1460 { 1461 setIDs(eObject, (EObject)i.next()); 1462 } 1463 return this; 1464 } 1465 }.doSwitch(child); 1466 } 1467 1468 public void validate(EObject object) 1469 { 1470 new EcoreSwitch() 1471 { 1472 public Object caseEDataType(EDataType eDataType) 1473 { 1474 return validateEDataType(eDataType); 1475 } 1476 1477 public Object caseEEnum(EEnum eEnum) 1478 { 1479 return validateEEnum(eEnum); 1480 } 1481 1482 public Object caseEClass(EClass eClass) 1483 { 1484 return validateEClass(eClass); 1485 } 1486 1487 public Object defaultCase(EObject eObject) 1488 { 1489 for (Iterator i = eObject.eContents().iterator(); i.hasNext();) 1490 { 1491 validate((EObject)i.next()); 1492 } 1493 return this; 1494 } 1495 }.doSwitch(object); 1496 } 1497 1498 protected Object validateEDataType(EDataType eDataType) 1499 { 1500 if (!(eDataType instanceof EEnum) && eDataType.getInstanceClassName() == null) 1501 { 1502 error(RoseImporterPlugin.INSTANCE.getString("_UI_DatatypeNotSetFor_message", new Object []{ eDataType.getName() })); 1503 eDataType.setInstanceClassName("java.lang.String"); 1504 } 1505 return null; 1506 } 1507 1508 protected Object validateEEnum(EEnum eEnum) 1509 { 1510 for (Iterator literals = eEnum.getELiterals().iterator(); literals.hasNext();) 1511 { 1512 EEnumLiteral eEnumLiteral = (EEnumLiteral)literals.next(); 1513 for (Iterator allLiterals = eEnum.getELiterals().iterator(); allLiterals.hasNext();) 1514 { 1515 EEnumLiteral otherLiteral = (EEnumLiteral)allLiterals.next(); 1516 if (eEnumLiteral == otherLiteral) 1517 { 1518 break; 1519 } 1520 else if (eEnumLiteral.getName().equalsIgnoreCase(otherLiteral.getName())) 1521 { 1522 error(RoseImporterPlugin.INSTANCE.getString("_UI_DuplicateLiteral_message", new Object []{ eEnumLiteral.getName(), eEnum.getName() })); 1523 literals.remove(); 1524 break; 1525 } 1526 } 1527 } 1528 return this; 1529 } 1530 1531 protected Object validateEClass(EClass eClass) 1532 { 1533 List oppositesToRemove = new ArrayList (); 1534 for (Iterator features = eClass.getEStructuralFeatures().iterator(); features.hasNext();) 1535 { 1536 EStructuralFeature eStructuralFeature = (EStructuralFeature)features.next(); 1537 if (eStructuralFeature instanceof EAttribute) 1538 { 1539 EAttribute eAttribute = (EAttribute)eStructuralFeature; 1540 1541 if (unsettablePrimitive) 1544 { 1545 try 1546 { 1547 EDataType eDataType = eAttribute.getEAttributeType(); 1548 if (eDataType instanceof EEnum || eDataType.getInstanceClass().isPrimitive()) 1549 { 1550 eAttribute.setUnsettable(true); 1551 } 1552 } 1553 catch (Exception e) 1554 { 1555 } 1556 } 1557 1558 for (Iterator allFeatures = eClass.getEAllStructuralFeatures().iterator(); allFeatures.hasNext();) 1559 { 1560 EStructuralFeature otherFeature = (EStructuralFeature)allFeatures.next(); 1561 if (eAttribute == otherFeature) 1562 { 1563 break; 1564 } 1565 else if (eAttribute.getName().equalsIgnoreCase(otherFeature.getName())) 1566 { 1567 error(RoseImporterPlugin.INSTANCE.getString("_UI_DuplicateAttribute_message", new Object []{ 1568 eAttribute.getName(), 1569 eClass.getName() })); 1570 features.remove(); 1571 break; 1572 } 1573 else if (!eAttribute.getEAttributeType().isSerializable() && !eAttribute.isTransient()) 1574 { 1575 error(RoseImporterPlugin.INSTANCE.getString("_UI_TheAttributeShouldBeTransient_message", new Object []{ 1576 eAttribute.getName(), 1577 eAttribute.getEType().getName() })); 1578 break; 1579 } 1580 1581 } 1582 } 1583 else 1584 { 1585 EReference eReference = (EReference)eStructuralFeature; 1586 EReference opposite = eReference.getEOpposite(); 1587 if (opposite != null) 1588 { 1589 if (opposite.eContainer() == null) 1590 { 1591 error(RoseImporterPlugin.INSTANCE.getString("_UI_AnAssociationHasADanglingEnd_message", new Object []{ 1592 opposite.getName(), 1593 eReference.getName() })); 1594 opposite = null; 1595 eReference.setEOpposite(null); 1596 } 1597 else if (opposite.isContainment()) 1598 { 1599 eReference.setTransient(true); 1602 1603 if (eReference.getUpperBound() != 1) 1604 { 1605 if (bounded.contains(eReference)) 1606 { 1607 error(RoseImporterPlugin.INSTANCE.getString("_UI_ContainerRelationUpperBound_message", new Object []{ 1608 opposite.getName(), 1609 eReference.getName() })); 1610 } 1611 eReference.setUpperBound(1); 1612 } 1613 } 1614 } 1615 1616 if (eReference.isTransient() && !eReference.isVolatile() && opposite != null && !opposite.isTransient() 1617 && opposite.isResolveProxies() && !opposite.isContainment()) 1618 { 1619 error(RoseImporterPlugin.INSTANCE.getString("_UI_CrossDocumentBidirectionalTransient_message", new Object []{ 1620 opposite.getName(), 1621 eReference.getName() })); 1622 } 1623 1624 for (Iterator allFeatures = eClass.getEAllStructuralFeatures().iterator(); allFeatures.hasNext();) 1625 { 1626 EStructuralFeature otherFeature = (EStructuralFeature)allFeatures.next(); 1627 if (eReference == otherFeature) 1628 { 1629 break; 1630 } 1631 else if (eReference.getName().equalsIgnoreCase(otherFeature.getName())) 1632 { 1633 error(RoseImporterPlugin.INSTANCE.getString("_UI_DuplicateReference_message", new Object []{ 1634 eReference.getName(), 1635 eClass.getName() })); 1636 if (opposite != null) 1637 { 1638 oppositesToRemove.add(opposite); 1639 } 1640 features.remove(); 1641 break; 1642 } 1643 } 1644 1645 if (!eReference.isContainer() && "java.util.Map$Entry".equals(eReference.getEType().getInstanceClassName())) 1646 { 1647 if (!eReference.isContainment() || !eReference.isMany()) 1648 { 1649 error(RoseImporterPlugin.INSTANCE.getString("_UI_MultiplicityManyContainmentIsAssumedFor_message", new Object []{ 1650 eReference.getName(), 1651 eClass.getName() })); 1652 eReference.setContainment(true); 1653 eReference.setUpperBound(-1); 1654 } 1655 } 1656 } 1657 } 1658 1659 for (Iterator opposites = oppositesToRemove.iterator(); opposites.hasNext();) 1660 { 1661 EReference opposite = (EReference)opposites.next(); 1662 EClass oppositeEClass = opposite.getEContainingClass(); 1663 if (oppositeEClass != null) 1664 { 1665 oppositeEClass.getEStructuralFeatures().remove(opposite); 1666 } 1667 } 1668 1669 for (Iterator operations = eClass.getEOperations().iterator(); operations.hasNext();) 1670 { 1671 EOperation eOperation = (EOperation)operations.next(); 1672 EClassifier opType = eOperation.getEType(); 1673 1674 if (opType instanceof EClass && "java.util.Map$Entry".equals(opType.getInstanceClassName())) 1675 { 1676 if (!eOperation.isMany()) 1677 { 1678 warning 1679 (RoseImporterPlugin.INSTANCE.getString 1680 ("_UI_MultiplicityManyIsAssumedForOperation_message", new Object [] { eOperation.getName(), eClass.getName() })); 1681 eOperation.setUpperBound(-1); 1682 } 1683 } 1684 1685 for (Iterator paramters = eOperation.getEParameters().iterator(); paramters.hasNext();) 1686 { 1687 EParameter eParameter = (EParameter)paramters.next(); 1688 EClassifier paramType = eParameter.getEType(); 1689 1690 if (paramType instanceof EClass && "java.util.Map$Entry".equals(paramType.getInstanceClassName())) 1691 { 1692 if (!eParameter.isMany()) 1693 { 1694 warning 1695 (RoseImporterPlugin.INSTANCE.getString 1696 ("_UI_MultiplicityManyIsAssumedForParameter_message", new Object [] { eParameter.getName(), eOperation.getName(), eClass.getName() })); 1697 eParameter.setUpperBound(-1); 1698 } 1699 } 1700 } 1701 } 1702 1703 if (eClass.getESuperTypes().size() > 1) 1704 { 1705 Iterator superTypes = eClass.getESuperTypes().iterator(); 1706 superTypes.next(); 1707 while (superTypes.hasNext()) 1708 { 1709 EClass superType = (EClass)superTypes.next(); 1710 superFeatureLoop: for (Iterator superFeatures = superType.getEAllStructuralFeatures().iterator(); superFeatures.hasNext();) 1711 { 1712 EStructuralFeature superFeature = (EStructuralFeature)superFeatures.next(); 1713 for (Iterator allFeatures = eClass.getEAllStructuralFeatures().iterator(); allFeatures.hasNext();) 1714 { 1715 EStructuralFeature otherFeature = (EStructuralFeature)allFeatures.next(); 1716 if (superFeature == otherFeature) 1717 { 1718 break; 1719 } 1720 else if (superFeature.getName().equalsIgnoreCase(otherFeature.getName())) 1721 { 1722 error(RoseImporterPlugin.INSTANCE.getString("_UI_DuplicateFeatureInheritance_message", new Object []{ 1723 superFeature.getName(), 1724 eClass.getName(), 1725 superType.getName() })); 1726 superTypes.remove(); 1727 break superFeatureLoop; 1728 } 1729 } 1730 } 1731 } 1732 } 1733 1734 if ("java.util.Map$Entry".equals(eClass.getInstanceClassName())) 1735 { 1736 EStructuralFeature keyFeature = eClass.getEStructuralFeature("key"); 1737 EStructuralFeature valueFeature = eClass.getEStructuralFeature("value"); 1738 if (keyFeature == null) 1739 { 1740 error(RoseImporterPlugin.INSTANCE.getString("_UI_ExpectingFeatureNamedKey_message", new Object []{ eClass.getName() })); 1741 eClass.setInstanceClassName(null); 1742 } 1743 1744 if (valueFeature == null) 1745 { 1746 error(RoseImporterPlugin.INSTANCE.getString("_UI_ExpectingFeatureNamedValue_message", new Object []{ eClass.getName() })); 1747 eClass.setInstanceClassName(null); 1748 } 1749 } 1750 return this; 1751 } 1752 1753 protected Comparator eStructuralFeatureComparator = new Comparator () 1754 { 1755 public int compare(Object o1, Object o2) 1756 { 1757 return eStructuralFeatures.indexOf(o1) - eStructuralFeatures.indexOf(o2); 1758 } 1759 }; 1760 1761 public void setEReferences() 1762 { 1763 for (Iterator i = roseUtil.refTable.keySet().iterator(); i.hasNext();) 1766 { 1767 EReference eReference = (EReference)i.next(); 1768 String quid = (String )roseUtil.refTable.get(eReference); 1769 TableObject tableObject = (TableObject)roseUtil.quidTable.get(quid); 1770 if (tableObject != null) 1771 { 1772 Object struct = tableObject.getObject(); 1773 if (struct instanceof EClass) 1774 { 1775 ((EClass)struct).getEStructuralFeatures().add( 1776 -1 - Collections.binarySearch(((EClass)struct).getEStructuralFeatures(), eReference, eStructuralFeatureComparator), 1777 eReference); 1778 } 1779 else 1780 { 1781 warning(RoseImporterPlugin.INSTANCE.getString("_UI_CannotAddReference_message", new Object []{ 1782 eReference.getName(), 1783 tableObject.getName() })); 1784 } 1785 } 1786 } 1787 1788 for (Iterator i = eStructuralFeatureToXMLNamespaceMap.entrySet().iterator(); i.hasNext();) 1789 { 1790 Map.Entry entry = (Map.Entry )i.next(); 1791 EStructuralFeature eStructuralFeature = (EStructuralFeature)entry.getKey(); 1792 if (eStructuralFeature.eContainer() != null) 1793 { 1794 ExtendedMetaData.INSTANCE.setNamespace((EStructuralFeature)entry.getKey(), (String )entry.getValue()); 1795 } 1796 } 1797 } 1798 1799 public void setETypeClassifier() 1800 { 1801 for (Iterator it = roseUtil.typeTable.keySet().iterator(); it.hasNext();) 1804 { 1805 EModelElement element = (EModelElement)it.next(); 1806 String type = (String )roseUtil.typeTable.get(element); 1807 int position = -1; 1808 if (element instanceof EAnnotation) 1809 { 1810 position = Integer.parseInt((String )((EAnnotation)element).getDetails().get("position")); 1811 element = (EModelElement)((EAnnotation)element).getReferences().get(0); 1812 } 1813 TableObject tableObj = null; 1814 if (type.indexOf(".") == -1) 1815 { 1816 String qualifier = ""; 1817 for (EObject parent = element.eContainer(); parent != null; parent = parent.eContainer()) 1818 { 1819 if (parent instanceof EPackage) 1820 { 1821 qualifier = ((EPackage)parent).getName() + "." + qualifier; 1822 } 1823 } 1824 tableObj = (TableObject)roseUtil.nameTable.get(qualifier + type); 1825 } 1826 1827 if (tableObj == null) 1828 { 1829 tableObj = (TableObject)roseUtil.nameTable.get(type); 1830 } 1831 1832 EClassifier eType; 1833 1834 if (tableObj != null && tableObj.getObject() != null && element instanceof ETypedElement) 1835 { 1836 eType = (EClassifier)tableObj.getObject(); 1839 } 1840 else 1841 { 1842 eType = getBasicType(type); 1845 1846 if (eType == null) 1847 { 1848 warning(RoseImporterPlugin.INSTANCE.getString("_UI_UnresolvedTypeNameFor_message", new Object []{ 1849 type, 1850 ((ENamedElement)element).getName() })); 1851 eType = getBasicType("EString"); 1852 } 1853 } 1854 1855 if (element instanceof EAttribute && eType instanceof EClass) 1856 { 1857 EAttribute eAttribute = (EAttribute)element; 1858 EReference eReference = ecoreFactory.createEReference(); 1859 1860 eReference.setName(eAttribute.getName()); 1861 eReference.setTransient(eAttribute.isTransient()); 1862 eReference.setVolatile(eAttribute.isVolatile()); 1863 eReference.setDerived(eAttribute.isDerived()); 1864 eReference.setChangeable(eAttribute.isChangeable()); 1865 eReference.setLowerBound(eAttribute.getLowerBound()); 1866 eReference.setUpperBound(eAttribute.getUpperBound()); 1867 eReference.setContainment(true); 1868 eReference.getEAnnotations().addAll(eAttribute.getEAnnotations()); 1869 eReference.setUnsettable(eAttribute.isUnsettable()); 1870 1871 eStructuralFeatures.set(eStructuralFeatures.indexOf(eAttribute), eReference); 1872 1873 EClass containingClass = eAttribute.getEContainingClass(); 1874 containingClass.getEStructuralFeatures().add(containingClass.getEStructuralFeatures().indexOf(eAttribute), eReference); 1875 containingClass.getEStructuralFeatures().remove(eAttribute); 1876 1877 element = eReference; 1878 } 1879 else if (element instanceof EReference) 1880 { 1881 EReference eReference = (EReference)element; 1884 boolean convert = eType instanceof EDataType; 1885 1886 int kind = ExtendedMetaData.INSTANCE.getFeatureKind(eReference); 1889 if (kind == ExtendedMetaData.ATTRIBUTE_WILDCARD_FEATURE || kind == ExtendedMetaData.ELEMENT_WILDCARD_FEATURE 1890 || kind == ExtendedMetaData.GROUP_FEATURE) 1891 { 1892 convert = true; 1893 eType = ecorePackage.getEFeatureMapEntry(); 1894 } 1895 1896 if (convert) 1897 { 1898 EAttribute eAttribute = ecoreFactory.createEAttribute(); 1899 1900 eAttribute.setName(eReference.getName()); 1901 eAttribute.setTransient(eReference.isTransient()); 1902 eAttribute.setVolatile(eReference.isVolatile()); 1903 eAttribute.setDerived(eReference.isDerived()); 1904 eAttribute.setChangeable(eReference.isChangeable()); 1905 eAttribute.setLowerBound(eReference.getLowerBound()); 1906 eAttribute.setUpperBound(eReference.getUpperBound()); 1907 eAttribute.getEAnnotations().addAll(eReference.getEAnnotations()); 1908 eAttribute.setUnsettable(eReference.isUnsettable()); 1909 1910 eStructuralFeatures.set(eStructuralFeatures.indexOf(eReference), eAttribute); 1911 1912 EClass containingClass = eReference.getEContainingClass(); 1913 if (containingClass != null) 1914 { 1915 containingClass.getEStructuralFeatures().add(containingClass.getEStructuralFeatures().indexOf(eReference), eAttribute); 1916 containingClass.getEStructuralFeatures().remove(eReference); 1917 } 1918 1919 element = eAttribute; 1920 } 1921 } 1922 1923 if (element instanceof EDataType) 1924 { 1925 ((EDataType)element).setInstanceClassName(eType.getInstanceClassName()); 1926 } 1927 else if (position != -1) 1928 { 1929 List exceptions = ((EOperation)element).getEExceptions(); 1930 if (!exceptions.contains(eType)) 1931 { 1932 if (position < exceptions.size()) 1933 { 1934 exceptions.add(position, eType); 1935 } 1936 else 1937 { 1938 exceptions.add(eType); 1939 } 1940 } 1941 } 1942 else 1943 { 1944 ((ETypedElement)element).setEType(eType); 1945 1946 if (element instanceof EStructuralFeature) 1947 { 1948 EStructuralFeature eStructuralFeature = (EStructuralFeature)element; 1949 if ("".equals(eStructuralFeature.getName())) 1950 { 1951 eStructuralFeature.setName(eType.getName()); 1952 } 1953 } 1954 } 1955 } 1956 } 1957 1958 protected EClassifier getBasicType(String value) 1959 { 1960 if (value.equals("boolean") || value.equalsIgnoreCase("eboolean")) 1961 { 1962 return ecorePackage.getEBoolean(); 1963 } 1964 else if (value.equalsIgnoreCase("boolean") || value.equalsIgnoreCase("ebooleanobject")) 1965 { 1966 return ecorePackage.getEBooleanObject(); 1967 } 1968 else if (value.equalsIgnoreCase("string") || value.equalsIgnoreCase("estring")) 1969 { 1970 return ecorePackage.getEString(); 1971 } 1972 else if (value.equalsIgnoreCase("char") || value.equalsIgnoreCase("echar")) 1973 { 1974 return ecorePackage.getEChar(); 1975 } 1976 else if (value.equalsIgnoreCase("character") || value.equalsIgnoreCase("echaracterobject")) 1977 { 1978 return ecorePackage.getECharacterObject(); 1979 } 1980 else if (value.equals("double") || value.equalsIgnoreCase("edouble") || value.equalsIgnoreCase("currency")) 1981 { 1982 return ecorePackage.getEDouble(); 1983 } 1984 else if (value.equalsIgnoreCase("double") || value.equalsIgnoreCase("edoubleobject")) 1985 { 1986 return ecorePackage.getEDoubleObject(); 1987 } 1988 else if (value.equalsIgnoreCase("int") || value.equalsIgnoreCase("eint")) 1989 { 1990 return ecorePackage.getEInt(); 1991 } 1992 else if (value.equalsIgnoreCase("integer") || value.equalsIgnoreCase("eintegerobject")) 1993 { 1994 return ecorePackage.getEIntegerObject(); 1995 } 1996 else if (value.equals("long long") || value.equals("long") || value.equalsIgnoreCase("elong")) 1997 { 1998 return ecorePackage.getELong(); 1999 } 2000 else if (value.equalsIgnoreCase("long") || value.equalsIgnoreCase("elongobject")) 2001 { 2002 return ecorePackage.getELongObject(); 2003 } 2004 else if (value.equals("float") || value.equalsIgnoreCase("efloat") || value.equalsIgnoreCase("single")) 2005 { 2006 return ecorePackage.getEFloat(); 2007 } 2008 else if (value.equalsIgnoreCase("float") || value.equalsIgnoreCase("efloatobject")) 2009 { 2010 return ecorePackage.getEFloatObject(); 2011 } 2012 else if (value.equals("short") || value.equalsIgnoreCase("eshort")) 2013 { 2014 return ecorePackage.getEShort(); 2015 } 2016 else if (value.equalsIgnoreCase("short") || value.equalsIgnoreCase("eshortobject")) 2017 { 2018 return ecorePackage.getEShortObject(); 2019 } 2020 else if (value.equals("byte") || value.equalsIgnoreCase("ebyte")) 2021 { 2022 return ecorePackage.getEByte(); 2023 } 2024 else if (value.equals("byte[]") || value.equalsIgnoreCase("ebytearray") || value.equalsIgnoreCase("ebyte[]")) 2025 { 2026 return ecorePackage.getEByteArray(); 2027 } 2028 else if (value.equalsIgnoreCase("byte") || value.equalsIgnoreCase("ebyteObject")) 2029 { 2030 return ecorePackage.getEByteObject(); 2031 } 2032 else if (value.equalsIgnoreCase("ebigdecimal")) 2033 { 2034 return ecorePackage.getEBigDecimal(); 2035 } 2036 else if (value.equalsIgnoreCase("ebiginteger")) 2037 { 2038 return ecorePackage.getEBigInteger(); 2039 } 2040 else if (value.equalsIgnoreCase("edate")) 2041 { 2042 return ecorePackage.getEDate(); 2043 } 2044 else if (value.equalsIgnoreCase("eobject")) 2045 { 2046 return ecorePackage.getEObject(); 2047 } 2048 else if (value.equalsIgnoreCase("efeaturemapentry")) 2049 { 2050 return ecorePackage.getEFeatureMapEntry(); 2051 } 2052 else 2053 { 2054 return null; 2055 } 2056 } 2057 2058 public void createEPackageForRootClasses(EList extent, RoseNode roseNode, String packageName) 2059 { 2060 ArrayList list = new ArrayList (); 2061 for (Iterator i = extent.iterator(); i.hasNext();) 2062 { 2063 Object object = i.next(); 2064 if (!(object instanceof EPackage)) 2065 { 2066 list.add(object); 2067 } 2068 } 2069 2070 if (!list.isEmpty()) 2071 { 2072 EPackage ePackage = ecoreFactory.createEPackage(); 2073 setEPackageProperties(roseNode, ePackage, packageName.toLowerCase()); 2074 2075 extent.add(ePackage); 2076 for (Iterator i = list.iterator(); i.hasNext();) 2077 { 2078 EClassifier eClassifier = (EClassifier)i.next(); 2079 ePackage.getEClassifiers().add(eClassifier); 2080 extent.remove(eClassifier); 2081 } 2082 } 2083 } 2084 2085 protected void build(RoseNode roseNode, Object parent, ENamedElement eNamedElement) 2086 { 2087 String quid = roseNode.getRoseId(); 2088 if (quid != null && !quid.equals("")) 2089 { 2090 quid = quid.substring(1, quid.length() - 1); 2091 } 2092 TableObject tableObj = (TableObject)roseUtil.quidTable.get(quid); 2093 if (tableObj != null) 2094 { 2095 tableObj.setObject(eNamedElement); 2096 } 2097 2098 if (parent instanceof EPackage) 2099 { 2100 ((EPackage)parent).getEClassifiers().add(eNamedElement); 2101 } 2102 else if (parent instanceof EList) 2103 { 2104 ((EList)parent).add(eNamedElement); 2105 } 2106 } 2107 2108 protected String upperCaseName(String name) 2109 { 2110 return name != null && name.length() > 0 && Character.isLowerCase(name.charAt(0)) ? Character.toUpperCase(name.charAt(0)) 2111 + name.substring(1) : name; 2112 } 2113 2114 protected String validName(String name) 2115 { 2116 return CodeGenUtil.validJavaIdentifier(name); 2117 } 2118 2119 protected void warning(String message) 2120 { 2121 System.err.println("-->Warning: " + message); 2122 roseUtil.getStatus().add(new Status(IStatus.WARNING, RoseImporterPlugin.getPlugin().getBundle().getSymbolicName(), 0, message, null)); 2123 } 2124 2125 protected void error(String message) 2126 { 2127 System.err.println("-->Error: " + message); 2128 roseUtil.getStatus().add(new Status(IStatus.ERROR, RoseImporterPlugin.getPlugin().getBundle().getSymbolicName(), 0, message, null)); 2129 } 2130 2131 protected String getQualifiedTypeName(ETypedElement typedElement, String type) 2132 { 2133 if (null == type || type.length() == 0 || "void".equals(type)) 2135 { 2136 return type; 2137 } 2138 2139 String qualifiedType = type; 2140 if (qualifiedType.indexOf("::") != -1) 2142 { 2143 StringTokenizer st = new StringTokenizer (qualifiedType, "::"); 2144 if (st.hasMoreTokens()) 2145 { 2146 st.nextToken(); 2147 } 2148 StringBuffer stringBuffer = new StringBuffer (); 2149 while (st.hasMoreTokens()) 2150 { 2151 stringBuffer.append(st.nextToken().replace('"', ' ').replace('[', ' ').replace(']', ' ').trim()); 2153 if (st.hasMoreTokens()) 2154 { 2155 stringBuffer.append("."); 2156 } 2157 } 2158 2159 qualifiedType = stringBuffer.toString(); 2160 } 2161 2162 if (qualifiedType.indexOf('.') == -1) 2164 { 2165 String qualifier = ""; 2166 for (EObject parent = typedElement.eContainer(); null != parent; parent = parent.eContainer()) 2167 { 2168 if (parent instanceof EPackage) 2169 { 2170 qualifier = ((EPackage)parent).getName() + "." + qualifier; 2171 } 2172 } 2173 2174 qualifiedType = qualifier + qualifiedType; 2175 } 2176 2177 if (!qualifiedType.equals(type) && !roseUtil.nameTable.containsKey(qualifiedType)) 2178 { 2179 qualifiedType = type; 2180 } 2181 2182 return qualifiedType; 2183 } 2184} 2185 | Popular Tags |