Search in sources :

Example 1 with XmlRootElement

use of jakarta.xml.bind.annotation.XmlRootElement in project jOOQ by jOOQ.

the class MiniJAXB method marshal.

public static void marshal(XMLAppendable object, Writer out) {
    try {
        XMLBuilder builder = XMLBuilder.formatting();
        XmlRootElement e = object.getClass().getAnnotation(XmlRootElement.class);
        if (e != null) {
            out.write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n");
            builder.append(e.name(), object);
        } else
            builder.append(object);
        builder.appendTo(out);
    } catch (Exception e) {
        throw new ConfigurationException("Cannot print object", e);
    }
}
Also used : XmlRootElement(jakarta.xml.bind.annotation.XmlRootElement) ConfigurationException(org.jooq.exception.ConfigurationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ConfigurationException(org.jooq.exception.ConfigurationException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) ReflectException(org.jooq.tools.reflect.ReflectException) SAXParseException(org.xml.sax.SAXParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 2 with XmlRootElement

use of jakarta.xml.bind.annotation.XmlRootElement 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)2 XmlSchema (jakarta.xml.bind.annotation.XmlSchema)1 XmlType (jakarta.xml.bind.annotation.XmlType)1 IOException (java.io.IOException)1 QName (javax.xml.namespace.QName)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 ConfigurationException (org.jooq.exception.ConfigurationException)1 ReflectException (org.jooq.tools.reflect.ReflectException)1 SAXException (org.xml.sax.SAXException)1 SAXParseException (org.xml.sax.SAXParseException)1