/// <summary> /// Initializes a new instance. /// </summary> /// <param name="item"></param> /// <param name="position"></param> /// <param name="size"></param> internal EvaluationContext(ModelItem item, int position, int size) : this(item.Model, item.Instance, item, position, size) { Contract.Requires<ArgumentNullException>(item != null); Contract.Requires<ArgumentNullException>(position >= 1); Contract.Requires<ArgumentNullException>(size >= 1); }
/// <summary> /// Initializes a new instance. /// </summary> /// <param name="element"></param> /// <param name="invoker"></param> internal UIBinding(XElement element, IInvoker invoker, ModelItem modelItem) : this(element, invoker) { Contract.Requires<ArgumentNullException>(element != null); Contract.Requires<ArgumentNullException>(invoker != null); this.modelItem = modelItem; }
/// <summary> /// Finishes a submission with instance replacement. /// </summary> /// <param name="response"></param> /// <param name="modelItem">Instance data node that was submitted.</param> void FinishWithReplaceInstance(ModelResponse response, ModelItem modelItem) { Contract.Requires<ArgumentNullException>(response != null); Contract.Requires<ArgumentException>(response.Body != null); Contract.Requires<ArgumentNullException>(modelItem != null); // When the attribute is absent, then the default is the instance that contains the submission data. var instance = modelItem != null ? modelItem.Instance : null; // Author-optional attribute specifying the instance to replace when the replace attribute value is // "instance". When the attribute is absent, then the default is the instance that contains the submission // data. An xforms-binding-exception (The xforms-binding-exception Event) occurs if this attribute does not // indicate an instance in the same model as the submission. if (properties.Instance != null) { var instanceElement = Element.ResolveId(properties.Instance); if (instanceElement != null) instance = instanceElement.Interface<Instance>(); } if (instance == null || instance.Element.Parent != Element.Parent) throw new DOMTargetEventException(Element, Events.BindingException, "Submission cannot specify foreign model instance."); var target = instance.State.Document.Root.Annotation<ModelItem>(); if (target == null) throw new InvalidOperationException(); // Author-optional attribute containing an expression that indicates the target node for data replacement. if (properties.TargetRef != null) { // The evaluation context for this attribute is the in-scope evaluation context for the submission // element, except the context node is modified to be the document element of the instance identified // by the instance attribute if present. var ec = new EvaluationContext( ModelItem.Get(context.Value.Context.Instance.State.Document.Root), 1, 1); // If the submission element has a targetref attribute, the attribute value is interpreted as a binding // expression to which the first-item rule is applied to obtain the replacement target node. target = new Binding(Element, ec, properties.TargetRef).ModelItem; } // final check if (target == null) throw new DOMTargetEventException(Element, Events.BindingException, "Null submission replacement target."); // Otherwise, those processing instructions and comments replace any processing instructions and comments // that previously appeared outside of the document element of the instance being replaced. target.Replace(response.Body); }
/// <summary> /// Initializes a new instance. /// </summary> /// <param name="model"></param> /// <param name="instance"></param> /// <param name="modelItem"></param> /// <param name="position"></param> /// <param name="size"></param> internal EvaluationContext(Model model, Instance instance, ModelItem modelItem, int position, int size) { Contract.Requires<ArgumentNullException>(model != null); Contract.Requires<ArgumentNullException>(instance != null); Contract.Requires<ArgumentNullException>(modelItem != null); Contract.Requires<ArgumentNullException>(position >= 1); Contract.Requires<ArgumentNullException>(size >= 1); this.model = model; this.instance = instance; this.modelItem = modelItem; this.position = position; this.size = size; }
/// <summary> /// Refreshes all properties. /// </summary> public void Refresh() { var oldItemType = DataType; var oldRelevant = Relevant; var oldReadOnly = ReadOnly; var oldRequired = Required; var oldValid = Valid; var oldValue = Value; if (binding != null) { binding.Recalculate(); if (modelItem != binding.ModelItem) modelItem = binding.ModelItem; } if (modelItem != null) { State.DataType = modelItem.ItemType; State.Relevant = modelItem.Relevant; State.ReadOnly = modelItem.ReadOnly; State.Required = modelItem.Required; State.Valid = modelItem.Valid; State.Value = modelItem.Value; } else { // default values State.DataType = null; State.Relevant = true; State.ReadOnly = false; State.Required = false; State.Valid = true; State.Value = null; } // mark all required events var valueChanged = Value != oldValue; if (valueChanged) { State.DispatchValueChanged = true; } if (Relevant != oldRelevant || valueChanged) { if (Relevant) State.DispatchEnabled = true; else State.DispatchDisabled = true; } if (ReadOnly != oldReadOnly || valueChanged) { if (ReadOnly) State.DispatchReadOnly = true; else State.DispatchReadWrite = true; } if (Required != oldRequired || valueChanged) { if (Required) State.DispatchRequired = true; else State.DispatchOptional = true; } if (Valid != oldValid || valueChanged) { if (Valid) State.DispatchValid = true; else State.DispatchInvalid = true; } }
/// <summary> /// Finishes a submission with instance replacement. /// </summary> /// <param name="response"></param> /// <param name="modelItem">Instance data node that was submitted.</param> void FinishWithReplaceInstance(ModelResponse response, ModelItem modelItem) { Contract.Requires <ArgumentNullException>(response != null); Contract.Requires <ArgumentException>(response.Body != null); Contract.Requires <ArgumentNullException>(modelItem != null); // When the attribute is absent, then the default is the instance that contains the submission data. var instance = modelItem != null ? modelItem.Instance : null; // Author-optional attribute specifying the instance to replace when the replace attribute value is // "instance". When the attribute is absent, then the default is the instance that contains the submission // data. An xforms-binding-exception (The xforms-binding-exception Event) occurs if this attribute does not // indicate an instance in the same model as the submission. if (properties.Instance != null) { var instanceElement = Element.ResolveId(properties.Instance); if (instanceElement != null) { instance = instanceElement.Interface <Instance>(); } } if (instance == null || instance.Element.Parent != Element.Parent) { throw new DOMTargetEventException(Element, Events.BindingException, "Submission cannot specify foreign model instance."); } var target = instance.State.Document.Root.Annotation <ModelItem>(); if (target == null) { throw new InvalidOperationException(); } // Author-optional attribute containing an expression that indicates the target node for data replacement. if (properties.TargetRef != null) { // The evaluation context for this attribute is the in-scope evaluation context for the submission // element, except the context node is modified to be the document element of the instance identified // by the instance attribute if present. var ec = new EvaluationContext( ModelItem.Get(context.Value.Context.Instance.State.Document.Root), 1, 1); // If the submission element has a targetref attribute, the attribute value is interpreted as a binding // expression to which the first-item rule is applied to obtain the replacement target node. target = new Binding(Element, ec, properties.TargetRef).ModelItem; } // final check if (target == null) { throw new DOMTargetEventException(Element, Events.BindingException, "Null submission replacement target."); } // Otherwise, those processing instructions and comments replace any processing instructions and comments // that previously appeared outside of the document element of the instance being replaced. target.Replace(response.Body); }
/// <summary> /// Applies all of the known values from the given model item to the current one. /// </summary> /// <param name="item"></param> public void Apply(ModelItem item) { Contract.Requires<ArgumentNullException>(item != null); State.Type = item.State.Type; State.Relevant = item.State.Relevant; State.ReadOnly = item.State.ReadOnly; State.Required = item.State.Required; State.Constraint = item.State.Constraint; State.Valid = item.State.Valid; }