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);
}
}
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);
}
Aggregations