The Compile Process
PRELIMINARY INFORMATION - SUBJECT TO CHANGE
The XFormsCompiler class is responsible for generating an XForm object, which hosts a static tree representation of the XForms state at any given moment.
The XFormsCompiler is always created using an XFormsCompilerSettings object. This settings object interfaces between the hosting environment and the XFormsCompiler.
Here's a (highly simplified) flow:
Example:
C# | Copy Code |
---|---|
XFormsCompilerSettings settings = new XFormsCompilerSettings(); (set settings...) XFormsCompiler compiler = XFormsCompiler.Create(this.CompilerSettings); XForm form = compiler.Compile(); |
An XFormsRenderDevice object can then be used to produce/update a representation of this compiled form and present it to the user.
Example:
C# | Copy Code |
---|---|
XFormsEnrichedHTML5RenderDevice device = new XFormsEnrichedHTML5RenderDevice(this.Context.Request.Url, this.Context.Request.Form, json); object data = device.Render(compiler, form, false); |
The XFormsCompilerSettings class
As we said, this object interfaces between the hosting environment and the XFormsCompiler. For instance, it provides a number of delegate properties that can be set to methods in the host, that will be called during form compilation.
The LoadResource delegate
This delegate method will be called anytime the XForms Compiler tries to load a resource required by the XForms runtime.
This can occur when schemas, instances and other data is referenced by the document, such as here:
XML | Copy Code |
---|---|
<xf:instance resource="/myform/my_default_instance.xml" /> |
Example:
C# | Copy Code |
---|---|
XFormsCompilerSettings settings = new XFormsCompilerSettings(); settings.LoadResource = LoadMyResource; (...) // Used to load a resource required by the current form at runtime. void LoadResource(object sender, XFormsHostEventArgs e) { string path = (string)e.GetParameter(); if (path.IndexOf('/') == -1) { string subFolder = this.Url.GetComponents(UriComponents.Path, UriFormat.SafeUnescaped); int p = subFolder.LastIndexOf('/'); subFolder = subFolder.Substring(0, p+1); path = "/" + subFolder + path; } Uri url = new Uri(this.Context.Request.Url, path); e.Result = XFormsUtils.GetStream(LoadResource(url)); } |