package code.donbonifacio.saft;

import code.donbonifacio.saft.elements.AuditFile;
import code.donbonifacio.saft.exceptions.SaftLoaderException;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import java.io.*;
import java.nio.charset.StandardCharsets;

import static com.google.common.base.Preconditions.checkNotNull;

/**
 * Loads and AuditFile from specific sources
 */
public final class SaftLoader {

    /**
     * Prevent creating objects of this class
     */
    private SaftLoader() {
        throw new AssertionError();
    }

    /**
     * Loads an AuditFile from a given fileName
     * @param fileName the file name to load from
     * @return the audit file
     * @throws SaftLoaderException
     */
    public static AuditFile loadFromFile(String fileName) throws SaftLoaderException {
        checkNotNull(fileName);

        try {
            FileInputStream fis = new FileInputStream(fileName);
            AuditFile auditFile = loadFrom(fis);
            fis.close();
            return auditFile;
        } catch(IOException ex) {
            throw new SaftLoaderException(ex);
        }
    }

    /**
     * Loads an AuditFile from a raw string
     * @param raw the raw xml string
     * @return the AuditFile
     * @throws SaftLoaderException
     */
    public static AuditFile loadFromString(String raw) throws SaftLoaderException {
        checkNotNull(raw);
        InputStream stream = new ByteArrayInputStream(raw.getBytes(StandardCharsets.UTF_8));
        return loadFrom(stream);
    }

    /**
     * Loads an AuditFile from an arbitrary stream
     * @param stream the source stream
     * @return the AuditFile
     * @throws SaftLoaderException
     */
    public static AuditFile loadFrom(InputStream stream) throws SaftLoaderException {
        checkNotNull(stream);
        try {
            JAXBContext jaxbContext = JAXBContext.newInstance(AuditFile.class);
            Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
            return (AuditFile) jaxbUnmarshaller.unmarshal(stream);
        } catch(Exception ex) {
            throw new SaftLoaderException(ex);
        }

    }
}

@@ -137,16 +137,73 @@
 ception;
+%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0A%0Aimport
@@ -478,16 +478,92 @@
 Loader %7B
+%0A    static final Logger logger = LoggerFactory.getLogger(SaftLoader.class);
 %0A%0A    /*
@@ -985,16 +985,77 @@
 leName);
+%0A        logger.debug(%22Loading AuditFile from %7B%7D%22, fileName);
 %0A%0A      
@@ -1566,32 +1566,32 @@
 aderException %7B%0A
-
         checkNot
@@ -1601,16 +1601,75 @@
 l(raw);%0A
+        logger.debug(%22Loading AuditFile from raw String%22);%0A
         

Add loggers with loading info