TreeElement class final

A node of an instance: an element (or attribute) with a name, multiplicity, value or children, and model properties such as relevance.

Port of org.javarosa.core.model.instance.TreeElement. Instance trees are the engine's mutable state, so this class is mutable; its reference cache behaves exactly like JavaRosa's (expired by name, multiplicity and parent changes on this node only).

Available extensions

Constructors

TreeElement([String? _name, int _multiplicity = TreeReference.defaultMultiplicity, bool _isPartial = false])
Creates an element called name with multiplicity; a null name is only used for the hidden root above an instance's top element.
TreeElement.attribute(String? namespace, String name, String value)
An attribute node with value.

Properties

attributeCount → int
Number of attributes.
no setter
attributes → List<TreeElement>
The attribute nodes.
no setter
attributeValue → String?
This attribute node's value. Throws if this is not an attribute.
no setter
bindAttributes ↔ List<TreeElement>
The bind attributes not handled by the engine (e.g. odk:length).
getter/setter pair
children → List<TreeElement>
The children, in document order (including repeat templates).
no setter
constraint ↔ Object?
The bind constraint (a Constraint, ported with the dependency graph in P3).
getter/setter pair
dataType ↔ DataType
The data type declared by the bind (default DataType.nullType).
getter/setter pair
depth → int
Number of named ancestors including this element.
no setter
hasChildren → bool
Whether there is at least one child.
no setter
hashCode → int
The hash code for this object.
no setterinherited
instanceName ↔ String?
The secondary instance this element belongs to (null = main).
getter/setter pair
isAttribute → bool
Whether this node is an attribute.
no setter
isChildable → bool
Whether this element can have children (it has no value).
no setter
isEnabled → bool
Whether this element is enabled, including the inherited state.
no setter
isLeaf → bool
Whether this element has no children.
no setter
isPartial → bool
Whether this element is a placeholder whose children load later.
no setter
isRelevant ↔ bool
Whether this element is relevant, including inherited relevance.
getter/setter pair
isRepeatable ↔ bool
Whether this element is a repeat (or repeat template).
getter/setter pair
isRequired ↔ bool
Whether a value is required.
getter/setter pair
multiplicity ↔ int
Position among same-named siblings, or a TreeReference.index* sentinel (template, attribute).
getter/setter pair
name ↔ String?
The element name (null only for an instance's hidden root).
getter/setter pair
namespace ↔ String?
Namespace URI.
getter/setter pair
namespacePrefix ↔ String?
Namespace prefix, used to match names such as orx:meta.
getter/setter pair
numChildren → int
Number of children.
no setter
parent ↔ TreeElement?
The parent element, or null for the hidden root.
getter/setter pair
preloadHandler ↔ String?
The jr:preload handler name.
getter/setter pair
preloadParams ↔ String?
The jr:preloadParams value.
getter/setter pair
ref → TreeReference
The absolute reference to this element (cached).
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
selfAndDescendants → Iterable<TreeElement>
This element and all its descendants, depth first (replaces JavaRosa's accept(ITreeVisitor)).
no setter
value ↔ AnswerValue?
The value, or null when empty.
getter/setter pair

Methods

addChild(TreeElement child) → void
Adds child in multiplicity order, adopting it and propagating this element's relevance, enabled state and instance name.
addListener(TreeElementListener listener) → void
Registers listener for state changes (once).
childAt(int i) → TreeElement
The child at i.
childMultiplicity(String name) → int
Number of non-template children matching name.
childrenWithName(String name) → List<TreeElement>
All non-template children matching name (* matches all).
clearCaches() → void
Forgets the cached ref of this element.
clearChildren() → void
Removes all children.
clearChildrenCaches() → void
Forgets the cached refs of all descendants.
deepCopy({required bool includeTemplates}) → TreeElement
A deep copy, leaving out repeat templates unless includeTemplates.
firstChild(String name, {String? namespace}) → TreeElement?
The first child called name, if any.
getAttribute(String? namespace, String name) → TreeElement?
The attribute called name in namespace (any namespace if null).
getAttributeValue(String? namespace, String name) → String?
The value of attribute name in namespace, if present.
getBindAttribute(String? namespace, String name) → TreeElement?
The bind attribute name in namespace, if present.
getBindAttributeValue(String? namespace, String name) → String?
The value of bind attribute name in namespace, if present.
getChild(String name, int multiplicity) → TreeElement?
The child called name with multiplicity, if any. name may be * to address children by position.
insertChildAt(int index, TreeElement child) → void
Inserts child at index without adopting it.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
populate(TreeElement incoming, FormDef form, {AnswerResolver resolver = defaultAnswerResolver}) → void

Available on TreeElement, provided by the TreeElementPopulate extension

Fills this template node (and its subtree) from the saved node incoming: typed values, repeat instances, attributes; a missing non-repeat child becomes non-relevant. Port of TreeElement.populate.
populatePartial(TreeElement element) → void
Replaces a partial element's children with element's.
removeAllListeners() → void
Unregisters all listeners.
removeChild(TreeElement child) → void
Removes child.
removeChildAt(int i) → void
Removes the child at i.
removeChildNamed(String name, int multiplicity) → void
Removes the child called name with multiplicity, if any.
removeChildrenNamed(String name) → void
Removes all children called name.
removeListener(TreeElementListener listener) → void
Unregisters listener.
setAnswer(AnswerValue? answer) → bool
Sets the value and notifies listeners; returns false (and does nothing) when both the old and new values are empty.
setAttribute(String? namespace, String name, String? value) → void
Sets, adds or (with a null value) removes an attribute.
setBindAttribute(String? namespace, String name, String? value) → void
Sets, adds or removes a bind attribute.
setEnabled(bool enabled, {bool inherited = false}) → void
Sets the enabled state (own or inherited); descendants inherit it.
shallowCopy() → TreeElement
A copy of this element that shares its children and parent.
toString() → String
A string representation of this object.
override

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

buildRef(TreeElement? element) → TreeReference
Builds the reference to element by walking up its parents.
findAttributeIn(List<TreeElement> attributes, String? namespace, String name) → TreeElement?
The attribute called name in namespace (any namespace if null) among attributes. Port of the static TreeElement.getAttribute.
setAttributeIn(TreeElement? parent, List<TreeElement> attributes, String? namespace, String name, String? value) → void
Sets, adds or (with a null value) removes an attribute in attributes, adopted by parent. Port of the static TreeElement.setAttribute.