示例#1
0
  /*
   * add a new resource to the node. E.g. the resource temperature or
   * humidity. If the path is /readings/temp, temp will be a subResource
   * of readings, which is a subResource of the node.
   */
  public ResourceBase addNodeResource(String path) {
    Scanner scanner = new Scanner(path);
    scanner.useDelimiter("/");
    String next = "";
    boolean resourceExist = false;
    Resource resource = this; // It's the resource that represents the endpoint

    ResourceBase subResource = null;
    while (scanner.hasNext()) {
      resourceExist = false;
      next = scanner.next();
      for (Resource res : resource.getChildren()) {
        if (res.getName().equals(next)) {
          subResource = (ResourceBase) res;
          resourceExist = true;
        }
      }
      if (!resourceExist) {
        subResource = new RDTagResource(next, true, this);
        resource.add(subResource);
      }
      resource = subResource;
    }
    subResource.setPath(resource.getPath());
    subResource.setName(next);
    scanner.close();
    return subResource;
  }
示例#2
0
  private void buildLinkFormat(Resource resource, StringBuilder builder, List<String> query) {
    if (resource.getChildren().size() > 0) {

      // Loop over all sub-resources
      for (Resource res : resource.getChildren()) {
        // System.out.println(resource.getSubResources().size());
        // System.out.println(res.getName());
        if (LinkFormat.matches(res, query) && res.getAttributes().getCount() > 0) {

          // Convert Resource to string representation and add
          // delimiter
          builder.append(toLinkFormatItem(res));
          builder.append(',');
        }
        // Recurse
        buildLinkFormat(res, builder, query);
      }
    }
  }