Package nl.rrd.wool.model
Class WoolNodeBody
- java.lang.Object
-
- nl.rrd.wool.model.WoolNodeBody
-
public class WoolNodeBody extends Object
A node body can occur in three different contexts inside aWoolNode.- Directly in the node. In this case it specifies the agent statement with possible commands and user replies.
- As part of a clause in a
WoolIfCommand. The content is the same as directly in the node. The only difference is that it is performed conditionally. - As part of a
WoolReply. In this case it specifies the user statement with possible commands, but no replies. Note that the UI shows these statements as options immediately along with the agent statement. ThisWoolNodeBodydoes not contain commands that are to be performed when the reply is chosen. Such commands are specified separately in aWoolReply.
The body contains a statement as a list of segments where each segment is one of:
TextSegment: aWoolVariableStringwith text and variablesCommandSegment: a command (see below)
The segments are always normalized so that subsequent text segments are automatically merged into one.
The type of commands depend on the context. Directly in the node or in a
WoolIfCommand, it can be:WoolActionCommand: Actions to perform along with the agent's text statement.WoolIfCommand: Contains clauses, each with aWoolNodeBodyspecifying conditional statements, replies and commands.WoolSetCommand: Sets a variable value.
As part of a reply (remember the earlier remarks about commands in a reply), it can be:
WoolInputCommand: Allow user to provide input other than just clicking the reply option.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classWoolNodeBody.CommandSegmentstatic classWoolNodeBody.Segmentstatic classWoolNodeBody.TextSegment
-
Constructor Summary
Constructors Constructor Description WoolNodeBody()
-
Method Summary
Modifier and Type Method Description voidaddReply(WoolReply reply)voidaddSegment(WoolNodeBody.Segment segment)voidexecute(Map<String,Object> variables, boolean trimText, WoolNodeBody processedBody)Executes the agent statement and reply statements in this body with respect to the specified variable map.WoolReplyfindReplyById(int replyId)List<WoolNodePointer>getNodePointers()voidgetNodePointers(Set<WoolNodePointer> pointers)List<String>getReadVariableNames()Retrieves all variable names that are read in this body.voidgetReadVariableNames(Set<String> varNames)Retrieves all variable names that are read in this body and adds them to the specified set.List<WoolReply>getReplies()List<WoolNodeBody.Segment>getSegments()Returns the segments as an unmodifiable list.List<String>getWriteVariableNames()Retrieves all variable names that are written in this body.voidgetWriteVariableNames(Set<String> varNames)Retrieves all variable names that are written in this body and adds them to the specified set.voidremoveLeadingWhitespace()voidremoveTrailingWhitespace()StringtoString()voidtrimWhitespace()
-
-
-
Method Detail
-
getSegments
public List<WoolNodeBody.Segment> getSegments()
Returns the segments as an unmodifiable list.- Returns:
- the segments as an unmodifiable list
-
addSegment
public void addSegment(WoolNodeBody.Segment segment)
-
findReplyById
public WoolReply findReplyById(int replyId)
-
addReply
public void addReply(WoolReply reply)
-
getReadVariableNames
public List<String> getReadVariableNames()
Retrieves all variable names that are read in this body.- Returns:
- the variable names that are read in this body
-
getReadVariableNames
public void getReadVariableNames(Set<String> varNames)
Retrieves all variable names that are read in this body and adds them to the specified set.- Parameters:
varNames- the set to which the variable names are added
-
getWriteVariableNames
public List<String> getWriteVariableNames()
Retrieves all variable names that are written in this body.- Returns:
- the variable names that are written in this body
-
getWriteVariableNames
public void getWriteVariableNames(Set<String> varNames)
Retrieves all variable names that are written in this body and adds them to the specified set.- Parameters:
varNames- the set to which the variable names are added
-
getNodePointers
public List<WoolNodePointer> getNodePointers()
-
getNodePointers
public void getNodePointers(Set<WoolNodePointer> pointers)
-
execute
public void execute(Map<String,Object> variables, boolean trimText, WoolNodeBody processedBody) throws EvaluationException
Executes the agent statement and reply statements in this body with respect to the specified variable map. It executes ("if" and "set") commands and resolves variables. Any resulting body content that should be sent to the client, is added to agent and reply statements in "processedBody". This content can be text or client commands, with all variables resolved.This method also normalizes whitespace in the text segments. It removes empty lines and makes sure that lines end with "\n". Within each line, it trims whitespace from the start and end, and it replaces any sequence of spaces and tabs with one space.
This method should only be called if all variables in the text segments have been resolved.
- Parameters:
variables- the variable maptrimText- true if trailing new lines should be trimmed, false if they should be preserved. This should be set to true for the body that is directly in the node. If the body is in an "if" clause or in a reply, it should be set to false.processedBody- the processed body- Throws:
EvaluationException- if an expression cannot be evaluated
-
trimWhitespace
public void trimWhitespace()
-
removeLeadingWhitespace
public void removeLeadingWhitespace()
-
removeTrailingWhitespace
public void removeTrailingWhitespace()
-
-