Eliminate XtendHelper and SchemaLock
[mdsal.git] / binding2 / mdsal-binding2-generator-impl / src / main / twirl / org / opendaylight / mdsal / binding / javav2 / generator / impl / yangTemplateWriteDataSchemaNode.scala.txt
1 @*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  *@
8
9 @**********************************************************
10 * Twirl YangTemplate for generating yang snippets.        *
11 * Twirl is transformed to Scala and compiled. Then,       *
12 * it can be called from Java with particular input        *
13 * parameters to render desired output code.               *
14 ***********************************************************@
15
16 @import org.opendaylight.yangtools.yang.model.api.AnyDataSchemaNode
17 @import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode
18 @import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode
19 @import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode
20 @import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode
21 @import org.opendaylight.yangtools.yang.model.api.DataSchemaNode
22 @import org.opendaylight.yangtools.yang.model.api.DocumentedNode.WithStatus
23 @import org.opendaylight.yangtools.yang.model.api.ElementCountConstraintAware
24 @import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode
25 @import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode
26 @import org.opendaylight.yangtools.yang.model.api.ListSchemaNode
27 @import org.opendaylight.yangtools.yang.model.api.MandatoryAware
28 @import org.opendaylight.yangtools.yang.model.api.Module
29 @import org.opendaylight.yangtools.yang.model.api.SchemaNode
30 @import org.opendaylight.yangtools.yang.model.api.Status
31 @import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode
32
33 @(dataSchemaNode: DataSchemaNode, module: Module)
34 @if(dataSchemaNode.isInstanceOf[ContainerSchemaNode]) {
35     @container(dataSchemaNode.asInstanceOf[ContainerSchemaNode], module)
36 }
37 @if(dataSchemaNode.isInstanceOf[AnyXmlSchemaNode]) {
38     anyxml @{dataSchemaNode.asInstanceOf[AnyXmlSchemaNode].getQName().getLocalName()}@if(dataSchemaNode.asInstanceOf[AnyXmlSchemaNode].getStatus() == Status.CURRENT && !dataSchemaNode.asInstanceOf[AnyXmlSchemaNode].isMandatory()){;} else { {
39         @mandatory(dataSchemaNode.asInstanceOf[AnyXmlSchemaNode])
40         @status(dataSchemaNode)
41     }}
42 }
43 @if(dataSchemaNode.isInstanceOf[AnyDataSchemaNode]) {
44     anydata @{dataSchemaNode.asInstanceOf[AnyDataSchemaNode].getQName().getLocalName()}@if(dataSchemaNode.asInstanceOf[AnyDataSchemaNode].getStatus() == Status.CURRENT && !dataSchemaNode.asInstanceOf[AnyDataSchemaNode].isMandatory()){;} else { {
45         @mandatory(dataSchemaNode.asInstanceOf[AnyDataSchemaNode])
46         @status(dataSchemaNode)
47     }}
48 }
49 @if(dataSchemaNode.isInstanceOf[LeafSchemaNode]) {
50     @if(!dataSchemaNode.asInstanceOf[LeafSchemaNode].isAddedByUses() && !dataSchemaNode.asInstanceOf[LeafSchemaNode].isAugmenting()){
51         leaf @{dataSchemaNode.asInstanceOf[LeafSchemaNode].getQName().getLocalName()} {
52             @if(dataSchemaNode.asInstanceOf[LeafSchemaNode].getDescription() != null){
53                 description "@{dataSchemaNode.asInstanceOf[LeafSchemaNode].getDescription()}";
54             }
55             @yangTemplateWriteType(dataSchemaNode.asInstanceOf[LeafSchemaNode].getType())
56             @mandatory(dataSchemaNode.asInstanceOf[LeafSchemaNode])
57             @status(dataSchemaNode)
58         }
59     }
60 }
61 @if(dataSchemaNode.isInstanceOf[LeafListSchemaNode]) {
62     leaf-list @{dataSchemaNode.asInstanceOf[LeafListSchemaNode].getQName().getLocalName()} {
63         @if(dataSchemaNode.asInstanceOf[LeafListSchemaNode].isUserOrdered()){
64             ordered-by user;
65         }
66         type @{dataSchemaNode.asInstanceOf[LeafListSchemaNode].getType().getQName().getLocalName()};
67         @minmaxelements(dataSchemaNode.asInstanceOf[LeafListSchemaNode])
68         @status(dataSchemaNode)
69     }
70 }
71 @if(dataSchemaNode.isInstanceOf[CaseSchemaNode]) {
72     case @{dataSchemaNode.asInstanceOf[CaseSchemaNode].getQName().getLocalName()} {
73         @for(childNode <- dataSchemaNode.asInstanceOf[CaseSchemaNode].getChildNodes()) {
74             @yangTemplateWriteDataSchemaNode(childNode, module)
75         }
76         @status(dataSchemaNode)
77     }
78 }
79 @if(dataSchemaNode.isInstanceOf[ChoiceSchemaNode]) {
80     choice @{dataSchemaNode.asInstanceOf[ChoiceSchemaNode].getQName().getLocalName()} {
81         @mandatory(dataSchemaNode.asInstanceOf[ChoiceSchemaNode])
82         @for(childNode <- dataSchemaNode.asInstanceOf[ChoiceSchemaNode].getCases().values()) {
83             @yangTemplateWriteDataSchemaNode(childNode, module)
84         }
85         @status(dataSchemaNode)
86     }
87 }
88 @if(dataSchemaNode.isInstanceOf[ListSchemaNode]) {
89     @list(dataSchemaNode.asInstanceOf[ListSchemaNode], module)
90 }
91
92 @mandatory(aware: MandatoryAware) = {
93     @if(aware.isMandatory()) {
94          mandatory true;
95     }
96 }
97
98 @minmaxelements(aware: ElementCountConstraintAware) = {
99     @if(aware.getElementCountConstraint().isPresent()) {
100         @defining(aware.getElementCountConstraint().get()) { constraint =>
101             @if(constraint.getMinElements() != null) {
102                 min-elements @{constraint.getMinElements()}
103             }
104             @if(constraint.getMaxElements() != null) {
105                 max-elements @{constraint.getMaxElements()}
106             }
107         }
108     }
109 }
110          
111 @status(aware: WithStatus) = {
112     @if(aware.getStatus() != Status.CURRENT) {
113         status @{aware.getStatus()};
114     }
115 }
116 @container(container: ContainerSchemaNode, module: Module) = {
117     container @{container.getQName().getLocalName()} {
118         @if(container.getChildNodes() != null && !container.getChildNodes().isEmpty()) {
119             @yangTemplateWriteDataSchemaNodes(container.getChildNodes(), module)
120         }
121         @if(container.getGroupings() != null && !container.getGroupings().isEmpty()) {
122             @yangTemplateWriteGroupingDefs(container.getGroupings(), module)
123         }
124         @if(container.getUses() != null && !container.getUses().isEmpty()) {
125             @yangTemplateWriteUsesNodes(container.getUses(), module)
126         }
127         @if(container.getUnknownSchemaNodes() != null && !container.getUnknownSchemaNodes().isEmpty()) {
128             @yangTemplateWriteUnknownSchemaNodes(container.getUnknownSchemaNodes(), module)
129         }
130         @if(container.getActions() != null && !container.getActions().isEmpty()) {
131             @yangTemplateWriteActions(container.getActions(), module)
132         }
133         @status(container)
134     }
135 }
136
137 @list(list: ListSchemaNode, module: Module) = {
138     list @{list.getQName().getLocalName()} {
139         @if(list.isUserOrdered()){
140             ordered-by user;
141         }
142         @minmaxelements(list)
143         key "@for(listKey <- list.getKeyDefinition()) {@{listKey.getLocalName()} }";
144         @if(!list.getUniqueConstraints().isEmpty()){
145             @for(listUnique <- list.getUniqueConstraints()){
146                 unique "@for(tagUnique <- listUnique.getTag()) {@{tagUnique.getLastComponent.getLocalName()} }";
147             }
148         }
149         @if(list.getChildNodes() != null && !list.getChildNodes().isEmpty()) {
150             @yangTemplateWriteDataSchemaNodes(list.getChildNodes(), module)
151         }
152         @if(list.getAvailableAugmentations() != null && !list.getAvailableAugmentations().isEmpty()) {
153             @yangTemplateWriteAugments(list.getAvailableAugmentations(), module)
154         }
155         @if(list.getGroupings() != null && !list.getGroupings().isEmpty()) {
156             @yangTemplateWriteGroupingDefs(list.getGroupings(), module)
157         }
158         @if(list.getUses() != null && !list.getUses().isEmpty()) {
159             @yangTemplateWriteUsesNodes(list.getUses(), module)
160         }
161         @if(list.getUnknownSchemaNodes() != null && !list.getUnknownSchemaNodes().isEmpty()) {
162             @yangTemplateWriteUnknownSchemaNodes(list.getUnknownSchemaNodes(), module)
163         }
164         @if(list.getActions() != null && !list.getActions().isEmpty()) {
165             @yangTemplateWriteActions(list.getActions(), module)
166         }
167         @status(list)
168     }
169 }