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.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
25 @generateYangSnippet(module)
28 @generateYangSnippet(module: Module) = {
29 module @{module.getName()} {
30 yang-version @module.getYangVersion();
31 namespace "@module.getNamespace().toString()";
32 prefix "@module.getPrefix()";
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())}; }
41 @if(module.getRevision() != null) {
42 revision @{SimpleDateFormatUtil.getRevisionFormat().format(module.getRevision())} {
43 @for(effectiveStatement <- module.asInstanceOf[EffectiveStatement[_, _]].effectiveSubstatements()){
44 @if(effectiveStatement.getDeclared().isInstanceOf[RevisionStatement]){
45 description "@{effectiveStatement.asInstanceOf[DocumentedNode].getDescription()}";
50 @if(module.getTypeDefinitions() != null && !module.getTypeDefinitions().isEmpty()){
51 @yangTemplateWriteTypeDefs(module.getTypeDefinitions())
53 @if(module.getChildNodes() != null) {
54 @yangTemplateWriteDataSchemaNodes(module.getChildNodes(), module)
56 @if(module.getGroupings() != null && !module.getGroupings().isEmpty()) {
57 @yangTemplateWriteGroupingDefs(module.getGroupings(), module)
59 @if(module.getAugmentations() != null && !module.getAugmentations().isEmpty()) {
60 @yangTemplateWriteAugments(module.getAugmentations(), module)
62 @if(module.getDeviations() != null && !module.getDeviations().isEmpty()) {
63 @yangTemplateWriteDeviations(module.getDeviations())
65 @if(module.getExtensionSchemaNodes() != null && !module.getExtensionSchemaNodes().isEmpty()) {
66 @for(extension <- module.getExtensionSchemaNodes()) {
67 @if(extension != null) {
68 @yangTemplateWriteExtension(extension)
72 @if(module.getFeatures() != null && !module.getFeatures().isEmpty()) {
73 @for(feature <- module.getFeatures()) {
74 @if(feature != null) {
75 @yangTemplateWriteFeature(feature)
79 @if(module.getIdentities() != null && !module.getIdentities().isEmpty()) {
80 @for(identity <- module.getIdentities()) {
81 @if(identity != null) {
82 @yangTemplateWriteIdentity(identity)
86 @if(module.getNotifications() != null && !module.getNotifications().isEmpty()) {
87 @for(notification <- module.getNotifications()) {
88 @if(notification != null) {
89 @yangTemplateWriteNotification(notification, module)
93 @if(module.getRpcs() != null && !module.getRpcs().isEmpty()) {
94 @for(rpc <- module.getRpcs()) {
96 @yangTemplateWriteRPC(rpc, module)
100 @if(module.getUnknownSchemaNodes() != null && !module.getUnknownSchemaNodes().isEmpty()) {
101 @yangTemplateWriteUnknownSchemaNodes(module.getUnknownSchemaNodes(), module)
103 @if(module.getUses() != null && !module.getUses().isEmpty()) {
104 @yangTemplateWriteUsesNodes(module.getUses(), module)