public class TreeElement extends Object implements Externalizable, AbstractTreeElement<TreeElement>
An element of a FormInstance.
TreeElements represent an XML node in the instance. It may either have a value (e.g.,
TreeElements can also represent attributes. Attributes are unique from normal elements in that they are not "children" of their parent, and are always leaf nodes: IE cannot have children.
TODO: Split out the bind-able session data from this class and leave only the mandatory values to speed up new DOM-like models
| Modifier and Type | Field and Description |
|---|---|
protected int |
dataType |
protected int |
multiplicity |
| Constructor and Description |
|---|
TreeElement()
TreeElement with null name and 0 multiplicity? (a "hidden root" node?)
|
TreeElement(String name) |
TreeElement(String name,
int multiplicity) |
| Modifier and Type | Method and Description |
|---|---|
void |
accept(ITreeVisitor visitor)
Visitor pattern acceptance method.
|
void |
addChild(TreeElement child) |
void |
alertStateObservers(int changeFlags) |
static TreeReference |
BuildRef(AbstractTreeElement elem) |
static int |
CalculateDepth(AbstractTreeElement elem) |
void |
clearCaches() |
void |
clearChildrenCaches() |
static TreeElement |
constructAttributeElement(String namespace,
String name,
String value)
Construct a TreeElement which represents an attribute with the provided
namespace and name.
|
TreeElement |
deepCopy(boolean includeTemplates) |
static TreeElement |
getAttribute(List<TreeElement> attributes,
String namespace,
String name)
Retrieves the TreeElement representing the attribute for
the provided namespace and name, or null if none exists.
|
TreeElement |
getAttribute(String namespace,
String name)
Retrieves the TreeElement representing the attribute at
the provided namespace and name, or null if none exists.
|
int |
getAttributeCount()
Returns the number of attributes of this element.
|
String |
getAttributeName(int index)
get name of attribute at 'index' in the list
|
String |
getAttributeNamespace(int index)
get namespace of attribute at 'index' in the list
|
String |
getAttributeValue() |
String |
getAttributeValue(int index)
get value of attribute at 'index' in the list
|
String |
getAttributeValue(String namespace,
String name)
get value of attribute with namespace:name' in the list
|
TreeElement |
getBindAttribute(String namespace,
String name)
Retrieves the TreeElement representing an arbitrary bind attribute
for this element at the provided namespace and name, or null if none exists.
|
List<TreeElement> |
getBindAttributes() |
String |
getBindAttributeValue(String namespace,
String name)
Returns the value of the given bind attribute from the given namespace.
|
TreeElement |
getChild(String name,
int multiplicity) |
TreeElement |
getChildAt(int i) |
int |
getChildMultiplicity(String name) |
List<TreeElement> |
getChildrenWithName(String name)
Get all the child nodes of this element, with specific name
|
Constraint |
getConstraint() |
int |
getDataType() |
int |
getDepth() |
String |
getInstanceName() |
int |
getMult() |
int |
getMultiplicity() |
String |
getName() |
String |
getNamespace() |
String |
getNamespacePrefix() |
int |
getNumChildren() |
AbstractTreeElement |
getParent() |
String |
getPreloadHandler() |
String |
getPreloadParams() |
TreeReference |
getRef() |
IAnswerData |
getValue() |
boolean |
hasChildren() |
boolean |
isAttribute() |
boolean |
isChildable() |
boolean |
isEnabled() |
boolean |
isLeaf() |
boolean |
isRelevant() |
boolean |
isRepeatable() |
boolean |
isRequired() |
void |
populate(TreeElement incoming,
FormDef f) |
void |
populateTemplate(TreeElement incoming,
FormDef f) |
void |
readExternal(DataInputStream in,
PrototypeFactory pf) |
void |
registerStateObserver(FormElementStateListener qsl) |
void |
removeChild(String name,
int multiplicity) |
void |
removeChild(TreeElement child) |
void |
removeChildAt(int i) |
void |
removeChildren(String name) |
boolean |
setAnswer(IAnswerData answer) |
void |
setAttribute(String namespace,
String name,
String value) |
static void |
setAttribute(TreeElement parent,
List<TreeElement> attrs,
String namespace,
String name,
String value) |
void |
setBindAttribute(String namespace,
String name,
String value) |
void |
setBindAttributes(List<TreeElement> bindAttributes) |
void |
setConstraint(Constraint constraint) |
void |
setDataType(int dataType) |
void |
setEnabled(boolean enabled) |
void |
setEnabled(boolean enabled,
boolean inherited) |
void |
setInstanceName(String instanceName) |
void |
setMult(int multiplicity) |
void |
setName(String name) |
void |
setNamespace(String namespace) |
void |
setNamespacePrefix(String namespacePrefix) |
void |
setParent(AbstractTreeElement parent) |
void |
setPreloadHandler(String preloadHandler) |
void |
setPreloadParams(String preloadParams) |
void |
setRelevant(boolean relevant) |
void |
setRepeatable(boolean repeatable) |
void |
setRequired(boolean required) |
void |
setValue(IAnswerData value) |
TreeElement |
shallowCopy() |
String |
toString() |
List<TreeReference> |
tryBatchChildFetch(String name,
int mult,
List<XPathExpression> predicates,
EvaluationContext evalContext)
TODO: Worst method name ever.
|
void |
unregisterAll() |
void |
unregisterStateObserver(FormElementStateListener qsl) |
void |
writeExternal(DataOutputStream out) |
public TreeElement()
public TreeElement(String name)
public TreeElement(String name, int multiplicity)
public static TreeElement constructAttributeElement(String namespace, String name, String value)
namespace - - if null will be converted to empty stringname - value - public static TreeElement getAttribute(List<TreeElement> attributes, String namespace, String name)
Retrieves the TreeElement representing the attribute for the provided namespace and name, or null if none exists.
If 'null' is provided for the namespace, it will match the first attribute with the matching name.
attributes - - list of attributes to searchnamespace - name - public static void setAttribute(TreeElement parent, List<TreeElement> attrs, String namespace, String name, String value)
public boolean isLeaf()
isLeaf in interface AbstractTreeElement<TreeElement>public boolean isChildable()
isChildable in interface AbstractTreeElement<TreeElement>public String getInstanceName()
getInstanceName in interface AbstractTreeElement<TreeElement>public void setInstanceName(String instanceName)
public void setValue(IAnswerData value)
public TreeElement getChild(String name, int multiplicity)
getChild in interface AbstractTreeElement<TreeElement>public List<TreeElement> getChildrenWithName(String name)
AbstractTreeElementgetChildrenWithName in interface AbstractTreeElement<TreeElement>public int getNumChildren()
getNumChildren in interface AbstractTreeElement<TreeElement>public boolean hasChildren()
hasChildren in interface AbstractTreeElement<TreeElement>public TreeElement getChildAt(int i)
getChildAt in interface AbstractTreeElement<TreeElement>public boolean isRepeatable()
isRepeatable in interface AbstractTreeElement<TreeElement>public boolean isAttribute()
isAttribute in interface AbstractTreeElement<TreeElement>public void setDataType(int dataType)
public void addChild(TreeElement child)
public void removeChild(TreeElement child)
public void removeChild(String name, int multiplicity)
public void removeChildren(String name)
public void removeChildAt(int i)
public int getChildMultiplicity(String name)
getChildMultiplicity in interface AbstractTreeElement<TreeElement>public TreeElement shallowCopy()
public TreeElement deepCopy(boolean includeTemplates)
public boolean isRelevant()
isRelevant in interface AbstractTreeElement<TreeElement>public boolean isEnabled()
public boolean setAnswer(IAnswerData answer)
public void setRequired(boolean required)
public void setRelevant(boolean relevant)
public void setBindAttributes(List<TreeElement> bindAttributes)
public List<TreeElement> getBindAttributes()
public TreeElement getBindAttribute(String namespace, String name)
Retrieves the TreeElement representing an arbitrary bind attribute for this element at the provided namespace and name, or null if none exists.
If 'null' is provided for the namespace, it will match the first attribute with the matching name.
public String getBindAttributeValue(String namespace, String name)
Example:
<bind assertion="blah"/>, calling getBindAttributeValue(null, "assertion") will return "blah"
<bind odk:assertion="blah"/>, calling getBindAttributeValue("odk", "assertion") will return "blah"
namespace - the namespace of the attribute. It can be nullname - the name of the attributepublic void setEnabled(boolean enabled)
public void setEnabled(boolean enabled,
boolean inherited)
public void registerStateObserver(FormElementStateListener qsl)
public void unregisterStateObserver(FormElementStateListener qsl)
public void unregisterAll()
public void alertStateObservers(int changeFlags)
public void accept(ITreeVisitor visitor)
AbstractTreeElementaccept in interface AbstractTreeElement<TreeElement>visitor - The visitor traveling this treepublic int getAttributeCount()
AbstractTreeElementgetAttributeCount in interface AbstractTreeElement<TreeElement>public String getAttributeNamespace(int index)
AbstractTreeElementgetAttributeNamespace in interface AbstractTreeElement<TreeElement>public String getAttributeName(int index)
AbstractTreeElementgetAttributeName in interface AbstractTreeElement<TreeElement>public String getAttributeValue(int index)
AbstractTreeElementgetAttributeValue in interface AbstractTreeElement<TreeElement>public String getAttributeValue()
public TreeElement getAttribute(String namespace, String name)
AbstractTreeElementgetAttribute in interface AbstractTreeElement<TreeElement>public String getAttributeValue(String namespace, String name)
AbstractTreeElementgetAttributeValue in interface AbstractTreeElement<TreeElement>public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException
readExternal in interface ExternalizableIOExceptionDeserializationExceptionpublic void writeExternal(DataOutputStream out) throws IOException
writeExternal in interface ExternalizableIOExceptionpublic void populate(TreeElement incoming, FormDef f)
public void populateTemplate(TreeElement incoming, FormDef f)
public TreeReference getRef()
getRef in interface AbstractTreeElement<TreeElement>public static TreeReference BuildRef(AbstractTreeElement elem)
public int getDepth()
getDepth in interface AbstractTreeElement<TreeElement>public static int CalculateDepth(AbstractTreeElement elem)
public String getPreloadHandler()
public Constraint getConstraint()
public void setPreloadHandler(String preloadHandler)
public void setConstraint(Constraint constraint)
public String getPreloadParams()
public void setPreloadParams(String preloadParams)
public String getName()
getName in interface AbstractTreeElement<TreeElement>public void setName(String name)
public int getMult()
getMult in interface AbstractTreeElement<TreeElement>public void setMult(int multiplicity)
public void setParent(AbstractTreeElement parent)
public AbstractTreeElement getParent()
getParent in interface AbstractTreeElement<TreeElement>public IAnswerData getValue()
getValue in interface AbstractTreeElement<TreeElement>public int getDataType()
getDataType in interface AbstractTreeElement<TreeElement>public boolean isRequired()
public void setRepeatable(boolean repeatable)
public int getMultiplicity()
public void clearCaches()
clearCaches in interface AbstractTreeElement<TreeElement>public void clearChildrenCaches()
public String getNamespace()
getNamespace in interface AbstractTreeElement<TreeElement>public void setNamespace(String namespace)
public List<TreeReference> tryBatchChildFetch(String name, int mult, List<XPathExpression> predicates, EvaluationContext evalContext)
AbstractTreeElementtryBatchChildFetch in interface AbstractTreeElement<TreeElement>predicates - possibly list of predicates to be evaluated. predicates will be removed from list if they are
able to be evaluatedpublic String getNamespacePrefix()
public void setNamespacePrefix(String namespacePrefix)
Copyright © 2022. All rights reserved.