github.com/Axway/agent-sdk@v1.1.101/pkg/util/wsdl/types.go (about) 1 package wsdl 2 3 import "encoding/xml" 4 5 // Definitions is the root element of a WSDL document. 6 type Definitions struct { 7 XMLName xml.Name `xml:"definitions"` 8 Name string `xml:"name,attr"` 9 TargetNamespace string `xml:"targetNamespace,attr"` 10 Namespaces map[string]string `xml:"-"` 11 SOAPEnv string `xml:"SOAP-ENV,attr"` 12 SOAPEnc string `xml:"SOAP-ENC,attr"` 13 Service Service `xml:"service"` 14 Imports []*Import `xml:"import"` 15 Schema Schema `xml:"types>schema"` 16 Messages []*Message `xml:"message"` 17 PortType []*PortType `xml:"portType"` 18 Binding Binding `xml:"binding"` 19 } 20 21 type definitionDup Definitions 22 23 // UnmarshalXML implements the xml.Unmarshaler interface. 24 func (def *Definitions) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { 25 for _, attr := range start.Attr { 26 if attr.Name.Space == "xmlns" { 27 if def.Namespaces == nil { 28 def.Namespaces = make(map[string]string) 29 } 30 def.Namespaces[attr.Name.Local] = attr.Value 31 } 32 } 33 return d.DecodeElement((*definitionDup)(def), &start) 34 } 35 36 // Service defines a WSDL service and with a location, like an HTTP server. 37 type Service struct { 38 Doc string `xml:"documentation"` 39 Ports []*Port `xml:"port"` 40 } 41 42 // Port for WSDL service. 43 type Port struct { 44 XMLName xml.Name `xml:"port"` 45 Name string `xml:"name,attr"` 46 Binding string `xml:"binding,attr"` 47 Address Address `xml:"address"` 48 } 49 50 // Address of WSDL service. 51 type Address struct { 52 XMLName xml.Name `xml:"address"` 53 Location string `xml:"location,attr"` 54 } 55 56 // Schema of WSDL document. 57 type Schema struct { 58 XMLName xml.Name `xml:"schema"` 59 TargetNamespace string `xml:"targetNamespace,attr"` 60 Namespaces map[string]string `xml:"-"` 61 Imports []*ImportSchema `xml:"import"` 62 Includes []*IncludeSchema `xml:"include"` 63 SimpleTypes []*SimpleType `xml:"simpleType"` 64 ComplexTypes []*ComplexType `xml:"complexType"` 65 Elements []*Element `xml:"element"` 66 } 67 68 // Unmarshaling solution from Matt Harden (http://grokbase.com/t/gg/golang-nuts/14bk21xb7a/go-nuts-extending-encoding-xml-to-capture-unknown-attributes) 69 // We duplicate the type Schema here so that we can unmarshal into it 70 // without recursively triggering the *Schema.UnmarshalXML method. 71 // Other options are to embed tt into Type or declare Type as a synonym for tt. 72 // The important thing is that tt is only used directly in *Schema.UnmarshalXML or Schema.MarshalXML. 73 type schemaDup Schema 74 75 // UnmarshalXML implements the xml.Unmarshaler interface. 76 func (schema *Schema) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { 77 for _, attr := range start.Attr { 78 if attr.Name.Space == "xmlns" { 79 if schema.Namespaces == nil { 80 schema.Namespaces = make(map[string]string) 81 } 82 schema.Namespaces[attr.Name.Local] = attr.Value 83 } 84 } 85 return d.DecodeElement((*schemaDup)(schema), &start) 86 } 87 88 // SimpleType describes a simple type, such as string. 89 type SimpleType struct { 90 XMLName xml.Name `xml:"simpleType"` 91 Name string `xml:"name,attr"` 92 Union *Union `xml:"union"` 93 Restriction *Restriction `xml:"restriction"` 94 TargetNamespace string 95 } 96 97 // Union is a mix of multiple types in a union. 98 type Union struct { 99 XMLName xml.Name `xml:"union"` 100 MemberTypes string `xml:"memberTypes,attr"` 101 } 102 103 // Restriction describes the WSDL type of the simple type and 104 // optionally its allowed values. 105 type Restriction struct { 106 XMLName xml.Name `xml:"restriction"` 107 Base string `xml:"base,attr"` 108 Enum []*Enum `xml:"enumeration"` 109 Attributes []*Attribute `xml:"attribute"` 110 } 111 112 // Enum describes one possible value for a Restriction. 113 type Enum struct { 114 XMLName xml.Name `xml:"enumeration"` 115 Value string `xml:"value,attr"` 116 } 117 118 // ComplexType describes a complex type, such as a struct. 119 type ComplexType struct { 120 XMLName xml.Name `xml:"complexType"` 121 Name string `xml:"name,attr"` 122 Abstract bool `xml:"abstract,attr"` 123 Doc string `xml:"annotation>documentation"` 124 AllElements []*Element `xml:"all>element"` 125 ComplexContent *ComplexContent `xml:"complexContent"` 126 SimpleContent *SimpleContent `xml:"simpleContent"` 127 Sequence *Sequence `xml:"sequence"` 128 Choice *Choice `xml:"choice"` 129 Attributes []*Attribute `xml:"attribute"` 130 TargetNamespace string 131 } 132 133 // SimpleContent describes simple content within a complex type. 134 type SimpleContent struct { 135 XMLName xml.Name `xml:"simpleContent"` 136 Extension *Extension `xml:"extension"` 137 Restriction *Restriction `xml:"restriction"` 138 } 139 140 // ComplexContent describes complex content within a complex type. Usually 141 // for extending the complex type with fields from the complex content. 142 type ComplexContent struct { 143 XMLName xml.Name `xml:"complexContent"` 144 Extension *Extension `xml:"extension"` 145 Restriction *Restriction `xml:"restriction"` 146 } 147 148 // Extension describes a complex content extension. 149 type Extension struct { 150 XMLName xml.Name `xml:"extension"` 151 Base string `xml:"base,attr"` 152 Sequence *Sequence `xml:"sequence"` 153 Choice *Choice `xml:"choice"` 154 Attributes []*Attribute `xml:"attribute"` 155 } 156 157 // Sequence describes a list of elements (parameters) of a type. 158 type Sequence struct { 159 XMLName xml.Name `xml:"sequence"` 160 ComplexTypes []*ComplexType `xml:"complexType"` 161 Elements []*Element `xml:"element"` 162 Any []*AnyElement `xml:"any"` 163 Choices []*Choice `xml:"choice"` 164 } 165 166 // Choice describes a list of elements (parameters) of a type. 167 type Choice struct { 168 XMLName xml.Name `xml:"choice"` 169 ComplexTypes []*ComplexType `xml:"complexType"` 170 Elements []*Element `xml:"element"` 171 Any []*AnyElement `xml:"any"` 172 } 173 174 // Attribute describes an attribute of a given type. 175 type Attribute struct { 176 XMLName xml.Name `xml:"attribute"` 177 Name string `xml:"name,attr"` 178 Ref string `xml:"ref,attr"` 179 Type string `xml:"type,attr"` 180 ArrayType string `xml:"arrayType,attr"` 181 Min int `xml:"minOccurs,attr"` 182 Max string `xml:"maxOccurs,attr"` // can be # or unbounded 183 Nillable bool `xml:"nillable,attr"` 184 } 185 186 // Element describes an element of a given type. 187 type Element struct { 188 XMLName xml.Name `xml:"element"` 189 Name string `xml:"name,attr"` 190 Ref string `xml:"ref,attr"` 191 Type string `xml:"type,attr"` 192 Min int `xml:"minOccurs,attr"` 193 Max string `xml:"maxOccurs,attr"` // can be # or unbounded 194 Nillable bool `xml:"nillable,attr"` 195 ComplexType *ComplexType `xml:"complexType"` 196 } 197 198 // AnyElement describes an element of an undefined type. 199 type AnyElement struct { 200 XMLName xml.Name `xml:"any"` 201 Min int `xml:"minOccurs,attr"` 202 Max string `xml:"maxOccurs,attr"` // can be # or unbounded 203 } 204 205 // Import points to another WSDL to be imported at root level. 206 type Import struct { 207 XMLName xml.Name `xml:"import"` 208 Namespace string `xml:"namespace,attr"` 209 Location string `xml:"location,attr"` 210 } 211 212 // ImportSchema points to another WSDL to be imported at schema level. 213 type ImportSchema struct { 214 XMLName xml.Name `xml:"import"` 215 Namespace string `xml:"namespace,attr"` 216 Location string `xml:"schemaLocation,attr"` 217 } 218 219 // IncludeSchema points to another WSDL to be imported at schema level. 220 type IncludeSchema struct { 221 XMLName xml.Name `xml:"include"` 222 Namespace string `xml:"namespace,attr"` 223 Location string `xml:"schemaLocation,attr"` 224 } 225 226 // Message describes the data being communicated, such as functions 227 // and their parameters. 228 type Message struct { 229 XMLName xml.Name `xml:"message"` 230 Name string `xml:"name,attr"` 231 Parts []*Part `xml:"part"` 232 } 233 234 // Part describes what Type or Element to use from the PortType. 235 type Part struct { 236 XMLName xml.Name `xml:"part"` 237 Name string `xml:"name,attr"` 238 Type string `xml:"type,attr,omitempty"` 239 Element string `xml:"element,attr,omitempty"` 240 } 241 242 // PortType describes a set of operations. 243 type PortType struct { 244 XMLName xml.Name `xml:"portType"` 245 Name string `xml:"name,attr"` 246 Operations []*Operation `xml:"operation"` 247 } 248 249 // Operation describes an operation. 250 type Operation struct { 251 XMLName xml.Name `xml:"operation"` 252 Name string `xml:"name,attr"` 253 Doc string `xml:"documentation"` 254 Input *IO `xml:"input"` 255 Output *IO `xml:"output"` 256 } 257 258 // IO describes which message is linked to an operation, for input 259 // or output parameters. 260 type IO struct { 261 XMLName xml.Name 262 Message string `xml:"message,attr"` 263 } 264 265 // Binding describes SOAP to WSDL binding. 266 type Binding struct { 267 XMLName xml.Name `xml:"binding"` 268 Name string `xml:"name,attr"` 269 Type string `xml:"type,attr"` 270 BindingType *BindingType `xml:"binding"` 271 Operations []*BindingOperation `xml:"operation"` 272 } 273 274 // BindingType contains additional meta data on how to implement the binding. 275 type BindingType struct { 276 Style string `xml:"style,attr"` 277 Transport string `xml:"transport,attr"` 278 } 279 280 // BindingOperation describes the requirement for binding SOAP to WSDL 281 // operations. 282 type BindingOperation struct { 283 XMLName xml.Name `xml:"operation"` 284 Name string `xml:"name,attr"` 285 Operation SOAP12Operation `xml:"http://schemas.xmlsoap.org/wsdl/soap12/ operation"` 286 Operation11 SOAP11Operation `xml:"http://schemas.xmlsoap.org/wsdl/soap/ operation"` 287 Input *BindingIO `xml:"input>body"` 288 Output *BindingIO `xml:"output>body"` 289 } 290 291 // SOAP12Operation describes a SOAP 1.2 operation. The soap12 namespace is 292 // important as the presence of a SOAP12Operation.Action is used to switch 293 // things over to sending the SOAP 1.2 content type header: 294 // (application/xml; charset=UTF-8; action='foobar') 295 type SOAP12Operation struct { 296 XMLName xml.Name `xml:"http://schemas.xmlsoap.org/wsdl/soap12/ operation"` 297 Action string `xml:"soapAction,attr"` 298 } 299 300 // SOAP11Operation describes a SOAP 1.1 operation. If it is specified in the wsdl, 301 // the soapAction will use this value instead of the default value 302 type SOAP11Operation struct { 303 XMLName xml.Name `xml:"http://schemas.xmlsoap.org/wsdl/soap/ operation"` 304 Action string `xml:"soapAction,attr"` 305 } 306 307 // BindingIO describes the IO binding of SOAP operations. See IO for details. 308 type BindingIO struct { 309 Parts string `xml:"parts,attr"` 310 Use string `xml:"use,attr"` 311 }