net.sf.sdedit.text
Class TextHandler

java.lang.Object
  extended by net.sf.sdedit.text.TextHandler
All Implemented Interfaces:
DiagramDataProvider

public class TextHandler
extends Object
implements DiagramDataProvider

A DiagramDataProvider implementation, reading a diagram specification from a single string.

Author:
Markus Strauch

Constructor Summary
TextHandler(String text)
          Creates a new TextHandler for the given text.
 
Method Summary
 boolean advance()
          Reads the next line in the specification.
 boolean closeFragment()
          Returns true if the last fragment returned by DiagramDataProvider.openFragment() is to be closed now (so it is a comment on the messages that were read between the last time DiagramDataProvider.openFragment() did not return null and now.
 String getAnnotation(Lifeline lifeline)
           
 String getCurrentLine()
          Returns the line that is currently read.
 String[] getDescription()
          Returns an array of strings to be used as a description of the diagram.
 Pair<Lifeline,Integer> getEventAssociation()
          If the current line specifies an association of a note to the current vertical position of a lifeline, this method returns a pair consisting of the lifeline and the note number.
 String getFragmentSeparator()
          If the following messages belong to a new section of the most recently opened fragment, this method returns the title of the section, otherwise null
 int getLineBegin()
          Returns the index of the first position of the current line in the specification.
 int getLineEnd()
          Returns the index of the last position of the current line in the specification string.
 int getLineNumber()
           
 Note getNote()
          If there is a note specified at the current line and the subsequent lines, a Note representation is returned, otherwise null
 Object getState()
          Gets the current state of the provider.
 String getText()
           
 String getTitle()
          Returns the diagram's title or null, if no title is defined
 MessageData nextMessage()
          Returns the MessageData object made from the current line.
 Lifeline nextObject()
          Returns the Lifeline object made from the current line}.
 String openFragment()
          If at the current position in the data the beginning of a fragment is specified, the title of the fragment is returned, otherwise null.
 void setDiagram(Diagram diagram)
          Sets the diagram instance that corresponds to the specification read by this TextHandler.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextHandler

public TextHandler(String text)
Creates a new TextHandler for the given text.

Parameters:
text - a diagram specification
Method Detail

setDiagram

public void setDiagram(Diagram diagram)
Sets the diagram instance that corresponds to the specification read by this TextHandler. This method is called inside Diagram.generate().

Specified by:
setDiagram in interface DiagramDataProvider
Parameters:
diagram - the diagram that corresponds to the specification read by this TextHandler

getLineBegin

public int getLineBegin()
Returns the index of the first position of the current line in the specification.

Returns:
the index of the first position of the current line in the specification

getState

public Object getState()
Description copied from interface: DiagramDataProvider
Gets the current state of the provider. The state depends on how far it has advanced when reading the data.

Specified by:
getState in interface DiagramDataProvider
Returns:
the current state of the provider or null if the provider does not provide information about its state

getLineNumber

public int getLineNumber()

getText

public String getText()

getLineEnd

public int getLineEnd()
Returns the index of the last position of the current line in the specification string.

Returns:
the index of the last position of the current line in the specification string

getCurrentLine

public String getCurrentLine()
Returns the line that is currently read.

Returns:
the line that is currently read

getTitle

public String getTitle()
Description copied from interface: DiagramDataProvider
Returns the diagram's title or null, if no title is defined

Specified by:
getTitle in interface DiagramDataProvider
Returns:
the diagram's title or null, if no title is defined
See Also:
DiagramDataProvider.getTitle()

getDescription

public String[] getDescription()
Description copied from interface: DiagramDataProvider
Returns an array of strings to be used as a description of the diagram.

Specified by:
getDescription in interface DiagramDataProvider
Returns:
an array of strings to be used as a description of the diagram

advance

public boolean advance()
Reads the next line in the specification. If another line is present, the next object reflecting the current line will be returned by a call to nextObject(), nextMessage(), getNote(), openFragment() or getEventAssociation().

Specified by:
advance in interface DiagramDataProvider
Returns:
flag denoting if another object or message line could be read

openFragment

public String openFragment()
Description copied from interface: DiagramDataProvider
If at the current position in the data the beginning of a fragment is specified, the title of the fragment is returned, otherwise null.

Specified by:
openFragment in interface DiagramDataProvider
Returns:
a fragment title, if one is specified currently, otherwise null

getFragmentSeparator

public String getFragmentSeparator()
Description copied from interface: DiagramDataProvider
If the following messages belong to a new section of the most recently opened fragment, this method returns the title of the section, otherwise null

Specified by:
getFragmentSeparator in interface DiagramDataProvider
Returns:
the title of a fragment section or null

closeFragment

public boolean closeFragment()
Description copied from interface: DiagramDataProvider
Returns true if the last fragment returned by DiagramDataProvider.openFragment() is to be closed now (so it is a comment on the messages that were read between the last time DiagramDataProvider.openFragment() did not return null and now.

Specified by:
closeFragment in interface DiagramDataProvider
Returns:
true if the last comment returned by DiagramDataProvider.openFragment() is to be closed now

nextMessage

public MessageData nextMessage()
                        throws SyntaxError
Returns the MessageData object made from the current line.

Specified by:
nextMessage in interface DiagramDataProvider
Returns:
the MessageData object made from the current line
Throws:
SyntaxError - if the next message cannot be parsed

nextObject

public Lifeline nextObject()
                    throws SyntaxError
Returns the Lifeline object made from the current line}.

Specified by:
nextObject in interface DiagramDataProvider
Returns:
the Lifeline object made from the current line
Throws:
SyntaxError - if the next object declaration is not well-formed

getAnnotation

public String getAnnotation(Lifeline lifeline)

getNote

public Note getNote()
             throws SyntaxError
If there is a note specified at the current line and the subsequent lines, a Note representation is returned, otherwise null

Specified by:
getNote in interface DiagramDataProvider
Returns:
a note, if one is specified at the current position in text, otherwise null
Throws:
SyntaxError

getEventAssociation

public Pair<Lifeline,Integer> getEventAssociation()
                                           throws SyntaxError
If the current line specifies an association of a note to the current vertical position of a lifeline, this method returns a pair consisting of the lifeline and the note number.

Specified by:
getEventAssociation in interface DiagramDataProvider
Returns:
a pair of a lifeline and a note number, if the current line specifies and association between the note and the lifeline, otherwise null
Throws:
SyntaxError


Copyright © 2011. All Rights Reserved.