/* (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);
 }
 /* (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;
 }
 /* (non-Javadoc)
  * @see org.eclipse.californium.core.server.resources.Resource#addObserveRelation(org.eclipse.californium.core.observe.ObserveRelation)
  */
 @Override
 public void addObserveRelation(ObserveRelation relation) {
   if (observeRelations.add(relation)) {
     LOGGER.info(
         "Replacing observe relation between " + relation.getKey() + " and resource " + getURI());
   } else {
     LOGGER.info(
         "Successfully established observe relation between "
             + relation.getKey()
             + " and resource "
             + getURI());
   }
   for (ResourceObserver obs : observers) obs.addedObserveRelation(relation);
 }
  /* (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#removeObserveRelation(org.eclipse.californium.core.observe.ObserveRelation)
  */
 @Override
 public void removeObserveRelation(ObserveRelation relation) {
   observeRelations.remove(relation);
   for (ResourceObserver obs : observers) obs.removedObserveRelation(relation);
 }
 /* (non-Javadoc)
  * @see org.eclipse.californium.core.server.resources.Resource#setPath(java.lang.String)
  */
 public synchronized void setPath(String path) {
   String old = this.path;
   this.path = path;
   for (ResourceObserver obs : observers) obs.changedPath(old);
   adjustChildrenPath();
 }