#!/usr/bin/env python
import coral
#M = coral.loadModel("../../lang/UML14/def/UML14.xmi")
M = coral.loadModel("tmp/uml14_with_operation.xml")
assert M

# This failed at some point...
# complicated way to find PresentationElement...
me = M.elements.select(lambda x: x.name == "ModelElement")[0]
assert me
assert me.name == "ModelElement"
anyabstractelement = me.superclasses[0]
assert anyabstractelement
assert anyabstractelement.name == "AnyAbstractElement"
print "We're now at AnyAbstractElement"
anyelement = anyabstractelement.superclasses[0]
assert anyelement
assert anyelement.name == "AnyElement"

print "we're now at AnyElement"
conn = anyelement.properties.select(lambda x: x.name == "xmi_extension")[0]
assert(conn)

assert(conn.element_kind)
print conn.element_kind.name


L = coral.smd2lang(M)
assert L
print "LANGUAGE", L

assert L.getRoot() is not None
assert L.getRoot() == L.getElement("Model")
assert L.getXMLNS() == "http://schema.omg.org/spec/UML/1.4"


# MODEL SIDE

me = M.elements.select(lambda x: x.name == "ModelElement")[0]
assert me
assert me.name == "ModelElement"
anyabstractelement = me.superclasses[0]
assert anyabstractelement
assert anyabstractelement.name == "AnyAbstractElement"
anyelement = anyabstractelement.superclasses[0]
assert anyelement
assert anyelement.name == "AnyElement"


# METAMODEL SIDE

me = L.getElement("ModelElement")
assert me
assert me.getName() == "ModelElement"
anyabstractelement = me.getSuperclasses()[0]
assert anyabstractelement
assert anyabstractelement.getName() == "AnyAbstractElement"
anyelement = anyabstractelement.getSuperclasses()[0]
assert anyelement
assert anyelement.getName() == "AnyElement"

UML14Class = L.getElement("Class")
C = UML14Class()
assert(C)
print C.name

print "---OPERATIONS---"
for op in UML14Class.__operations__():
    print op
    print op.getFuncName()
print "---END OPS---"
print

C.myFunction()

print
print "---END---"
