Class XsdTreeNode

java.lang.Object
org.djutils.event.LocalEventProducer
org.opentrafficsim.editor.XsdTreeNode
All Implemented Interfaces:
Serializable, Remote, org.djutils.event.EventProducer
Direct Known Subclasses:
XsdTreeNodeRoot

public class XsdTreeNode extends org.djutils.event.LocalEventProducer implements Serializable
Underlying data structure object of the editor. Starting with the root node "Ots", all the information is stored in a tree. The tree follows the XSD logic, e.g. "Ots.Network.Link". XsdTreeNode's have a Node object from the XSD DOM tree. From this information it can be derived what the child nodes should be, and which attributes are contained.

This class is mostly straightforward in the sense that there are direct parent-child relations, and that changing an option replaces a node. When an xsd:sequence is part of an xsd:choice or xsd:all, things become complex as the xsd:sequence is a single option. Therefore the xsd:sequence becomes a node visible in the tree, when it's an option under a choice. Furthermore, for each xsd:choice or xsd:all node an XsdTreeNode is created that is not visible in the tree. It stores all options XsdTreeNode's and knows what option is selected. Only one options is ever in the list of children of the parent node.

Copyright (c) 2023-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.

Author:
Wouter Schakel
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final org.djutils.event.EventType
    Event when an option is changed.
    (package private) boolean
    Whether the node is active.
    static final org.djutils.event.EventType
    Event when an attribute value is changed.
    (package private) List<XsdTreeNode>
    Children nodes.
    (package private) XsdTreeNode
    Choice node, represents an xsd:choice of which 1 option is shown.
    static final org.djutils.event.EventType
    Event when a node is moved.
    static final org.djutils.event.EventType
    Event when an option is changed.
    (package private) List<XsdTreeNode>
    Option nodes.
    (package private) XsdTreeNode
    Parent node.
    (package private) Node
    Element defining node that referred to a type.
    (package private) XsdTreeNode
    Currently selection option in the choice node.
    static final org.djutils.event.EventType
    Event when a node value is changed.
    (package private) Node
    Node from XSD that this XsdTreeNode represents.

    Fields inherited from interface org.djutils.event.EventProducer

    FIRST_POSITION, LAST_POSITION
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Constructor for root node, based on an XsdSchema.
    (package private)
    XsdTreeNode(XsdTreeNode parent, Node xsdNode, org.djutils.immutablecollections.ImmutableList<Node> hiddenNodes)
    Construct a node without referring node.
    (package private)
    XsdTreeNode(XsdTreeNode parent, Node xsdNode, org.djutils.immutablecollections.ImmutableList<Node> hiddenNodes, Node referringXsdNode)
    Constructor with referring node for extended types.
  • Method Summary

    Modifier and Type
    Method
    Description
    add()
    Adds a node of similar type next to this node under the parent.
    void
    Adds a validator for the value of an attribute.
    void
    addAttributeValidator(String attribute, ValueValidator validator, Object field)
    Adds a validator for the value of an attribute.
    void
    addConsumer(String menuItem, Consumer<XsdTreeNode> consumer)
    A consumer can be set externally and will receive this node when its menu item is selected.
    boolean
    addListener(org.djutils.event.EventListener listener, org.djutils.event.EventType eventType)
    void
    Adds a validator for the node.
    void
    Adds a validator for the value.
    protected void
    Assures children are present.
    int
    Returns the number of attributes; directly for an XsdAttributesTableModel.
    boolean
    Returns whether the attribute is an expression.
    boolean
    Returns whether this node can contain the information of the given node.
    boolean
    Returns whether the node can be moved down in the parent.
    boolean
    Returns whether the node can be moved up in the parent.
    void
    consume(String menuItem)
    Triggers the node to be consumed.
    void
    Copies the active status, value, choice, attributes and children of this node in to the given node.
    (package private) void
    Creates the option nodes as part of an xsd:choice or xsd:all node.
    Creates a full copy of this node, next to this node under the same parent.
    Duplicates this node, but under the given parent node.
    Creates an empty copy of this node, i.e. without children, options, attributes.
    Returns the base type of the attribute, e.g. xsd:double.
    int
    Returns the index of the named attribute.
    Returns the name of the indexed attribute.
    getAttributeNode(int index)
    Returns the attributes at given index; directly for an XsdAttributesTableModel.
    Returns all restrictions for the given attribute.
    getAttributeValue(int index)
    Returns an attribute value; directly for an XsdAttributesTableModel.
    Returns the value of an attribute.
    getChild(int index)
    Returns the child at given index; directly for an XsdTreeTableModel.
    int
    Returns the number of children; directly for an XsdTreeTableModel.
    Returns a list of the child nodes.
    Returns the menu items for which this node has consumers.
    Returns the node to which an attribute refers via a KeyValidator.
    Returns the node to which an attribute refers via a KeyValidator.
    Returns the node to which the value refers via a KeyValidator.
    Returns the default value for the attribute.
    Returns the description of this node.
    Returns the first child with given name.
    Returns the value of an attribute with name "Id".
    Returns all restrictions for Id attribute.
    Returns the name of this node, as appropriate in XML.
    Returns the selected option.
    Returns a list of options.
    Returns the parent node.
    Returns the path from root to this node.
    Returns the path string of this element, e.g.
    Returns the root node.
    Returns a string that is the name of the node, without any additional information on id and additional string function.
    Returns the value of this node.
    Returns all restrictions for the value.
    boolean
    hasAttribute(String attribute)
    Returns whether this node has an attribute with given name.
    boolean
    Returns whether this node has any consumers.
    boolean
    Returns whether the value, any of the attributes, or any of the sub-elements, has an expression.
    boolean
    Returns whether the Id is an expression.
    void
    Sets the valid status of this node and all parent nodes to unknown.
    (package private) void
    Invalidates entire tree in a nested manner.
    boolean
    Returns whether the node is active.
    boolean
    Returns whether a node of the same type may be added next to this node under the parent.
    boolean
    Returns whether this node is (part of) a choice, i.e. should show an option can be set here.
    boolean
    Returns whether this node is editable; i.e. whether a value can be set on the node, i.e. has a simple value, e.g.
    boolean
    Returns whether this node has an attribute named "Id".
    boolean
    Returns whether this node exists as its loaded from an include.
    boolean
    Returns whether this node may be removed without violating "minOccurs" constraints.
    boolean
    Returns whether the contents of the attributes, value and other aspects of the node itself are valid.
    boolean
    isType(String path)
    Returns whether this node is of the type defined by the path.
    boolean
    Returns whether the node, and all its children recursively, is valid.
    protected void
    loadChildren(List<Integer> indices, NodeList childrenXml, boolean loadingSubSequence)
    Parses child nodes from XML in to this node's children, as far as it can given available inactive child nodes.
    void
    loadXmlNodes(Node nodeXml)
    Parses the information from an XML node into this node.
    int
    Returns the maximum number of this element under the parent node, as defined in maxOccurs in XSD.
    int
    Returns the minimum number of this element under the parent node, as defined in minOccurs in XSD.
    void
    move(int down)
    Move the node to a different position in the parent, relative to the current position.
    final void
    Removes this node from the tree structure.
    Returns a message why the attribute value is invalid, or null if it is valid.
    Returns a message why the id is invalid, or null if it is valid.
    Returns a message why the node is invalid, or null if it is valid.
    Returns a message why the value is invalid, or null if it is valid.
    void
    saveXmlNodes(Document document, Node xmlParent)
    Saves the content of this node in a new XML element under the given XML parent.
    void
    Sets this node to be active if it is not already.
    void
    setAttributeValue(int index, String value)
    Sets an attribute value; directly for an XsdAttributesTableModel.
    void
    Sets an attribute value; directly for an XsdAttributesTableModel.
    void
    setChild(int index, XsdTreeNode child)
    Sets the given node as child of this node.
    void
    Sets the value for an attribute with name "Id".
    void
    Deactivates this node.
    void
    Sets the node as newly selected option.
    void
    setStringFunction(Function<XsdTreeNode,String> stringFunction, boolean overwrite)
    This function can be set externally and supplies an additional String to clarify this node in the tree.
    void
    Sets the value on this node.
    Returns the short string, appended with any additional information on id and additional string function.
    boolean
    Returns whether the value is an expression.

    Methods inherited from class org.djutils.event.LocalEventProducer

    addListener, addListener, addListener, fireEvent, fireEvent, fireEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, getEventListenerMap, getEventTypesWithListeners, getListenerReferences, hasListeners, numberOfListeners, removeAllListeners, removeAllListeners, removeListener

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • VALUE_CHANGED

      public static final org.djutils.event.EventType VALUE_CHANGED
      Event when a node value is changed.
    • ATTRIBUTE_CHANGED

      public static final org.djutils.event.EventType ATTRIBUTE_CHANGED
      Event when an attribute value is changed.
    • OPTION_CHANGED

      public static final org.djutils.event.EventType OPTION_CHANGED
      Event when an option is changed.
    • ACTIVATION_CHANGED

      public static final org.djutils.event.EventType ACTIVATION_CHANGED
      Event when an option is changed.
    • MOVED

      public static final org.djutils.event.EventType MOVED
      Event when a node is moved.
    • parent

      XsdTreeNode parent
      Parent node.
    • xsdNode

      Node xsdNode
      Node from XSD that this XsdTreeNode represents. Most typically an xsd:element node.
    • referringXsdNode

      Node referringXsdNode
      Element defining node that referred to a type. The type is defined by .xsdNode, the referring node is used for original information on name and occurrence. For simple element nodes this is null.
    • choice

      XsdTreeNode choice
      Choice node, represents an xsd:choice of which 1 option is shown. All options are XsdTreeNode's themselves.
    • options

      List<XsdTreeNode> options
      Option nodes. These can be directly applicable in the tree, or they can represent an xsd:sequence.
    • selected

      XsdTreeNode selected
      Currently selection option in the choice node.
    • children

      List<XsdTreeNode> children
      Children nodes.
    • active

      boolean active
      Whether the node is active. Inactive nodes show the user what type of node can be created in its place.
  • Constructor Details

    • XsdTreeNode

      protected XsdTreeNode(Schema schema)
      Constructor for root node, based on an XsdSchema. Note: XsdTreeNodeRoot should be used for the root. The XsdSchema that will be available to all nodes in the tree.
      Parameters:
      schema - XsdSchema; XSD schema.
    • XsdTreeNode

      XsdTreeNode(XsdTreeNode parent, Node xsdNode, org.djutils.immutablecollections.ImmutableList<Node> hiddenNodes)
      Construct a node without referring node.
      Parameters:
      parent - XsdTreeNode; parent.
      xsdNode - Node; XSD node that this tree node represents.
      hiddenNodes - ImmutableList<Node>; nodes between the XSD node of the parent, and this tree node's XSD node.
    • XsdTreeNode

      XsdTreeNode(XsdTreeNode parent, Node xsdNode, org.djutils.immutablecollections.ImmutableList<Node> hiddenNodes, Node referringXsdNode)
      Constructor with referring node for extended types. If the node is xsd:choice or xsd:all, this node will represent the choice. All options are then created as separate XsdTreeNode's by this constructor. For each option that is an xsd:sequence, this constructor will also create the nodes in that sequence, as those nodes function on the child-level of this node. They are coupled to this choice by their parentChoice, allowing them to delete and add on this level.

      The hidden nodes are all elements between the parent element and this element. For example {xsd:complexType, xsd:choice} between the following child element and its containing object:
       <xsd:element name="OBJECT">
         <xsd:complexType>
           <xsd:choice>
             <xsd:element name="CHILD" />
           </xsd:choice>
         </xsd:complexType>
       </xsd:element>
       
      The hidden nodes will not include a referring node. For example the following "OBJECT" element will result in hidden nodes {xsd:complexType, xsd:sequence} and the referring node is the Node with the ref="OBJECT" attribute. The XsdTreeNode representing this element will itself wrap the node with name="OBJECT".
       <xsd:element name="PARENT">
         <xsd:complexType>
           <xsd:sequence>
             <xsd:element ref="OBJECT" />
           </xsd:sequence>
         </xsd:complexType>
       </xsd:element>
       
      Parameters:
      parent - XsdTreeNode; parent.
      xsdNode - Node; XSD node that this tree node represents.
      hiddenNodes - ImmutableList<Node>; nodes between the XSD node of the parent, and this tree node's XSD node.
      referringXsdNode - Node; original node that referred to Node through a ref={ref} or type={type} attribute, it is used for naming and occurrence, may be null if not applicable.
  • Method Details

    • getPath

      public List<XsdTreeNode> getPath()
      Returns the path from root to this node.
      Returns:
      List<XsdTreeNode>; list of node along the path.
    • getRoot

      public XsdTreeNodeRoot getRoot()
      Returns the root node.
      Returns:
      XsdTreeNodeRoot; root node.
    • getNodeName

      public String getNodeName()
      Returns the name of this node, as appropriate in XML. Examples are Node, RoadLayout, and TacticalPlanner. Most typically this is the "name" attribute of an xsd:element. In other cases it is the ref={ref} attribute of the referring Node. In rare cases it is "xi:include".
      Returns:
      String; name of this node, as appropriate in XML.
    • isChoice

      public boolean isChoice()
      Returns whether this node is (part of) a choice, i.e. should show an option can be set here.
      Returns:
      boolean; whether this node is (part of) a choice, i.e. should show an option can be set here.
    • getOptions

      public List<XsdOption> getOptions()
      Returns a list of options.
      Returns:
      List<XsdOption>; list of options.
    • setOption

      public void setOption(XsdTreeNode node)
      Sets the node as newly selected option. All current nodes from the choice set are removed from the parent node.
      Parameters:
      node - XsdTreeNode; newly selected node. Must be part of the choice that this node represents.
    • getOption

      public XsdTreeNode getOption()
      Returns the selected option.
      Returns:
      XsdTreeNode; selected option.
    • setChild

      public void setChild(int index, XsdTreeNode child)
      Sets the given node as child of this node.
      Parameters:
      index - int; index to insert the node.
      child - XsdTreeNode; child node.
    • createOptions

      void createOptions()
      Creates the option nodes as part of an xsd:choice or xsd:all node.
    • getChildCount

      public int getChildCount()
      Returns the number of children; directly for an XsdTreeTableModel.
      Returns:
      int; number of children.
    • getChild

      public XsdTreeNode getChild(int index)
      Returns the child at given index; directly for an XsdTreeTableModel.
      Parameters:
      index - int; child index.
      Returns:
      XsdTreeNode; child.
    • getFirstChild

      public XsdTreeNode getFirstChild(String name)
      Returns the first child with given name. The node may be within a series of xsd:sequence and xsd:choice/xsd:all intermediate nodes.
      Parameters:
      name - String; child name.
      Returns:
      XsdTreeNode; child.
    • getChildren

      public List<XsdTreeNode> getChildren()
      Returns a list of the child nodes.
      Returns:
      List<XsdTreeNode>; list of the child nodes; safe copy.
    • assureChildren

      protected void assureChildren()
      Assures children are present. If a child has minOccurs > 1, additional child nodes are added. Result is cached.
    • getParent

      public XsdTreeNode getParent()
      Returns the parent node.
      Returns:
      parent node, is null for the root.
    • attributeCount

      public int attributeCount()
      Returns the number of attributes; directly for an XsdAttributesTableModel.
      Returns:
      int; number of attributes.
    • getAttributeNode

      public Node getAttributeNode(int index)
      Returns the attributes at given index; directly for an XsdAttributesTableModel.
      Parameters:
      index - int; attribute index.
      Returns:
      Node; attribute node.
    • setAttributeValue

      public void setAttributeValue(int index, String value)
      Sets an attribute value; directly for an XsdAttributesTableModel.
      Parameters:
      index - int; index of the attribute.
      value - String; value of the attribute.
    • setAttributeValue

      public void setAttributeValue(String name, String value)
      Sets an attribute value; directly for an XsdAttributesTableModel.
      Parameters:
      name - String; name of the attribute.
      value - String; value of the attribute.
    • getAttributeValue

      public String getAttributeValue(int index)
      Returns an attribute value; directly for an XsdAttributesTableModel.
      Parameters:
      index - int; index of the attribute.
      Returns:
      String; value of the attribute.
    • getDefaultAttributeValue

      public String getDefaultAttributeValue(int index)
      Returns the default value for the attribute.
      Parameters:
      index - int; attribute index.
      Returns:
      String; default value for the attribute, or null if there is no default value.
    • getAttributeValue

      public String getAttributeValue(String attribute)
      Returns the value of an attribute.
      Parameters:
      attribute - String; name of the attribute.
      Returns:
      String; value of the attribute.
      Throws:
      IllegalStateException - when the node does not have the attribute.
    • getAttributeIndexByName

      public int getAttributeIndexByName(String attribute)
      Returns the index of the named attribute.
      Parameters:
      attribute - String; attribute name.
      Returns:
      int; index of the named attribute.
      Throws:
      NoSuchElementException - when the attribute is not in this node.
    • getAttributeNameByIndex

      public String getAttributeNameByIndex(int index)
      Returns the name of the indexed attribute.
      Parameters:
      index - int; attribute index.
      Returns:
      String; name of the indexed attribute.
    • hasAttribute

      public boolean hasAttribute(String attribute)
      Returns whether this node has an attribute with given name.
      Parameters:
      attribute - String; attribute name.
      Returns:
      boolean; whether this node has an attribute with given name.
    • isActive

      public boolean isActive()
      Returns whether the node is active. If not, it only exists to show the user what type of node may be created here, or as a choice option currently not chosen.
      Returns:
      boolean; whether the node is active.
    • setActive

      public void setActive()
      Sets this node to be active if it is not already. If this node is the selected node within a choice, it also activates all other options of the choice.
    • setInactive

      public void setInactive()
      Deactivates this node.
    • isIdentifiable

      public boolean isIdentifiable()
      Returns whether this node has an attribute named "Id".
      Returns:
      boolean; whether this node has an attribute named "Id".
    • setId

      public void setId(String id)
      Sets the value for an attribute with name "Id".
      Parameters:
      id - String; value to set.
    • getId

      public String getId()
      Returns the value of an attribute with name "Id".
      Returns:
      String; value of an attribute with name "Id".
    • isEditable

      public boolean isEditable()
      Returns whether this node is editable; i.e. whether a value can be set on the node, i.e. has a simple value, e.g. <Node>Simple value</Node>.
      Returns:
      boolean; whether this node is editable, i.e. whether a value can be set on the node.
    • isInclude

      public boolean isInclude()
      Returns whether this node exists as its loaded from an include.
      Returns:
      boolean; whether this node exists as its loaded from an include.
    • setValue

      public void setValue(String value)
      Sets the value on this node.
      Parameters:
      value - String; value to set.
    • getValue

      public String getValue()
      Returns the value of this node.
      Returns:
      String; value of this node.
    • isAddable

      public boolean isAddable()
      Returns whether a node of the same type may be added next to this node under the parent. This is based on maxOccurs.
      Returns:
      boolean; whether a node of the same type may be added next to this node under the parent.
    • add

      public XsdTreeNode add()
      Adds a node of similar type next to this node under the parent. If the node is a choice, the same selected option will be set in the added node. In this way the user sees that node option copied.
      Returns:
      XsdTreeNode; added node.
    • duplicate

      public XsdTreeNode duplicate()
      Creates a full copy of this node, next to this node under the same parent.
      Returns:
      XsdTreeNode; newly created node.
    • duplicate

      public XsdTreeNode duplicate(XsdTreeNode newParent)
      Duplicates this node, but under the given parent node.
      Parameters:
      newParent - XsdTreeNode; parent node.
      Returns:
      XsdTreeNode; newly created node.
    • emptyCopy

      public XsdTreeNode emptyCopy()
      Creates an empty copy of this node, i.e. without children, options, attributes.
      Returns:
      XsdTreeNode; empty copy.
    • copyInto

      public void copyInto(XsdTreeNode copyNode)
      Copies the active status, value, choice, attributes and children of this node in to the given node.
      Parameters:
      copyNode - XsdTreeNode; node to copy data in to.
    • isRemovable

      public boolean isRemovable()
      Returns whether this node may be removed without violating "minOccurs" constraints.
      Returns:
      boolean; whether this node may be removed without violating "minOccurs" constraints.
    • remove

      public final void remove()
      Removes this node from the tree structure. For nodes with minOccurs = 0 that are the last of their type in the context of their parent, the node is deactivated rather than removed. This method also explicitly removes all children nodes recursively. If the node is part of a sequence that is an option in a parentChoice, the node is removed from there.
    • canMoveUp

      public boolean canMoveUp()
      Returns whether the node can be moved up in the parent.
      Returns:
      boolean; whether the node can be moved up in the parent.
    • canMoveDown

      public boolean canMoveDown()
      Returns whether the node can be moved down in the parent.
      Returns:
      boolean; whether the node can be moved down in the parent.
    • move

      public void move(int down)
      Move the node to a different position in the parent, relative to the current position.
      Parameters:
      down - int; number of moves down. May be negative for up.
    • minOccurs

      public int minOccurs()
      Returns the minimum number of this element under the parent node, as defined in minOccurs in XSD.
      Returns:
      int; minimum number of this element under the parent node, as defined in minOccurs in XSD.
    • maxOccurs

      public int maxOccurs()
      Returns the maximum number of this element under the parent node, as defined in maxOccurs in XSD. The XSD value "unbounded" results in a value of -1.
      Returns:
      int; maximum number of this element under the parent node, as defined in maxOccurs in XSD.
    • getPathString

      public String getPathString()
      Returns the path string of this element, e.g. "Ots.Definitions.RoadLayouts". This is used to identify each unique type of element.
      Returns:
      String; path string of this element, e.g. "Ots.Definitions.RoadLayouts".
    • isSelfValid

      public boolean isSelfValid()
      Returns whether the contents of the attributes, value and other aspects of the node itself are valid. This excludes child nodes.
      Returns:
      whether the contents of the attributes, value and other aspects of the node itself are valid.
    • isValid

      public boolean isValid()
      Returns whether the node, and all its children recursively, is valid. This means all required values are supplied, and all supplied values comply to their respective types and constraints.
      Returns:
      boolean; whether the node is valid.
    • invalidate

      public void invalidate()
      Sets the valid status of this node and all parent nodes to unknown.
    • invalidateAll

      void invalidateAll(XsdTreeNode node)
      Invalidates entire tree in a nested manner. Triggered after the path of the current file changes in the root node.
      Parameters:
      node - XsdTreeNode; node to nest through.
    • hasExpression

      public boolean hasExpression()
      Returns whether the value, any of the attributes, or any of the sub-elements, has an expression.
      Returns:
      boolean; whether the node has an expression.
    • valueIsExpression

      public boolean valueIsExpression()
      Returns whether the value is an expression.
      Returns:
      boolean; whether the value is an expression.
    • attributeIsExpression

      public boolean attributeIsExpression(int index)
      Returns whether the attribute is an expression.
      Parameters:
      index - int; attribute index.
      Returns:
      boolean; whether the attribute is an expression.
    • idIsExpression

      public boolean idIsExpression()
      Returns whether the Id is an expression.
      Returns:
      boolean; whether the Id is an expression.
    • addNodeValidator

      public void addNodeValidator(Function<XsdTreeNode,String> validator)
      Adds a validator for the node.
      Parameters:
      validator - Function<XsdTreeNode, String>; validator.
    • addValueValidator

      public void addValueValidator(ValueValidator validator, Object field)
      Adds a validator for the value.
      Parameters:
      validator - ValueValidator; validator.
      field - Object; field.
    • addAttributeValidator

      public void addAttributeValidator(String attribute, ValueValidator validator)
      Adds a validator for the value of an attribute.
      Parameters:
      attribute - String; attribute name.
      validator - ValueValidator; validator.
    • addAttributeValidator

      public void addAttributeValidator(String attribute, ValueValidator validator, Object field)
      Adds a validator for the value of an attribute. The field object is any object that is returned to the validator in its getOptions() method, such that it can know for which field option values should be given.
      Parameters:
      attribute - String; attribute name.
      validator - ValueValidator; validator.
      field - Object; field.
    • reportInvalidId

      public String reportInvalidId()
      Returns a message why the id is invalid, or null if it is valid. This should only be used to determine a GUI indication on an invalid Id. For other cases processing the attributes includes the Id.
      Returns:
      String; message why the id is invalid, or null if it is valid.
    • reportInvalidNode

      public String reportInvalidNode()
      Returns a message why the node is invalid, or null if it is valid. This only concerns validators on node level, i.e. not on attribute or value level. E.g. because the node is duplicate in its parent.
      Returns:
      String; message why the id is invalid, or null if it is valid.
    • reportInvalidValue

      public String reportInvalidValue()
      Returns a message why the value is invalid, or null if it is valid.
      Returns:
      String; message why the value is invalid, or null if it is valid.
    • reportInvalidAttributeValue

      public String reportInvalidAttributeValue(int index)
      Returns a message why the attribute value is invalid, or null if it is valid.
      Parameters:
      index - int; index of the attribute.
      Returns:
      String; message why the attribute value is invalid, or null if it is valid.
    • getValueRestrictions

      public List<String> getValueRestrictions()
      Returns all restrictions for the value. These are not sorted and may contain duplicates.
      Returns:
      List<String>; list of restrictions for the value.
    • getAttributeRestrictions

      public List<String> getAttributeRestrictions(int index)
      Returns all restrictions for the given attribute. These are not sorted and may contain duplicates.
      Parameters:
      index - int; attribute number.
      Returns:
      List<String>; list of restrictions for the attribute.
    • getCoupledKeyrefNodeAttribute

      public XsdTreeNode getCoupledKeyrefNodeAttribute(int index)
      Returns the node to which an attribute refers via a KeyValidator.
      Parameters:
      index - int; index of the attribute.
      Returns:
      XsdTreeNode; node to which an attribute refers via a KeyValidator, or null if no such node.
    • getCoupledKeyrefNodeAttribute

      public XsdTreeNode getCoupledKeyrefNodeAttribute(String attribute)
      Returns the node to which an attribute refers via a KeyValidator.
      Parameters:
      attribute - String; attribute name.
      Returns:
      XsdTreeNode; node to which an attribute refers via a KeyValidator, or null if no such node.
    • getCoupledKeyrefNodeValue

      public XsdTreeNode getCoupledKeyrefNodeValue()
      Returns the node to which the value refers via a KeyValidator.
      Returns:
      XsdTreeNode; node to which the value refers via a KeyValidator, or null if no such node.
    • getIdRestrictions

      public List<String> getIdRestrictions()
      Returns all restrictions for Id attribute. These are not sorted and may contain duplicates. Id restrictions may be valid if the Id field point to another element.
      Returns:
      List<String>; list of restrictions for the Id.
    • getAttributeBaseType

      public String getAttributeBaseType(int index)
      Returns the base type of the attribute, e.g. xsd:double.
      Parameters:
      index - int; attribute index.
      Returns:
      String; base type of the attribute, e.g. xsd:double.
    • isType

      public boolean isType(String path)
      Returns whether this node is of the type defined by the path.
      Parameters:
      path - String; path of the type in dotted xpath notation, e.g. "SignalGroup.TrafficLight".
      Returns:
      boolean; whether this node is of the type defined by the path.
    • canContain

      public boolean canContain(XsdTreeNode copied)
      Returns whether this node can contain the information of the given node. This only check equivalence of the underlying XSD node. The referring node may be different, as two elements may refer to the same type.
      Parameters:
      copied - XsdTreeNode; node that was copied, and may be pasted/inserted here.
      Returns:
      boolean; whether this node can contain the information of the given node.
    • setStringFunction

      public void setStringFunction(Function<XsdTreeNode,String> stringFunction, boolean overwrite)
      This function can be set externally and supplies an additional String to clarify this node in the tree.
      Parameters:
      stringFunction - Function<XsdTreeNode, String> string function.
      overwrite - boolean; overwrite existing. When true, a possible existing string function is overwritten.
    • addConsumer

      public void addConsumer(String menuItem, Consumer<XsdTreeNode> consumer)
      A consumer can be set externally and will receive this node when its menu item is selected.
      Parameters:
      menuItem - String; name of item as presented to the user.
      consumer - Consumer<XsdTreeNode>; editor.
    • hasConsumer

      public boolean hasConsumer()
      Returns whether this node has any consumers.
      Returns:
      boolean; whether this node has any consumers.
    • getDescription

      public String getDescription()
      Returns the description of this node.
      Returns:
      String; description of this node, null if there is none.
    • getConsumerMenuItems

      public Set<String> getConsumerMenuItems()
      Returns the menu items for which this node has consumers.
      Returns:
      Set<String>; menu items for which this node has consumers.
    • consume

      public void consume(String menuItem)
      Triggers the node to be consumed.
      Parameters:
      menuItem - String; menu item.
    • getShortString

      public String getShortString()
      Returns a string that is the name of the node, without any additional information on id and additional string function.
      Returns:
      String; string that is the name of the node.
    • toString

      public String toString()
      Returns the short string, appended with any additional information on id and additional string function.
      Overrides:
      toString in class Object
      Returns:
      String; short string, appended with any additional information on id and additional string function.
    • saveXmlNodes

      public void saveXmlNodes(Document document, Node xmlParent)
      Saves the content of this node in a new XML element under the given XML parent. This involves a value, attributes, and children. Children are further saved in a recursive manner. If this node is not active, this method does nothing.

      If this node represents a sequence as a choice option, all children are saved directly under the given XML parent node, and no information of this node itself is saved (as such nodes have no attributes or value). In other words, in that case this node is only a virtual layer presented to the user, but does not result in a layer in XML.
      Parameters:
      document - Document; used to create the new XML node.
      xmlParent - Node; parent XML node.
    • loadXmlNodes

      public void loadXmlNodes(Node nodeXml)
      Parses the information from an XML node into this node. This entails a tag value, attributes, and children, for as far as each of these is present. In a recursive manner, all child nodes are further loaded.
      Parameters:
      nodeXml - Node; node from XML.
    • loadChildren

      protected void loadChildren(List<Integer> indices, NodeList childrenXml, boolean loadingSubSequence)
      Parses child nodes from XML in to this node's children, as far as it can given available inactive child nodes. Note that these child nodes are derived from the XSD schema. This method will first find a relevant node to load each child XML node into. The relevant node can be found in two ways:
      1. The previous child node is relevant for the XML child node. This happens when XML specifies multiple nodes of the same type, in a sequence or choice with multiple occurrence. The previous child node will be added, such that information of the XML child node can be loaded in to the added child node.
      2. We move to the next child node until we find a node that is relevant for the XML child node. This should only skip inactive nodes for which XML specifies no information.
      Next, the information from XML is loaded in to the relevant child node. This can happen in three ways:
      1. The relevant node is not a choice, information is loaded in to it with loadXmlNodes.
      2. The relevant node is a choice, where the relevant option is not a sequence. The option will be set in the choice. Information is loaded in to the selected option with loadXmlNodes.
      3. The relevant node is a choice, where the relevant option is a sequence. The option (sequence node) will be set in the choice. The relevant child in the sequence is found, and all XML child nodes that can be loaded in to it, are by calling loadChildren.
      Note that for case 3, the child content of a deeper XsdChildNode is defined at the same level in XML. Hence, only some of the XML children may be loaded in the deeper level. To keep track of which XML child nodes are loaded where, the value indices[0] is given as input (previous nodes have already been loaded at a higher level or in another choice sequence). In this value also the index of the first XML child node that could not be loaded in the choice sequence is returned.

      The parameter indices is also used when an XML node cannot be loaded at all because it does not comply with the XSD schema. This will cause the loading to run through all children to see whether it can be loaded there. The second value indices[1] is used as input to know where to continue in a second call to this method after an earlier call came across an XML node that could not be loaded. In indices[1] the index of the last child node in to which XML data was loaded is given.
      Parameters:
      indices - List<Integer>; index of the first XML child node to load, and first XsdTreeNode index to use.
      childrenXml - NodeList; list of XML child nodes as specified within one parent XML tag.
      loadingSubSequence - boolean; whether this call is loading children as a sub-sequence.
    • addListener

      public boolean addListener(org.djutils.event.EventListener listener, org.djutils.event.EventType eventType)
      Specified by:
      addListener in interface org.djutils.event.EventProducer
      Overrides:
      addListener in class org.djutils.event.LocalEventProducer