#!/usr/bin/env python
import coral ; metamodel=coral.lang.UML14 

xmi = coral.Language.__getLanguage__("XMI", 0, 0)
assert(xmi)

d = coral.AnyAbstractElement()

p1 = coral.PresentationElement()
p2 = coral.PresentationElement()

ext = xmi.getElement("Extension").newAtom()
setattr(ext, "extender", "fi.abo.www@marcus.alanen")
setattr(ext, "extenderID", "this is optional")
ext.xmi_contents.add(p1)
ext.xmi_contents.add(p2)

d.xmi_extension.add(ext)

coral.saveModel("tmp/out_XMILang.xml", d)

loaded = coral.loadModel("tmp/out_XMILang.xml")
assert(coral.isSameModel(loaded, d))
assert(coral.isSameModel(d, loaded))

print "OK"
print loaded
print loaded.xmi_extension
print loaded.xmi_extension[0]
print getattr(loaded.xmi_extension[0], "extender")
print getattr(loaded.xmi_extension[0], "extenderID")
print loaded.xmi_extension[0].xmi_contents
print loaded.xmi_extension[0].xmi_contents[0]
print loaded.xmi_extension[0].xmi_contents[1]

assert(coral.isSameModel(loaded.xmi_extension[0].xmi_contents[0], p1))
assert(coral.isSameModel(loaded.xmi_extension[0].xmi_contents[1], p2))

