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 @import org.opendaylight.mdsal.binding.javav2.generator.util.JavaIdentifier.CLASS
10 @import org.opendaylight.mdsal.binding.javav2.generator.util.JavaIdentifierNormalizer.normalizeSpecificIdentifier
11 @import org.opendaylight.mdsal.binding.javav2.generator.util.JavaIdentifierNormalizer.normalizeFullPackageName
12 @import org.opendaylight.mdsal.binding.javav2.java.api.generator.util.TextTemplateUtil.getSourcePath
13 @import org.opendaylight.mdsal.binding.javav2.java.api.generator.renderers.YangModuleInfoTemplateRenderer.getSortedQName
14 @import org.opendaylight.mdsal.binding.javav2.util.BindingMapping.getRootPackageName
15 @import org.opendaylight.mdsal.binding.javav2.util.BindingMapping.MODULE_INFO_CLASS_NAME
16 @import org.opendaylight.yangtools.yang.model.api.Module
17 @import org.opendaylight.yangtools.yang.model.api.SchemaContext
19 @(module: Module, ctx: SchemaContext, importedNames: Map[String, String])
20 @if(module != null && ctx != null) {
21 public final class @{MODULE_INFO_CLASS_NAME} implements @{importedNames.get("yangModuleInfo")} {
23 private static final @{importedNames.get("yangModuleInfo")} INSTANCE = new @{MODULE_INFO_CLASS_NAME}();
25 private final @{importedNames.get("string")} name = "@{module.getName}";
26 private final @{importedNames.get("string")} namespace = "@{module.getNamespace.toString}";
27 private final @{importedNames.get("string")} semanticVersion = "@{module.getSemanticVersion}";
28 private final @{importedNames.get("string")} revision = "@{module.getQNameModule.getFormattedRevision}";
29 private final @{importedNames.get("string")} resourcePath = "@{getSourcePath(module)}";
30 private final @{importedNames.get("set")}<YangModuleInfo> importedModules;
32 public static @{importedNames.get("yangModuleInfo")} getInstance() {
36 @{classBody(module, MODULE_INFO_CLASS_NAME)}
40 @generateSubInfo(module: Module) = {
41 @for(submodule <- module.getSubmodules) {
42 private static final class @{normalizeSpecificIdentifier(submodule.getName, CLASS)}Info implements @{importedNames.get("yangModuleInfo")} {
44 private static final @{importedNames.get("yangModuleInfo")} INSTANCE = new @{normalizeSpecificIdentifier(submodule.getName, CLASS)}Info();
46 private final @{importedNames.get("string")} name = "@{submodule.getName}";
47 private final @{importedNames.get("string")} semanticVersion = "@{submodule.getSemanticVersion}";
48 private final @{importedNames.get("string")} namespace = "@{submodule.getNamespace.toString}";
49 private final @{importedNames.get("string")} revision = "@{submodule.getQNameModule.getFormattedRevision}";
50 private final @{importedNames.get("string")} resourcePath = "@{getSourcePath(submodule)}";
51 private final @{importedNames.get("set")}<YangModuleInfo> importedModules;
53 public static @{importedNames.get("yangModuleInfo")} getInstance() {
57 @{classBody(submodule, normalizeSpecificIdentifier(submodule.getName, CLASS) + "Info")}
62 @classBody(module: Module, className: String) = {
63 private @{className}() {
64 @if(!module.getImports.isEmpty || !module.getSubmodules.isEmpty) {
65 @{importedNames.get("set")}<@{importedNames.get("yangModuleInfo")}> set = new @{importedNames.get("hashSet")}<>();
67 @if(!module.getImports.isEmpty) {
68 @for(moduleImport <- module.getImports) {
69 @if(moduleImport.getRevision == null) {
70 set.add(@{normalizeFullPackageName(getRootPackageName(getSortedQName(ctx.getModules, moduleImport
71 .getModuleName)))}.@{MODULE_INFO_CLASS_NAME}.getInstance());
73 set.add(@{normalizeFullPackageName(getRootPackageName(ctx.findModuleByName(moduleImport
74 .getModuleName, moduleImport.getRevision)))}.@{MODULE_INFO_CLASS_NAME}.getInstance());
78 @if(!module.getSubmodules.isEmpty) {
79 @for(submodule <- module.getSubmodules) {
80 set.add(@{normalizeSpecificIdentifier(submodule.getName, CLASS)}Info.getInstance());
83 @if(module.getImports.isEmpty && module.getSubmodules.isEmpty) {
84 importedModules = @{importedNames.get("collections")}.emptySet();
86 importedModules = @{importedNames.get("immutableSet")}.copyOf(set);
89 @{importedNames.get("inputStream")} stream = @{MODULE_INFO_CLASS_NAME}.class.getResourceAsStream(resourcePath);
91 throw new IllegalStateException("Resource '" + resourcePath + "' is missing");
95 } catch (@{importedNames.get("iOException")} e) {
96 // Resource leak, but there is nothing we can do
101 public @{importedNames.get("string")} getName() {
106 public @{importedNames.get("string")} getRevision() {
111 public @{importedNames.get("string")} getNamespace() {
116 public @{importedNames.get("optional")}<@{importedNames.get("semVer")}> getSemanticVersion() {
117 return Optional.of(@{importedNames.get("semVer")}.valueOf(semanticVersion));
121 public @{importedNames.get("schemaSourceRepresentation")} getModuleSourceRepresentation() {
127 public @{importedNames.get("inputStream")} getModuleSourceStream() {
128 @{importedNames.get("inputStream")} stream = @{MODULE_INFO_CLASS_NAME}.class.getResourceAsStream(resourcePath);
129 if (stream == null) {
130 throw new IllegalStateException("Resource '" + resourcePath + "' is missing");
136 public @{importedNames.get("set")}<@{importedNames.get("yangModuleInfo")}> getImportedModules() {
137 return importedModules;
141 public @{importedNames.get("string")} toString() {
142 @{importedNames.get("stringBuilder")} sb = new @{importedNames.get("stringBuilder")}(this.getClass().getCanonicalName());
144 sb.append("name = " + name);
145 sb.append(", namespace = " + namespace);
146 sb.append(", semanticVersion = " + semanticVersion);
147 sb.append(", revision = " + revision);
148 sb.append(", resourcePath = " + resourcePath);
149 sb.append(", imports = " + importedModules);
151 return sb.toString();
154 @{generateSubInfo(module)}