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.netconf.cli.io;
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;
21 public class BaseConsoleContext<T extends DataSchemaNode> implements ConsoleContext {
23 private static final Completer SKIP_COMPLETER = new StringsCompleter(IOUtil.SKIP);
25 private final T dataSchemaNode;
27 public BaseConsoleContext(final T dataSchemaNode) {
28 Preconditions.checkNotNull(dataSchemaNode);
29 this.dataSchemaNode = dataSchemaNode;
33 public Completer getCompleter() {
34 final ArrayList<Completer> completers = Lists.newArrayList(SKIP_COMPLETER);
35 completers.addAll(getAdditionalCompleters());
36 return new AggregateCompleter(completers);
39 protected List<Completer> getAdditionalCompleters() {
40 return Collections.emptyList();
44 public Optional<String> getPrompt() {
45 return Optional.of(dataSchemaNode.getQName().getLocalName());
48 protected T getDataSchemaNode() {
49 return dataSchemaNode;