a05a169c991fc71fa5259729c15df6ce883426cb
[controller.git] / opendaylight / netconf / netconf-cli / src / main / java / org / opendaylight / controller / netconf / cli / reader / impl / LeafListEntryReader.java
1
2 /*
3  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9 package org.opendaylight.controller.netconf.cli.reader.impl;
10
11 import com.google.common.base.Optional;
12 import com.google.common.collect.Lists;
13 import jline.console.completer.Completer;
14 import org.opendaylight.controller.netconf.cli.io.BaseConsoleContext;
15 import org.opendaylight.controller.netconf.cli.io.ConsoleContext;
16 import org.opendaylight.controller.netconf.cli.io.ConsoleIO;
17 import org.opendaylight.controller.netconf.cli.reader.GenericListEntryReader;
18 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
20 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
21
22 import java.util.List;
23
24 class LeafListEntryReader extends BasicDataHolderReader<LeafListSchemaNode> implements
25         GenericListEntryReader<LeafListSchemaNode> {
26
27     public LeafListEntryReader(final ConsoleIO console, final SchemaContext schemaContext) {
28         super(console, schemaContext);
29     }
30
31     public LeafListEntryReader(final ConsoleIO console, final SchemaContext schemaContext, final boolean readConfigNode) {
32         super(console, schemaContext, readConfigNode);
33     }
34
35     @Override
36     protected TypeDefinition<?> getType(final LeafListSchemaNode schemaNode) {
37         return schemaNode.getType();
38     }
39
40     @Override
41     protected ConsoleContext getContext(final LeafListSchemaNode schemaNode) {
42         return new BaseConsoleContext<LeafListSchemaNode>(schemaNode) {
43
44             @Override
45             public Optional<String> getPrompt() {
46                 return Optional.of("[entry]");
47             }
48
49             @Override
50             protected List<Completer> getAdditionalCompleters() {
51                 return Lists.<Completer> newArrayList(getBaseCompleter(getDataSchemaNode()));
52             }
53         };
54     }
55 }