Java XML JAXB Context getJaxbContext(Class... classTypes)

Here you can find the source of getJaxbContext(Class... classTypes)

Description

Get

License

Open Source License

Parameter

Parameter Description
classType a parameter

Exception

Parameter Description
JAXBException an exception

Declaration

@SuppressWarnings("rawtypes")
private static synchronized JAXBContext getJaxbContext(Class... classTypes) throws JAXBException 

Method Source Code

//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;
    }
}

Related

  1. getContextForNamespace(String namespace)
  2. getContextPath(Class... classes)
  3. getCustomContext()
  4. getCustomIdentityJAXBContext()
  5. getJaxbContext(Class... classes)
  6. getJAXBContext(Class clazz)
  7. getJAXBContext(Class clazz)
  8. getJaxbContext(Class clazz)
  9. getJAXBContext(Class clazz)