Package org.apache.wicket.request.mapper
Class CompoundRequestMapper
- java.lang.Object
-
- org.apache.wicket.request.mapper.CompoundRequestMapper
-
- All Implemented Interfaces:
Iterable<IRequestMapper>
,IRequestMapper
,ICompoundRequestMapper
- Direct Known Subclasses:
SystemMapper
public class CompoundRequestMapper extends Object implements ICompoundRequestMapper
Thread safe compoundIRequestMapper
. The mappers are searched depending on their compatibility score and the orders they were registered. If two or moreIRequestMapper
s have the same compatibility score, the last registered mapper has highest priority.- Author:
- igor.vaynberg, Matej Knopp
-
-
Constructor Summary
Constructors Constructor Description CompoundRequestMapper()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CompoundRequestMapper
add(IRequestMapper mapper)
Registers aIRequestMapper
int
getCompatibilityScore(Request request)
The scope of the compound mapper is the highest score of the registered mappers.Iterator<IRequestMapper>
iterator()
Url
mapHandler(IRequestHandler handler)
Searches the registeredIRequestMapper
s to find one that can map theIRequestHandler
.IRequestHandler
mapRequest(Request request)
Searches the registeredIRequestMapper
s to find one that can map theRequest
.CompoundRequestMapper
remove(IRequestMapper mapper)
Unregisters aIRequestMapper
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
CompoundRequestMapper
public CompoundRequestMapper()
-
-
Method Detail
-
add
public CompoundRequestMapper add(IRequestMapper mapper)
Description copied from interface:ICompoundRequestMapper
Registers aIRequestMapper
- Specified by:
add
in interfaceICompoundRequestMapper
- Returns:
this
for chaining
-
remove
public CompoundRequestMapper remove(IRequestMapper mapper)
Description copied from interface:ICompoundRequestMapper
Unregisters aIRequestMapper
- Specified by:
remove
in interfaceICompoundRequestMapper
- Returns:
this
for chaining
-
mapRequest
public IRequestHandler mapRequest(Request request)
Searches the registeredIRequestMapper
s to find one that can map theRequest
. Each registeredIRequestMapper
is asked to provide its compatibility score. Then the mappers are asked to map the request in order depending on the provided compatibility score.The mapper with highest compatibility score which can map the request is returned.
- Specified by:
mapRequest
in interfaceIRequestMapper
- Parameters:
request
-- Returns:
- RequestHandler for the request or
null
if no mapper for the request is found.
-
mapHandler
public Url mapHandler(IRequestHandler handler)
Searches the registeredIRequestMapper
s to find one that can map theIRequestHandler
. Each registeredIRequestMapper
is asked to map theIRequestHandler
until a mapper which can map theIRequestHandler
is found or no more mappers are left.The mappers are searched in reverse order as they have been registered. More recently registered mappers have bigger priority.
- Specified by:
mapHandler
in interfaceIRequestMapper
- Parameters:
handler
-- Returns:
- Url for the handler or
null
if no mapper for the handler is found.
-
getCompatibilityScore
public int getCompatibilityScore(Request request)
The scope of the compound mapper is the highest score of the registered mappers. Returns the score representing how compatible this request mapper is to processing the given request. When a request comes in all mappers are scored and are tried in order from highest score to lowest.A good criteria for calculating the score is the number of matched url segments. For example when there are two mappers for a mounted page, one mapped to
/foo
another to/foo/bar
and the incoming request URL is /foo/bar/baz, the mapping to/foo/bar
should probably handle the request first as it has matching segments count of 2 while the first one has only matching segments count of 1.Note that the method can return value greater then zero even if the mapper does not recognize the request.
- Specified by:
getCompatibilityScore
in interfaceIRequestMapper
- Returns:
- the compatibility score, e.g. count of matching segments
-
iterator
public Iterator<IRequestMapper> iterator()
- Specified by:
iterator
in interfaceIterable<IRequestMapper>
-
-