forked from hooklift/gowsdl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisitor.go
More file actions
110 lines (96 loc) · 2.65 KB
/
visitor.go
File metadata and controls
110 lines (96 loc) · 2.65 KB
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
package gowsdl
type visitor struct {
all []*XSDSchema
}
type visitorConfig struct {
onEnterSchema func(*XSDSchema)
onExitSchema func(*XSDSchema)
onEnterElement func(*XSDElement)
onExitElement func(*XSDElement)
onEnterComplexType func(*XSDComplexType)
onExitComplexType func(*XSDComplexType)
onEnterSimpleType func(*XSDSimpleType)
onExitSimpleType func(*XSDSimpleType)
onEnterAttribute func(*XSDAttribute)
onExitAttribute func(*XSDAttribute)
}
func (v visitor) visit(cfg *visitorConfig) {
for _, schema := range v.all {
if cfg.onEnterSchema != nil {
cfg.onEnterSchema(schema)
}
v.visitSchema(schema, cfg)
if cfg.onExitSchema != nil {
cfg.onExitSchema(schema)
}
}
}
func (v visitor) visitSchema(s *XSDSchema, cfg *visitorConfig) {
for _, elm := range s.Elements {
v.visitElement(elm, cfg)
}
for _, ct := range s.ComplexTypes {
v.visitComplexType(ct, cfg)
}
for _, st := range s.SimpleType {
v.visitSimpleType(st, cfg)
}
}
func (v visitor) visitElements(es []*XSDElement, cfg *visitorConfig) {
for _, e := range es {
v.visitElement(e, cfg)
}
}
func (v visitor) visitAttribute(attr *XSDAttribute, cfg *visitorConfig) {
if cfg.onEnterAttribute != nil {
cfg.onEnterAttribute(attr)
}
if cfg.onExitAttribute != nil {
cfg.onExitAttribute(attr)
}
}
func (v visitor) visitAttributes(attrs []*XSDAttribute, cfg *visitorConfig) {
for _, attr := range attrs {
v.visitAttribute(attr, cfg)
}
}
func (v visitor) visitElement(e *XSDElement, cfg *visitorConfig) {
if cfg.onEnterElement != nil {
cfg.onEnterElement(e)
}
if e.ComplexType != nil {
v.visitComplexType(e.ComplexType, cfg)
}
if e.SimpleType != nil {
v.visitSimpleType(e.SimpleType, cfg)
}
if cfg.onExitElement != nil {
cfg.onExitElement(e)
}
}
func (v visitor) visitComplexType(ct *XSDComplexType, cfg *visitorConfig) {
if cfg.onEnterComplexType != nil {
cfg.onEnterComplexType(ct)
}
v.visitElements(ct.Sequence, cfg)
v.visitElements(ct.Choice, cfg)
v.visitElements(ct.SequenceChoice, cfg)
v.visitElements(ct.All, cfg)
v.visitAttributes(ct.Attributes, cfg)
v.visitAttributes(ct.ComplexContent.Extension.Attributes, cfg)
v.visitElements(ct.ComplexContent.Extension.Sequence, cfg)
v.visitElements(ct.ComplexContent.Extension.Choice, cfg)
v.visitElements(ct.ComplexContent.Extension.SequenceChoice, cfg)
v.visitAttributes(ct.SimpleContent.Extension.Attributes, cfg)
if cfg.onExitComplexType != nil {
cfg.onExitComplexType(ct)
}
}
func (v visitor) visitSimpleType(st *XSDSimpleType, cfg *visitorConfig) {
if cfg.onEnterSimpleType != nil {
cfg.onEnterSimpleType(st)
}
if cfg.onExitSimpleType != nil {
cfg.onExitSimpleType(st)
}
}