public static DataSchemaNode findSchemaForChild(final ChoiceSchemaNode schema, final QName childPartialQName) { for (final CaseSchemaNode choiceCaseNode : schema.getCases().values()) { final Optional<DataSchemaNode> childSchema = findFirstSchema(childPartialQName, choiceCaseNode.getChildNodes()); if (childSchema.isPresent()) { return childSchema.get(); } } throw new IllegalStateException(String.format("Unknown child(ren) node(s) detected, identified by: %s, in: %s", childPartialQName, schema)); }
/** * Returns the concrete cases according to specified name, disregarding their namespace. * * @param localname * local name of sought child as String * @return child case nodes matching specified local name, empty list if no match is found. * @throws NullPointerException if localname is null */ @Beta default List<CaseSchemaNode> findCaseNodes(final String localname) { return getCases().values().stream().filter(node -> localname.equals(node.getQName().getLocalName())) .collect(ImmutableList.toImmutableList()); }
private static SchemaNode findChildInCases(final ChoiceSchemaNode parent, final QName qname) { DataSchemaNode schema = null; for (final CaseSchemaNode caze : parent.getCases().values()) { final DataSchemaNode potential = caze.getDataChildByName(qname); if (potential != null) { schema = potential; break; } } return schema; }
private void emitCaseNode(final CaseSchemaNode caze) { if (!super.emitInstantiated && caze.isAugmenting()) { return; } super.writer.startCaseNode(caze.getQName()); caze.getWhenCondition().ifPresent(this::emitWhen); // FIXME: BUG-2444: *(ifFeatureNode ) emitDocumentedNode(caze); emitDataNodeContainer(caze); emitUnknownStatementNodes(caze.getUnknownSchemaNodes()); super.writer.endNode(); }
if (caseNode != null && !caseNode.isAddedByUses() && !caseNode.isAugmenting()) { final GeneratedTypeBuilder caseTypeBuilder = addDefaultInterfaceDefinition(context, caseNode); caseTypeBuilder.addImplementsType(refChoiceType); annotateDeprecatedIfNecessary(caseNode.getStatus(), caseTypeBuilder); context.addCaseType(caseNode.getPath(), caseTypeBuilder); context.addChoiceToCaseMapping(refChoiceType, caseTypeBuilder, caseNode); final Iterable<DataSchemaNode> caseChildNodes = caseNode.getChildNodes(); if (caseChildNodes != null) { final SchemaPath choiceNodeParentPath = choiceNode.getPath().getParent();
for (final CaseSchemaNode choiceCase : ((ChoiceSchemaNode) dsn).getCases().values()) { final DataSchemaNode dataChildByName = choiceCase.getDataChildByName(qname); if (dataChildByName != null) { return Optional.of(dataChildByName); final Optional<DataSchemaNode> foundDsn = findFirstSchema(qname, choiceCase.getChildNodes()); if (foundDsn.isPresent()) { return foundDsn;
static CaseEnforcer forTree(final CaseSchemaNode schema, final DataTreeConfiguration treeConfig) { final TreeType type = treeConfig.getTreeType(); final Builder<NodeIdentifier, DataSchemaNode> childrenBuilder = ImmutableMap.builder(); final Builder<AugmentationIdentifier, AugmentationSchemaNode> augmentationsBuilder = ImmutableMap.builder(); if (SchemaAwareApplyOperation.belongsToTree(type, schema)) { for (final DataSchemaNode child : schema.getChildNodes()) { if (SchemaAwareApplyOperation.belongsToTree(type, child)) { childrenBuilder.put(NodeIdentifier.create(child.getQName()), child); } } for (final AugmentationSchemaNode augment : schema.getAvailableAugmentations()) { if (augment.getChildNodes().stream() .anyMatch(child -> SchemaAwareApplyOperation.belongsToTree(type, child))) { augmentationsBuilder.put(DataSchemaContextNode.augmentationIdentifierFrom(augment), augment); } } } final ImmutableMap<NodeIdentifier, DataSchemaNode> children = childrenBuilder.build(); return children.isEmpty() ? null : new CaseEnforcer(children, augmentationsBuilder.build(), MandatoryLeafEnforcer.forContainer(schema, treeConfig)); }
/** * Find a specific data schema child, if present. This method searches among its {@link CaseSchemaNode}s, * potentially recursing to nested choices. * * @param qname * QName of sought data schema node * @return Matching node, or empty if no match is found * @throws NullPointerException if qname is null */ @Beta default Optional<DataSchemaNode> findDataSchemaChild(final QName qname) { requireNonNull(qname); for (CaseSchemaNode caseNode : getCases().values()) { final Optional<DataSchemaNode> child = caseNode.findDataChildByName(qname); if (child.isPresent()) { return child; } } return Optional.empty(); }
for (final CaseSchemaNode choiceCase : ((ChoiceSchemaNode) dsn).getCases().values()) { final DataSchemaNode dataChildByName = choiceCase.getDataChildByName(qname); if (dataChildByName != null) { return Optional.of(dataChildByName); final Optional<DataSchemaNode> foundDsn = findFirstSchema(qname, choiceCase.getChildNodes()); if (foundDsn.isPresent()) { return foundDsn;
static CaseEnforcer forTree(final CaseSchemaNode schema, final DataTreeConfiguration treeConfig) { final TreeType type = treeConfig.getTreeType(); final Builder<NodeIdentifier, DataSchemaNode> childrenBuilder = ImmutableMap.builder(); final Builder<AugmentationIdentifier, AugmentationSchemaNode> augmentationsBuilder = ImmutableMap.builder(); if (SchemaAwareApplyOperation.belongsToTree(type, schema)) { for (final DataSchemaNode child : schema.getChildNodes()) { if (SchemaAwareApplyOperation.belongsToTree(type, child)) { childrenBuilder.put(NodeIdentifier.create(child.getQName()), child); } } for (final AugmentationSchemaNode augment : schema.getAvailableAugmentations()) { if (augment.getChildNodes().stream() .anyMatch(child -> SchemaAwareApplyOperation.belongsToTree(type, child))) { augmentationsBuilder.put(DataSchemaContextNode.augmentationIdentifierFrom(augment), augment); } } } final ImmutableMap<NodeIdentifier, DataSchemaNode> children = childrenBuilder.build(); if (children.isEmpty()) { return null; } final ImmutableMap<AugmentationIdentifier, AugmentationSchemaNode> augmentations = augmentationsBuilder.build(); final Optional<MandatoryLeafEnforcer> enforcer = MandatoryLeafEnforcer.forContainer(schema, treeConfig); return enforcer.isPresent() ? new EnforcingMandatory(children, augmentations, enforcer.get()) : new CaseEnforcer(children, augmentations); }
/** * Find a specific data schema child, if present. This method searches among its {@link CaseSchemaNode}s, * potentially recursing to nested choices. * * @param qname * QName of sought data schema node * @return Matching node, or empty if no match is found * @throws NullPointerException if qname is null */ @Beta default Optional<DataSchemaNode> findDataSchemaChild(final QName qname) { requireNonNull(qname); for (CaseSchemaNode caseNode : getCases().values()) { final Optional<DataSchemaNode> child = caseNode.findDataChildByName(qname); if (child.isPresent()) { return child; } } return Optional.empty(); }
public static DataSchemaNode findSchemaForChild(final ChoiceSchemaNode schema, final QName childPartialQName) { for (final CaseSchemaNode choiceCaseNode : schema.getCases().values()) { final Optional<DataSchemaNode> childSchema = findFirstSchema(childPartialQName, choiceCaseNode.getChildNodes()); if (childSchema.isPresent()) { return childSchema.get(); } } throw new IllegalStateException(String.format("Unknown child(ren) node(s) detected, identified by: %s, in: %s", childPartialQName, schema)); }
/** * Returns the concrete cases according to specified name, disregarding their namespace. * * @param localname * local name of sought child as String * @return child case nodes matching specified local name, empty list if no match is found. * @throws NullPointerException if localname is null */ @Beta default List<CaseSchemaNode> findCaseNodes(final String localname) { return getCases().values().stream().filter(node -> localname.equals(node.getQName().getLocalName())) .collect(ImmutableList.toImmutableList()); }
private static SchemaNode findCaseByChild(final ChoiceSchemaNode parent, final QName qname) { DataSchemaNode schema = null; for (final CaseSchemaNode caze : parent.getCases().values()) { final DataSchemaNode potential = caze.getDataChildByName(qname); if (potential != null) { schema = caze; break; } } return schema; }
ChoiceNodeNormalization(final ChoiceSchemaNode schema) { super(NodeIdentifier.create(schema.getQName())); final ImmutableMap.Builder<PathArgument, InstanceIdToNodes<?>> byArgBuilder = ImmutableMap.builder(); for (final CaseSchemaNode caze : schema.getCases().values()) { for (final DataSchemaNode cazeChild : caze.getChildNodes()) { final InstanceIdToNodes<?> childOp = fromDataSchemaNode(cazeChild); byArgBuilder.put(childOp.getIdentifier(), childOp); } } byArg = byArgBuilder.build(); }
public static Optional<CaseSchemaNode> findInstantiatedCase(final ChoiceSchemaNode instantiatedChoice, final CaseSchemaNode originalDefinition) { CaseSchemaNode 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 // for (CaseSchemaNode caze : instantiatedChoice.findCaseNodes(originalDefinition.getQName().getLocalName())) { if (originalDefinition.equals(SchemaNodeUtils.getRootOriginalIfPossible(caze))) { return Optional.of(caze); } } return Optional.empty(); }
private static SchemaNode findChildInCases(final ChoiceSchemaNode parent, final QName qname) { DataSchemaNode schema = null; for (final CaseSchemaNode caze : parent.getCases().values()) { final DataSchemaNode potential = caze.getDataChildByName(qname); if (potential != null) { schema = potential; break; } } return schema; }
ChoiceNodeNormalization(final ChoiceSchemaNode schema) { super(NodeIdentifier.create(schema.getQName())); final ImmutableMap.Builder<PathArgument, InstanceIdToNodes<?>> byArgBuilder = ImmutableMap.builder(); for (final CaseSchemaNode caze : schema.getCases().values()) { for (final DataSchemaNode cazeChild : caze.getChildNodes()) { final InstanceIdToNodes<?> childOp = fromDataSchemaNode(cazeChild); byArgBuilder.put(childOp.getIdentifier(), childOp); } } byArg = byArgBuilder.build(); }
final QName qname = originalDefinition.getQName(); final CaseSchemaNode potential = instantiatedChoice.getCaseNodeByName(qname); if (originalDefinition.equals(potential)) {
private static SchemaNode findCaseByChild(final ChoiceSchemaNode parent, final QName qname) { DataSchemaNode schema = null; for (final CaseSchemaNode caze : parent.getCases().values()) { final DataSchemaNode potential = caze.getDataChildByName(qname); if (potential != null) { schema = caze; break; } } return schema; }