public static Optional<ChoiceSchemaNode> findInstantiatedChoice(final DataNodeContainer ctxNode, final QName choiceName) { DataSchemaNode potential = ctxNode.getDataChildByName(choiceName); if (potential instanceof ChoiceSchemaNode) { return Optional.of((ChoiceSchemaNode) potential); } return Optional.empty(); }
public static Optional<ChoiceSchemaNode> findInstantiatedChoice(final DataNodeContainer ctxNode, final QName choiceName) { DataSchemaNode potential = ctxNode.getDataChildByName(choiceName); if (potential == null) { potential = ctxNode.getDataChildByName(choiceName.getLocalName()); } if (potential instanceof ChoiceSchemaNode) { return Optional.of((ChoiceSchemaNode) potential); } return Optional.absent(); }
/** * Find choice schema node in parent node by qname of choice. * * @param ctxNode * - parent node * @param choiceName * - qname of choice * @return choice schema node if exists,.empty() otherwise */ public static Optional<ChoiceSchemaNode> findInstantiatedChoice(final DataNodeContainer ctxNode, final QName choiceName) { final DataSchemaNode potential = ctxNode.getDataChildByName(choiceName); if (potential instanceof ChoiceSchemaNode) { return Optional.of((ChoiceSchemaNode) potential); } return Optional.empty(); }
private static Optional<DataSchemaNode> findChildSchemaNode(final DataNodeContainer parent, final QName child) { DataSchemaNode potential = parent.getDataChildByName(child); if (potential == null) { final Iterable<ChoiceSchemaNode> choices = FluentIterable.from(parent.getChildNodes()) .filter(ChoiceSchemaNode.class); potential = findChoice(choices, child); } return Optional.fromNullable(potential); }
private static Optional<DataSchemaNode> findChildSchemaNode(final DataNodeContainer parent, final QName child) { DataSchemaNode potential = parent.getDataChildByName(child); if (potential == null) { potential = findChoice(Iterables.filter(parent.getChildNodes(), ChoiceSchemaNode.class), child); } return Optional.ofNullable(potential); }
public static Set<DataSchemaNode> getRealSchemasForAugment(final DataNodeContainer targetSchema, final AugmentationSchemaNode augmentSchema) { final Set<DataSchemaNode> realChildNodes = new HashSet<>(); for (final DataSchemaNode dataSchemaNode : augmentSchema.getChildNodes()) { final DataSchemaNode realChild = targetSchema.getDataChildByName(dataSchemaNode.getQName()); realChildNodes.add(realChild); } return realChildNodes; }
public static Set<DataSchemaNode> getRealSchemasForAugment(final DataNodeContainer targetSchema, final AugmentationSchemaNode augmentSchema) { final Set<DataSchemaNode> realChildNodes = new HashSet<>(); for (final DataSchemaNode dataSchemaNode : augmentSchema.getChildNodes()) { final DataSchemaNode realChild = targetSchema.getDataChildByName(dataSchemaNode.getQName()); realChildNodes.add(realChild); } return realChildNodes; }
private static Optional<DataSchemaNode> findChildSchemaNode(final DataNodeContainer parent, final QName child) { DataSchemaNode potential = parent.getDataChildByName(child); if (potential == null) { potential = findChoice(Iterables.filter(parent.getChildNodes(), ChoiceSchemaNode.class), child); } return Optional.ofNullable(potential); }
static DataSchemaNode findChildSchemaNode(final DataNodeContainer parent, final QName child) { final DataSchemaNode potential = parent.getDataChildByName(child); return potential == null ? findChoice(Iterables.filter(parent.getChildNodes(), ChoiceSchemaNode.class), child) : potential; }
static DataSchemaNode findChildSchemaNode(final DataNodeContainer parent, final QName child) { final DataSchemaNode potential = parent.getDataChildByName(child); return potential == null ? findChoice(Iterables.filter(parent.getChildNodes(), ChoiceSchemaNode.class), child) : potential; }
private static DataNodeContainer augmentationProxy(final AugmentationSchemaNode augmentation, final DataNodeContainer schema) { final Set<DataSchemaNode> children = new HashSet<>(); for (final DataSchemaNode augNode : augmentation.getChildNodes()) { children.add(schema.getDataChildByName(augNode.getQName())); } return new EffectiveAugmentationSchema(augmentation, children); }
/** * Find child schema node identified by its QName within a provided schema node. * * @param schema schema for parent node - search root * @param qname qname(with or without a revision) of a child node to be found in the parent schema * @return found schema node * @throws java.lang.IllegalStateException if the child was not found in parent schema node */ public static DataSchemaNode findSchemaForChild(final DataNodeContainer schema, final QName qname) { // Try to find child schema node directly, but use a fallback that compares QNames without revisions // and auto-expands choices final DataSchemaNode dataChildByName = schema.getDataChildByName(qname); return dataChildByName == null ? findSchemaForChild(schema, qname, schema.getChildNodes()) : dataChildByName; }
/** * Find child schema node identified by its QName within a provided schema node. * * @param schema schema for parent node - search root * @param qname qname(with or without a revision) of a child node to be found in the parent schema * @return found schema node * @throws java.lang.IllegalStateException if the child was not found in parent schema node */ public static DataSchemaNode findSchemaForChild(final DataNodeContainer schema, final QName qname) { // Try to find child schema node directly, but use a fallback that compares QNames without revisions // and auto-expands choices final DataSchemaNode dataChildByName = schema.getDataChildByName(qname); return dataChildByName == null ? findSchemaForChild(schema, qname, schema.getChildNodes()) : dataChildByName; }
/** * Returns an AugmentationSchemaNode as effective in a parent node. * * @param schema Augmentation schema * @param parent Parent schema * @return Adjusted Augmentation schema * @throws NullPointerException if any of the arguments is null */ public static AugmentationSchemaNode create(final AugmentationSchemaNode schema, final DataNodeContainer parent) { Set<DataSchemaNode> children = new HashSet<>(); for (DataSchemaNode augNode : schema.getChildNodes()) { children.add(parent.getDataChildByName(augNode.getQName())); } return new EffectiveAugmentationSchema(schema, children); }
private static DataSchemaNode dataNodeChildByQName(final DataNodeContainer container, final QName name) { final DataSchemaNode ret = container.getDataChildByName(name); if (ret == null) { for (final DataSchemaNode node : container.getChildNodes()) { if ((node instanceof ChoiceSchemaNode)) { final ChoiceSchemaNode choiceNode = ((ChoiceSchemaNode) node); final DataSchemaNode childByQName = ControllerContext.childByQName(choiceNode, name); if (childByQName != null) { return childByQName; } } } } return ret; }
/** * Returns an AugmentationSchemaNode as effective in a parent node. * * @param schema Augmentation schema * @param parent Parent schema * @return Adjusted Augmentation schema * @throws NullPointerException if any of the arguments is null */ public static AugmentationSchemaNode create(final AugmentationSchemaNode schema, final DataNodeContainer parent) { Set<DataSchemaNode> children = new HashSet<>(); for (DataSchemaNode augNode : schema.getChildNodes()) { children.add(parent.getDataChildByName(augNode.getQName())); } return new EffectiveAugmentationSchema(schema, children); }
@Override public ModificationApplyOperation load(@Nonnull final PathArgument key) { if (key instanceof AugmentationIdentifier && schema instanceof AugmentationTarget) { return SchemaAwareApplyOperation.from(schema, (AugmentationTarget) schema, (AugmentationIdentifier) key, treeConfig); } final DataSchemaNode child = schema.getDataChildByName(key.getNodeType()); checkArgument(child != null, "Schema %s does not have a node for child %s", schema, key.getNodeType()); return SchemaAwareApplyOperation.from(child, treeConfig); } });
@Override public ModificationApplyOperation load(@Nonnull final PathArgument key) { if (key instanceof AugmentationIdentifier && schema instanceof AugmentationTarget) { return SchemaAwareApplyOperation.from(schema, (AugmentationTarget) schema, (AugmentationIdentifier) key, treeConfig); } final DataSchemaNode child = schema.getDataChildByName(key.getNodeType()); checkArgument(child != null, "Schema %s does not have a node for child %s", schema, key.getNodeType()); return SchemaAwareApplyOperation.from(child, treeConfig); } });
private SchemaNode getSchema(final PathArgument name) { final Object parent = getParent(); SchemaNode schema = null; final QName qname = name.getNodeType(); if (parent instanceof DataNodeContainer) { schema = ((DataNodeContainer)parent).getDataChildByName(qname); if (schema == null) { if (parent instanceof GroupingDefinition) { schema = (GroupingDefinition) parent; } else if (parent instanceof NotificationDefinition) { schema = (NotificationDefinition) parent; } } } else if (parent instanceof ChoiceSchemaNode) { schema = findChildInCases((ChoiceSchemaNode) parent, qname); } else { throw new IllegalStateException("Unsupported schema type " + parent.getClass() + " on stack."); } checkArgument(schema != null, "Could not find schema for node %s in %s", qname, parent); return schema; }
public static Entry<String, DataSchemaNode> toRestconfIdentifier(final YangInstanceIdentifier xmlInstanceIdentifier, final SchemaContext schemaContext) { final Iterable<YangInstanceIdentifier.PathArgument> elements = xmlInstanceIdentifier.getPathArguments(); final StringBuilder ret = new StringBuilder(); final QName startQName = elements.iterator().next().getNodeType(); URI namespace = startQName.getNamespace(); Date revision = startQName.getRevision(); final Module initialModule = schemaContext.findModuleByNamespaceAndRevision(namespace, revision); DataNodeContainer node = (initialModule); DataSchemaNode schemaNode = null; for (final YangInstanceIdentifier.PathArgument element : elements) { final DataSchemaNode potentialNode = node.getDataChildByName(element.getNodeType()); if (!isListOrContainer(potentialNode)) { return null; } node = ((DataNodeContainer) potentialNode); schemaNode = potentialNode; ret.append(convertToRestconfIdentifier(element, node, schemaContext)); } return new SimpleEntry<>(ret.toString(), schemaNode); }