public YangInstanceIdentifier toLegacy(final YangInstanceIdentifier normalized) throws DataNormalizationException { ImmutableList.Builder<PathArgument> legacyArgs = ImmutableList.builder(); DataNormalizationOperation<?> currentOp = operation; for (PathArgument normalizedArg : normalized.getPathArguments()) { currentOp = currentOp.getChild(normalizedArg); if (!currentOp.isMixin()) { legacyArgs.add(normalizedArg); } } return YangInstanceIdentifier.create(legacyArgs.build()); }
public boolean isNodeMixin(final YangInstanceIdentifier path) { final DataNormalizationOperation<?> operation; try { operation = dataNormalizer.getOperation(path); } catch (final DataNormalizationException e) { throw new RestconfDocumentedException("Data normalizer failed. Normalization isn't possible", e); } return operation.isMixin(); }
public YangInstanceIdentifier toNormalized(final YangInstanceIdentifier legacy) { ImmutableList.Builder<PathArgument> normalizedArgs = ImmutableList.builder(); DataNormalizationOperation<?> currentOp = operation; Iterator<PathArgument> arguments = legacy.getPathArguments().iterator(); try { while (arguments.hasNext()) { PathArgument legacyArg = arguments.next(); currentOp = currentOp.getChild(legacyArg); checkArgument(currentOp != null, "Legacy Instance Identifier %s is not correct. Normalized Instance Identifier so far %s", legacy, normalizedArgs.build()); while (currentOp.isMixin()) { normalizedArgs.add(currentOp.getIdentifier()); currentOp = currentOp.getChild(legacyArg.getNodeType()); } normalizedArgs.add(legacyArg); } } catch (DataNormalizationException e) { throw new IllegalArgumentException(String.format("Failed to normalize path %s", legacy), e); } return YangInstanceIdentifier.create(normalizedArgs.build()); }