#!/usr/bin/env python
import coral

from coral.modeler import modeler

UML14 = coral.lang.UML14
XMIDI = coral.lang.XMIDI20

st = coral.Project()
m = UML14.Model()
c = UML14.Class()
gn_m = XMIDI.GraphNode()
gn_c = XMIDI.GraphNode()

m.__setProject__(st)
gn_c.__setProject__(st)

gn_m.contained.add(gn_c)
m.ownedElement.add(c)

gn_m.semanticModel = XMIDI.Uml1SemanticModelBridge()
gn_c.semanticModel = XMIDI.Uml1SemanticModelBridge()

gn_m.semanticModel.element = m
gn_c.semanticModel.element = c

TM = coral.getTransactionManager()
TM.beginModifyCmd()
try:
    c.namespace = None
finally:
    TM.endModifyCmd()

assert c.namespace is None
assert len(m.ownedElement) == 0
s = c.__getSlotByOppositeName__(XMIDI.Uml1SemanticModelBridge, "element")
assert len(s) == 0
assert gn_c.semanticModel.element is None
