Package org.opentrafficsim.editor
Class XsdTreeNodeUtil
java.lang.Object
org.opentrafficsim.editor.XsdTreeNodeUtil
This class exists to keep
XsdTreeNode
at manageable size. It houses all static methods used in XsdTreeNode
.
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
-
Method Summary
Modifier and TypeMethodDescription(package private) static void
addChildren
(Node node, XsdTreeNode parentNode, List<XsdTreeNode> children, org.djutils.immutablecollections.ImmutableList<Node> hiddenNodes, Schema schema, boolean flattenSequence, int skip) Main expansion algorithm.static void
addXsdAllValidator
(XsdTreeNode shared, XsdTreeNode node) Add xsd all validator to the given node.(package private) static org.djutils.immutablecollections.ImmutableList<Node>
Returns a copy of the input list, with the extra node appended at the end.protected static void
fireCreatedEventOnExistingNodes
(XsdTreeNode node, org.djutils.event.EventListener listener) Recursively throws creation events for all current nodes in the tree.(package private) static int
Parses the minOcccurs or maxOccurs value from given node.getOptionsFromRestrictions
(List<Node> restrictions) Returns a list of options derived from a list of restrictions (xsd:restriction).getRelevantNodesWithChildren
(Node node, org.djutils.immutablecollections.ImmutableList<Node> hiddenNodes, Schema schema) Returns from the XSD definition the appropriate nodes to take children from at the level of the input node, in the order in which they should appear.(package private) static boolean
haveSameType
(XsdTreeNode node1, XsdTreeNode node2) Returns whether nodes are of the same type.(package private) static Node
Returns the element referred to by ref={ref} in an xsd:element.(package private) static int
resolveInsertion
(int insertIndex, int removeIndex) Takes the minimum of both indices, while ignoring negative values (indicating an element was not found for deletion).(package private) static String
separatedName
(String name) Adds a thin space before each capital character in aString
, except the first.(package private) static Node
Returns the element referred to by type={type} in an xsd:element.static boolean
valuesAreEqual
(String value1, String value2) Returns whether the two values are equal, wherenull
is consider equal to an empty string.
-
Method Details
-
addXsdAllValidator
Add xsd all validator to the given node.- Parameters:
shared
- XsdTreeNode; shared xsd:all node.node
- XsdTreeNode; xsd:all node, or one of its children.
-
getOccurs
Parses the minOcccurs or maxOccurs value from given node. If it is not supplied, the default of 1 is given.- Parameters:
node
- Node; node.attribute
- String; "minOccurs" or "maxOccurs".- Returns:
- int; value of occurs, -1 represents "unbounded".
-
addChildren
static void addChildren(Node node, XsdTreeNode parentNode, List<XsdTreeNode> children, org.djutils.immutablecollections.ImmutableList<Node> hiddenNodes, Schema schema, boolean flattenSequence, int skip) Main expansion algorithm. Loops all child XSD nodes, and selects those that define next elements.- Parameters:
node
- Node; node to get the children of.parentNode
- XsdTreeNode; parent node for the created children.children
- List<XsdTreeNode>; list to add the children to. This may be different fromparentNode.children
due to layered choice structures.hiddenNodes
- ImmutableList<Node>; nodes between the XSD node of the parent, and this tree node's XSD node.schema
- XsdSchema; schema to get types and referred elements from.flattenSequence
- boolean; when true, treats an xsd:sequence child as an extension of the node. In the context of a choice this should remain separated.skip
- int; child index to skip, this is used when copying choice options from an option that is already created.
-
append
static org.djutils.immutablecollections.ImmutableList<Node> append(org.djutils.immutablecollections.ImmutableList<Node> hiddenNodes, Node node) Returns a copy of the input list, with the extra node appended at the end.- Parameters:
hiddenNodes
- ImmutableList<Node>; hidden nodes list.node
- Node; node to append.- Returns:
- ImmutableList<Node>; copy of the input list, with the extra node appended at the end.
-
getOptionsFromRestrictions
Returns a list of options derived from a list of restrictions (xsd:restriction).- Parameters:
restrictions
- List<Node>; list of restrictions.- Returns:
- List<String>; list of options.
-
fireCreatedEventOnExistingNodes
protected static void fireCreatedEventOnExistingNodes(XsdTreeNode node, org.djutils.event.EventListener listener) throws RemoteException Recursively throws creation events for all current nodes in the tree. This method is forXsdTreeNodeRoot
.- Parameters:
node
- XsdTreeNode; node.listener
- EventListener; listener.- Throws:
RemoteException
- if event cannot be fired.
-
resolveInsertion
static int resolveInsertion(int insertIndex, int removeIndex) Takes the minimum of both indices, while ignoring negative values (indicating an element was not found for deletion).- Parameters:
insertIndex
- int; previously determined insertion index; may be updated to lower value.removeIndex
- int; index of element that is removed.- Returns:
- int; minimum of both indices, while ignoring negative values.
-
getRelevantNodesWithChildren
static Map<Node,org.djutils.immutablecollections.ImmutableList<Node>> getRelevantNodesWithChildren(Node node, org.djutils.immutablecollections.ImmutableList<Node> hiddenNodes, Schema schema) Returns from the XSD definition the appropriate nodes to take children from at the level of the input node, in the order in which they should appear. This is often the xsd:complexType within an xsd:element, but can become as complex as containing multiple xsd:extension and their referred base types. An xsd:sequence is also common. Adding children in the order as they appear perNode
, and in the order theNode
's are given, results in an overall order suitable for XML.- Parameters:
node
- Node; node to expand further.hiddenNodes
- ImmutableList<Node>; nodes between the XSD node of the parent, and this tree node's XSD node.schema
- XsdSchema; schema to retrieve types.- Returns:
- Map<Node, ImmutableList<Node>>; map of nodes containing relevant children at the level of the input node, and their appropriate hidden nodes.
-
haveSameType
Returns whether nodes are of the same type. This regards the referring XSD node if it exists, otherwise it regards the regular XSD node.- Parameters:
node1
- XsdTreeNode; node 1.node2
- XsdTreeNode; node 1.- Returns:
- boolean; whether nodes are of the same type.
-
ref
Returns the element referred to by ref={ref} in an xsd:element. Will returnXiIncludeNode.XI_INCLUDE
for xi:include.- Parameters:
node
- Node; node, must have ref={ref} attribute.ref
- String; value of ref={ref}.schema
- XsdSchema; schema to take element from.- Returns:
- Node; element referred to by ref={ref} in an xsd:element.
-
type
Returns the element referred to by type={type} in an xsd:element. Ignores all types starting with "xsd:" as these are standard types to which user input can be validated directly.- Parameters:
node
- Node; node, must have type={type} attribute.type
- String; value of type={type}.schema
- XsdSchema; schema to take type from.- Returns:
- Node; element referred to by type={type} in an xsd:element.
-
separatedName
Adds a thin space before each capital character in aString
, except the first.- Parameters:
name
- String; name of node.- Returns:
- String; input string but with a thin space before each capital character, except the first.
-
valuesAreEqual
Returns whether the two values are equal, wherenull
is consider equal to an empty string.- Parameters:
value1
- String; value 1.value2
- String; value 2.- Returns:
- whether the two values are equal, where
null
is consider equal to an empty string.
-