Here you can find the source of getContext(final Class> theClass)
Parameter | Description |
---|---|
theClass | the class to retrieve the JAXBContext for |
Parameter | Description |
---|---|
JAXBException | throws a JAXBException if context cannot be created |
private static JAXBContext getContext(final Class<?> theClass) throws JAXBException
//package com.java2s; import java.util.HashMap; import java.util.Map; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; public class Main { /**//from w w w . j a v a 2 s . c o m * Map of classes and respective JAXBContexts. */ private static Map<Class<?>, JAXBContext> serMap = new HashMap<Class<?>, JAXBContext>(); /** * Gets the JAXBContext for the passed in class. * @param theClass * the class to retrieve the JAXBContext for * @return * the JAXBContext that has been found or created * @throws JAXBException * throws a JAXBException if context cannot be created */ private static JAXBContext getContext(final Class<?> theClass) throws JAXBException { if (serMap.containsKey(theClass)) { return serMap.get(theClass); } else { final JAXBContext jContext = JAXBContext.newInstance(theClass); serMap.put(theClass, jContext); return jContext; } } }