Class FragmentResult


  • public abstract class FragmentResult
    extends Object
    Represents an outcome of template fragment. We use this to hide difference between TF that produce single node and collection of nodes. Besides, we keep TF parent's containment link needed for weave scenario (during weave, there's supplied parent node, and knowledge about specific aggregations comes from TF's parent node, while during regular apply, all TFs in template are assumed (there's checking rule to ensure that) to be under same parent AND aggregation. As there's no distinction between templates for WEAVE and CALL, effectively WEAVE can not inject TF nodes into different aggregation links, though it pretends it does. (well, one can ignore errors in templates and get TF with different aggregation links).

    XXX Though I like the idea of templates being functional and side-effect free supplier of new nodes, I find possibility to have single template with fragments for different aggregation roles appealing. Besides, I'd like uniformity for WEAVE and CALL templates, and though different aggregations for weave don't work now (due to checking rule), there's code already that supports scenario of different aggregation roles and it's a pity to throw it away. HOWEVER, shall not forget about 'in-line' templates where no aggregation link is available. Therefore, I plan to use this FragmentResult to experiment with alternatives for TemplateDeclaration#apply. First, FragmentResult would help to streamline implementation of apply and weave, I'd like to keep differences between the two minimal. After all, there's Perhaps, in the future, a composite object with FragmentResult may replace #apply() return value (now Collection<SNode>) and there'd be no need for explicit TemplateDeclarationWeavingAware2.weave(WeaveContext, NodeWeaveFacility), return value of apply would give a chance for outer code to control whether to apply or to weave TF outcome nodes.

    XXX If there's ever a handy way to generate sequence of optional calls a.first().second().third(), might be reasonable to return this from methods to get nice nodeFragment(tnode1).label("").reportTo() lines without intermediate local variables. Check TemplateDeclarationWeavingAware2 for extra stuff.

    Since:
    2018.2