def buildGeneralizations(self, doc, objects): gens = doc.getElementsByTagName(self.GENERALIZATION) for gen in gens: if not self.getId(gen): continue try: par0 = getElementByTagName(gen, self.GEN_PARENT, recursive=1) child0 = getElementByTagName(gen, self.GEN_CHILD, recursive=1) try: par = objects[getSubElement(par0).getAttribute( 'xmi.idref')] except KeyError: log.warn( "Parent Object not found for generalization " "relation '%s', parent=%s'.", self.getId(gen), self.getName(par0)) continue child = objects[getSubElement(child0).getAttribute( 'xmi.idref')] par.addGenChild(child) child.addGenParent(par) except IndexError: log.error("Gen: index error for generalization '%s'.", self.getId(gen)) raise
def getAssocEndParticipantId(self, el): assocend = getElementByTagName(el, self.ASSOCEND_PARTICIPANT, None) if not assocend: assocend = getElementByTagName(el, self.ASSOCENDTYPE, None) if not assocend: return None classifier = getSubElement(assocend) if not classifier: log.warn("No assocEnd participant found for '%s'.", self.getId(el)) return None return classifier.getAttribute('xmi.idref')
def getPackageElements(self, el): """Gets all package nodes below the current node (only one level).""" res = [] #in case the el is a document we have to crawl down until we have ownedElements ownedElements = getElementByTagName(el, self.OWNED_ELEMENT, default=None) if not ownedElements: if el.tagName == self.PACKAGE: return [] el = getElementByTagName(el, self.MODEL, recursive=1) ownedElements = getElementByTagName(el, self.OWNED_ELEMENT) res = getElementsByTagName(ownedElements, self.PACKAGE) return res
def buildRealizations(self, doc, objects): abs = doc.getElementsByTagName(self.ABSTRACTION) for ab in abs: if not self.getId(ab): continue abstraction = XMIAbstraction(ab) if not abstraction.hasStereoType('realize') and \ not abstraction.hasStereoType('adapts'): log.debug("Skipping dep: %s", abstraction.getStereoType()) continue try: try: par0 = getElementByTagName(ab, self.DEP_SUPPLIER, recursive=1) sub = getSubElement(par0, ignoremult=1) par = objects[sub.getAttribute('xmi.idref')] except (KeyError, IndexError): log.warn( "Parent Object not found for realization or adaptation " "relation:%s, parent %s.", self.getId(ab), self.getName(par0)) continue try: child0 = getElementByTagName(ab, self.DEP_CLIENT, recursive=1) sub = getSubElement(child0, ignoremult=1) child_xmid = sub.getAttribute('xmi.idref') child = objects[child_xmid] except (KeyError, IndexError): log.warn( "Child element for realization or adaptation relation not found. " "Parent name = '%s' relation xmi_id = '%s'.", par.getName(), self.getId(ab)) if abstraction.hasStereoType('realize'): par.addRealizationChild(child) child.addRealizationParent(par) if abstraction.hasStereoType('adapts'): par.addAdaptationChild(child) child.addAdaptationParent(par) except IndexError: log.error("ab: index error for dependencies; %s", self.getId(ab)) raise
def getExpressionBody(self, element, tagname = None): if not tagname: tagname = self.EXPRESSION exp = getElementByTagName(element, self.EXPRESSION_BODY, recursive=1, default=None) if exp and exp.firstChild: return exp.firstChild.nodeValue else: return None
def buildRealizations(self, doc, objects): abs = doc.getElementsByTagName(self.ABSTRACTION) for ab in abs: if not self.getId(ab): continue abstraction = XMIAbstraction(ab) if not abstraction.hasStereoType('realize') and \ not abstraction.hasStereoType('adapts'): log.debug("Skipping dep: %s", abstraction.getStereoType()) continue try: try: par0 = getElementByTagName(ab, self.DEP_SUPPLIER, recursive=1) sub = getSubElement(par0, ignoremult=1) par = objects[sub.getAttribute('xmi.idref')] except (KeyError, IndexError): log.warn("Parent Object not found for realization or adaptation " "relation:%s, parent %s.", self.getId(ab), self.getName(par0)) continue try: child0 = getElementByTagName(ab, self.DEP_CLIENT, recursive=1) sub = getSubElement(child0, ignoremult=1) child_xmid = sub.getAttribute('xmi.idref') child = objects[child_xmid] except (KeyError, IndexError): log.warn("Child element for realization or adaptation relation not found. " "Parent name = '%s' relation xmi_id = '%s'.", par.getName(), self.getId(ab)) if abstraction.hasStereoType('realize'): par.addRealizationChild(child) child.addRealizationParent(par) if abstraction.hasStereoType('adapts'): par.addAdaptationChild(child) child.addAdaptationParent(par) except IndexError: log.error("ab: index error for dependencies; %s", self.getId(ab)) raise
def getModel(self, doc): content = self.getContent(doc) try: model = getElementByTagName(content, XMI.MODEL, recursive=0) except TypeError: #handle a bug in ArgoUML that causes 2 model entries in the xmi #from which one is empty models = getElementsByTagName(content, XMI.MODEL, recursive=0) model = models[1] return model
def getExpressionBody(self, element, tagname=None): if not tagname: tagname = self.EXPRESSION exp = getElementByTagName(element, self.EXPRESSION_BODY, recursive=1, default=None) if exp and exp.firstChild: return exp.firstChild.nodeValue else: return None
def getModel(self, doc): content = self.getContent(doc) try: model = getElementByTagName(content, XMI.MODEL, recursive=0) except TypeError: #handle a bug in ArgoUML that causes 2 model entries in the xmi #from which one is empty models = getElementsByTagName(content, XMI.MODEL, recursive=0) model=models[1] return model
def buildGeneralizations(self, doc, objects): gens = doc.getElementsByTagName(self.GENERALIZATION) for gen in gens: if not self.getId(gen):continue try: par0 = getElementByTagName(gen, self.GEN_PARENT, recursive=1) child0 = getElementByTagName(gen, self.GEN_CHILD, recursive=1) try: par = objects[getSubElement(par0).getAttribute('xmi.idref')] except KeyError: log.warn("Parent Object not found for generalization " "relation '%s', parent=%s'.", self.getId(gen), self.getName(par0)) continue child = objects[getSubElement(child0).getAttribute('xmi.idref')] par.addGenChild(child) child.addGenParent(par) except IndexError: log.error("Gen: index error for generalization '%s'.", self.getId(gen)) raise
def getContent(self, doc): return getElementByTagName(doc, self.XMI_CONTENT, recursive=1)
def getOwnedElement(self, el): return getElementByTagName(el, self.OWNED_ELEMENT, default=None)
def calcClassAbstract(self, o): abs = getElementByTagName(o.domElement, self.ISABSTRACT, None) if abs: o.isabstract = abs.getAttribute('xmi.value') == 'true' else: o.isabstract = 0