org.argouml.notation.providers.uml
Class AbstractMessageNotationUml

java.lang.Object
  extended by org.argouml.notation.NotationProvider
      extended by org.argouml.notation.providers.MessageNotation
          extended by org.argouml.notation.providers.uml.AbstractMessageNotationUml
Direct Known Subclasses:
MessageNotationUml, SDMessageNotationUml

public abstract class AbstractMessageNotationUml
extends MessageNotation

This abstract class provides the common functionality for the UML notation of messages.
It is extended by MessageNotationUml, with the notation of messages as seen in collaboration diagrams, and SDMessageNotationUml, with the notation of messages as seen in sequence diagrams.

The Message notation syntax is a line of the following form, which we can generate and parse:

 intno := integer|name
 seq := intno ['.' intno]*
 recurrence := '*'['//'] | '*'['//']'[' iteration ']' | '['
 condition ']'
 seqelem := {[intno] ['['recurrence']']}
 seq_expr := seqelem ['.' seqelem]*
 ret_list := lvalue [',' lvalue]*
 arg_list := rvalue [',' rvalue]*
 predecessor := seq [',' seq]* '/'
 message := [predecessor] seq_expr ':' [ret_list :=] name ([arg_list])
 
Which is rather complex, so a few examples: This syntax is compatible with the UML 1.4.2 specification.

Actually, only a subset of this syntax is currently supported, and some is not even planned to be supported. The exceptions are intno, which only allows a number possibly followed by a sequence of letters in the range 'a' - 'z', seqelem, which does not allow a recurrence, and message, which does allow one recurrence near seq_expr.

(formerly, the supported syntax was: name: action )

Generating a string from the model has some extra functionality: If obtaining the Script of the Action returns an empty string, then an alternative representation is given: If the action is a CallAction, use the name of its Operation, and if it is a SendAction, the name of its Signal. If also this returns no string, then we display the name of the Message.

Rationale: This allows ArgoUML to show something on the diagram with older projects, which only had the name of the Message filled in by the user. This also may improve the diagrams for imported XMI.

Parsing a text that is generated by one of the backup scenarios, causes it to be written back in the script of the Action. Hence, editing the text on the diagram only once causes the Action Script to be used from then on.

Supported operations for the parser:

Since:
0.28.alpha1
See Also:
MessageNotationUml, SDMessageNotationUml

Nested Class Summary
protected static class AbstractMessageNotationUml.MsgPtr
          An object containing an UML Message object.
 
Constructor Summary
AbstractMessageNotationUml(java.lang.Object umlMessage)
           
 
Method Summary
protected  void buildAction(java.lang.Object umlMessage)
          Build a CallAction for the given UML Message if it did not have an Action yet.
protected  int countSuccessors(java.lang.Object message)
          Count the number of successors of the given Message.
protected  java.lang.String fillBlankFunctionName(java.lang.Object umlMessage, java.lang.String fname, boolean mayDeleteExpr)
          Fill in the function name if it is blank.
protected  java.lang.StringBuilder fillBlankVariableName(java.lang.Object umlMessage, java.lang.StringBuilder varname, boolean mayDeleteExpr)
          Fill in the variable name if it is blank.
protected  java.lang.String generateMessageNumber(java.lang.Object umlMessage, java.lang.Object umlPredecessor, int position)
          Generate the "intno" of the given Message.
protected  java.lang.String generateRecurrence(java.lang.Object expr)
          Generates a textual description of an IterationExpression.
protected  java.lang.String getInitiatorOfAction(java.lang.Object umlAction)
           
 java.lang.String getParsingHelp()
           
protected  boolean handleArguments(java.lang.Object umlMessage, java.util.List<java.lang.String> args, boolean refindOperation)
           
protected  boolean handleFunctionName(java.lang.Object umlMessage, java.lang.String fname, java.lang.StringBuilder varname, boolean refindOperation)
          Store the given function name and return variable name in the script of the action of the given message.
protected  void handleGuard(java.lang.Object umlMessage, java.lang.StringBuilder guard, boolean parallell, boolean iterative)
          Store the parsed guard in the UML objects related to the given Message.
protected  void handleOperation(java.lang.Object umlMessage, java.lang.String fname, boolean refindOperation)
          Update the model with the operation name.
protected  void handlePredecessors(java.lang.Object umlMessage, java.util.List<java.util.List> predecessors, boolean hasPredecessors)
          Set the predecessors of the given Message.
protected  boolean handleSequenceNumber(java.lang.Object umlMessage, java.util.List<java.lang.Integer> seqno, boolean refindOperation)
           
protected  java.util.List<CustomSeparator> initParameterSeparators()
           
 void parse(java.lang.Object umlMessage, java.lang.String text)
          Parses the given text, and adapts the modelElement and maybe related elements accordingly.
protected  java.util.List<java.lang.String> parseArguments(java.lang.String paramExpr, boolean mayDeleteExpr)
           
protected  void parseMessage(java.lang.Object umlMessage, java.lang.String s)
          Parse a Message textual description.
protected  int recCountPredecessors(java.lang.Object umlMessage, AbstractMessageNotationUml.MsgPtr ptr)
          Recursively count the number of predecessors of the given Message, and return (a pointer to) the first Message in the chain.
protected  java.lang.String toString(java.lang.Object umlMessage, boolean showSequenceNumbers)
           
 
Methods inherited from class org.argouml.notation.providers.MessageNotation
initialiseListener
 
Methods inherited from class org.argouml.notation.NotationProvider
addElementListener, addElementListener, addElementListener, cleanListener, formatNameList, formatNameList, removeAllElementListeners, removeElementListener, toString, updateListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractMessageNotationUml

public AbstractMessageNotationUml(java.lang.Object umlMessage)
Parameters:
umlMessage - the UML Message object
Method Detail

toString

protected java.lang.String toString(java.lang.Object umlMessage,
                                    boolean showSequenceNumbers)

getInitiatorOfAction

protected java.lang.String getInitiatorOfAction(java.lang.Object umlAction)

initParameterSeparators

protected java.util.List<CustomSeparator> initParameterSeparators()

parse

public void parse(java.lang.Object umlMessage,
                  java.lang.String text)
Description copied from class: NotationProvider
Parses the given text, and adapts the modelElement and maybe related elements accordingly.

Specified by:
parse in class NotationProvider
Parameters:
umlMessage - the modelelement to adapt
text - the string given by the user to be parsed to adapt the model

getParsingHelp

public java.lang.String getParsingHelp()
Specified by:
getParsingHelp in class NotationProvider
Returns:
a i18 key that represents a help string giving an explanation to the user of the syntax

generateMessageNumber

protected java.lang.String generateMessageNumber(java.lang.Object umlMessage,
                                                 java.lang.Object umlPredecessor,
                                                 int position)
Generate the "intno" of the given Message.

If the predecessor of the given message has only one successor, then we return the string representation of the given integer.

If the predecessor of the given message has more than one successor, then this is a case of parallel execution of messages, e.g. Message 3.1a and Message 3.1b are concurrent within activation 3.1. Hence In this case we use a syntax like: 1a, 1b, 1c. This means that the first successor in the ordered list of successors that has more than one entry will get the postfix a, the second b, etc. TODO: Document exceptional behaviour.

Parameters:
umlMessage - the UML message object to generate the sequence number for
umlPredecessor - the immediate predecessor message (UML object) that has the given message as successor
position - the integer position of the given message within its sequence
Returns:
the generated sequence expression string, or null if the given Message was null

countSuccessors

protected int countSuccessors(java.lang.Object message)
Count the number of successors of the given Message.

Successors have the same Activator as the given message. This Activator may be null.

Parameters:
message - the UML Message object
Returns:
the number of successors: 0..n

generateRecurrence

protected java.lang.String generateRecurrence(java.lang.Object expr)
Generates a textual description of an IterationExpression.

Parameters:
expr - the given UML expression object or null
Returns:
the string

parseMessage

protected void parseMessage(java.lang.Object umlMessage,
                            java.lang.String s)
                     throws java.text.ParseException
Parse a Message textual description.

TODO: - This method is too complex, lets break it up.

Parameters:
umlMessage - the UML Message object to apply any changes to
s - the String to parse
Throws:
java.text.ParseException - when it detects an error in the attribute string. See also ParseError.getErrorOffset().

parseArguments

protected java.util.List<java.lang.String> parseArguments(java.lang.String paramExpr,
                                                          boolean mayDeleteExpr)
Parameters:
paramExpr -
mayDeleteExpr -
Returns:

handlePredecessors

protected void handlePredecessors(java.lang.Object umlMessage,
                                  java.util.List<java.util.List> predecessors,
                                  boolean hasPredecessors)
                           throws java.text.ParseException
Set the predecessors of the given Message.

Parameters:
umlMessage - the given UML Message object to be adapted
predecessors - the given predecessors as parsed
hasPredecessors - true if there are some, if false we do nothing
Throws:
java.text.ParseException - if something is wrong with the predecessor text

handleOperation

protected void handleOperation(java.lang.Object umlMessage,
                               java.lang.String fname,
                               boolean refindOperation)
                        throws java.text.ParseException
Update the model with the operation name.

The given operation name is located on the receiver of the given message. If an operation with the given name and a matching number of arguments is located, then the CallAction of the message is adapted accordingly.

Parameters:
umlMessage - the message of which the CallAction is to be adapted
fname - the name of the operation to be used
refindOperation - true if we have to set the operation of the CallAction
Throws:
java.text.ParseException - if the operation syntax can not be parsed

handleSequenceNumber

protected boolean handleSequenceNumber(java.lang.Object umlMessage,
                                       java.util.List<java.lang.Integer> seqno,
                                       boolean refindOperation)
                                throws java.text.ParseException
Parameters:
umlMessage -
seqno -
refindOperation -
Returns:
Throws:
java.text.ParseException

handleArguments

protected boolean handleArguments(java.lang.Object umlMessage,
                                  java.util.List<java.lang.String> args,
                                  boolean refindOperation)
Parameters:
umlMessage -
args -
refindOperation -
Returns:

handleFunctionName

protected boolean handleFunctionName(java.lang.Object umlMessage,
                                     java.lang.String fname,
                                     java.lang.StringBuilder varname,
                                     boolean refindOperation)
Store the given function name and return variable name in the script of the action of the given message.

Constraint: the given Message shall have an Action.

Parameters:
umlMessage - the given UML Message object to adapt
fname - the name of the function
varname - the return variable name
refindOperation - if false, then we may return true or false. If true, we return true.
Returns:
true if we stored the fname and varname in the Action of the Message

fillBlankVariableName

protected java.lang.StringBuilder fillBlankVariableName(java.lang.Object umlMessage,
                                                        java.lang.StringBuilder varname,
                                                        boolean mayDeleteExpr)
Fill in the variable name if it is blank.

The variable name is the part in front of the assignment operator.

Parameters:
umlMessage - the given message to fill the variable name for
varname - if null, then we get the variable name from the model.
mayDeleteExpr - if true, then we may delete the variable, and hence we return an empty string
Returns:
the original variable name, or if it was null, a variable name generated from the model

fillBlankFunctionName

protected java.lang.String fillBlankFunctionName(java.lang.Object umlMessage,
                                                 java.lang.String fname,
                                                 boolean mayDeleteExpr)
Fill in the function name if it is blank.

The fname is the part of the script after the assignment operator.

Parameters:
umlMessage - the given message to fill the fname for
fname - if null, then we get the fname from the model.
mayDeleteExpr - if true, then we may delete the function, and hence we return an empty string
Returns:
the original fname, or if it was null, a fname generated from the model

handleGuard

protected void handleGuard(java.lang.Object umlMessage,
                           java.lang.StringBuilder guard,
                           boolean parallell,
                           boolean iterative)
Store the parsed guard in the UML objects related to the given Message.

Parameters:
umlMessage - the UML Message object
guard - the guard expression string
parallell - true if parallel execution was indicated
iterative - true if this is an iterative expression, as opposed to a condition

buildAction

protected void buildAction(java.lang.Object umlMessage)
Build a CallAction for the given UML Message if it did not have an Action yet.

Parameters:
umlMessage - the UML Message object to create an Action for

recCountPredecessors

protected int recCountPredecessors(java.lang.Object umlMessage,
                                   AbstractMessageNotationUml.MsgPtr ptr)
Recursively count the number of predecessors of the given Message, and return (a pointer to) the first Message in the chain.

Parameters:
umlMessage - the UML Message to count the predecessors for
ptr - an object to contain the returned first Message
Returns:
the number of messages in the chain


ArgoUML © 1996-2006ArgoUML HomepageArgoUML Developers' pageArgoUML Cookbook