Java XML JAXB Unmarshaller unmarshallJAXBElement(JAXBElement v)

Here you can find the source of unmarshallJAXBElement(JAXBElement v)

Description

unmarshall JAXB Element

License

Open Source License

Declaration

public static <BoundType> BoundType unmarshallJAXBElement(JAXBElement<? extends BoundType> v) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.adapters.XmlAdapter;

public class Main {
    public static <ValueType, BoundType> ValueType unmarshallJAXBElement(
            Class<? extends XmlAdapter<BoundType, ValueType>> xmlAdapterClass, JAXBElement<? extends BoundType> v) {
        try {/*ww  w. j  a v a 2s. c  o  m*/
            if (v == null) {
                return null;
            } else {
                final XmlAdapter<BoundType, ValueType> xmlAdapter = getXmlAdapter(xmlAdapterClass);
                return xmlAdapter.unmarshal(v.getValue());
            }
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }

    public static <BoundType> BoundType unmarshallJAXBElement(JAXBElement<? extends BoundType> v) {
        if (v == null) {
            return null;
        } else {
            return v.getValue();
        }
    }

    public static <ValueType, BoundType> XmlAdapter<ValueType, BoundType> getXmlAdapter(
            Class<? extends XmlAdapter<ValueType, BoundType>> xmlAdapterClass) {
        try {
            final XmlAdapter<ValueType, BoundType> xmlAdapter = xmlAdapterClass.newInstance();
            return xmlAdapter;
        } catch (IllegalAccessException iaex) {
            throw new RuntimeException(iaex);
        } catch (InstantiationException iex) {
            throw new RuntimeException(iex);
        }
    }
}

Related

  1. unmarshall(String xml, Class... classesToBeBound)
  2. unmarshall(String xml, Class clazz)
  3. unmarshall(String xml, URL schemaURL, Class... classesToBeBound)
  4. unmarshaller(Class entityType, InputStream in)
  5. unmarshaller(String xml, Class T)
  6. unMarshallRequest(String xmlString)
  7. unmarshallString(String str, Class c)
  8. unmarshallXml(final String string, final Class type)
  9. unmarshallXMLtoObject(final byte[] xmlObject, final Class objectClass, final URL schemaURL)