var Module currentModule;
val Map<String, String> imports = new HashMap();
var SchemaContext ctx;
+
+ StringBuilder augmentChildNodesAsString
+
+ DataSchemaNode lastNodeInTargetPath = null
def generate(SchemaContext context, File targetPath, Set<Module> modulesToGen) throws IOException {
path = targetPath;
}
return '''
<h2>Augmentations</h2>
-
+
<ul>
«FOR augment : module.augmentations»
<li>
<h3 id="«schemaPathToString(module, augment.targetPath, context, augment)»">
Target [«typeAnchorLink(augment.targetPath,schemaPathToString(module, augment.targetPath, context, augment))»]</h3>
«augment.description»
+ Status: «strong(String.valueOf(augment.status))»
«IF augment.reference !== null»
Reference «augment.reference»
«ENDIF»
«FOR childNode : augment.childNodes»
«childNode.printSchemaNodeInfo»
«ENDFOR»
+
+ <h3>Example</h3>
+ «createAugmentChildNodesAsString(new ArrayList(augment.childNodes))»
+ «printNodeChildren(parseTargetPath(augment.targetPath))»
</li>
«ENDFOR»
</ul>
'''
}
+
+ private def createAugmentChildNodesAsString(List<DataSchemaNode> childNodes) {
+ augmentChildNodesAsString = new StringBuilder();
+ augmentChildNodesAsString.append(printNodeChildren(childNodes))
+ return ''
+ }
+
+ private def parseTargetPath(SchemaPath path) {
+ val List<DataSchemaNode> nodes = new ArrayList<DataSchemaNode>();
+ for (QName pathElement : path.pathFromRoot) {
+ val prefix = pathElement.prefix
+ val moduleName = imports.get(prefix)
+ if(moduleName != null) {
+ val revision = pathElement.revision
+ val module = ctx.findModuleByName(moduleName, revision)
+ var foundNode = module.getDataChildByName(pathElement)
+ if(foundNode == null) {
+ val child = nodes.last
+ if (child instanceof DataNodeContainer) {
+ val dataContNode = child as DataNodeContainer
+ foundNode = findNodeInChildNodes(pathElement, dataContNode.childNodes)
+ }
+ }
+ if(foundNode != null) {
+ nodes.add(foundNode);
+ }
+ }
+ }
+ if(! nodes.empty) {
+ lastNodeInTargetPath = nodes.get(nodes.size() - 1)
+ }
+
+ val List<DataSchemaNode> targetPathNodes = new ArrayList<DataSchemaNode>();
+ targetPathNodes.add(lastNodeInTargetPath)
+
+ return targetPathNodes
+ }
+
+ private def DataSchemaNode findNodeInChildNodes(QName findingNode, Set<DataSchemaNode> childNodes) {
+ for(child : childNodes) {
+ if (child.QName.equals(findingNode))
+ return child;
+ }
+ // find recursively
+ for(child : childNodes) {
+ if(child instanceof ContainerSchemaNode) {
+ val contChild = child as ContainerSchemaNode
+ val foundChild = findNodeInChildNodes(findingNode, contChild.childNodes)
+ if (foundChild != null)
+ return foundChild;
+ }
+ else if(child instanceof ListSchemaNode) {
+ val listChild = child as ListSchemaNode
+ val foundChild = findNodeInChildNodes(findingNode, listChild.childNodes)
+ if (foundChild != null)
+ return foundChild;
+ }
+ }
+ }
+
+ private def printNodeChildren(List<DataSchemaNode> childNodes) {
+ if (childNodes.empty) {
+ return ''
+ }
+
+ return
+ '''
+ <pre>
+ «printAugmentedNode(childNodes.get(0))»
+ </pre>
+ '''
+ }
+
+ private def printAugmentedNode(DataSchemaNode child) {
+
+ if(child instanceof ChoiceCaseNode)
+ return ''
+
+ return
+ '''
+ «IF child instanceof ContainerSchemaNode»
+ «printContainerNode(child as ContainerSchemaNode)»
+ «ENDIF»
+ «IF child instanceof AnyXmlSchemaNode»
+ «printAnyXmlNode(child as AnyXmlSchemaNode)»
+ «ENDIF»
+ «IF child instanceof LeafSchemaNode»
+ «printLeafNode(child as LeafSchemaNode)»
+ «ENDIF»
+ «IF child instanceof LeafListSchemaNode»
+ «printLeafListNode(child as LeafListSchemaNode)»
+ «ENDIF»
+ «IF child instanceof ListSchemaNode»
+ «printListNode(child as ListSchemaNode)»
+ «ENDIF»
+ «IF child instanceof ChoiceNode»
+ «printChoiceNode(child as ChoiceNode)»
+ «ENDIF»
+ '''
+ }
+
+ private def printChoiceNode(ChoiceNode child) {
+ val List<ChoiceCaseNode> cases = new ArrayList(child.cases);
+ if(!cases.empty) {
+ val ChoiceCaseNode aCase = cases.get(0)
+ for(caseChildNode : aCase.childNodes)
+ printAugmentedNode(caseChildNode)
+ }
+ }
+
+ private def printListNode(ListSchemaNode listNode) {
+ return
+ '''
+ <«listNode.QName.localName»«IF !listNode.QName.namespace.equals(currentModule.namespace)» xmlns="«listNode.QName.namespace»"«ENDIF»>
+ «FOR child : listNode.childNodes»
+ «printAugmentedNode(child)»
+ «ENDFOR»
+ </«listNode.QName.localName»>
+ '''
+ }
+
+ private def printContainerNode(ContainerSchemaNode containerNode) {
+ return
+ '''
+ <«containerNode.QName.localName»«IF !containerNode.QName.namespace.equals(currentModule.namespace)» xmlns="«containerNode.QName.namespace»"«ENDIF»>
+ «FOR child : containerNode.childNodes»
+ «printAugmentedNode(child)»
+ «ENDFOR»
+ </«containerNode.QName.localName»>
+ '''
+ }
+
+ private def printLeafListNode(LeafListSchemaNode leafListNode) {
+ return
+ '''
+ <«leafListNode.QName.localName»>. . .</«leafListNode.QName.localName»>
+ <«leafListNode.QName.localName»>. . .</«leafListNode.QName.localName»>
+ <«leafListNode.QName.localName»>. . .</«leafListNode.QName.localName»>
+ '''
+ }
+
+ private def printAnyXmlNode(AnyXmlSchemaNode anyXmlNode) {
+ return
+ '''
+ <«anyXmlNode.QName.localName»>. . .</«anyXmlNode.QName.localName»>
+ '''
+ }
+
+ private def printLeafNode(LeafSchemaNode leafNode) {
+ return
+ '''
+ <«leafNode.QName.localName»>. . .</«leafNode.QName.localName»>
+ '''
+ }
private def augmentationsSummary(Module module, SchemaContext context) {
if (module.augmentations.empty) {
«ENDFOR»
</ul>
<ul>
- «val Set<TypeDefinition<?>> typedefs = dataNode.typeDefinitions»
- «FOR typeDef : typedefs»
+ «FOR typeDef : dataNode.typeDefinitions»
«typeDef.restrictions»
«ENDFOR»
</ul>
def CharSequence printShortInfo(ContainerSchemaNode node, int level, InstanceIdentifier path) {
val newPath = path.append(node);
return '''
- <li>«strong(localLink(newPath,node.QName.localName))» (container)</li>
+ <li>«strong(localLink(newPath,node.QName.localName))» (container)
+ <ul>
+ <li>configuration data: «strong(String.valueOf(node.configuration))»</li>
+ </ul>
+ </li>
'''
}
def CharSequence printShortInfo(ListSchemaNode node, int level, InstanceIdentifier path) {
val newPath = path.append(node);
return '''
- <li>«strong(localLink(newPath,node.QName.localName))» (list)</li>
+ <li>«strong(localLink(newPath,node.QName.localName))» (list)
+ <ul>
+ <li>configuration data: «strong(String.valueOf(node.configuration))»</li>
+ </ul>
+ </li>
'''
}
def CharSequence printShortInfo(AnyXmlSchemaNode node, int level, InstanceIdentifier path) {
return '''
- <li>«strong((node.QName.localName))» (anyxml)</li>
+ <li>«strong((node.QName.localName))» (anyxml)
+ <ul>
+ <li>configuration data: «strong(String.valueOf(node.configuration))»</li>
+ <li>mandatory: «strong(String.valueOf(node.constraints.mandatory))»</li>
+ </ul>
+ </li>
'''
}
def CharSequence printShortInfo(LeafSchemaNode node, int level, InstanceIdentifier path) {
return '''
- <li>«strong((node.QName.localName))» (leaf)</li>
+ <li>«strong((node.QName.localName))» (leaf)
+ <ul>
+ <li>configuration data: «strong(String.valueOf(node.configuration))»</li>
+ <li>mandatory: «strong(String.valueOf(node.constraints.mandatory))»</li>
+ </ul>
+ </li>
'''
}
def CharSequence printShortInfo(LeafListSchemaNode node, int level, InstanceIdentifier path) {
return '''
- <li>«strong((node.QName.localName))» (leaf-list)</li>
+ <li>«strong((node.QName.localName))» (leaf-list)
+ <ul>
+ <li>configuration data: «strong(String.valueOf(node.configuration))»</li>
+ </ul>
+ </li>
'''
}
«ENDIF»
'''
-}
+}
\ No newline at end of file