Exemplo n.º 1
0
    def build_class_extensions(cls, obj: ElementBase, target: Class):
        """Build the item class extensions from the given ElementBase
        children."""

        restrictions = obj.get_restrictions()
        extensions = [
            cls.build_class_extension(target, base, restrictions)
            for base in obj.bases
        ]
        extensions.extend(cls.children_extensions(obj, target))
        target.extensions = collections.unique_sequence(extensions)
Exemplo n.º 2
0
    def build_class_extensions(cls, obj: ElementBase, target: Class):
        """Build the item class extensions from the given ElementBase
        children."""
        extensions = set()
        raw_type = obj.raw_type
        if raw_type:
            restrictions = obj.get_restrictions()
            extensions.add(
                cls.build_class_extension(target, raw_type, restrictions))

        extensions.update(cls.children_extensions(obj, target))

        target.extensions = list(extensions)
Exemplo n.º 3
0
    def build_class_extensions(cls, obj: ElementBase, target: Class):
        """Build the item class extensions from the given ElementBase
        children."""
        extensions = {}
        raw_type = obj.raw_type
        if raw_type:
            restrictions = obj.get_restrictions()
            extension = cls.build_class_extension(target, raw_type, 0, restrictions)
            extensions[raw_type] = extension

        for extension in cls.children_extensions(obj, target):
            extensions[extension.type.name] = extension

        target.extensions = sorted(extensions.values(), key=lambda x: x.type.index)
Exemplo n.º 4
0
    def process_enum_extension(cls, source: Class, target: Class,
                               ext: Extension):
        """
        Process enumeration class extension.

        Extension cases:
            1. Enumeration: copy all attr properties
            2. Simple type: copy value attr properties
            3. Complex type:
                3.1 Target has one member, clone source and set fixed default value
                3.2 Invalid schema.
        """
        if source.is_enumeration:
            source_attrs = {attr.name: attr for attr in source.attrs}
            target.attrs = [
                source_attrs[attr.name].clone()
                if attr.name in source_attrs else attr for attr in target.attrs
            ]
            target.extensions.remove(ext)
        elif len(source.attrs) == 1:
            source_attr = source.attrs[0]
            for attr in target.attrs:
                attr.types.extend([x.clone() for x in source_attr.types])
                attr.restrictions.merge(source_attr.restrictions)

            target.extensions.remove(ext)
        elif len(target.attrs) == 1:  # We are not an enumeration pal.
            default = target.attrs[0].default
            target.attrs = [attr.clone() for attr in source.attrs]
            target.extensions = [ext.clone() for ext in source.extensions]

            for attr in target.attrs:
                if attr.xml_type is None:
                    attr.default = default
                    attr.fixed = True
        else:
            raise CodeGenerationError(
                "Enumeration class with a complex extension.")