Java XML JAXB Marshaller marshall(String cntxtPkg, Object obj, OutputStream out)

Here you can find the source of marshall(String cntxtPkg, Object obj, OutputStream out)

Description

marshall

License

Open Source License

Declaration

public static void marshall(String cntxtPkg, Object obj, OutputStream out)
            throws JAXBException, SAXException, IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;

import java.io.OutputStream;

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

import org.xml.sax.SAXException;

public class Main {
    private static final HashMap<String, JAXBContext> marshallContexts = new HashMap<String, JAXBContext>();

    public static void marshall(String cntxtPkg, Object obj, OutputStream out)
            throws JAXBException, SAXException, IOException {
        Marshaller marshaller = createMarshall(cntxtPkg);
        if (marshaller == null)
            return;
        marshaller.marshal(obj, out);// ww w  . ja va 2  s . c  om
    }

    private static Marshaller createMarshall(String pkgName) throws JAXBException {
        JAXBContext jaxbCtx = null;
        if ((jaxbCtx = marshallContexts.get(pkgName)) == null) {
            jaxbCtx = JAXBContext.newInstance(pkgName);
            marshallContexts.put(pkgName, jaxbCtx);
        }
        Marshaller marshaller = jaxbCtx.createMarshaller();
        return marshaller;
    }
}

Related

  1. marshall(Object o)
  2. marshall(Object obj)
  3. marshall(Object obj, URL schemaURL, Class... classesToBeBound)
  4. marshall(Object toMarshall)
  5. marshall(OutputStream os, JAXBElement element)
  6. marshall(String file, JAXBElement object, Class context)
  7. marshaller(Object o, Class T)
  8. marshaller(Object obj, File file)
  9. marshallerObject(Class c, Object o)