package com.orionplatform.documents.xml;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.xml.bind.JAXBException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactoryConfigurationError;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import com.orionplatform.core.abstraction.OrionService;
import com.orionplatform.documents.xml.tasks.ConvertObjectToXMLTask;
import com.orionplatform.documents.xml.tasks.ConvertXMLToObjectTask;
import com.orionplatform.documents.xml.tasks.OpenXMLFileTask;
import com.orionplatform.documents.xml.tasks.SaveXMLToFileTask;

public class XMLService extends OrionService
{
    public static synchronized Document openXMLFile(File XMLFilePath) throws JAXBException, ParserConfigurationException, SAXException, IOException
    {
        return OpenXMLFileTask.run(XMLFilePath);
    }
    
    
    public static synchronized void saveXMLToFile(Document XMLDocument, String XMLFilePath) throws TransformerFactoryConfigurationError, TransformerConfigurationException, IllegalArgumentException, FileNotFoundException, TransformerException
    {
        saveXMLToFile(XMLDocument, new File(XMLFilePath));
    }

    
    public static synchronized void saveXMLToFile(Document XMLDocument, File XMLFile) throws TransformerFactoryConfigurationError, TransformerConfigurationException, IllegalArgumentException, FileNotFoundException, TransformerException
    {
        SaveXMLToFileTask.run(XMLDocument, XMLFile);
    }

    
    public static synchronized void convertObjectToXML(Object objectToConvert, String XMLFilePath) throws JAXBException
    {
        convertObjectToXML(objectToConvert, new File(XMLFilePath));
    }
    

    public static synchronized void convertObjectToXML(Object objectToConvert, File XMLFile) throws JAXBException
    {
        ConvertObjectToXMLTask.run(objectToConvert, XMLFile);
    }
    
    
    public static synchronized Object convertXMLToObject(Class<?> classToMapTheXMLData, String XMLFilePath) throws JAXBException
    {
        return convertXMLToObject(classToMapTheXMLData, new File(XMLFilePath));
    }


    public static synchronized Object convertXMLToObject(Class<?> classToMapTheXMLData, File XMLFile) throws JAXBException
    {
        return ConvertXMLToObjectTask.run(classToMapTheXMLData, XMLFile);
    }
}