- if (current == null) {
- return null;
- }
- }
- }
- return current;
- }
-
- public static String modifyOperationToXmlString(final ModifyAction operation) {
- return operation.name().toLowerCase();
- }
-
-
- public static CompositeNode createEditConfigStructure(final YangInstanceIdentifier dataPath, final Optional<ModifyAction> operation,
- final Optional<CompositeNode> lastChildOverride) {
- Preconditions.checkArgument(Iterables.isEmpty(dataPath.getPathArguments()) == false, "Instance identifier with empty path %s", dataPath);
-
- List<YangInstanceIdentifier.PathArgument> reversedPath = Lists.reverse(dataPath.getPath());
-
- // Create deepest edit element with expected edit operation
- CompositeNode previous = getDeepestEditElement(reversedPath.get(0), operation, lastChildOverride);
-
- // Remove already processed deepest child
- reversedPath = Lists.newArrayList(reversedPath);
- reversedPath.remove(0);
-
- // Create edit structure in reversed order
- for (final YangInstanceIdentifier.PathArgument arg : reversedPath) {
- final CompositeNodeBuilder<ImmutableCompositeNode> builder = ImmutableCompositeNode.builder();
- builder.setQName(arg.getNodeType());
-
- addPredicatesToCompositeNodeBuilder(getPredicates(arg), builder);
-
- builder.add(previous);
- previous = builder.toInstance();
- }
- return ImmutableCompositeNode.create(NETCONF_CONFIG_QNAME, ImmutableList.<Node<?>>of(previous));
- }
-
- public static void addPredicatesToCompositeNodeBuilder(final Map<QName, Object> predicates, final CompositeNodeBuilder<ImmutableCompositeNode> builder) {
- for (final Map.Entry<QName, Object> entry : predicates.entrySet()) {
- builder.addLeaf(entry.getKey(), entry.getValue());
- }
- }
-
- public static Map<QName, Object> getPredicates(final YangInstanceIdentifier.PathArgument arg) {
- Map<QName, Object> predicates = Collections.emptyMap();
- if (arg instanceof YangInstanceIdentifier.NodeIdentifierWithPredicates) {
- predicates = ((YangInstanceIdentifier.NodeIdentifierWithPredicates) arg).getKeyValues();
- }
- return predicates;
- }
-
- public static CompositeNode getDeepestEditElement(final YangInstanceIdentifier.PathArgument arg, final Optional<ModifyAction> operation, final Optional<CompositeNode> lastChildOverride) {
- final CompositeNodeBuilder<ImmutableCompositeNode> builder = ImmutableCompositeNode.builder();
- builder.setQName(arg.getNodeType());
-
- final Map<QName, Object> predicates = getPredicates(arg);
- addPredicatesToCompositeNodeBuilder(predicates, builder);
-
- if (operation.isPresent()) {
- builder.setAttribute(NETCONF_OPERATION_QNAME, modifyOperationToXmlString(operation.get()));
- }
- if (lastChildOverride.isPresent()) {
- final List<Node<?>> children = lastChildOverride.get().getValue();
- for(final Node<?> child : children) {
- if(!predicates.containsKey(child.getKey())) {
- builder.add(child);