/* (non-Javadoc)
  * @see org.eclipse.californium.core.server.resources.Resource#add(org.eclipse.californium.core.server.resources.Resource)
  */
 @Override
 public synchronized void add(Resource child) {
   if (child.getName() == null) throw new NullPointerException("Child must have a name");
   if (child.getParent() != null) child.getParent().delete(child);
   children.put(child.getName(), child);
   child.setParent(this);
   for (ResourceObserver obs : observers) obs.addedChild(child);
 }
  /**
   * Delete this resource from its parents and notify all observing CoAP clients that this resource
   * is no longer accessible.
   */
  public synchronized void delete() {
    Resource parent = getParent();
    if (parent != null) {
      parent.delete(this);
    }

    if (isObservable()) {
      clearAndNotifyObserveRelations(ResponseCode.NOT_FOUND);
    }
  }
 /* (non-Javadoc)
  * @see org.eclipse.californium.core.server.resources.Resource#delete(org.eclipse.californium.core.server.resources.Resource)
  */
 @Override
 public synchronized boolean delete(Resource child) {
   Resource deleted = delete(child.getName());
   if (deleted == child) {
     child.setParent(null);
     child.setPath(null);
     for (ResourceObserver obs : observers) obs.removedChild(child);
     return true;
   }
   return false;
 }
  @Override
  public void handlePOST(CoapExchange exchange) {
    String payload = exchange.getRequestText();
    String[] parts = payload.split("\\?");
    String[] path = parts[0].split("/");
    Resource resource = create(new LinkedList<String>(Arrays.asList(path)));

    Response response = new Response(ResponseCode.CREATED);
    response.getOptions().setLocationPath(resource.getURI());
    exchange.respond(response);
  }
  /* (non-Javadoc)
   * @see org.eclipse.californium.core.server.resources.Resource#setName(java.lang.String)
   */
  public synchronized void setName(String name) {
    if (name == null) throw new NullPointerException();
    String old = this.name;

    // adjust parent if in tree
    Resource parent = getParent();
    if (parent != null) {
      synchronized (parent) {
        parent.delete(this);
        this.name = name;
        parent.add(this);
      }
    } else {
      this.name = name;
    }
    adjustChildrenPath();

    for (ResourceObserver obs : observers) obs.changedName(old);
  }
 /* (non-Javadoc)
  * @see org.eclipse.californium.core.server.resources.Resource#getEndpoints()
  */
 public List<Endpoint> getEndpoints() {
   if (parent == null) return Collections.emptyList();
   else return parent.getEndpoints();
 }
 /* (non-Javadoc)
  * @see org.eclipse.californium.core.server.resources.Resource#getExecutor()
  */
 public ExecutorService getExecutor() {
   return parent != null ? parent.getExecutor() : null;
 }
 /**
  * Adjust the path of all children. This method is invoked when the URI of this resource has
  * changed, e.g., if its name or the name of an ancestor has changed.
  */
 private void adjustChildrenPath() {
   String childpath = path + name + /*since 23.7.2013*/ "/";
   for (Resource child : children.values()) child.setPath(childpath);
 }
 /* (non-Javadoc)
  * @see org.eclipse.californium.core.server.resources.Resource#setParent(org.eclipse.californium.core.server.resources.Resource)
  */
 public void setParent(Resource parent) {
   this.parent = parent;
   if (parent != null) this.path = parent.getPath() + parent.getName() + "/";
   adjustChildrenPath();
 }