- public Optional<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 Optional<InstanceIdentifier<? extends DataObject>> toBindingAugmented(
- final org.opendaylight.yangtools.yang.data.api.InstanceIdentifier normalized)
- throws DeserializationException {
- Optional<InstanceIdentifier<? extends DataObject>> potential = toBindingImpl(normalized);
- // Shorthand check, if codec already supports deserialization
- // of AugmentationIdentifier we will return
- if (potential.isPresent() && isAugmentationIdentifier(potential.get())) {
- return potential;
- }
-
- int normalizedCount = getAugmentationCount(normalized);
- 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 {
- if (!isNotRepresentable(childPath)) {
- InstanceIdentifier<? extends DataObject> potentialPath = shortenToLastAugment(toBindingImpl(
- childPath).get());
- int potentialAugmentCount = getAugmentationCount(potentialPath);
- if(potentialAugmentCount == normalizedCount) {
- return Optional.<InstanceIdentifier<? extends DataObject>> of(potentialPath);
- }
- }
- } catch (Exception e) {
- LOG.trace("Unable to deserialize aug. child path for {}", childPath, e);
- }
- }
- return Optional.absent();
- }
-
- private Optional<InstanceIdentifier<? extends DataObject>> toBindingImpl(
- final org.opendaylight.yangtools.yang.data.api.InstanceIdentifier normalized)
- throws DeserializationException {
- org.opendaylight.yangtools.yang.data.api.InstanceIdentifier legacyPath;
-