Todd 59b2711e1b schema: apply more default values
These are implied values as they are the defaults in the XSD
for optional attributes/elements. However I've noticed that
I keep running into issues where Mac Excel/Word fail to open
a file unless an optional default is provided.

I'll just add them all to hopefully increase compatibility and
save painful file format debugging sessions later.
2017-09-04 17:14:06 -05:00

113 lines
3.3 KiB
Go

// Copyright 2017 Baliance. All rights reserved.
//
// Use of this source code is governed by the terms of the Affero GNU General
// Public License version 3.0 as published by the Free Software Foundation and
// appearing in the file LICENSE included in the packaging of this file. A
// commercial license can be purchased by contacting sales@baliance.com.
package diagram
import (
"encoding/xml"
"fmt"
)
type AG_ConstraintRefAttributes struct {
RefTypeAttr ST_ConstraintType
RefForAttr ST_ConstraintRelationship
RefForNameAttr *string
RefPtTypeAttr ST_ElementType
}
func NewAG_ConstraintRefAttributes() *AG_ConstraintRefAttributes {
ret := &AG_ConstraintRefAttributes{}
ret.RefTypeAttr = ST_ConstraintTypeNone
ret.RefForAttr = ST_ConstraintRelationshipSelf
ret.RefPtTypeAttr = ST_ElementTypeAll
return ret
}
func (m *AG_ConstraintRefAttributes) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
if m.RefTypeAttr != ST_ConstraintTypeUnset {
attr, err := m.RefTypeAttr.MarshalXMLAttr(xml.Name{Local: "refType"})
if err != nil {
return err
}
start.Attr = append(start.Attr, attr)
}
if m.RefForAttr != ST_ConstraintRelationshipUnset {
attr, err := m.RefForAttr.MarshalXMLAttr(xml.Name{Local: "refFor"})
if err != nil {
return err
}
start.Attr = append(start.Attr, attr)
}
if m.RefForNameAttr != nil {
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "refForName"},
Value: fmt.Sprintf("%v", *m.RefForNameAttr)})
}
if m.RefPtTypeAttr != ST_ElementTypeUnset {
attr, err := m.RefPtTypeAttr.MarshalXMLAttr(xml.Name{Local: "refPtType"})
if err != nil {
return err
}
start.Attr = append(start.Attr, attr)
}
return nil
}
func (m *AG_ConstraintRefAttributes) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
// initialize to default
m.RefTypeAttr = ST_ConstraintTypeNone
m.RefForAttr = ST_ConstraintRelationshipSelf
m.RefPtTypeAttr = ST_ElementTypeAll
for _, attr := range start.Attr {
if attr.Name.Local == "refType" {
m.RefTypeAttr.UnmarshalXMLAttr(attr)
}
if attr.Name.Local == "refFor" {
m.RefForAttr.UnmarshalXMLAttr(attr)
}
if attr.Name.Local == "refForName" {
parsed, err := attr.Value, error(nil)
if err != nil {
return err
}
m.RefForNameAttr = &parsed
}
if attr.Name.Local == "refPtType" {
m.RefPtTypeAttr.UnmarshalXMLAttr(attr)
}
}
// skip any extensions we may find, but don't support
for {
tok, err := d.Token()
if err != nil {
return fmt.Errorf("parsing AG_ConstraintRefAttributes: %s", err)
}
if el, ok := tok.(xml.EndElement); ok && el.Name == start.Name {
break
}
}
return nil
}
// Validate validates the AG_ConstraintRefAttributes and its children
func (m *AG_ConstraintRefAttributes) Validate() error {
return m.ValidateWithPath("AG_ConstraintRefAttributes")
}
// ValidateWithPath validates the AG_ConstraintRefAttributes and its children, prefixing error messages with path
func (m *AG_ConstraintRefAttributes) ValidateWithPath(path string) error {
if err := m.RefTypeAttr.ValidateWithPath(path + "/RefTypeAttr"); err != nil {
return err
}
if err := m.RefForAttr.ValidateWithPath(path + "/RefForAttr"); err != nil {
return err
}
if err := m.RefPtTypeAttr.ValidateWithPath(path + "/RefPtTypeAttr"); err != nil {
return err
}
return nil
}