Here you can find the source of getJaxbContext(Class... classTypes)
Parameter | Description |
---|---|
classType | a parameter |
Parameter | Description |
---|---|
JAXBException | an exception |
@SuppressWarnings("rawtypes") private static synchronized JAXBContext getJaxbContext(Class... classTypes) throws JAXBException
//package com.java2s; //License from project: Open Source License 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 a2 s . c o m * The next code store the jaxb context to be used by all threads. Just * create a new jaxb context if the current context doesn't contain the * given class. */ private static final Map<String, JAXBContext> jaxbContextMap = new HashMap<String, JAXBContext>(); /** * Get * * @param classType * @return * @throws JAXBException */ @SuppressWarnings("rawtypes") private static synchronized JAXBContext getJaxbContext(Class... classTypes) throws JAXBException { JAXBContext retObj = null; String key = ""; for (Class classType : classTypes) { if (!"".equals(key)) { key += ";"; } key += classType.getName(); } retObj = jaxbContextMap.get(key); if (retObj == null) { retObj = JAXBContext.newInstance(classTypes); jaxbContextMap.put(key, retObj); } return retObj; } }