JaxbService
Allows instances of JAXB-annotated classes to be marshalled to XML and unmarshalled from XML back into domain objects.
The default implementation automatically caches the JAXB marshallers by target class.
API
interface JaxbService {
T fromXml(Class<T> domainClass, String xml) (1)
T fromXml(Class<T> domainClass, String xml, Map<String, Object> unmarshallerProperties) (2)
String toXml(Object domainObject) (3)
String toXml(Object domainObject, Map<String, Object> marshallerProperties) (4)
Map<String, String> toXsd(Object domainObject, CausewaySchemas causewaySchemas) (5)
}
1 | fromXml(Class, String)
Unmarshalls the XML to the specified domain class. |
2 | fromXml(Class, String, Map)
Unmarshalls the XML to the specified domain class, with additional properties passed through to the JAXBContext used to performed the unmarshalling. |
3 | toXml(Object)
Marshalls the object into XML (using a JAXBContext for the object’s class). |
4 | toXml(Object, Map)
Marshalls the object into XML specifying additional properties (passed to the JAXBContext used for the object’s class). |
5 | toXsd(Object, CausewaySchemas)
Generates a map of each of the schemas referenced; the key is the schema namespace, the value is the XML of the schema itself. |
Members
fromXml(Class, String, Map)
Unmarshalls the XML to the specified domain class, with additional properties passed through to the JAXBContext used to performed the unmarshalling.
toXml(Object, Map)
Marshalls the object into XML specifying additional properties (passed to the JAXBContext used for the object’s class).
toXsd(Object, CausewaySchemas)
Generates a map of each of the schemas referenced; the key is the schema namespace, the value is the XML of the schema itself.
A JAXB-annotated domain object will live in its own XSD namespace and may reference multiple other XSD schemas. In particular, many JAXB domain objects will reference the common causeway schemas. The CausewaySchemas paramter indicates whether these schemas should be included or excluded from the map.
Implementation
Apache Causeway provides a default implementation of the service, o.a.c.applib.services.jaxb.JaxbServiceDefault
.
This automatically caches JAXBContext
s for each domain class as requested.
Usage within the framework
This service is provided as a convenience for applications, but is also used internally by the framework to marshall @XmlRootElement-annotated view models.
The functionality to download XML and XSD schemas is also exposed in the UI through mixins of the Dto interface.