2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netconf.cli.commands.output;
10 import com.google.common.base.Preconditions;
11 import com.google.common.collect.Lists;
12 import com.google.common.collect.Maps;
13 import java.util.List;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
17 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
18 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
21 * Output values for and rpc/command execution.
25 private final NormalizedNode<?, ?> output;
27 public Output(final NormalizedNode<?, ?> output) {
28 if (output instanceof ContainerNode && output.getNodeType().getLocalName() == "rpc-reply") {
29 this.output = ((ContainerNode) output).getValue().iterator().next();
35 public Map<DataSchemaNode, List<NormalizedNode<?, ?>>> unwrap(final OutputDefinition outputDefinition) {
36 Preconditions.checkArgument(!outputDefinition.isEmpty());
38 final Map<QName, DataSchemaNode> mappedSchemaNodes = mapOutput(outputDefinition);
39 final Map<DataSchemaNode, List<NormalizedNode<?, ?>>> mappedNodesToSchema = Maps.newHashMap();
41 final DataSchemaNode schemaNode = mappedSchemaNodes.get(output.getNodeType().withoutRevision());
42 final List<NormalizedNode<?, ?>> list = mappedNodesToSchema.get(schemaNode) == null
43 ? Lists.newArrayList() : mappedNodesToSchema.get(schemaNode);
45 mappedNodesToSchema.put(schemaNode, list);
47 return mappedNodesToSchema;
50 public NormalizedNode<?, ?> getOutput() {
54 private Map<QName, DataSchemaNode> mapOutput(final OutputDefinition outputDefinition) {
55 final Map<QName, DataSchemaNode> mapped = Maps.newHashMap();
56 for (final DataSchemaNode dataSchemaNode : outputDefinition) {
57 // without revision since data QNames come without revision
58 mapped.put(dataSchemaNode.getQName().withoutRevision(), dataSchemaNode);