Purchase Order Sample

Purchase order sample demonstrates the usage of AnnoxAnnotationReader with classes based on the well-known purchase order schema from the XML Schema Primer.

The task is as follows. We have a number of Java classes which represent the purchase order schema. The goal is to make them work with JAXB without annotating them.

Here's how to solve this task.

First of all we need to create XML resources for our classes. In this sample we have the following classes:

For demonstration purposes I'll put definitions for the first four classes in a common org/jvnet/annox/samples/po/package-info.ann.xml resource and the last class in his own org/jvnet/annox/samples/po/Items$Item.ann.xml resource.

To read annotations from these XML resource I only need to configure JAXB context with an instance of the AnnoxAnnotationReader:

final RuntimeAnnotationReader annotationReader = new AnnoxAnnotationReader();

final Map<String, Object> properties = new HashMap<String, Object>();

properties.put(JAXBRIContext.ANNOTATION_READER, annotationReader);

final JAXBContext context = JAXBContext.newInstance(
	"org.jvnet.annox.samples.po",
	Thread.currentThread().getContextClassLoader(),
	properties);

final JAXBElement<PurchaseOrderType> purchaseOrderElement =
	(JAXBElement<PurchaseOrderType>) context.createUnmarshaller().
		unmarshal(getClass().getResource("po.xml"));

final PurchaseOrderType purchaseOrder = purchaseOrderElement.getValue();

You may download the Ant or Maven distribution of the purchase order sample from the download page.


Browse Space

- Pages
- News
- Labels
- Attachments
- Bookmarks
- Mail
- Activity
- Advanced

Explore Confluence

- Popular Labels
- Notation Guide
- Impressum

Your Account

Log In

 

Other Features

Add Content