Package org.jrest4guice.rest

Examples of org.jrest4guice.rest.ServiceRoute


   * @param resourceClass
   *            资源对应的实现类
   */
  public void addResource(String uri, Class resourceClass,
      boolean processMethod) {
    ServiceRoute current = this.doAddResource(uri, resourceClass, root,
        null);
    if (!processMethod)
      return;

    this.addResourceByClassMethodInfo(resourceClass, current);
View Full Code Here


    // 如果URI以"/"开头,则将当前的父结点指向root
    if (uri.startsWith("/"))
      parent = root;

    String[] routePath = uri.split("/");
    ServiceRoute current = parent;
    ServiceRoute child = null;
    for (String s : routePath) {
      s = s.trim();
      if ("".equals(s))
        continue;
      child = current.getRouteChild(s);
      Matcher matcher = paramPattern.matcher(s);
      if (matcher.matches()) {// 处理参数类型的路由节点
        child = new ServiceRoute(matcher.group(1));
        current.addParamChild(PARAM_KEY, child);
      } else {// 处理变通类型的路由节点(只有最末端的节点才会绑定到服务)
        if (child == null)
          child = new ServiceRoute();
        current.addRouteChild(s, child);
      }

      current = child;
    }
View Full Code Here

   * @param params
   * @return
   */
  public Service lookupResource(String uri) {
    String[] routePath = uri.split("/");
    ServiceRoute current = root;
    ServiceRoute child = null;
    List<ServiceRoute> paramChild = null;
    int index = 0;
    int len = routePath.length;
    for (String path : routePath) {
      index++;

      if (current == null)
        break;

      path = path.trim();
      if ("".equals(path))
        continue;

      paramChild = current.getParamChild(PARAM_KEY);
      if (paramChild != null) {
        for (ServiceRoute p : paramChild)
          RestContextManager.getModelMap()
              .put(p.getParamName(), path);
      }

      child = current.getRouteChild(path);
      if (child == null && paramChild != null && index < len) {
        child = this.lookupNextRoute(routePath[index], paramChild);
      }

      if (child == null && paramChild != null) {
        child = this.lookupNextRoute(null, paramChild);
      }

      ServiceRoute parent = current.getParent();
      if (child == null
          && (parent != null && this.hasRouteNode(path, parent
              .getRouteChildren()))) {
        continue;
      }

      current = child;
View Full Code Here

    return result;
  }

  private ServiceRoute lookupNextRoute(String nodeName,
      List<ServiceRoute> paramChild) {
    ServiceRoute route = null;
    Map<String, ServiceRoute> routeChildren;
    top: for (ServiceRoute r : paramChild) {
      routeChildren = r.getRouteChildren();
      if (routeChildren.size() > 0) {
        for (String key : routeChildren.keySet()) {
View Full Code Here

TOP

Related Classes of org.jrest4guice.rest.ServiceRoute

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.