@Override public final void startContainerNode(final NodeIdentifier name, final int childSizeHint) throws IOException { final SchemaNode schema = tracker.startContainerNode(name); final boolean isPresence = schema instanceof ContainerSchemaNode ? ((ContainerSchemaNode) schema).isPresenceContainer() : DEFAULT_EMIT_EMPTY_CONTAINERS; context = new JSONStreamWriterNamedObjectContext(context, name, isPresence); }
private void emitRefineContainerNodes(final ContainerSchemaNode value) { final ContainerSchemaNode original = getOriginalChecked(value); // emitMustNodes(child.getConstraints().getMustConstraints()); if (Objects.deepEquals(original.isPresenceContainer(), value.isPresenceContainer())) { emitPresenceNode(value.isPresenceContainer()); } if (Objects.deepEquals(original.isConfiguration(), value.isConfiguration())) { emitConfigNode(value.isConfiguration()); } emitDocumentedNodeRefine(original, value); }
@Override public final void startContainerNode(final NodeIdentifier name, final int childSizeHint) throws IOException { final SchemaNode schema = tracker.startContainerNode(name); final boolean isPresence = schema instanceof ContainerSchemaNode ? ((ContainerSchemaNode) schema).isPresenceContainer() : DEFAULT_EMIT_EMPTY_CONTAINERS; context = new JSONStreamWriterNamedObjectContext(context, name, isPresence); }
/** * Check if new data are empty but still to be considered as a modification, meaning it's presence has a meaning * e.g. containers with presence statement. */ private static boolean isEmptyPresenceNode(@Nonnull final Modification modification) { return modification.is(ContainerSchemaNode.class) && ((ContainerSchemaNode) modification.getSchemaNode()).isPresenceContainer() && modification.getChildNodes().isEmpty() && VALID_MODIFICATIONS.contains(modification.getModificationType()); }
static ModificationApplyOperation of(final ContainerSchemaNode schema, final DataTreeConfiguration treeConfig) { if (schema.isPresenceContainer()) { final Optional<MandatoryLeafEnforcer> enforcer = MandatoryLeafEnforcer.forContainer(schema, treeConfig); return enforcer.isPresent() ? new EnforcingMandatory(schema, treeConfig, enforcer.get()) : new ContainerModificationStrategy(schema, treeConfig); } return new StructuralContainerModificationStrategy(schema, treeConfig); }
/** * Checks whether node is non-presence container but with changed nested data */ private static boolean isNonPresenceOverride(@Nonnull final Modification modification) { return modification.is(ContainerSchemaNode.class)// must be container && !((ContainerSchemaNode) modification.getSchemaNode()).isPresenceContainer() // must be non-presence && modification.getChildNodes().isEmpty() // is override to empty && modification.isBeforeAndAfterDifferent()// to detect that it is modification && modification.getDataBefore().isPresent(); // to ensure the case when overriding previously existing }
@Override public Collection<NormalizedNodeUpdate> normalizedUpdates(@Nonnull final YangInstanceIdentifier topLevelIdentifier, @Nonnull final Map.Entry<YangInstanceIdentifier.PathArgument, DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?>> entry) { final ContainerSchemaNode containerSchemaNode = (ContainerSchemaNode) SchemaContextUtil .findDataSchemaNode(ctx, getSchemaPath(topLevelIdentifier, entry)); if (containerSchemaNode.isPresenceContainer()) { LOG.debug("Processing {} as presence container", topLevelIdentifier); // if presence container - create delete right away return ((ContainerNode) entry.getValue()).getValue().stream() .map(containerNode -> new NormalizedNodeUpdate( YangInstanceIdentifier.builder(topLevelIdentifier) .node(containerNode.getIdentifier()).build(), containerNode, null)) .collect(Collectors.toList()); } else { LOG.debug("Processing {} as non-presence container", topLevelIdentifier); // if non-presence - goes deep with base logic return super.normalizedUpdates(topLevelIdentifier, entry); } }
public static ModificationApplyOperation from(final DataSchemaNode schemaNode, final DataTreeConfiguration treeConfig) { if (treeConfig.getTreeType() == TreeType.CONFIGURATION) { checkArgument(schemaNode.isConfiguration(), "Supplied %s does not belongs to configuration tree.", schemaNode.getPath()); } if (schemaNode instanceof ContainerSchemaNode) { final ContainerSchemaNode containerSchema = (ContainerSchemaNode) schemaNode; return containerSchema.isPresenceContainer() ? new PresenceContainerModificationStrategy(containerSchema, treeConfig) : new StructuralContainerModificationStrategy(containerSchema, treeConfig); } else if (schemaNode instanceof ListSchemaNode) { return fromListSchemaNode((ListSchemaNode) schemaNode, treeConfig); } else if (schemaNode instanceof ChoiceSchemaNode) { return new ChoiceModificationStrategy((ChoiceSchemaNode) schemaNode, treeConfig); } else if (schemaNode instanceof LeafListSchemaNode) { return fromLeafListSchemaNode((LeafListSchemaNode) schemaNode, treeConfig); } else if (schemaNode instanceof LeafSchemaNode) { return new LeafModificationStrategy((LeafSchemaNode) schemaNode); } throw new IllegalArgumentException("Not supported schema node type for " + schemaNode.getClass()); }
private static void findMandatoryNodes(final Builder<YangInstanceIdentifier> builder, final YangInstanceIdentifier id, final DataNodeContainer schema, final TreeType type) { for (final DataSchemaNode child : schema.getChildNodes()) { if (SchemaAwareApplyOperation.belongsToTree(type, child)) { if (child instanceof ContainerSchemaNode) { final ContainerSchemaNode container = (ContainerSchemaNode) child; if (!container.isPresenceContainer()) { findMandatoryNodes(builder, id.node(NodeIdentifier.create(child.getQName())), container, type); } } else { boolean needEnforce = child instanceof MandatoryAware && ((MandatoryAware) child).isMandatory(); if (!needEnforce && child instanceof ElementCountConstraintAware) { needEnforce = ((ElementCountConstraintAware) child) .getElementCountConstraint().map(constraint -> { final Integer min = constraint.getMinElements(); return min != null && min > 0; }).orElse(Boolean.FALSE).booleanValue(); } if (needEnforce) { final YangInstanceIdentifier childId = id.node(NodeIdentifier.create(child.getQName())); LOG.debug("Adding mandatory child {}", childId); builder.add(childId.toOptimized()); } } } } }
private static void findMandatoryNodes(final Builder<YangInstanceIdentifier> builder, final YangInstanceIdentifier id, final DataNodeContainer schema, final TreeType type) { for (final DataSchemaNode child : schema.getChildNodes()) { if (SchemaAwareApplyOperation.belongsToTree(type, child)) { if (child instanceof ContainerSchemaNode) { final ContainerSchemaNode container = (ContainerSchemaNode) child; if (!container.isPresenceContainer()) { findMandatoryNodes(builder, id.node(NodeIdentifier.create(child.getQName())), container, type); } } else { boolean needEnforce = child instanceof MandatoryAware && ((MandatoryAware) child).isMandatory(); if (!needEnforce && child instanceof ElementCountConstraintAware) { needEnforce = ((ElementCountConstraintAware) child) .getElementCountConstraint().map(constraint -> { final Integer min = constraint.getMinElements(); return min != null && min > 0; }).orElse(Boolean.FALSE).booleanValue(); } if (needEnforce) { final YangInstanceIdentifier childId = id.node(NodeIdentifier.create(child.getQName())); LOG.debug("Adding mandatory child {}", childId); builder.add(childId.toOptimized()); } } } } } }
private void emitContainer(final ContainerSchemaNode child) { super.writer.startContainerNode(child.getQName()); child.getMustConstraints().forEach(this::emitMust); child.getWhenCondition().ifPresent(this::emitWhen); // FIXME: BUG-2444: whenNode //:Optional // FIXME: BUG-2444: *(ifFeatureNode ) emitPresenceNode(child.isPresenceContainer()); emitConfigNode(child.isConfiguration()); emitDocumentedNode(child); emitDataNodeContainer(child); emitUnknownStatementNodes(child.getUnknownSchemaNodes()); emitNotifications(child.getNotifications()); emitActions(child.getActions()); super.writer.endNode(); }