{
PageParameters pageParameters = attributesWrapper.getPageParameters();
List<MethodMappingInfo> mappedMethodsCandidates = mappedMethods.get(pageParameters.getIndexedCount() +
"_" + attributesWrapper.getHttpMethod());
ScoreMethodAndExtractPathVars highiestScoredMethod = null;
// no method mapped
if (mappedMethodsCandidates == null || mappedMethodsCandidates.size() == 0)
return null;
/**
* To select the "best" method, a score is assigned to every mapped method. To calculate the
* score method calculateScore is executed for every segment.
*/
int highestScore = 0;
for (MethodMappingInfo mappedMethod : mappedMethodsCandidates)
{
ScoreMethodAndExtractPathVars scoredMethod =
new ScoreMethodAndExtractPathVars(mappedMethod, pageParameters);
for (AbstractURLSegment segment : mappedMethod.getSegments())
{
segment.accept(scoredMethod);
if(!scoredMethod.isSegmentValid())
{
break;
}
}
if(highestScore > 0 && scoredMethod.getScore() == highestScore)
{
// if we have more than one method with the highest score, throw
// ambiguous exception.
throwAmbiguousMethodsException(scoredMethod, highiestScoredMethod);
}
if (scoredMethod.getScore() >= highestScore)
{
highestScore = scoredMethod.getScore();
highiestScoredMethod = scoredMethod;
}
}
return highiestScoredMethod;