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; }
private static DataSchemaNode childByQName(final ChoiceCaseNode container, final QName name) { return container.getDataChildByName(name); }
if (caseNode != null && !caseNode.isAddedByUses() && !caseNode.isAugmenting()) { final String packageName = packageNameForGeneratedType(basePackageName, caseNode.getPath()); final GeneratedTypeBuilder caseTypeBuilder = addDefaultInterfaceDefinition(packageName, caseNode, module); caseTypeBuilder.addImplementsType(refChoiceType); 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 Optional<ChoiceCaseNode> findInstantiatedCase(final ChoiceSchemaNode instantiatedChoice, final ChoiceCaseNode originalDefinition) { ChoiceCaseNode potential = instantiatedChoice.getCaseNodeByName(originalDefinition.getQName()); if(originalDefinition.equals(potential)) { return Optional.of(potential); } if (potential != null) { SchemaNode potentialRoot = SchemaNodeUtils.getRootOriginalIfPossible(potential); if (originalDefinition.equals(potentialRoot)) { return Optional.of(potential); } } // We try to find case by name, then lookup its root definition // and compare it with original definition // This solves case, if choice was inside grouping // which was used in different module and thus namespaces are // different, but local names are still same. // // Still we need to check equality of definition, because local name is not // sufficient to uniquelly determine equality of cases // potential = instantiatedChoice.getCaseNodeByName(originalDefinition.getQName().getLocalName()); if(potential != null && (originalDefinition.equals(SchemaNodeUtils.getRootOriginalIfPossible(potential)))) { return Optional.of(potential); } return Optional.absent(); }
node = targetNode.getCaseNodeByName(caseNode.getQName().getLocalName()); final Iterable<DataSchemaNode> childNodes = node.getChildNodes(); if (childNodes != null) { resolveDataSchemaNodes(module, basePackageName, caseTypeBuilder, childOfType, childNodes);
if (choiceCaseNode.getConstraints() == null || choiceCaseNode.getConstraints().getWhenCondition() == null) { return; RevisionAwareXPath xPath = choiceCaseNode.getConstraints().getWhenCondition(); Matcher matcher = getWhenConditionMatcher(configModulePrefix, xPath); if (matcher.matches() == false) {
for (DataSchemaNode dsn : ccNode.getChildNodes()) { if (qNameToNodes.containsKey(dsn.getQName())) { write(qNameToNodes.get(dsn.getQName()), dsn);
/** * 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; }
private static DataSchemaNode searchInCases(final ChoiceSchemaNode choiceNode, final QName arg) { Set<ChoiceCaseNode> cases = choiceNode.getCases(); for (ChoiceCaseNode caseNode : cases) { DataSchemaNode node = caseNode.getDataChildByName(arg); if (node != null) { return node; } } return null; }
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; }
private boolean belongsToCase(final ChoiceCaseNode detectedCase, final YangInstanceIdentifier.PathArgument childToProcess) { return detectedCase.getDataChildByName(childToProcess.getNodeType()) != null; }