import java.io.IOException
import java.io.OutputStreamWriter
import java.nio.charset.StandardCharsets
+import java.nio.file.Files
import java.util.ArrayList
import java.util.Collection
import java.util.HashMap
import org.opendaylight.yangtools.yang.model.api.UsesNode
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute
-import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition
-import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition
-import org.opendaylight.yangtools.yang.model.api.type.Int8TypeDefinition
-import org.opendaylight.yangtools.yang.model.api.type.Int16TypeDefinition
-import org.opendaylight.yangtools.yang.model.api.type.Int32TypeDefinition
-import org.opendaylight.yangtools.yang.model.api.type.Int64TypeDefinition
import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint
+import org.opendaylight.yangtools.yang.model.api.type.LengthRestrictedTypeDefinition
import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint
-import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition
-import org.opendaylight.yangtools.yang.model.api.type.Uint8TypeDefinition
-import org.opendaylight.yangtools.yang.model.api.type.Uint16TypeDefinition
-import org.opendaylight.yangtools.yang.model.api.type.Uint32TypeDefinition
-import org.opendaylight.yangtools.yang.model.api.type.Uint64TypeDefinition
+import org.opendaylight.yangtools.yang.model.api.type.RangeRestrictedTypeDefinition
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.sonatype.plexus.build.incremental.BuildContext
def generate(BuildContext buildContext, EffectiveModelContext context, File targetPath, Set<Module> modulesToGen)
throws IOException {
path = targetPath;
- path.mkdirs();
+ Files.createDirectories(path.getParentFile().toPath())
val it = new HashSet;
for (module : modulesToGen) {
add(generateDocumentation(buildContext, module, context));
val destination = new File(path, '''«module.name».html''')
this.ctx = ctx;
module.imports.forEach[importModule | this.imports.put(importModule.prefix, importModule.moduleName)]
+ var OutputStreamWriter fw
+ var BufferedWriter bw
try {
- val fw = new OutputStreamWriter(buildContext.newFileOutputStream(destination), StandardCharsets.UTF_8)
- val bw = new BufferedWriter(fw)
+ fw = new OutputStreamWriter(buildContext.newFileOutputStream(destination), StandardCharsets.UTF_8)
+ bw = new BufferedWriter(fw)
currentModule = module;
bw.append(generate(module, ctx));
- bw.close();
- fw.close();
} catch (IOException e) {
LOG.error("Failed to emit file {}", destination, e);
+ } finally {
+ if (bw !== null) {
+ bw.close();
+ }
+ if (fw !== null) {
+ fw.close();
+ }
}
return destination;
}
for (QName pathElement : path.nodeIdentifiers) {
val module = ctx.findModule(pathElement.module)
if (module.isPresent) {
- var foundNode = module.get.getDataChildByName(pathElement)
+ var foundNode = module.get.dataChildByName(pathElement)
if (foundNode === null) {
val child = nodes.last
if (child instanceof DataNodeContainer) {
«module.childNodes.treeSet(YangInstanceIdentifier.builder.build())»
'''
- private def dispatch CharSequence tree(ChoiceSchemaNode node,YangInstanceIdentifier path) '''
+ private def CharSequence tree(ChoiceSchemaNode node, YangInstanceIdentifier path) '''
«node.nodeName» (choice)
«casesTree(node.cases, path)»
'''
</ul>
'''
- private def dispatch CharSequence tree(DataSchemaNode node,YangInstanceIdentifier path) '''
- «node.nodeName»
- '''
+ private def CharSequence tree(DataSchemaNode node, YangInstanceIdentifier path) {
+ if (node instanceof ChoiceSchemaNode) {
+ return tree(node, path)
+ } else if (node instanceof ListSchemaNode) {
+ return tree(node, path)
+ } else if (node instanceof ContainerSchemaNode) {
+ return tree(node, path)
+ }
+ return node.nodeName
+ }
- private def dispatch CharSequence tree(ListSchemaNode node,YangInstanceIdentifier path) '''
+ private def CharSequence tree(ListSchemaNode node, YangInstanceIdentifier path) '''
«val newPath = path.append(node)»
«localLink(newPath,node.nodeName)»
«node.childNodes.treeSet(newPath)»
'''
- private def dispatch CharSequence tree(ContainerSchemaNode node,YangInstanceIdentifier path) '''
+ private def CharSequence tree(ContainerSchemaNode node,YangInstanceIdentifier path) '''
«val newPath = path.append(node)»
«localLink(newPath,node.nodeName)»
«node.childNodes.treeSet(newPath)»
} else if(node instanceof LeafListSchemaNode) {
return '''
«printInfo(node, "leaf-list")»
- «listItem("type", node.type?.QName.localName)»
+ «IF node.type !== null»
+ «listItem("type", node.type.QName.localName)»
+ «ENDIF»
</ul>
'''
} else if(node instanceof ListSchemaNode) {
'''
- private def dispatch CharSequence asXmlExampleTag(LeafSchemaNode node, YangInstanceIdentifier identifier) '''
- «node.QName.xmlExampleTag("...")»
- '''
-
- private def dispatch CharSequence asXmlExampleTag(LeafListSchemaNode node, YangInstanceIdentifier identifier) '''
- <!-- This node could appear multiple times -->
- «node.QName.xmlExampleTag("...")»
- '''
-
- private def dispatch CharSequence asXmlExampleTag(ContainerSchemaNode node, YangInstanceIdentifier identifier) '''
- <!-- See «localLink(identifier.append(node),"definition")» for child nodes. -->
- «node.QName.xmlExampleTag("...")»
- '''
-
-
- private def dispatch CharSequence asXmlExampleTag(ListSchemaNode node, YangInstanceIdentifier identifier) '''
- <!-- See «localLink(identifier.append(node),"definition")» for child nodes. -->
- <!-- This node could appear multiple times -->
- «node.QName.xmlExampleTag("...")»
- '''
-
-
- private def dispatch CharSequence asXmlExampleTag(DataSchemaNode node, YangInstanceIdentifier identifier) '''
- <!-- noop -->
- '''
-
+ private def CharSequence asXmlExampleTag(DataSchemaNode node, YangInstanceIdentifier identifier) {
+ if (node instanceof LeafSchemaNode) {
+ return '''«node.QName.xmlExampleTag("...")»'''
+ }
+ if (node instanceof LeafListSchemaNode) {
+ return '''
+ <!-- This node could appear multiple times -->
+ «node.QName.xmlExampleTag("...")»
+ '''
+ }
+ if (node instanceof ContainerSchemaNode) {
+ return '''
+ <!-- See «localLink(identifier.append(node),"definition")» for child nodes. -->
+ «node.QName.xmlExampleTag("...")»
+ '''
+ }
+ if (node instanceof ListSchemaNode) {
+ return '''
+ <!-- See «localLink(identifier.append(node),"definition")» for child nodes. -->
+ <!-- This node could appear multiple times -->
+ «node.QName.xmlExampleTag("...")»
+ '''
+ }
+ return "<!-- noop -->"
+ }
def xmlExampleTag(QName name, CharSequence data) {
return '''<«name.localName» xmlns="«name.namespace»">«data»</«name.localName»>'''
</h«level»>
'''
-
-
- private def dispatch CharSequence printInfo(DataSchemaNode node, int level, YangInstanceIdentifier path) '''
- «header(level+1,node.QName)»
- '''
-
- private def dispatch CharSequence printInfo(ContainerSchemaNode node, int level, YangInstanceIdentifier path) '''
+ private def CharSequence printInfo(ContainerSchemaNode node, int level, YangInstanceIdentifier path) '''
«val newPath = path.append(node)»
«header(level,newPath)»
<dl>
«node.childNodes.printChildren(level,newPath)»
'''
- private def dispatch CharSequence printInfo(ListSchemaNode node, int level, YangInstanceIdentifier path) '''
+ private def CharSequence printInfo(ListSchemaNode node, int level, YangInstanceIdentifier path) '''
«val newPath = path.append(node)»
«header(level,newPath)»
<dl>
«node.childNodes.printChildren(level,newPath)»
'''
- private def dispatch CharSequence printInfo(ChoiceSchemaNode node, int level, YangInstanceIdentifier path) '''
+ private def CharSequence printInfo(ChoiceSchemaNode node, int level, YangInstanceIdentifier path) '''
«val Set<DataSchemaNode> choiceCases = new HashSet(node.cases)»
«choiceCases.printChildren(level, path)»
'''
- private def dispatch CharSequence printInfo(CaseSchemaNode node, int level, YangInstanceIdentifier path) '''
+ private def CharSequence printInfo(CaseSchemaNode node, int level, YangInstanceIdentifier path) '''
«node.childNodes.printChildren(level, path)»
'''
for (name : path) {
if (parent instanceof DataNodeContainer) {
- var SchemaNode node = parent.getDataChildByName(name)
+ var SchemaNode node = parent.dataChildByName(name)
if (node === null && (parent instanceof Module)) {
val notifications = (parent as Module).notifications;
for (notification : notifications) {
</ul>
'''
- private def dispatch CharSequence tree(Void obj, YangInstanceIdentifier path) '''
- '''
-
-
/* #################### RESTRICTIONS #################### */
private def restrictions(TypeDefinition<?> type) '''
«type.toRange»
'''
- private def dispatch toLength(TypeDefinition<?> type) {
- }
-
- private def dispatch toLength(BinaryTypeDefinition type) '''
- «type.lengthConstraint.toLengthStmt»
- '''
-
- private def dispatch toLength(StringTypeDefinition type) '''
- «type.lengthConstraint.toLengthStmt»
- '''
-
- private def dispatch toRange(TypeDefinition<?> type) {
- }
-
- private def dispatch toRange(DecimalTypeDefinition type) '''
- «type.rangeConstraint.toRangeStmt»
- '''
-
- private def dispatch toRange(Int8TypeDefinition type) '''
- «type.rangeConstraint.toRangeStmt»
- '''
-
- private def dispatch toRange(Int16TypeDefinition type) '''
- «type.rangeConstraint.toRangeStmt»
- '''
-
- private def dispatch toRange(Int32TypeDefinition type) '''
- «type.rangeConstraint.toRangeStmt»
- '''
-
- private def dispatch toRange(Int64TypeDefinition type) '''
- «type.rangeConstraint.toRangeStmt»
- '''
-
- private def dispatch toRange(Uint8TypeDefinition type) '''
- «type.rangeConstraint.toRangeStmt»
- '''
-
- private def dispatch toRange(Uint16TypeDefinition type) '''
- «type.rangeConstraint.toRangeStmt»
- '''
-
- private def dispatch toRange(Uint32TypeDefinition type) '''
- «type.rangeConstraint.toRangeStmt»
+ private def toLength(TypeDefinition<?> type) '''
+ «IF type instanceof LengthRestrictedTypeDefinition»
+ «type.lengthConstraint.toLengthStmt»
+ «ENDIF»
'''
- private def dispatch toRange(Uint64TypeDefinition type) '''
- «type.rangeConstraint.toRangeStmt»
+ private def toRange(TypeDefinition<?> type) '''
+ «IF type instanceof RangeRestrictedTypeDefinition»
+ «type.rangeConstraint.toRangeStmt»
+ «ENDIF»
'''
def toLengthStmt(Optional<LengthConstraint> lengths) '''
return result.toString
}
- private def dispatch addedByInfo(SchemaNode node) '''
- '''
+ private def addedByInfo(SchemaNode node) {
+ if (node instanceof DataSchemaNode) {
+ return addedByInfo(node)
+ }
+ return ""
+ }
- private def dispatch addedByInfo(DataSchemaNode node) '''
+ private def addedByInfo(DataSchemaNode node) '''
«IF node.augmenting»(A)«ENDIF»«IF node.addedByUses»(U)«ENDIF»
'''
- private def dispatch isAddedBy(SchemaNode node) {
+ private def isAddedBy(SchemaNode node) {
+ if (node instanceof DataSchemaNode) {
+ return node.augmenting || node.addedByUses
+ }
return false
}
- private def dispatch isAddedBy(DataSchemaNode node) {
- return node.augmenting || node.addedByUses
+ private def nodeName(SchemaNode node) {
+ if (node instanceof ContainerSchemaNode) {
+ return nodeName(node);
+ } else if (node instanceof ListSchemaNode) {
+ return nodeName(node);
+ }
+ val addedByInfo = node.addedByInfo
+ if (node.isAddedBy) {
+ return '''«italic(node.QName.localName)»«addedByInfo»'''
+ }
+ return '''«node.QName.localName»«addedByInfo»'''
}
- private def dispatch nodeName(SchemaNode node) '''
- «IF node.isAddedBy»
- «italic(node.QName.localName)»«node.addedByInfo»
- «ELSE»
- «node.QName.localName»«node.addedByInfo»
- «ENDIF»
- '''
-
- private def dispatch nodeName(ContainerSchemaNode node) '''
+ private def nodeName(ContainerSchemaNode node) '''
«IF node.isAddedBy»
«strong(italic(node.QName.localName))»«node.addedByInfo»
«ELSE»
«ENDIF»
'''
- private def dispatch nodeName(ListSchemaNode node) '''
+ private def nodeName(ListSchemaNode node) '''
«IF node.isAddedBy»
«strong(italic(node.QName.localName))» «IF node.keyDefinition !== null && !node.keyDefinition.empty»«node.listKeys»«ENDIF»«node.addedByInfo»
«ELSE»