SwitchSelector is an enhanced Selector interface that allows a
context object to be created to optimize selector conditional testing.
The original Selector interface supports an if-then-else style
of conditional testing depending on whether a particular expression is true.
This causes Selector.select() to be invoked for each <map:when>
statement which may be undesirable due to performance or logic reasons.
Example, the following sitemap snippet:
<map:select type="aSelector">
<map:when test="test-expr1">...</map:when>
<map:when test="test-expr2">...</map:when>
</map:select>
is interpreted as (pseudo-code):
if (aSelector.select("test-expr1", objectModel, params)) {
...
} else if (aSelector.select("test-expr2", objectModel, params)) {
...
}
ie. aSelector.select(...) is called once for each <map:when>
statement.
SwitchSelector allows the developer to first create a
context object which is passed with each call to select(). This context
object is created before any conditional tests are made, and hence can be
used to optimize conditional testing.
The above example implemented as a SwitchSelector would be
interpreted as (psuedo-code):
Object selectorContext = aSelector.getSelectorContext(objectModel, params);
if (aSelector.select("test-expr1", selectorContext)) {
...
else if (aSelector.select("test-expr2", selectorContext)) {
...
}
ie. the bulk of the selector's work is done in getSelectorContext(),
select() simply compares whether the expression should be considered true.
author: Marcus Crafter author: Sylvain Wallez version: CVS $Id: SwitchSelector.java 433543 2006-08-22 06:22:54Z crossley $ |