Changeset 2008


Ignore:
Timestamp:
07/14/15 11:45:13 (9 years ago)
Author:
sherbold
Message:
  • moved logic for the creation of Interactions from event sequences from the UML utils to a separate class
Location:
trunk/autoquest-plugin-uml/src/main/java/de/ugoe/cs/autoquest/plugin/uml
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-plugin-uml/src/main/java/de/ugoe/cs/autoquest/plugin/uml/UMLUtils.java

    r2005 r2008  
    3030import java.util.logging.Level; 
    3131 
    32 import org.apache.commons.lang.mutable.MutableInt; 
    3332import org.eclipse.emf.common.util.EList; 
    3433import org.eclipse.uml2.uml.Activity; 
    3534import org.eclipse.uml2.uml.ActivityEdge; 
    3635import org.eclipse.uml2.uml.ActivityNode; 
    37 import org.eclipse.uml2.uml.CallConcurrencyKind; 
    3836import org.eclipse.uml2.uml.CallEvent; 
    3937import org.eclipse.uml2.uml.CallOperationAction; 
     
    4240import org.eclipse.uml2.uml.Connector; 
    4341import org.eclipse.uml2.uml.ConnectorEnd; 
    44 import org.eclipse.uml2.uml.DataType; 
    4542import org.eclipse.uml2.uml.Element; 
    4643import org.eclipse.uml2.uml.Expression; 
    47 import org.eclipse.uml2.uml.InstanceSpecification; 
    48 import org.eclipse.uml2.uml.InstanceValue; 
    4944import org.eclipse.uml2.uml.Interaction; 
    5045import org.eclipse.uml2.uml.InteractionFragment; 
     
    6762import org.eclipse.uml2.uml.Property; 
    6863import org.eclipse.uml2.uml.Region; 
    69 import org.eclipse.uml2.uml.Slot; 
    7064import org.eclipse.uml2.uml.StateMachine; 
    7165import org.eclipse.uml2.uml.Stereotype; 
     
    426420     *            Name of the test context that should be used. If this value is null, the first 
    427421     *            test context found is used. 
    428      * @param useRandomRequestBodies 
     422     * @param useRandomMsgBodies 
    429423     *            defines is random request bodies are used or the body of the associated event 
    430424     */ 
     
    433427                                                                 String interactionName, 
    434428                                                                 String testContextName, 
    435                                                                  boolean useRandomRequestBodies) 
     429                                                                 boolean useRandomMsgBodies) 
    436430    { 
    437         final Component testContext = fetchTestContext(model, testContextName); 
    438         if (testContext == null) { 
    439             throw new RuntimeException("Could not find any test context in the model"); 
    440         } 
    441  
    442         final Operation operation = testContext.createOwnedOperation(interactionName, null, null); 
    443         operation.applyStereotype(UTPUtils.getTestCaseStereotype(model)); 
    444  
    445         final Interaction interaction = 
    446             (Interaction) testContext.createPackagedElement(interactionName + "_Impl", 
    447                                                             UMLPackage.Literals.INTERACTION); 
    448         operation.getMethods().add(interaction); 
    449  
    450         // create lifelines 
    451         Lifeline userLifeline = null; 
    452  
    453         for (Property property : fetchAllSUTProperties(testContext)) { 
    454             String serviceName = property.getName(); 
    455             Lifeline targetLifeline = interaction.createLifeline(serviceName); 
    456             targetLifeline.setRepresents(property); 
    457         } 
    458         for (Property property : fetchAllTestComponentProperties(testContext)) { 
    459             userLifeline = interaction.createLifeline(property.getName()); 
    460             userLifeline.setRepresents(property); 
    461         } 
    462  
    463         if (userLifeline == null) { 
    464             throw new RuntimeException("No TestComponent found, could not create user lifeline."); 
    465         } 
    466         if (interaction.getLifelines().size() < 2) { 
    467             throw new RuntimeException("Fewer than two lifelines created. No SUT found."); 
    468         } 
    469  
    470         int i = 0; 
    471         for (Event event : sequence) { 
    472             if (!(event.equals(Event.STARTEVENT) || event.equals(Event.ENDEVENT))) { 
    473                 String serviceName = SOAPUtils.getServiceNameFromEvent(event); 
    474                 String methodName = SOAPUtils.getCalledMethodFromEvent(event); 
    475                 String clientName = SOAPUtils.getClientNameFromEvent(event); 
    476                 String prefix = interactionName + "_" + i + "_" + methodName + "_"; 
    477                 // determine lifelines 
    478                 Lifeline msgTargetLifeline; 
    479                 Lifeline msgSourceLifeline; 
    480  
    481                 msgSourceLifeline = interaction.getLifeline(clientName); 
    482                 msgTargetLifeline = interaction.getLifeline(serviceName); 
    483  
    484                 if (msgSourceLifeline == null) { 
    485                     throw new RuntimeException( 
    486                                                "Error creating message: could not determine source lifeline for component: " + 
    487                                                    clientName); 
    488                 } 
    489                 if (msgTargetLifeline == null) { 
    490                     throw new RuntimeException( 
    491                                                "Error creating message: could not determine target lifeline for component: " + 
    492                                                    serviceName); 
    493                 } 
    494                 // determine correct target interface 
    495                 Set<Interface> targetInterfaces = 
    496                     getRealizedInterfacesFromProperty((Property) msgTargetLifeline.getRepresents()); 
    497                 if (targetInterfaces.isEmpty()) { 
    498                     throw new RuntimeException("no interface associated with the property " + 
    499                         msgTargetLifeline.getRepresents().getName()); 
    500                 } 
    501                 Interface targetInterface = null; 
    502                 for (Interface intface : targetInterfaces) { 
    503                     if (getOperationFromName(intface.getOperations(), methodName) != null) { 
    504                         // interface found 
    505                         targetInterface = intface; 
    506                         break; 
    507                     } 
    508                 } 
    509                 if (targetInterface == null) { 
    510                     StringBuilder errStrBuilder = new StringBuilder(); 
    511                     errStrBuilder 
    512                         .append("Error creating message: operation not found in the implementing interfaces ("); 
    513                     Iterator<Interface> iter = targetInterfaces.iterator(); 
    514                     while (iter.hasNext()) { 
    515                         String interfaceName = iter.next().getName(); 
    516                         errStrBuilder.append(interfaceName); 
    517                         if (iter.hasNext()) { 
    518                             errStrBuilder.append(","); 
    519                         } 
    520                         else { 
    521                             errStrBuilder.append("): " + methodName); 
    522                         } 
    523                     } 
    524                     throw new RuntimeException(errStrBuilder.toString()); 
    525                 } 
    526  
    527                 Operation calledOperation = 
    528                     getOperationFromName(targetInterface.getOperations(), methodName); 
    529                 // get connector 
    530                 Connector connector = 
    531                     inferConnector(msgSourceLifeline, msgTargetLifeline, targetInterface); 
    532                 if (connector == null) { 
    533                     throw new RuntimeException( 
    534                                                "Error creating message: could not find connector between the two life lines that supports the target interface at the target lifeline"); 
    535                 } 
    536  
    537                 boolean asynch = false; 
    538                 if (calledOperation.getConcurrency() == CallConcurrencyKind.CONCURRENT_LITERAL) { 
    539                     asynch = true; 
    540                 } 
    541  
    542                 if (SOAPUtils.isSOAPRequest(event)) { 
    543                     // setup for both SYNCH and ASYNCH calls 
    544                     MessageOccurrenceSpecification callSendFragment = 
    545                         (MessageOccurrenceSpecification) interaction 
    546                             .createFragment(prefix + "callSendFragment", 
    547                                             UMLPackage.Literals.MESSAGE_OCCURRENCE_SPECIFICATION); 
    548                     MessageOccurrenceSpecification callRecvFragment = 
    549                         (MessageOccurrenceSpecification) interaction 
    550                             .createFragment(prefix + "callRecvFragment", 
    551                                             UMLPackage.Literals.MESSAGE_OCCURRENCE_SPECIFICATION); 
    552  
    553                     callSendFragment.setCovered(msgSourceLifeline); 
    554                     callRecvFragment.setCovered(msgTargetLifeline); 
    555  
    556                     // create call 
    557                     Message callMessage = interaction.createMessage(prefix + "call"); 
    558                     callMessage.setSignature(calledOperation); 
    559                     setMessageParameters(callMessage, calledOperation, event, 
    560                                          useRandomRequestBodies, prefix); 
    561                     callMessage.setConnector(connector); 
    562                     callMessage.setSendEvent(callSendFragment); 
    563                     callMessage.setReceiveEvent(callRecvFragment); 
    564                     callSendFragment.setMessage(callMessage); 
    565                     callRecvFragment.setMessage(callMessage); 
    566  
    567                     if (asynch) { 
    568                         // Create ASYNCH call 
    569                         callMessage.setMessageSort(MessageSort.ASYNCH_CALL_LITERAL); 
    570                     } 
    571                     else { 
    572                         // SYNCH call 
    573                         callMessage.setMessageSort(MessageSort.SYNCH_CALL_LITERAL); 
    574                     } 
    575                 } 
    576                 if (!asynch && SOAPUtils.isSOAPResponse(event)) { 
    577                     // setup reply and behavior execution specifications 
    578                     MessageOccurrenceSpecification replySendFragment = 
    579                         (MessageOccurrenceSpecification) interaction 
    580                             .createFragment(prefix + "replySendFragment", 
    581                                             UMLPackage.Literals.MESSAGE_OCCURRENCE_SPECIFICATION); 
    582                     MessageOccurrenceSpecification replyRecvFragment = 
    583                         (MessageOccurrenceSpecification) interaction 
    584                             .createFragment(prefix + "replyRecvFragment", 
    585                                             UMLPackage.Literals.MESSAGE_OCCURRENCE_SPECIFICATION); 
    586  
    587                     replySendFragment.setCovered(msgTargetLifeline); 
    588                     replyRecvFragment.setCovered(msgSourceLifeline); 
    589  
    590                     /* 
    591                      * BehaviorExecutionSpecification sourceBehaviorExecutionSpecification = 
    592                      * (BehaviorExecutionSpecification) interaction .createFragment(":" + methodName 
    593                      * + "_sourceBhvExecSpec", 
    594                      * UMLPackage.Literals.BEHAVIOR_EXECUTION_SPECIFICATION); 
    595                      * BehaviorExecutionSpecification targetBehaviorExecutionSpecification = 
    596                      * (BehaviorExecutionSpecification) interaction .createFragment(":" + methodName 
    597                      * + "_targetBhvExecSpec", 
    598                      * UMLPackage.Literals.BEHAVIOR_EXECUTION_SPECIFICATION); 
    599                      *  
    600                      * sourceBehaviorExecutionSpecification.setStart(callSendFragment); 
    601                      * sourceBehaviorExecutionSpecification.setFinish(replyRecvFragment); 
    602                      * targetBehaviorExecutionSpecification.setStart(callRecvFragment); 
    603                      * targetBehaviorExecutionSpecification.setFinish(replySendFragment); 
    604                      */ 
    605  
    606                     // create reply 
    607                     Message replyMessage = interaction.createMessage(prefix + "_reply"); 
    608                     replyMessage.setMessageSort(MessageSort.REPLY_LITERAL); 
    609                     replyMessage.setSignature(calledOperation); 
    610                     // setReplyMessageParameters(replyMessage, calledOperation); 
    611                     setMessageParameters(replyMessage, calledOperation, event, 
    612                                          useRandomRequestBodies, prefix); 
    613                     replyMessage.setConnector(connector); 
    614                     replyMessage.setSendEvent(replySendFragment); 
    615                     replyMessage.setReceiveEvent(replyRecvFragment); 
    616                     replySendFragment.setMessage(replyMessage); 
    617                     replyRecvFragment.setMessage(replyMessage); 
    618                 } 
    619  
    620                 i++; 
    621             } 
    622         } 
    623         return interaction; 
     431        UMLInteractionCreator interactionCreator = new UMLInteractionCreator(model, testContextName, useRandomMsgBodies); 
     432        return interactionCreator.createInteraction(sequence, interactionName); 
    624433    } 
    625434 
     
    768577     * @return first matching operation; null if no match is found 
    769578     */ 
    770     private static Operation getOperationFromName(EList<Operation> operations, String name) { 
     579    public static Operation getOperationFromName(EList<Operation> operations, String name) { 
    771580        if (name == null) { 
    772581            throw new IllegalArgumentException("name of the operation must not be null"); 
     
    837646     * @return realized interfaces 
    838647     */ 
    839     private static Set<Interface> getRealizedInterfacesFromProperty(Property property) { 
     648    public static Set<Interface> getRealizedInterfacesFromProperty(Property property) { 
    840649        return getRealizedInterfaceFromComponent((Component) property.getType()); 
    841650    } 
     
    851660     * @return realized interfaces 
    852661     */ 
    853     private static Set<Interface> getRealizedInterfaceFromComponent(Component component) { 
     662    public static Set<Interface> getRealizedInterfaceFromComponent(Component component) { 
    854663        Set<Interface> interfaces = new HashSet<>(); 
    855664        // Interface myInterface = null; 
     
    881690     * @return {@link Component} to which the TestContext stereotype is applied 
    882691     */ 
    883     private static Component fetchTestContext(final Package pkg, final String testContextName) { 
     692    public static Component fetchTestContext(final Package pkg, final String testContextName) { 
    884693        List<Component> testContexts = fetchAllTestContexts(pkg); 
    885694        if (testContexts.isEmpty()) { 
     
    913722     * @return {@link List} of test contexts 
    914723     */ 
    915     private static List<Component> fetchAllTestContexts(final Package pkg) { 
     724    public static List<Component> fetchAllTestContexts(final Package pkg) { 
    916725        final Stereotype utpTestContext = UTPUtils.getTestContextStereotype(pkg.getModel()); 
    917726        final List<Component> testContexts = new LinkedList<>(); 
     
    938747     * @return properties that represent test components 
    939748     */ 
    940     private static Set<Property> fetchAllTestComponentProperties(final Component testContext) { 
     749    public static Set<Property> fetchAllTestComponentProperties(final Component testContext) { 
    941750        // fetch all SUTs and TestComponents 
    942751        final Stereotype utpTestComponent = 
     
    960769     * @return properties that represent the SUTs 
    961770     */ 
    962     private static Set<Property> fetchAllSUTProperties(final Component testContext) { 
     771    public static Set<Property> fetchAllSUTProperties(final Component testContext) { 
    963772        // fetch all SUTs and TestComponents 
    964773        final Stereotype utpSUT = UTPUtils.getSUTStereotype(testContext.getModel()); 
     
    982791     *            target lifeline of the message 
    983792     */ 
    984     private static Connector inferConnector(Lifeline msgSourceLifeline, 
     793    public static Connector inferConnector(Lifeline msgSourceLifeline, 
    985794                                            Lifeline msgTargetLifeline, 
    986795                                            Interface targetInterface) 
     
    1045854    } 
    1046855 
    1047     /** 
    1048      * <p> 
    1049      * Sets values for the parameters of a call message. The values are, if possible, inferred from 
    1050      * the event that is provided. 
    1051      * </p> 
    1052      *  
    1053      * @param message 
    1054      *            call message for which the parameters are set 
    1055      * @param calledOperation 
    1056      *            operation that is called by the message 
    1057      * @param event 
    1058      *            event that provides the parameters; in case of null, default values are assumed 
    1059      * @param useRandomMsgBodies 
    1060      *            defines is random request bodies are used or the body of the associated event 
    1061      * @param prefix 
    1062      *            prefix of the call message; used to create good warnings and debugging information 
    1063      */ 
    1064     private static void setMessageParameters(Message message, 
    1065                                              Operation calledOperation, 
    1066                                              Event event, 
    1067                                              boolean useRandomMsgBodies, 
    1068                                              String prefix) 
    1069     { 
    1070         org.w3c.dom.Element requestBody; 
    1071         if (SOAPUtils.isSOAPRequest(event)) { 
    1072             requestBody = 
    1073                 SOAPUtils.getSoapBodyFromEvent(event, useRandomMsgBodies, CallType.REQUEST); 
    1074         } 
    1075         else { 
    1076             requestBody = 
    1077                 SOAPUtils.getSoapBodyFromEvent(event, useRandomMsgBodies, CallType.RESPONSE); 
    1078         } 
    1079         Package instSpecPkg = null; 
    1080         MutableInt instSpecNumber = new MutableInt(0); 
    1081  
    1082         // Set parameters of operation 
    1083         for (Parameter param : calledOperation.getOwnedParameters()) { 
    1084             if (instSpecPkg == null) { 
    1085                 instSpecPkg = getOrCreateInstanceSpecificationPackage(message.getModel(), event); 
    1086             } 
    1087  
    1088             String path = calledOperation.getName() + ":" + param.getType().getName(); 
    1089             if ((isInParameter(param) && SOAPUtils.isSOAPRequest(event)) || 
    1090                 (isOutParameter(param) && SOAPUtils.isSOAPResponse(event))) 
    1091             { 
    1092  
    1093                 // create parameters node 
    1094                 if (!(param.getType() instanceof DataType)) { 
    1095                     throw new RuntimeException("TODO error handling; parameters missing"); 
    1096                 } 
    1097                 DataType parametersNode = (DataType) param.getType(); 
    1098                 InstanceSpecification instSpecParameters = 
    1099                     (InstanceSpecification) instSpecPkg 
    1100                         .createPackagedElement(prefix + "instspec" + instSpecNumber.intValue() + 
    1101                                                    "_" + param.getType().getName(), 
    1102                                                UMLPackage.Literals.INSTANCE_SPECIFICATION); 
    1103                 instSpecParameters.getClassifiers().add((DataType) param.getType()); 
    1104                 instSpecNumber.setValue(instSpecNumber.intValue() + 1); 
    1105                 InstanceValue instanceValue = 
    1106                     (InstanceValue) message.createArgument(param.getName(), param.getType(), 
    1107                                                            UMLPackage.Literals.INSTANCE_VALUE); 
    1108                 instanceValue.setInstance(instSpecParameters); 
    1109  
    1110                 for (Property internalParameter : parametersNode.getAllAttributes()) { 
    1111                     if (internalParameter.getType() instanceof DataType) { 
    1112                         List<org.w3c.dom.Element> paramNodes = 
    1113                             SOAPUtils.getMatchingChildNode(internalParameter.getType().getName(), 
    1114                                                            requestBody); 
    1115                         int multiplicityChosen = paramNodes.size(); 
    1116  
    1117                         if (multiplicityChosen == 0 && internalParameter.getLower() > 0) { 
    1118                             Console 
    1119                                 .traceln(Level.WARNING, 
    1120                                          "required attribute not found in SOAP message: " + path); 
    1121                             Console 
    1122                                 .traceln(Level.WARNING, 
    1123                                          "setting default values for this attribute and all its children"); 
    1124                             Console.traceln(Level.FINE, "XML structure of path:" + 
    1125                                 StringTools.ENDLINE + SOAPUtils.getSerialization(requestBody)); 
    1126                             multiplicityChosen = internalParameter.getLower(); 
    1127                         } 
    1128                         for (int i = 0; i < multiplicityChosen; i++) { 
    1129                             org.w3c.dom.Element paramNode = null; 
    1130                             if (!paramNodes.isEmpty()) { 
    1131                                 paramNode = paramNodes.get(i); 
    1132                             } 
    1133  
    1134                             Slot slot = instSpecParameters.createSlot(); 
    1135                             slot.setDefiningFeature(internalParameter); 
    1136  
    1137                             InstanceValue value = 
    1138                                 (InstanceValue) slot 
    1139                                     .createValue(internalParameter.getName() + "_" + i, 
    1140                                                  internalParameter.getType(), 
    1141                                                  UMLPackage.Literals.INSTANCE_VALUE); 
    1142                             value 
    1143                                 .setInstance(createInstanceSpecification((DataType) internalParameter 
    1144                                                                              .getType(), 
    1145                                                                          instSpecPkg, prefix, 
    1146                                                                          instSpecNumber, paramNode, 
    1147                                                                          path)); 
    1148                             /* 
    1149                              * InstanceValue value = (InstanceValue) argument .createOperand(null, 
    1150                              * internalParameter.getType(), UMLPackage.Literals.INSTANCE_VALUE); 
    1151                              * value.setInstance(instSpec); 
    1152                              */ 
    1153                         } 
    1154                     } 
    1155                     else if (internalParameter.getType() instanceof PrimitiveType) { 
    1156                         createSlotPrimitiveType(instSpecParameters, internalParameter, requestBody, 
    1157                                                 path); 
    1158                     } 
    1159                 } 
    1160             } 
    1161             else { 
    1162                 // set literalNull for out and return parameters 
    1163                 // argument.createOperand(null, param.getType(), UMLPackage.Literals.LITERAL_NULL); 
    1164                 message.createArgument(param.getName(), param.getType(), 
    1165                                        UMLPackage.Literals.LITERAL_NULL); 
    1166             } 
    1167         } 
    1168     } 
    1169  
    1170     /** 
    1171      * <p> 
    1172      * Creates an {@link InstanceSpecification} for a data type in the given package. The values are 
    1173      * inferred, if possible, from the DOM node. The prefix and the path are used for naming the 
    1174      * instance specification and to provide good warnings and debug information in case of 
    1175      * problems. 
    1176      * </p> 
    1177      *  
    1178      * @param type 
    1179      *            DataType for which the {@link InstanceSpecification} is created 
    1180      * @param pkg 
    1181      *            package in which the {@link InstanceSpecification} is created 
    1182      * @param prefix 
    1183      *            prefix used for naming the {@link InstanceSpecification} 
    1184      * @param currentNode 
    1185      *            node of a DOM from which values are inferred 
    1186      * @param path 
    1187      *            used for warnings and debug information 
    1188      * @return {@link InstanceSpecification} for the given type 
    1189      */ 
    1190     private static InstanceSpecification createInstanceSpecification(DataType type, 
    1191                                                                      Package pkg, 
    1192                                                                      String prefix, 
    1193                                                                      MutableInt instSpecNumber, 
    1194                                                                      org.w3c.dom.Element currentNode, 
    1195                                                                      String path) 
    1196     { 
    1197         if ("".equals(path)) { 
    1198             path = type.getName(); 
    1199         } 
    1200  
    1201         InstanceSpecification instSpec = 
    1202             (InstanceSpecification) pkg 
    1203                 .createPackagedElement(prefix + "instspec" + instSpecNumber.intValue() + "_" + 
    1204                                            type.getName(), 
    1205                                        UMLPackage.Literals.INSTANCE_SPECIFICATION); 
    1206         instSpec.getClassifiers().add(type); 
    1207         instSpecNumber.setValue(instSpecNumber.intValue() + 1); 
    1208         for (Property prop : type.getAllAttributes()) { 
    1209             if (prop.getType() instanceof PrimitiveType) { 
    1210                 createSlotPrimitiveType(instSpec, prop, currentNode, path); 
    1211             } 
    1212             else if (prop.getType() instanceof DataType) { 
    1213                 List<org.w3c.dom.Element> attributeNodes = null; 
    1214                 int multiplicityChosen = 0; 
    1215                 if (currentNode != null) { 
    1216                     attributeNodes = SOAPUtils.getMatchingChildNode(prop.getName(), currentNode); 
    1217                     multiplicityChosen = attributeNodes.size(); 
    1218                 } 
    1219  
    1220                 if (multiplicityChosen == 0 && prop.getLower() > 0) { 
    1221                     if (currentNode != null) { 
    1222                         Console.traceln(Level.WARNING, 
    1223                                         "required attribute not found in SOAP message: " + path + 
    1224                                             "." + prop.getName()); 
    1225                         Console 
    1226                             .traceln(Level.WARNING, 
    1227                                      "setting default values for this attribute and all its children"); 
    1228                         Console.traceln(Level.FINE, "XML structure of path:" + StringTools.ENDLINE + 
    1229                             SOAPUtils.getSerialization(currentNode)); 
    1230                     } 
    1231                     multiplicityChosen = prop.getLower(); 
    1232                 } 
    1233                 for (int i = 0; i < multiplicityChosen; i++) { 
    1234                     org.w3c.dom.Element attributeNode = null; 
    1235                     if (attributeNodes != null && !attributeNodes.isEmpty()) { 
    1236                         attributeNode = attributeNodes.get(i); 
    1237                     } 
    1238  
    1239                     Slot slot = instSpec.createSlot(); 
    1240                     slot.setDefiningFeature(prop); 
    1241  
    1242                     InstanceValue value = 
    1243                         (InstanceValue) slot.createValue(prop.getName() + "_" + i, prop.getType(), 
    1244                                                          UMLPackage.Literals.INSTANCE_VALUE); 
    1245                     value.setInstance(createInstanceSpecification((DataType) prop.getType(), pkg, 
    1246                                                                   prefix, instSpecNumber, 
    1247                                                                   attributeNode, 
    1248                                                                   path + "." + prop.getName())); 
    1249                 } 
    1250             } 
    1251             else { 
    1252                 Console.traceln(Level.SEVERE, "property neither DataType nor PrimitiveType: " + 
    1253                     prop.getType()); 
    1254                 throw new RuntimeException("can only handle DataType and PrimitiveType properties but was: " + prop.getType().getClass().getName()); 
    1255             } 
    1256         } 
    1257         return instSpec; 
    1258     } 
    1259  
    1260     /** 
    1261      * <p> 
    1262      * Gets or creates a {@link Package} for {@link InstanceSpecification} created by the 
    1263      * usage-based testing. Each service gets its own sub-package within a package called 
    1264      * UBT_InstanceSpecifications. " 
    1265      * </p> 
    1266      *  
    1267      * @param model 
    1268      *            model in which the package is generated 
    1269      * @param event 
    1270      *            event from which the service name is inferred 
    1271      * @return package for the {@link InstanceSpecification}s 
    1272      */ 
    1273     private static Package getOrCreateInstanceSpecificationPackage(Model model, Event event) { 
    1274         String pkgUBTInstSpecs = "UBT_InstanceSpecifications"; 
    1275         Package ubtInstSpecPkg = (Package) model.getOwnedMember(pkgUBTInstSpecs); 
    1276         if (ubtInstSpecPkg == null) { 
    1277             ubtInstSpecPkg = 
    1278                 (Package) model.createPackagedElement(pkgUBTInstSpecs, UMLPackage.Literals.PACKAGE); 
    1279         } 
    1280         String serviceName = SOAPUtils.getServiceNameFromEvent(event); 
    1281         Package serviceInstSpecPkg = (Package) ubtInstSpecPkg.getOwnedMember(serviceName); 
    1282         if (serviceInstSpecPkg == null) { 
    1283             serviceInstSpecPkg = 
    1284                 (Package) ubtInstSpecPkg.createPackagedElement(serviceName, 
    1285                                                                UMLPackage.Literals.PACKAGE); 
    1286         } 
    1287         return serviceInstSpecPkg; 
    1288     } 
     856     
    1289857 
    1290858    /** 
     
    1381949    } 
    1382950 
    1383     /** 
    1384      * <p> 
    1385      * Creates a {@link Slot} in an {@link InstanceSpecification} for a primitive type. 
    1386      * </p> 
    1387      *  
    1388      * @param instSpec 
    1389      *            instance specification to which the slot is added 
    1390      * @param prop 
    1391      *            property that describes the slot 
    1392      * @param currentNode 
    1393      *            DOM node from which is value for the slot is inferred 
    1394      * @param path 
    1395      *            used for warnings and debug information 
    1396      */ 
    1397     private static void createSlotPrimitiveType(InstanceSpecification instSpec, 
    1398                                                 Property prop, 
    1399                                                 org.w3c.dom.Element currentNode, 
    1400                                                 String path) 
    1401     { 
    1402         List<String> attributeValues = SOAPUtils.getValuesFromElement(prop.getName(), currentNode); 
    1403  
    1404         if (attributeValues.isEmpty()) { 
    1405             if (prop.getLower() == 0) { 
    1406                 // ignoring optional attribute 
    1407                 return; 
    1408             } 
    1409             else { 
    1410                 if (currentNode != null) { 
    1411                     Console.traceln(Level.WARNING, 
    1412                                     "required attribute not found in SOAP message: " + path + "." + 
    1413                                         prop.getName()); 
    1414                     Console.traceln(Level.WARNING, "setting default values for this attribute"); 
    1415                     Console.traceln(Level.FINE, "XML structure of path:" + StringTools.ENDLINE + 
    1416                         SOAPUtils.getSerialization(currentNode)); 
    1417                 } 
    1418                 attributeValues.add(null); 
    1419             } 
    1420         } 
    1421         for (String attributeValue : attributeValues) { 
    1422             Slot slot = instSpec.createSlot(); 
    1423             slot.setDefiningFeature(prop); 
    1424             if ("String".equals(prop.getType().getName())) { 
    1425                 LiteralString value = 
    1426                     (LiteralString) slot.createValue(prop.getName(), null, 
    1427                                                      UMLPackage.Literals.LITERAL_STRING); 
    1428                 if (attributeValue != null) { 
    1429                     value.setValue(attributeValue); 
    1430                 } 
    1431                 else { 
    1432                     value.setValue("foobar"); 
    1433                 } 
    1434             } 
    1435             else if ("Integer".equals(prop.getType().getName())) { 
    1436                 LiteralInteger value = 
    1437                     (LiteralInteger) slot.createValue(prop.getName(), null, 
    1438                                                       UMLPackage.Literals.LITERAL_INTEGER); 
    1439                 if (attributeValue != null) { 
    1440                     value.setValue(Integer.parseInt(attributeValue)); 
    1441                 } 
    1442                 else { 
    1443                     value.setValue(42); 
    1444                 } 
    1445             } 
    1446             else if ("Boolean".equals(prop.getType().getName())) { 
    1447                 LiteralBoolean value = 
    1448                     (LiteralBoolean) slot.createValue(prop.getName(), null, 
    1449                                                       UMLPackage.Literals.LITERAL_BOOLEAN); 
    1450                 if (attributeValue != null) { 
    1451                     value.setValue(Boolean.parseBoolean(attributeValue)); 
    1452                 } 
    1453                 else { 
    1454                     value.setValue(true); 
    1455                 } 
    1456             } 
    1457             else if ("Real".equals(prop.getType().getName())) { 
    1458                 LiteralReal value = 
    1459                     (LiteralReal) slot.createValue(prop.getName(), null, 
    1460                                                    UMLPackage.Literals.LITERAL_REAL); 
    1461                 if (attributeValue != null) { 
    1462                     value.setValue(Double.parseDouble(attributeValue)); 
    1463                 } 
    1464                 else { 
    1465                     value.setValue(3.14); 
    1466                 } 
    1467             } 
    1468             else { 
    1469                 Console.traceln(Level.SEVERE, "could not create literal for primitive type: " + 
    1470                     prop.getType().getName()); 
    1471                 throw new RuntimeException("unknown primitive type: " + prop.getType().getName()); 
    1472             } 
    1473         } 
    1474     } 
     951     
    1475952 
    1476953    /** 
     
    1483960     * @return true if the direction is IN or INOUT; false otherwise 
    1484961     */ 
    1485     private static boolean isInParameter(Parameter parameter) { 
     962    public static boolean isInParameter(Parameter parameter) { 
    1486963        return parameter.getDirection() == ParameterDirectionKind.IN_LITERAL || 
    1487964            parameter.getDirection() == ParameterDirectionKind.INOUT_LITERAL; 
     
    1497974     * @return true if the direction is RETURN, OUT, or INOUT; false otherwise 
    1498975     */ 
    1499     private static boolean isOutParameter(Parameter parameter) { 
     976    public static boolean isOutParameter(Parameter parameter) { 
    1500977        return parameter.getDirection() == ParameterDirectionKind.RETURN_LITERAL || 
    1501978            parameter.getDirection() == ParameterDirectionKind.OUT_LITERAL || 
     
    1513990     * @return true if the message is a call message; false otherwise 
    1514991     */ 
    1515     private static boolean isCallMessage(Message message) { 
     992    public static boolean isCallMessage(Message message) { 
    1516993        if (message == null) { 
    1517994            return false; 
Note: See TracChangeset for help on using the changeset viewer.