public String urlFor(
RequestContext context,
Object key,
Object param) {
Route route = routes.get(key);
if (route != null) {
Map<String, Object> map = new HashMap<String,Object>();
Context ctx = getContext(param);
for (String var : ctx) {
map.put(var, ctx.resolve(var));
}
for (String var : route.getVariables()) {
Object value = context.getTarget().getParameter(var);
if (!map.containsKey(var) && value != null) {
map.put(var, value);
}
}
return context.getTargetBasePath() + route.expand(getContext(map));
} else {
return null;
}
}