MethodExpression expression = new MethodExpression(root, "", invoker); root.addExpression(expression); return expression; MethodExpression expression = new MethodExpression(root, "", invoker, "(.*)"); root.addExpression(expression); return expression; exp = new MethodExpression(node, path, invoker); exp = new MethodExpression(node, path, invoker, "(/.+)?"); exp = new MethodExpression(node, path, invoker); node.addExpression(exp); exp = new MethodExpression(node, path, invoker, "(.*)"); node.addExpression(exp);
if (expressionMatched && expression.isLocator()) { logger.log("MATCH_PATH_SKIPPED", expression.getRegex()); continue; Pattern pattern = expression.getPattern(); Matcher matcher = pattern.matcher(path); matcher.region(start, path.length()); ResourceInvoker invoker = expression.getInvoker(); if (invoker instanceof ResourceLocatorInvoker) int length = matcher.start(expression.getNumGroups() + 1); if (length == -1) Pattern p = expression.getPattern(); Matcher m = p.matcher(path); m.region(start, path.length()); expression.populatePathParams(request, matcher, path); logger.log("MATCH_LOCATOR", invoker.getMethod()); return invoker; logger.log("MATCH_PATH_NOT_MATCHED", expression.getRegex()); match.expression.populatePathParams(request, match.matcher, path); logger.log("MATCH_PATH_SELECTED", match.expression.getRegex()); return match.expression.getInvoker();
public void potentials(String path, int start, List<MethodExpression> matches) { if (start == path.length()) // we've reached end of string { matches.addAll(targets); return; } if (start < path.length()) { String simpleSegment = null; int endOfSegmentIndex = path.indexOf('/', start); if (endOfSegmentIndex > -1) simpleSegment = path.substring(start, endOfSegmentIndex); else simpleSegment = path.substring(start); SegmentNode child = children.get(simpleSegment); if (child != null) { int next = start + simpleSegment.length(); if (endOfSegmentIndex > -1) next++; // go past '/' child.potentials(path, next, matches); } } for (MethodExpression exp : targets) { // skip any static matches as they will not match anyways if (exp.getNumGroups() > 0 || exp.getInvoker() instanceof ResourceLocatorInvoker) { matches.add(exp); } } }
public MultivaluedMap<String, ResourceInvoker> getBounded() { MultivaluedHashMap<String, ResourceInvoker> rtn = new MultivaluedHashMap<String, ResourceInvoker>(); for (Map.Entry<String, List<MethodExpression>> entry : bounded.entrySet()) { for (MethodExpression exp : entry.getValue()) { rtn.add(entry.getKey(), exp.getInvoker()); } } return rtn; }
@Override public int compareTo(SortEntry o) { if (consumes.isWildcardType() && !o.consumes.isWildcardType()) return 1; if (!consumes.isWildcardType() && o.consumes.isWildcardType()) return -1; if (consumes.isWildcardSubtype() && !o.consumes.isWildcardSubtype()) return 1; if (!consumes.isWildcardSubtype() && o.consumes.isWildcardSubtype()) return -1; if (consumes.q > o.consumes.q) return -1; if (consumes.q < o.consumes.q) return 1; if (consumes.qs > o.consumes.qs) return -1; if (consumes.qs < o.consumes.qs) return 1; if (consumes.d < o.consumes.d) return -1; if (consumes.d > o.consumes.d) return 1; if (consumes.dm < o.consumes.dm) return -1; if (consumes.dm > o.consumes.dm) return 1; if (produces.isWildcardType() && !o.produces.isWildcardType()) return 1; if (!produces.isWildcardType() && o.produces.isWildcardType()) return -1; if (produces.isWildcardSubtype() && !o.produces.isWildcardSubtype()) return 1; if (!produces.isWildcardSubtype() && o.produces.isWildcardSubtype()) return -1; if (produces.q > o.produces.q) return -1; if (produces.q < o.produces.q) return 1; if (produces.qs > o.produces.qs) return -1; if (produces.qs < o.produces.qs) return 1; if (produces.d < o.produces.d) return -1; if (produces.d > o.produces.d) return 1; if (produces.dm < o.produces.dm) return -1; if (produces.dm > o.produces.dm) return 1; return match.expression.compareTo(o.match.expression); } }
SortEntry a; SortEntry b = it.next(); Method first = b.match.expression.getInvoker().getMethod(); while (it.hasNext()) s.add(first); s.add(b.match.expression.getInvoker().getMethod());
public void potentials(String path, int start, List<MethodExpression> matches) { if (start == path.length()) // we've reached end of string { matches.addAll(targets); return; } if (start < path.length()) { String simpleSegment = null; int endOfSegmentIndex = path.indexOf('/', start); if (endOfSegmentIndex > -1) simpleSegment = path.substring(start, endOfSegmentIndex); else simpleSegment = path.substring(start); SegmentNode child = children.get(simpleSegment); if (child != null) { int next = start + simpleSegment.length(); if (endOfSegmentIndex > -1) next++; // go past '/' child.potentials(path, next, matches); } } for (MethodExpression exp : targets) { // skip any static matches as they will not match anyways if (exp.getNumGroups() > 0 || exp.getInvoker() instanceof ResourceLocatorInvoker) { matches.add(exp); } } }
@Override public int compareTo(SortEntry o) { if (consumes.isWildcardType() && !o.consumes.isWildcardType()) return 1; if (!consumes.isWildcardType() && o.consumes.isWildcardType()) return -1; if (consumes.isWildcardSubtype() && !o.consumes.isWildcardSubtype()) return 1; if (!consumes.isWildcardSubtype() && o.consumes.isWildcardSubtype()) return -1; if (consumes.q > o.consumes.q) return -1; if (consumes.q < o.consumes.q) return 1; if (consumes.qs > o.consumes.qs) return -1; if (consumes.qs < o.consumes.qs) return 1; if (consumes.d < o.consumes.d) return -1; if (consumes.d > o.consumes.d) return 1; if (consumes.dm < o.consumes.dm) return -1; if (consumes.dm > o.consumes.dm) return 1; if (produces.isWildcardType() && !o.produces.isWildcardType()) return 1; if (!produces.isWildcardType() && o.produces.isWildcardType()) return -1; if (produces.isWildcardSubtype() && !o.produces.isWildcardSubtype()) return 1; if (!produces.isWildcardSubtype() && o.produces.isWildcardSubtype()) return -1; if (produces.q > o.produces.q) return -1; if (produces.q < o.produces.q) return 1; if (produces.qs > o.produces.qs) return -1; if (produces.qs < o.produces.qs) return 1; if (produces.d < o.produces.d) return -1; if (produces.d > o.produces.d) return 1; if (produces.dm < o.produces.dm) return -1; if (produces.dm > o.produces.dm) return 1; return match.expression.compareTo(o.match.expression); } }
if (expressionMatched && expression.isLocator()) continue; Pattern pattern = expression.getPattern(); Matcher matcher = pattern.matcher(path); matcher.region(start, path.length()); ResourceInvoker invoker = expression.getInvoker(); if (invoker instanceof ResourceLocatorInvoker) int length = matcher.start(expression.getNumGroups() + 1); if (length == -1) Pattern p = expression.getPattern(); Matcher m = p.matcher(path); m.region(start, path.length()); uriInfo.pushMatchedURI(substring); expression.populatePathParams(request, matcher, path); return invoker; match.expression.populatePathParams(request, match.matcher, path); return match.expression.getInvoker();
public void removeBinding(String path, Method method) { List<MethodExpression> expressions = bounded.get(path); if (expressions == null) return; for (MethodExpression expression : expressions) { ResourceInvoker invoker = expression.getInvoker(); if (invoker.getMethod().equals(method)) { expression.parent.targets.remove(expression); expressions.remove(expression); if (expressions.size() == 0) bounded.remove(path); size--; if (invoker instanceof ResourceMethodInvoker) { ((ResourceMethodInvoker)invoker).cleanup(); } return; } } }
public void potentials(String path, int start, List<MethodExpression> matches) { if (start == path.length()) // we've reached end of string { matches.addAll(targets); return; } if (start < path.length()) { String simpleSegment = null; int endOfSegmentIndex = path.indexOf('/', start); if (endOfSegmentIndex > -1) simpleSegment = path.substring(start, endOfSegmentIndex); else simpleSegment = path.substring(start); SegmentNode child = children.get(simpleSegment); if (child != null) { int next = start + simpleSegment.length(); if (endOfSegmentIndex > -1) next++; // go past '/' child.potentials(path, next, matches); } } for (MethodExpression exp : targets) { // skip any static matches as they will not match anyways if (exp.getNumGroups() > 0 || exp.getInvoker() instanceof ResourceLocatorInvoker) { matches.add(exp); } } }
@Override public int compareTo(SortEntry o) { if (consumes.isWildcardType() && !o.consumes.isWildcardType()) return 1; if (!consumes.isWildcardType() && o.consumes.isWildcardType()) return -1; if (consumes.isWildcardSubtype() && !o.consumes.isWildcardSubtype()) return 1; if (!consumes.isWildcardSubtype() && o.consumes.isWildcardSubtype()) return -1; if (consumes.q > o.consumes.q) return -1; if (consumes.q < o.consumes.q) return 1; if (consumes.qs > o.consumes.qs) return -1; if (consumes.qs < o.consumes.qs) return 1; if (consumes.d < o.consumes.d) return -1; if (consumes.d > o.consumes.d) return 1; if (consumes.dm < o.consumes.dm) return -1; if (consumes.dm > o.consumes.dm) return 1; if (produces.isWildcardType() && !o.produces.isWildcardType()) return 1; if (!produces.isWildcardType() && o.produces.isWildcardType()) return -1; if (produces.isWildcardSubtype() && !o.produces.isWildcardSubtype()) return 1; if (!produces.isWildcardSubtype() && o.produces.isWildcardSubtype()) return -1; if (produces.q > o.produces.q) return -1; if (produces.q < o.produces.q) return 1; if (produces.qs > o.produces.qs) return -1; if (produces.qs < o.produces.qs) return 1; if (produces.d < o.produces.d) return -1; if (produces.d > o.produces.d) return 1; if (produces.dm < o.produces.dm) return -1; if (produces.dm > o.produces.dm) return 1; return match.expression.compareTo(o.match.expression); } }
MethodExpression expression = new MethodExpression(root, "", invoker); root.addExpression(expression); return expression; MethodExpression expression = new MethodExpression(root, "", invoker, "(.*)"); root.addExpression(expression); return expression; exp = new MethodExpression(node, path, invoker); exp = new MethodExpression(node, path, invoker, "(/.+)?"); exp = new MethodExpression(node, path, invoker); node.addExpression(exp); exp = new MethodExpression(node, path, invoker, "(.*)"); node.addExpression(exp);
if (expressionMatched && expression.isLocator()) { logger.log("MATCH_PATH_SKIPPED", expression.getRegex()); continue; Pattern pattern = expression.getPattern(); Matcher matcher = pattern.matcher(path); matcher.region(start, path.length()); ResourceInvoker invoker = expression.getInvoker(); if (invoker instanceof ResourceLocatorInvoker) int length = matcher.start(expression.getNumGroups() + 1); if (length == -1) Pattern p = expression.getPattern(); Matcher m = p.matcher(path); m.region(start, path.length()); expression.populatePathParams(request, matcher, path); logger.log("MATCH_LOCATOR", invoker.getMethod()); return invoker; logger.log("MATCH_PATH_NOT_MATCHED", expression.getRegex()); match.expression.populatePathParams(request, match.matcher, path); logger.log("MATCH_PATH_SELECTED", match.expression.getRegex()); return match.expression.getInvoker();
ResourceMethodInvoker invoker = (ResourceMethodInvoker) match.expression.getInvoker(); if (invoker.getHttpMethods().contains(httpMethod.toUpperCase())) for (Match match : matches) allowed.addAll(((ResourceMethodInvoker) match.expression.getInvoker()).getHttpMethods()); for (Match match : matches) if (((ResourceMethodInvoker) match.expression.getInvoker()).getHttpMethods().contains("PATCH")) patchAccepts.addAll(Arrays.asList(((ResourceMethodInvoker) match.expression.getInvoker()) .getConsumes())); for (Match match : list) ResourceMethodInvoker invoker = (ResourceMethodInvoker) match.expression.getInvoker(); if (contentType == null) contentType = MediaType.WILDCARD_TYPE; final Method m = match.expression.getInvoker().getMethod(); sortList.add(new SortEntry(match, consume, sortFactor, produce));
MethodExpression expression = new MethodExpression(root, "", invoker); root.addExpression(expression); return expression; MethodExpression expression = new MethodExpression(root, "", invoker, "(.*)"); root.addExpression(expression); return expression; exp = new MethodExpression(node, path, invoker); exp = new MethodExpression(node, path, invoker, "(/.+)?"); exp = new MethodExpression(node, path, invoker); node.addExpression(exp); exp = new MethodExpression(node, path, invoker, "(.*)"); node.addExpression(exp);
public MultivaluedMap<String, ResourceInvoker> getBounded() { MultivaluedHashMap<String, ResourceInvoker> rtn = new MultivaluedHashMap<String, ResourceInvoker>(); for (Map.Entry<String, List<MethodExpression>> entry : bounded.entrySet()) { for (MethodExpression exp : entry.getValue()) { rtn.add(entry.getKey(), exp.getInvoker()); } } return rtn; }
public MultivaluedMap<String, ResourceInvoker> getBounded() { MultivaluedHashMap<String, ResourceInvoker> rtn = new MultivaluedHashMap<String, ResourceInvoker>(); for (Map.Entry<String, List<MethodExpression>> entry : bounded.entrySet()) { for (MethodExpression exp : entry.getValue()) { rtn.add(entry.getKey(), exp.getInvoker()); } } return rtn; }
SortEntry a; SortEntry b = it.next(); Method first = b.match.expression.getInvoker().getMethod(); while (it.hasNext()) s.add(first); s.add(b.match.expression.getInvoker().getMethod());
public void removeBinding(String path, Method method) { List<MethodExpression> expressions = bounded.get(path); if (expressions == null) return; for (MethodExpression expression : expressions) { ResourceInvoker invoker = expression.getInvoker(); if (invoker.getMethod().equals(method)) { expression.parent.targets.remove(expression); expressions.remove(expression); if (expressions.size() == 0) bounded.remove(path); size--; if (invoker instanceof ResourceMethodInvoker) { ((ResourceMethodInvoker)invoker).cleanup(); } return; } } }