Using the Purchase Order schema from Exercise 1 and 2, you will now use the new XMLProcessor API to dynamically load conformant XML documents.
At the end of the lab, you should be able to:
This exercise is carried out entirely using the Eclipse Software Development Kit (SDK) version 3.2 with the Eclipse Modeling Framework (EMF) 2.2 installed into it. The exercise instructions refer to this product as either Eclipse or as "the workbench."
In your workspace, there should be a EMF_Workshop/Exercise5_Dynamic_EMF folder containing Exercise5.java and XMLSchemaDynamicProcessing.java. Exercise5.java is the class you will modify to perform the work noted above. XMLSchemaDynamicProcessing.java is an alternate solution, using older EMF API, to further demonstrate the speed and simplicity of the new XMLProcessor API. This API is only available in EMF 2.2 (and beyond) - in the past, a more cumbersome solution was required to accomplish the same task.
You should see the following output:
name: Scarlet O'Hara street: 321 Backwoods Lane city: Louisville state: AL zip: 67655 <?xml version="1.0" encoding="UTF-8"?> <po:order xmlns:po="http://www.example.com/po" orderDate="2006-03-20"> <shipTo> <name>Scarlet O'Hara</name> <street>321 Backwoods Lane</street> <city>Louisville</city> <state>AL</state> <zip>67655</zip> </shipTo> <billTo> <name>Rhett Butler</name> <street>123 Iditarod Lane</street> <city>Nome</city> <state>AK</state> <zip>34582</zip> </billTo> <po:comment>For Scarlet's Birthday</po:comment> <items partNum="SWH123456"> <productName>Wireless Headphones</productName> <quantity>2</quantity> <price>75.0</price> <po:comment>Backordered</po:comment> <shipDate>2006-03-23</shipDate> </items> <items partNum="STV999876"> <productName>Plasma Television</productName> <quantity>1</quantity> <price>499.0</price> <po:comment>Fragile</po:comment> <shipDate>2006-03-23</shipDate> </items> </po:order>
<?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="src"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="src" path="/org.eclipse.emf.common"/> <classpathentry kind="src" path="/org.eclipse.emf.ecore"/> <classpathentry kind="src" path="/org.eclipse.emf.ecore.xmi"/> <classpathentry kind="src" path="/org.eclipse.xsd"/> <classpathentry kind="output" path="bin"/> </classpath>
Bear in mind, however, that you will get errors in Exercise2.java, Exercise3.java and Exercise4.java, since they will now be missing dependencies. If Eclipse offers a warning stating "Errors exist in required project(s): Exercises. Continue launch?", you can safely hit Yes to continue. In order to re-run Exercises 2 - 4, you will have to undo this step.
In Exercise 2, we used the static API (generated model code) to load data from a model instance document. With the XMLProcessor API, you no longer need to have generated all that model code - you can now accomplish the same tasks dynamically using nothing more than 4 EMF plugins and a schema document.