package votorola.a.response.line; // Copyright 2009, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software"), to deal in the Votorola Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to whom the Votorola Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Votorola Software. THE VOTOROLA SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE VOTOROLA SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE. import java.io.*; import java.net.*; import java.sql.*; import java.util.*; import javax.script.*; import votorola.a.*; import votorola.g.lang.*; import votorola.g.option.*; /** Base class of executables that compile results, such as lists or counts. */ public @ThreadSafe abstract class ResultsCompiler { /** Compiles a map of options that are common to all results compilers. */ protected static HashMap compileBaseOptions() { final HashMap optionMap = CommandLine.compileBaseOptions(); String name; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - name = "etc"; optionMap.put( name, new Option( name, Option.OPTIONAL_ARGUMENT )); // - - - return optionMap; } /** The lazilly initialized vote-server. */ protected VoteServer voteServer() throws IOException, ScriptException, URISyntaxException { if( _voteServer == null ) _voteServer = new VoteServer( System.getProperty( "user.name" )); return _voteServer; } private VoteServer _voteServer; /** The lazilly started and locked vote-server run. */ protected VoteServer.Run vsRun() throws IOException, ScriptException, SQLException, URISyntaxException { if( _vsRun == null ) { _vsRun = voteServer().new Run( /*isSingleThreaded*/true ); _vsRun.singleServiceLock().lock(); // no need to unlock, single access } return _vsRun; } private VoteServer.Run _vsRun; // ==================================================================================== /** An allowable action for a results compiler. */ protected static enum Action { snap, ready, mount, report, umount, ureport, status; /** The last of the actions valid for use as an end action, in an * --etc option. */ public static final Action END_ACTION_LAST = umount; /** Returns true if an end action beyond the current action is specified in an * --etc option. Exits the system if the option is not well formed. */ public boolean isEtc( final String commandName, final Map optionMap ) { final Option etc = optionMap.get( "etc" ); if( !etc.hasOccured() ) return false; final String endActionArg = etc.argumentValue(); final Action endAction; if( endActionArg == null ) endAction = END_ACTION_LAST; // default else { try { endAction = valueOf( endActionArg ); } catch( IllegalArgumentException x ) { System.err.println( commandName + ": unrecognized end-action in --etc: " + endActionArg ); System.err.println( GetoptX.createHelpPrompt( commandName )); System.exit( 1 ); return false; // redundant return, to prevent compiler warnings } if( endAction.ordinal() > END_ACTION_LAST.ordinal() ) { System.err.println( commandName + ": invalid end-action in --etc: " + endActionArg ); System.err.println( GetoptX.createHelpPrompt( commandName )); System.exit( 1 ); } } return endAction.ordinal() > ordinal(); } } }