//very similar to parent(), but assumes contextRef refers to a singular, existing node in the model //this means we can do '/a/b/c + ../../d/e/f = /a/d/e/f', which we couldn't do in parent() //return null if context ref is not absolute, or we parent up past the root node //NOTE: this function still works even when contextRef contains INDEX_UNBOUND multiplicites... conditions depend on this behavior, // even though it's slightly icky public TreeReference anchor(TreeReference contextRef) { if (isAbsolute()) { return(this.clone()); } else if (!contextRef.isAbsolute()) { return(null); } else { TreeReference newRef = contextRef.clone(); int contextSize = contextRef.size(); if (refLevel > contextSize) { return(null); //tried to do '/..' } else { for (int i = 0; i < refLevel; i++) { newRef.removeLastLevel(); } for (int i = 0; i < size(); i++) { newRef.add(this.getName(i), this.getMultiplicity(i)); } return(newRef); } } }
//return a new reference that is this reference anchored to a passed-in parent reference //if this reference is absolute, return self //if this ref has 'parent' steps (..), it can only be anchored if the parent ref is a relative ref consisting only of other 'parent' steps //return null in these invalid situations public TreeReference parent(TreeReference parentRef) { if (isAbsolute()) { return(this); } else { TreeReference newRef = parentRef.clone(); if (refLevel > 0) { if (!parentRef.isAbsolute() && parentRef.size() == 0) { parentRef.refLevel += refLevel; } else { return(null); } } for (int i = 0; i < names.Count; i++) { newRef.add(this.getName(i), this.getMultiplicity(i)); } return(newRef); } }
public TreeReference addNode(TreeReference ambigRef) { TreeReference ref_ = ambigRef.clone(); if (createNode(ref_) != null) { return(ref_); } else { return(null); } }
public TreeReference addNode(TreeReference ambigRef, IAnswerData data, int dataType) { TreeReference ref_ = ambigRef.clone(); TreeElement node = createNode(ref_); if (node != null) { if (dataType >= 0) { node.dataType = dataType; } node.setValue(data); return(ref_); } else { return(null); } }