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; } }
@Override @SuppressWarnings("checkstyle:parameterName") public int compareTo(@Nonnull final PathArgument o) { if (!(o instanceof AugmentationIdentifier)) { return -1; } AugmentationIdentifier other = (AugmentationIdentifier) o; Set<QName> otherChildNames = other.getPossibleChildNames(); int thisSize = childNames.size(); int otherSize = otherChildNames.size(); if (thisSize == otherSize) { // Quick Set-based comparison if (childNames.equals(otherChildNames)) { return 0; } // We already know the sets are not equal, but have equal size, hence the sets differ in their elements, // but potentially share a common set of elements. The most consistent way of comparing them is using // total ordering defined by QName's compareTo. Hence convert both sets to lists ordered // by QName.compareTo() and decide on the first differing element. final List<QName> diff = new ArrayList<>(Sets.symmetricDifference(childNames, otherChildNames)); verify(!diff.isEmpty(), "Augmentation identifiers %s and %s report no difference", this, o); diff.sort(QName::compareTo); return childNames.contains(diff.get(0)) ? -1 : 1; } else if (thisSize < otherSize) { return 1; } else { return -1; } } }
Set<QName> childNames = new HashSet<>(); childNames.add(Y_NODE_NAME); AugmentationIdentifier ai = new AugmentationIdentifier(childNames); Optional<DataContainerChild<? extends PathArgument, ?>> t = conNode.getChild(ai); if (t.isPresent()) {
new NodeIdentifierWithPredicates(QName.create(TEST_QNAME, "list-entry"), QName.create(TEST_QNAME, "key"), 10), new AugmentationIdentifier(ImmutableSet.of( QName.create(TEST_QNAME, "aug1"), QName.create(TEST_QNAME, "aug2"))), new NodeWithValue<>(QName.create(TEST_QNAME, "leaf-list-entry"), "foo"));
ImmutableSet.of(QName.create(CONTAINER_Q_NAME, "aug1"), QName.create(CONTAINER_Q_NAME, "aug1")); final AugmentationNode augmentationNode = Builders.augmentationBuilder() .withNodeIdentifier(new YangInstanceIdentifier.AugmentationIdentifier(childNames)) .withChild(createLeaf("aug1", "aug1Value")) .withChild(createLeaf("aug2", "aug2Value"))
Set<QName> childNames = new HashSet<>(); childNames.add(Y_NODE_NAME); AugmentationIdentifier ai = new AugmentationIdentifier(childNames); Optional<DataContainerChild<? extends PathArgument, ?>> t = conNode.getChild(ai); if (t.isPresent()) {
AugmentationIdentifier identifier = (AugmentationIdentifier) pathArgument; for (QName key : identifier.getPossibleChildNames()) { Object value = key; NormalizedNodeMessages.Attribute attribute =
.filter(aug -> identifier.equals(new YangInstanceIdentifier.AugmentationIdentifier( aug.getChildNodes().stream() .map(SchemaNode::getQName)
final AugmentationIdentifier identifier = new AugmentationIdentifier(childNames); final AugmentationSchemaNode proxy = new EffectiveAugmentationSchema(origSchemas.stream().findFirst().get(), realChilds);
case NodeTypes.AUGMENTATION_NODE : YangInstanceIdentifier.AugmentationIdentifier augIdentifier = new YangInstanceIdentifier.AugmentationIdentifier(readQNameSet());
case NodeTypes.AUGMENTATION_NODE : YangInstanceIdentifier.AugmentationIdentifier augIdentifier = new YangInstanceIdentifier.AugmentationIdentifier(readQNameSet());
return new YangInstanceIdentifier.AugmentationIdentifier(qNameSet);
final AugmentationIdentifier identifier = new AugmentationIdentifier(childNames); final AugmentationSchemaNode proxy = new EffectiveAugmentationSchema(origSchema, realChilds); return new SimpleEntry<>(identifier, proxy);
writeQNameSet(augmentationIdentifier.getPossibleChildNames()); break; default :
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()))
@Override public void writePathArgument(final PathArgument pathArgument) throws IOException { byte type = PathArgumentTypes.getSerializablePathArgumentType(pathArgument); output.writeByte(type); switch(type) { case PathArgumentTypes.NODE_IDENTIFIER: NodeIdentifier nodeIdentifier = (NodeIdentifier) pathArgument; writeQName(nodeIdentifier.getNodeType()); break; case PathArgumentTypes.NODE_IDENTIFIER_WITH_PREDICATES: NodeIdentifierWithPredicates nodeIdentifierWithPredicates = (NodeIdentifierWithPredicates) pathArgument; writeQName(nodeIdentifierWithPredicates.getNodeType()); writeKeyValueMap(nodeIdentifierWithPredicates.getKeyValues()); break; case PathArgumentTypes.NODE_IDENTIFIER_WITH_VALUE : NodeWithValue<?> nodeWithValue = (NodeWithValue<?>) pathArgument; writeQName(nodeWithValue.getNodeType()); writeObject(nodeWithValue.getValue()); break; case PathArgumentTypes.AUGMENTATION_IDENTIFIER : AugmentationIdentifier augmentationIdentifier = (AugmentationIdentifier) pathArgument; // No Qname in augmentation identifier writeQNameSet(augmentationIdentifier.getPossibleChildNames()); break; default : throw new IllegalStateException("Unknown node identifier type is found : " + pathArgument.getClass().toString() ); } }
@Override @SuppressWarnings("checkstyle:parameterName") public int compareTo(@Nonnull final PathArgument o) { if (!(o instanceof AugmentationIdentifier)) { return -1; } AugmentationIdentifier other = (AugmentationIdentifier) o; Set<QName> otherChildNames = other.getPossibleChildNames(); int thisSize = childNames.size(); int otherSize = otherChildNames.size(); if (thisSize == otherSize) { // Quick Set-based comparison if (childNames.equals(otherChildNames)) { return 0; } // We already know the sets are not equal, but have equal size, hence the sets differ in their elements, // but potentially share a common set of elements. The most consistent way of comparing them is using // total ordering defined by QName's compareTo. Hence convert both sets to lists ordered // by QName.compareTo() and decide on the first differing element. final List<QName> diff = new ArrayList<>(Sets.symmetricDifference(childNames, otherChildNames)); verify(!diff.isEmpty(), "Augmentation identifiers %s and %s report no difference", this, o); diff.sort(QName::compareTo); return childNames.contains(diff.get(0)) ? -1 : 1; } else if (thisSize < otherSize) { return 1; } else { return -1; } } }
/** * 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 boolean isTransitiveAttribute(final DataContainerChild<? extends PathArgument, ?> child) { if (child.getIdentifier() instanceof AugmentationIdentifier) { final AugmentationIdentifier ai = (AugmentationIdentifier) child.getIdentifier(); for (final QName name : ai.getPossibleChildNames()) { LOG.trace("Augmented QNAME {}", name); if (this.transitiveCollection.contains(name)) { return true; } } return false; } if (this.transitiveCollection.contains(child.getNodeType())) { return true; } if (UnrecognizedAttributes.QNAME.equals(child.getNodeType())) { final Optional<NormalizedNode<?, ?>> maybeTransitive = NormalizedNodes.findNode(child, this.transitiveLeaf); if (maybeTransitive.isPresent()) { return (Boolean) maybeTransitive.get().getValue(); } } return false; }