- Entry<org.opendaylight.yangtools.yang.data.api.InstanceIdentifier, CompositeNode> legacyEntry = bindingToLegacy
- .toDataDom(binding);
- Entry<org.opendaylight.yangtools.yang.data.api.InstanceIdentifier, NormalizedNode<?, ?>> normalizedEntry = legacyToNormalized
- .toNormalized(legacyEntry);
- LOG.trace("Serialization of {}, Legacy Representation: {}, Normalized Representation: {}", binding,
- legacyEntry, normalizedEntry);
- if (Augmentation.class.isAssignableFrom(binding.getKey().getTargetType())) {
-
- for (DataContainerChild<? extends PathArgument, ?> child : ((DataContainerNode<?>) normalizedEntry
- .getValue()).getValue()) {
- if (child instanceof AugmentationNode) {
- ImmutableList<PathArgument> childArgs = ImmutableList.<PathArgument> builder()
- .addAll(normalizedEntry.getKey().getPath()).add(child.getIdentifier()).build();
- org.opendaylight.yangtools.yang.data.api.InstanceIdentifier childPath = new org.opendaylight.yangtools.yang.data.api.InstanceIdentifier(
- childArgs);
- return new SimpleEntry<org.opendaylight.yangtools.yang.data.api.InstanceIdentifier, NormalizedNode<?, ?>>(
- childPath, child);
- }
- }
-
- }
- return normalizedEntry;
-
- }
-
- public InstanceIdentifier<? extends DataObject> toBinding(
- final org.opendaylight.yangtools.yang.data.api.InstanceIdentifier normalized)
- throws DeserializationException {
-
- PathArgument lastArgument = Iterables.getLast(normalized.getPath());
- // Used instance-identifier codec do not support serialization of last path
- // argument if it is AugmentationIdentifier (behaviour expected by old datastore)
- // in this case, we explicitly check if last argument is augmentation
- // to process it separately
- if (lastArgument instanceof AugmentationIdentifier) {
- return toBindingAugmented(normalized);
- }
- return toBindingImpl(normalized);
- }
-
- private InstanceIdentifier<? extends DataObject> toBindingAugmented(
- final org.opendaylight.yangtools.yang.data.api.InstanceIdentifier normalized) throws DeserializationException {
- InstanceIdentifier<? extends DataObject> potential = toBindingImpl(normalized);
- // Shorthand check, if codec already supports deserialization
- // of AugmentationIdentifier we will return
- if(isAugmentationIdentifier(potential)) {
- return potential;
- }
-
- AugmentationIdentifier lastArgument = (AugmentationIdentifier) Iterables.getLast(normalized.getPath());
-
- // Here we employ small trick - Binding-aware Codec injects an pointer to augmentation class
- // if child is referenced - so we will reference child and then shorten path.
- for (QName child : lastArgument.getPossibleChildNames()) {
- org.opendaylight.yangtools.yang.data.api.InstanceIdentifier childPath = new org.opendaylight.yangtools.yang.data.api.InstanceIdentifier(
- ImmutableList.<PathArgument> builder()
- .addAll(normalized.getPath()).add(new NodeIdentifier(child)).build());
- try {
-
- InstanceIdentifier<? extends DataObject> potentialPath = shortenToLastAugment(toBindingImpl(childPath));
- return potentialPath;
- } catch (Exception e) {
- LOG.trace("Unable to deserialize aug. child path for {}",childPath,e);
- }
- }
- return toBindingImpl(normalized);
- }
-
- private InstanceIdentifier<? extends DataObject> toBindingImpl(
- final org.opendaylight.yangtools.yang.data.api.InstanceIdentifier normalized)
- throws DeserializationException {
- org.opendaylight.yangtools.yang.data.api.InstanceIdentifier legacyPath;