/******************************************************************************* * Copyright (C) 2011 Mathew Hemphill * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . ******************************************************************************/ package com.ojump.sequence.graphics.viewer; import com.ojump.sequence.Constants; import com.ojump.sequence.SequenceDiagramBuilder; import com.ojump.sequence.model.Lifeline; import com.ojump.sequence.model.Note; import com.ojump.sequence.model.SequenceDiagram; /** * Reference implementation of a viewable sequence diagram. * * @author Mathew Hemphill */ public class SequenceDiagramViewableReferenceImpl implements SequenceDiagramViewable { /** * {@inheritDoc} */ public SequenceDiagram getSequenceDiagram() { SequenceDiagramBuilder builder = new SequenceDiagramBuilder(); builder.startSequenceDiagram(); final Lifeline actor = builder.addLifeline(Constants.Classifiers.ACTOR, "Actor"); final Lifeline class1 = builder.addLifeline(Constants.Classifiers.CLASS, "Class1"); final Lifeline class2 = builder.addLifeline(Constants.Classifiers.CLASS, "Class2"); final Lifeline class3 = builder.addLifeline(Constants.Classifiers.CLASS, "Class3"); class3.setLifelineStartDeferred(true); final Lifeline class4 = builder.addLifeline(Constants.Classifiers.CLASS, "Class4"); final Lifeline class5 = builder.addLifeline(Constants.Classifiers.CLASS, "Class5"); final Lifeline database = builder.addLifeline(Constants.Classifiers.DATABASE, "Database"); final Note longNote = new Note(); longNote.setMessage("This is a really long note that spans multiple lines of text and tends to waffle on a bit."); final Note shortNote = new Note(); shortNote.setMessage("Short note"); // simple message... builder.addMessageAndStartActivation(Constants.MessageTypes.SYNCHRONOUS, "synchronousMessage(record)", actor, class1, longNote); // shows activations that are ended without reply messages... builder.addMessageAndStartActivation(Constants.MessageTypes.SYNCHRONOUS, "method()", class1, class2, null); builder.addMessageAndStartActivation(Constants.MessageTypes.SYNCHRONOUS, "method()", class2, class4, null); builder.addMessageAndStartActivation(Constants.MessageTypes.SYNCHRONOUS, "method()", class4, class5, null); builder.endActivation(); builder.endActivation(); builder.endActivation(); // shows activations that are ended with reply messages... builder.addMessageAndStartActivation(Constants.MessageTypes.SYNCHRONOUS, "method()", class1, class2, null); builder.addMessageAndStartActivation(Constants.MessageTypes.SYNCHRONOUS, "method()", class2, class4, null); builder.addMessageAndStartActivation(Constants.MessageTypes.SYNCHRONOUS, "method()", class4, class5, null); builder.addMessage(Constants.MessageTypes.REPLY, "id", class5, class4, null); builder.endActivation(); builder.addMessage(Constants.MessageTypes.REPLY, null, class4, class2, null); builder.endActivation(); builder.addMessage(Constants.MessageTypes.REPLY, null, class2, class1, null); builder.endActivation(); // shows messages going from left to right and from right to left... builder.addMessageAndStartActivation(Constants.MessageTypes.SYNCHRONOUS, "method()", class1, class5, null); builder.addMessageAndStartActivation(Constants.MessageTypes.SYNCHRONOUS, "method()", class5, class2, null); builder.addMessage(Constants.MessageTypes.REPLY, null, class2, class5, null); builder.endActivation(); builder.addMessage(Constants.MessageTypes.REPLY, null, class5, class1, null); builder.endActivation(); // shows messages going from left to right and from right to left with a message to self... builder.addMessageAndStartActivation(Constants.MessageTypes.SYNCHRONOUS, "method()", class1, class5, null); builder.addMessageAndStartActivation(Constants.MessageTypes.SYNCHRONOUS, "method()", class5, class2, null); builder.addMessage(Constants.MessageTypes.SYNCHRONOUS, "messageToSelf()", class2, class2, null); builder.addMessage(Constants.MessageTypes.REPLY, null, class2, class5, null); builder.endActivation(); builder.addMessage(Constants.MessageTypes.REPLY, null, class5, class1, null); builder.endActivation(); // shows messages without using activations... builder.addMessage(Constants.MessageTypes.SYNCHRONOUS, "method()", class1, class5, null); builder.addMessage(Constants.MessageTypes.SYNCHRONOUS, "method()", class5, class2, null); builder.addMessage(Constants.MessageTypes.SYNCHRONOUS, "messageToSelf()", class2, class2, null); builder.addMessage(Constants.MessageTypes.REPLY, null, class2, class5, null); builder.addMessage(Constants.MessageTypes.REPLY, null, class5, class1, null); // shows a start (create) message... // shows a start (create) message (with note)... final Note createNote = new Note(); createNote.setMessage("instantiate class3"); builder.addLifelineStartMessage("new", class1, class3, createNote); builder.addMessageAndStartActivation(Constants.MessageTypes.SYNCHRONOUS, "delete", class1, class3, null); builder.endActivation(); builder.addLifelineEnd(class3); // shows a loop... builder.addInteractionFragment("loop"); builder.addGuardedFragment("[foreach record]"); builder.addLifelineStartMessage("new", class1, class3, null); builder.addMessageAndStartActivation(Constants.MessageTypes.SYNCHRONOUS, "method()", class1, class2, null); builder.addMessage(Constants.MessageTypes.REPLY, null, class2, class1, longNote); builder.endActivation(); builder.addMessageAndStartActivation(Constants.MessageTypes.SYNCHRONOUS, "method(user, record, customer)", class1, class3, null); builder.endActivation(); // shows an alternative (if) statement... builder.addInteractionFragment("alt"); builder.addGuardedFragment("[if record.exists]"); builder.addMessageAndStartActivation(Constants.MessageTypes.SYNCHRONOUS, "update(user, record)", class1, class5, null); builder.addMessage(Constants.MessageTypes.SYNCHRONOUS, "update record", class5, database, null); builder.addMessage(Constants.MessageTypes.REPLY, "", class5, class1, null); builder.endActivation(); builder.endGuardedFragment(); builder.addGuardedFragment("[else]"); builder.addMessageAndStartActivation(Constants.MessageTypes.SYNCHRONOUS, "insert(user, record)", class1, class5, null); builder.addMessage(Constants.MessageTypes.SYNCHRONOUS, "insert record", class5, database, null); builder.addMessage(Constants.MessageTypes.REPLY, "id", class5, class1, null); builder.endActivation(); builder.endGuardedFragment(); builder.endInteractionFragment(); // shows a delete message (with empty activation)... builder.addMessageAndStartActivation(Constants.MessageTypes.SYNCHRONOUS, "delete", class1, class3, null); builder.endActivation(); builder.addLifelineEnd(class3); builder.endGuardedFragment(); builder.endInteractionFragment(); builder.addMessage(Constants.MessageTypes.REPLY, "", class1, actor, null); builder.endActivation(); return builder.getSequenceDiagram(); } }