Esempio n. 1
0
def attr_parse(parent: UMLClass, element, root, stereotypes) -> UMLAttribute:
    value = element.get("value").strip("<div>").strip("</div>").strip("<br")
    # height = int(element.find("mxGeometry").get("y"))

    dq = []
    if "{dq_even}" in value:
        dq.append('even')
        value = value.replace("{dq_even}", "").strip()

    is_id = False
    if "{id}" in value:
        is_id = True
        value = value.replace("{id}", "").strip()

    visibility: bool = False
    if value.startswith("+"):
        visibility = True
    value = value.strip("+").strip("-").strip()

    name, attr_type = value.split(":")

    attr = UMLAttribute(parent, name, element.get('id'))
    if is_id:
        attr.is_id = is_id
        parent.id_attribute = attr
    attr.visibility = visibility

    attr.validations = dq

    attr.set_type(attr_type.strip())

    return attr
Esempio n. 2
0
 def setUp(self):
     self.tree = etree.fromstring("""
                 <xmi:XMI xmi:version="2.1" xmlns:uml="http://schema.omg.org/spec/UML/2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" xmlns:thecustomprofile="http://www.sparxsystems.com/profiles/thecustomprofile/1.0">
                     <packagedElement xmi:type="uml:Association" xmi:id="EAID_3CFEE303_0F7B_46c6_81DE_D14F1BED8EA7" visibility="public">
                         <memberEnd xmi:idref="EAID_dstFEE303_0F7B_46c6_81DE_D14F1BED8EA7"/>
                         <memberEnd xmi:idref="EAID_srcFEE303_0F7B_46c6_81DE_D14F1BED8EA7"/>
                         <ownedEnd xmi:type="uml:Property" xmi:id="EAID_srcFEE303_0F7B_46c6_81DE_D14F1BED8EA7" visibility="public" association="EAID_3CFEE303_0F7B_46c6_81DE_D14F1BED8EA7" isStatic="false" isReadOnly="false" isDerived="false" isOrdered="false" isUnique="true" isDerivedUnion="false" aggregation="composite">
                             <type xmi:idref="EAID_DEFD1F62_622E_479b_8CB9_E219E818F917"/>
                             <lowerValue xmi:type="uml:LiteralInteger" xmi:id="EAID_LI000003__0F7B_46c6_81DE_D14F1BED8EA7" value="0"/>
                             <upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="EAID_LI000004__0F7B_46c6_81DE_D14F1BED8EA7" value="-1"/>
                         </ownedEnd>
                     </packagedElement>
                 </xmi:XMI>""")
     self.package = UMLPackage("id", "name")
     self.source = UMLClass(self.package, "source", "id")
     self.dest = UMLClass(self.package, "dest", "id")
Esempio n. 3
0
def class_parse(package: UMLPackage, element, root) -> UMLClass:
    stereotypes = []
    label = element.get("label").split("<div>")
    if len(label) == 1:
        name = label[0].replace("<b>", "").replace("</b>", "").replace(
            "<i>", "").replace("</i>", "").replace('<br>', "").strip()
    else:
        name = label[-1].replace("</div>", "").replace("<b>", "").replace(
            "</b>", "").replace("<i>", "").replace("</i>",
                                                   "").replace('<br>',
                                                               "").strip()
        stereotypes = label[-2].split('&lt;&lt;')[-1].split(
            '&gt;&gt;')[0].split(',')

    id = element.get("id")
    cls = UMLClass(package, name, id)
    for stereotype in stereotypes:
        cls.stereotypes.append(stereotype.strip())

    abstract = element.get("Abstract")
    if abstract is not None and abstract == "True":
        cls.is_abstract = True

    logger.debug("Added UMLClass {}".format(cls.name))

    children = root.findall(
        './diagram/mxGraphModel/root/mxCell[@parent="{}"]'.format(id))
    # Grab a list of the attribute stereotypes and their heights
    stereotypes = []
    for child in children:
        value = child.get("value")
        if "<<" in value:
            geometry = child.find("mxGeometry")
            stereotypes.append(
                (value.strip("<<").strip(">>"), int(geometry.get("y"))))

    # Create all the attributes
    for child in children:
        value = child.get("value")
        if value[0:2] != "<<":
            attr = attr_parse(cls, child, root, stereotypes)
            cls.attributes.append(attr)

    return cls
Esempio n. 4
0
def class_parse(package, element, root):
    cls: UMLClass = UMLClass(package, element.get('name'),
                             element.get('{%s}id' % ns['xmi']))
    if element.get('isAbstract') == 'true':
        cls.is_abstract = True
    else:
        cls.is_abstract = False

    # If the class is inherited from a superclass then get the ID. The actual object will be found in a separate pass
    # as it may not have been parsed yet
    generalization_element = element.find('generalization')
    if generalization_element is not None:
        cls.generalization_id = generalization_element.get('general')

    # Loop through class elements children for attributes.
    for child in element:
        e_type = child.get('{%s}type' % ns['xmi'])

        if e_type == 'uml:Property':
            # Associations will be done in a separate pass
            if child.get('association') is None and child.get(
                    'name') is not None:
                attr = attr_parse(cls, child, root)
                cls.attributes.append(attr)

    # Detail is sparx sprecific
    # TODO: Put modelling tool in settings and use tool specific parser here
    detail = root.xpath("//element[@xmi:idref='%s']" % cls.id,
                        namespaces=ns)[0]
    properties = detail.find('properties')
    cls.alias = properties.get('alias')
    cls.documentation = properties.get('documentation')
    if cls.documentation is None:
        cls.documentation = ""

    project = detail.find('project')
    cls.status = project.get('status')

    # Get stereotypes, when multiple are provided only the first is found in the stereotype tag but all are found in
    # xrefs
    xrefs = detail.find('xrefs')
    value = xrefs.get('value')
    if value is not None:
        cls.stereotypes = re.findall('@STEREO;Name=(.*?);', value)

    logger.debug(f"Added UMLClass {cls.name}")
    return cls
Esempio n. 5
0
 def setUp(self):
     self.tree = etree.fromstring("""
                 <xmi:XMI xmi:version="2.1" xmlns:uml="http://schema.omg.org/spec/UML/2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" xmlns:thecustomprofile="http://www.sparxsystems.com/profiles/thecustomprofile/1.0">
                     <packagedElement xmi:type="uml:Class" xmi:id="EAID_5A9CB912_F283_41ae_9E4D_D73598C576AE" name="ExternalReference" visibility="public">
                         <generalization xmi:type="uml:Generalization" xmi:id="EAID_77E50BFE_0D46_43af_9C90_896E06269211" general="12345"/>
                     </packagedElement>
                     <element xmi:idref="EAID_5A9CB912_F283_41ae_9E4D_D73598C576AE" xmi:type="uml:Class" name="ExternalReference" scope="public">
                         <model package="EAPK_EA154075_33FD_455d_B07A_FCBD08A7882D" tpos="0" ea_localid="664" ea_eleType="element"/>
                         <properties isSpecification="false" sType="Class" nType="0" scope="public" isRoot="false" isLeaf="false" isActive="false"/>
                         <project author="atkinp" version="1.0" phase="1.0" created="2019-07-24 08:42:52" modified="2020-06-23 19:23:20" complexity="1" status="Proposed"/>
                         <code gentype="Java"/>
                         <style appearance="BackColor=-1;BorderColor=-1;BorderWidth=-1;FontColor=-1;VSwimLanes=1;HSwimLanes=1;BorderStyle=0;"/>
                         <tags/>
                         <xrefs/>
                         <extendedProperties tagged="0" package_name="Common"/>
                     </element>
                 </xmi:XMI>""")
     self.package = UMLPackage("id", "name")
     self.generalization = UMLClass(self.package, "source", "12345")
Esempio n. 6
0
def attr_parse(parent: UMLClass, element, root, stereotypes) -> UMLAttribute:
    value = element.get("value").strip("<div>").strip("</div>").strip("<br")
    # height = int(element.find("mxGeometry").get("y"))

    dq = []
    if "{dq_even}" in value:
        dq.append('even')
        value = value.replace("{dq_even}", "").strip()

    is_id = False
    if "{id}" in value:
        is_id = True
        value = value.replace("{id}", "").strip()

    visibility: bool = False
    if value.startswith("+"):
        visibility = True
    value = value.strip("+").strip("-").strip()

    name, attr_type = value.split(":")
    attr_type = attr_type.strip()

    attr = UMLAttribute(parent, name, element.get('id'))
    if is_id:
        attr.is_id = is_id
        parent.id_attribute = attr
    attr.visibility = visibility

    attr.validations = dq

    attr.type = attr_type
    if attr.type == 'string':
        attr.length = 100

    if attr_type in generation_fields[settings['generation_type']].keys():
        attr.dest_type = generation_fields[
            settings['generation_type']][attr_type]
    else:
        attr.dest_type = attr_type

    return attr
Esempio n. 7
0
 def setUp(self):
     self.tree = etree.fromstring("""
                 <xmi:XMI xmi:version="2.1" xmlns:uml="http://schema.omg.org/spec/UML/2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" xmlns:thecustomprofile="http://www.sparxsystems.com/profiles/thecustomprofile/1.0">
                     <ownedAttribute xmi:type="uml:Property" xmi:id="EAID_7EBDF95C_3A97_4163_A683_3ACC3CF507E4" name="system" visibility="private" isStatic="false" isReadOnly="false" isDerived="false" isOrdered="false" isUnique="true" isDerivedUnion="false">
                         <type xmi:idref="EAJava_int"/>
                     </ownedAttribute>
                     <attribute xmi:idref="EAID_7EBDF95C_3A97_4163_A683_3ACC3CF507E4" name="id" scope="Private">
                         <initial/>
                         <documentation/>
                         <model ea_localid="1213" ea_guid="{47318F66-BBA6-4e9f-9045-83B2E12E25C8}"/>
                         <properties type="int" precision="0" collection="false" length="0" static="0" duplicates="0" changeability="changeable"/>
                         <coords ordered="0" scale="0"/>
                         <containment containment="Not Specified" position="0"/>
                         <stereotype/>
                         <bounds lower="1" upper="1"/>
                         <options/>
                         <style/>
                         <styleex value="volatile=0;"/>
                         <tags/>
                         <xrefs value="$XREFPROP=$XID={EA9F1375-D590-4c2b-8721-DC0B55BFE4A9}$XID;$NAM=CustomProperties$NAM;$TYP=attribute property$TYP;$VIS=Public$VIS;$PAR=0$PAR;$DES=@PROP=@NAME=isID@ENDNAME;@TYPE=Boolean@ENDTYPE;@VALU=1@ENDVALU;@PRMT=@ENDPRMT;@ENDPROP;$DES;$CLT={47318F66-BBA6-4e9f-9045-83B2E12E25C8}$CLT;$SUP=&lt;none&gt;$SUP;$ENDXREF;"/>
                     </attribute>
                 </xmi:XMI>""")
     self.package = UMLPackage("id", "name")
     self.parent = UMLClass(self.package, "name", "id")
Esempio n. 8
0
 def setUp(self):
     self.root_package = UMLPackage("1", "root")
     child = UMLPackage("2", "child1", self.root_package)
     self.root_package.children.append(child)
     cls = UMLClass(child, "class1", "3")
     child.classes.append(cls)