/*
   * (non-Javadoc)
   *
   * @see
   * javax.management.DynamicMBean#setAttributes(javax.management.AttributeList
   * )
   */
  @Override
  public AttributeList setAttributes(final AttributeList attributes) {
    assert (attributes != null);
    RifidiService service = target.get();
    if (service != null) {
      service.setAttributes(attributes);
    }

    // keep track of changed attributes since there might be an error
    AttributeList changedAttributes = new AttributeList();

    for (Attribute attribute : attributes.asList()) {

      String attrName = attribute.getName();
      Integer pos = nameToPos.get(attrName);
      if (pos == null) {
        logger.error("Error when trying to set " + attribute.getName());
      } else {
        this.attributes.set(pos, attribute);
        changedAttributes.add(this.attributes.get(pos));
      }
    }

    notifierService.attributesChanged(getServiceID(), (AttributeList) changedAttributes);
    return (AttributeList) changedAttributes.clone();
  }
  /*
   * (non-Javadoc)
   *
   * @see
   * javax.management.DynamicMBean#setAttribute(javax.management.Attribute)
   */
  @Override
  public void setAttribute(final Attribute attribute)
      throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException,
          ReflectionException {
    assert (attribute != null);
    RifidiService service = target.get();
    if (service != null) {
      service.setAttribute(attribute);
    }

    attributes.set(nameToPos.get(attribute.getName()), attribute);
    notifierService.attributesChanged(getServiceID(), (AttributeList) attributes.clone());
  }