Contents

Introduction

This example leverages EclipseLink JAXB (MOXy)'s concepts of externalized metadata represented as a MetadataSource (see MetadataRepository example for more information), and extensible models (see Extensible example for more information). The MetadataSource will be used to define the metadata for the extensions. In EclipseLink 2.3 the ability for a JAXBContext to be "refreshed" was introduced. This means that without stopping the application the metadata can be updated to include information about new extensions.

Demo

MOXy provides a class called JAXBHelper to easily obtain MOXy's implementation of JAXBContext. This exposes the refreshMetadata() method. The refreshMetadata() call does not affect any marshal or unmarshal operations that may currently be in progress, and once the refresh is complete the new metadata will be used.

XML Output

In the first document that is marshalled the extensions are not included, this is because the JAXBContext is not yet aware of the metadata. Once the metadata has been added and the JAXBContext refreshed the new properties are included. One thing to note is that we did not need to obtain a new instance of Marshaller.

ExtensionMetadataSource

In the MetadataRepository example the metadata was in the form of an XML document. In this example the metadata is provided in the form of the corresponding object model. Using the model provides us an easy means to programmatically update it. The XmlBindings model was generated from the schema for MOXy's externalized metadata format: [[1]].

Java Model with @XmlVirtualAccessMethods annotation

The @XmlVirtualAccessMethods annotation is used to specify that a class is extensible. An extensible class is required to have a "get" method that returns a value by property name, and a "set" method that stores a value by property name. The default names for these methods are "get" and "set", and can be overridden with the @XmlVirtualAccessMethods annotation.