All Downloads are FREE. Search and download functionalities are using the official Maven repository.

shz.xml.JdkXmlHelp Maven / Gradle / Ivy

package shz.xml;

import org.w3c.dom.Node;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
import shz.PRException;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.transform.Result;
import java.io.*;
import java.net.URL;

@SuppressWarnings("unchecked")
public final class JdkXmlHelp {
    private JdkXmlHelp() {
        throw new IllegalStateException();
    }

    @SafeVarargs
    public static  T unmarshal(File file, Class... classes) {
        try {
            return (T) JAXBContext.newInstance(classes).createUnmarshaller().unmarshal(file);
        } catch (JAXBException e) {
            throw PRException.of(e);
        }
    }

    @SafeVarargs
    public static  T unmarshal(InputStream is, Class... classes) {
        try {
            return (T) JAXBContext.newInstance(classes).createUnmarshaller().unmarshal(is);
        } catch (JAXBException e) {
            throw PRException.of(e);
        }
    }

    @SafeVarargs
    public static  T unmarshal(Reader reader, Class... classes) {
        try {
            return (T) JAXBContext.newInstance(classes).createUnmarshaller().unmarshal(reader);
        } catch (JAXBException e) {
            throw PRException.of(e);
        }
    }

    @SafeVarargs
    public static  T unmarshal(URL url, Class... classes) {
        try {
            return (T) JAXBContext.newInstance(classes).createUnmarshaller().unmarshal(url);
        } catch (JAXBException e) {
            throw PRException.of(e);
        }
    }

    @SafeVarargs
    public static  T unmarshal(InputSource source, Class... classes) {
        try {
            return (T) JAXBContext.newInstance(classes).createUnmarshaller().unmarshal(source);
        } catch (JAXBException e) {
            throw PRException.of(e);
        }
    }

    @SafeVarargs
    public static  T unmarshal(Node node, Class... classes) {
        try {
            return (T) JAXBContext.newInstance(classes).createUnmarshaller().unmarshal(node);
        } catch (JAXBException e) {
            throw PRException.of(e);
        }
    }

    public static  T unmarshal(File file, String contextPath) {
        try {
            return (T) JAXBContext.newInstance(contextPath).createUnmarshaller().unmarshal(file);
        } catch (JAXBException e) {
            throw PRException.of(e);
        }
    }

    public static  T unmarshal(InputStream is, String contextPath) {
        try {
            return (T) JAXBContext.newInstance(contextPath).createUnmarshaller().unmarshal(is);
        } catch (JAXBException e) {
            throw PRException.of(e);
        }
    }

    public static  T unmarshal(Reader reader, String contextPath) {
        try {
            return (T) JAXBContext.newInstance(contextPath).createUnmarshaller().unmarshal(reader);
        } catch (JAXBException e) {
            throw PRException.of(e);
        }
    }

    public static  T unmarshal(URL url, String contextPath) {
        try {
            return (T) JAXBContext.newInstance(contextPath).createUnmarshaller().unmarshal(url);
        } catch (JAXBException e) {
            throw PRException.of(e);
        }
    }

    public static  T unmarshal(InputSource source, String contextPath) {
        try {
            return (T) JAXBContext.newInstance(contextPath).createUnmarshaller().unmarshal(source);
        } catch (JAXBException e) {
            throw PRException.of(e);
        }
    }

    public static  T unmarshal(Node node, String contextPath) {
        try {
            return (T) JAXBContext.newInstance(contextPath).createUnmarshaller().unmarshal(node);
        } catch (JAXBException e) {
            throw PRException.of(e);
        }
    }

    public static void marshal(Object t, Result result, Class... classes) {
        try {
            JAXBContext.newInstance(classes).createMarshaller().marshal(t, result);
        } catch (JAXBException e) {
            throw PRException.of(e);
        }
    }

    public static void marshal(Object t, File file, Class... classes) {
        try {
            JAXBContext.newInstance(classes).createMarshaller().marshal(t, file);
        } catch (JAXBException e) {
            throw PRException.of(e);
        }
    }

    public static void marshal(Object t, OutputStream out, Class... classes) {
        try {
            JAXBContext.newInstance(classes).createMarshaller().marshal(t, out);
        } catch (JAXBException e) {
            throw PRException.of(e);
        }
    }

    public static void marshal(Object t, Writer writer, Class... classes) {
        try {
            JAXBContext.newInstance(classes).createMarshaller().marshal(t, writer);
        } catch (JAXBException e) {
            throw PRException.of(e);
        }
    }

    public static void marshal(Object t, ContentHandler contentHandler, Class... classes) {
        try {
            JAXBContext.newInstance(classes).createMarshaller().marshal(t, contentHandler);
        } catch (JAXBException e) {
            throw PRException.of(e);
        }
    }

    public static void marshal(Object t, Node node, Class... classes) {
        try {
            JAXBContext.newInstance(classes).createMarshaller().marshal(t, node);
        } catch (JAXBException e) {
            throw PRException.of(e);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy