Java XML QName marshallJAXBElement(Class declaredType, QName name, Class scope, BoundType v)

Here you can find the source of marshallJAXBElement(Class declaredType, QName name, Class scope, BoundType v)

Description

marshall JAXB Element

License

Open Source License

Declaration

public static <BoundType> JAXBElement<BoundType> marshallJAXBElement(Class<BoundType> declaredType, QName name,
            Class<?> scope, 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;
import javax.xml.namespace.QName;

public class Main {
    public static <ValueType, BoundType> JAXBElement<BoundType> marshallJAXBElement(
            Class<? extends XmlAdapter<BoundType, ValueType>> xmlAdapterClass, Class<BoundType> declaredType,
            QName name, Class<?> scope, ValueType v) {
        try {//w  w  w. java 2 s . co m
            if (v == null) {
                return null;
            } else {
                final XmlAdapter<BoundType, ValueType> xmlAdapter = getXmlAdapter(xmlAdapterClass);
                return new JAXBElement<BoundType>(name, declaredType, scope, xmlAdapter.marshal(v));
            }
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }

    public static <BoundType> JAXBElement<BoundType> marshallJAXBElement(Class<BoundType> declaredType, QName name,
            Class<?> scope, BoundType v) {
        if (v == null) {
            return null;
        } else {
            return new JAXBElement<BoundType>(name, declaredType, scope, v);
        }
    }

    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. isTagName(Element element, QName name)
  2. isType(Map> types, QName name, QName attributeName)
  3. isValidQName(String localPart)
  4. isWildcardType(QName type)
  5. marshal(T value, Class elementClass, String packageName, QName q_name, OutputStream oStream)
  6. marshalToString(T obj, Class clazz, QName qname)
  7. match(XMLStreamReader reader, QName name)
  8. matches(Node node, String requiredLocalName, QName requiredNamespace)
  9. matches(QName qname, Node node)