Class WoolNodeBody


  • public class WoolNodeBody
    extends Object
    A node body can occur in three different contexts inside a WoolNode.

    • 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. This WoolNodeBody does not contain commands that are to be performed when the reply is chosen. Such commands are specified separately in a WoolReply.

    The body contains a statement as a list of segments where each segment is one of:

    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:

    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.

    • Constructor Detail

      • WoolNodeBody

        public WoolNodeBody()
    • Method Detail

      • getSegments

        public List<WoolNodeBody.Segment> getSegments()
        Returns the segments as an unmodifiable list.
        Returns:
        the segments as an unmodifiable list
      • clearSegments

        public void clearSegments()
      • 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
      • 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 map
        trimText - 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()