xsd_schema/parser/frames/
notation.rs1pub struct NotationFrame {
7 name: Option<NameId>,
8 public: Option<String>,
9 system: Option<String>,
10 id: Option<String>,
11 annotation: Option<Annotation>,
12 source: Option<SourceRef>,
13 foreign_attributes: Vec<ForeignAttribute>,
14}
15
16impl NotationFrame {
17 pub fn new(
18 attrs: &AttributeMap,
19 name_table: &NameTable,
20 source: Option<SourceRef>,
21 ) -> SchemaResult<Self> {
22 let name = attrs
23 .get_value_by_name(name_table, "name")
24 .and_then(|s| name_table.get(s));
25
26 let public = attrs
27 .get_value_by_name(name_table, "public")
28 .map(String::from);
29
30 let system = attrs
31 .get_value_by_name(name_table, "system")
32 .map(String::from);
33
34 let id = attrs
35 .get_value_by_name(name_table, "id")
36 .map(String::from);
37
38 Ok(Self {
39 name,
40 public,
41 system,
42 id,
43 annotation: None,
44 source,
45 foreign_attributes: Vec::new(),
46 })
47 }
48}
49
50impl Frame for NotationFrame {
51 fn allows(&self, local_name: &str, _name_table: &NameTable) -> bool {
52 matches!(local_name, xsd_names::ANNOTATION)
53 }
54
55 fn allows_attribute(&self, local_name: &str, _name_table: &NameTable) -> bool {
56 matches!(local_name, "name" | "public" | "system" | "id")
57 }
58
59 fn on_child_start(&mut self, _local_name: &str, _name_table: &NameTable) {}
60
61 fn attach(&mut self, child: FrameResult) -> SchemaResult<()> {
62 if let FrameResult::Annotation(ann) = child {
63 self.annotation = Some(ann);
64 }
65 Ok(())
66 }
67
68 fn finish(self: Box<Self>) -> SchemaResult<FrameResult> {
69 let annotation = merge_foreign_attributes(
70 self.annotation,
71 self.foreign_attributes,
72 self.source.clone(),
73 );
74 Ok(FrameResult::Notation(NotationResult {
75 name: self.name,
76 public: self.public,
77 system: self.system,
78 id: self.id,
79 annotation,
80 source: self.source,
81 }))
82 }
83
84 fn has_annotation(&self) -> bool {
85 self.annotation.is_some()
86 }
87
88 fn source(&self) -> Option<&SourceRef> {
89 self.source.as_ref()
90 }
91
92 fn set_foreign_attributes(&mut self, attrs: Vec<ForeignAttribute>) {
93 self.foreign_attributes = attrs;
94 }
95}
96