Java XML JAXB Context getContext(final Class theClass)

Here you can find the source of getContext(final Class theClass)

Description

Gets the JAXBContext for the passed in class.

License

Open Source License

Parameter

Parameter Description
theClass the class to retrieve the JAXBContext for

Exception

Parameter Description
JAXBException throws a JAXBException if context cannot be created

Return

the JAXBContext that has been found or created

Declaration

private static JAXBContext getContext(final Class<?> theClass) 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 {
    /**//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;
        }
    }
}

Related

  1. getContext()
  2. getContext()
  3. getContext()
  4. getContext(Class c)
  5. getContext(Class clazz)
  6. getContext(String uddiVersion)
  7. getContextFor(final Class clazz)
  8. getContextForNamespace(String namespace)
  9. getContextPath(Class... classes)