def attr_parse(parent: UMLClass, element, root): attr = UMLAttribute(parent, element.get('name'), element.get('{%s}id' % ns['xmi'])) attr.visibility = element.get('visibility') type_elem = element.find('type') if type_elem is not None: type_id = type_elem.get('{%s}idref' % ns['xmi']) if type_id[:4] == 'EAID': attr.classification_id = type_id else: logging.error( f"Attribute {attr.name} of class {parent} does not have a type") # Detail is sparx sprecific # TODO: Put modelling tool in settings and use tool specific parser here detail = root.xpath("//attribute[@xmi:idref='%s']" % attr.id, namespaces=ns)[0] properties = detail.find('properties') attr.set_type(properties.get('type')) doc = detail.find('documentation') doc = doc.get('value') if doc is not None: attr.documentation = doc alias_node = detail.find('style') attr.alias = alias_node.get('value') xrefs = detail.find('xrefs') if xrefs.get('value') is not None and 'NAME=isID' in xrefs.get('value'): attr.is_id = True attr.parent.id_attribute = attr else: attr.is_id = False stereotype = detail.find('stereotype') if stereotype is not None: attr.stereotype = stereotype.get('stereotype') constraints = detail.find('Constraints') if constraints is not None: for constraint in constraints: name = constraint.get('name') if name == 'unique': attr.is_unique = True elif name.startswith('length'): attr.length = int(name.split("=")[1]) return attr
def attr_parse(parent: UMLClass, element, root): attr = UMLAttribute(parent, element.get('name'), element.get('{%s}id' % ns['xmi'])) attr.visibility = element.get('visibility') type_elem = element.find('type') type_id = type_elem.get('{%s}idref' % ns['xmi']) if type_id[:4] == 'EAID': attr.classification_id = type_id # Detail is sparx sprecific # TODO: Put modelling tool in settings and use tool specific parser here detail = root.xpath("//attribute[@xmi:idref='%s']" % attr.id, namespaces=ns)[0] properties = detail.find('properties') attr.type = properties.get('type') if properties.get('type') in generation_fields[ settings['generation_type']].keys(): attr.dest_type = generation_fields[settings['generation_type']][ properties.get('type')] else: attr.dest_type = properties.get('type') xrefs = detail.find('xrefs') if xrefs.get('value') is not None and 'NAME=isID' in xrefs.get('value'): attr.is_id = True attr.parent.id_attribute = attr else: attr.is_id = False # Todo: decide how to include string lengths in UML if attr.type == 'string': attr.length = 100 stereotype = detail.find('stereotype') if stereotype is not None: attr.stereotype = stereotype.get('stereotype') constraints = detail.find('Constraints') if constraints is not None: for constraint in constraints: name = constraint.get('name') if name == 'unique': attr.is_unique = True elif name.startswith('length'): attr.length = int(name.split("=")[1]) return attr