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.controller.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.CompositeNode;
17 import org.opendaylight.yangtools.yang.data.api.Node;
18 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
21 * Output values for and rpc/command execution
25 private final CompositeNode output;
27 public Output(final CompositeNode output) {
31 public Map<DataSchemaNode, List<Node<?>>> unwrap(final OutputDefinition outputDefinition) {
32 Preconditions.checkArgument(outputDefinition.isEmpty() == false);
34 final Map<QName, DataSchemaNode> mappedSchemaNodes = mapOutput(outputDefinition);
35 final Map<DataSchemaNode, List<Node<?>>> mappedNodesToSchema = Maps.newHashMap();
37 for (final Node<?> node : output.getValue()) {
38 final DataSchemaNode schemaNode = mappedSchemaNodes.get(node.getKey().withoutRevision());
39 final List<Node<?>> list = mappedNodesToSchema.get(schemaNode) == null ? Lists.<Node<?>> newArrayList()
40 : mappedNodesToSchema.get(schemaNode);
42 mappedNodesToSchema.put(schemaNode, list);
45 return mappedNodesToSchema;
48 public CompositeNode getOutput() {
52 private Map<QName, DataSchemaNode> mapOutput(final OutputDefinition outputDefinition) {
53 final Map<QName, DataSchemaNode> mapped = Maps.newHashMap();
54 for (final DataSchemaNode dataSchemaNode : outputDefinition) {
55 // without revision since data QNames come without revision
56 mapped.put(dataSchemaNode.getQName().withoutRevision(), dataSchemaNode);