Package ch.ethz.inf.vs.californium.server.resources

Examples of ch.ethz.inf.vs.californium.server.resources.Resource$ResourceTreeBuilder


  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;
  }
View Full Code Here


    System.out.println(endpointQuery);
       
    query.removeAll(toRemove);
   
    while (resIt.hasNext()){
      Resource res = resIt.next();
      if (res.getClass() == RDNodeResource.class){
        RDNodeResource node = (RDNodeResource) res;
        if ( (domainQuery.isEmpty() || domainQuery.equals(node.getDomain())) &&
           (endpointQuery.isEmpty() || endpointQuery.equals(node.getEndpointIdentifier())) ) {
          String link = node.toLinkFormat(query);
          result += (!link.isEmpty()) ? link+"," : "";
View Full Code Here

            break;
          }
        }
      }
      while (!todo.isEmpty()) {
        Resource current = todo.pop();
        if (current.getAttributes().containsAttribute("ep")) {
          targets.add(current);
        }
        for (Resource child : current.getChildren()) {
          todo.add(child);
        }
      }

    }
View Full Code Here

      tail = path.substring(pos + 1);
    } else {
      head = path;
    }

    Resource sub = root.getChild(head);

    if (sub != null) {
      return getSubResource(sub, tail);
    } else {
      return null;
View Full Code Here

  private Set<RDTagResource> getSubResourceWithTags(HashMap<String, String> tags, Resource start) {
    LinkedList<Resource> toDo = new LinkedList<Resource>();
    toDo.add(start);
    HashSet<RDTagResource> result = new HashSet<RDTagResource>();
    while (!toDo.isEmpty()) {
      Resource current = toDo.pop();
      if (current.getClass() == RDTagResource.class) {
        if (((RDTagResource) current).containsMultipleTags(tags)) {
          result.add((RDTagResource) current);
        }
      }
      toDo.addAll(current.getChildren());
    }
    return result;
  }
View Full Code Here

    }
   
    Iterator<Resource>  resIt = resources.iterator();
   
    while (resIt.hasNext()){
      Resource res = resIt.next();
      if (res.getClass() == RDNodeResource.class){
        RDNodeResource node = (RDNodeResource) res;
        if ( (domainQuery.isEmpty() || domainQuery.equals(node.getDomain())) &&
           (endpointQuery.isEmpty() || endpointQuery.equals(node.getEndpointIdentifier())) &&
           (endpointTypeQuery.isEmpty() || endpointTypeQuery.contains(node.getEndpointType()))) {
       
View Full Code Here

      if (attr.getName().equals(LinkFormat.DOMAIN))
        domainQuery = attr.getValue();
    }
   
    while (resIt.hasNext()){
      Resource res = resIt.next();
      if (res.getClass() == RDNodeResource.class){
        RDNodeResource node = (RDNodeResource) res;
        if ((domainQuery.isEmpty() || domainQuery.equals(node.getDomain()))){
          availableDomains.add(node.getDomain());
        }
      }
View Full Code Here

      if (actualDiscovery == "") {
        System.err.println("Empty Link Format, check manually");
        return false;
      }

      Resource res = LinkParser.parseTree(actualDiscovery);

      List<String> query = Arrays.asList(expextedAttribute);

      boolean success = true;

      for (Resource sub : res.getChildren()) {

        // goes to leaf resource -- necessary?
        while (sub.getChildren().size() > 0) {
          sub = sub.getChildren().iterator().next();
        }
View Full Code Here

   */
  @Override
  public void deliverRequest(final Exchange exchange) {
    Request request = exchange.getRequest();
    List<String> path = request.getOptions().getURIPaths();
    final Resource resource = findResource(path);
    if (resource != null) {
      checkForObserveOption(exchange, resource);
     
      // Get the executor and let it process the request
      Executor executor = resource.getExecutor();
      if (executor != null) {
        executor.execute(new Runnable() {
          public void run() {
            resource.handleRequest(exchange);
          } });
      } else {
        resource.handleRequest(exchange);
      }
    } else {
      LOGGER.info("Did not find resource " + path.toString());
      exchange.sendResponse(new Response(ResponseCode.NOT_FOUND));
    }
View Full Code Here

   * @param list the path as list of resource names
   * @return the resource or null if not found
   */
  private Resource findResource(List<String> list) {
    LinkedList<String> path = new LinkedList<String>(list);
    Resource current = root;
    while (!path.isEmpty() && current != null) {
      String name = path.removeFirst();
      current = current.getChild(name);
    }
    return current;
  }
View Full Code Here

TOP

Related Classes of ch.ethz.inf.vs.californium.server.resources.Resource$ResourceTreeBuilder

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.