Beispiel #1
0
def createStereotype(owner, element):
	if isinstance(element, Package):
		if StereotypesHelper.hasStereotype(element, StereotypesHelper.getStereotype(project, "View")):
			package = element.getName().find("View")
		 	if package == -1:
		 		element.setName(element.getName() + " View")
		else:
		 	package = element.getName().find("Package")
		 	if package == -1:
		 		element.setName(element.getName() + " View")            
	
	if not isinstance(element, EnumerationLiteral):
	    eSter = StereotypesHelper.getAllAssignedStereotypes([element])
	    eSter = filter(lambda element: element != StereotypesHelper.getStereotype(project, "Diagram Info"), eSter)
	    newSter = StereotypesHelper.createStereotype(owner, element.getName(), [StereotypesHelper.getBaseClass(element)])
	    StereotypesHelper.addStereotypeByString(element, element.getName())
	    for e in eSter:
	    	newgen = ef.createGeneralizationInstance()
	    	gl.log(e.getQualifiedName())
	    	gl.log(newSter.getQualifiedName())
	        newgen.setGeneral(e)
	        newgen.setSpecific(newSter)
	        newgen.setOwner(newSter)
	    	icon = filter(lambda element: isinstance(element, Image), e.getOwnedElement())
	    	if icon:
	    		icon = icon[0]
	    		newicon= ef.createImageInstance()
	    		newicon.setLocation(icon.getLocation())
	    		newicon.setContent(icon.getContent())
	    		newicon.setFormat(icon.getFormat())
	    		newicon.setOwner(newSter)	
	        
	return
Beispiel #2
0
def createStereotypedElement(stereotype, owner):
    new = None
    mclass = StereotypesHelper.getBaseClassesAsClasses(stereotype)
    for m in mclass:
        insCreate = str(m)
        findtrunc = insCreate.split(".")
        insCreate = findtrunc[len(findtrunc)-1]
        insCreate = insCreate[:-2]
        if insCreate != "Property" and insCreate != "Association" and insCreate != "Dependency" and insCreate != "Relationship" and insCreate != "Element" and insCreate != "Operation" and insCreate!= "Property" and insCreate!= "EnumerationLiteral":
            instanceCreate = 'create'+insCreate+'Instance'
            new = eval('ef.create'+insCreate+'Instance()')
            new.setOwner(owner)
            new.setName(stereotype.getName())
            StereotypesHelper.addStereotypeByString(new, stereotype.getName())
    return new
Beispiel #3
0
def createFlowPorts(connectorTargets, validateOnly, connectorType):
    #Initialize
    nestSter = StereotypesHelper.getStereotype(project, 'NestedConnectorEnd')
    flowSter = StereotypesHelper.getStereotype(project, 'FlowPort')
    conveyedApplied = 0
    conveyedBadApply = 0
    noConveyed = 0
    noConnector = 0
    connectorCreated = 0
    typeMis = 0
    badConveyed = 0
    context = connectorTargets.getFeaturingClassifier()
    contextPackage = context[0].getOwningPackage()
    connectorEnds = connectorTargets.getEnd()
    connectorInformation = connectorTargets.get_informationFlowOfRealizingConnector(
    )
    cInfoNames = []
    cInfoTypes = []
    cInfoSource = {}
    cInfoTarg = {}
    badConn = []
    #	Retrieve conveyed information from connector (connectortTargets); Create a list of: information types and connector ends(sources and targets)
    if connectorType == 'assembly' and len(connectorInformation) == 0:
        gl.log('ERROR: No Conveyed Information. Stopping Execution')
        return
    for c in connectorInformation:
        cInfoTypes.append(c.getConveyed())
        for cg in c.getConveyed():
            if cg in cInfoSource:
                cInfoSource[cg].append(ModelHelper.getSupplierElement(c))
            else:
                cInfoSource[cg] = [ModelHelper.getSupplierElement(c)]
            if cg in cInfoTarg:
                cInfoTarg[cg].append(ModelHelper.getClientElement(c))
            else:
                cInfoTarg[cg] = [ModelHelper.getClientElement(c)]
        for con in c.getConveyed():
            cInfoNames.append(con.getName())
    cInfoTypes = flatten(cInfoTypes)
    rE = connectorEnds[0]
    sE = connectorEnds[1]

    #	Get the roles and property paths for the connector ends
    r = rE.getRole()
    rPaths = StereotypesHelper.getStereotypePropertyValue(
        rE, nestSter, 'propertyPath')
    s = sE.getRole()
    sPaths = StereotypesHelper.getStereotypePropertyValue(
        sE, nestSter, 'propertyPath')
    gl.log('Validating from ' + r.getName())
    # Get the nested ports for each end.  Build lists of qualified names for opposite end of validation and port types of validation end
    rPorts = filter(
        lambda element: StereotypesHelper.hasStereotypeOrDerived(
            element, 'FlowPort'),
        r.getType().getOwnedElement())
    sPorts = filter(
        lambda element: StereotypesHelper.hasStereotypeOrDerived(
            element, 'FlowPort'),
        s.getType().getOwnedElement())
    sPortsQual = []
    for spq in sPorts:
        sPortsQual.append(spq.getQualifiedName())
    rPortTypes = []
    for rpt in rPorts:
        rPortTypes.append(rpt.getType())


#Check to see if all conveyed information types match at least one port type of the validation end
    pcNoMatch = filter(lambda element: element not in rPortTypes, cInfoTypes)
    for p in pcNoMatch:
        gl.log('ERROR: Conveyed information has no matching port: ' +
               p.getName())
    for rp in rPorts:
        match = 0
        #if the port has a connector end and the other end's qualified name is in the list of opposite end qualified names then the connector exists
        for e in rp.getEnd():
            opp = findOppositeEnd(e.getRole(), e, e.getOwner())
            if opp.getRole().getQualifiedName() in sPortsQual:
                #have to check property path; otherwise an error will occur.

                match = 1
        if rp.getEnd() or match == 1:
            gl.log('Connector already exists for port ' + rp.getName())
            conveyedApplied += 1

        if not rp.getEnd() or match == 0:
            gl.log('WARNING: No connector for port = ' + rp.getName())
            noConnector += 1
            go = 0
            if (rp.getType() in cInfoTypes
                    or connectorType == 'delegation') and validateOnly != True:
                if connectorType == 'assembly':
                    goAhead = checkDirection(rp, cInfoTarg, cInfoSource, r)
                else:
                    goAhead = 1
                #				gl.log('debug ' + str(goAhead))
                if goAhead == 1:
                    new = ef.createConnectorInstance()
                    new.setOwner(context[0])
                    new.setName(rp.getName() + 'connector')
                    StereotypesHelper.addStereotypeByString(
                        new.getEnd()[0], 'NestedConnectorEnd')
                    StereotypesHelper.addStereotypeByString(
                        new.getEnd()[1], 'NestedConnectorEnd')
                    for rpa in rPaths:
                        StereotypesHelper.setStereotypePropertyValue(
                            new.getEnd()[0], nestSter, 'propertyPath', rpa,
                            True)
                    StereotypesHelper.setStereotypePropertyValue(
                        new.getEnd()[0], nestSter, 'propertyPath', r, True)
                    new.getEnd()[0].setRole(rp)
                    new.getEnd()[0].setPartWithPort(r)
                    otherEnd = filter(
                        lambda element: StereotypesHelper.
                        hasStereotypeOrDerived(element, "FlowPort"),
                        s.getType().getOwnedElement())
                    otherEnd = filter(
                        lambda element: element.getType() == rp.getType(),
                        otherEnd)
                    if connectorType == 'assembly':
                        otherEnd = filter(
                            lambda element: StereotypesHelper
                            .getStereotypePropertyValue(
                                element, flowSter, "direction"
                            ) != StereotypesHelper.getStereotypePropertyValue(
                                rp, flowSter, 'direction'), otherEnd)
                    else:
                        otherEnd = filter(
                            lambda element: StereotypesHelper
                            .getStereotypePropertyValue(
                                element, flowSter, "direction"
                            ) == StereotypesHelper.getStereotypePropertyValue(
                                rp, flowSter, "direction"), otherEnd)
                    for sp in sPaths:
                        StereotypesHelper.setStereotypePropertyValue(
                            new.getEnd()[1], nestSter, 'propertyPath', sp,
                            True)
                    StereotypesHelper.setStereotypePropertyValue(
                        new.getEnd()[1], nestSter, 'propertyPath', s, True)
                    new.getEnd()[1].setRole(otherEnd[0])
                    new.getEnd()[1].setPartWithPort(s)
                    if connectorType == 'assembly':
                        newC = ef.createInformationFlowInstance()
                        newC.setOwner(contextPackage)
                        StereotypesHelper.addStereotypeByString(
                            newC, 'ItemFlow')
                        newC.setName('flow for ' + rp.getType().getName())
                        newC.getConveyed().add(rp.getType())
                        new.get_informationFlowOfRealizingConnector().add(newC)
                        if StereotypesHelper.getStereotypePropertyValue(
                                rp, 'FlowPort',
                                'direction')[0].getName() == 'in':
                            ModelHelper.setSupplierElement(newC, rp)
                            ModelHelper.setClientElement(newC, otherEnd[0])
                        else:
                            ModelHelper.setSupplierElement(newC, otherEnd[0])
                            ModelHelper.setClientElement(newC, rp)
                        gl.log(
                            'Connector and Conveyed Information created between '
                            + rp.getQualifiedName() + ' and ' +
                            otherEnd[0].getQualifiedName())
                    else:
                        gl.log('Connector created between' +
                               rp.getQualifiedName() + 'and' +
                               otherEnd[0].getQualifiedName())
                    connectorCreated += 1
        else:
            for endA in filter(
                    lambda element: element.getOwner().getOwner() == context[0
                                                                             ],
                    rp.getEnd()):
                endB = findOppositeEnd(endA.getRole(), endA, endA.getOwner())
                'check if correct typing'
                if not endA.getOwner().get_informationFlowOfRealizingConnector(
                ) and connectorType == 'assembly':
                    gl.log(
                        'ERROR: No conveyed information applied to connector between '
                        + endA.getRole().getName() + ' and ' +
                        endB.getRole().getName())
                    noConveyed += 1
                    if validateOnly != True and rp.getType() in cInfoTypes:
                        goAhead1 = checkDirection(rp, cInfoTarg, cInfoSource,
                                                  r)
                        #						gl.log('port: '+ endA.getRole().getType().getName())
                        #						gl.log('other:' + endB.getRole().getType().getName())
                        if goAhead1 == 1 and endA.getRole().getType(
                        ) == endB.getRole().getType():
                            new = ef.createInformationFlowInstance()
                            new.setOwner(contextPackage)
                            StereotypesHelper.addStereotypeByString(
                                new, 'ItemFlow')
                            new.setName('flow for ' + rp.getType().getName())
                            new.getConveyed().add(rp.getType())
                            endA.getOwner(
                            ).get_informationFlowOfRealizingConnector().add(
                                new)
                            if StereotypesHelper.getStereotypePropertyValue(
                                    rp, "FlowPort",
                                    "direction")[0].getName() == 'in':
                                ModelHelper.setSupplierElement(new, rp)
                                ModelHelper.setClientElement(
                                    new, endB.getRole())
                            else:
                                ModelHelper.setSupplierElement(
                                    new, endB.getRole())
                                ModelHelper.setClientElement(new, rp)
                                gl.log(
                                    'FIX: conveyed information applied to connector between '
                                    + rp.getQualifiedName() + ' and ' +
                                    endB.getRole().getQualifiedName())
                        else:
                            gl.log('ERROR port types do not match: ' +
                                   endA.getRole().getName() + ' and ' +
                                   endB.getRole().getName())
                            typeMis += 1
                for info in endA.getOwner(
                ).get_informationFlowOfRealizingConnector():
                    if connectorType == 'assembly':
                        if info.getConveyed()[0].getName() == rp.getType(
                        ).getName():
                            gl.log(
                                'Conveyed Information already applied for port of type: '
                                + str(rp.getType().getName()))
                            conveyedApplied += 1
                        else:
                            gl.log(
                                'ERROR: conveyed information does not match for port of type: '
                                + str(rp.getType().getName()))
                            conveyedBadApply += 1

    gl.log('Validation Summary:')
    gl.log('No Connectors = ' + str(noConnector))
    if connectorType == 'assembly':
        gl.log('Conveyed Information = ' + str(conveyedApplied))
        gl.log('Connectors with No Conveyed Information = ' + str(noConveyed))
    else:
        gl.log('Connectors = ' + str(conveyedApplied))
    gl.log('Bad Conveyed = ' + str(conveyedBadApply))
    gl.log('Port Type MisMatch = ' + str(typeMis))
    gl.log('Extra Conveyed Information = ' + str(len(pcNoMatch)))
    gl.log('Fix Summary: ')
    gl.log('Connectors Created = ' + str(connectorCreated))