-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_type.go
More file actions
72 lines (62 loc) · 2.09 KB
/
simple_type.go
File metadata and controls
72 lines (62 loc) · 2.09 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
package goxc
import (
"encoding/xml"
"strings"
)
type SimpleType struct {
Class
XMLName xml.Name `xml:"simpleType"`
Name string `xml:"name,attr"`
Annotation *Annotation `xml:"annotation,omitempty"`
Restriction *Restriction `xml:"restriction,omitempty"`
Union *Union `xml:"union,omitempty"`
List *List `xml:"list,omitempty"`
Imports []*Import
PackageName, Parent, Type string
}
func (s *SimpleType) Generate(targetPrefix string, namespaces map[string]string) {
s.Version = version
s.Rev = rev
if s.isRestriction() {
if s.Restriction.isEnumeration() {
s.prepareRestriction(targetPrefix, namespaces)
s.Restriction.Generate(targetPrefix, namespaces)
} else {
s.Type = Replace(targetPrefix, s.Restriction.Base, namespaces)
s.Imports = Append(s.Imports, s.Type, namespaces)
generateStruct(s, "templates/simple_type.tmpl", s.PackageName, s.Name, "simpleType")
}
}
if s.isUnion() {
s.Type = Replace(targetPrefix, strings.Replace(s.Union.MemberTypes, " ", "\n", -1), namespaces)
generateStruct(s, "templates/union_type.tmpl", s.PackageName, s.Name, "simpleType (unionType)")
}
if s.isList() {
s.Type = Replace(targetPrefix, s.List.ItemType, namespaces)
generateStruct(s, "templates/list_type.tmpl", s.PackageName, s.Name, "simpleType (listType)")
}
}
func (s *SimpleType) isRestriction() bool {
return s.Restriction != nil
}
func (s *SimpleType) isUnion() bool {
return s.Union != nil
}
func (s *SimpleType) isList() bool {
return s.List != nil
}
func (s *SimpleType) hasParent() bool {
return s.Parent != ""
}
func (s *SimpleType) prepareRestriction(targetPrefix string, namespaces map[string]string) {
s.Restriction.PackageName = s.PackageName
s.Restriction.Name = s.Name
if strings.Contains(s.Restriction.Base, ":") {
s.Type = Replace(targetPrefix, s.Restriction.Base, namespaces)
} else {
s.Type = Upper(s.Restriction.Base)
}
if s.hasParent() && strings.Contains(s.Restriction.Base, ":") {
s.Restriction.Name = s.Type
}
}