from node.ext.uml.classes import (
    Class,
    Interface,
    Association,
    AssociationClass,
)
from agx.transform.xmi2uml.flavours import XMI2_1
from configure import registerXMIScope
from util import (
    isprofilemember,
    assignxmiprops,
)


tags = [XMI2_1.PACKAGED_ELEMENT]
registerXMIScope('package', 'xmi2uml', tags, 'uml:Package')


@handler('package', 'xmi2uml', 'hierarchygenerator', 'package')
def package(self, source, target):
    """Create packages.
    """
    package = Package()
    assignxmiprops(package,source)
    target.anchor[source.attributes['name']] = package
    target.finalize(source, package)


tags = [XMI2_1.PACKAGED_ELEMENT]
registerXMIScope('class', 'xmi2uml', tags, 'uml:Class')
        uppervalue = INFINITE
    else:
        uppervalue = int(uppervalue)
    associationend.uppervalue = uppervalue
    lowervalue = source['lowerValue'].attributes.get('value', '*') if source.has_key('lowervalue') else 1
    if lowervalue == '*':
        lowervalue = INFINITE
    else:
        lowervalue = int(lowervalue)
    associationend.lowervalue = lowervalue
    target.anchor[source.attributes['name']] = associationend
    target.finalize(source, associationend)


tags = [XMI2_1.PACKAGED_ELEMENT]
registerXMIScope('dependency', 'xmi2uml', tags, 'uml:Dependency')


@handler('dependency', 'xmi2uml', 'datatypedependentgenerator',
         'dependency', order=20)
def dependency(self, source, target):
    if isprofilemember(source):
        return
    tok = token('sourcetotargetuuidmapping', False)
    supplier_source = source.refindex[source.attributes['supplier']]
    supplieruuid = tok.uuids[supplier_source.uuid]
    supplier = target.anchor.node(supplieruuid)
    client_source = source.refindex[source.attributes['client']]
    clientuuid = tok.uuids[client_source.uuid]
    client = target.anchor.node(clientuuid)
    dependency = Dependency()
tags = get_active_flavour().profiles()
# XXX: should be implemented, so that regexps are supported
registerXMLScope("profile", "xmi2uml", tags)


@handler("profile", "xmi2uml", "profilegenerator", "profile")
def profile(self, source, target):
    """Create profile.
    """
    profile = Profile()
    target.anchor.root[source.attributes["name"]] = profile
    write_source_to_target_mapping(source, profile)


tags = [get_active_flavour().PACKAGED_ELEMENT]
registerXMIScope("stereotypedef", "xmi2uml", tags, "uml:Stereotype")


@handler("stereotypetokenizer", "xmi2uml", "profilegenerator", "stereotypedef")
def stereotypetokenizer(self, source, target):
    """Collect stereotype definitions from UML profile.
    """
    next = source
    while True:
        next = next.__parent__
        if IXMINode.providedBy(next) or next is None:
            break
        profilexml = next
    profile = profilexml.values()[0].attributes["name"]

    defs = {