/* * libbrlapi - A library providing access to braille terminals for applications. * * Copyright (C) 2006-2021 by * Samuel Thibault * Sébastien Hinderer * * libbrlapi comes with ABSOLUTELY NO WARRANTY. * * This is free software, placed under the terms of the * GNU Lesser General Public License, as published by the Free Software * Foundation; either version 2.1 of the License, or (at your option) any * later version. Please see the file LICENSE-LGPL for details. * * Web Page: http://brltty.app/ * * This software is maintained by Dave Mielke . */ package org.a11y.brlapi; import java.util.List; import java.util.ArrayList; public abstract class Program extends ProgramComponent implements Runnable { protected abstract void runProgram () throws ProgramException; public final boolean isClient () { return isClient(this); } public final String getName () { return getProgramName(getClass()); } protected final void writeProgramMessage (String format, Object... arguments) { System.err.println((getName() + ": " + String.format(format, arguments))); } protected static class Option { public final static char PREFIX_CHARACTER = '-'; public interface Handler { public void handleOption (String[] operands) throws SyntaxException; } private final String optionName; private final Handler optionHandler; private final String[] operandDescriptions; public Option (String name, Handler handler, String... operands) { optionName = name; optionHandler = handler; operandDescriptions = operands; } public final String getName () { return optionName; } public final Handler getHandler () { return optionHandler; } public final String[] getOperands () { int count = operandDescriptions.length; String[] result = new String[count]; System.arraycopy(operandDescriptions, 0, result, 0, count); return result; } } private final String[] programArguments; private final KeywordMap