Remove netconf from commons/opendaylight pom
[controller.git] / opendaylight / netconf / tools / netconf-cli / src / main / java / org / opendaylight / controller / netconf / cli / io / BaseConsoleContext.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.io;
9
10 import com.google.common.base.Optional;
11 import com.google.common.base.Preconditions;
12 import com.google.common.collect.Lists;
13 import java.util.ArrayList;
14 import java.util.Collections;
15 import java.util.List;
16 import jline.console.completer.AggregateCompleter;
17 import jline.console.completer.Completer;
18 import jline.console.completer.StringsCompleter;
19 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
20
21 public class BaseConsoleContext<T extends DataSchemaNode> implements ConsoleContext {
22
23     private static final Completer SKIP_COMPLETER = new StringsCompleter(IOUtil.SKIP);
24
25     private final T dataSchemaNode;
26
27     public BaseConsoleContext(final T dataSchemaNode) {
28         Preconditions.checkNotNull(dataSchemaNode);
29         this.dataSchemaNode = dataSchemaNode;
30     }
31
32     @Override
33     public Completer getCompleter() {
34         final ArrayList<Completer> completers = Lists.newArrayList(SKIP_COMPLETER);
35         completers.addAll(getAdditionalCompleters());
36         return new AggregateCompleter(completers);
37     }
38
39     protected List<Completer> getAdditionalCompleters() {
40         return Collections.emptyList();
41     }
42
43     @Override
44     public Optional<String> getPrompt() {
45         return Optional.of(dataSchemaNode.getQName().getLocalName());
46     }
47
48     protected T getDataSchemaNode() {
49         return dataSchemaNode;
50     }
51 }