Java XML JAXB Marshaller getMarshaller(Class clazz)

Here you can find the source of getMarshaller(Class clazz)

Description

get Marshaller

License

Apache License

Declaration

private static <T> Marshaller getMarshaller(Class<T> clazz) throws JAXBException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.HashMap;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

public class Main {
    private static HashMap<Class<?>, Marshaller> marshallers = new HashMap<>();

    private static <T> Marshaller getMarshaller(Class<T> clazz) throws JAXBException {
        Marshaller marshaller = marshallers.get(clazz);
        if (marshaller == null)
            marshaller = createMarshaller(clazz);
        return marshaller;
    }//from www. j a v a 2 s  .co m

    private static <T> Marshaller createMarshaller(Class<T> clazz) throws JAXBException {
        Marshaller marshaller = createJAXBContext(clazz).createMarshaller();
        marshallers.put(clazz, marshaller);
        return marshaller;
    }

    private static <T> JAXBContext createJAXBContext(Class<T> clazz) throws JAXBException {
        return JAXBContext.newInstance(clazz);
    }
}

Related

  1. getJSIDLMarshaller()
  2. getMarshaller()
  3. getMarshaller()
  4. getMarshaller(boolean prettyFormat)
  5. getMarshaller(Class c)
  6. getMarshaller(final String contextPath)
  7. getMarshaller(String jaxbContext, boolean pretty)
  8. getSchemaLocation(@Nonnull final Marshaller aMarshaller)
  9. getSunNamespacePrefixMapper(@Nonnull final Marshaller aMarshaller)