Search in sources :

Example 1 with XmlType

use of jakarta.xml.bind.annotation.XmlType in project spring-framework by spring-projects.

the class Jaxb2XmlDecoder method toQName.

/**
 * Returns the qualified name for the given class, according to the mapping rules
 * in the JAXB specification.
 */
QName toQName(Class<?> outputClass) {
    String localPart;
    String namespaceUri;
    if (outputClass.isAnnotationPresent(XmlRootElement.class)) {
        XmlRootElement annotation = outputClass.getAnnotation(XmlRootElement.class);
        localPart = annotation.name();
        namespaceUri = annotation.namespace();
    } else if (outputClass.isAnnotationPresent(XmlType.class)) {
        XmlType annotation = outputClass.getAnnotation(XmlType.class);
        localPart = annotation.name();
        namespaceUri = annotation.namespace();
    } else {
        throw new IllegalArgumentException("Output class [" + outputClass.getName() + "] is neither annotated with @XmlRootElement nor @XmlType");
    }
    if (JAXB_DEFAULT_ANNOTATION_VALUE.equals(localPart)) {
        localPart = ClassUtils.getShortNameAsProperty(outputClass);
    }
    if (JAXB_DEFAULT_ANNOTATION_VALUE.equals(namespaceUri)) {
        Package outputClassPackage = outputClass.getPackage();
        if (outputClassPackage != null && outputClassPackage.isAnnotationPresent(XmlSchema.class)) {
            XmlSchema annotation = outputClassPackage.getAnnotation(XmlSchema.class);
            namespaceUri = annotation.namespace();
        } else {
            namespaceUri = XMLConstants.NULL_NS_URI;
        }
    }
    return new QName(namespaceUri, localPart);
}
Also used : XmlRootElement(jakarta.xml.bind.annotation.XmlRootElement) XmlSchema(jakarta.xml.bind.annotation.XmlSchema) QName(javax.xml.namespace.QName) XmlType(jakarta.xml.bind.annotation.XmlType)

Aggregations

XmlRootElement (jakarta.xml.bind.annotation.XmlRootElement)1 XmlSchema (jakarta.xml.bind.annotation.XmlSchema)1 XmlType (jakarta.xml.bind.annotation.XmlType)1 QName (javax.xml.namespace.QName)1