简体   繁体   English

在Web-fragment.xml中排序

[英]ordering in Web-fragment.xml

I am preparing for OCEJWCD. 我正在为OCEJWCD做准备。 And I came accorss this question. 我同意这个问题。 And no idea what will be the answer.I thought the correct answer is that the order can not be predicted. 我不知道答案是什么。我认为正确的答案是无法预测顺序。 Which is wrong.Can someone plzz help me to understand it, 哪有错,有人可以帮我理解吗,

Q: In an application there are three web-fragment.xml. 问:在一个应用程序中有三个web-fragment.xml。 Given below. 在下面给出。 At which order these descriptor will be parsed. 这些描述符将以什么顺序进行解析。 Given that there is no absoulte ordering in web.xml. 假定web.xml中没有绝对排序。

Web Fragment A 网页片段A

<web-fragment>
<name>A</name>
<ordering>
    <before>
        <others/>
        <name>B</name>
    </before>
</ordering>

Web-fragment B: 网络片段B:

<web-fragment>
<name>B</name>
<ordering>
    <before>
        <others/>
        <name>C</name>
    </before>
</ordering>

Web-fragment C: 网络片段C:

<web-fragment>
<name>C</name>
<ordering>
    <before>
        <others/>
    </before>
</ordering>

Thanks in advance. 提前致谢。

From the specs 从规格

<before> means the document must be ordered before the document with the name matching what is specified within the nested <name> element. <before>表示必须在名称与嵌套的<name>元素中指定的名称匹配的文档之前对文档进行排序。

There is a special element <others/> which may be included zero or one time within the <before> or <after> element, or zero or one time directly within the <absolute-ordering> element. 有一个特殊元素<others />,它可以在<before>或<after>元素中包含零或一次,或者直接在<absolute-ordering>元素中包含零或一次。 The <others/> element must be handled as follows. <others />元素必须按以下方式处理。

If the <before> element contains a nested <others/>, the document will be moved to the beginning of the list of sorted documents. 如果<before>元素包含嵌套的<others />,则文档将被移到已排序文档列表的开头。 If there are multiple documents stating <before><others/>, they will all be at the beginning of the list of sorted documents, but the ordering within the group of such documents is unspecified. 如果有多个文档说明<before> <others />,它们都将位于已排序文档列表的开头, 但是未指定此类文档中的顺序。

This clearly says that the ordering between A,B and C is not deterministic. 这清楚地表明,A,B和C之间的顺序不是确定的。

But then there is this section 但是接下来是本节

Within a <before> or <after> element, if an <others/> element is present, but is not the only <name> element within its parent element, the other elements within that parent must be considered in the ordering process. 在<before>或<after>元素中,如果存在<others />元素, 但不是其父元素中唯一的<name>元素,则在排序过程中必须考虑该父元素中的其他元素。

Now both A and B fall into this category where their web fragments have a <name> element besides <others/>. 现在,A和B都属于此类别,它们的Web片段除<others />之外还具有<name>元素。 And in this case, the spec says that the other elements have to be considered in the ordering process. 并且在这种情况下,规范指出在订购过程中必须考虑其他元素。 So A should be before B and B should be before C. Voila, its deterministic now and the order would be 因此,A应该在B之前,而B应该在C. Voila之前,现在它的确定性是

  1. A 一种
  2. B
  3. C C

To test, we can write 3 filters and define one in each web fragment and check the order of loading. 为了进行测试,我们可以编写3个过滤器,并在每个Web片段中定义一个过滤器,并检查加载顺序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM