Package org.javarosa.core.model.instance
Class TreeReference
java.lang.Object
org.javarosa.core.model.instance.TreeReference
- All Implemented Interfaces:
Serializable,Externalizable
public class TreeReference extends Object implements Externalizable, Serializable
- See Also:
- Serialized Form
-
Field Summary
Fields Modifier and Type Field Description static intCONTEXT_ABSOLUTEstatic intCONTEXT_INHERITEDstatic intCONTEXT_INSTANCEstatic intCONTEXT_ORIGINALstatic intDEFAULT_MULTIPLICITYMultiplicity demarcates the position of a given element with respect to other elements of the same name.static intDEFAULT_MUTLIPLICITYDeprecated.replaced byDEFAULT_MULTIPLICITYstatic intINDEX_ATTRIBUTEMultiplicity flag for an attributestatic intINDEX_REPEAT_JUNCTUREstatic intINDEX_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 addedstatic intINDEX_UNBOUNDRefers to all instances of an element, e.g.static StringNAME_WILDCARDstatic intREF_ABSOLUTE -
Constructor Summary
Constructors Constructor Description TreeReference() -
Method Summary
Modifier and Type Method Description voidadd(String name, int mult)voidaddPredicate(int key, List<XPathExpression> xpe)TreeReferenceanchor(TreeReference baseReference)Builds and returns a new reference that is this reference anchored to a passed-in base reference.TreeReferenceclone()TreeReferencecontextualize(TreeReference contextRef)booleanequals(Object o)TreeReferenceextendRef(String name, int mult)clone and extend a reference by one levelTreeReferencegenericize()intgetContext()StringgetInstanceName()intgetMultiplicity(int index)intgetMultLast()StringgetName(int index)StringgetNameLast()TreeReferencegetParentRef()List<XPathExpression>getPredicate(int key)intgetRefLevel()TreeReferencegetSubReference(int level)Returns the subreference of this reference up to the level specified.inthashCode()booleanhasPredicates()voidincrementRefLevel()TreeReferenceintersect(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.booleanisAbsolute()booleanisAmbiguous()booleanisParentOf(TreeReference child, boolean properParent)TreeReferenceparent(TreeReference baseReference)Builds and returns a new reference that is this reference anchored to a passed-in base reference.voidreadExternal(DataInputStream in, PrototypeFactory pf)TreeReferencerelativize(TreeReference parent)booleanremoveLastLevel()TreeReferenceremovePredicates()static TreeReferencerootRef()static TreeReferenceselfRef()voidsetContext(int context)voidsetInstanceName(String instanceName)voidsetMultiplicity(int i, int mult)voidsetRefLevel(int refLevel)intsize()StringtoShortString()StringtoString()StringtoString(boolean includePredicates)StringtoString(boolean includePredicates, boolean zeroIndexMult)voidwriteExternal(DataOutputStream out)
-
Field Details
-
DEFAULT_MUTLIPLICITY
Deprecated.replaced byDEFAULT_MULTIPLICITY- See Also:
- Constant Field Values
-
DEFAULT_MULTIPLICITY
public static final int DEFAULT_MULTIPLICITYMultiplicity demarcates the position of a given element with respect to other elements of the same name. 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.- See Also:
- Constant Field Values
-
INDEX_UNBOUND
public static final int INDEX_UNBOUNDRefers to all instances of an element, e.g. /data/b[-1] refers to b[0] and b[1]- See Also:
- Constant Field Values
-
INDEX_TEMPLATE
public static final 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- See Also:
- Constant Field Values
-
INDEX_ATTRIBUTE
public static final int INDEX_ATTRIBUTEMultiplicity flag for an attribute- See Also:
- Constant Field Values
-
INDEX_REPEAT_JUNCTURE
public static final int INDEX_REPEAT_JUNCTURE- See Also:
- Constant Field Values
-
CONTEXT_ABSOLUTE
public static final int CONTEXT_ABSOLUTE- See Also:
- Constant Field Values
-
CONTEXT_INHERITED
public static final int CONTEXT_INHERITED- See Also:
- Constant Field Values
-
CONTEXT_ORIGINAL
public static final int CONTEXT_ORIGINAL- See Also:
- Constant Field Values
-
CONTEXT_INSTANCE
public static final int CONTEXT_INSTANCE- See Also:
- Constant Field Values
-
REF_ABSOLUTE
public static final int REF_ABSOLUTE- See Also:
- Constant Field Values
-
NAME_WILDCARD
- See Also:
- Constant Field Values
-
-
Constructor Details
-
TreeReference
public TreeReference()
-
-
Method Details
-
rootRef
-
selfRef
-
getInstanceName
-
setInstanceName
-
getMultiplicity
public int getMultiplicity(int index) -
getName
-
getMultLast
public int getMultLast() -
getNameLast
-
setMultiplicity
public void setMultiplicity(int i, int mult) -
size
public int size() -
add
-
addPredicate
-
getPredicate
-
getRefLevel
public int getRefLevel() -
setRefLevel
public void setRefLevel(int refLevel) -
incrementRefLevel
public void incrementRefLevel() -
isAbsolute
public boolean isAbsolute() -
isAmbiguous
public boolean isAmbiguous() -
clone
-
removeLastLevel
public boolean removeLastLevel() -
getParentRef
-
parent
Builds and returns a new reference that is this reference anchored to a passed-in base reference. Unlike inanchor(TreeReference), the base reference can be relative. This allows anchoring of nodes with inherited context such as inTreeElement.BuildRef(org.javarosa.core.model.instance.AbstractTreeElement)whichanchorcan'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'.- Returns:
- a new TreeReference that represents this reference anchored to the parent or null if this ref has parent steps and the parent ref is not a relative reference consisting only of other 'parent' steps.
-
anchor
Builds and returns a new reference that is this reference anchored to a passed-in base reference. Unlike inparent(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 byparent(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- Returns:
- a new TreeReference that represents this reference anchored to the context.
- Throws:
XPathException- if the context reference is not absolute or if there is an attempt to parent past the root node (too many '../' levels).
-
contextualize
-
relativize
-
genericize
-
isParentOf
-
extendRef
clone and extend a reference by one level- Parameters:
name-mult-- Returns:
-
equals
-
hashCode
public int hashCode() -
toString
-
toString
-
toString
-
toShortString
-
readExternal
public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionDeserializationException
-
writeExternal
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
intersect
Intersect this tree reference with another, returning a new tree reference which contains all of the common elements, starting with the root element. 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.- Parameters:
b- The tree reference to intersect- Returns:
- The tree reference containing the common basis of this ref and b
-
setContext
public void setContext(int context) -
getContext
public int getContext() -
getSubReference
Returns the subreference of this reference up to the level specified. Used to identify the reference context for a predicate at the same level Must be an absolute reference, otherwise will throw IllegalArgumentException- Parameters:
level-- Returns:
-
hasPredicates
public boolean hasPredicates() -
removePredicates
-