Merge "BUG 2799: SPI for EventSources"
[controller.git] / opendaylight / netconf / netconf-cli / src / main / java / org / opendaylight / controller / netconf / cli / reader / custom / EditContentReader.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.netconf.cli.reader.custom;
9
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.schema.NormalizedNode;
20 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
21 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
23
24 public class EditContentReader extends ChoiceReader {
25
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");
28
29     // FIXME this could be removed if feature/if-feature are supported
30
31     public EditContentReader(final ConsoleIO console, final CommandArgHandlerRegistry argumentHandlerRegistry, final SchemaContext schemaContext) {
32         super(console, argumentHandlerRegistry, schemaContext);
33     }
34
35     @Override
36     public List<NormalizedNode<?, ?>> readWithContext(final ChoiceSchemaNode 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);
41     }
42
43 }