Using the Purchase Order model, you will make the same modifications to instance data as in Exercise 2, but this time you will record the changes and serialize the change description.
This is to demonstrate how you can record changes made to instance data, rather than simply recording the resulting instance, in the event that you're modifying a large file or want to create a service that saves time and bandwidth by sending only deltas rather than entire instances. To keep things simple, we will continue to use the Exercises project started in the previous exercise. If you did not complete the exercise, you can copy the solution into your Exercises project and start from there.
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/Exercise3_Recording_Changes folder that contains a Java file named Exercise3.java. This is the class you will modify to perform the work noted above.
The solution to this exercise is available as a complete project in the EMF_Workshop/Solution3 folder.
<?xml version="1.0" encoding="ASCII"?> <change:ChangeDescription xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:change="http://www.eclipse.org/emf/2003/Change" xmlns:po="http://www.example.com/po"> <objectChanges key="po.xml#//@order"> <value featureName="items"> <listChanges index="1" referenceValues="#//@objectsToAttach.0"/> </value> <value featureName="comment" dataValue="For Scarlet's Birthday"/> </objectChanges> <objectsToAttach xsi:type="po:Item" partNum="STV999876"> <productName>Plasma Television</productName> <quantity>1</quantity> <price>499.0</price> <po:comment>Fragile</po:comment> <shipDate>2006-03-23</shipDate> </objectsToAttach> </change:ChangeDescription>
---
<?xml version="1.0" encoding="ASCII"?> <change:ChangeDescription xmlns:change="http://www.eclipse.org/emf/2003/Change"> <objectChanges key="po.xml#//@order"> <value featureName="items"> <listChanges kind="REMOVE" index="1"/> </value> <value featureName="comment" dataValue="Plasma Television (STV999876) is discontinued and has been removed from the order."/> </objectChanges> </change:ChangeDescription>
<?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="ASCII"?> <change:ChangeDescription xmlns:change="http://www.eclipse.org/emf/2003/Change"/>
<?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>Plasma Television (STV999876) is discontinued and has been removed from the order.</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> </po:order>
You have learned how to record changes made to an instance of an EMF model, and seen how the result is a description of the reverse delta. You then applied and reversed the change description to obtain the forward delta, and serialized that result.