ChangeSummary
ようやくChangeSummaryです。謎のxmlの不具合でやたらと時間がかかってしまいましたが、さっそくDataObjectを編集してみましょう。SDOUtilを使って、xmlからDataGraphを生成します。
元のxml
<?xml version=”1.0″ encoding=”UTF-8″?>
<sdo:datagraph xmlns:fireworks=”fireworksDataGraph.xsd” xmlns:sdo=”commonj.sdo”>
<fireworks:fireworksEvent eventID=”1″ eventName=”全国新作花火競技会” location=”諏訪湖” date=”2007-09-01″>
<comments>雨天決行</comments>
<firework id=”1″ title=”Advanced Technologies” pyrotechnist=”松尾潤子” size=”3″ pattern=”型物” score=”0″/>
</fireworks:fireworksEvent>
</sdo:datagraph>
今年の全国新作花火競技会で、松尾潤子さんという花火師が”Advanced Technologies”というタイトルの花火を上げます。それを審査員が採点するプログラムとなっています。
前準備として、ChangeSummaryのloggingを開始。
ChangeSummary cs = dataGraph.getChangeSummary();
cs.beginLogging();
先ずはルートDataObject (dataObject)から、XPathを指定してfireworkデータオブジェクトのidプロパティの値が1のDataObjectを取得します。pathは操作対象となるDataObjectの構造を知らないと指定できませんが、データソースに関係なく統一的な手法でアクセスできるのはやはり便利です。
DataObject firework = dataObject.getDataObject(“firework[id = 1]“);
次に、scoreを編集。元のxmlで、scoreが要素なのか属性なのかを気にせずにアクセスできています。
firework.setInt(“score”, 99);
DataGraphをファイルに書き出すと、ChangeSummaryは次のようなxmlで表現されていました。
<?xml version=”1.0″ encoding=”UTF-8″?>
<sdo:datagraph xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xmlns:fireworks=”fireworksDataGraph.xsd” xmlns:sdo=”commonj.sdo” xmlns:sdo_1=”http://www.apache.org/tuscany/2005/SDO”>
<changeSummary xmlns=”"
logging=”true”>
<objectChanges key=”#//@eRootObject/@firework.0″>
<value xsi:type=”sdo_1:ChangeSummarySetting” featureName=”score” dataValue=”0″/>
</objectChanges>
</changeSummary>
<fireworks:FireworksEventType eventID=”1″
eventName=”全国新作花火競技会” location=”諏訪湖” date=”2007-09-01″>
<comments>雨天決行</comments>
<firework id=”1″ title=”Advanced Technologies” pyrotechnist=”松尾潤子” size=”3″ pattern=”型物” score=”99″/>
</fireworks:FireworksEventType>
</sdo:datagraph>
undoも可能。
cs.undoChanges();
undoした場合、ChangeSummaryは残りません。但し、loggingを開始すると、変更しなくてもchangeSummary要素が追加されます。
<?xml version=”1.0″ encoding=”UTF-8″?>
<sdo:datagraph xmlns:fireworks=”fireworksDataGraph.xsd” xmlns:sdo=”commonj.sdo”>
<changeSummary xmlns=”"
logging=”true”/>
<fireworks:FireworksEventType eventID=”1″
eventName=”全国新作花火競技会” location=”諏訪湖” date=”2007-09-01″>
<comments>雨天決行</comments>
<firework id=”1″ title=”Advanced Technologies” pyrotechnist=”松尾潤子” size=”3″ pattern=”型物” score=”0″/>
</fireworks:FireworksEventType>
</sdo:datagraph>