Juan Hernandez has posted comments on this change. Change subject: codegen: Only top level elements in root class map ......................................................................
Patch Set 1: This is my understanding of why we need this dictionary: 1. The XML to Python converter needs it because when parsing an XML document it needs to know what is the class corresponding to the XML tag of the root element. By default it assumes that the class is named exactly as the tag. For example, if we give the parser the following XML document: <cluster ...> <cpu ...> </cpu> .. </cluster> It will try to instantiate a "cluster" class, which doesn't exist. So we need to tell the converter to use the "Cluster" class instead. This isn't needed for non root elements, as the mapping between tag name and class name is already included in the generated code. For example, when parsing the above cluster the Cluster class already knows that the "cpu" tag corresponds to the "CPU" class: def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): if nodeName_ == 'cpu': obj_ = CPU.factory() obj_.build(child_) self.set_cpu(obj_) ... So for this purpose we only need to include in the dictionary entries for the XML elements that may be the root of a document. A XML document that contains any other root element isn't valid, it doesn't match the XML schema. 2. You say that we need this dictionary for the conversion of Python to XML, and that is true, for the same reasons, but again only for elements that may appear as roots of documents, as for the others the generated code already knows how to do it. For example, for the CPU inside a Cluster: def exportChildren(self, outfile, ...): ... if self.cpu is not None: self.cpu.export(outfile, level, namespace_, name_='cpu', pretty_print=pretty_print) ... As you can see the generated code already knows that in this context the name to use is "cpu", not "CPU". So the only place where we need to instruct it to use different names is for elements that may appear as root of valid XML documents. -- To view, visit http://gerrit.ovirt.org/23964 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: comment Gerrit-Change-Id: Ifcdefe71f3d15ab0da841f35b4b94916d19d950d Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine-sdk Gerrit-Branch: master Gerrit-Owner: Juan Hernandez <juan.hernan...@redhat.com> Gerrit-Reviewer: Juan Hernandez <juan.hernan...@redhat.com> Gerrit-Reviewer: Michael Pasternak <mishka8...@yahoo.com> Gerrit-Reviewer: Ravi Nori <rn...@redhat.com> Gerrit-HasComments: No _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches