Search in sources :

Example 1 with ForwardMessage

use of net.sf.sdedit.message.ForwardMessage in project abstools by abstools.

the class MessageProcessor method _processMessage.

private ForwardMessage _processMessage(boolean openFragments) throws SemanticError {
    checkSemantics();
    if (diagram.isThreaded()) {
        findThreadNumbers();
        diagram.setCallerThread(callerThread);
    } else {
        noThreadingChecks();
    }
    caller = findCaller();
    if (!isPrimitiveMessage()) {
        callee = findCallee();
    } else {
        callee = null;
    }
    ForwardMessage message = getMessage();
    // fixes bug 2019720
    if (openFragments) {
        diagram.getFragmentManager().openFragments();
    }
    return message;
}
Also used : ForwardMessage(net.sf.sdedit.message.ForwardMessage)

Example 2 with ForwardMessage

use of net.sf.sdedit.message.ForwardMessage in project abstools by abstools.

the class Diagram method readNextMessage.

private void readNextMessage() throws SyntaxError, SemanticError {
    MessageData data = provider.nextMessage();
    noteManager.closeNote(data.getCaller());
    String[] callees = data.getCallees();
    if (callees.length == 1) {
        throw new SyntaxError(provider, "A broadcast message must have at least two receivers");
    }
    if (callees.length >= 2) {
        if (data.isSpawnMessage()) {
            throw new SyntaxError(provider, "Broadcast messages are spawning by default");
        }
        Set<String> calleeSet = new HashSet<String>();
        Lifeline[] allButLast = new Lifeline[callees.length - 1];
        for (int i = 0; i < callees.length; i++) {
            String callee = callees[i];
            if (callee.length() == 0) {
                throw new SyntaxError(provider, "Malformed broadcast message");
            }
            if (!calleeSet.add(callee)) {
                throw new SyntaxError(provider, "Duplicate receiver: " + callee);
            }
            if (callee.equals(data.getCaller())) {
                throw new SyntaxError(provider, "The sender " + callee + " cannot be a " + "receiver of the broadcast message");
            }
            noteManager.closeNote(callee);
            MessageData part = new MessageData();
            // TODO mnemonics
            part.setCaller(data.getCaller());
            part.setCallee(callee);
            part.setLevel(data.getLevel());
            part.setThread(data.getThread());
            if (getLifeline(data.getCaller()) != null) {
                if (!getLifeline(data.getCaller()).isAlwaysActive()) {
                    part.setSpawnMessage(true);
                }
            }
            part.setReturnsInstantly(data.returnsInstantly());
            if (i == 0) {
                part.setNoteNumber(data.getNoteNumber());
                part.setMessage(data.getMessage());
                part.setBroadcastType(BroadcastMessage.FIRST);
            } else if (i == callees.length - 1) {
                part.setBroadcastType(BroadcastMessage.LAST);
            } else {
                part.setBroadcastType(BroadcastMessage.OTHER);
            }
            BroadcastMessage msg = (BroadcastMessage) processor.processMessage(part);
            if (i < callees.length - 1) {
                allButLast[i] = msg.getCallee();
            } else {
                msg.setOtherCallees(allButLast);
            }
            processor.execute(msg);
        }
    } else {
        noteManager.closeNote(data.getCallee());
        ForwardMessage msg = processor.processMessage(data);
        processor.execute(msg);
    }
    fragmentManager.clearLabels();
}
Also used : ForwardMessage(net.sf.sdedit.message.ForwardMessage) SyntaxError(net.sf.sdedit.error.SyntaxError) BroadcastMessage(net.sf.sdedit.message.BroadcastMessage) HashSet(java.util.HashSet)

Aggregations

ForwardMessage (net.sf.sdedit.message.ForwardMessage)2 HashSet (java.util.HashSet)1 SyntaxError (net.sf.sdedit.error.SyntaxError)1 BroadcastMessage (net.sf.sdedit.message.BroadcastMessage)1