xsd_parser/types/info/
complex.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//! Contains the [`ComplexInfo`] type information and all related types.

use crate::schema::xs::{
    Annotation, NamespaceListType, NotNamespaceType, ProcessContentsType, QnameListAType,
    QnameListType,
};
use crate::schema::{MaxOccurs, MinOccurs};
use crate::types::{Ident, TypeEq, Types};

use super::{AttributesInfo, Base, ElementsInfo};

/// Type information that contains data about a complex type.
#[derive(Debug, Clone)]
pub struct ComplexInfo {
    /// Base type of the complex type.
    pub base: Base,

    /// Content type information of the complex type that contains the actual
    /// information about the elements that are defined for this type.
    pub content: Option<Ident>,

    /// Minimum occurrence of this complex types content type.
    pub min_occurs: MinOccurs,

    /// Maximum occurrence of this complex types content type.
    pub max_occurs: MaxOccurs,

    /// Whether the type is abstract or not.
    pub is_abstract: bool,

    /// List of attributes defined for this complex type.
    pub attributes: AttributesInfo,

    /// If this complex type accepts any other attribute, that is not defined by
    /// this type, this contains the information for these attributes, otherwise
    /// it is set to `None`.
    pub any_attribute: Option<AnyAttributeInfo>,
}

/// Represents a group of elements.
///
/// This is usually a `xs:all`, `xs:choice` or `xs:sequence`.
#[derive(Default, Debug, Clone)]
pub struct GroupInfo {
    /// If this group accepts any other element, that is not defined by this group,
    /// this field contains the information for these elements, otherwise it is
    /// set to `None`.
    pub any: Option<AnyInfo>,

    /// List of elements defined in this group.
    pub elements: ElementsInfo,
}

/// Contains information about elements that may occur in the XML file that
/// are not explicitly defined by the schema.
#[allow(missing_docs)]
#[derive(Default, Debug, Clone, Eq, PartialEq)]
pub struct AnyInfo {
    pub id: Option<String>,
    pub namespace: Option<NamespaceListType>,
    pub not_namespace: Option<NotNamespaceType>,
    pub process_contents: Option<ProcessContentsType>,
    pub not_q_name: Option<QnameListType>,
    pub min_occurs: Option<MinOccurs>,
    pub max_occurs: Option<MaxOccurs>,
    pub annotation: Option<Annotation>,
}

/// Contains information about attributes that may occur in the XML file that
/// are not explicitly defined by the schema.
#[allow(missing_docs)]
#[derive(Default, Debug, Clone, Eq, PartialEq)]
pub struct AnyAttributeInfo {
    pub id: Option<String>,
    pub namespace: Option<NamespaceListType>,
    pub not_namespace: Option<NotNamespaceType>,
    pub process_contents: Option<ProcessContentsType>,
    pub not_q_name: Option<QnameListAType>,
    pub annotation: Option<Annotation>,
}

/* GroupInfo */

impl TypeEq for GroupInfo {
    fn type_eq(&self, other: &Self, types: &Types) -> bool {
        let Self { any, elements } = self;

        any.eq(&other.any) && elements.type_eq(&other.elements, types)
    }
}

/* ComplexInfo */

impl Default for ComplexInfo {
    fn default() -> Self {
        Self {
            base: Base::None,
            content: None,
            min_occurs: 1,
            max_occurs: MaxOccurs::Bounded(1),
            is_abstract: false,
            attributes: AttributesInfo::default(),
            any_attribute: None,
        }
    }
}

impl TypeEq for ComplexInfo {
    fn type_eq(&self, other: &Self, types: &Types) -> bool {
        let Self {
            base,
            content,
            min_occurs,
            max_occurs,
            is_abstract,
            attributes,
            any_attribute,
        } = self;

        base.type_eq(&other.base, types)
            && content.type_eq(&other.content, types)
            && min_occurs.eq(&other.min_occurs)
            && max_occurs.eq(&other.max_occurs)
            && is_abstract.eq(&other.is_abstract)
            && attributes.type_eq(&other.attributes, types)
            && any_attribute.eq(&other.any_attribute)
    }
}