public class TreeReference extends Object implements Externalizable, Serializable
| Modifier and Type | Field and Description |
|---|---|
static int |
CONTEXT_ABSOLUTE |
static int |
CONTEXT_INHERITED |
static int |
CONTEXT_INSTANCE |
static int |
CONTEXT_ORIGINAL |
static int |
DEFAULT_MULTIPLICITY
Multiplicity demarcates the position of a given element with respect to other elements
of the same name.
|
static int |
DEFAULT_MUTLIPLICITY
Deprecated.
replaced by
DEFAULT_MULTIPLICITY |
static int |
INDEX_ATTRIBUTE
Multiplicity flag for an attribute
|
static int |
INDEX_REPEAT_JUNCTURE |
static int |
INDEX_TEMPLATE
'repeats' (sections of a form that can multiply themselves) are populated with a
template that never exists in the form (IE: If you serialized the form to XML
it wouldn't be there) but provides the xml structure that should be replicated
when a 'repeat' is added
|
static int |
INDEX_UNBOUND
Refers to all instances of an element, e.g.
|
static String |
NAME_WILDCARD |
static int |
REF_ABSOLUTE |
| Constructor and Description |
|---|
TreeReference() |
| Modifier and Type | Method and Description |
|---|---|
void |
add(String name,
int mult) |
void |
addPredicate(int key,
List<XPathExpression> xpe) |
TreeReference |
anchor(TreeReference baseReference)
Builds and returns a new reference that is this reference anchored to a passed-in base reference.
|
TreeReference |
clone() |
TreeReference |
contextualize(TreeReference contextRef) |
boolean |
equals(Object o) |
TreeReference |
extendRef(String name,
int mult)
clone and extend a reference by one level
|
TreeReference |
genericize() |
int |
getContext()
Deprecated.
use #getContextType() instead
|
int |
getContextType() |
String |
getInstanceName() |
int |
getMultiplicity(int index) |
int |
getMultLast() |
String |
getName(int index) |
String |
getNameLast() |
TreeReference |
getParentRef() |
List<XPathExpression> |
getPredicate(int key) |
int |
getRefLevel() |
TreeReference |
getSubReference(int level)
Returns the subreference of this reference up to the level specified.
|
int |
hashCode() |
boolean |
hasPredicates() |
void |
incrementRefLevel() |
TreeReference |
intersect(TreeReference b)
Intersect this tree reference with another, returning a new tree reference
which contains all of the common elements, starting with the root element.
|
boolean |
isAbsolute() |
boolean |
isAmbiguous() |
boolean |
isAncestorOf(TreeReference child,
boolean properParent) |
boolean |
isParentOf(TreeReference child,
boolean properParent)
Deprecated.
replaced by
isAncestorOf(TreeReference, boolean) |
TreeReference |
parent(TreeReference baseReference)
Builds and returns a new reference that is this reference anchored to a passed-in base reference.
|
void |
readExternal(DataInputStream in,
PrototypeFactory pf) |
TreeReference |
relativize(TreeReference parent) |
boolean |
removeLastLevel() |
TreeReference |
removePredicates() |
TreeReference |
removePredicates(int i) |
static TreeReference |
rootRef() |
static TreeReference |
selfRef() |
void |
setContext(int contextType)
Deprecated.
use #setContextType(int) instead
|
void |
setContextType(int contextType) |
void |
setInstanceName(String instanceName) |
void |
setMultiplicity(int i,
int mult) |
void |
setRefLevel(int refLevel) |
int |
size() |
String |
toShortString() |
String |
toString() |
String |
toString(boolean includePredicates) |
String |
toString(boolean includePredicates,
boolean zeroIndexMult) |
void |
writeExternal(DataOutputStream out) |
@Deprecated public static final int DEFAULT_MUTLIPLICITY
DEFAULT_MULTIPLICITYpublic static final int DEFAULT_MULTIPLICITY
Since users usually want to select the first instance from the nodeset returned from a reference query, let the default multiplicity be selecting the first node.
public static final int INDEX_UNBOUND
public static final int INDEX_TEMPLATE
public static final int INDEX_ATTRIBUTE
public static final int INDEX_REPEAT_JUNCTURE
public static final int CONTEXT_ABSOLUTE
public static final int CONTEXT_INHERITED
public static final int CONTEXT_ORIGINAL
public static final int CONTEXT_INSTANCE
public static final int REF_ABSOLUTE
public static final String NAME_WILDCARD
public static TreeReference rootRef()
public static TreeReference selfRef()
public String getInstanceName()
public void setInstanceName(String instanceName)
public int getMultiplicity(int index)
public String getName(int index)
public int getMultLast()
public String getNameLast()
public void setMultiplicity(int i,
int mult)
public int size()
public void add(String name, int mult)
public void addPredicate(int key,
List<XPathExpression> xpe)
public List<XPathExpression> getPredicate(int key)
public int getRefLevel()
public void setRefLevel(int refLevel)
public void incrementRefLevel()
public boolean isAbsolute()
public boolean isAmbiguous()
public TreeReference clone()
public boolean removeLastLevel()
public TreeReference getParentRef()
public TreeReference parent(TreeReference baseReference)
Unlike in anchor(TreeReference), the base reference can be relative. This allows anchoring of nodes
with inherited context such as in TreeElement.BuildRef(org.javarosa.core.model.instance.AbstractTreeElement) which
anchor can't do. However, if this ref has 'parent' steps (..), it can only be
anchored if the base ref is a relative ref consisting only of other 'parent' steps. For example,
'../../a'.parent('..') is valid and yields '../../../a'.
public TreeReference anchor(TreeReference baseReference) throws XPathException
Unlike in parent(TreeReference), the base reference must be absolute and refer to a singular, existing
node in the model. For example, this allows '../../d/e/f'.anchor('/a/b/c') -> '/a/d/e/f' which can't be done by
parent(TreeReference).
NOTE: this function still works even when baseReference contains INDEX_UNBOUND multiplicities. Conditions depend on this behavior, even though it's slightly icky.
TODO: Technically we should possibly be modifying context stuff here instead of in the xpath stuff
XPathException - if the context reference is not absolute or if there is an attempt to parent past the
root node (too many '../' levels).public TreeReference contextualize(TreeReference contextRef)
public TreeReference relativize(TreeReference parent)
public TreeReference genericize()
@Deprecated public boolean isParentOf(TreeReference child, boolean properParent)
isAncestorOf(TreeReference, boolean)public boolean isAncestorOf(TreeReference child, boolean properParent)
public TreeReference extendRef(String name, int mult)
public String toString(boolean includePredicates)
public String toString(boolean includePredicates, boolean zeroIndexMult)
public String toShortString()
public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException
readExternal in interface ExternalizableIOExceptionDeserializationExceptionpublic void writeExternal(DataOutputStream out) throws IOException
writeExternal in interface ExternalizableIOExceptionpublic TreeReference intersect(TreeReference b)
Note that relative references by their nature can't share steps, so intersecting any (or by any) relative ref will result in the root ref. Additionally, if the two references don't share any steps, the intersection will consist of the root reference.
b - The tree reference to intersect@Deprecated public void setContext(int contextType)
public void setContextType(int contextType)
@Deprecated public int getContext()
public int getContextType()
public TreeReference getSubReference(int level)
Used to identify the reference context for a predicate at the same level
Must be an absolute reference, otherwise will throw IllegalArgumentException
public boolean hasPredicates()
public TreeReference removePredicates()
public TreeReference removePredicates(int i)
Copyright © 2021. All rights reserved.