ReadComponentDefinition reads a ComponentDefinition from a file
(FileName string, ACTVersion string)
| 287 | |
| 288 | // ReadComponentDefinition reads a ComponentDefinition from a file |
| 289 | func ReadComponentDefinition(FileName string, ACTVersion string) (ComponentDefinition, error) { |
| 290 | var component ComponentDefinition |
| 291 | component.ImportedComponentDefinitions = make(map[string]ComponentDefinition, 0) |
| 292 | component.NameMapsLookup = NameMaps{ |
| 293 | enumMap : make(map[string]bool, 0), |
| 294 | structMap : make(map[string]bool, 0), |
| 295 | classMap : make(map[string]bool, 0), |
| 296 | functionTypeMap : make(map[string]bool, 0), |
| 297 | } |
| 298 | |
| 299 | absFileName, err := filepath.Abs(FileName) |
| 300 | if err != nil { |
| 301 | return component, err |
| 302 | } |
| 303 | directory := filepath.Dir(absFileName) |
| 304 | |
| 305 | file, err := os.Open(FileName) |
| 306 | if err != nil { |
| 307 | return component, err |
| 308 | } |
| 309 | |
| 310 | bytes, err := ioutil.ReadAll(file) |
| 311 | if err != nil { |
| 312 | return component, err |
| 313 | } |
| 314 | |
| 315 | component.ACTVersion = ACTVersion |
| 316 | err = xml.Unmarshal(bytes, &component) |
| 317 | if err != nil { |
| 318 | return component, err |
| 319 | } |
| 320 | |
| 321 | for i := 0; i < len(component.ImportComponents); i++ { |
| 322 | importComponent := component.ImportComponents[i] |
| 323 | subFileName := filepath.Join(directory, importComponent.URI) |
| 324 | |
| 325 | subComponent, err := ReadComponentDefinition(subFileName, ACTVersion) |
| 326 | if err != nil { |
| 327 | return component, err |
| 328 | } |
| 329 | if (subComponent.NameSpace != importComponent.Namespace) { |
| 330 | return component, fmt.Errorf("Namespace of imported component \"%s\" does not match declared namespace \"%s\"", importComponent.Namespace, subComponent.NameSpace); |
| 331 | } |
| 332 | component.ImportedComponentDefinitions[importComponent.Namespace] = subComponent |
| 333 | } |
| 334 | component.Normalize() |
| 335 | |
| 336 | return component, nil |
| 337 | } |
| 338 | |
| 339 | func getIndentationString(str string) string { |
| 340 | if str == "tabs" { |