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.reader.custom;
10 import com.google.common.base.Preconditions;
11 import java.io.IOException;
12 import java.util.List;
13 import org.opendaylight.controller.netconf.cli.CommandArgHandlerRegistry;
14 import org.opendaylight.controller.netconf.cli.commands.CommandConstants;
15 import org.opendaylight.controller.netconf.cli.io.ConsoleIO;
16 import org.opendaylight.controller.netconf.cli.reader.ReadingException;
17 import org.opendaylight.controller.netconf.cli.reader.impl.ChoiceReader;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.data.api.Node;
20 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
21 import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
22 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
24 public class EditContentReader extends ChoiceReader {
26 public static final QName EDIT_CONTENT_QNAME = QName.create(CommandConstants.NETCONF_BASE_QNAME, "edit-content");
27 public static final QName CONFIG_QNAME = QName.create(EDIT_CONTENT_QNAME, "config");
29 // FIXME this could be removed if feature/if-feature are supported
31 public EditContentReader(final ConsoleIO console, final CommandArgHandlerRegistry argumentHandlerRegistry, final SchemaContext schemaContext) {
32 super(console, argumentHandlerRegistry, schemaContext);
36 public List<Node<?>> readWithContext(final ChoiceNode choiceNode) throws IOException, ReadingException {
37 Preconditions.checkState(choiceNode.getQName().equals(EDIT_CONTENT_QNAME), "Unexpected choice %s, expected %s", choiceNode, EDIT_CONTENT_QNAME);
38 final ChoiceCaseNode selectedCase = choiceNode.getCaseNodeByName(CONFIG_QNAME);
39 Preconditions.checkNotNull(selectedCase, "Unexpected choice %s, expected %s that contains %s", choiceNode, EDIT_CONTENT_QNAME, CONFIG_QNAME);
40 return readSelectedCase(selectedCase);