/*
   * (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());
  }
 /**
  * Constructor.
  *
  * @param context
  * @param serviceID
  * @param factoryID
  * @param attributes
  * @param sessionDTOs
  */
 public DefaultConfigurationImpl(
     final String serviceID,
     final String factoryID,
     final AttributeList attributes,
     final NotifierService notifierService,
     final JMXService jmxService,
     Set<SessionDTO> sessionDTOs) {
   this.notifierService = notifierService;
   this.nameToProperty = new HashMap<String, Property>();
   this.nameToOperation = new HashMap<String, Operation>();
   this.factoryID = factoryID;
   this.serviceID = serviceID;
   this.attributes = (AttributeList) attributes.clone();
   disableAutoStart = false;
   for (Object o : this.attributes) {
     Attribute att = (Attribute) o;
     String name = att.getName();
     if (name.equals("DisableAutoStart")) {
       // This is the 'override' autostart, so we will default to true
       // unless it is explicitly set to false
       if (att.getValue() != null && ((String) att.getValue()).equalsIgnoreCase("true")) {
         disableAutoStart = true;
       }
       break;
     }
   }
   this.listeners = new CopyOnWriteArraySet<AttributesChangedListener>();
   this.target = new AtomicReference<RifidiService>(null);
   this.jmxService = jmxService;
   this.sessionDTOs = new ConcurrentHashMap<SessionDTO, String>();
   if (sessionDTOs != null) {
     for (SessionDTO dto : sessionDTOs) {
       this.sessionDTOs.put(dto, "-1");
     }
   }
 }