# This file is part of the Coral project.
# Please read the copyright notice in the LICENSE file.

from coral import log
logger=log.getLogger("coral")
# This file was created automatically by SWIG.
# Don't modify this file, modify the SWIG interface instead.
# This file is compatible with both classic and new-style classes.
import libcoral as _coral

import inspect
from coral.exceptions import WFRException
import os
import os.path

def formatWellFormedRuleException(rule,object):
    t = object.__type__()
    p = []
    while t:
        p.append(t.getName())
        t = t.__package__()
    p.reverse()
    ps = "::".join(p)
    s=    "\nRule name: " + ps + "." + rule.getFuncName()+"\n"
    try:
        s=s+"Rule body:\n" + object.getCode()
    except:
        pass
    s = s + "Offender:" + str(object) + "\n"
    return s

def isWellFormed(self,toIgnore=[]):
    cl = self.__type__().getAllSuperclasses()
    cl.append(self.__type__())
    for c in cl:
        for op in c.__operations__():
            if op.getFuncName() in toIgnore:
                continue
            if not op.isWFR():
                continue
            if not op.getFunc()(self):
                raise WFRException("Well-formed rule " + c.getName() + "." + op.getFuncName() + " does not hold " + formatWellFormedRuleException(op, self), self)

def _swig_setattr(self,class_type,name,value):
    if (name == "this"):
        if isinstance(value, class_type):
            self.__dict__[name] = value.this
            return
    method = class_type.__swig_setmethods__.get(name,None)
    if method: return method(self,value)
    self.__dict__[name] = value

def _swig_getattr(self,class_type,name):
    method = class_type.__swig_getmethods__.get(name,None)
    if method: return method(self)
    if isinstance(self, EnumerationDefinition):
    	return self.getIndexByDescription(name)
    raise AttributeError,name

def Element_swig_setattr(self,name,value):
    if name == "__project__":
        return self.__setProject__(value)
    vtype = type(value)
    if vtype == list or issubclass(vtype, Slot):
        if self.__type__().getPropertyByName(name).getTarget() == coralPyObj:
            self.__getSlotByNameInsert__(name, value)
            return
        feature = self.__getattr__(name)
        feature.resetSlot()
        for i in value:
            feature.add(i)
    elif value is None or isinstance(value, Element):
        self.__getSlotByNameInsertElement__(name, value)
    else:
        self.__getSlotByNameInsert__(name, value)

import types
try:
    _object = types.ObjectType
    _newclass = 1
except AttributeError:
    class _object : pass
    _newclass = 0


class ref_counted(_object):
    def __del__(self, *args):
        if _coral: self.unref()
    __swig_setmethods__ = {}
    __setattr__ = lambda self, name, value: _swig_setattr(self, ref_counted, name, value)
    __swig_getmethods__ = {}
    __getattr__ = lambda self, name: _swig_getattr(self, ref_counted, name)
    def __init__(self,*args):
        _swig_setattr(self, ref_counted, 'this', _coral.new_ref_counted(*args))
    def ref(*args): return _coral.ref_counted_ref(*args)
    def unref(*args): return _coral.ref_counted_unref(*args)
    def get_ref_count(*args): return _coral.ref_counted_get_ref_count(*args)
    def get_id(*args): return _coral.ref_counted_get_id(*args)
    def __eq__(*args): return _coral.ref_counted___eq__(*args)
    def __ne__(*args): return _coral.ref_counted___ne__(*args)
    def __hash__(*args): return _coral.ref_counted___hash__(*args)
    def __repr__(self):
        return "<C ref_counted instance at %s>" % (self.this,)

class ref_countedPtr(ref_counted):
    def __init__(self,this):
        _swig_setattr(self, ref_counted, 'this', this)
_coral.ref_counted_swigregister(ref_countedPtr)

class ModelFeatureIterator(ref_counted):
    __swig_setmethods__ = {}
    for _s in [ref_counted]: __swig_setmethods__.update(_s.__swig_setmethods__)
    __setattr__ = lambda self, name, value: _swig_setattr(self, ModelFeatureIterator, name, value)
    __swig_getmethods__ = {}
    for _s in [ref_counted]: __swig_getmethods__.update(_s.__swig_getmethods__)
    __getattr__ = lambda self, name: _swig_getattr(self, ModelFeatureIterator, name)
    def __init__(self,*args):
        _swig_setattr(self, ModelFeatureIterator, 'this', _coral.new_ModelFeatureIterator(*args))
    def __iter__(*args): return _coral.ModelFeatureIterator___iter__(*args)
    def next(*args):
        t = _coral.ModelFeatureIterator_next(*args)
        if t is None: raise StopIteration
        return t
    def __repr__(self):
        return "<C ModelFeatureIterator instance at %s>" % (self.this,)

class ModelFeatureIteratorPtr(ModelFeatureIterator):
    def __init__(self,this):
    	self.__dict__["this"] = this
_coral.ModelFeatureIterator_swigregister(ModelFeatureIteratorPtr)

class PropertyIterator(ref_counted):
    __swig_setmethods__ = {}
    for _s in [ref_counted]: __swig_setmethods__.update(_s.__swig_setmethods__)
    __setattr__ = lambda self, name, value: _swig_setattr(self, PropertyIterator, name, value)
    __swig_getmethods__ = {}
    for _s in [ref_counted]: __swig_getmethods__.update(_s.__swig_getmethods__)
    __getattr__ = lambda self, name: _swig_getattr(self, PropertyIterator, name)
    def __init__(self,*args):
        _swig_setattr(self, PropertyIterator, 'this', _coral.new_PropertyIterator(*args))
    def __iter__(*args): return _coral.PropertyIterator___iter__(*args)
    def next(*args):
        t = _coral.PropertyIterator_next(*args)
        if t is None: raise StopIteration
        return t
    def __repr__(self):
        return "<C PropertyIterator instance at %s>" % (self.this,)

class PropertyIteratorPtr(PropertyIterator):
    def __init__(self,this):
    	self.__dict__["this"] = this
_coral.PropertyIterator_swigregister(PropertyIteratorPtr)

class SuperClassesIterator(ref_counted):
    __swig_setmethods__ = {}
    for _s in [ref_counted]: __swig_setmethods__.update(_s.__swig_setmethods__)
    __setattr__ = lambda self, name, value: _swig_setattr(self, SuperClassesIterator, name, value)
    __swig_getmethods__ = {}
    for _s in [ref_counted]: __swig_getmethods__.update(_s.__swig_getmethods__)
    __getattr__ = lambda self, name: _swig_getattr(self, SuperClassesIterator, name)
    def __init__(self,*args):
        _swig_setattr(self, SuperClassesIterator, 'this', _coral.new_SuperClassesIterator(*args))
    def __iter__(*args): return _coral.SuperClassesIterator___iter__(*args)
    def next(*args):
        t = _coral.SuperClassesIterator_next(*args)
        if t is None: raise StopIteration
        return t
    def __repr__(self):
        return "<C SuperClassesIterator instance at %s>" % (self.this,)

class SuperClassesIteratorPtr(SuperClassesIterator):
    def __init__(self,this):
    	self.__dict__["this"] = this
_coral.SuperClassesIterator_swigregister(SuperClassesIteratorPtr)

class SubClassesIterator(ref_counted):
    __swig_setmethods__ = {}
    for _s in [ref_counted]: __swig_setmethods__.update(_s.__swig_setmethods__)
    __setattr__ = lambda self, name, value: _swig_setattr(self, SubClassesIterator, name, value)
    __swig_getmethods__ = {}
    for _s in [ref_counted]: __swig_getmethods__.update(_s.__swig_getmethods__)
    __getattr__ = lambda self, name: _swig_getattr(self, SubClassesIterator, name)
    def __init__(self,*args):
        _swig_setattr(self, SubClassesIterator, 'this', _coral.new_SubClassesIterator(*args))
    def __iter__(*args): return _coral.SubClassesIterator___iter__(*args)
    def next(*args):
        t = _coral.SubClassesIterator_next(*args)
        if t is None: raise StopIteration
        return t
    def __repr__(self):
        return "<C SubClassesIterator instance at %s>" % (self.this,)

class SubClassesIteratorPtr(SubClassesIterator):
    def __init__(self,this):
    	self.__dict__["this"] = this
_coral.SubClassesIterator_swigregister(SubClassesIteratorPtr)

class AllSuperClassesIterator(ref_counted):
    __swig_setmethods__ = {}
    for _s in [ref_counted]: __swig_setmethods__.update(_s.__swig_setmethods__)
    __setattr__ = lambda self, name, value: _swig_setattr(self, AllSuperClassesIterator, name, value)
    __swig_getmethods__ = {}
    for _s in [ref_counted]: __swig_getmethods__.update(_s.__swig_getmethods__)
    __getattr__ = lambda self, name: _swig_getattr(self, AllSuperClassesIterator, name)
    def __init__(self,*args):
        _swig_setattr(self, AllSuperClassesIterator, 'this', _coral.new_AllSuperClassesIterator(*args))
    def __iter__(*args): return _coral.AllSuperClassesIterator___iter__(*args)
    def next(*args):
        t = _coral.AllSuperClassesIterator_next(*args)
        if t is None: raise StopIteration
        return t
    def __repr__(self):
        return "<C AllSuperClassesIterator instance at %s>" % (self.this,)

class AllSuperClassesIteratorPtr(AllSuperClassesIterator):
    def __init__(self,this):
        _swig_setattr(self, AllSuperClassesIterator, 'this', this)
_coral.AllSuperClassesIterator_swigregister(AllSuperClassesIteratorPtr)

class MDAEDIterator(ref_counted):
    __swig_setmethods__ = {}
    for _s in [ref_counted]: __swig_setmethods__.update(_s.__swig_setmethods__)
    __setattr__ = lambda self, name, value: _swig_setattr(self, MDAEDIterator, name, value)
    __swig_getmethods__ = {}
    for _s in [ref_counted]: __swig_getmethods__.update(_s.__swig_getmethods__)
    __getattr__ = lambda self, name: _swig_getattr(self, MDAEDIterator, name)
    def __init__(self,*args):
        _swig_setattr(self, MDAEDIterator, 'this', _coral.new_MDAEDIterator(*args))
    def __iter__(*args): return _coral.MDAEDIterator___iter__(*args)
    def next(*args):
        t = _coral.MDAEDIterator_next(*args)
        if t is None: raise StopIteration
        return t
    def __repr__(self):
        return "<C MDAEDIterator instance at %s>" % (self.this,)

class MDAEDIteratorPtr(MDAEDIterator):
    def __init__(self,this):
    	self.__dict__["this"] = this
_coral.MDAEDIterator_swigregister(MDAEDIteratorPtr)

class OperationsIterator(ref_counted):
    __swig_setmethods__ = {}
    for _s in [ref_counted]: __swig_setmethods__.update(_s.__swig_setmethods__)
    __setattr__ = lambda self, name, value: _swig_setattr(self, OperationsIterator, name, value)
    __swig_getmethods__ = {}
    for _s in [ref_counted]: __swig_getmethods__.update(_s.__swig_getmethods__)
    __getattr__ = lambda self, name: _swig_getattr(self, OperationsIterator, name)
    def __init__(self,*args):
        _swig_setattr(self, OperationsIterator, 'this', _coral.new_OperationsIterator(*args))
    def __iter__(*args): return _coral.OperationsIterator___iter__(*args)
    def next(*args):
        t = _coral.OperationsIterator_next(*args)
        if t is None: raise StopIteration
        return t
    def __repr__(self):
        return "<C OperationsIterator instance at %s>" % (self.this,)

class OperationsIteratorPtr(OperationsIterator):
    def __init__(self,this):
    	self.__dict__["this"] = this
_coral.OperationsIterator_swigregister(OperationsIteratorPtr)

class Atom(ref_counted):
    __swig_setmethods__ = {}
    for _s in [ref_counted]: __swig_setmethods__.update(_s.__swig_setmethods__)
    __setattr__ = lambda self, name, value: _swig_setattr(self, Atom, name, value)
    __swig_getmethods__ = {}
    for _s in [ref_counted]: __swig_getmethods__.update(_s.__swig_getmethods__)
    __getattr__ = lambda self, name: _swig_getattr(self, Atom, name)
    def __type__(*args): return _coral.Atom___type__(*args)
    def __isPart__(*args): return _coral.Atom___isPart__(*args)
    def __str__(*args): return _coral.Atom___str__(*args)
    def __asSet__(*args): return _coral.Atom___asSet__(*args)
    def oclIsKindOf(*args): return _coral.Atom_oclIsKindOf(*args)
    def __int__(*args): return _coral.Atom___int__(*args)
    def __long__(*args): return _coral.Atom___long__(*args)
    def __float__(*args): return _coral.Atom___float__(*args)
    def __getEValue__(*args): return _coral.Atom___getEValue__(*args)
    def __getEValueByName__(*args): return _coral.Atom___getEValueByName__(*args)
    def __setEValue__(*args): return _coral.Atom___setEValue__(*args)
    def __setEValueByName__(*args): return _coral.Atom___setEValueByName__(*args)
    def __getPyValue__(*args): return _coral.Atom___getPyValue__(*args)
    def __setPyValue__(*args): return _coral.Atom___setPyValue__(*args)
    def __getIValue__(*args): return _coral.Atom___getIValue__(*args)
    def __setIValue__(*args): return _coral.Atom___setIValue__(*args)
    def __getDValue__(*args): return _coral.Atom___getDValue__(*args)
    def __setDValue__(*args): return _coral.Atom___setDValue__(*args)
    def __setString__(*args): return _coral.Atom___setString__(*args)
    def __getString__(*args): return _coral.Atom___getString__(*args)
    def __init__(self): raise RuntimeError, "No constructor defined"
    def __repr__(self):
        return "<C Atom instance at %s>" % (self.this,)

class AtomPtr(Atom):
    def __init__(self,this):
        _swig_setattr(self, Atom, 'this', this)
_coral.Atom_swigregister(AtomPtr)

class Element(Atom):
    def __call__(self,*args,**kargs):
        return self.__invoke__(*args,**kargs)
    def __kill__(self): 
        self.__setProject__(None)
        self.__resetAttrs__()
    def __getattr__(self, name):
        try:
            t = self.__getSlotByName__(name)
        except RuntimeError:
            if name == "__project__":
                return self.__getProject__()
            if name == "__meta__":
                return self.__type__().getCorrespondingElement()
            try:
                return self.__type__().__bindOperation__(name,self)
            except AttributeError:
                try:
                    operation = self.__type__().__bindOperation__("__browse__", self)(name)
                except AttributeError:
                    raise AttributeError("AttributeError: " + str(self) + " has no attribute '" + str(name) + "'")
                return operation
        if t.getProperty().isAtMostOne():
            # This makes things much faster, but we always have to keep the same slot!
            self.__dict__[name] = t[0]
            return t[0]
        # This makes things much faster, but we always have to keep the same slot!
        self.__dict__[name] = t
        return t

    __swig_setmethods__ = {}
    for _s in [Atom]: __swig_setmethods__.update(_s.__swig_setmethods__)
    __setattr__ = lambda self, name, value: Element_swig_setattr(self, name, value)
    __swig_getmethods__ = {}
    for _s in [Atom]: __swig_getmethods__.update(_s.__swig_getmethods__)
    def __init__(self,*args):
        _swig_setattr(self, Element, 'this', _coral.new_Element(*args))
    def __XMIid__(*args): return _coral.Element___XMIid__(*args)
    def __resetXMIid__(*args): return _coral.Element___resetXMIid__(*args)
    def __switchType__(*args): return _coral.Element___switchType__(*args)
    def isWellFormed(*args): return _coral.Element_isWellFormed(*args)
    def isWellFormedRecursive(*args): return _coral.Element_isWellFormedRecursive(*args)
    def __parent__(*args): return _coral.Element___parent__(*args)
    def __parentSlot__(*args): return _coral.Element___parentSlot__(*args)
    def __getRoot__(*args): return _coral.Element___getRoot__(*args)
    def __getAllParts__(*args): return _coral.Element___getAllParts__(*args)
    def __getProject__(*args): return _coral.Element___getProject__(*args)
    def __setProject__(*args): return _coral.Element___setProject__(*args)
    def __getRootsProject__(*args): return _coral.Element___getRootsProject__(*args)
    def __setXMIid__(*args): return _coral.Element___setXMIid__(*args)
    def __hasSlotByName__(*args): return _coral.Element___hasSlotByName__(*args)
    def __getSlotRO__(*args): return _coral.Element___getSlotRO__(*args)
    def __getSlotByName__(*args): return _coral.Element___getSlotByName__(*args)
    def __getSlotByOppositeName__(*args): return _coral.Element___getSlotByOppositeName__(*args)
    def __getSlotByNameInsert__(*args): return _coral.Element___getSlotByNameInsert__(*args)
    def __getSlotByNameInsertElement__(*args): return _coral.Element___getSlotByNameInsertElement__(*args)
    def __getSlotOneElement__(*args): return _coral.Element___getSlotOneElement__(*args)
    def __type__(*args): return _coral.Element___type__(*args)
    def __isPart__(*args): return _coral.Element___isPart__(*args)
    def __isConnectedTo__(*args): return _coral.Element___isConnectedTo__(*args)
    def __resetAttrs__(*args): return _coral.Element___resetAttrs__(*args)
    def __all_slots__(*args): return _coral.Element___all_slots__(*args)
    def __properties__(*args): return _coral.Element___properties__(*args)
    def __repr__(self):
        return "<C Element instance at %s>" % (self.this,)

class ElementPtr(Element):
    def __init__(self,this):
    	self.__dict__["this"] = this
    	self.ref()
_coral.Element_swigregister(ElementPtr)

class Slot(_object):
    def __type__(self):
          return self.getProperty()
    def __getattr__(self, name):
        o = None
        if name == "__meta__":
            return self.__type__().getCorrespondingElement()
        c = self.getCollection().newSimilarCollection()
        isPrimitive = self.getProperty().getTarget().getPropertyByName(name).getTarget().isDatatypeDefinition()
        for i in self:
            if isPrimitive:
                # BUG assumes [0] exists
                c.add(i.__getSlotByName__(name)[0])
            else:
                for a in i.__getSlotByName__(name):
                    c.add(a)
        return c
    def __mul__(self, v):
        assert(type(v)==type(""))
        return v.join([str(x) for x in self])
    def collect(self, func):
        return self.getCollection().collect(func)
    def select(self, func):
        return self.getCollection().select(func)
    def reject(self, func):
        return self.getCollection().reject(func)
    def exists(self, func):
        return self.getCollection().exists(func)
    def forAll(self, func):
        return self.getCollection().forAll(func)
    def __setslice__(self, start, stop, contents):
        for i in xrange(start, stop):
            self.drop_index(start)
        for i in contents:
            self.insert(i, start)
            start += 1
    def __getslice__(self, start, stop):
        return [ self[i] for i in xrange(start, min(self.size(),stop)) ]
    __swig_setmethods__ = {}
    __setattr__ = lambda self, name, value: _swig_setattr(self, Slot, name, value)
    __swig_getmethods__ = {}
    def getElement(*args): return _coral.Slot_getElement(*args)
    def clone(*args): return _coral.Slot_clone(*args)
    def getCollection(*args): return _coral.Slot_getCollection(*args)
    def getProperty(*args): return _coral.Slot_getProperty(*args)
    def __iter__(*args): return _coral.Slot___iter__(*args)
    def __getitem__(*args): return _coral.Slot___getitem__(*args)
    def __str__(*args): return _coral.Slot___str__(*args)
    def __setitem__(*args): return _coral.Slot___setitem__(*args)
    def __len__(*args): return _coral.Slot___len__(*args)
    def size(*args): return _coral.Slot_size(*args)
    def resetSlot(*args): return _coral.Slot_resetSlot(*args)
    def insert(*args): return _coral.Slot_insert(*args)
    def drop(*args): return _coral.Slot_drop(*args)
    def remove(*args): return _coral.Slot_remove(*args)
    def drop_index(*args): return _coral.Slot_drop_index(*args)
    def add(*args): return _coral.Slot_add(*args)
    def append(*args): return _coral.Slot_append(*args)
    def __init__(self): raise RuntimeError, "No constructor defined"
    def __repr__(self):
        return "<C Slot instance at %s>" % (self.this,)

class SlotPtr(Slot):
    def __init__(self,this):
        _swig_setattr(self, Slot, 'this', this)
_coral.Slot_swigregister(SlotPtr)

class ElementPrimitive(Atom):
    def __getattr__(self,name):
        if name == "__meta__":
            return self.__type__().getCorrespondingElement()
        return _swig_getattr(self, ElementPrimitive, name)
    def __eq__(*args):
        o = args[1]
        s = args[0]
        t = type(o)
        if o is None:
            return False
        if t == int:
            return int(s) == o
        if t == float:
            return float(s) == o
        if t == unicode or t == str:
            return unicode(s) == o
        return _coral.ElementPrimitive___eq__(*args)
    def __ne__(*args):
        o = args[1]
        s = args[0]
        t = type(o)
        if o is None:
            return True
        if t == int:
            return int(s) != o
        if t == float:
            return float(s) != o
        if t == unicode or t == str:
            return unicode(s) != o
        return _coral.ElementPrimitive___ne__(*args)
    def __lt__(*args):
        o = args[1]
        s = args[0]
        t = type(o)
        if t == int:
            return int(s) < o
        if t == float:
            return float(s) < o
        if t == unicode or t == str:
            return unicode(s) < o
        return _coral.ElementPrimitive___lt__(*args)
    def __le__(*args):
        o = args[1]
        s = args[0]
        t = type(o)
        if t == int:
            return int(s) <= o
        if t == float:
            return float(s) <= o
        if t == unicode or t == str:
            return unicode(s) <= o
        return _coral.ElementPrimitive___le__(*args)
    def __gt__(*args):
        o = args[1]
        s = args[0]
        t = type(o)
        if t == int:
            return int(s) > o
        if t == float:
            return float(s) > o
        if t == unicode or t == str:
            return unicode(s) > o
        return _coral.ElementPrimitive___gt__(*args)
    def __ge__(*args):
        o = args[1]
        s = args[0]
        t = type(o)
        if t == int:
            return int(s) >= o
        if t == float:
            return float(s) >= o
        if t == unicode or t == str:
            return unicode(s) > o
        return _coral.ElementPrimitive___ge__(*args)

    def encode(self, encoding):
        return self.__str__().encode(encoding)
    def __getitem__(self, idx):
        if self.oclIsKindOf(String):
            return unicode(self)[idx]
        assert 0
    def __add__(self, other):
        if self.oclIsKindOf(UnlimitedInteger):
            return long(self) + other
        if self.oclIsKindOf(UnlimitedReal):
            return float(self) + other
        if self.oclIsKindOf(String):
            return unicode(self) + other
        assert 0
    def __sub__(self, other):
        if self.oclIsKindOf(UnlimitedInteger):
            return long(self) - other
        if self.oclIsKindOf(UnlimitedReal):
            return float(self) - other
        #if self.oclIsKindOf(String):
        #    return unicode(self) - other
        assert 0
    def __mul__(self, other):
        if self.oclIsKindOf(UnlimitedInteger):
            return long(self) * other
        if self.oclIsKindOf(UnlimitedReal):
            return float(self) * other
        if self.oclIsKindOf(String):
            return unicode(self) * other
        assert 0
    def __div__(self, other):
        if self.oclIsKindOf(UnlimitedInteger):
            return long(self) / other
        if self.oclIsKindOf(UnlimitedReal):
            return float(self) / other
        if self.oclIsKindOf(String):
            return unicode(self) / other
        assert 0
    def __floordiv__(self, other):
        if self.oclIsKindOf(UnlimitedInteger):
            return long(self) // other
        if self.oclIsKindOf(UnlimitedReal):
            return float(self) // other
        #if self.oclIsKindOf(String):
        #    return unicode(self) // other
        assert 0
    def __mod__(self, other):
        if self.oclIsKindOf(UnlimitedInteger):
            return long(self) % other
        if self.oclIsKindOf(UnlimitedReal):
            return float(self) % other
        #if self.oclIsKindOf(String):
        #    return unicode(self) % other
        assert 0
    def __radd__(self, other):
        if self.oclIsKindOf(UnlimitedInteger):
            return other + long(self)
        if self.oclIsKindOf(UnlimitedReal):
            return other + float(self)
        if self.oclIsKindOf(String):
            return other + unicode(self)
        assert 0
    def __rsub__(self, other):
        if self.oclIsKindOf(UnlimitedInteger):
            return other - long(self)
        if self.oclIsKindOf(UnlimitedReal):
            return other - float(self)
        #if self.oclIsKindOf(String):
        #    return other - unicode(self)
        assert 0
    def __rdiv__(self, other):
        if self.oclIsKindOf(UnlimitedInteger):
            return other / long(self)
        if self.oclIsKindOf(UnlimitedReal):
            return other / float(self)
        #if self.oclIsKindOf(String):
        #    return other / unicode(self)
        assert 0
    def __rfloordiv__(self, other):
        if self.oclIsKindOf(UnlimitedInteger):
            return other // long(self)
        if self.oclIsKindOf(UnlimitedReal):
            return other // float(self)
        #if self.oclIsKindOf(String):
        #    return other // unicode(self)
        assert 0
    def __neg__(self):
        if self.oclIsKindOf(UnlimitedInteger):
            return -long(self)
        if self.oclIsKindOf(UnlimitedReal):
            return -float(self)
        #if self.oclIsKindOf(String):
        #    return -unicode(self)
        assert 0
    def __pos__(self):
        if self.oclIsKindOf(UnlimitedInteger):
            return +long(self)
        if self.oclIsKindOf(UnlimitedReal):
            return +float(self)
        if self.oclIsKindOf(String):
            return +unicode(self)
        assert 0
    def __abs__(self):
        if self.oclIsKindOf(UnlimitedInteger):
            return abs(long(self))
        if self.oclIsKindOf(UnlimitedReal):
            return abs(float(self))
        #if self.oclIsKindOf(String):
        #    return abs(unicode(self))
        assert 0
    __swig_setmethods__ = {}
    for _s in [Atom]: __swig_setmethods__.update(_s.__swig_setmethods__)
    __setattr__ = lambda self, name, value: _swig_setattr(self, ElementPrimitive, name, value)
    __swig_getmethods__ = {}
    for _s in [Atom]: __swig_getmethods__.update(_s.__swig_getmethods__)
    def __type__(*args): return _coral.ElementPrimitive___type__(*args)
    def clone(*args): return _coral.ElementPrimitive_clone(*args)
    def reset(*args): return _coral.ElementPrimitive_reset(*args)
    def swapWithAtom(*args): return _coral.ElementPrimitive_swapWithAtom(*args)
    def __len__(*args): return _coral.ElementPrimitive___len__(*args)
    def __unicode__(*args): return _coral.ElementPrimitive___unicode__(*args)
    def __init__(self): raise RuntimeError, "No constructor defined"
    def __repr__(self):
        return "<C ElementPrimitive instance at %s>" % (self.this,)

class ElementPrimitivePtr(ElementPrimitive):
    def __init__(self,this):
    	self.__dict__["this"] = this
    	self.ref()
_coral.ElementPrimitive_swigregister(ElementPrimitivePtr)

setCorrespondingElement = _coral.setCorrespondingElement

class Meta2ModelBridge(ref_counted):
    __swig_setmethods__ = {}
    for _s in [ref_counted]: __swig_setmethods__.update(_s.__swig_setmethods__)
    __setattr__ = lambda self, name, value: _swig_setattr(self, Meta2ModelBridge, name, value)
    __swig_getmethods__ = {}
    for _s in [ref_counted]: __swig_getmethods__.update(_s.__swig_getmethods__)
    __getattr__ = lambda self, name: _swig_getattr(self, Meta2ModelBridge, name)
    def getCorrespondingElement(*args): return _coral.Meta2ModelBridge_getCorrespondingElement(*args)
    def __init__(self,*args):
        _swig_setattr(self, Meta2ModelBridge, 'this', _coral.new_Meta2ModelBridge(*args))
    def __repr__(self):
        return "<C Meta2ModelBridge instance at %s>" % (self.this,)

class Meta2ModelBridgePtr(Meta2ModelBridge):
    def __init__(self,this):
        _swig_setattr(self, Meta2ModelBridge, 'this', this)
_coral.Meta2ModelBridge_swigregister(Meta2ModelBridgePtr)

class AbstractElementDefinition(Meta2ModelBridge):

    def getOperations(self):
        return [ i for i in self.__operations__() ]
    def getSuperclasses(self):
        return [ i for i in self.__superclasses__() ]
    def getAllSuperclasses(self):
        return [ i for i in self.__all_superclasses__() ]
    def getSubclasses(self):
        return [ i for i in self.__subclasses__() ]

    __swig_setmethods__ = {}
    for _s in [Meta2ModelBridge]: __swig_setmethods__.update(_s.__swig_setmethods__)
    __setattr__ = lambda self, name, value: _swig_setattr(self, AbstractElementDefinition, name, value)
    __swig_getmethods__ = {}
    for _s in [Meta2ModelBridge]: __swig_getmethods__.update(_s.__swig_getmethods__)
    __getattr__ = lambda self, name: _swig_getattr(self, AbstractElementDefinition, name)
    def getOperation(*args): return _coral.AbstractElementDefinition_getOperation(*args)
    __swig_getmethods__["getAbstractElementDefinitionFromSMD"] = lambda x: _coral.AbstractElementDefinition_getAbstractElementDefinitionFromSMD
    if _newclass:getAbstractElementDefinitionFromSMD = staticmethod(_coral.AbstractElementDefinition_getAbstractElementDefinitionFromSMD)
    def __addOperation__(*args): return _coral.AbstractElementDefinition___addOperation__(*args)
    def __removeOperation__(*args): return _coral.AbstractElementDefinition___removeOperation__(*args)
    def __bindOperation__(*args): return _coral.AbstractElementDefinition___bindOperation__(*args)
    def isAbstract(*args): return _coral.AbstractElementDefinition_isAbstract(*args)
    def setAbstract(*args): return _coral.AbstractElementDefinition_setAbstract(*args)
    def getName(*args): return _coral.AbstractElementDefinition_getName(*args)
    def addSubclass(*args): return _coral.AbstractElementDefinition_addSubclass(*args)
    def addSuperclass(*args): return _coral.AbstractElementDefinition_addSuperclass(*args)
    def isDatatypeDefinition(*args): return _coral.AbstractElementDefinition_isDatatypeDefinition(*args)
    def isEnumerationDefinition(*args): return _coral.AbstractElementDefinition_isEnumerationDefinition(*args)
    def __package__(*args): return _coral.AbstractElementDefinition___package__(*args)
    def __language__(*args): return _coral.AbstractElementDefinition___language__(*args)
    def isRootDefinition(*args): return _coral.AbstractElementDefinition_isRootDefinition(*args)
    def isSubclass(*args): return _coral.AbstractElementDefinition_isSubclass(*args)
    def isProperSubclass(*args): return _coral.AbstractElementDefinition_isProperSubclass(*args)
    def __superclasses__(*args): return _coral.AbstractElementDefinition___superclasses__(*args)
    def __all_superclasses__(*args): return _coral.AbstractElementDefinition___all_superclasses__(*args)
    def __subclasses__(*args): return _coral.AbstractElementDefinition___subclasses__(*args)
    def __operations__(*args): return _coral.AbstractElementDefinition___operations__(*args)
    def isPresentation(*args): return _coral.AbstractElementDefinition_isPresentation(*args)
    def newAtom(*args): return _coral.AbstractElementDefinition_newAtom(*args)
    def newElement(*args): return _coral.AbstractElementDefinition_newElement(*args)
    def __str__(*args): return _coral.AbstractElementDefinition___str__(*args)
    def __init__(self): raise RuntimeError, "No constructor defined"
    def __repr__(self):
        return "<C AbstractElementDefinition instance at %s>" % (self.this,)

class AbstractElementDefinitionPtr(AbstractElementDefinition):
    def __init__(self,this):
    	self.__dict__["this"] = this
    	self.ref()
_coral.AbstractElementDefinition_swigregister(AbstractElementDefinitionPtr)
AbstractElementDefinition_getAbstractElementDefinitionFromSMD = _coral.AbstractElementDefinition_getAbstractElementDefinitionFromSMD


inheritanceTree = _coral.inheritanceTree

crossesPresentationLayer = _coral.crossesPresentationLayer

class ElementDefinition(AbstractElementDefinition):
    __swig_setmethods__ = {}
    for _s in [AbstractElementDefinition]: __swig_setmethods__.update(_s.__swig_setmethods__)
    __setattr__ = lambda self, name, value: _swig_setattr(self, ElementDefinition, name, value)
    __swig_getmethods__ = {}
    for _s in [AbstractElementDefinition]: __swig_getmethods__.update(_s.__swig_getmethods__)
    __getattr__ = lambda self, name: _swig_getattr(self, ElementDefinition, name)
    def __propagateProperties(*args): return _coral.ElementDefinition___propagateProperties(*args)
    def __init__(self,*args):
        _swig_setattr(self, ElementDefinition, 'this', _coral.new_ElementDefinition(*args))
    def addProperty(*args): return _coral.ElementDefinition_addProperty(*args)
    def addPropertyRecursive(*args): return _coral.ElementDefinition_addPropertyRecursive(*args)
    def getPropertyByName(*args): return _coral.ElementDefinition_getPropertyByName(*args)
    def getPropertyByOpposite(*args): return _coral.ElementDefinition_getPropertyByOpposite(*args)
    def isMOFDatatype(*args): return _coral.ElementDefinition_isMOFDatatype(*args)
    def setMOFDatatype(*args): return _coral.ElementDefinition_setMOFDatatype(*args)
    def __call__(*args, **kwargs):
    	elem = _coral.ElementDefinition___call__(*args)
    	for key in kwargs.keys():
    		setattr(elem, key, kwargs[key])
    	elem.unref()
    	return elem
    def isPresentation(*args): return _coral.ElementDefinition_isPresentation(*args)
    def __properties__(*args): return _coral.ElementDefinition___properties__(*args)
    def __repr__(self):
        return "<C ElementDefinition instance at %s>" % (self.this,)

class ElementDefinitionPtr(ElementDefinition):
    def __init__(self,this):
    	self.__dict__["this"] = this
    	self.ref()
_coral.ElementDefinition_swigregister(ElementDefinitionPtr)

class Property(Meta2ModelBridge):
    __swig_setmethods__ = {}
    for _s in [Meta2ModelBridge]: __swig_setmethods__.update(_s.__swig_setmethods__)
    __setattr__ = lambda self, name, value: _swig_setattr(self, Property, name, value)
    __swig_getmethods__ = {}
    for _s in [Meta2ModelBridge]: __swig_getmethods__.update(_s.__swig_getmethods__)
    __getattr__ = lambda self, name: _swig_getattr(self, Property, name)
    def getOwner(*args): return _coral.Property_getOwner(*args)
    def getROSlot(*args): return _coral.Property_getROSlot(*args)
    def getDefaultValue(*args): return _coral.Property_getDefaultValue(*args)
    def isMultSingle(*args): return _coral.Property_isMultSingle(*args)
    def isMultUnlimited(*args): return _coral.Property_isMultUnlimited(*args)
    def isAtMostOne(*args): return _coral.Property_isAtMostOne(*args)
    def isAtLeastOne(*args): return _coral.Property_isAtLeastOne(*args)
    def getMultLower(*args): return _coral.Property_getMultLower(*args)
    def getMultUpper(*args): return _coral.Property_getMultUpper(*args)
    def isOrdered(*args): return _coral.Property_isOrdered(*args)
    def isBag(*args): return _coral.Property_isBag(*args)
    def isBidirectional(*args): return _coral.Property_isBidirectional(*args)
    def isComposition(*args): return _coral.Property_isComposition(*args)
    def isAssociation(*args): return _coral.Property_isAssociation(*args)
    def isUnserializable(*args): return _coral.Property_isUnserializable(*args)
    def isAnonymous(*args): return _coral.Property_isAnonymous(*args)
    def getName(*args): return _coral.Property_getName(*args)
    def getTarget(*args): return _coral.Property_getTarget(*args)
    def getOppositeProperty(*args): return _coral.Property_getOppositeProperty(*args)
    def __init__(self,*args):
        _swig_setattr(self, Property, 'this', _coral.new_Property(*args))
    def __repr__(self):
        return "<C Property instance at %s>" % (self.this,)

class PropertyPtr(Property):
    def __init__(self,this):
    	self.__dict__["this"] = this
    	self.ref()
_coral.Property_swigregister(PropertyPtr)

class Package(AbstractElementDefinition):
    __swig_setmethods__ = {}
    for _s in [AbstractElementDefinition]: __swig_setmethods__.update(_s.__swig_setmethods__)
    __setattr__ = lambda self, name, value: _swig_setattr(self, Package, name, value)
    __swig_getmethods__ = {}
    for _s in [AbstractElementDefinition]: __swig_getmethods__.update(_s.__swig_getmethods__)
    def getXMLNS(*args): return _coral.Package_getXMLNS(*args)
    def setXMLNS(*args): return _coral.Package_setXMLNS(*args)
    def __elements__(*args): return _coral.Package___elements__(*args)
    def __imported_elements__(*args): return _coral.Package___imported_elements__(*args)
    def __language__(*args): return _coral.Package___language__(*args)
    def __init__(self,*args):
        _swig_setattr(self, Package, 'this', _coral.new_Package(*args))
    def getElement(*args): return _coral.Package_getElement(*args)
    def __getattr__(*args): return _coral.Package___getattr__(*args)
    def addElement(*args): return _coral.Package_addElement(*args)
    def removeElement(*args): return _coral.Package_removeElement(*args)
    def importElement(*args): return _coral.Package_importElement(*args)
    __swig_getmethods__["__getLanguageByXMLNS__"] = lambda x: _coral.Package___getLanguageByXMLNS__
    if _newclass:__getLanguageByXMLNS__ = staticmethod(_coral.Package___getLanguageByXMLNS__)
    def __repr__(self):
        return "<C Package instance at %s>" % (self.this,)

class PackagePtr(Package):
    def __init__(self,this):
    	self.__dict__["this"] = this
    	self.ref()
_coral.Package_swigregister(PackagePtr)
Package___getLanguageByXMLNS__ = _coral.Package___getLanguageByXMLNS__


class Language(Package):
    __swig_setmethods__ = {}
    for _s in [Package]: __swig_setmethods__.update(_s.__swig_setmethods__)
    __setattr__ = lambda self, name, value: _swig_setattr(self, Language, name, value)
    __swig_getmethods__ = {}
    for _s in [Package]: __swig_getmethods__.update(_s.__swig_getmethods__)
    def __init__(self,*args):
        _swig_setattr(self, Language, 'this', _coral.new_Language(*args))
    def setRoot(*args): return _coral.Language_setRoot(*args)
    def getRoot(*args): return _coral.Language_getRoot(*args)
    def getVersion(*args): return _coral.Language_getVersion(*args)
    def getRevision(*args): return _coral.Language_getRevision(*args)
    __swig_getmethods__["__getLanguage__"] = lambda x: _coral.Language___getLanguage__
    if _newclass:__getLanguage__ = staticmethod(_coral.Language___getLanguage__)
    def __repr__(self):
        return "<C Language instance at %s>" % (self.this,)

class LanguagePtr(Language):
    def __init__(self,this):
    	self.__dict__["this"] = this
    	self.ref()
_coral.Language_swigregister(LanguagePtr)
Language___getLanguage__ = _coral.Language___getLanguage__


class Collection(ref_counted):

    def __getattr__(self, name):
        o = None
        c = self.newSimilarCollection()
        for i in self:
            for a in i.__getSlotByName__(name):
                c.add(a)
        return c
    def __add__(self, coll):
        res = self.clone()
        res.unionWith(coll)
        return res
    def __sub__(self, coll):
        return self.clone().setDifference(coll)
    def __and__(self, coll):
        res = self.clone()
        res.intersectWith(coll)
        return res
    def unionWith(*args):
        if isinstance(args[1], Slot):
            return args[0].unionWith(args[1].getCollection())
        return _coral.Collection_unionWith(*args)
    def intersectWith(*args):
        if isinstance(args[1], Slot):
            return args[0].intersectWith(args[1].getCollection())
        return _coral.Collection_intersectWith(*args)
    def setDifference(*args):
        if isinstance(args[1], Slot):
            return args[0].setDifference(args[1].getCollection())
        return _coral.Collection_setDifference(*args)
    def collect(self, func):
        # Does not have to be a Bag explicitly.
        res = self.newSimilarCollection()
        for i in self:
            ans = func(i)
            if ans:
                res.append(ans)
        return res
    def select(self, func):
        res = self.newSimilarCollection()
        for i in self:
            if func(i):
                res.append(i)
        return res
    def reject(self, func):
        res = self.newSimilarCollection()
        for i in self:
            if not func(i):
                res.append(i)
        return res
    def forAll(self,f):
        nitems=self.__len__()
        if nitems == 0 or not inspect.getargspec(f)[0]:
            return 1

        nargs=len(inspect.getargspec(f)[0])
        if inspect.getargspec(f)[3]:
            nargs=nargs-len(inspect.getargspec(f)[3])
            
        assert(nargs>0)
        index=[0]*nargs
        
        our_elems = []
        for i in self:
            our_elems.append(i)
        
        while 1:
            args=[]
            for x in index:
                args.append(our_elems[x])
            if not f(*args):
                return 0
            c=len(index)-1
            index[c]=index[c]+1
            while index[c]==nitems:
                index[c]=0
                c=c-1
                if c<0:
                    return 1
                else:
                    index[c]=index[c]+1 
                if index[c]==nitems-1:
                    c=c-1

    def exists(self,f):
        nitems=self.__len__()
        if nitems == 0 or not inspect.getargspec(f)[0]:
            return 0

        nargs=len(inspect.getargspec(f)[0])
        if inspect.getargspec(f)[3]:
            nargs=nargs-len(inspect.getargspec(f)[3])
            
        assert(nargs>0)
        index=[0]*nargs
        
        our_elems = []
        for i in self:
            our_elems.append(i)
        
        while 1:
            args=[]
            for x in index:
                args.append(our_elems[x])
            if f(*args):
                return 1
            c=len(index)-1
            index[c]=index[c]+1
            while index[c]==nitems:
                index[c]=0
                c=c-1
                if c<0:
                    return 0
                else:
                    index[c]=index[c]+1 
                if index[c]==nitems-1:
                    c=c-1
		continue
    __swig_setmethods__ = {}
    for _s in [ref_counted]: __swig_setmethods__.update(_s.__swig_setmethods__)
    __setattr__ = lambda self, name, value: _swig_setattr(self, Collection, name, value)
    __swig_getmethods__ = {}
    for _s in [ref_counted]: __swig_getmethods__.update(_s.__swig_getmethods__)
    def isOrdered(*args): return _coral.Collection_isOrdered(*args)
    def isBag(*args): return _coral.Collection_isBag(*args)
    def size(*args): return _coral.Collection_size(*args)
    def __len__(*args): return _coral.Collection___len__(*args)
    def isEmpty(*args): return _coral.Collection_isEmpty(*args)
    def __nonzero__(*args): return _coral.Collection___nonzero__(*args)
    def nonEmpty(*args): return _coral.Collection_nonEmpty(*args)
    def includes(*args): return _coral.Collection_includes(*args)
    def __contains__(*args): return _coral.Collection___contains__(*args)
    def excludes(*args): return _coral.Collection_excludes(*args)
    def count(*args): return _coral.Collection_count(*args)
    def includesAll(*args): return _coral.Collection_includesAll(*args)
    def excludesAll(*args): return _coral.Collection_excludesAll(*args)
    def __iter__(*args): return _coral.Collection___iter__(*args)
    def insert(*args): return _coral.Collection_insert(*args)
    def __getitem__(*args): return _coral.Collection___getitem__(*args)
    def __setitem__(*args): return _coral.Collection___setitem__(*args)
    def remove_keepref(*args): return _coral.Collection_remove_keepref(*args)
    def drop(*args): return _coral.Collection_drop(*args)
    def add(*args): return _coral.Collection_add(*args)
    def append(*args): return _coral.Collection_append(*args)
    def drop_index(*args): return _coral.Collection_drop_index(*args)
    def reset(*args): return _coral.Collection_reset(*args)
    def __str__(*args): return _coral.Collection___str__(*args)
    def __unicode__(*args): return _coral.Collection___unicode__(*args)
    def newSimilarCollection(*args): return _coral.Collection_newSimilarCollection(*args)
    def clone(*args): return _coral.Collection_clone(*args)
    __swig_getmethods__["newCollection"] = lambda x: _coral.Collection_newCollection
    if _newclass:newCollection = staticmethod(_coral.Collection_newCollection)
    def __init__(self): raise RuntimeError, "No constructor defined"
    def __repr__(self):
        return "<C Collection instance at %s>" % (self.this,)

class CollectionPtr(Collection):
    def __init__(self,this):
    	self.__dict__["this"] = this
    	self.ref()
_coral.Collection_swigregister(CollectionPtr)
Collection_newCollection = _coral.Collection_newCollection


class Bag(Collection):
    __swig_setmethods__ = {}
    for _s in [Collection]: __swig_setmethods__.update(_s.__swig_setmethods__)
    __setattr__ = lambda self, name, value: _swig_setattr(self, Bag, name, value)
    __swig_getmethods__ = {}
    for _s in [Collection]: __swig_getmethods__.update(_s.__swig_getmethods__)
    def __init__(self,*args):
        _swig_setattr(self, Bag, 'this', _coral.new_Bag(*args))
    def __repr__(self):
        return "<C Bag instance at %s>" % (self.this,)

class BagPtr(Bag):
    def __init__(self,this):
    	self.__dict__["this"] = this
    	self.ref()
_coral.Bag_swigregister(BagPtr)

class OrderedSet(Collection):
    __swig_setmethods__ = {}
    for _s in [Collection]: __swig_setmethods__.update(_s.__swig_setmethods__)
    __setattr__ = lambda self, name, value: _swig_setattr(self, OrderedSet, name, value)
    __swig_getmethods__ = {}
    for _s in [Collection]: __swig_getmethods__.update(_s.__swig_getmethods__)
    def __init__(self,*args):
        _swig_setattr(self, OrderedSet, 'this', _coral.new_OrderedSet(*args))
    def __repr__(self):
        return "<C OrderedSet instance at %s>" % (self.this,)

class OrderedSetPtr(OrderedSet):
    def __init__(self,this):
    	self.__dict__["this"] = this
    	self.ref()
_coral.OrderedSet_swigregister(OrderedSetPtr)

class Sequence(Collection):
    __swig_setmethods__ = {}
    for _s in [Collection]: __swig_setmethods__.update(_s.__swig_setmethods__)
    __setattr__ = lambda self, name, value: _swig_setattr(self, Sequence, name, value)
    __swig_getmethods__ = {}
    for _s in [Collection]: __swig_getmethods__.update(_s.__swig_getmethods__)
    def __init__(self,*args):
        _swig_setattr(self, Sequence, 'this', _coral.new_Sequence(*args))
    def __repr__(self):
        return "<C Sequence instance at %s>" % (self.this,)

class SequencePtr(Sequence):
    def __init__(self,this):
    	self.__dict__["this"] = this
    	self.ref()
_coral.Sequence_swigregister(SequencePtr)

class Set(Collection):
    __swig_setmethods__ = {}
    for _s in [Collection]: __swig_setmethods__.update(_s.__swig_setmethods__)
    __setattr__ = lambda self, name, value: _swig_setattr(self, Set, name, value)
    __swig_getmethods__ = {}
    for _s in [Collection]: __swig_getmethods__.update(_s.__swig_getmethods__)
    def __init__(self,*args):
        _swig_setattr(self, Set, 'this', _coral.new_Set(*args))
    def __repr__(self):
        return "<C Set instance at %s>" % (self.this,)

class SetPtr(Set):
    def __init__(self,this):
    	self.__dict__["this"] = this
    	self.ref()
_coral.Set_swigregister(SetPtr)

class Iterator(ref_counted):
    __swig_setmethods__ = {}
    for _s in [ref_counted]: __swig_setmethods__.update(_s.__swig_setmethods__)
    __setattr__ = lambda self, name, value: _swig_setattr(self, Iterator, name, value)
    __swig_getmethods__ = {}
    for _s in [ref_counted]: __swig_getmethods__.update(_s.__swig_getmethods__)
    __getattr__ = lambda self, name: _swig_getattr(self, Iterator, name)
    def __init__(self,*args):
        _swig_setattr(self, Iterator, 'this', _coral.new_Iterator(*args))
    def next(*args):
        t = _coral.Iterator_next(*args)
        if t is None: raise StopIteration
        return t
    def __iter__(*args): return _coral.Iterator___iter__(*args)
    def __repr__(self):
        return "<C Iterator instance at %s>" % (self.this,)

class IteratorPtr(Iterator):
    def __init__(self,this):
    	self.__dict__["this"] = this
_coral.Iterator_swigregister(IteratorPtr)

class DatatypeDefinition(AbstractElementDefinition):
    __swig_setmethods__ = {}
    for _s in [AbstractElementDefinition]: __swig_setmethods__.update(_s.__swig_setmethods__)
    __setattr__ = lambda self, name, value: _swig_setattr(self, DatatypeDefinition, name, value)
    __swig_getmethods__ = {}
    for _s in [AbstractElementDefinition]: __swig_getmethods__.update(_s.__swig_getmethods__)
    __getattr__ = lambda self, name: _swig_getattr(self, DatatypeDefinition, name)
    def __init__(self,*args):
        _swig_setattr(self, DatatypeDefinition, 'this', _coral.new_DatatypeDefinition(*args))
    def __repr__(self):
        return "<C DatatypeDefinition instance at %s>" % (self.this,)

class DatatypeDefinitionPtr(DatatypeDefinition):
    def __init__(self,this):
    	self.__dict__["this"] = this
    	self.ref()
_coral.DatatypeDefinition_swigregister(DatatypeDefinitionPtr)

class EnumerationDefinition(DatatypeDefinition):
    __swig_setmethods__ = {}
    for _s in [DatatypeDefinition]: __swig_setmethods__.update(_s.__swig_setmethods__)
    __setattr__ = lambda self, name, value: _swig_setattr(self, EnumerationDefinition, name, value)
    __swig_getmethods__ = {}
    for _s in [DatatypeDefinition]: __swig_getmethods__.update(_s.__swig_getmethods__)
    __getattr__ = lambda self, name: _swig_getattr(self, EnumerationDefinition, name)
    def __init__(self,*args):
        _swig_setattr(self, EnumerationDefinition, 'this', _coral.new_EnumerationDefinition(*args))
    def __addEnum__(*args): return _coral.EnumerationDefinition___addEnum__(*args)
    def getDescription(*args): return _coral.EnumerationDefinition_getDescription(*args)
    def getIndexByDescription(*args): return _coral.EnumerationDefinition_getIndexByDescription(*args)
    def size(*args): return _coral.EnumerationDefinition_size(*args)
    def __repr__(self):
        return "<C EnumerationDefinition instance at %s>" % (self.this,)

class EnumerationDefinitionPtr(EnumerationDefinition):
    def __init__(self,this):
    	self.__dict__["this"] = this
    	self.ref()
_coral.EnumerationDefinition_swigregister(EnumerationDefinitionPtr)

class PyOperation(ref_counted):
    __swig_setmethods__ = {}
    for _s in [ref_counted]: __swig_setmethods__.update(_s.__swig_setmethods__)
    __setattr__ = lambda self, name, value: _swig_setattr(self, PyOperation, name, value)
    __swig_getmethods__ = {}
    for _s in [ref_counted]: __swig_getmethods__.update(_s.__swig_getmethods__)
    __getattr__ = lambda self, name: _swig_getattr(self, PyOperation, name)
    def __init__(self,*args):
        _swig_setattr(self, PyOperation, 'this', _coral.new_PyOperation(*args))
    def getFunc(*args): return _coral.PyOperation_getFunc(*args)
    def isWFR(*args): return _coral.PyOperation_isWFR(*args)
    def getFuncName(*args): return _coral.PyOperation_getFuncName(*args)
    def getCode(*args): return _coral.PyOperation_getCode(*args)
    def __call__(*args, **kwargs):
    	elem = _coral.ElementDefinition___call__(*args)
    	for key in kwargs.keys():
    		setattr(elem, key, kwargs[key])
    	elem.unref()
    	return elem
    def getOperationLanguage(*args): return _coral.PyOperation_getOperationLanguage(*args)
    def __repr__(self):
        return "<C PyOperation instance at %s>" % (self.this,)

class PyOperationPtr(PyOperation):
    def __init__(self,this):
    	self.__dict__["this"] = this
    	self.ref()
_coral.PyOperation_swigregister(PyOperationPtr)

class Project(ref_counted):
    __swig_setmethods__ = {}
    for _s in [ref_counted]: __swig_setmethods__.update(_s.__swig_setmethods__)
    __setattr__ = lambda self, name, value: _swig_setattr(self, Project, name, value)
    __swig_getmethods__ = {}
    for _s in [ref_counted]: __swig_getmethods__.update(_s.__swig_getmethods__)
    __getattr__ = lambda self, name: _swig_getattr(self, Project, name)
    def __init__(self,*args):
        _swig_setattr(self, Project, 'this', _coral.new_Project(*args))
    def __str__(*args): return _coral.Project___str__(*args)
    def isInvalid(*args): return _coral.Project_isInvalid(*args)
    def isUserProject(*args): return _coral.Project_isUserProject(*args)
    def setUserProject(*args): return _coral.Project_setUserProject(*args)
    def invalidate(*args): return _coral.Project_invalidate(*args)
    def setInvalid(*args): return _coral.Project_setInvalid(*args)
    def getXMIFormat(*args): return _coral.Project_getXMIFormat(*args)
    def setXMIFormat(*args): return _coral.Project_setXMIFormat(*args)
    def contents(*args): return _coral.Project_contents(*args)
    def setFilename(*args): return _coral.Project_setFilename(*args)
    def getFilename(*args): return _coral.Project_getFilename(*args)
    def getHrefFilename(*args): return _coral.Project_getHrefFilename(*args)
    __swig_getmethods__["getProjectByFilename"] = lambda x: _coral.Project_getProjectByFilename
    if _newclass:getProjectByFilename = staticmethod(_coral.Project_getProjectByFilename)
    def __repr__(self):
        return "<C Project instance at %s>" % (self.this,)

class ProjectPtr(Project):
    def __init__(self,this):
    	self.__dict__["this"] = this
    	self.ref()
_coral.Project_swigregister(ProjectPtr)
Project_getProjectByFilename = _coral.Project_getProjectByFilename


getAllProjects = _coral.getAllProjects

getCanonicalFilename = _coral.getCanonicalFilename

getCoralPath = _coral.getCoralPath

setCoralPath = _coral.setCoralPath

addXMLNSRmap = _coral.addXMLNSRmap

xmlns_db_size = _coral.xmlns_db_size

xmlns_db_xmlns = _coral.xmlns_db_xmlns

xmlns_db_filename = _coral.xmlns_db_filename

xmlns_db_metamodelname = _coral.xmlns_db_metamodelname

xmlns_db_version = _coral.xmlns_db_version

xmlns_db_revision = _coral.xmlns_db_revision

garbage_collect = _coral.garbage_collect

ModelCopy = _coral.ModelCopy

ModelCopy_One = _coral.ModelCopy_One

isSameModel = _coral.isSameModel

Element__getMyselfAndParents__ = _coral.Element__getMyselfAndParents__

Element__getParentsAndMyself__ = _coral.Element__getParentsAndMyself__

XMIDI_LocalToGlobalPosition = _coral.XMIDI_LocalToGlobalPosition

XMIDI_GlobalToLocalPosition = _coral.XMIDI_GlobalToLocalPosition

XMIDI_HasReferentialRole = _coral.XMIDI_HasReferentialRole

XMIDI_find_property_upwards = _coral.XMIDI_find_property_upwards

XMIDI_find_either_property_upwards = _coral.XMIDI_find_either_property_upwards

ModelDifference = _coral.ModelDifference

ModelDifference_One = _coral.ModelDifference_One

smd2lang = _coral.smd2lang

getDebugLog = _coral.getDebugLog

setDebugObserver = _coral.setDebugObserver

getUniqueID = _coral.getUniqueID

class Transaction(ref_counted):
    __swig_setmethods__ = {}
    for _s in [ref_counted]: __swig_setmethods__.update(_s.__swig_setmethods__)
    __setattr__ = lambda self, name, value: _swig_setattr(self, Transaction, name, value)
    __swig_getmethods__ = {}
    for _s in [ref_counted]: __swig_getmethods__.update(_s.__swig_getmethods__)
    __getattr__ = lambda self, name: _swig_getattr(self, Transaction, name)
    def __init__(self,*args):
        _swig_setattr(self, Transaction, 'this', _coral.new_Transaction(*args))
    def __str__(*args): return _coral.Transaction___str__(*args)
    def size(*args): return _coral.Transaction_size(*args)
    def __getitem__(*args): return _coral.Transaction___getitem__(*args)
    def __repr__(self):
        return "<C Transaction instance at %s>" % (self.this,)

class TransactionPtr(Transaction):
    def __init__(self,this):
    	self.__dict__["this"] = this
    	self.ref()
_coral.Transaction_swigregister(TransactionPtr)

class Command(ref_counted):
    __swig_setmethods__ = {}
    for _s in [ref_counted]: __swig_setmethods__.update(_s.__swig_setmethods__)
    __setattr__ = lambda self, name, value: _swig_setattr(self, Command, name, value)
    __swig_getmethods__ = {}
    for _s in [ref_counted]: __swig_getmethods__.update(_s.__swig_getmethods__)
    __getattr__ = lambda self, name: _swig_getattr(self, Command, name)
    def __str__(*args): return _coral.Command___str__(*args)
    def execute(*args): return _coral.Command_execute(*args)
    def unexecute(*args): return _coral.Command_unexecute(*args)
    def __init__(self): raise RuntimeError, "No constructor defined"
    def __repr__(self):
        return "<C Command instance at %s>" % (self.this,)

class CommandPtr(Command):
    def __init__(self,this):
    	self.__dict__["this"] = this
    	self.ref()
_coral.Command_swigregister(CommandPtr)

class ElementCommand(Command):
    __swig_setmethods__ = {}
    for _s in [Command]: __swig_setmethods__.update(_s.__swig_setmethods__)
    __setattr__ = lambda self, name, value: _swig_setattr(self, ElementCommand, name, value)
    __swig_getmethods__ = {}
    for _s in [Command]: __swig_getmethods__.update(_s.__swig_getmethods__)
    __getattr__ = lambda self, name: _swig_getattr(self, ElementCommand, name)
    def getAtom(*args): return _coral.ElementCommand_getAtom(*args)
    def __init__(self): raise RuntimeError, "No constructor defined"
    def __repr__(self):
        return "<C ElementCommand instance at %s>" % (self.this,)

class ElementCommandPtr(ElementCommand):
    def __init__(self,this):
    	self.__dict__["this"] = this
    	self.ref()
_coral.ElementCommand_swigregister(ElementCommandPtr)

class NewProjectCommand(Command):
    __swig_setmethods__ = {}
    for _s in [Command]: __swig_setmethods__.update(_s.__swig_setmethods__)
    __setattr__ = lambda self, name, value: _swig_setattr(self, NewProjectCommand, name, value)
    __swig_getmethods__ = {}
    for _s in [Command]: __swig_getmethods__.update(_s.__swig_getmethods__)
    __getattr__ = lambda self, name: _swig_getattr(self, NewProjectCommand, name)
    def __init__(self,*args):
        _swig_setattr(self, NewProjectCommand, 'this', _coral.new_NewProjectCommand(*args))
    def getNewProject(*args): return _coral.NewProjectCommand_getNewProject(*args)
    def __repr__(self):
        return "<C NewProjectCommand instance at %s>" % (self.this,)

class NewProjectCommandPtr(NewProjectCommand):
    def __init__(self,this):
    	self.__dict__["this"] = this
    	self.ref()
_coral.NewProjectCommand_swigregister(NewProjectCommandPtr)

class ProjectNameChangeCommand(Command):
    __swig_setmethods__ = {}
    for _s in [Command]: __swig_setmethods__.update(_s.__swig_setmethods__)
    __setattr__ = lambda self, name, value: _swig_setattr(self, ProjectNameChangeCommand, name, value)
    __swig_getmethods__ = {}
    for _s in [Command]: __swig_getmethods__.update(_s.__swig_getmethods__)
    __getattr__ = lambda self, name: _swig_getattr(self, ProjectNameChangeCommand, name)
    def __init__(self,*args):
        _swig_setattr(self, ProjectNameChangeCommand, 'this', _coral.new_ProjectNameChangeCommand(*args))
    def getProject(*args): return _coral.ProjectNameChangeCommand_getProject(*args)
    def getOldFilename(*args): return _coral.ProjectNameChangeCommand_getOldFilename(*args)
    def getOldHrefFilename(*args): return _coral.ProjectNameChangeCommand_getOldHrefFilename(*args)
    def __repr__(self):
        return "<C ProjectNameChangeCommand instance at %s>" % (self.this,)

class ProjectNameChangeCommandPtr(ProjectNameChangeCommand):
    def __init__(self,this):
    	self.__dict__["this"] = this
    	self.ref()
_coral.ProjectNameChangeCommand_swigregister(ProjectNameChangeCommandPtr)

class ProjectChangeCommand(ElementCommand):
    __swig_setmethods__ = {}
    for _s in [ElementCommand]: __swig_setmethods__.update(_s.__swig_setmethods__)
    __setattr__ = lambda self, name, value: _swig_setattr(self, ProjectChangeCommand, name, value)
    __swig_getmethods__ = {}
    for _s in [ElementCommand]: __swig_getmethods__.update(_s.__swig_getmethods__)
    __getattr__ = lambda self, name: _swig_getattr(self, ProjectChangeCommand, name)
    def __init__(self,*args):
        _swig_setattr(self, ProjectChangeCommand, 'this', _coral.new_ProjectChangeCommand(*args))
    def getOldProject(*args): return _coral.ProjectChangeCommand_getOldProject(*args)
    def __repr__(self):
        return "<C ProjectChangeCommand instance at %s>" % (self.this,)

class ProjectChangeCommandPtr(ProjectChangeCommand):
    def __init__(self,this):
    	self.__dict__["this"] = this
    	self.ref()
_coral.ProjectChangeCommand_swigregister(ProjectChangeCommandPtr)

class ChangeElementPrimitiveCommand(ElementCommand):
    __swig_setmethods__ = {}
    for _s in [ElementCommand]: __swig_setmethods__.update(_s.__swig_setmethods__)
    __setattr__ = lambda self, name, value: _swig_setattr(self, ChangeElementPrimitiveCommand, name, value)
    __swig_getmethods__ = {}
    for _s in [ElementCommand]: __swig_getmethods__.update(_s.__swig_getmethods__)
    __getattr__ = lambda self, name: _swig_getattr(self, ChangeElementPrimitiveCommand, name)
    def __init__(self,*args):
        _swig_setattr(self, ChangeElementPrimitiveCommand, 'this', _coral.new_ChangeElementPrimitiveCommand(*args))
    def getNewAtom(*args): return _coral.ChangeElementPrimitiveCommand_getNewAtom(*args)
    def __repr__(self):
        return "<C ChangeElementPrimitiveCommand instance at %s>" % (self.this,)

class ChangeElementPrimitiveCommandPtr(ChangeElementPrimitiveCommand):
    def __init__(self,this):
    	self.__dict__["this"] = this
    	self.ref()
_coral.ChangeElementPrimitiveCommand_swigregister(ChangeElementPrimitiveCommandPtr)

class ElementChangeSlotCommand(ElementCommand):
    __swig_setmethods__ = {}
    for _s in [ElementCommand]: __swig_setmethods__.update(_s.__swig_setmethods__)
    __setattr__ = lambda self, name, value: _swig_setattr(self, ElementChangeSlotCommand, name, value)
    __swig_getmethods__ = {}
    for _s in [ElementCommand]: __swig_getmethods__.update(_s.__swig_getmethods__)
    __getattr__ = lambda self, name: _swig_getattr(self, ElementChangeSlotCommand, name)
    def __init__(self,*args):
        _swig_setattr(self, ElementChangeSlotCommand, 'this', _coral.new_ElementChangeSlotCommand(*args))
    def getSlot(*args): return _coral.ElementChangeSlotCommand_getSlot(*args)
    def __repr__(self):
        return "<C ElementChangeSlotCommand instance at %s>" % (self.this,)

class ElementChangeSlotCommandPtr(ElementChangeSlotCommand):
    def __init__(self,this):
    	self.__dict__["this"] = this
    	self.ref()
_coral.ElementChangeSlotCommand_swigregister(ElementChangeSlotCommandPtr)

class ElementNewCommand(ElementCommand):
    __swig_setmethods__ = {}
    for _s in [ElementCommand]: __swig_setmethods__.update(_s.__swig_setmethods__)
    __setattr__ = lambda self, name, value: _swig_setattr(self, ElementNewCommand, name, value)
    __swig_getmethods__ = {}
    for _s in [ElementCommand]: __swig_getmethods__.update(_s.__swig_getmethods__)
    __getattr__ = lambda self, name: _swig_getattr(self, ElementNewCommand, name)
    def __init__(self,*args):
        _swig_setattr(self, ElementNewCommand, 'this', _coral.new_ElementNewCommand(*args))
    def getNewElement(*args): return _coral.ElementNewCommand_getNewElement(*args)
    def __repr__(self):
        return "<C ElementNewCommand instance at %s>" % (self.this,)

class ElementNewCommandPtr(ElementNewCommand):
    def __init__(self,this):
    	self.__dict__["this"] = this
    	self.ref()
_coral.ElementNewCommand_swigregister(ElementNewCommandPtr)

class ElementUUIDCommand(ElementCommand):
    __swig_setmethods__ = {}
    for _s in [ElementCommand]: __swig_setmethods__.update(_s.__swig_setmethods__)
    __setattr__ = lambda self, name, value: _swig_setattr(self, ElementUUIDCommand, name, value)
    __swig_getmethods__ = {}
    for _s in [ElementCommand]: __swig_getmethods__.update(_s.__swig_getmethods__)
    __getattr__ = lambda self, name: _swig_getattr(self, ElementUUIDCommand, name)
    def __init__(self,*args):
        _swig_setattr(self, ElementUUIDCommand, 'this', _coral.new_ElementUUIDCommand(*args))
    def getOldXMIid(*args): return _coral.ElementUUIDCommand_getOldXMIid(*args)
    def __repr__(self):
        return "<C ElementUUIDCommand instance at %s>" % (self.this,)

class ElementUUIDCommandPtr(ElementUUIDCommand):
    def __init__(self,this):
    	self.__dict__["this"] = this
    	self.ref()
_coral.ElementUUIDCommand_swigregister(ElementUUIDCommandPtr)

getTransactionManager = _coral.getTransactionManager

class Manager(_object):
    __swig_setmethods__ = {}
    __setattr__ = lambda self, name, value: _swig_setattr(self, Manager, name, value)
    __swig_getmethods__ = {}
    __getattr__ = lambda self, name: _swig_getattr(self, Manager, name)
    def already_modified(*args): return _coral.Manager_already_modified(*args)
    def isUndoOrRedo(*args): return _coral.Manager_isUndoOrRedo(*args)
    def addObserver(*args): return _coral.Manager_addObserver(*args)
    def addBusyObserver(*args): return _coral.Manager_addBusyObserver(*args)
    def removeBusyObserver(*args): return _coral.Manager_removeBusyObserver(*args)
    def removeObserver(*args): return _coral.Manager_removeObserver(*args)
    def getAmountOfTransactions(*args): return _coral.Manager_getAmountOfTransactions(*args)
    def getCurrentTransactionPosition(*args): return _coral.Manager_getCurrentTransactionPosition(*args)
    def getTransaction(*args): return _coral.Manager_getTransaction(*args)
    def getCurrentTransaction(*args): return _coral.Manager_getCurrentTransaction(*args)
    def beginModifyCmd(*args): return _coral.Manager_beginModifyCmd(*args)
    def endModifyCmd(*args):
        res = _coral.Manager_endModifyCmd(*args)
        if res:
            storages = Project.getAllProjects()
            try:
                for st in storages:
                    for r in st.contents():
                        success = r.isWellFormedRecursive()
                        if not success:
                            raise WFRException()
            except:
                args[0].undo()
                raise #Re-raise it
    def beginTransaction(*args): return _coral.Manager_beginTransaction(*args)
    def endTransaction(*args):
        return Manager.endModifyCmd(*args)
    def beginStrictTransaction(*args): return _coral.Manager_beginStrictTransaction(*args)
    def endStrictTransaction(*args):
        return Manager.endModifyCmd(*args)
    def isCreatingTransaction(*args): return _coral.Manager_isCreatingTransaction(*args)
    def getHistoryLimit(*args): return _coral.Manager_getHistoryLimit(*args)
    def setHistoryLimit(*args): return _coral.Manager_setHistoryLimit(*args)
    def trimPast(*args): return _coral.Manager_trimPast(*args)
    def trimFuture(*args): return _coral.Manager_trimFuture(*args)
    def clear(*args): return _coral.Manager_clear(*args)
    def canUndo(*args): return _coral.Manager_canUndo(*args)
    def canRedo(*args): return _coral.Manager_canRedo(*args)
    def undo(*args): return _coral.Manager_undo(*args)
    def redo(*args): return _coral.Manager_redo(*args)
    def __init__(self): raise RuntimeError, "No constructor defined"
    def __repr__(self):
        return "<C Manager instance at %s>" % (self.this,)

class ManagerPtr(Manager):
    def __init__(self,this):
        _swig_setattr(self, Manager, 'this', this)
_coral.Manager_swigregister(ManagerPtr)

loadModel = _coral.loadModel

saveModel = _coral.saveModel

loadDocument = _coral.loadDocument

loadDocument_str = _coral.loadDocument_str

saveDocument = _coral.saveDocument

saveDocument_str = _coral.saveDocument_str

getSupportedXMIVersions = _coral.getSupportedXMIVersions


# This file is part of the Coral project.
# Please read the copyright notice in the LICENSE file.
#
# Coral's version
#
version = "0.8.1"
#
# Build date
build_date = ""

#
# Installation path
installation_path = ""

#
# The kind_t from coral/core/AbstractElementDefinition.h
#

def implies(a,b):
    return not a or b

class kind_t:
    KIND_ORDERED = 1
    KIND_BAG = 2
    KIND_BIDI = 4
    KIND_NOSERIALIZE = 8
    KIND_ANONYMOUS = 16
    KIND_COMPOSITION = 32
    KIND_ASSOCIATION = 64
    
MODELCOPY_DONT_CREATE_NEW_UUIDS = 1
MODELCOPY_DONT_ATTACH_TO_PARENTS = 2
MODELCOPY_DONT_SKIP_PYOBJECTS = 4
MODELCOPY_DONT_KEEP_ASSOCIATIONS_OUTSIDE_SUBTREE = 8

TRANSACTION_REDO = 0
TRANSACTION_UNDO = 1
TRANSACTION_ORDINARY = 2

MODELDIFFERENCE_IGNORE_DIAGRAM_INFORMATION = 1
MODELDIFFERENCE_ONLY_DIAGRAM_INFORMATION = 2

#
# The Coral CORE metamodel
#
__core = Language.__getLanguage__("CORE", 0, 1)
Name = __core.getElement("Name")
String = __core.getElement("String")
Boolean = __core.getElement("Boolean")
Integer = __core.getElement("Integer")
UnlimitedInteger = __core.getElement("UnlimitedInteger")
UnlimitedReal = __core.getElement("UnlimitedReal")
Float = __core.getElement("Float")
Double = __core.getElement("Double")
coralPyObj = __core.getElement("coralPyObj")

AnyElement = __core.getElement("AnyElement")
AnyAbstractElement = __core.getElement("AnyAbstractElement")
PresentationElement = __core.getElement("PresentationElement")

#
# XML namespaces
#

def __fixXMLNS(thelist):
    # Add reverse mappings from XML namespaces to metamodels
    import re
    for __i in thelist:
        __lines = []
        try:
            __f = open(__i, "r")
        except:
            continue
        try:
            __lines=__f.readlines()
        finally:
            __f.close()
        if len(__lines)>2:
            __name=""
            __major=-1
            __minor=-1
            __filename=""
            __xmlns = []
            for __l in __lines:
                __m = re.search("^name\s+(.*)", __l)
                if __m:
                    __name = __m.group(1)
                __m = re.search("^file\s+(.*)", __l)
                if __m:
                    __filename = __m.group(1)
                __m = re.search("^version\s+(.*)", __l)
                if __m:
                    __major = int(__m.group(1))
                __m = re.search("^revision\s+(.*)", __l)
                if __m:
                    __minor = int(__m.group(1))
                __m = re.search("^xmlns\s+(.*)", __l)
                if __m:
                    __xmlns.append(__m.group(1))
            if __filename == "":
                print "ERROR Language " + __name + str(__major) + str(__minor) + " has no filename defined in its manifest.txt!"
                continue
            if __filename[0] != "/":
                __filename = os.path.split(__i)[0] + os.sep + __filename
            if __name == "" \
               or __xmlns == []:
                continue
            for __x in __xmlns:
                _coral.addXMLNSRmap(__x, __filename, __name, __major, __minor)

#
# Add languages found under
# coral/lang/*
# and
# ~/.coral/coral/lang/*
# to the kernel's knowledge
#
import glob
__fixXMLNS(glob.glob(installation_path + "/coral/lang/*/manifest*.txt"))
import configuration
_user_home = configuration.getUserHome()
__fixXMLNS(glob.glob(_user_home + "/.coral/coral/lang/*/manifest*.txt"))
del configuration
del _user_home
del glob

class __PythonLanguageProxy:
    def __getattr__(self,name):
        assert(len(name)>=3)
        # UML_1_4 ?
        i = name.split("_")
        if (len(i)==3):
            return Language.__getLanguage__(i[0], int(i[1]), int(i[2]))
        # UML14 ?        
        return Language.__getLanguage__(name[:-2], int(name[-2:-1]), int(name[-1:]))

    def __call__(self,name,version,revision):
        return Language.__getLanguage__(name, int(version), int(revision))

lang = __PythonLanguageProxy()

# Begin of "unification" patch
class __PythonMetamodelProxy:
    def __getattr__(self,name):
        if not name:
            return None
        
        L = getattr(lang, name)
        if not L:
            return None
        else:
            return L.getCorrespondingElement()

    def __call__(self,name,version,revision):
        return lang(name,version,revision).getCorrespondingElement()

meta = __PythonMetamodelProxy()

##def __browse__(self,name):
##    return self.elements.select(lambda e: e.name==name)[0]

##def __invoke__(self,*args,**kargs):
##    name=self.name
##    edclass=None

##    print "I am slow: ALG1"
##    p=self.package

##    while(not p.oclIsKindOf(lang.SMD01.Language)):
##          p=p.package

##    l = Language.__getLanguage__(unicode(p.name), int(p.version),int(p.revision))
         
##    if l:
##        edclass=l.getElement(unicode(name))            
##    return edclass(*args,**kargs)

##lang.SMD01.Package.__addOperation__(PyOperation(__browse__,"Python",inspect.getsource(__browse__),0))

##lang.SMD01.ElementDefinition.__addOperation__(PyOperation(__invoke__,"Python",inspect.getsource(__invoke__),0))

# Atom.oclIsKindOf should work with SMD elements

# return true of ElementDefinition a is a subtype of ElementDefinition b

def isSubType(a,b):
    while(a):
        if a==b:
            return True
        else:
            for s in a.superclasses:
                if isSubType(s,b):
                    return True
        return False

def oclIsKindOf(self,c):
    if isinstance(c,AbstractElementDefinition):
        return _coral.Atom_oclIsKindOf(self, c)
    else:
        return isSubType(self.__meta__, c)
                

Atom.oclIsKindOf= oclIsKindOf


# slot search by name

def getItemByPositionOrByName(self,q):
    if type(q)==type(""):
        return self.select(lambda e: e.name==q)[0]
    else:
        return _coral.Slot___getitem__(self, q)

Slot.__getitem__= getItemByPositionOrByName

# End of "unification" patch



# Don't use this crap.
def __import__(self,dict):
    # ugly hack to import a language into a namespace
    for x in self.__elements__():
        dict[x.getName()]=x
Language.__import__=__import__
        


TransactionManager=getTransactionManager()

def find(element,query):
    return element.__getAllParts__().select(query)

# User Projects

Project.addModel = (lambda self, e: e.__setProject__(self))
Project.saveToDocument= (lambda self: saveDocument(self))
                  
def loadDocument(*args,**kargs):
    prj=_coral.loadDocument(*args,**kargs)
    prj.setUserProject(True)
    return prj

def loadInternalDocument(*args,**kargs):
    prj = _coral.loadDocument(*args,**kargs)
    prj.setUserProject(False)
    return prj

def __addOperationsToInternalModel(language, langstring):
    for p in language.elements:
        for o in p.operations:
            code=""
            for l in o.code:
                code += str(l)+"\n"
            exec compile(code,"<string>","exec")
            eval(langstring+p.name).__addOperation__(PyOperation(eval(str(o.name)),"Python",str(o.name),0))    

# The kernel has a built SMD01 language. However, the user
# can define *additional* operations in the SMD01 metamodel.
# Currently ther kernel does not load them. This really ugly
# code does that
# The same goeas for the CORE01 metamodel

__addOperationsToInternalModel(meta.SMD01,"lang.SMD01.")
__addOperationsToInternalModel(meta.CORE01,"lang.CORE01.")


def newProject(metamodel,projectName=""):
    "create a project based on language"
    prj = Project()
    if projectName:
        prj.setFileName(prj)
    root = metamodel.root_ed()
    root.__setProject__(prj)
    return (prj,root)



#
# Convenient (debug?) shorthand to get a set of graphnodes that are
# connected to our element
#
def gfx(element):
    return element.xmidi_get_graphelements()


import site

copyright=site._Printer("copyright","""@@@COPYRIGHT@@@""")
license=site._Printer("license","""@@@LICENSE@@@""")
credits=site._Printer("credits","""@@@CREDITS@@@""")

# Hide all projects that have been used so far
for p in getAllProjects():
    p.setUserProject(False)
