org.apache.wicket.request.mapper
Class CompoundRequestMapper

java.lang.Object
  extended by 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 compound IRequestMapper. The mappers are searched depending on their compatibility score and the orders they were registered. If two or more IRequestMappers have the same compatibility score, the last registered mapper has highest priority.

Author:
igor.vaynberg, Matej Knopp

Constructor Summary
CompoundRequestMapper()
          Construct.
 
Method Summary
 CompoundRequestMapper add(IRequestMapper encoder)
          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 IRequestMappers to find one that can encode the IRequestHandler.
 IRequestHandler mapRequest(Request request)
          Searches the registered IRequestMappers to find one that can decode the Request.
 CompoundRequestMapper remove(IRequestMapper encoder)
          Unregisters IRequestMapper
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompoundRequestMapper

public CompoundRequestMapper()
Construct.

Method Detail

add

public CompoundRequestMapper add(IRequestMapper encoder)
Description copied from interface: ICompoundRequestMapper
Registers a IRequestMapper

Specified by:
add in interface ICompoundRequestMapper
Returns:
this for chaining
See Also:
ICompoundRequestMapper.add(org.apache.wicket.request.IRequestMapper)

remove

public CompoundRequestMapper remove(IRequestMapper encoder)
Description copied from interface: ICompoundRequestMapper
Unregisters IRequestMapper

Specified by:
remove in interface ICompoundRequestMapper
Returns:
this for chaining
See Also:
ICompoundRequestMapper.remove(org.apache.wicket.request.IRequestMapper)

mapRequest

public IRequestHandler mapRequest(Request request)
Searches the registered IRequestMappers to find one that can decode the Request. Each registered IRequestMapper is asked to provide the matching segments count. Then the encoders are asked to decode the request in order depending on the provided segments count.

The encoder with highest matching segments count that can decode the request is returned.

Specified by:
mapRequest in interface IRequestMapper
Parameters:
request -
Returns:
RequestHandler for the request or null if no encoder for the request is found.

mapHandler

public Url mapHandler(IRequestHandler handler)
Searches the registered IRequestMappers to find one that can encode the IRequestHandler. Each registered IRequestMapper is asked to encode the IRequestHandler until an encoder that can encode the IRequestHandler is found or no more encoders are left.

The handlers are searched in reverse order as they have been registered. More recently registered handlers have bigger priority.

Specified by:
mapHandler in interface IRequestMapper
Parameters:
handler -
Returns:
Url for the handler or null if no encoder 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 encoders for mounted page, one mapped to /foo another to /foo/bar and the incoming request URL is /foo/bar/baz, the encoder mapped to /foo/bar will 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 encoder can not decode the request.

Specified by:
getCompatibilityScore in interface IRequestMapper
Returns:
count of matching segments

iterator

public Iterator<IRequestMapper> iterator()

Specified by:
iterator in interface Iterable<IRequestMapper>


Copyright © 2004-2011 Apache Software Foundation. All Rights Reserved.