package net.ihe.xcpd.resp.action;

import java.io.ByteArrayInputStream;
import java.io.StringWriter;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;

import org.hl7.v3.PRPAIN201305UV02;
import org.hl7.v3.PRPAIN201306UV02;


/**
 * 
 * @author abderrazek boufahja
 *
 */
public class StringTransformer {
    
    public static String PRPAIN201305UV02ToString (PRPAIN201305UV02 requestV3){
        String res = null;
        if (requestV3 != null){
            try {
                StringWriter sw = new StringWriter();
                javax.xml.bind.JAXBContext jaxbCtx = javax.xml.bind.JAXBContext.newInstance(requestV3.getClass().getPackage().getName());
                javax.xml.bind.Marshaller marshaller = jaxbCtx.createMarshaller();
                marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_ENCODING, "UTF-8"); //NOI18N
                marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
                marshaller.marshal(requestV3, sw);
                res = sw.toString();
            } catch (javax.xml.bind.JAXBException ex) {
                java.util.logging.Logger.getLogger("global").log(java.util.logging.Level.SEVERE, null, ex.getMessage()); //NOI18N
            }
        }
        return res;
    }
    
    public static PRPAIN201305UV02 String2PRPAIN201305UV02(String input){
        PRPAIN201305UV02 res = null;
        try{
            ByteArrayInputStream bais = new ByteArrayInputStream(input.getBytes());
            JAXBContext jc = JAXBContext.newInstance("org.hl7.v3");
            Unmarshaller unmarshaller = jc.createUnmarshaller();
            res = (PRPAIN201305UV02) unmarshaller.unmarshal(bais);
            System.out.println(res.getCreationTime().getValue());
        }
        catch (Exception e) {
            java.util.logging.Logger.getLogger("global").log(java.util.logging.Level.SEVERE, null, e.getMessage());
        }
        return res;
    }
    
    
    public static String PRPAIN201306UV02ToString (PRPAIN201306UV02 responseV3){
        String res = null;
        if (responseV3 != null){
            try {
                
                StringWriter sw = new StringWriter();
                javax.xml.bind.JAXBContext jaxbCtx = javax.xml.bind.JAXBContext.newInstance(responseV3.getClass().getPackage().getName());
                javax.xml.bind.Marshaller marshaller = jaxbCtx.createMarshaller();
                marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_ENCODING, "UTF-8"); //NOI18N
                marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
                marshaller.marshal(responseV3, sw);
                res = sw.toString();
                
            } catch (Exception ex) {
                java.util.logging.Logger.getLogger("global").log(java.util.logging.Level.SEVERE, null, ex.getMessage());
                //java.util.logging.Logger.getLogger("global").log(java.util.logging.Level.SEVERE, null, ex); //NOI18N
            }
        }
        return res;
    }
    
    public static PRPAIN201306UV02 String2PRPAIN201306UV02(String input){
        PRPAIN201306UV02 res = null;
        try{
            ByteArrayInputStream bais = new ByteArrayInputStream(input.getBytes());
            JAXBContext jc = JAXBContext.newInstance("org.hl7.v3");
            Unmarshaller unmarshaller = jc.createUnmarshaller();
            res = (PRPAIN201306UV02) unmarshaller.unmarshal(bais);
            System.out.println(res.getCreationTime().getValue());
        }
        catch (Exception e) {
            java.util.logging.Logger.getLogger("global").log(java.util.logging.Level.SEVERE, null, e.getMessage());
        }
        return res;
    }

}
