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. *
15 * Note: we should introduce our own format instead of txt *
16 ***********************************************************@
18 @import org.opendaylight.mdsal.binding.javav2.generator.impl.util.YangTextTemplate
19 @import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil
20 @import org.opendaylight.yangtools.yang.model.api.Module
24 @generateYangSnippet(module)
27 @generateYangSnippet(module: Module) = {
28 module @{module.getName()} {
29 yang-version @module.getYangVersion();
30 namespace "@module.getNamespace().toString()";
31 prefix "@module.getPrefix()";
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()}"; }
40 @if(module.getRevision() != null) {
41 revision @{SimpleDateFormatUtil.getRevisionFormat().format(module.getRevision())} {
42 description "@{YangTextTemplate.formatToParagraph(module.getDescription(), 12)}";
45 @if(module.getChildNodes() != null) {
46 @yangTemplateWriteDataSchemaNodes(module.getChildNodes())
48 @if(module.getGroupings() != null && !module.getGroupings().isEmpty()) {
49 @yangTemplateWriteGroupingDefs(module.getGroupings())
51 @if(module.getAugmentations() != null && !module.getAugmentations().isEmpty()) {
52 @yangTemplateWriteAugments(module.getAugmentations())
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()}";
61 @for(deviation <- deviation.getDeviates()) {
62 @if(deviation != null && deviation.getDeviateType() != null ) {
63 deviation @{deviation.getDeviateType().name()};
70 @if(module.getExtensionSchemaNodes() != null && !module.getExtensionSchemaNodes().isEmpty()) {
71 @for(extension <- module.getExtensionSchemaNodes()) {
72 @if(extension != null) {
73 @yangTemplateWriteExtension(extension)
77 @if(module.getFeatures() != null && !module.getFeatures().isEmpty()) {
78 @for(feature <- module.getFeatures()) {
79 @if(feature != null) {
80 @yangTemplateWriteFeature(feature)
84 @if(module.getIdentities() != null && !module.getIdentities().isEmpty()) {
85 @for(identity <- module.getIdentities()) {
86 @if(identity != null) {
87 @yangTemplateWriteIdentity(identity)
91 @if(module.getNotifications() != null && !module.getNotifications().isEmpty()) {
92 @for(notification <- module.getNotifications()) {
93 @if(notification != null) {
94 @yangTemplateWriteNotification(notification)
98 @if(module.getRpcs() != null && !module.getRpcs().isEmpty()) {
99 @for(rpc <- module.getRpcs()) {
101 @yangTemplateWriteRPC(rpc)
105 @if(module.getUnknownSchemaNodes() != null && !module.getUnknownSchemaNodes().isEmpty()) {
106 @yangTemplateWriteUnknownSchemaNodes(module.getUnknownSchemaNodes())
108 @if(module.getUses() != null && !module.getUses().isEmpty()) {
109 @yangTemplateWriteUsesNodes(module.getUses())