diff --git a/common/parser/parser.go b/common/parser/parser.go index b10cc33..717ff11 100644 --- a/common/parser/parser.go +++ b/common/parser/parser.go @@ -460,14 +460,22 @@ func getAssociations(doc *xmlquery.Node, c *xmlquery.Node) []types.Association { continue } - assoc := buildAssociation(doc, relationElement, q.Role, isParent) + connector := relationElement.Parent.Parent + isSource := isStructuralSource(connector, classId) + + assoc := buildAssociation(doc, relationElement, q.Role, isParent, isSource) assocs = append(assocs, assoc) } } return assocs } -func buildAssociation(doc *xmlquery.Node, rel *xmlquery.Node, role types.AssociationRole, isParent bool) types.Association { +func isStructuralSource(connector *xmlquery.Node, classId string) bool { + structuralSourceID := connector.SelectElement("source").SelectAttr("idref") + return structuralSourceID == classId +} + +func buildAssociation(doc *xmlquery.Node, rel *xmlquery.Node, role types.AssociationRole, isParent bool, isSource bool) types.Association { targetId := rel.Parent.SelectAttr("idref") targetClassElement := findClassElementByID(doc, targetId) @@ -477,11 +485,12 @@ func buildAssociation(doc *xmlquery.Node, rel *xmlquery.Node, role types.Associa Multiplicity: rel.SelectElement("../type").SelectAttr("multiplicity"), Package: getPackagePath(targetClassElement, doc), Deprecated: rel.SelectElement("../../tags/tag[@name='DEPRECATED']") != nil, - Source: getAssociationSource(rel, role, isParent), + InverseName: getAssociationInverseName(rel, role, isParent), + IsSource: isSource, } } -func getAssociationSource(rel *xmlquery.Node, role types.AssociationRole, isParent bool) string { +func getAssociationInverseName(rel *xmlquery.Node, role types.AssociationRole, isParent bool) string { direction := rel.SelectElement("../../properties").SelectAttr("direction") if direction != "Bi-Directional" || isParent { diff --git a/common/types/association.go b/common/types/association.go index d73999b..3e2dbf6 100644 --- a/common/types/association.go +++ b/common/types/association.go @@ -3,8 +3,9 @@ package types type Association struct { Name string Target string - Source string + InverseName string Package string Deprecated bool Multiplicity string + IsSource bool } diff --git a/generate/generator.go b/generate/generator.go index d096577..6854343 100644 --- a/generate/generator.go +++ b/generate/generator.go @@ -84,11 +84,17 @@ var funcMap = template.FuncMap{ return multiplicity } }, - "resolveSource": func(source string) string { - if source == "" { + "resolveInverseName": func(inverseName string) string { + if inverseName == "" { return "null" } - return strconv.Quote(source) + return strconv.Quote(inverseName) + }, + "resolveSource": func(inverseName string, isSource bool) string { + if inverseName == "" { + return "null" + } + return strconv.FormatBool(isSource) }, "modelRename": func(s string) string { if s == "FintMainObject" { diff --git a/generate/java/java_class_tpl.go b/generate/java/java_class_tpl.go index f3d9804..327b122 100644 --- a/generate/java/java_class_tpl.go +++ b/generate/java/java_class_tpl.go @@ -51,19 +51,21 @@ public {{- if .Abstract }} abstract {{- end }} class {{ .Name }} {{ if .Extends @Getter public enum Relasjonsnavn implements FintRelation { {{- range $i, $rel := .Relations }} - {{ upperCase $rel.Name }}("{{ $rel.Name }}", "{{ $rel.Package }}.{{ $rel.Target }}", {{ resolveMultiplicity $rel.Multiplicity }}, {{ resolveSource $rel.Source }}){{ if ne $i $c }},{{ else }};{{ end -}} + {{ upperCase $rel.Name }}("{{ $rel.Name }}", "{{ $rel.Package }}.{{ $rel.Target }}", {{ resolveMultiplicity $rel.Multiplicity }}, {{ resolveSource $rel.InverseName $rel.IsSource }}, {{ resolveInverseName $rel.InverseName }}){{ if ne $i $c }},{{ else }};{{ end -}} {{ end }} private final String name; private final String packageName; private final FintMultiplicity multiplicity; private final String inverseName; + private final Boolean isSource; - private Relasjonsnavn(String name, String packageName, FintMultiplicity multiplicity, String inverseName) { + private Relasjonsnavn(String name, String packageName, FintMultiplicity multiplicity, Boolean isSource, String inverseName) { this.name = name; this.packageName = packageName; this.multiplicity = multiplicity; this.inverseName = inverseName; + this.isSource = isSource; } } {{ end -}}