I am preparing for 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. Given below. At which order these descriptor will be parsed. Given that there is no absoulte ordering in web.xml.
Web Fragment A
<web-fragment>
<name>A</name>
<ordering>
<before>
<others/>
<name>B</name>
</before>
</ordering>
Web-fragment B:
<web-fragment>
<name>B</name>
<ordering>
<before>
<others/>
<name>C</name>
</before>
</ordering>
Web-fragment 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.
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. The <others/> element must be handled as follows.
If the <before> element contains a nested <others/>, the document will be moved to the beginning of the list of sorted documents. 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.
This clearly says that the ordering between A,B and C is not deterministic.
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.
Now both A and B fall into this category where their web fragments have a <name> element besides <others/>. 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
To test, we can write 3 filters and define one in each web fragment and check the order of loading.