Changeset 2038 for trunk/autoquest-plugin-uml/src/main/java/de
- Timestamp:
- 09/23/15 16:31:31 (9 years ago)
- Location:
- trunk/autoquest-plugin-uml/src/main/java/de/ugoe/cs/autoquest/plugin/uml
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-plugin-uml/src/main/java/de/ugoe/cs/autoquest/plugin/uml/UMLInteractionCreator.java
r2011 r2038 52 52 import org.eclipse.uml2.uml.Slot; 53 53 import org.eclipse.uml2.uml.Type; 54 import org.eclipse.uml2.uml.UMLFactory; 54 55 import org.eclipse.uml2.uml.UMLPackage; 55 56 … … 85 86 86 87 /** 87 * a cache of the already created instance specification; used to create the overall number of generated specifications 88 * a cache of the already created instance specification; used to create the overall number of 89 * generated specifications 88 90 */ 89 91 private final Map<String, InstanceSpecification> instanceSpecificationCache; … … 380 382 int multiplicityChosen = paramNodes.size(); 381 383 382 if (multiplicityChosen == 0 && internalParameter.getLower() > 0) { 384 if (multiplicityChosen == 0 && internalParameter.getLower() > 0 && 385 requestBody != null) 386 { 383 387 Console 384 388 .traceln(Level.WARNING, … … 391 395 multiplicityChosen = internalParameter.getLower(); 392 396 } 393 for (int i = 0; i < multiplicityChosen; i++) { 394 org.w3c.dom.Element paramNode = null; 395 if (!paramNodes.isEmpty()) { 396 paramNode = paramNodes.get(i); 397 } 398 397 if (multiplicityChosen > 0) { 399 398 Slot slot = instSpecParameters.createSlot(); 400 399 slot.setDefiningFeature(internalParameter); 401 402 InstanceValue value = 403 (InstanceValue) slot 404 .createValue(internalParameter.getName() + "_" + i, 405 internalParameter.getType(), 406 UMLPackage.Literals.INSTANCE_VALUE); 407 InstanceSpecification instSpec = 408 createInstanceSpecification((DataType) internalParameter.getType(), 409 instSpecPkg, prefix, instSpecNumber, 410 paramNode, path); 411 value.setInstance(instSpec); 412 /* 413 * InstanceValue value = (InstanceValue) argument .createOperand(null, 414 * internalParameter.getType(), UMLPackage.Literals.INSTANCE_VALUE); 415 * value.setInstance(instSpec); 416 */ 400 for (int i = 0; i < multiplicityChosen; i++) { 401 org.w3c.dom.Element paramNode = null; 402 if (!paramNodes.isEmpty()) { 403 paramNode = paramNodes.get(i); 404 } 405 406 InstanceValue value = 407 (InstanceValue) slot 408 .createValue(internalParameter.getName() + "_" + i, 409 internalParameter.getType(), 410 UMLPackage.Literals.INSTANCE_VALUE); 411 InstanceSpecification instSpec = 412 createInstanceSpecification((DataType) internalParameter 413 .getType(), 414 instSpecPkg, prefix, 415 instSpecNumber, paramNode, path); 416 value.setInstance(instSpec); 417 /* 418 * InstanceValue value = (InstanceValue) argument 419 * .createOperand(null, internalParameter.getType(), 420 * UMLPackage.Literals.INSTANCE_VALUE); value.setInstance(instSpec); 421 */ 422 } 417 423 } 418 424 } … … 477 483 createSlotPrimitiveType(instSpec, prop, currentNode, path); 478 484 } 479 else if (prop.getType() instanceof Enumeration 485 else if (prop.getType() instanceof Enumeration) { 480 486 createSlotEnumeration(instSpec, prop, currentNode, path); 481 487 } 482 488 else if (prop.getType() instanceof DataType) { 483 if ( isXSDSequence(prop.getType())) { // XSD sequence, no real type489 if (isXSDSequence(prop.getType())) { // XSD sequence, no real type 484 490 List<String> childNames = SOAPUtils.getChildNodeNames(currentNode); 485 491 List<org.w3c.dom.Element> childNodes = SOAPUtils.getChildElements(currentNode); 486 EList<Property> sequenceProperties = ((DataType) prop.getType()).getAllAttributes(); 492 EList<Property> sequenceProperties = 493 ((DataType) prop.getType()).getAllAttributes(); 487 494 boolean sequenceIsMatch = true; 488 if( sequenceProperties.size()==childNames.size()) { 489 for(int i=0; sequenceIsMatch && i<sequenceProperties.size() ; i++) { 495 // can currently only work with exactly one sequence and no optional elements 496 if (sequenceProperties.size() == childNames.size()) { 497 for (int i = 0; sequenceIsMatch && i < sequenceProperties.size(); i++) { 490 498 Property propSeq = sequenceProperties.get(i); 491 499 String currentChildName = childNames.get(i); 492 if ( isXSDChoice(propSeq.getType() )) {500 if (isXSDChoice(propSeq.getType())) { 493 501 boolean choiceMatchFound = false; 494 for( Property propChoice : ((DataType) propSeq.getType()).getAllAttributes() ) { 495 if( currentChildName.equals(propChoice.getName()) ) { 502 for (Property propChoice : ((DataType) propSeq.getType()) 503 .getAllAttributes()) 504 { 505 if (currentChildName.equals(propChoice.getName())) { 496 506 choiceMatchFound = true; 497 507 } 498 508 } 499 509 sequenceIsMatch &= choiceMatchFound; 500 } else { 510 } 511 else { 501 512 sequenceIsMatch &= currentChildName.equals(propSeq.getName()); 502 513 } 503 514 } 504 if( sequenceIsMatch ) { 505 // this is the correct sequence, it matches; now appropriate data must be created 506 515 if (sequenceIsMatch) { 516 // this is the correct sequence, it matches; now appropriate data must 517 // be created 518 507 519 // first we create the slot and instance specification for the sequence 508 520 Slot slot = instSpec.createSlot(); 509 521 slot.setDefiningFeature(prop); 510 522 InstanceValue value = 511 (InstanceValue) slot.createValue(prop.getName(), prop.getType(), UMLPackage.Literals.INSTANCE_VALUE); 523 (InstanceValue) slot 524 .createValue(prop.getName(), prop.getType(), 525 UMLPackage.Literals.INSTANCE_VALUE); 512 526 InstanceSpecification instSpecSequence = 513 (InstanceSpecification) pkg 514 .createPackagedElement(prefix + prop.getName() + "_instspec" + instSpecNumber.intValue() + "_" + 515 type.getName(), 516 UMLPackage.Literals.INSTANCE_SPECIFICATION); 527 (InstanceSpecification) pkg 528 .createPackagedElement(prefix + prop.getName() + "_instspec" + 529 instSpecNumber.intValue() + "_" + 530 type.getName(), 531 UMLPackage.Literals.INSTANCE_SPECIFICATION); 517 532 instSpecSequence.getClassifiers().add((DataType) prop.getType()); 518 533 instSpecNumber.setValue(instSpecNumber.intValue() + 1); 519 534 value.setInstance(instSpecSequence); 520 521 // now we create the slots and instance specifications for the elements of the sequence 522 for(int i=0; i<sequenceProperties.size() ; i++) { 535 536 // now we create the slots and instance specifications for the elements 537 // of the sequence 538 for (int i = 0; i < sequenceProperties.size(); i++) { 523 539 Property propSeq = sequenceProperties.get(i); 524 540 String currentChildName = childNames.get(i); 525 541 slot = instSpecSequence.createSlot(); 526 542 slot.setDefiningFeature(propSeq); 527 value = (InstanceValue) slot.createValue(propSeq.getName(), propSeq.getType(), UMLPackage.Literals.INSTANCE_VALUE); 528 if( isXSDChoice(propSeq.getType() ) ) { 543 value = 544 (InstanceValue) slot 545 .createValue(propSeq.getName(), propSeq.getType(), 546 UMLPackage.Literals.INSTANCE_VALUE); 547 if (isXSDChoice(propSeq.getType())) { 529 548 // create the inner choice instance spec 530 InstanceSpecification instSpecSequenceChoice = (InstanceSpecification) pkg 531 .createPackagedElement(prefix + propSeq.getName() + "_instspec" + instSpecNumber.intValue() + "_" + 532 propSeq.getType().getName(), 533 UMLPackage.Literals.INSTANCE_SPECIFICATION); 534 instSpecSequenceChoice.getClassifiers().add((DataType) propSeq.getType()); 535 instSpecNumber.setValue(instSpecNumber.intValue()+1); 549 InstanceSpecification instSpecSequenceChoice = 550 (InstanceSpecification) pkg 551 .createPackagedElement(prefix + propSeq.getName() + 552 "_instspec" + 553 instSpecNumber.intValue() + 554 "_" + 555 propSeq.getType().getName(), 556 UMLPackage.Literals.INSTANCE_SPECIFICATION); 557 instSpecSequenceChoice.getClassifiers().add((DataType) propSeq 558 .getType()); 559 instSpecNumber.setValue(instSpecNumber.intValue() + 1); 536 560 value.setInstance(instSpecSequenceChoice); 537 for( Property propChoice : ((DataType) propSeq.getType()).getAllAttributes() ) { 538 if( currentChildName.equals(propChoice.getName()) ) { 561 for (Property propChoice : ((DataType) propSeq.getType()) 562 .getAllAttributes()) 563 { 564 if (currentChildName.equals(propChoice.getName())) { 539 565 slot = instSpecSequenceChoice.createSlot(); 540 566 slot.setDefiningFeature(propChoice); 541 value = (InstanceValue) slot.createValue(propChoice.getName(), propChoice.getType(), UMLPackage.Literals.INSTANCE_VALUE); 542 value.setInstance(createInstanceSpecification((DataType) propChoice.getType(), pkg, prefix, instSpecNumber, childNodes.get(i), path+"."+propChoice.getName())); 567 value = 568 (InstanceValue) slot 569 .createValue(propChoice.getName(), 570 propChoice.getType(), 571 UMLPackage.Literals.INSTANCE_VALUE); 572 value 573 .setInstance(createInstanceSpecification((DataType) propChoice 574 .getType(), 575 pkg, 576 prefix, 577 instSpecNumber, 578 childNodes 579 .get(i), 580 path + 581 "." + 582 propChoice 583 .getName())); 543 584 break; 544 585 } 545 586 } 546 } else {547 value.setInstance(createInstanceSpecification((DataType) propSeq.getType(), pkg, prefix, instSpecNumber, childNodes.get(i), path+"."+propSeq.getName()));548 587 } 549 } 588 else { 589 value 590 .setInstance(createInstanceSpecification((DataType) propSeq 591 .getType(), pkg, prefix, instSpecNumber, childNodes 592 .get(i), path + "." + propSeq.getName())); 593 } 594 } 550 595 } 551 596 } 552 597 } 553 else if( isXSDChoice(prop.getType()) ) { 554 // TODO implement handling of choices, if required for the MIDAS pilots 555 Console.traceln(Level.SEVERE, "cannot handle choices that are the child elements of normal data types yet!"); 556 Console.traceln(Level.SEVERE, "choice is ignored and no data is created."); 557 } else { 598 else if (isXSDChoice(prop.getType())) { 599 for (Property propChoice : ((DataType) prop.getType()).getAllAttributes()) { 600 List<org.w3c.dom.Element> matchingChildren = 601 SOAPUtils.getMatchingChildNode(propChoice.getName(), currentNode); 602 if (!matchingChildren.isEmpty()) { 603 // create instance specification for the choice 604 Slot slot = instSpec.createSlot(); 605 slot.setDefiningFeature(prop); 606 InstanceValue value = 607 (InstanceValue) slot 608 .createValue(prop.getName(), prop.getType(), 609 UMLPackage.Literals.INSTANCE_VALUE); 610 InstanceSpecification instSpecSequence = 611 (InstanceSpecification) pkg 612 .createPackagedElement(prefix + prop.getName() + "_instspec" + 613 instSpecNumber.intValue() + "_" + 614 type.getName(), 615 UMLPackage.Literals.INSTANCE_SPECIFICATION); 616 instSpecSequence.getClassifiers().add((DataType) prop.getType()); 617 instSpecNumber.setValue(instSpecNumber.intValue() + 1); 618 value.setInstance(instSpecSequence); 619 620 // now the slot and instance specification for the matching choice 621 slot = instSpecSequence.createSlot(); 622 slot.setDefiningFeature(propChoice); 623 value = 624 (InstanceValue) slot 625 .createValue(propChoice.getName(), propChoice.getType(), 626 UMLPackage.Literals.INSTANCE_VALUE); 627 value 628 .setInstance(createInstanceSpecification((DataType) propChoice 629 .getType(), pkg, prefix, instSpecNumber, matchingChildren 630 .get(0), path + "." + propChoice.getName())); 631 } 632 } 633 } 634 else { 635 // normal child, neither choice nor sequence 558 636 List<org.w3c.dom.Element> attributeNodes = null; 559 637 int multiplicityChosen = 0; 560 638 if (currentNode != null) { 561 attributeNodes = SOAPUtils.getMatchingChildNode(prop.getName(), currentNode); 639 attributeNodes = 640 SOAPUtils.getMatchingChildNode(prop.getName(), currentNode); 562 641 multiplicityChosen = attributeNodes.size(); 563 642 } 564 643 565 644 if (multiplicityChosen == 0 && prop.getLower() > 0) { 566 645 if (currentNode != null) { 567 646 Console.traceln(Level.WARNING, 568 "required attribute not found in SOAP message: " + path +569 "." + prop.getName());647 "required attribute not found in SOAP message: " + 648 path + "." + prop.getName()); 570 649 Console 571 650 .traceln(Level.WARNING, 572 651 "setting default values for this attribute and all its children"); 573 Console.traceln(Level.FINE, "XML structure of path:" + StringTools.ENDLINE +574 S OAPUtils.getSerialization(currentNode));652 Console.traceln(Level.FINE, "XML structure of path:" + 653 StringTools.ENDLINE + SOAPUtils.getSerialization(currentNode)); 575 654 } 576 655 multiplicityChosen = prop.getLower(); 577 656 } 578 for (int i = 0; i < multiplicityChosen; i++) {657 if (multiplicityChosen == 1) { 579 658 org.w3c.dom.Element attributeNode = null; 580 659 if (attributeNodes != null && !attributeNodes.isEmpty()) { 581 attributeNode = attributeNodes.get( i);660 attributeNode = attributeNodes.get(0); 582 661 } 583 662 584 663 Slot slot = instSpec.createSlot(); 585 664 slot.setDefiningFeature(prop); 586 665 587 666 InstanceValue value = 588 (InstanceValue) slot.createValue(prop.getName() + "_" + i, prop.getType(), 667 (InstanceValue) slot.createValue(prop.getName() + "_" + 1, 668 prop.getType(), 589 669 UMLPackage.Literals.INSTANCE_VALUE); 590 value.setInstance(createInstanceSpecification((DataType) prop.getType(), pkg, 591 prefix, instSpecNumber, 592 attributeNode, 593 path + "." + prop.getName())); 670 value.setInstance(createInstanceSpecification((DataType) prop.getType(), 671 pkg, prefix, instSpecNumber, 672 attributeNode, path + "." + 673 prop.getName())); 674 } 675 else if (multiplicityChosen > 1) { 676 Slot slot = instSpec.createSlot(); 677 slot.setDefiningFeature(prop); 678 for (int i = 0; i < multiplicityChosen; i++) { 679 // TODO maybe not yet correct 680 org.w3c.dom.Element attributeNode = null; 681 if (attributeNodes != null && !attributeNodes.isEmpty()) { 682 attributeNode = attributeNodes.get(i); 683 } 684 685 InstanceValue value = UMLFactory.eINSTANCE.createInstanceValue(); 686 value 687 .setInstance(createInstanceSpecification((DataType) prop.getType(), 688 pkg, prefix, 689 instSpecNumber, 690 attributeNode, path + "." + 691 prop.getName())); 692 slot.getValues().add(value); 693 } 594 694 } 595 695 } … … 686 786 UMLPackage.Literals.LITERAL_REAL); 687 787 if (attributeValue != null) { 788 System.out.println(attributeValue); 688 789 value.setValue(Double.parseDouble(attributeValue)); 689 790 } … … 697 798 Console.traceln(Level.SEVERE, "attribute is ignored!"); 698 799 // TODO 699 //throw new RuntimeException("unknown primitive type: " + prop.getType().getName()); 700 } 701 } 702 } 703 800 // throw new RuntimeException("unknown primitive type: " + 801 // prop.getType().getName()); 802 } 803 } 804 } 805 704 806 /** 705 807 * <p> … … 717 819 */ 718 820 private void createSlotEnumeration(InstanceSpecification instSpec, 719 720 721 821 Property prop, 822 org.w3c.dom.Element currentNode, 823 String path) 722 824 { 723 825 List<String> attributeValues = SOAPUtils.getValuesFromElement(prop.getName(), currentNode); … … 743 845 Slot slot = instSpec.createSlot(); 744 846 slot.setDefiningFeature(prop); 745 746 InstanceValue value = (InstanceValue) slot.createValue(prop.getName(), null, UMLPackage.Literals.INSTANCE_VALUE); 747 if( attributeValue!=null ) { 847 848 InstanceValue value = 849 (InstanceValue) slot.createValue(prop.getName(), null, 850 UMLPackage.Literals.INSTANCE_VALUE); 851 if (attributeValue != null) { 748 852 value.setInstance(((Enumeration) prop.getType()).getOwnedLiteral(attributeValue)); 749 } else { 853 } 854 else { 750 855 throw new RuntimeException("cannot create enumeration literal with dummy value"); 751 856 } … … 807 912 Element target = ((Generalization) relationship).getTargets().get(0); 808 913 if (target instanceof PrimitiveType) { 809 return typeName.equals(((PrimitiveType) target).getName()); 914 if (typeName.equals(((PrimitiveType) target).getName())) { 915 return true; 916 } 810 917 } 811 918 } … … 813 920 return false; 814 921 } 815 922 816 923 /** 817 924 * <p> 818 925 * Checks if a type is an anonymous inner type that represents an XSD sequence 819 926 * </p> 820 * 821 * @param type type that is checked 927 * 928 * @param type 929 * type that is checked 822 930 * @return true if XSD sequence; false otherwise 823 931 */ 824 932 private boolean isXSDSequence(Type type) { 825 if ( type==null || type.getName()==null) {933 if (type == null || type.getName() == null) { 826 934 return false; 827 935 } 828 936 return type.getName().matches("sequence\\d*"); 829 937 } 830 938 831 939 /** 832 940 * <p> 833 941 * Checks if a type is an anonymous inner type that represents an XSD choice 834 942 * </p> 835 * 836 * @param type type that is checked 943 * 944 * @param type 945 * type that is checked 837 946 * @return true if XSD choice; false otherwise 838 947 */ 839 948 private boolean isXSDChoice(Type type) { 840 if ( type==null || type.getName()==null) {949 if (type == null || type.getName() == null) { 841 950 return false; 842 951 } -
trunk/autoquest-plugin-uml/src/main/java/de/ugoe/cs/autoquest/plugin/uml/UMLUtils.java
r2015 r2038 438 438 } catch(Exception e) { 439 439 Console.traceln(Level.SEVERE, "failure for " + interactionName+"_"+i + ": " + e.getMessage()); 440 e.printStackTrace(); 440 441 } 441 442 }
Note: See TracChangeset
for help on using the changeset viewer.