stella.xml
Class DOMSequence.TaskElement

java.lang.Object
  extended by stella.xml.DOMSequence.TaskElement
Enclosing class:
DOMSequence

public class DOMSequence.TaskElement
extends Object

Represents a special Element, namely a Task element in an xml-sequencer file. Provides methods to querry special properties of a task element. Set methods are directly bound to the underlying Element and hence change the Element in the parental document.


Field Summary
private  Element anchor
           
 
Constructor Summary
protected DOMSequence.TaskElement(Element src)
          Constructs a new task element from an element.
 
Method Summary
private  String[] extractAll(NodeList list)
          Returns a string array of all first child nodes of the nodes found in the list.
 String[] getCommand()
          Returns all command templates tied to this task.
private  String getCommandAttribute(String template, String att)
          Returns the value of the attribute of the given name within the command with the given template.
 String getCommandID(String template)
          Returns the command id-attribute linked to the command with argumental command template.
 String getCommandInit(String template)
          Returns the command initialization string.
 String getCommandParameter(String template)
          Returns all parameter names linked to the command element whose template name is equal to the argument.
 String getCommandRef(String template)
          Returns the command ref-attribute linked to the command with argumental command template.
private  String getCommandTemplate(Element command)
          Returns the command template specified in this command-element.
 String getComplete()
          Returns the complete condition tied to this task.
 String getCondition()
          Returns the condition of this task element.
 String[] getFalse()
          Returns all triggers by name that get false as tied to this task.
 String getID()
          Returns the value of the id attribute of this task element.
 Map<String,Object> getSet()
          Returns a map of parameter names to new parameter values.
private  NodeList getSub(String tag)
          Returns a node list of elements with the given tag name.
 String[] getTrue()
          Returns all triggers by name that get true as tied to this task.
 boolean isDone()
          Returns true if the value of the done attribute of this task element is true.
 boolean isSending()
          Returns true if the value of the done attribute of this task element is sending.
 void setCommand(String[] templates)
          Sets the command templates tied to this task.
private  void setCommandAttribute(String template, String att, String val)
          Adds or updates an attribute of the given name within the command with the given template.
 void setCommandID(String template, String id)
          Sets the command id-attribute linked to the command with argumental command template.
 void setCommandInit(String template, String init)
          Sets the command parameter-attribute linked to the command with the given template name.
 void setCommandParameter(String template, String parameter)
          Sets the command parameter-attribute linked to the command with the given template name.
 void setCommandRef(String template, String ref)
          Sets the command ref-attribute linked to the command with argumental command template.
 void setDone(boolean to)
          Sets the value of the done attribute.
 void setSending()
          Sets the value of the done attribute to DTDConstants.SENDING.
 String toString()
          String version of a task element is its ID plus info on done/sending status if applicable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

anchor

private Element anchor
Constructor Detail

DOMSequence.TaskElement

protected DOMSequence.TaskElement(Element src)
Constructs a new task element from an element. If the argument is not named according to DTDConstants.TASK an IllegalArgumentException is thrown.

Method Detail

getID

public String getID()
Returns the value of the id attribute of this task element. This is a required attribute and therefore always present.


isDone

public boolean isDone()
Returns true if the value of the done attribute of this task element is true.


isSending

public boolean isSending()
Returns true if the value of the done attribute of this task element is sending.


setDone

public void setDone(boolean to)
Sets the value of the done attribute. This method sets the attribute in the underlying DOM element and therefore alters the structure of the DOM.


setSending

public void setSending()
Sets the value of the done attribute to DTDConstants.SENDING. This method should be called after a condition is met, all the command templates have been extracted and sent to the devices. After this method has been called, further calls to getCommand() return null to indicate that no more commands have to be sent for this task.


getCondition

public String getCondition()
Returns the condition of this task element. The condition is used to allow issuing the commands of this task, if fulfilled.


getComplete

public String getComplete()
Returns the complete condition tied to this task.


getCommand

public String[] getCommand()
Returns all command templates tied to this task. If the status of the task element has been set to DTDConstants.SENDING (via the done attribute of the task), null is returned.


getCommandInit

public String getCommandInit(String template)
Returns the command initialization string. Used for rendering templates.


getCommandParameter

public String getCommandParameter(String template)
Returns all parameter names linked to the command element whose template name is equal to the argument.


getCommandID

public String getCommandID(String template)
Returns the command id-attribute linked to the command with argumental command template. If no id is present, null is returned.


getCommandRef

public String getCommandRef(String template)
Returns the command ref-attribute linked to the command with argumental command template. If no ref attribute is present, the id-atrribute is returned.


setCommandID

public void setCommandID(String template,
                         String id)
Sets the command id-attribute linked to the command with argumental command template.


setCommandRef

public void setCommandRef(String template,
                          String ref)
Sets the command ref-attribute linked to the command with argumental command template.


setCommandParameter

public void setCommandParameter(String template,
                                String parameter)
Sets the command parameter-attribute linked to the command with the given template name.


setCommandInit

public void setCommandInit(String template,
                           String init)
Sets the command parameter-attribute linked to the command with the given template name.


setCommand

public void setCommand(String[] templates)
Sets the command templates tied to this task. Changes the DOM-substructure. The number of new templates must be identical to the number of actual templates.


getTrue

public String[] getTrue()
Returns all triggers by name that get true as tied to this task.


getFalse

public String[] getFalse()
Returns all triggers by name that get false as tied to this task.


getSet

public Map<String,Object> getSet()
Returns a map of parameter names to new parameter values. This method scans for all DTDConstants.SET elements. Each DTDConstants.SET element has an attribute, DTDConstants.SETNAME, which is used as a parameter name, i.e. a key in the returned map. The first sub-text-node value of the set-element is used as the new parameter value, i.e. is the value matched to the key. If the DTDConstants.CLASS attribute is given, the value object is of the stated class, constructed with the text-value string.

Returns:
null, if no DTDConstants.SET elements is given.

toString

public String toString()
String version of a task element is its ID plus info on done/sending status if applicable.

Overrides:
toString in class Object

getCommandTemplate

private String getCommandTemplate(Element command)
Returns the command template specified in this command-element. Note that only the first (text) node found is used. The return value is trimmed.


getCommandAttribute

private String getCommandAttribute(String template,
                                   String att)
Returns the value of the attribute of the given name within the command with the given template. If the attribute is not present, null is returned.


setCommandAttribute

private void setCommandAttribute(String template,
                                 String att,
                                 String val)
Adds or updates an attribute of the given name within the command with the given template.

Parameters:
template - The command which attribute should be set.
att - The name of the attribute.
val - The new value of the attribute.

getSub

private NodeList getSub(String tag)
Returns a node list of elements with the given tag name.


extractAll

private String[] extractAll(NodeList list)
Returns a string array of all first child nodes of the nodes found in the list. This can only work if the node list consists of element nodes which have no attributes and a single text node as a child.