2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
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 ***********************************************************@
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
33 @(dataSchemaNode: DataSchemaNode, module: Module)
34 @if(dataSchemaNode.isInstanceOf[ContainerSchemaNode]) {
35 @container(dataSchemaNode.asInstanceOf[ContainerSchemaNode], module)
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)
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)
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()}";
55 @yangTemplateWriteType(dataSchemaNode.asInstanceOf[LeafSchemaNode].getType())
56 @mandatory(dataSchemaNode.asInstanceOf[LeafSchemaNode])
57 @status(dataSchemaNode)
61 @if(dataSchemaNode.isInstanceOf[LeafListSchemaNode]) {
62 leaf-list @{dataSchemaNode.asInstanceOf[LeafListSchemaNode].getQName().getLocalName()} {
63 @if(dataSchemaNode.asInstanceOf[LeafListSchemaNode].isUserOrdered()){
66 type @{dataSchemaNode.asInstanceOf[LeafListSchemaNode].getType().getQName().getLocalName()};
67 @minmaxelements(dataSchemaNode.asInstanceOf[LeafListSchemaNode])
68 @status(dataSchemaNode)
71 @if(dataSchemaNode.isInstanceOf[CaseSchemaNode]) {
72 case @{dataSchemaNode.asInstanceOf[CaseSchemaNode].getQName().getLocalName()} {
73 @for(childNode <- dataSchemaNode.asInstanceOf[CaseSchemaNode].getChildNodes()) {
74 @yangTemplateWriteDataSchemaNode(childNode, module)
76 @status(dataSchemaNode)
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)
85 @status(dataSchemaNode)
88 @if(dataSchemaNode.isInstanceOf[ListSchemaNode]) {
89 @list(dataSchemaNode.asInstanceOf[ListSchemaNode], module)
92 @mandatory(aware: MandatoryAware) = {
93 @if(aware.isMandatory()) {
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()}
104 @if(constraint.getMaxElements() != null) {
105 max-elements @{constraint.getMaxElements()}
111 @status(aware: WithStatus) = {
112 @if(aware.getStatus() != Status.CURRENT) {
113 status @{aware.getStatus()};
116 @container(container: ContainerSchemaNode, module: Module) = {
117 container @{container.getQName().getLocalName()} {
118 @if(container.getChildNodes() != null && !container.getChildNodes().isEmpty()) {
119 @yangTemplateWriteDataSchemaNodes(container.getChildNodes(), module)
121 @if(container.getGroupings() != null && !container.getGroupings().isEmpty()) {
122 @yangTemplateWriteGroupingDefs(container.getGroupings(), module)
124 @if(container.getUses() != null && !container.getUses().isEmpty()) {
125 @yangTemplateWriteUsesNodes(container.getUses(), module)
127 @if(container.getUnknownSchemaNodes() != null && !container.getUnknownSchemaNodes().isEmpty()) {
128 @yangTemplateWriteUnknownSchemaNodes(container.getUnknownSchemaNodes(), module)
130 @if(container.getActions() != null && !container.getActions().isEmpty()) {
131 @yangTemplateWriteActions(container.getActions(), module)
137 @list(list: ListSchemaNode, module: Module) = {
138 list @{list.getQName().getLocalName()} {
139 @if(list.isUserOrdered()){
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()} }";
149 @if(list.getChildNodes() != null && !list.getChildNodes().isEmpty()) {
150 @yangTemplateWriteDataSchemaNodes(list.getChildNodes(), module)
152 @if(list.getAvailableAugmentations() != null && !list.getAvailableAugmentations().isEmpty()) {
153 @yangTemplateWriteAugments(list.getAvailableAugmentations(), module)
155 @if(list.getGroupings() != null && !list.getGroupings().isEmpty()) {
156 @yangTemplateWriteGroupingDefs(list.getGroupings(), module)
158 @if(list.getUses() != null && !list.getUses().isEmpty()) {
159 @yangTemplateWriteUsesNodes(list.getUses(), module)
161 @if(list.getUnknownSchemaNodes() != null && !list.getUnknownSchemaNodes().isEmpty()) {
162 @yangTemplateWriteUnknownSchemaNodes(list.getUnknownSchemaNodes(), module)
164 @if(list.getActions() != null && !list.getActions().isEmpty()) {
165 @yangTemplateWriteActions(list.getActions(), module)