def VP_XMLUtil(self,root,namespaces,PROJECT_DIR,_dmoName): elements = root.findall("packagedElement") dmo = DomainModel(_dmoName) # ZHIYUN: store all mapping of attribute id to its name elemType={} for element in elements: if element.get(self.xmiPrefixAppender('type', namespaces["xmi_namespace"] )) == "uml:DataType": typeId=element.get(self.xmiPrefixAppender('id', namespaces["xmi_namespace"] )) elemType[typeId]=element.get("name") # ZHIYUN: adding elements into model elem={} for element in elements: if element.get(self.xmiPrefixAppender('type', namespaces["xmi_namespace"] )) == "uml:Class": elemId = element.get(self.xmiPrefixAppender('id', namespaces["xmi_namespace"] )) elemName = element.get('name').strip() dmo.declareElement(elemName , elemId) elem[elemId]=elemName # ZHIYUN: adding attributes to element for element in elements: if element.get(self.xmiPrefixAppender('type', namespaces["xmi_namespace"] )) == "uml:Class": elemName = element.get('name').strip() elemAttributes = element.findall('ownedAttribute') if elemAttributes is not None: for elemAttribute in elemAttributes: AttributeName = elemAttribute.get('name') AttributeId = elemAttribute.get('type') # ZHIYUN: add simple attributes if elemType.has_key(AttributeId): AttributeType = elemType[AttributeId] AttributeTypeSetter=dt.SimpleType(AttributeType) dmo.defineSimpleAttribute(elemName, AttributeName, AttributeTypeSetter) # ZHIYUN: add complex attribute elif elem.has_key(AttributeId): AttributeElemName = elem[AttributeId] AttributeTypeSetter=dt.ComplexType(AttributeElemName) dmo.defineComplexAttribute(elemName,AttributeName, AttributeElemName, AttributeTypeSetter) # ZHIYUN: adding relations to elemnents # ZHIYUN: add generalization relations for element in elements: if element.get(self.xmiPrefixAppender('type', namespaces["xmi_namespace"] )) == "uml:Class": elemId = element.get(self.xmiPrefixAppender('id', namespaces["xmi_namespace"] )) elemRelations = element.findall('generalization') if elemRelations is None : continue for elemRelation in elemRelations: relationId = elemRelation.get(self.xmiPrefixAppender('id',namespaces["xmi_namespace"])) dmo.defineRelation(relationId, str(elemId), str(elemRelation.get('general')) , str("Generalization")) # ZHIYUN: add other relations for element in elements: if element.get(self.xmiPrefixAppender('type', namespaces["xmi_namespace"] )) == "uml:Association": relationId = element.get(self.xmiPrefixAppender('id', namespaces["xmi_namespace"])) ownedEnds=element.findall('ownedEnd') start=ownedEnds[1] end=ownedEnds[0] # ZHIYUN: add upper value of start and end class to relation startUpperVaule="unknown" endUpperValue='unknown' if(start.find('upperValue') is not None): startUpperVaule=start.find('upperValue').get('value') if(end.find('upperValue') is not None): endUpperValue=end.find('upperValue').get('value') # ZHIYUN: add relations if start.get('aggregation')=="shared": dmo.defineRelation(relationId, str(start.get('type')), str(end.get('type')),str("Aggregation"), startUpperVaule,endUpperValue) elif start.get('aggregation')=="composite": dmo.defineRelation(relationId, str(start.get('type')), str(end.get('type')) , str("Composition"),startUpperVaule,endUpperValue) else: dmo.defineRelation(relationId, str(start.get('type')), str(end.get('type')) , str("Association"),startUpperVaule,endUpperValue) #edm_utils.copyDirLink('code_templates/node_modules', PROJECT_DIR + "/" +'node_modules') json_file = open(PROJECT_DIR + "/" + _dmoName + ".json", "w") json_file.write(dmo.toJson()) json_file.close() return dmo.toJson()