Example usage for javax.xml.bind.annotation.adapters XmlAdapter marshal

List of usage examples for javax.xml.bind.annotation.adapters XmlAdapter marshal

Introduction

In this page you can find the example usage for javax.xml.bind.annotation.adapters XmlAdapter marshal.

Prototype

public abstract ValueType marshal(BoundType v) throws Exception;

Source Link

Document

Convert a bound type to a value type.

Usage

From source file:Main.java

public static <ValueType, BoundType> ValueType marshall(
        Class<? extends XmlAdapter<ValueType, BoundType>> xmlAdapterClass, BoundType v) {
    try {/*www.  j a va 2s .c  o m*/
        final XmlAdapter<ValueType, BoundType> xmlAdapter = getXmlAdapter(xmlAdapterClass);
        return xmlAdapter.marshal(v);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}

From source file:Main.java

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 .  j a  v  a  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);
    }
}

From source file:net.firejack.platform.core.utils.Factory.java

private Object get(Object bean, String name, Class valueType) {
    try {/* w  w  w . j a  v a  2  s. c  om*/
        Object value;
        try {
            value = getInstance().getProperty(bean, name);
        } catch (NoSuchMethodException e) {
            value = getInstance().getProperty(bean, fixPath(name));
        } catch (Exception e) {
            value = null;
        }

        if (!Hibernate.isInitialized(value))
            value = null;

        if (value != null && valueType != null && value.getClass() != valueType) {
            XmlAdapter adapter = adapters.get(valueType.getName() + value.getClass().getName());
            if (adapter != null)
                try {
                    return adapter.marshal(value);
                } catch (ClassCastException e) {
                    return adapter.unmarshal(value);
                }
        }

        return value;
    } catch (Exception e) {
        logger.warn(e.getMessage());
    }
    return null;
}