Package org.opentrafficsim.editor
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
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".
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'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
FieldsModifier and TypeFieldDescriptionstatic final org.djutils.event.EventTypeEvent when an option is changed.(package private) booleanWhether the node is active.static final org.djutils.event.EventTypeEvent when an attribute value is changed.(package private) List<XsdTreeNode>Children nodes.(package private) XsdTreeNodeChoice node, represents an xsd:choice of which 1 option is shown.static final org.djutils.event.EventTypeEvent when a node is moved.static final org.djutils.event.EventTypeEvent when an option is changed.(package private) List<XsdTreeNode>Option nodes.(package private) XsdTreeNodeParent node.(package private) NodeElement defining node that referred to a type.(package private) XsdTreeNodeCurrently selection option in the choice node.static final org.djutils.event.EventTypeEvent when a node value is changed.(package private) NodeNode from XSD that thisXsdTreeNoderepresents.Fields inherited from interface org.djutils.event.EventProducer
FIRST_POSITION, LAST_POSITION -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedXsdTreeNode(Schema schema) Constructor for root node, based on anXsdSchema.(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 TypeMethodDescriptionadd()Adds a node of similar type next to this node under the parent.voidaddAttributeValidator(String attribute, ValueValidator validator) Adds a validator for the value of an attribute.voidaddAttributeValidator(String attribute, ValueValidator validator, Object field) Adds a validator for the value of an attribute.voidaddConsumer(String menuItem, Consumer<XsdTreeNode> consumer) A consumer can be set externally and will receive this node when its menu item is selected.booleanaddListener(org.djutils.event.EventListener listener, org.djutils.event.EventType eventType) voidaddNodeValidator(Function<XsdTreeNode, String> validator) Adds a validator for the node.voidaddValueValidator(ValueValidator validator, Object field) Adds a validator for the value.protected voidAssures children are present.intReturns the number of attributes; directly for anXsdAttributesTableModel.booleanattributeIsExpression(int index) Returns whether the attribute is an expression.booleancanContain(XsdTreeNode copied) Returns whether this node can contain the information of the given node.booleanReturns whether the node can be moved down in the parent.booleanReturns whether the node can be moved up in the parent.voidTriggers the node to be consumed.voidcopyInto(XsdTreeNode copyNode) Copies the active status, value, choice, attributes and children of this node in to the given node.(package private) voidCreates 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.duplicate(XsdTreeNode newParent) Duplicates this node, but under the given parent node.Creates an empty copy of this node, i.e. without children, options, attributes.getAttributeBaseType(int index) Returns the base type of the attribute, e.g. xsd:double.intgetAttributeIndexByName(String attribute) Returns the index of the named attribute.getAttributeNameByIndex(int index) Returns the name of the indexed attribute.getAttributeNode(int index) Returns the attributes at given index; directly for anXsdAttributesTableModel.getAttributeRestrictions(int index) Returns all restrictions for the given attribute.getAttributeValue(int index) Returns an attribute value; directly for anXsdAttributesTableModel.getAttributeValue(String attribute) Returns the value of an attribute.getChild(int index) Returns the child at given index; directly for anXsdTreeTableModel.intReturns the number of children; directly for anXsdTreeTableModel.Returns a list of the child nodes.Returns the menu items for which this node has consumers.getCoupledKeyrefNodeAttribute(int index) Returns the node to which an attribute refers via a KeyValidator.getCoupledKeyrefNodeAttribute(String attribute) Returns the node to which an attribute refers via a KeyValidator.Returns the node to which the value refers via a KeyValidator.getDefaultAttributeValue(int index) Returns the default value for the attribute.Returns the description of this node.getFirstChild(String name) Returns the first child with given name.getId()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.getPath()Returns the path from root to this node.Returns the path string of this element, e.g.getRoot()Returns the root node.Returns a string that is the name of the node, without any additional information on id and additional string function.getValue()Returns the value of this node.Returns all restrictions for the value.booleanhasAttribute(String attribute) Returns whether this node has an attribute with given name.booleanReturns whether this node has any consumers.booleanReturns whether the value, any of the attributes, or any of the sub-elements, has an expression.booleanReturns whether the Id is an expression.voidSets the valid status of this node and all parent nodes to unknown.(package private) voidinvalidateAll(XsdTreeNode node) Invalidates entire tree in a nested manner.booleanisActive()Returns whether the node is active.booleanReturns whether a node of the same type may be added next to this node under the parent.booleanisChoice()Returns whether this node is (part of) a choice, i.e. should show an option can be set here.booleanReturns whether this node is editable; i.e. whether a value can be set on the node, i.e. has a simple value, e.g.booleanReturns whether this node has an attribute named "Id".booleanReturns whether this node exists as its loaded from an include.booleanReturns whether this node may be removed without violating "minOccurs" constraints.booleanReturns whether the contents of the attributes, value and other aspects of the node itself are valid.booleanReturns whether this node is of the type defined by the path.booleanisValid()Returns whether the node, and all its children recursively, is valid.protected voidloadChildren(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.voidloadXmlNodes(Node nodeXml) Parses the information from an XML node into this node.intReturns the maximum number of this element under the parent node, as defined in maxOccurs in XSD.intReturns the minimum number of this element under the parent node, as defined in minOccurs in XSD.voidmove(int down) Move the node to a different position in the parent, relative to the current position.final voidremove()Removes this node from the tree structure.reportInvalidAttributeValue(int index) Returns a message why the attribute value is invalid, ornullif it is valid.Returns a message why the id is invalid, ornullif it is valid.Returns a message why the node is invalid, ornullif it is valid.Returns a message why the value is invalid, ornullif it is valid.voidsaveXmlNodes(Document document, Node xmlParent) Saves the content of this node in a new XML element under the given XML parent.voidSets this node to be active if it is not already.voidsetAttributeValue(int index, String value) Sets an attribute value; directly for anXsdAttributesTableModel.voidsetAttributeValue(String name, String value) Sets an attribute value; directly for anXsdAttributesTableModel.voidsetChild(int index, XsdTreeNode child) Sets the given node as child of this node.voidSets the value for an attribute with name "Id".voidDeactivates this node.voidsetOption(XsdTreeNode node) Sets the node as newly selected option.voidsetStringFunction(Function<XsdTreeNode, String> stringFunction, boolean overwrite) This function can be set externally and supplies an additionalStringto clarify this node in the tree.voidSets the value on this node.toString()Returns the short string, appended with any additional information on id and additional string function.booleanReturns 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
-
Field Details
-
VALUE_CHANGED
public static final org.djutils.event.EventType VALUE_CHANGEDEvent when a node value is changed. -
ATTRIBUTE_CHANGED
public static final org.djutils.event.EventType ATTRIBUTE_CHANGEDEvent when an attribute value is changed. -
OPTION_CHANGED
public static final org.djutils.event.EventType OPTION_CHANGEDEvent when an option is changed. -
ACTIVATION_CHANGED
public static final org.djutils.event.EventType ACTIVATION_CHANGEDEvent when an option is changed. -
MOVED
public static final org.djutils.event.EventType MOVEDEvent when a node is moved. -
parent
XsdTreeNode parentParent node. -
xsdNode
Node xsdNodeNode from XSD that thisXsdTreeNoderepresents. Most typically an xsd:element node. -
referringXsdNode
Node referringXsdNodeElement 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 isnull. -
choice
XsdTreeNode choiceChoice node, represents an xsd:choice of which 1 option is shown. All options areXsdTreeNode's themselves. -
options
List<XsdTreeNode> optionsOption nodes. These can be directly applicable in the tree, or they can represent an xsd:sequence. -
selected
XsdTreeNode selectedCurrently selection option in the choice node. -
children
List<XsdTreeNode> childrenChildren nodes. -
active
boolean activeWhether the node is active. Inactive nodes show the user what type of node can be created in its place.
-
-
Constructor Details
-
XsdTreeNode
Constructor for root node, based on anXsdSchema. Note:XsdTreeNodeRootshould be used for the root. TheXsdSchemathat 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 separateXsdTreeNode'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 theirparentChoice, 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 theNodewith the ref="OBJECT" attribute. TheXsdTreeNoderepresenting 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 toNodethrough a ref={ref} or type={type} attribute, it is used for naming and occurrence, may benullif not applicable.
-
-
Method Details
-
getPath
Returns the path from root to this node.- Returns:
- List<XsdTreeNode>; list of node along the path.
-
getRoot
Returns the root node.- Returns:
- XsdTreeNodeRoot; root node.
-
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 referringNode. 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
Returns a list of options.- Returns:
- List<XsdOption>; list of options.
-
setOption
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
Returns the selected option.- Returns:
- XsdTreeNode; selected option.
-
setChild
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 anXsdTreeTableModel.- Returns:
- int; number of children.
-
getChild
Returns the child at given index; directly for anXsdTreeTableModel.- Parameters:
index- int; child index.- Returns:
- XsdTreeNode; child.
-
getFirstChild
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
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
Returns the parent node.- Returns:
- parent node, is
nullfor the root.
-
attributeCount
public int attributeCount()Returns the number of attributes; directly for anXsdAttributesTableModel.- Returns:
- int; number of attributes.
-
getAttributeNode
Returns the attributes at given index; directly for anXsdAttributesTableModel.- Parameters:
index- int; attribute index.- Returns:
- Node; attribute node.
-
setAttributeValue
Sets an attribute value; directly for anXsdAttributesTableModel.- Parameters:
index- int; index of the attribute.value- String; value of the attribute.
-
setAttributeValue
Sets an attribute value; directly for anXsdAttributesTableModel.- Parameters:
name- String; name of the attribute.value- String; value of the attribute.
-
getAttributeValue
Returns an attribute value; directly for anXsdAttributesTableModel.- Parameters:
index- int; index of the attribute.- Returns:
- String; value of the attribute.
-
getDefaultAttributeValue
Returns the default value for the attribute.- Parameters:
index- int; attribute index.- Returns:
- String; default value for the attribute, or
nullif there is no default value.
-
getAttributeValue
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
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
Returns the name of the indexed attribute.- Parameters:
index- int; attribute index.- Returns:
- String; name of the indexed attribute.
-
hasAttribute
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
Sets the value for an attribute with name "Id".- Parameters:
id- String; value to set.
-
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
Sets the value on this node.- Parameters:
value- String; value to set.
-
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
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
Creates a full copy of this node, next to this node under the same parent.- Returns:
- XsdTreeNode; newly created node.
-
duplicate
Duplicates this node, but under the given parent node.- Parameters:
newParent- XsdTreeNode; parent node.- Returns:
- XsdTreeNode; newly created node.
-
emptyCopy
Creates an empty copy of this node, i.e. without children, options, attributes.- Returns:
- XsdTreeNode; empty copy.
-
copyInto
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 aparentChoice, 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
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
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
Adds a validator for the node.- Parameters:
validator- Function<XsdTreeNode, String>; validator.
-
addValueValidator
Adds a validator for the value.- Parameters:
validator- ValueValidator; validator.field- Object; field.
-
addAttributeValidator
Adds a validator for the value of an attribute.- Parameters:
attribute- String; attribute name.validator- ValueValidator; validator.
-
addAttributeValidator
Adds a validator for the value of an attribute. The field object is any object that is returned to the validator in itsgetOptions()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
Returns a message why the id is invalid, ornullif 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
nullif it is valid.
-
reportInvalidNode
Returns a message why the node is invalid, ornullif 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
nullif it is valid.
-
reportInvalidValue
Returns a message why the value is invalid, ornullif it is valid.- Returns:
- String; message why the value is invalid, or
nullif it is valid.
-
reportInvalidAttributeValue
Returns a message why the attribute value is invalid, ornullif it is valid.- Parameters:
index- int; index of the attribute.- Returns:
- String; message why the attribute value is invalid, or
nullif it is valid.
-
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
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
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
nullif no such node.
-
getCoupledKeyrefNodeAttribute
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
nullif no such node.
-
getCoupledKeyrefNodeValue
Returns the node to which the value refers via a KeyValidator.- Returns:
- XsdTreeNode; node to which the value refers via a KeyValidator, or
nullif no such node.
-
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
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
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
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
This function can be set externally and supplies an additionalStringto clarify this node in the tree.- Parameters:
stringFunction- Function<XsdTreeNode, String> string function.overwrite- boolean; overwrite existing. Whentrue, a possible existing string function is overwritten.
-
addConsumer
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
Returns the description of this node.- Returns:
- String; description of this node,
nullif there is none.
-
getConsumerMenuItems
Returns the menu items for which this node has consumers.- Returns:
- Set<String>; menu items for which this node has consumers.
-
consume
Triggers the node to be consumed.- Parameters:
menuItem- String; menu item.
-
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
Returns the short string, appended with any additional information on id and additional string function. -
saveXmlNodes
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
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:- 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.
- 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.
- The relevant node is not a choice, information is loaded in to it with
loadXmlNodes. - 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. - 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.
XsdChildNodeis 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 valueindices[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 parameterindicesis 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 valueindices[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. Inindices[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:
addListenerin interfaceorg.djutils.event.EventProducer- Overrides:
addListenerin classorg.djutils.event.LocalEventProducer
-