|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface SwitchSelector
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.
Field Summary | |
---|---|
static String |
ROLE
|
Method Summary | |
---|---|
Object |
getSelectorContext(Map objectModel,
Parameters parameters)
Method to create a selector context. |
boolean |
select(String expression,
Object selectorContext)
Switch Selectors test patterns against a context object and signal success with the returned boolean value |
Methods inherited from interface org.apache.cocoon.selection.Selector |
---|
select |
Field Detail |
---|
static final String ROLE
Method Detail |
---|
Object getSelectorContext(Map objectModel, Parameters parameters)
objectModel
- The Map
containing object of the
calling environment which may be used
to select values to test the expression.parameters
- The sitemap parameters, as specified by
<parameter/> tags.
boolean select(String expression, Object selectorContext)
expression
- The expression to test.selectorContext
- The context this test should be performed in.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |