/*
* Assert that we have the proper number of parameters.
*/
if (getParameterCount() != parameters.length)
{
throw new PrettyException("Invalid number of path parameters supplied for pattern: " + originalPattern
+ ", expected <" + getParameterCount() + ">, but got <" + parameters.length + ">");
}
/*
* Build the result URL
*/
int paramIndex = 0;
List<String> resultSegments = new ArrayList<String>();
for (Segment segment : pathSegments)
{
String template = segment.getTemplate();
Matcher parameterMatcher = Segment.getTemplateMatcher(template);
StringBuffer sb = new StringBuffer();
while (parameterMatcher.find())
{
String replacement = parameters[paramIndex].toString().replace("$", "\\$");
parameterMatcher.appendReplacement(sb, replacement);
paramIndex++;
}
parameterMatcher.appendTail(sb);
resultSegments.add(sb.toString());
}
result = new URL(resultSegments, urlPattern.getMetadata());
}
else if (getParameterCount() > 0)
{
throw new PrettyException("Invalid number of parameters supplied: " + originalPattern + ", expected <"
+ getParameterCount() + ">, got <0>");
}
return result;
}