Ignore:
Timestamp:
09/18/14 09:58:15 (10 years ago)
Author:
sherbold
Message:
  • updated UMLUtils.createInteractionFromEventSequence to be compatible with the MIDAS DSL
File:
1 edited

Legend:

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

    r1643 r1752  
    2424 
    2525import org.eclipse.emf.common.util.EList; 
    26 import org.eclipse.uml2.uml.Association; 
    27 import org.eclipse.uml2.uml.Class; 
    2826import org.eclipse.uml2.uml.Comment; 
     27import org.eclipse.uml2.uml.Component; 
     28import org.eclipse.uml2.uml.Connector; 
     29import org.eclipse.uml2.uml.ConnectorEnd; 
    2930import org.eclipse.uml2.uml.Element; 
    3031import org.eclipse.uml2.uml.Interaction; 
    3132import org.eclipse.uml2.uml.InteractionFragment; 
     33import org.eclipse.uml2.uml.Interface; 
    3234import org.eclipse.uml2.uml.Lifeline; 
    3335import org.eclipse.uml2.uml.Message; 
    3436import org.eclipse.uml2.uml.MessageOccurrenceSpecification; 
     37import org.eclipse.uml2.uml.MessageSort; 
    3538import org.eclipse.uml2.uml.Model; 
    3639import org.eclipse.uml2.uml.Operation; 
     40import org.eclipse.uml2.uml.Port; 
    3741import org.eclipse.uml2.uml.Region; 
    3842import org.eclipse.uml2.uml.StateMachine; 
     
    258262                                                          String interactionName) 
    259263    { 
    260         Map<String, Class> classMap = new HashMap<>(); 
     264        Map<String, Interface> interfaceMap = new HashMap<>(); 
     265        Map<String, Port> portMap = new HashMap<>(); 
    261266 
    262267        EList<Element> elements = model.getOwnedElements(); 
    263268        for (Element element : elements) { 
    264             if (element instanceof Class) { 
    265                 classMap.put(((Class) element).getName(), (Class) element); 
     269            if (element instanceof Interface) { 
     270                interfaceMap.put(((Interface) element).getName(), (Interface) element); 
    266271            } 
    267272        } 
     
    272277 
    273278        Lifeline userLifeline = interaction.createLifeline("user"); 
    274  
     279         
     280        Component testContext = (Component) model.getPackagedElement("TestContext", true, UMLPackage.Literals.COMPONENT, true); 
     281        userLifeline.setRepresents(testContext.getAttribute("user", null)); 
     282         
     283        Component userComponent = (Component) model.getPackagedElement("User", true, UMLPackage.Literals.COMPONENT, true); 
     284        Port userPort = (Port) userComponent.getAttribute("p_user_rlus", null); 
     285         
    275286        int i = 0; 
    276287        for (Event event : sequence) { 
     
    279290                String methodName = getCalledMethodFromEvent(event); 
    280291 
    281                 Class targetClass = classMap.get(serviceName); 
    282                 if (targetClass == null) { 
     292                Interface targetInterface = interfaceMap.get(serviceName); 
     293                if (targetInterface == null) { 
    283294                    throw new RuntimeException( 
    284                                                "Could not find class in the UML model that belong to the service: " + 
     295                                               "Could not find interface in the UML model that belong to the service: " + 
    285296                                                   serviceName); 
    286297                } 
     
    289300                if (targetLifeline == null) { 
    290301                    targetLifeline = interaction.createLifeline(serviceName); 
    291                     Association association = 
    292                         (Association) model.getPackagedElement("user_" + serviceName, true, 
    293                                                                UMLPackage.Literals.ASSOCIATION, 
    294                                                                true); 
    295                     targetLifeline 
    296                         .setRepresents(association.getMemberEnd(serviceName, 
    297                                                                 classMap.get(serviceName))); 
     302                     
     303                     
     304                    targetLifeline.setRepresents(testContext.getAttribute(serviceName+"_property", null)); 
     305 
     306                    Component component = (Component) model.getPackagedElement(serviceName, true, UMLPackage.Literals.COMPONENT, true); 
     307                    portMap.put(serviceName, (Port) component.getAttribute("p_" + serviceName, null)); 
    298308                } 
    299309                MessageOccurrenceSpecification sendFragment = 
     
    310320 
    311321                Message message = interaction.createMessage(methodName); 
    312                 message.setSignature(getOperationFromName(targetClass.getOperations(), methodName)); 
     322                if( getOperationFromName(targetInterface.getOperations(), methodName)==null ) { 
     323                    System.out.println("operation not found: " + methodName); 
     324                } 
     325                message.setSignature(getOperationFromName(targetInterface.getOperations(), methodName)); 
     326                message.setMessageSort(MessageSort.ASYNCH_CALL_LITERAL); 
    313327                message.setSendEvent(sendFragment); 
    314328                message.setReceiveEvent(recvFragment); 
    315  
     329                                 
     330                EList<ConnectorEnd> sourceEnds = userPort.getEnds(); 
     331                EList<ConnectorEnd> targetEnds = portMap.get(serviceName).getEnds(); 
     332                 
     333                for( ConnectorEnd sourceEnd : sourceEnds ) { 
     334                    Connector sourceConnector = (Connector) sourceEnd.eContainer(); 
     335                    for( ConnectorEnd targetEnd : targetEnds ) { 
     336                        Connector targetConnector =  (Connector) targetEnd.eContainer(); 
     337                        if( targetConnector==sourceConnector ) { 
     338                            message.setConnector(targetConnector); 
     339                        } 
     340                    } 
     341                }                
     342                 
    316343                sendFragment.setMessage(message); 
    317344                recvFragment.setMessage(message); 
Note: See TracChangeset for help on using the changeset viewer.