Skip to content

Commit

Permalink
Begins work to generate operations
Browse files Browse the repository at this point in the history
  • Loading branch information
c4milo committed Jan 4, 2014
1 parent 5bbded5 commit a6f7a25
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 14 deletions.
37 changes: 31 additions & 6 deletions gowsdl.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ func (g *GoWsdl) genTypes() ([]byte, error) {
"makeFieldPublic": makeFieldPublic,
}

//TODO resolve element refs in place.
//g.resolveElementsRefs()

data := new(bytes.Buffer)
tmpl := template.Must(template.New("types").Funcs(funcMap).Parse(typesTmpl))
err := tmpl.Execute(data, g.wsdl.Types)
Expand All @@ -247,15 +250,32 @@ func (g *GoWsdl) genTypes() ([]byte, error) {
return data.Bytes(), nil
}

// func (g *GoWsdl) resolveElementsRefs() error {
// for _, schema := range g.wsdl.Types.Schemas {
// for _, globalEl := range schema.Elements {
// for _, localEl := range globalEl.ComplexType.Sequence.Elements {

// }
// }
// }
// }

func (g *GoWsdl) genOperations() ([]byte, error) {
for _, pt := range g.wsdl.PortTypes {
for _, _ = range pt.Operations {
//log.Printf("Operation %s -> i: %#v, o: %#v, f: %#v", o.Name, o.Input, o.Output, o.Faults)
}
log.Printf("Total ops: %d\n", len(pt.Operations))
funcMap := template.FuncMap{
"toGoType": toGoType,
"stripns": stripns,
"replaceReservedWords": replaceReservedWords,
"makeFieldPublic": makeFieldPublic,
}

return nil, nil
data := new(bytes.Buffer)
tmpl := template.Must(template.New("operations").Funcs(funcMap).Parse(opsTmpl))
err := tmpl.Execute(data, g.wsdl.PortTypes)
if err != nil {
return nil, err
}

return data.Bytes(), nil
}

var reservedWords = map[string]string{
Expand Down Expand Up @@ -296,6 +316,7 @@ func replaceReservedWords(identifier string) string {

var xsd2GoTypes = map[string]string{
"string": "string",
"token": "string",
"float": "float32",
"double": "float64",
"decimal": "float64",
Expand Down Expand Up @@ -350,6 +371,10 @@ func stripns(xsdType string) string {

func makeFieldPublic(field_ string) string {
field := []rune(field_)
if len(field) == 0 {
return field_
}

field[0] = unicode.ToUpper(field[0])
return string(field)
}
Expand Down
5 changes: 5 additions & 0 deletions operations_tmpl.go
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
package main

var opsTmpl = `
{{range .Operations}}
{{end}}
`
36 changes: 28 additions & 8 deletions types_tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ package main

var typesTmpl = `
{{define "SimpleType"}}
{{$name := .Name}}
type {{.Name}} {{toGoType .Restriction.Base}}
{{$name := replaceReservedWords .Name}}
type {{$name}} {{toGoType .Restriction.Base}}
const (
{{with .Restriction}}
{{range .Enumeration}}
{{replaceReservedWords .Value | makeFieldPublic}} {{$name}} = "{{.Value}}" {{end}}
{{$value := replaceReservedWords .Value}}{{$value | makeFieldPublic}} {{$name}} = "{{$value}}" {{end}}
{{end}}
)
{{end}}
{{define "ComplexType"}}
{{define "ComplexTypeGlobal"}}
{{$name := replaceReservedWords .Name}}
type {{.Name}} struct {
type {{$name}} struct {
{{if ne .ComplexContent.Extension.Base ""}}
{{$baseType := .ComplexContent.Extension.Base}}
{{ if $baseType }}
Expand All @@ -29,14 +29,34 @@ var typesTmpl = `
}
{{end}}
{{define "ComplexTypeLocal"}}
{{$name := replaceReservedWords .Name}}
{{with .ComplexType}}
type {{$name}} struct {
{{if ne .ComplexContent.Extension.Base ""}}
{{$baseType := .ComplexContent.Extension.Base}}
{{ if $baseType }}
*{{stripns $baseType}}
{{end}}
{{template "Elements" .ComplexContent.Extension.Sequence.Elements}}
{{ else }}
{{template "Elements" .Sequence.Elements}}
{{end}}
}
{{end}}
{{end}}
{{define "Elements"}}
{{range .}}
{{replaceReservedWords .Name | makeFieldPublic}} {{if eq .MaxOccurs "unbounded"}}[]{{end}}{{.Type | toGoType}}{{end}}
{{replaceReservedWords .Name}} {{if eq .MaxOccurs "unbounded"}}[]{{end}}{{.Type | toGoType}}{{end}}
{{end}}
package main
//Generated by https://github.com/c4milo/gowsdl
//Do not modify
//Copyright (c) 2014, Camilo Aguilar. All rights reserved.
import (
"encoding/xml"
//"time"
Expand All @@ -51,11 +71,11 @@ import (
{{end}}
{{range .Elements}}
{{if not .Type}}
{{template "ComplexTypeLocal" .}}
{{end}}
{{end}}
{{range .ComplexTypes}}
{{template "ComplexType" .}}
{{template "ComplexTypeGlobal" .}}
{{end}}
{{end}}
`
1 change: 1 addition & 0 deletions xsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type XsdElement struct {
Name string `xml:"name,attr"`
Nillable bool `xml:"nillable,attr"`
Type string `xml:"type,attr"`
Ref string `xml:"ref,attr"`
MinOccurs string `xml:"minOccurs,attr"`
MaxOccurs string `xml:"maxOccurs,attr"`
ComplexType *XsdComplexType `xml:"http://www.w3.org/2001/XMLSchema complexType"` //local
Expand Down

0 comments on commit a6f7a25

Please sign in to comment.