From: <de...@us...> - 2003-05-29 07:20:12
|
Update of /cvsroot/pymerase/pymerase/pymerase/input In directory sc8-pr-cvs1:/tmp/cvs-serv7383 Modified Files: parseXMI.py Log Message: Tried to move closer to classesInModel dictionary index being UUID based. Fixed the sigmoid bug by chainging a return into a continue. Index: parseXMI.py =================================================================== RCS file: /cvsroot/pymerase/pymerase/pymerase/input/parseXMI.py,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** parseXMI.py 9 May 2003 19:11:02 -0000 1.18 --- parseXMI.py 29 May 2003 07:20:08 -0000 1.19 *************** *** 264,274 **** otherEnd = thisEnd.getOppositeEnd() otherEndType = otherEnd.getType() - print "Mult: ", thisEnd.getMultiplicity(), otherEnd.getMultiplicity() if thisEnd.getMultiplicity() != fkeyTypes.OneToOne and otherEnd.getMultiplicity() != fkeyTypes.OneToOne: err = "Pymerase doesn't support Many To Many relationships"+ os.linesep err += "please add a linking table" - print err warn(err, RuntimeWarning) - print "add link" elif thisEnd.getMultiplicity() != fkeyTypes.OneToOne: # put the key in this end --- 264,271 ---- *************** *** 282,287 **** fkeyName) thisEndType.addAttribute(foreignKey) - print "added %s to %s" % (fkeyName, thisEndType.getName(None)) - print "onetoone" elif otherEnd.getMultiplicity() != fkeyTypes.OneToOne: # put the key in the other end --- 279,282 ---- *************** *** 296,303 **** fkeyName) otherEndType.addAttribute(foreignKey) - print "added %s to %s" % (fkeyName, otherEndType.getName(None)) - print "manytoone" else: ! print "other" --- 291,296 ---- fkeyName) otherEndType.addAttribute(foreignKey) else: ! raise SyntaxError("Unrecognized multiplicity") *************** *** 316,322 **** if attributeType.isNativeType(language="python"): ! return ! ! otherEndType = classesInModel.get(attributeType.getTypeString(), None) if otherEndType is not None: #print "NEED to convert %s to relation" % (attributeType) --- 309,327 ---- if attributeType.isNativeType(language="python"): ! continue ! ! # Map type name to UUID: ! for uuid, classModel in classesInModel.items(): ! if attributeType.getTypeString() == classModel.name: ! attributeUUID = uuid ! break ! else: ! warn("In %s couldn't find %s" % ( ! thisEndType.getName(None), ! attributeType.getTypeString()), ! RuntimeWarning) ! ! ! otherEndType = classesInModel.get(attributeUUID, None) if otherEndType is not None: #print "NEED to convert %s to relation" % (attributeType) *************** *** 340,347 **** association = createAssociation(pymeraseConfig, thisEnd, otherEnd) ! # modify current attribute to be of FK type attribute.setType(PymeraseType('integer')) # FIXME: converting to fk type needs to have a more general solution attribute.setName(attribute.getName(None) + "_fk") def constructForeignKey(pymeraseConfig, classesInModel, attributeName): --- 345,358 ---- association = createAssociation(pymeraseConfig, thisEnd, otherEnd) ! # modify current attribute to be of FK type? attribute.setType(PymeraseType('integer')) # FIXME: converting to fk type needs to have a more general solution attribute.setName(attribute.getName(None) + "_fk") + else: + warn("Attribute %s of type %s in class %s was not defined in model" % ( + attribute.getName(None), + attributeType.getTypeString(), + thisEndType.getName(None)), + RuntimeWarning) def constructForeignKey(pymeraseConfig, classesInModel, attributeName): *************** *** 393,405 **** def parseXMIClass(self, classesInModel, xmiClass): name = xmiClass.name warn("Parsing class %s" % (name), DebugWarning) # FIXME: bad hack to ignore garbage provided by NSUML # FIXME: perhaps we should ignore things that are part of the java package? ! if name == "String": ! warn("Skipping String", DebugWarning) ! return None ! classMetaInfo = classesInModel.setdefault(name, XMIClassMetaInfo(self.pymeraseConfig, name)) --- 404,417 ---- def parseXMIClass(self, classesInModel, xmiClass): name = xmiClass.name + UUID = self.getUUID(xmiClass) warn("Parsing class %s" % (name), DebugWarning) # FIXME: bad hack to ignore garbage provided by NSUML # FIXME: perhaps we should ignore things that are part of the java package? ! #if name == "String": ! # warn("Skipping String", DebugWarning) ! # return None ! classMetaInfo = classesInModel.setdefault(UUID, XMIClassMetaInfo(self.pymeraseConfig, name)) *************** *** 409,413 **** for generalization in xmiClass.generalization: baseClassName = generalization.parent.name ! baseClassRef = classesInModel.setdefault(baseClassName, XMIClassMetaInfo(self.pymeraseConfig, baseClassName)) --- 421,426 ---- for generalization in xmiClass.generalization: baseClassName = generalization.parent.name ! baseClassUUID = self.getUUID(generalization) ! baseClassRef = classesInModel.setdefault(baseClassUUID, XMIClassMetaInfo(self.pymeraseConfig, baseClassName)) *************** *** 451,461 **** # get names of types thisEndTypeName = self.getEndClassName(end) otherEndTypeName = self.getEndClassName(self.getOppositeEnd(end)) # get references to type objects from the master class list ! thisEndType = classesInModel.setdefault(thisEndTypeName, XMIClassMetaInfo(self.pymeraseConfig, thisEndTypeName)) ! otherEndType = classesInModel.setdefault(otherEndTypeName, XMIClassMetaInfo(self.pymeraseConfig, otherEndTypeName)) --- 464,476 ---- # get names of types thisEndTypeName = self.getEndClassName(end) + thisEndTypeUUID = self.getUUID(end) otherEndTypeName = self.getEndClassName(self.getOppositeEnd(end)) + otherEndTypeUUID = self.getUUID(self.getOppositeEnd(end)) # get references to type objects from the master class list ! thisEndType = classesInModel.setdefault(thisEndTypeUUID, XMIClassMetaInfo(self.pymeraseConfig, thisEndTypeName)) ! otherEndType = classesInModel.setdefault(otherEndTypeUUID, XMIClassMetaInfo(self.pymeraseConfig, otherEndTypeName)) *************** *** 512,515 **** --- 527,535 ---- else: raise RuntimeError("Couldn't find opposite end") + + def getUUID(self, model_element): + """Return the unique id of a UML model element + """ + return model_element.name *************** *** 553,558 **** parsedClass = umlParser.parseXMIClass(classesInModel, xmiClass) if parsedClass is not None: ! classesInModel[parsedClass.getName(None)] = parsedClass ! addForeignKeys(pymeraseConfig, classesInModel) --- 573,578 ---- parsedClass = umlParser.parseXMIClass(classesInModel, xmiClass) if parsedClass is not None: ! classesInModel[parsedClass.getUUID()] = parsedClass ! addForeignKeys(pymeraseConfig, classesInModel) |