private JSONObject processChoiceNode(final ChoiceSchemaNode choiceNode, final String moduleName, final JSONObject models, final SchemaContext schemaContext) throws JSONException, IOException { Set<ChoiceCaseNode> cases = choiceNode.getCases(); JSONArray choiceProps = new JSONArray(); for (ChoiceCaseNode choiceCase : cases) { String choiceName = choiceCase.getQName().getLocalName(); JSONObject choiceProp = processChildren(choiceCase.getChildNodes(), choiceCase.getQName(), moduleName, models, schemaContext); JSONObject choiceObj = new JSONObject(); choiceObj.put(choiceName, choiceProp); choiceObj.put(TYPE_KEY, OBJECT_TYPE); choiceProps.put(choiceObj); } JSONObject oneOfProps = new JSONObject(); oneOfProps.put(ONE_OF_KEY, choiceProps); oneOfProps.put(TYPE_KEY, OBJECT_TYPE); return oneOfProps; }
/** * Since each case statement within a module must provide unique child nodes, it is allowed to wrap * the actual configuration with a container node with name equal to case name. * * @param choiceCaseNode state or configuration case statement * @return either choiceCaseNode or its only child container */ private static <HAS_CHILDREN_AND_QNAME extends DataNodeContainer & SchemaNode> HAS_CHILDREN_AND_QNAME getDataNodeContainer(final ChoiceCaseNode choiceCaseNode) { Collection<DataSchemaNode> childNodes = choiceCaseNode.getChildNodes(); if (childNodes.size() == 1) { DataSchemaNode onlyChild = childNodes.iterator().next(); if (onlyChild instanceof ContainerSchemaNode) { ContainerSchemaNode onlyContainer = (ContainerSchemaNode) onlyChild; if (Objects.equals(onlyContainer.getQName().getLocalName(), choiceCaseNode.getQName().getLocalName())) { // the actual configuration is inside dummy container return (HAS_CHILDREN_AND_QNAME) onlyContainer; } } } return (HAS_CHILDREN_AND_QNAME) choiceCaseNode; }
node = targetNode.getCaseNodeByName(caseNode.getQName().getLocalName()); final Iterable<DataSchemaNode> childNodes = node.getChildNodes(); if (childNodes != null) { resolveDataSchemaNodes(module, basePackageName, caseTypeBuilder, childOfType, childNodes);
genCtx.get(module).addCaseType(caseNode.getPath(), caseTypeBuilder); genCtx.get(module).addChoiceToCaseMapping(refChoiceType, caseTypeBuilder, caseNode); final Iterable<DataSchemaNode> caseChildNodes = caseNode.getChildNodes(); if (caseChildNodes != null) { final SchemaPath choiceNodeParentPath = choiceNode.getPath().getParent();
public static CharSequence writeChoiceCaseNode(final ChoiceCaseNode choiceCaseNode) { StringConcatenation _builder = new StringConcatenation(); _builder.append("case "); QName _qName = choiceCaseNode.getQName(); String _localName = _qName.getLocalName(); _builder.append(_localName, ""); _builder.append(" {"); _builder.newLineIfNotEmpty(); { Collection<DataSchemaNode> _childNodes = choiceCaseNode.getChildNodes(); for(final DataSchemaNode childNode : _childNodes) { _builder.append(" "); CharSequence _writeDataSchemaNode = YangTemplate.writeDataSchemaNode(childNode); _builder.append(_writeDataSchemaNode, " "); _builder.newLineIfNotEmpty(); } } _builder.append("}"); _builder.newLine(); return _builder; }
for (DataSchemaNode dsn : ccNode.getChildNodes()) { if (qNameToNodes.containsKey(dsn.getQName())) { write(qNameToNodes.get(dsn.getQName()), dsn);