Class TreeElement
- All Implemented Interfaces:
AbstractTreeElement<TreeElement>,Externalizable
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
- Author:
- Clayton Sims
-
Field Summary
Fields Modifier and Type Field Description protected intdataTypeprotected intmultiplicity -
Constructor Summary
Constructors Constructor Description TreeElement()TreeElement with null name and 0 multiplicity? (a "hidden root" node?)TreeElement(String name)TreeElement(String name, int multiplicity) -
Method Summary
Modifier and Type Method Description voidaccept(ITreeVisitor visitor)Visitor pattern acceptance method.voidaddChild(TreeElement child)voidalertStateObservers(int changeFlags)static TreeReferenceBuildRef(AbstractTreeElement elem)static intCalculateDepth(AbstractTreeElement elem)voidclearCaches()voidclearChildrenCaches()static TreeElementconstructAttributeElement(String namespace, String name, String value)Construct a TreeElement which represents an attribute with the provided namespace and name.TreeElementdeepCopy(boolean includeTemplates)TreeElementgetAttribute(String namespace, String name)Retrieves the TreeElement representing the attribute at the provided namespace and name, or null if none exists.static TreeElementgetAttribute(List<TreeElement> attributes, String namespace, String name)Retrieves the TreeElement representing the attribute for the provided namespace and name, or null if none exists.intgetAttributeCount()Returns the number of attributes of this element.StringgetAttributeName(int index)get name of attribute at 'index' in the listStringgetAttributeNamespace(int index)get namespace of attribute at 'index' in the listStringgetAttributeValue()StringgetAttributeValue(int index)get value of attribute at 'index' in the listStringgetAttributeValue(String namespace, String name)get value of attribute with namespace:name' in the listTreeElementgetBindAttribute(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()StringgetBindAttributeValue(String namespace, String name)Returns the value of the given bind attribute from the given namespace.TreeElementgetChild(String name, int multiplicity)TreeElementgetChildAt(int i)intgetChildMultiplicity(String name)List<TreeElement>getChildrenWithName(String name)Get all the child nodes of this element, with specific nameConstraintgetConstraint()intgetDataType()intgetDepth()StringgetInstanceName()intgetMult()intgetMultiplicity()StringgetName()StringgetNamespace()StringgetNamespacePrefix()intgetNumChildren()AbstractTreeElementgetParent()StringgetPreloadHandler()StringgetPreloadParams()TreeReferencegetRef()IAnswerDatagetValue()booleanhasChildren()booleanisAttribute()booleanisChildable()booleanisEnabled()booleanisLeaf()booleanisRelevant()booleanisRepeatable()booleanisRequired()voidpopulate(TreeElement incoming, FormDef f)voidpopulateTemplate(TreeElement incoming, FormDef f)voidreadExternal(DataInputStream in, PrototypeFactory pf)voidregisterStateObserver(FormElementStateListener qsl)voidremoveChild(String name, int multiplicity)voidremoveChild(TreeElement child)voidremoveChildAt(int i)voidremoveChildren(String name)booleansetAnswer(IAnswerData answer)voidsetAttribute(String namespace, String name, String value)static voidsetAttribute(TreeElement parent, List<TreeElement> attrs, String namespace, String name, String value)voidsetBindAttribute(String namespace, String name, String value)voidsetBindAttributes(List<TreeElement> bindAttributes)voidsetConstraint(Constraint constraint)voidsetDataType(int dataType)voidsetEnabled(boolean enabled)voidsetEnabled(boolean enabled, boolean inherited)voidsetInstanceName(String instanceName)voidsetMult(int multiplicity)voidsetName(String name)voidsetNamespace(String namespace)voidsetNamespacePrefix(String namespacePrefix)voidsetParent(AbstractTreeElement parent)voidsetPreloadHandler(String preloadHandler)voidsetPreloadParams(String preloadParams)voidsetRelevant(boolean relevant)voidsetRepeatable(boolean repeatable)voidsetRequired(boolean required)voidsetValue(IAnswerData value)TreeElementshallowCopy()StringtoString()List<TreeReference>tryBatchChildFetch(String name, int mult, List<XPathExpression> predicates, EvaluationContext evalContext)TODO: Worst method name ever.voidunregisterAll()voidunregisterStateObserver(FormElementStateListener qsl)voidwriteExternal(DataOutputStream out)
-
Field Details
-
multiplicity
protected int multiplicity -
dataType
protected int dataType
-
-
Constructor Details
-
TreeElement
public TreeElement()TreeElement with null name and 0 multiplicity? (a "hidden root" node?) -
TreeElement
-
TreeElement
-
-
Method Details
-
constructAttributeElement
Construct a TreeElement which represents an attribute with the provided namespace and name.- Parameters:
namespace- - if null will be converted to empty stringname-value-- Returns:
- A new instance of a TreeElement
-
getAttribute
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.
- Parameters:
attributes- - list of attributes to searchnamespace-name-- Returns:
- TreeElement
-
setAttribute
public static void setAttribute(TreeElement parent, List<TreeElement> attrs, String namespace, String name, String value) -
isLeaf
public boolean isLeaf()- Specified by:
isLeafin interfaceAbstractTreeElement<TreeElement>
-
isChildable
public boolean isChildable()- Specified by:
isChildablein interfaceAbstractTreeElement<TreeElement>
-
getInstanceName
- Specified by:
getInstanceNamein interfaceAbstractTreeElement<TreeElement>
-
setInstanceName
-
setValue
-
getChild
- Specified by:
getChildin interfaceAbstractTreeElement<TreeElement>
-
getChildrenWithName
Description copied from interface:AbstractTreeElementGet all the child nodes of this element, with specific name- Specified by:
getChildrenWithNamein interfaceAbstractTreeElement<TreeElement>- Returns:
-
getNumChildren
public int getNumChildren()- Specified by:
getNumChildrenin interfaceAbstractTreeElement<TreeElement>
-
hasChildren
public boolean hasChildren()- Specified by:
hasChildrenin interfaceAbstractTreeElement<TreeElement>
-
getChildAt
- Specified by:
getChildAtin interfaceAbstractTreeElement<TreeElement>
-
isRepeatable
public boolean isRepeatable()- Specified by:
isRepeatablein interfaceAbstractTreeElement<TreeElement>
-
isAttribute
public boolean isAttribute()- Specified by:
isAttributein interfaceAbstractTreeElement<TreeElement>
-
setDataType
public void setDataType(int dataType) -
addChild
-
removeChild
-
removeChild
-
removeChildren
-
removeChildAt
public void removeChildAt(int i) -
getChildMultiplicity
- Specified by:
getChildMultiplicityin interfaceAbstractTreeElement<TreeElement>
-
shallowCopy
-
deepCopy
-
isRelevant
public boolean isRelevant()- Specified by:
isRelevantin interfaceAbstractTreeElement<TreeElement>
-
isEnabled
public boolean isEnabled() -
setAnswer
-
setRequired
public void setRequired(boolean required) -
setRelevant
public void setRelevant(boolean relevant) -
setBindAttributes
-
getBindAttributes
-
getBindAttribute
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.
- Returns:
- TreeElement
-
getBindAttributeValue
Returns the value of the given bind attribute from the given namespace.Example:
- Given a binding
<bind assertion="blah"/>, callinggetBindAttributeValue(null, "assertion")will return"blah" - Given a binding
<bind odk:assertion="blah"/>, callinggetBindAttributeValue("odk", "assertion")will return"blah"
- Parameters:
namespace- the namespace of the attribute. It can be nullname- the name of the attribute
- Given a binding
-
setBindAttribute
-
setEnabled
public void setEnabled(boolean enabled) -
setEnabled
public void setEnabled(boolean enabled, boolean inherited) -
registerStateObserver
-
unregisterStateObserver
-
unregisterAll
public void unregisterAll() -
alertStateObservers
public void alertStateObservers(int changeFlags) -
accept
Description copied from interface:AbstractTreeElementVisitor pattern acceptance method.- Specified by:
acceptin interfaceAbstractTreeElement<TreeElement>- Parameters:
visitor- The visitor traveling this tree
-
getAttributeCount
public int getAttributeCount()Description copied from interface:AbstractTreeElementReturns the number of attributes of this element.- Specified by:
getAttributeCountin interfaceAbstractTreeElement<TreeElement>
-
getAttributeNamespace
Description copied from interface:AbstractTreeElementget namespace of attribute at 'index' in the list- Specified by:
getAttributeNamespacein interfaceAbstractTreeElement<TreeElement>- Returns:
- String
-
getAttributeName
Description copied from interface:AbstractTreeElementget name of attribute at 'index' in the list- Specified by:
getAttributeNamein interfaceAbstractTreeElement<TreeElement>- Returns:
- String
-
getAttributeValue
Description copied from interface:AbstractTreeElementget value of attribute at 'index' in the list- Specified by:
getAttributeValuein interfaceAbstractTreeElement<TreeElement>- Returns:
- String
-
getAttributeValue
-
getAttribute
Description copied from interface:AbstractTreeElementRetrieves the TreeElement representing the attribute 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.- Specified by:
getAttributein interfaceAbstractTreeElement<TreeElement>- Returns:
- TreeElement
-
getAttributeValue
Description copied from interface:AbstractTreeElementget value of attribute with namespace:name' in the list- Specified by:
getAttributeValuein interfaceAbstractTreeElement<TreeElement>- Returns:
- String
-
setAttribute
-
readExternal
public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionDeserializationException
-
writeExternal
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
populate
-
populateTemplate
-
getRef
- Specified by:
getRefin interfaceAbstractTreeElement<TreeElement>
-
BuildRef
-
getDepth
public int getDepth()- Specified by:
getDepthin interfaceAbstractTreeElement<TreeElement>
-
CalculateDepth
-
getPreloadHandler
-
getConstraint
-
setPreloadHandler
-
setConstraint
-
getPreloadParams
-
setPreloadParams
-
getName
- Specified by:
getNamein interfaceAbstractTreeElement<TreeElement>
-
setName
-
getMult
public int getMult()- Specified by:
getMultin interfaceAbstractTreeElement<TreeElement>
-
setMult
public void setMult(int multiplicity) -
setParent
-
getParent
- Specified by:
getParentin interfaceAbstractTreeElement<TreeElement>
-
getValue
- Specified by:
getValuein interfaceAbstractTreeElement<TreeElement>
-
toString
-
getDataType
public int getDataType()- Specified by:
getDataTypein interfaceAbstractTreeElement<TreeElement>
-
isRequired
public boolean isRequired() -
setRepeatable
public void setRepeatable(boolean repeatable) -
getMultiplicity
public int getMultiplicity() -
clearCaches
public void clearCaches()- Specified by:
clearCachesin interfaceAbstractTreeElement<TreeElement>
-
clearChildrenCaches
public void clearChildrenCaches() -
getNamespace
- Specified by:
getNamespacein interfaceAbstractTreeElement<TreeElement>
-
setNamespace
-
tryBatchChildFetch
public List<TreeReference> tryBatchChildFetch(String name, int mult, List<XPathExpression> predicates, EvaluationContext evalContext)Description copied from interface:AbstractTreeElementTODO: Worst method name ever. Don't use this unless you know what's up.- Specified by:
tryBatchChildFetchin interfaceAbstractTreeElement<TreeElement>predicates- possibly list of predicates to be evaluated. predicates will be removed from list if they are able to be evaluated- Returns:
-
getNamespacePrefix
-
setNamespacePrefix
-