package eu.eudat.logic.utilities.documents.xml.dmpXml;

import eu.eudat.logic.utilities.documents.xml.dmpXml.dmpProfileModel.DmpProfile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import java.io.File;
import java.io.IOException;

public class ImportXmlBuilderDmpProfile {
    private static final Logger logger = LoggerFactory.getLogger(ImportXmlBuilderDmpProfile.class);

    public DmpProfile build(File xmlFile) throws IOException {
        DmpProfile dmpProfile = new DmpProfile();
        JAXBContext jaxbContext = null;
        try {
            jaxbContext = JAXBContext.newInstance(DmpProfile.class);
            Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
            dmpProfile = (DmpProfile) unmarshaller.unmarshal(xmlFile);
        } catch (JAXBException e) {
            logger.error(e.getMessage(), e);
        }

        return dmpProfile;
    }

}
