-
Notifications
You must be signed in to change notification settings - Fork 20
/
property-definition.go
81 lines (65 loc) · 2.13 KB
/
property-definition.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package tosca_v2_0
import (
"github.com/tliron/puccini/tosca"
)
//
// PropertyDefinition
//
// [TOSCA-v2.0] @ ?
// [TOSCA-Simple-Profile-YAML-v1.3] @ 3.6.10
// [TOSCA-Simple-Profile-YAML-v1.2] @ 3.6.9
// [TOSCA-Simple-Profile-YAML-v1.1] @ 3.5.8
// [TOSCA-Simple-Profile-YAML-v1.0] @ 3.5.8
//
type PropertyDefinition struct {
*AttributeDefinition `name:"property definition"`
Required *bool `read:"required"`
ConstraintClauses ConstraintClauses `read:"constraints,[]ConstraintClause"`
}
func NewPropertyDefinition(context *tosca.Context) *PropertyDefinition {
return &PropertyDefinition{AttributeDefinition: NewAttributeDefinition(context)}
}
// tosca.Reader signature
func ReadPropertyDefinition(context *tosca.Context) tosca.EntityPtr {
self := NewPropertyDefinition(context)
context.ValidateUnsupportedFields(context.ReadFields(self))
return self
}
func (self *PropertyDefinition) Inherit(parentDefinition *PropertyDefinition) {
logInherit.Debugf("property definition: %s", self.Name)
self.AttributeDefinition.Inherit(parentDefinition.AttributeDefinition)
if (self.Required == nil) && (parentDefinition.Required != nil) {
self.Required = parentDefinition.Required
}
if parentDefinition.ConstraintClauses != nil {
self.ConstraintClauses = parentDefinition.ConstraintClauses.Append(self.ConstraintClauses)
}
}
// parser.Renderable interface
func (self *PropertyDefinition) Render() {
logRender.Debugf("property definition: %s", self.Name)
self.AttributeDefinition.Render()
self.ConstraintClauses.Render(self.DataType)
}
func (self *PropertyDefinition) IsRequired() bool {
// defaults to true
return (self.Required == nil) || *self.Required
}
//
// PropertyDefinitions
//
type PropertyDefinitions map[string]*PropertyDefinition
func (self PropertyDefinitions) Inherit(parentDefinitions PropertyDefinitions) {
for name, definition := range parentDefinitions {
if _, ok := self[name]; !ok {
self[name] = definition
}
}
for name, definition := range self {
if parentDefinition, ok := parentDefinitions[name]; ok {
if definition != parentDefinition {
definition.Inherit(parentDefinition)
}
}
}
}