package com.atolcd.parapheur.repo;

import java.io.IOException;
import java.util.Properties;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;

public class ParapheurVersionProperties implements InitializingBean
{
   private static final String PARAPHEUR_VERSION_NUMBER = "ph_version";
   private static final String PARAPHEUR_BUILD_NUMBER = "ph_build";
   
   private Properties parapheurProperties;
   
   /**
    * Charge les propriétés du parapheur depuis un fichier
    * 
    * @param descriptorResource  ressource contenant les méta-données du parapheur
    * @throws IOException
    */
   public void setDescriptor(Resource descriptorResource)
       throws IOException
   {
       this.parapheurProperties = new Properties();
       this.parapheurProperties.load(descriptorResource.getInputStream());
   }
   
   public String getVersionNumber()
   {
      return (String) this.parapheurProperties.get(PARAPHEUR_VERSION_NUMBER);
   }
   
   public String getBuildNumber()
   {
      return (String) this.parapheurProperties.get(PARAPHEUR_BUILD_NUMBER);
   }

   /**
    * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
    */
   public void afterPropertiesSet() throws Exception
   {
      Assert.notNull(getVersionNumber(), "Aucun numéro de version trouvé");
      Assert.notNull(getBuildNumber(), "Aucun numéro de build trouvé");
      
   }
}
