public override void processAction(FormDef model, TreeReference contextRef) { //Qualify the reference if necessary TreeReference qualifiedReference = contextRef == null?target:target.contextualize(contextRef); //For now we only process setValue actions which are within the //context if a context is provided. This happens for repeats where //insert events should only trigger on the right nodes if (contextRef != null) { //Note: right now we're qualifying then testing parentage to see wheter //there was a conflict, but it's not super clear whether this is a perfect //strategy if (!contextRef.isParentOf(qualifiedReference, false)) { return; } } //TODO: either the target or the value's node might not exist here, catch and throw //reasonably EvaluationContext context = new EvaluationContext(model.EvaluationContext, qualifiedReference); System.Object result; if (explicitValue != null) { result = explicitValue; } else { result = XPathFuncExpr.unpack(value_Renamed.eval(model.MainInstance, context)); } AbstractTreeElement node = context.resolveReference(qualifiedReference); if (node == null) { throw new System.NullReferenceException("Target of TreeReference " + qualifiedReference.toString(true) + " could not be resolved!"); } int dataType = node.getDataType(); IAnswerData val = Recalculate.wrapData(result, dataType); model.setValue(val == null?null:AnswerDataFactory.templateByDataType(dataType).cast(val.uncast()), qualifiedReference); }
/// <summary> For the current index: Checks whether the index represents a node which /// should exist given a non-interactive repeat, along with a count for that /// repeat which is beneath the dynamic level specified. /// /// If this index does represent such a node, the new model for the repeat is /// created behind the scenes and the index for the initial question is /// returned. /// /// Note: This method will not prevent the addition of new repeat elements in /// the interface, it will merely use the xforms repeat hint to create new /// nodes that are assumed to exist /// /// </summary> /// <param name="index">The index to be evaluated as to whether the underlying model is /// hinted to exist /// </param> private void createModelIfNecessary(FormIndex index) { if (index.InForm) { IFormElement e = Form.getChild(index); if (e is GroupDef) { GroupDef g = (GroupDef)e; if (g.Repeat && g.CountReference != null) { // Lu Gram: repeat count XPath needs to be contextualized for nested repeat groups TreeReference countRef = FormInstance.unpackReference(g.CountReference); TreeReference contextualized = countRef.contextualize(index.Reference); IAnswerData count = Form.MainInstance.resolveReference(contextualized).getValue(); if (count != null) { long fullcount = ((System.Int32)count.Value); TreeReference ref_Renamed = Form.getChildInstanceRef(index); TreeElement element = Form.MainInstance.resolveReference(ref_Renamed); if (element == null) { if (index.getTerminal().InstanceIndex < fullcount) { try { Form.createNewRepeat(index); } catch (InvalidReferenceException ire) { SupportClass.WriteStackTrace(ire, Console.Error); //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" throw new System.SystemException("Invalid Reference while creting new repeat!" + ire.Message); } } } } } } } }
public override XPathNodeset eval(FormInstance m, EvaluationContext ec) { TreeReference genericRef = getReference(); TreeReference ref_Renamed; if (genericRef.Context == TreeReference.CONTEXT_ORIGINAL) { ref_Renamed = genericRef.contextualize(ec.OriginalContext); } else { ref_Renamed = genericRef.contextualize(ec.ContextRef); } //We don't necessarily know the model we want to be working with until we've contextualized the //node //check if this nodeset refers to a non-main instance if (ref_Renamed.InstanceName != null && ref_Renamed.Absolute) { FormInstance nonMain = ec.getInstance(ref_Renamed.InstanceName); if (nonMain != null) { m = nonMain; } else { throw new XPathMissingInstanceException(ref_Renamed.InstanceName, "Instance referenced by " + ref_Renamed.toString(true) + " does not exist"); } } else { //TODO: We should really stop passing 'm' around and start just getting the right instance from ec //at a more central level m = ec.MainInstance; if (m == null) { System.String refStr = ref_Renamed == null?"":ref_Renamed.toString(true); throw new XPathException("Cannot evaluate the reference [" + refStr + "] in the current evaluation context. No default instance has been declared!"); } } // regardless of the above, we want to ensure there is a definition if (m.getRoot() == null) { //This instance is _declared_, but doesn't actually have any data in it. throw new XPathMissingInstanceException(ref_Renamed.InstanceName, "Instance referenced by " + ref_Renamed.toString(true) + " has not been loaded"); } // this makes no sense... // if (ref.isAbsolute() && m.getTemplatePath(ref) == null) { // Vector<TreeReference> nodesetRefs = new Vector<TreeReference>(); // return new XPathNodeset(nodesetRefs, m, ec); // } //to fix conditions based on non-relevant data, filter the nodeset by relevancy for (int i = 0; i < nodesetRefs.size(); i++) { if (!m.resolveReference((TreeReference)nodesetRefs.elementAt(i)).isRelevant()) { nodesetRefs.removeElementAt(i); i--; } } return(new XPathNodeset(nodesetRefs, m, ec)); }
private void InitBlock() { if (expr is XPathPathExpr) { return(((XPathPathExpr)expr).eval(model, evalContext).getReferences()); } else { throw new FatalException("evalNodeset: must be path expression"); } Set <TreeReference> triggers = new HashSet <TreeReference>(); getTriggers(expr, triggers, contextRef); return(triggers); if (x is XPathPathExpr) { TreeReference ref_Renamed = ((XPathPathExpr)x).getReference(); TreeReference contextualized = ref_Renamed; if (contextRef != null) { contextualized = ref_Renamed.contextualize(contextRef); } //TODO: It's possible we should just handle this the same way as "genericize". Not entirely clear. if (contextualized.hasPredicates()) { contextualized = contextualized.removePredicates(); } v.add(contextualized); for (int i = 0; i < ref_Renamed.size(); i++) { if (predicates == null) { continue; } //we can't generate this properly without an absolute reference if (!ref_Renamed.Absolute) { throw new System.ArgumentException("can't get triggers for relative references"); } TreeReference predicateContext = ref_Renamed.getSubReference(i); for (XPathExpression predicate: predicates) { getTriggers(predicate, v, predicateContext); } } } else if (x is XPathBinaryOpExpr) { getTriggers(((XPathBinaryOpExpr)x).a, v, contextRef); getTriggers(((XPathBinaryOpExpr)x).b, v, contextRef); } else if (x is XPathUnaryOpExpr) { getTriggers(((XPathUnaryOpExpr)x).a, v, contextRef); } else if (x is XPathFuncExpr) { XPathFuncExpr fx = (XPathFuncExpr)x; for (int i = 0; i < fx.args.Length; i++) { getTriggers(fx.args[i], v, contextRef); } } return(expr.pivot(model, evalContext)); }