Here you can find the source of getJAXBContext(Class> objclass)
Parameter | Description |
---|---|
obj | the object to be serialised |
objclass | the class of the object to be serialised |
Parameter | Description |
---|---|
JAXBException | an exception |
static private JAXBContext getJAXBContext(Class<?> objclass) throws JAXBException
//package com.java2s; // sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is import java.util.HashMap; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; public class Main { private static HashMap<String, JAXBContext> jaxbContentCache = new HashMap<String, JAXBContext>(); /** Serialise the object to an XML string * @param obj the object to be serialised * @param objclass the class of the object to be serialised * @return an XML string representing the object, or null if the object couldn't be serialised * @throws JAXBException // ww w . j av a2 s . co m */ static private JAXBContext getJAXBContext(Class<?> objclass) throws JAXBException { JAXBContext jaxbContext; if (jaxbContentCache.containsKey(objclass.getName())) { jaxbContext = jaxbContentCache.get(objclass.getName()); } else { jaxbContext = JAXBContext.newInstance(objclass); jaxbContentCache.put(objclass.getName(), jaxbContext); } return jaxbContext; } }