Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.HashMap; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; import org.xml.sax.SAXException; public class Main { private static final HashMap<String, JAXBContext> marshallContexts = new HashMap<String, JAXBContext>(); private static Unmarshaller createUmarshall(String pkgName) throws JAXBException, SAXException { JAXBContext jaxbCtx = null; if ((jaxbCtx = marshallContexts.get(pkgName)) == null) { jaxbCtx = JAXBContext.newInstance(pkgName); marshallContexts.put(pkgName, jaxbCtx); } Unmarshaller unmarshaller = jaxbCtx.createUnmarshaller(); return unmarshaller; } }