Changeset 1633 for trunk/autoquest-plugin-uml/src
- Timestamp:
- 07/31/14 14:37:39 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-plugin-uml/src/main/java/de/ugoe/cs/autoquest/plugin/uml/UMLUtils.java
r1624 r1633 241 241 /** 242 242 * <p> 243 * Extends a given model with an interaction that represents an observed sequence. 244 * </p> 245 * 246 * @param sequence sequence that is added as sequence diagram 247 * @param model UML model to which the interaction is added 248 * @param interactionName name of the interaction 249 */ 250 public static void createInteractionFromEventSequence(List<Event> sequence, Model model, String interactionName) 243 * Extends a given model with an interaction that represents an observed sequence. 244 * </p> 245 * 246 * @param sequence 247 * sequence that is added as sequence diagram 248 * @param model 249 * UML model to which the interaction is added 250 * @param interactionName 251 * name of the interaction 252 */ 253 public static void createInteractionFromEventSequence(List<Event> sequence, 254 Model model, 255 String interactionName) 251 256 { 252 257 Map<String, Class> classMap = new HashMap<>(); … … 260 265 261 266 Interaction interaction = 262 (Interaction) model 263 .createPackagedElement(interactionName,UMLPackage.Literals.INTERACTION);267 (Interaction) model.createPackagedElement(interactionName, 268 UMLPackage.Literals.INTERACTION); 264 269 265 270 Lifeline userLifeline = interaction.createLifeline("user"); … … 267 272 int i = 0; 268 273 for (Event event : sequence) { 269 if (event.getType() instanceof SOAPEventType) { 270 SOAPEventType eventType = (SOAPEventType) event.getType(); 271 String serviceName = eventType.getServiceName(); 272 String methodName = eventType.getCalledMethod(); 273 Class targetClass = classMap.get(serviceName); 274 if (targetClass == null) { 274 if (!(event.equals(Event.STARTEVENT) || event.equals(Event.ENDEVENT))) { 275 if (event.getType() instanceof SOAPEventType) { 276 SOAPEventType eventType = (SOAPEventType) event.getType(); 277 String serviceName = eventType.getServiceName(); 278 String methodName = eventType.getCalledMethod(); 279 Class targetClass = classMap.get(serviceName); 280 if (targetClass == null) { 281 throw new RuntimeException( 282 "Could not find class in the UML model that belong to the service: " + 283 serviceName); 284 } 285 286 Lifeline targetLifeline = interaction.getLifeline(serviceName); 287 if (targetLifeline == null) { 288 targetLifeline = interaction.createLifeline(serviceName); 289 Association association = 290 (Association) model.getPackagedElement("user_" + serviceName, true, 291 UMLPackage.Literals.ASSOCIATION, 292 true); 293 targetLifeline.setRepresents(association.getMemberEnd(serviceName, classMap 294 .get(serviceName))); 295 } 296 MessageOccurrenceSpecification sendFragment = 297 (MessageOccurrenceSpecification) interaction 298 .createFragment(i + ":" + methodName + "_sendFragment", 299 UMLPackage.Literals.MESSAGE_OCCURRENCE_SPECIFICATION); 300 MessageOccurrenceSpecification recvFragment = 301 (MessageOccurrenceSpecification) interaction 302 .createFragment(i + ":" + methodName + "_recvFragment", 303 UMLPackage.Literals.MESSAGE_OCCURRENCE_SPECIFICATION); 304 305 sendFragment.setCovered(userLifeline); 306 recvFragment.setCovered(targetLifeline); 307 308 Message message = interaction.createMessage(methodName); 309 message.setSignature(getOperationFromName(targetClass.getOperations(), 310 methodName)); 311 message.setSendEvent(sendFragment); 312 message.setReceiveEvent(recvFragment); 313 314 sendFragment.setMessage(message); 315 recvFragment.setMessage(message); 316 } 317 else { 275 318 throw new RuntimeException( 276 "Could not find class in the UML model that belong to the service: " + 277 serviceName); 278 } 279 280 Lifeline targetLifeline = interaction.getLifeline(serviceName); 281 if (targetLifeline == null) { 282 targetLifeline = interaction.createLifeline(serviceName); 283 Association association = 284 (Association) model.getPackagedElement("user_" + serviceName, true, 285 UMLPackage.Literals.ASSOCIATION, 286 true); 287 targetLifeline 288 .setRepresents(association.getMemberEnd(serviceName, 289 classMap.get(serviceName))); 290 } 291 MessageOccurrenceSpecification sendFragment = 292 (MessageOccurrenceSpecification) interaction 293 .createFragment(i + ":" + methodName + "_sendFragment", 294 UMLPackage.Literals.MESSAGE_OCCURRENCE_SPECIFICATION); 295 MessageOccurrenceSpecification recvFragment = 296 (MessageOccurrenceSpecification) interaction 297 .createFragment(i + ":" + methodName + "_recvFragment", 298 UMLPackage.Literals.MESSAGE_OCCURRENCE_SPECIFICATION); 299 300 sendFragment.setCovered(userLifeline); 301 recvFragment.setCovered(targetLifeline); 302 303 Message message = interaction.createMessage(methodName); 304 message.setSignature(getOperationFromName(targetClass.getOperations(), methodName)); 305 message.setSendEvent(sendFragment); 306 message.setReceiveEvent(recvFragment); 307 308 sendFragment.setMessage(message); 309 recvFragment.setMessage(message); 310 } 311 else { 312 throw new RuntimeException( 313 "Wrong event type. Only SOAPEventType supported but was: " + 314 event.getType().getClass().getName()); 315 } 316 i++; 319 "Wrong event type. Only SOAPEventType supported but was: " + 320 event.getType().getClass().getName()); 321 } 322 i++; 323 } 317 324 } 318 325 }
Note: See TracChangeset
for help on using the changeset viewer.