Java XML JAXB Unmarshaller unmarshal(org.w3c.dom.Element elem, Class c)

Here you can find the source of unmarshal(org.w3c.dom.Element elem, Class c)

Description

unmarshal

License

Open Source License

Declaration

public static Object unmarshal(org.w3c.dom.Element elem, Class<?> c) throws JAXBException 

Method Source Code

//package com.java2s;
//## The MIT License

import java.util.concurrent.ConcurrentHashMap;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

import javax.xml.bind.Unmarshaller;

public class Main {
    private static ConcurrentHashMap<Class<?>, JAXBContext> contextMap = new ConcurrentHashMap<Class<?>, JAXBContext>();

    public static Object unmarshal(org.w3c.dom.Element elem, Class<?> c) throws JAXBException {
        Object result = null;/* w w  w.ja  va 2 s.  c o m*/

        JAXBContext jc = getContext(c);
        Unmarshaller um = jc.createUnmarshaller();
        result = um.unmarshal(elem);

        return result;
    }

    private static JAXBContext getContext(Class<?> c) throws JAXBException {
        JAXBContext jc = contextMap.get(c);
        if (jc == null) {
            jc = JAXBContext.newInstance(c);
            contextMap.put(c, jc);
        }

        return jc;
    }
}

Related

  1. unmarshal(InputStream is, Class clazz)
  2. unmarshal(InputStream stream, Class clazz)
  3. unmarshal(JAXBContext context, Class clazz, String source)
  4. unmarshal(JAXBContext jaxbContext, XMLStreamReader xmlStreamReader)
  5. unmarshal(org.w3c.dom.Element elem, Class c)
  6. unmarshal(String b, Class implClass, Class... bc)
  7. unmarshal(String content, Class clasz)
  8. unMarshal(String contextPath, InputStream xmlStream)
  9. unmarshal(String ObjXml, Class configurationClass)