Bug 1411-4: MDSAL Binding2 Generator Impl
[mdsal.git] / binding2 / mdsal-binding2-generator-impl / src / main / twirl / org / opendaylight / mdsal / binding2 / yangTemplateForModule.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 * Note: we should introduce our own format instead of txt *
16 ***********************************************************@
17
18 @import org.opendaylight.mdsal.binding2.generator.impl.util.YangTextTemplate
19 @import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil
20 @import org.opendaylight.yangtools.yang.model.api.Module
21
22 @(module: Module)
23 @if(module != null) {
24     @generateYangSnippet(module)
25 }
26
27 @generateYangSnippet(module: Module) = {
28     module @{module.getName()} {
29         yang-version @module.getYangVersion();
30         namespace "@module.getNamespace().toString()";
31         prefix "@module.getPrefix()";
32
33         @if(module.getImports() != null && !module.getImports().isEmpty()) {
34             @for(moduleImport <- module.getImports()) {
35                 @if(moduleImport != null && !moduleImport.getModuleName()) {
36                     import @{moduleImport.getModuleName()} { prefix "@{moduleImport.getPrefix()}"; }
37                 }
38             }
39         }
40         @if(module.getRevision() != null) {
41             revision @{SimpleDateFormatUtil.getRevisionFormat().format(module.getRevision())} {
42                 description "@{YangTextTemplate.formatToParagraph(module.getDescription(), 12)}";
43             }
44         }
45         @if(module.getChildNodes() != null) {
46             @yangTemplateWriteDataSchemaNodes(module.getChildNodes())
47         }
48         @if(module.getGroupings() != null && !module.getGroupings().isEmpty()) {
49             @yangTemplateWriteGroupingDefs(module.getGroupings())
50         }
51         @if(module.getAugmentations() != null && !module.getAugmentations().isEmpty()) {
52             @yangTemplateWriteAugments(module.getAugmentations())
53         }
54         @if(module.getDeviations() != null && !module.getDeviations().isEmpty()) {
55             @for(deviation <- module.getDeviations()) {
56                 @if(deviation != null) {
57                     deviation @{deviation.getTargetPath()} {
58                         @if(deviation.getReference() != null && !deviation.getReference().isEmpty()) {
59                             reference "@{deviation.getReference()}";
60                         }
61                         @for(deviation <- deviation.getDeviates()) {
62                             @if(deviation != null && deviation.getDeviateType() != null ) {
63                                 deviation @{deviation.getDeviateType().name()};
64                             }
65                         }
66                     }
67                 }
68             }
69         }
70         @if(module.getExtensionSchemaNodes() != null && !module.getExtensionSchemaNodes().isEmpty()) {
71             @for(extension <- module.getExtensionSchemaNodes()) {
72                 @if(extension != null) {
73                     @yangTemplateWriteExtension(extension)
74                 }
75             }
76         }
77         @if(module.getFeatures() != null && !module.getFeatures().isEmpty()) {
78             @for(feature <- module.getFeatures()) {
79                 @if(feature != null) {
80                     @yangTemplateWriteFeature(feature)
81                 }
82             }
83         }
84         @if(module.getIdentities() != null && !module.getIdentities().isEmpty()) {
85             @for(identity <- module.getIdentities()) {
86                 @if(identity != null) {
87                     @yangTemplateWriteIdentity(identity)
88                 }
89             }
90         }
91         @if(module.getNotifications() != null && !module.getNotifications().isEmpty()) {
92             @for(notification <- module.getNotifications()) {
93                 @if(notification != null) {
94                     @yangTemplateWriteNotification(notification)
95                 }
96             }
97         }
98         @if(module.getRpcs() != null && !module.getRpcs().isEmpty()) {
99             @for(rpc <- module.getRpcs()) {
100                 @if(rpc != null) {
101                     @yangTemplateWriteRPC(rpc)
102                 }
103             }
104         }
105         @if(module.getUnknownSchemaNodes() != null && !module.getUnknownSchemaNodes().isEmpty()) {
106             @yangTemplateWriteUnknownSchemaNodes(module.getUnknownSchemaNodes())
107         }
108         @if(module.getUses() != null && !module.getUses().isEmpty()) {
109             @yangTemplateWriteUsesNodes(module.getUses())
110         }
111     }
112 }