public YangInstanceIdentifier.AugmentationIdentifier getPathArgument() { final String childQNames = matcher.group(1); final Set<QName> childNames = new HashSet<>(); for (String name : COMMA_SPLITTER.split(childQNames)) { childNames.add(QNameFactory.create(name)); } return new YangInstanceIdentifier.AugmentationIdentifier(childNames); }
/** * Create AugmentationIdentifier from an AugmentationSchemaNode. * * @param schema Augmentation schema * @return AugmentationIdentifier for the schema * @throws NullPointerException if {@code schema} is null */ public static AugmentationIdentifier augmentationIdentifierFrom(final AugmentationSchemaNode schema) { return new AugmentationIdentifier(schema.getChildNodes().stream().map(DataSchemaNode::getQName) .collect(Collectors.toSet())); }
/** * Create AugmentationIdentifier from an AugmentationSchemaNode. * * @param schema Augmentation schema * @return AugmentationIdentifier for the schema * @throws NullPointerException if {@code schema} is null */ public static AugmentationIdentifier augmentationIdentifierFrom(final AugmentationSchemaNode schema) { return new AugmentationIdentifier(schema.getChildNodes().stream().map(DataSchemaNode::getQName) .collect(Collectors.toSet())); }
final AugmentationIdentifier identifier = new AugmentationIdentifier(childNames); final AugmentationSchemaNode proxy = new EffectiveAugmentationSchema(origSchema, realChilds); return new SimpleEntry<>(identifier, proxy);
case NodeTypes.AUGMENTATION_NODE : YangInstanceIdentifier.AugmentationIdentifier augIdentifier = new YangInstanceIdentifier.AugmentationIdentifier(readQNameSet());
case NodeTypes.AUGMENTATION_NODE : YangInstanceIdentifier.AugmentationIdentifier augIdentifier = new YangInstanceIdentifier.AugmentationIdentifier(readQNameSet());
childNames.add(Y_PERIOD_NAME); childNames.add(Y_SUB_ID_NAME); AugmentationIdentifier ai = new AugmentationIdentifier(childNames); AugmentationNode an = Builders.augmentationBuilder().withNodeIdentifier(ai) .withChild(ImmutableNodes.leafNode(Y_PERIOD_NAME, inputData.getPeriod()))
/** * Parse a protocol buffer PathArgument and return an MD-SAL PathArgument * * @param pathArgument protocol buffer PathArgument * @return MD-SAL PathArgument */ private static PathArgument parsePathArgument( NormalizedNodeMessages.PathArgument pathArgument) { if (NodeWithValue.class.getSimpleName().equals(pathArgument.getType())) { NodeWithValue<?> nodeWithValue = new NodeWithValue<>( QNameFactory.create(pathArgument.getNodeType().getValue()), parseAttribute(pathArgument.getAttributes(0))); return nodeWithValue; } else if(NodeIdentifierWithPredicates.class.getSimpleName().equals(pathArgument.getType())){ NodeIdentifierWithPredicates nodeIdentifierWithPredicates = new NodeIdentifierWithPredicates( QNameFactory.create(pathArgument.getNodeType().getValue()), toAttributesMap(pathArgument.getAttributesList())); return nodeIdentifierWithPredicates; } else if(AugmentationIdentifier.class.getSimpleName().equals(pathArgument.getType())){ Set<QName> qNameSet = new HashSet<>(); for(NormalizedNodeMessages.Attribute attribute : pathArgument.getAttributesList()){ qNameSet.add(QNameFactory.create(attribute.getValue())); } return new AugmentationIdentifier(qNameSet); } return NodeIdentifierFactory.getArgument(pathArgument.getValue()); }
public Entry<AugmentationIdentifier, AugmentationSchema> getResolvedAugmentationSchema(final DataNodeContainer target, final Class<? extends Augmentation<?>> aug) { final AugmentationSchema origSchema = getAugmentationDefinition(aug); Preconditions.checkArgument(origSchema != null, "Augmentation %s is not known in current schema context",aug); /* * FIXME: Validate augmentation schema lookup * * Currently this algorithm, does not verify if instantiated child nodes * are real one derived from augmentation schema. The problem with * full validation is, if user used copy builders, he may use * augmentation which was generated for different place. * * If this augmentations have same definition, we emit same identifier * with data and it is up to underlying user to validate data. * */ final Set<QName> childNames = new HashSet<>(); final Set<DataSchemaNode> realChilds = new HashSet<>(); for (final DataSchemaNode child : origSchema.getChildNodes()) { realChilds.add(target.getDataChildByName(child.getQName())); childNames.add(child.getQName()); } final AugmentationIdentifier identifier = new AugmentationIdentifier(childNames); final AugmentationSchema proxy = new EffectiveAugmentationSchema(origSchema, realChilds); return new AbstractMap.SimpleEntry<>(identifier, proxy); }
private AugmentationSchemaNode findAugmentation(Object currentNode, final YangInstanceIdentifier.AugmentationIdentifier identifier) { if (currentNode != null) { // check if identifier points to some augmentation of currentNode if (currentNode instanceof AugmentationTarget) { Optional<AugmentationSchemaNode> augmentationSchema = ((AugmentationTarget) currentNode).getAvailableAugmentations().stream() .filter(aug -> identifier.equals(new YangInstanceIdentifier.AugmentationIdentifier( aug.getChildNodes().stream() .map(SchemaNode::getQName) .collect(Collectors.toSet())))) .findFirst(); if (augmentationSchema.isPresent()) { return augmentationSchema.get(); } } // continue search: Collection<DataSchemaNode> childNodes = Collections.emptyList(); if (currentNode instanceof DataNodeContainer) { childNodes = ((DataNodeContainer) currentNode).getChildNodes(); } else if (currentNode instanceof ChoiceSchemaNode) { childNodes = ((ChoiceSchemaNode) currentNode).getCases().values().stream() .flatMap(cas -> cas.getChildNodes().stream()).collect(Collectors.toList()); } return childNodes.stream().map(n -> findAugmentation(n, identifier)).filter(n -> n != null).findFirst() .orElse(null); } else { return null; } }
public static MapEntryNode createAugmentedListEntry(final int id, final String name) { Set<QName> childAugmentations = new HashSet<>(); childAugmentations.add(AUG_CONT_QNAME); ContainerNode augCont = ImmutableContainerNodeBuilder .create() .withNodeIdentifier( new YangInstanceIdentifier.NodeIdentifier(AUG_CONT_QNAME)) .withChild(ImmutableNodes.leafNode(AUG_NAME_QNAME, name)).build(); final YangInstanceIdentifier.AugmentationIdentifier augmentationIdentifier = new YangInstanceIdentifier.AugmentationIdentifier(childAugmentations); final AugmentationNode augmentationNode = Builders.augmentationBuilder() .withNodeIdentifier(augmentationIdentifier).withChild(augCont) .build(); return ImmutableMapEntryNodeBuilder .create() .withNodeIdentifier( new YangInstanceIdentifier.NodeIdentifierWithPredicates( AUGMENTED_LIST_QNAME, ID_QNAME, id)) .withChild(ImmutableNodes.leafNode(ID_QNAME, id)) .withChild(augmentationNode).build(); }
@Override public PathArgument readPathArgument() throws IOException { // read Type int type = input.readByte(); switch(type) { case PathArgumentTypes.AUGMENTATION_IDENTIFIER : return new YangInstanceIdentifier.AugmentationIdentifier(readQNameSet()); case PathArgumentTypes.NODE_IDENTIFIER : return new NodeIdentifier(readQName()); case PathArgumentTypes.NODE_IDENTIFIER_WITH_PREDICATES : return new NodeIdentifierWithPredicates(readQName(), readKeyValueMap()); case PathArgumentTypes.NODE_IDENTIFIER_WITH_VALUE : return new NodeWithValue<>(readQName(), readObject()); default : return null; } }
@Override public PathArgument readPathArgument() throws IOException { // read Type int type = input.readByte(); switch (type) { case PathArgumentTypes.AUGMENTATION_IDENTIFIER : return new YangInstanceIdentifier.AugmentationIdentifier(readQNameSet()); case PathArgumentTypes.NODE_IDENTIFIER : return new NodeIdentifier(readQName()); case PathArgumentTypes.NODE_IDENTIFIER_WITH_PREDICATES : return readNormalizedNodeWithPredicates(); case PathArgumentTypes.NODE_IDENTIFIER_WITH_VALUE : return new NodeWithValue<>(readQName(), readObject()); default : return null; } }
private AugmentationIdentifier transform(final AugmentationIdentifier identifier) { ImmutableSet.Builder<QName> builder = ImmutableSet.builder(); for (QName original : identifier.getPossibleChildNames()) { builder.add(transform(original)); } return new AugmentationIdentifier(builder.build()); }
private static AugmentationIdentifier getAugmentationIdentifier(final AugmentationSchemaNode augment) { final Set<QName> childNames = new HashSet<>(); for (final DataSchemaNode child : augment.getChildNodes()) { childNames.add(child.getQName()); } return new AugmentationIdentifier(childNames); }
private static AugmentationIdentifier getAugmentationIdentifier(final AugmentationSchemaNode augment) { final Set<QName> childNames = new HashSet<>(); for (final DataSchemaNode child : augment.getChildNodes()) { childNames.add(child.getQName()); } return new AugmentationIdentifier(childNames); }
private AugmentationIdentifier getAugmentationIdentifier(final AugmentationSchema augment) { final Set<QName> childNames = new HashSet<>(); for (final DataSchemaNode child : augment.getChildNodes()) { childNames.add(child.getQName()); } return new AugmentationIdentifier(childNames); }
@Test public void testLeafNodePrunedWhenHasAugmentationParentAndSchemaMissing() throws IOException { AugmentationIdentifier augId = new AugmentationIdentifier(Sets.newHashSet(TestModel.AUG_CONT_QNAME)); NormalizedNodePruner pruner = prunerFullSchema(YangInstanceIdentifier.builder() .node(TestModel.TEST_QNAME).node(TestModel.AUGMENTED_LIST_QNAME) .node(TestModel.AUGMENTED_LIST_QNAME).node(augId).build()); LeafNode<Object> child = Builders.leafBuilder().withNodeIdentifier( new NodeIdentifier(TestModel.INVALID_QNAME)).withValue("test").build(); NormalizedNode<?, ?> input = Builders.augmentationBuilder().withNodeIdentifier(augId).withChild(child).build(); NormalizedNodeWriter.forStreamWriter(pruner).write(input); NormalizedNode<?, ?> actual = pruner.normalizedNode(); assertEquals("normalizedNode", Builders.augmentationBuilder().withNodeIdentifier(augId).build(), actual); }
private static YangInstanceIdentifier.AugmentationIdentifier autmentationId(final String... nodes) { final Set<QName> qNames = Arrays.stream(nodes) .map(node -> QName.create(CONTAINER_Q_NAME, node)) .collect(Collectors.toSet()); return new YangInstanceIdentifier.AugmentationIdentifier(qNames); }
public static AugmentationIdentifier augmentationIdentifierFrom(final AugmentationSchemaNode augmentation) { final ImmutableSet.Builder<QName> potentialChildren = ImmutableSet.builder(); for (final DataSchemaNode child : augmentation.getChildNodes()) { potentialChildren.add(child.getQName()); } return new AugmentationIdentifier(potentialChildren.build()); }