#!/usr/bin/env python
#
# Poseidon produces XMI files with only one end of
# a bidirectional connection connected.
#
# Coral fixes this on-the-fly
#

import coral
L = coral.lang.UML14

st = coral.loadDocument("poseidon_subclassing.xmi")

m = st.contents()[0]
e1  = m.ownedElement[0]
e2  = m.ownedElement[1]
e3  = m.ownedElement[2]

csuper = None
csub = None
gen = None

if e1.oclIsKindOf(L.Class):
    if e1.name == "super":
        csuper = e1
    if e1.name == "sub":
        csub = e1
else:
    gen = e1

if e2.oclIsKindOf(L.Class):
    if e2.name == "super":
        csuper = e2
    if e2.name == "sub":
        csub = e2
else:
    gen = e2

if e3.oclIsKindOf(L.Class):
    if e3.name == "super":
        csuper = e3
    if e3.name == "sub":
        csub = e3
else:
    gen = e3

assert csuper
assert csub
assert gen

assert gen.child == csub
assert gen.parent == csuper
assert csub.generalization[0] == gen
assert csuper.specialization[0] == gen
