+++ /dev/null
-@*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *@
-
-@import java.util.function.Function;
-@import java.util.Optional
-@import org.opendaylight.mdsal.binding.javav2.generator.util.JavaIdentifier.CLASS
-@import org.opendaylight.mdsal.binding.javav2.generator.util.JavaIdentifierNormalizer.normalizeSpecificIdentifier
-@import org.opendaylight.mdsal.binding.javav2.generator.util.JavaIdentifierNormalizer.normalizeFullPackageName
-@import org.opendaylight.mdsal.binding.javav2.java.api.generator.util.TextTemplateUtil.getSourcePath
-@import org.opendaylight.mdsal.binding.javav2.java.api.generator.renderers.YangModuleInfoTemplateRenderer.getSortedQName
-@import org.opendaylight.mdsal.binding.javav2.util.BindingMapping.getRootPackageName
-@import org.opendaylight.mdsal.binding.javav2.util.BindingMapping.MODULE_INFO_CLASS_NAME
-@import org.opendaylight.yangtools.yang.model.api.Module
-@import org.opendaylight.yangtools.yang.model.api.SchemaContext
-
-@(module: Module, ctx: SchemaContext, importedNames: Map[String, String],
-moduleFilePathResolver: Function[Module, Optional[String]])
-@if(module != null && ctx != null) {
-public final class @{MODULE_INFO_CLASS_NAME} implements @{importedNames.get("yangModuleInfo")} {
-
- private static final @{importedNames.get("yangModuleInfo")} INSTANCE = new @{MODULE_INFO_CLASS_NAME}();
-
- private final @{importedNames.get("string")} name = "@{module.getName}";
- private final @{importedNames.get("string")} namespace = "@{module.getNamespace.toString}";
- private final @{importedNames.get("string")} semanticVersion = "@{module.getSemanticVersion}";
- private final @{importedNames.get("string")} revision = @if(module.getRevision.isPresent) { "@{module.getRevision.get.toString}" } else { null };
- private final @{importedNames.get("string")} resourcePath = "@{getSourcePath(module, moduleFilePathResolver)}";
- private final @{importedNames.get("set")}<YangModuleInfo> importedModules;
-
- public static @{importedNames.get("yangModuleInfo")} getInstance() {
- return INSTANCE;
- }
-
- @{classBody(module, MODULE_INFO_CLASS_NAME)}
-}
-}
-
-@generateSubInfo(module: Module) = {
-@for(submodule <- module.getSubmodules) {
- private static final class @{normalizeSpecificIdentifier(submodule.getName, CLASS)}Info implements @{importedNames.get("yangModuleInfo")} {
-
- private static final @{importedNames.get("yangModuleInfo")} INSTANCE = new @{normalizeSpecificIdentifier(submodule.getName, CLASS)}Info();
-
- private final @{importedNames.get("string")} name = "@{submodule.getName}";
- private final @{importedNames.get("string")} semanticVersion = "@{submodule.getSemanticVersion}";
- private final @{importedNames.get("string")} namespace = "@{submodule.getNamespace.toString}";
- private final @{importedNames.get("string")} revision = @if(module.getRevision.isPresent) { "@{module.getRevision.get.toString}" } else { null };
- private final @{importedNames.get("string")} resourcePath = "@{getSourcePath(submodule, moduleFilePathResolver)}";
- private final @{importedNames.get("set")}<YangModuleInfo> importedModules;
-
- public static @{importedNames.get("yangModuleInfo")} getInstance() {
- return INSTANCE;
- }
-
- @{classBody(submodule, normalizeSpecificIdentifier(submodule.getName, CLASS) + "Info")}
- }
-}
-}
-
-@classBody(module: Module, className: String) = {
- private @{className}() {
- @if(!module.getImports.isEmpty || !module.getSubmodules.isEmpty) {
- @{importedNames.get("set")}<@{importedNames.get("yangModuleInfo")}> set = new @{importedNames.get("hashSet")}<>();
- }
- @if(!module.getImports.isEmpty) {
- @for(moduleImport <- module.getImports) {
- set.add(@{normalizeFullPackageName(getRootPackageName(ctx.findModule(moduleImport
- .getModuleName, moduleImport.getRevision).get))}.@{MODULE_INFO_CLASS_NAME}.getInstance());
- }
- }
- @if(!module.getSubmodules.isEmpty) {
- @for(submodule <- module.getSubmodules) {
- set.add(@{normalizeSpecificIdentifier(submodule.getName, CLASS)}Info.getInstance());
- }
- }
- @if(module.getImports.isEmpty && module.getSubmodules.isEmpty) {
- importedModules = @{importedNames.get("collections")}.emptySet();
- } else {
- importedModules = @{importedNames.get("immutableSet")}.copyOf(set);
- }
-
- @{importedNames.get("inputStream")} stream = @{MODULE_INFO_CLASS_NAME}.class.getResourceAsStream(resourcePath);
- if (stream == null) {
- throw new IllegalStateException("Resource '" + resourcePath + "' is missing");
- }
- try {
- stream.close();
- } catch (@{importedNames.get("iOException")} e) {
- // Resource leak, but there is nothing we can do
- }
- }
-
- @@Override
- public @{importedNames.get("string")} getName() {
- return name;
- }
-
- @@Override
- public @{importedNames.get("string")} getRevision() {
- return revision;
- }
-
- @@Override
- public @{importedNames.get("string")} getNamespace() {
- return namespace;
- }
-
- @@Override
- public @{importedNames.get("optional")}<@{importedNames.get("semVer")}> getSemanticVersion() {
- return Optional.of(@{importedNames.get("semVer")}.valueOf(semanticVersion));
- }
-
- @@Override
- public @{importedNames.get("schemaSourceRepresentation")} getModuleSourceRepresentation() {
- //TODO implement
- return null;
- }
-
- @@Override
- public @{importedNames.get("inputStream")} getModuleSourceStream() {
- @{importedNames.get("inputStream")} stream = @{MODULE_INFO_CLASS_NAME}.class.getResourceAsStream(resourcePath);
- if (stream == null) {
- throw new IllegalStateException("Resource '" + resourcePath + "' is missing");
- }
- return stream;
- }
-
- @@Override
- public @{importedNames.get("set")}<@{importedNames.get("yangModuleInfo")}> getImportedModules() {
- return importedModules;
- }
-
- @@Override
- public @{importedNames.get("string")} toString() {
- @{importedNames.get("stringBuilder")} sb = new @{importedNames.get("stringBuilder")}(this.getClass().getCanonicalName());
- sb.append("[");
- sb.append("name = " + name);
- sb.append(", namespace = " + namespace);
- sb.append(", semanticVersion = " + semanticVersion);
- sb.append(", revision = " + revision);
- sb.append(", resourcePath = " + resourcePath);
- sb.append(", imports = " + importedModules);
- sb.append("]");
- return sb.toString();
- }
-
- @{generateSubInfo(module)}
-}