Java XML JAXB Context getJaxbContext(String contextPath)

Here you can find the source of getJaxbContext(String contextPath)

Description

Returns a JAXB context for the given context path.

License

Open Source License

Parameter

Parameter Description
contextPath the JAXB context path

Exception

Parameter Description
JAXBException if the context could not be retrieved

Return

the jaxb context for the given context path

Declaration

public static synchronized JAXBContext getJaxbContext(String contextPath) throws JAXBException 

Method Source Code

//package com.java2s;

import java.util.HashMap;

import java.util.Map;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

public class Main {
    private static final Map JAXB_CONTEXT_MAP = new HashMap();

    /**//from ww  w. j  a  v  a 2 s .  co m
     * Returns a JAXB context for the given context path. Contexts are
     * cached in a hash map.
     * @param contextPath the JAXB context path
     * @return the jaxb context for the given context path
     * @throws JAXBException if the context could not be retrieved
     */
    public static synchronized JAXBContext getJaxbContext(String contextPath) throws JAXBException {
        JAXBContext ctx = (JAXBContext) JAXB_CONTEXT_MAP.get(contextPath);
        if (ctx == null) {
            ctx = JAXBContext.newInstance(contextPath);
            JAXB_CONTEXT_MAP.put(contextPath, ctx);
        }
        return ctx;
    }
}

Related

  1. getJAXBContext(Class clazz)
  2. getJaxbContext(Class clazz)
  3. getJAXBContext(Class clazz)
  4. getJAXBContext(Class objclass)
  5. getJaxbContext(Class valueType)
  6. getJAXBContext(String contextPath)
  7. getJAXBContext(String namespaces)
  8. getJAXBContext(String packagePrefix)
  9. getJAXBContextForWebService(Class webService)