/**
  * Création d'une configuration
  *
  * @param config
  */
 public void create(DataConfiguration config) {
   DataConfigurationAccess access = new DataConfigurationAccess();
   try {
     config.setDate(new Date());
     config.setActive(false);
     access.createConfiguration(config);
   } finally {
     access.close();
   }
 }
 /**
  * Suppression d'une configuration
  *
  * @param id
  */
 public void delete(int id) {
   DataConfigurationAccess access = new DataConfigurationAccess();
   try {
     DataConfiguration item = new DataConfiguration();
     item.setId(id);
     access.deleteConfiguration(item);
   } finally {
     access.close();
   }
 }
 /**
  * Changement de l'activation d'une configuration
  *
  * @param id
  * @param active
  */
 public void changeActive(int id, boolean active) {
   DataConfigurationAccess access = new DataConfigurationAccess();
   try {
     DataConfiguration item = access.getConfigurationByKey(id);
     item.setActive(active);
     access.updateConfiguration(item);
   } finally {
     access.close();
   }
 }
 /**
  * Changement du commentaire d'une configuration
  *
  * @param id
  * @param comment
  */
 public void changeComment(int id, String comment) {
   DataConfigurationAccess access = new DataConfigurationAccess();
   try {
     DataConfiguration item = access.getConfigurationByKey(id);
     item.setComment(comment);
     access.updateConfiguration(item);
   } finally {
     access.close();
   }
 }
 /**
  * Lecture des configurations actives
  *
  * @param netList
  * @param coreList
  */
 public void loadActives(
     List<XmlNetContainer> netList, List<XmlCoreContainer> coreList, List<XmlUiContainer> uiList) {
   List<DataConfiguration> list = listActives();
   for (DataConfiguration item : list) {
     if (tryReadNet(item.getContent(), netList)) continue;
     if (tryReadCore(item.getContent(), coreList)) continue;
     if (tryReadUi(item.getContent(), uiList)) continue;
     throw new UnsupportedOperationException(
         "Invalid configuration content wirth id : " + item.getId());
   }
 }
  private DataConfiguration tryReadUi(byte[] data) {
    try {
      XmlUiContainer container = ExchangeManager.importUiContainer(new ByteArrayInputStream(data));

      DataConfiguration config = new DataConfiguration();
      config.setType(TYPE_UI);
      config.setContent(data);
      config.setComment(
          "documentName : "
              + container.documentName
              + "\ndocumentVersion : "
              + container.documentVersion);
      return config;
    } catch (JAXBException e) {
      return null;
    }
  }
  private DataConfiguration tryReadNet(byte[] data) {
    try {
      XmlNetContainer container =
          org.mylife.home.net.exchange.ExchangeManager.importNetContainer(
              new ByteArrayInputStream(data));

      DataConfiguration config = new DataConfiguration();
      config.setType(TYPE_NET);
      config.setContent(data);
      config.setComment(
          "componentsVersion : "
              + container.componentsVersion
              + "\ndocumentVersion : "
              + container.documentVersion);
      return config;

    } catch (JAXBException e) {
      return null;
    }
  }