public class CompoundRequestMapper extends Object implements ICompoundRequestMapper
IRequestMapper
. The mappers are searched depending on their
compatibility score and the orders they were registered. If two or more IRequestMapper
s
have the same compatibility score, the last registered mapper has highest priority.Constructor and Description |
---|
CompoundRequestMapper() |
Modifier and Type | Method and Description |
---|---|
CompoundRequestMapper |
add(IRequestMapper mapper)
Registers a
IRequestMapper |
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 registered
IRequestMapper s to find one that can map the
IRequestHandler . |
IRequestHandler |
mapRequest(Request request)
Searches the registered
IRequestMapper s to find one that can map the Request . |
CompoundRequestMapper |
remove(IRequestMapper mapper)
Unregisters a
IRequestMapper |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public CompoundRequestMapper add(IRequestMapper mapper)
ICompoundRequestMapper
IRequestMapper
add
in interface ICompoundRequestMapper
this
for chainingpublic CompoundRequestMapper remove(IRequestMapper mapper)
ICompoundRequestMapper
IRequestMapper
remove
in interface ICompoundRequestMapper
this
for chainingpublic IRequestHandler mapRequest(Request request)
IRequestMapper
s to find one that can map the Request
.
Each registered IRequestMapper
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.
mapRequest
in interface IRequestMapper
request
- null
if no mapper for the request is
found.public Url mapHandler(IRequestHandler handler)
IRequestMapper
s to find one that can map the
IRequestHandler
. Each registered IRequestMapper
is asked to map the
IRequestHandler
until a mapper which can map the IRequestHandler
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.
mapHandler
in interface IRequestMapper
handler
- null
if no mapper for the handler is found.public int getCompatibilityScore(Request request)
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.
getCompatibilityScore
in interface IRequestMapper
public Iterator<IRequestMapper> iterator()
iterator
in interface Iterable<IRequestMapper>
Copyright © 2006–2022 Apache Software Foundation. All rights reserved.