02dbb57aab88d4ca26286f0f4776c4e09afc3426
[mdsal.git] / binding2 / mdsal-binding2-generator-impl / src / main / twirl / org / opendaylight / mdsal / binding / javav2 / generator / impl / 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
16 @import org.opendaylight.mdsal.binding.javav2.generator.impl.util.YangTextTemplate
17 @import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil
18 @import org.opendaylight.yangtools.yang.model.api.Module
19 @import org.opendaylight.yangtools.yang.model.api.DocumentedNode
20 @import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement
21 @import org.opendaylight.yangtools.yang.model.api.stmt.RevisionStatement
22
23 @(module: Module)
24 @if(module != null) {
25     @generateYangSnippet(module)
26 }
27
28 @generateYangSnippet(module: Module) = {
29     module @{module.getName()} {
30         yang-version @module.getYangVersion();
31         namespace "@module.getNamespace().toString()";
32         prefix "@module.getPrefix()";
33
34         @if(module.getImports() != null && !module.getImports().isEmpty()) {
35             @for(moduleImport <- module.getImports()) {
36                 @if(moduleImport != null && moduleImport.getModuleName() != "") {
37                     import @{moduleImport.getModuleName()} { prefix "@{moduleImport.getPrefix()}"; revision-date @{SimpleDateFormatUtil.getRevisionFormat().format(moduleImport.getRevision())}; }
38                 }
39             }
40         }
41         @if(module.getRevision() != null) {
42             @for(effectiveStatement <- module.asInstanceOf[EffectiveStatement[_, _]].effectiveSubstatements()){
43                 @if(effectiveStatement.getDeclared().isInstanceOf[RevisionStatement]){
44                     @if(effectiveStatement.asInstanceOf[DocumentedNode].getDescription() == null || effectiveStatement.asInstanceOf[DocumentedNode].getDescription().isEmpty()){
45                         revision @{SimpleDateFormatUtil.getRevisionFormat().format(module.getRevision())};
46                     } else {
47                         revision @{SimpleDateFormatUtil.getRevisionFormat().format(module.getRevision())} {
48                             description "@{effectiveStatement.asInstanceOf[DocumentedNode].getDescription()}";
49                         }
50                     }
51                 }
52             }
53         }
54         @if(module.getTypeDefinitions() != null && !module.getTypeDefinitions().isEmpty()){
55             @yangTemplateWriteTypeDefs(module.getTypeDefinitions())
56         }
57         @if(module.getChildNodes() != null) {
58             @yangTemplateWriteDataSchemaNodes(module.getChildNodes(), module)
59         }
60         @if(module.getGroupings() != null && !module.getGroupings().isEmpty()) {
61             @yangTemplateWriteGroupingDefs(module.getGroupings(), module)
62         }
63         @if(module.getAugmentations() != null && !module.getAugmentations().isEmpty()) {
64             @yangTemplateWriteAugments(module.getAugmentations(), module)
65         }
66         @if(module.getDeviations() != null && !module.getDeviations().isEmpty()) {
67             @yangTemplateWriteDeviations(module.getDeviations())
68         }
69         @if(module.getExtensionSchemaNodes() != null && !module.getExtensionSchemaNodes().isEmpty()) {
70             @for(extension <- module.getExtensionSchemaNodes()) {
71                 @if(extension != null) {
72                     @yangTemplateWriteExtension(extension)
73                 }
74             }
75         }
76         @if(module.getFeatures() != null && !module.getFeatures().isEmpty()) {
77             @for(feature <- module.getFeatures()) {
78                 @if(feature != null) {
79                     @yangTemplateWriteFeature(feature)
80                 }
81             }
82         }
83         @if(module.getIdentities() != null && !module.getIdentities().isEmpty()) {
84             @for(identity <- module.getIdentities()) {
85                 @if(identity != null) {
86                     @yangTemplateWriteIdentity(identity)
87                 }
88             }
89         }
90         @if(module.getNotifications() != null && !module.getNotifications().isEmpty()) {
91             @for(notification <- module.getNotifications()) {
92                 @if(notification != null) {
93                     @yangTemplateWriteNotification(notification, module)
94                 }
95             }
96         }
97         @if(module.getRpcs() != null && !module.getRpcs().isEmpty()) {
98             @for(rpc <- module.getRpcs()) {
99                 @if(rpc != null) {
100                     @yangTemplateWriteRPC(rpc, module)
101                 }
102             }
103         }
104         @if(module.getUnknownSchemaNodes() != null && !module.getUnknownSchemaNodes().isEmpty()) {
105             @yangTemplateWriteUnknownSchemaNodes(module.getUnknownSchemaNodes(), module)
106         }
107         @if(module.getUses() != null && !module.getUses().isEmpty()) {
108             @yangTemplateWriteUsesNodes(module.getUses(), module)
109         }
110     }
111 }