All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openl.util.JAXBUtils Maven / Gradle / Ivy

The newest version!
package org.openl.util;

import java.lang.reflect.ParameterizedType;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

public final class JAXBUtils {
    private JAXBUtils() {
    }

    public static Class extractValueTypeIfAnnotatedWithXmlJavaTypeAdapter(Class boundType) {
        return extractValueTypeIfAnnotatedWithXmlJavaTypeAdapter(boundType,
                boundType.getAnnotation(XmlJavaTypeAdapter.class));
    }

    public static Class extractValueTypeIfAnnotatedWithXmlJavaTypeAdapter(Class boundType,
                                                                             XmlJavaTypeAdapter xmlJavaTypeAdapter) {
        if (!boundType.isPrimitive()) {
            if (xmlJavaTypeAdapter != null) {
                @SuppressWarnings("rawtypes")
                Class xmlAdapterClass = xmlJavaTypeAdapter.value();
                java.lang.reflect.Type type = xmlAdapterClass.getGenericSuperclass();
                if (type instanceof ParameterizedType) {
                    ParameterizedType parameterizedType = (ParameterizedType) type;
                    java.lang.reflect.Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
                    if (actualTypeArguments[0] instanceof Class) {
                        return (Class) actualTypeArguments[0];
                    }
                }
            }
        }
        return null;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy