private RouteMeta getByFullClassAndName(String name) { RouteMeta meta = fullClassAndNameToRoute.get(name); if(meta == null) throw new RouteNotFoundException("route="+name+" not found."); return meta; }
private RouteMeta getByName(String name) { if(duplicateNames.contains(name)) { Set<RouteId> keySet = routeIdToRoute.keySet(); String routes = ""; for(RouteId id : keySet) { if(name.equals(id.name())) routes += "\nroute="+id.getClass(); } throw new RouteNotFoundException("There is more than one route matching the name. Qualify it with the class like XXXRouteId." +name+". Same names are found in these enum classes="+routes); } RouteMeta routeMeta = routeNameToRoute.get(name); if(routeMeta == null) throw new RouteNotFoundException("route="+name+" not found."); return routeMeta; }
private RouteMeta getByClassAndName(String name) { if(duplicateClassAndNames.contains(name)) { Set<RouteId> keySet = routeIdToRoute.keySet(); String routes = ""; for(RouteId id : keySet) { String potentialName = id.getClass().getSimpleName()+"."+id.name(); if(name.equals(potentialName)) routes += "\nroute="+id.getClass().getName()+"."+id.name(); } throw new RouteNotFoundException("There is more than one route matching the class and name. Qualify it with the package like org.web." +name+". These are the conflicting ids which is why you need to be more specific="+routes); } RouteMeta routeMeta = classAndNameToRoute.get(name); if(routeMeta == null) throw new RouteNotFoundException("route="+name+" not found"); return routeMeta; }
public String convertToUrl(String routeId, Map<String, String> args, boolean isValidating) { RouteMeta routeMeta = get(routeId); Route route = routeMeta.getRoute(); String urlPath = route.getFullPath(); List<String> pathParamNames = route.getPathParamNames(); for(String param : pathParamNames) { String val = args.get(param); if(val == null) { String strArgs = ""; for(Entry<String, String> entry : args.entrySet()) { boolean equals = entry.getKey().equals(param); strArgs = " ARG:'"+entry.getKey()+"'='"+entry.getValue()+"' equals="+equals+"\n"; } throw new RouteNotFoundException("missing argument. param="+param+" is required" + " to exist(and cannot be null as well). route="+routeId+" args="+strArgs); } String encodedVal = urlEncode(val); urlPath = urlPath.replace("{"+param+"}", encodedVal); } if(isValidating) return urlPath; return createUrl(route, urlPath); }