示例#1
0
 def generate_mapping(self):
     logger.info("root object is " + self.root_object_id)
     root_object_type = self.object_types[self.root_object_id]
     self.append_xml("<VODML>")
     self.append_xml("<MODELS>")
     for k, v in self.imports.items():
         self.append_xml("<MODEL>")
         self.append_xml("<NAME>" + k + "</NAME>")
         self.append_xml("<URL>" + v + "</URL>")
         self.append_xml("</MODEL>")
     self.append_xml("</MODELS>")
     self.append_xml("<GLOBALS>")
     self.append_xml("</GLOBALS>")
     self.append_xml("<TEMPLATES  table_ref='Results'>")
     self.generate_object_mapping(root_object_type, 'root')
     self.append_xml("</TEMPLATES>")
     self.append_xml("</VODML>")
示例#2
0
    def generate_mapping(self):
        logger.info("root object is " + self.root_object_id)
        root_object_type = self.object_types[self.root_object_id]
        self.append_xml("<MODEL_INSTANCE>")
        self.append_xml("<MODELS>")
        for k, v in self.imports.items():
            self.append_xml("<MODEL>")
            self.append_xml("<NAME>" + k + "</NAME>")
            self.append_xml("<URL>" + v + "</URL>")
            self.append_xml("</MODEL>")
        self.append_xml("</MODELS>")
        self.append_xml("<GLOBALS>")
        self.generate_enumtypes_mapping()

        self.append_xml("</GLOBALS>")
        self.append_xml("<TABLE_MAPPING  tableref='Results'>")
        self.generate_object_mapping(root_object_type, 'root')
        self.append_xml("</TABLE_MAPPING>")
        self.append_xml("</MODEL_INSTANCE>")
示例#3
0
    def read_data_type(self, model_name, datatype_tag):
        vodmlid = ''
        name = ''
        superclass = ''
        ref = ''
        attributes = dict()
        constraints = VodmlConstraintDict()
        abstract = False
        if datatype_tag.get("abstract") == "true":
            abstract = True
        for datatype_tag_child in datatype_tag.findall('*'):
            if datatype_tag_child.tag == "vodml-id":
                vodmlid = model_name + ":" + datatype_tag_child.text
                logger.info("READING DATA TYPE " + vodmlid)

            elif datatype_tag_child.tag == "name":
                name = datatype_tag_child.text
            elif datatype_tag_child.tag == "vodml-ref":
                ref = datatype_tag_child.text
            elif datatype_tag_child.tag == "attribute" or datatype_tag_child.tag == "reference":
                att = self.read_attribute(model_name, datatype_tag_child)
                attributes[att.vodmlid] = att
            elif datatype_tag_child.tag == "extends":
                for super_type_child in datatype_tag_child.findall(
                        'vodml-ref'):
                    superclass = super_type_child.text
                    break
            elif datatype_tag_child.tag == "constraint":
                ct = self.read_constraint(model_name, datatype_tag_child)
                constraints.add_contraint(ct)

            elif datatype_tag_child.tag == "reference":
                att = self.read_reference(model_name, datatype_tag_child)
                attributes[att.vodmlid] = att

        retour = VodmlDataType(vodmlid, name, ref, superclass, attributes,
                               abstract, constraints)

        return retour
示例#4
0
    def read_object_type(self, model_name, object_type_tag):
        attributes = dict()
        constraints = VodmlConstraintDict()
        superclass = ''

        abstract = False
        if object_type_tag.get("abstract") == "true":
            abstract = True
        for object_type_child in object_type_tag.findall('*'):
            if object_type_child.tag == "vodml-id":
                vodmlid = model_name + ":" + object_type_child.text
                logger.info("READING OBJECT TYPE " + vodmlid)

            elif object_type_child.tag == "name":
                name = object_type_child.text
            elif object_type_child.tag == "composition" or object_type_child.tag == "attribute":
                #or multiplicity_tag_child in object_type_child.findall('maxOccurs'):
                #    array_size = int(multiplicity_tag_child.text)
                att = self.read_attribute(model_name, object_type_child)
                attributes[att.vodmlid] = att
            elif object_type_child.tag == "extends":
                for super_type_child in object_type_child.findall('vodml-ref'):
                    superclass = super_type_child.text
                    break
            elif object_type_child.tag == "reference":
                att = self.read_reference(model_name, object_type_child)
                attributes[att.vodmlid] = att

            elif object_type_child.tag == "constraint":
                ct = self.read_constraint(model_name, object_type_child)
                constraints.add_contraint(ct)

        obj = VodmlObjectType(vodmlid, name, superclass, attributes, abstract,
                              constraints)

        return obj
示例#5
0
 def read_package(self, model_name, package_node):
     if package_node.tag == 'package':
         package_name = package_node.find("name").text
         logger.info("Reading package " + package_name)
         for child in package_node.findall('*'):
             if child.tag == "objectType":
                 ot = self.read_object_type(model_name, child)
                 logger.info("ADD OBJECT " + ot.__repr__())
                 self.object_types[ot.vodmlid] = ot
             elif child.tag == 'primitiveType' or child.tag == 'enumeration':
                 dt = self.read_data_type(model_name, child)
                 logger.info("ADD PRIM TYPE " + dt.__repr__())
                 self.primitive_types[dt.vodmlid] = dt
             elif child.tag == "dataType":
                 ot = self.read_data_type(model_name, child)
                 logger.info("ADD DATA TYPE " + ot.__repr__())
                 self.data_types[ot.vodmlid] = ot
             elif child.tag == 'package':
                 self.read_package(model_name, child)
示例#6
0
    def resolve_constaints(self):
        for obj in self.object_types.values():
            for attribute in obj.attributes.values():
                if attribute.vodmlid in obj.vodml_constraints.keys():
                    vodml_constraint = obj.vodml_constraints.constraints[
                        attribute.vodmlid]
                    if vodml_constraint.is_single:
                        new_type = vodml_constraint.subsets[0]
                        if new_type in self.data_types.keys():
                            attribute.dmtype = self.data_types[
                                new_type].vodmlid
                        elif new_type in self.object_types.keys():
                            attribute.dmtype = self.object_types[
                                new_type].vodmlid
                            logger.info("Constraint found in object type " +
                                        obj.vodmlid + " " + attribute.vodmlid +
                                        "==>" + new_type)
                    else:
                        logger.info(
                            "Constraint multiple found in object type " +
                            obj.vodmlid + " " + attribute.vodmlid + "==>" +
                            vodml_constraint.subsets)

        for obj in self.data_types.values():
            for attribute in obj.attributes.values():
                if attribute.vodmlid in obj.vodml_constraints.keys():
                    vodml_constraint = obj.vodml_constraints.constraints[
                        attribute.vodmlid]
                    if vodml_constraint.is_single:
                        new_type = vodml_constraint.subsets[0]
                        if new_type in self.data_types.keys():
                            attribute.dmtype = self.data_types[
                                new_type].vodmlid
                        elif new_type in self.object_types.keys():
                            attribute.dmtype = self.object_types[
                                new_type].vodmlid
                            logger.info("Constraint found in data type " +
                                        obj.vodmlid + " " + attribute.vodmlid +
                                        "==>" + new_type)
                    else:
                        logger.info("Constraint multiple found in data type " +
                                    obj.vodmlid + " " + attribute.vodmlid +
                                    "==>" + vodml_constraint.subsets)
示例#7
0
    def resolve_inheritance(self):
        for obj in self.data_types.values():
            superclass = obj.superclass
            while superclass != '':
                sup_obj = None
                if superclass in self.data_types:
                    sup_obj = self.data_types[superclass]
                elif superclass in self.primitive_types:
                    sup_obj = self.primitive_types[superclass]
                else:
                    self.log_error(
                        str(superclass) +
                        " Neither in dataType nor in primitive types")
                for k, v in sup_obj.attributes.items():
                    obj.attributes[k] = v
                logger.info("merge data %s %s", sup_obj.vodmlid, obj.vodmlid)
                logger.info("Constraint %s", sup_obj.vodml_constraints)

                obj.vodml_constraints.merge(sup_obj.vodml_constraints)

                #for k,v in sup_obj.vodml_constraints.constraints.items():
                #    print(sup_obj.vodml_constraints.constraints)
                #    obj.vodml_constraints.merge(v)
                superclass = sup_obj.superclass

        #for obj in  self.object_types.values():
        for vodmlid in self.object_types.keys():
            obj = self.object_types[vodmlid]
            superclass = obj.superclass
            while superclass != '':
                sup_obj = None
                if superclass in self.object_types:
                    sup_obj = self.object_types[superclass]
                elif superclass in self.data_types:
                    sup_obj = self.data_types[superclass]
                else:
                    self.log_error(superclass +
                                   " Neither in dataType or objectType")

                for k, v in sup_obj.attributes.items():
                    obj.attributes[k] = v
                #for k,v in sup_obj.vodml_constraints.items():
                #    obj.vodml_constraints[k] = v
                logger.info("merge obs " + sup_obj.vodmlid + "  " +
                            obj.vodmlid)
                obj.vodml_constraints.merge(sup_obj.vodml_constraints)
                superclass = sup_obj.superclass
示例#8
0
    def parse_vodml_file(self, filename='', model=None):
        logger.info("Reading FILE " + filename + " for model " + model)

        if filename.startswith("http://") or filename.startswith("https://"):
            tree = etree.ElementTree(file=urllib.request.urlopen(filename))
        else:
            tree = etree.parse(filename)

        root = tree.getroot()
        #ns = {"vo-dml": "http://www.ivoa.net/xml/VODML/v1"}
        if model == None:
            model_name = root.find("name").text
        else:
            model_name = model

        logger.info("PARSE FILE " + filename + " for model " + model)

        for node in tree.xpath("import"):
            name = node.find('name').text
            url = node.find('url').text
            if not name in self.imports:
                # Let's take the import name as VODML prefix
                model_name = name
                logger.info("PARSE IMPORT " + name)
                self.parse_vodml_file(filename=url, model=model_name)
                logger.info("END PARSE " + name)
                self.imports[name] = url

        if model == None:
            model_name = root.find("name").text
        else:
            model_name = model

        for node in tree.xpath("*"):
            if node.tag == 'package':
                self.read_package(model_name, node)
            elif node.tag == 'primitiveType' or node.tag == 'enumeration':
                dt = self.read_data_type(model_name, node)
                logger.info("ADD primitiveType " + dt.vodmlid)
                self.primitive_types[dt.vodmlid] = dt
            elif node.tag == 'dataType' or node.tag == 'reference':
                dt = self.read_data_type(model_name, node)
                logger.info("ADD dataType " + dt.__repr__())
                self.data_types[dt.vodmlid] = dt
            elif node.tag == 'objectType':
                dt = self.read_object_type(model_name, node)
                logger.info("ADD objectType " + dt.vodmlid)
                #                 if  dt.vodmlid == "coords:Axis":
                #                     print(dt.__repr__())
                #                     sys.exit()
                self.object_types[dt.vodmlid] = dt