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 jline.console.completer.Completer;
13 import jline.console.completer.NullCompleter;
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.impl.BasicDataHolderReader;
18 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
23 public class PasswordReader extends BasicDataHolderReader<DataSchemaNode> {
25 private static final char PASSWORD_MASK = '*';
27 public PasswordReader(final ConsoleIO console, final SchemaContext schemaContext) {
28 super(console, schemaContext);
32 protected ConsoleContext getContext(final DataSchemaNode schemaNode) {
33 return new BaseConsoleContext<DataSchemaNode>(schemaNode) {
35 public Completer getCompleter() {
36 return new NullCompleter();
42 protected TypeDefinition<?> getType(final DataSchemaNode schemaNode) {
43 Preconditions.checkArgument(schemaNode instanceof LeafSchemaNode);
44 return ((LeafSchemaNode)schemaNode).getType();
48 protected String readValue() throws IOException {
49 return console.read(PASSWORD_MASK);