package sikd.sikd5.transaksi.upload;

import java.io.Serializable;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.transform.stream.StreamSource;
import sikd.sikd5.sikd5bean.ws.transaksi.Headerlog_WS;

/**
 *
 * @author sora
 */
public class XmlServiceUtil implements Serializable{
    
    
//    static JAXBContext getJaxBContext(String ikd) throws Exception{
//        if( ikd.trim().equals("ANG") ) return JAXBContext.newInstance(Apbd_WS.class);
//        else return null;
//    }
    
    @SuppressWarnings("ConvertToStringSwitch")
    static Object settingDataParsing(Unmarshaller um, String xmlFileName) throws Exception{
        Object result =  um.unmarshal(new StreamSource(xmlFileName), Headerlog_WS.class).getValue();
        return result;
    }
    
    public static Object parsingXML(String xmlFileName) throws Exception {
        try {
            JAXBContext jc = JAXBContext.newInstance(Headerlog_WS.class);
            if (jc != null) {
                Unmarshaller um = jc.createUnmarshaller();
                return settingDataParsing(um, xmlFileName);
            }
            return null;
        } catch (JAXBException ex) {
            Logger.getLogger(XmlServiceUtil.class.getName()).log(Level.SEVERE, null, ex);
            throw new Exception("gagal parsing XML " + ex.getMessage());
        }
    }
    
}
