001package votorola.a.count; // Copyright 2010, 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. 002 003import java.io.*; 004import java.util.*; 005import votorola.a.*; 006import votorola.a.response.*; 007import votorola.g.option.*; 008 009 010/** Responder for the command 'reconstruct' - to reconstruct a poll from scratch. All 011 * configuration items that were cached in previous constructions are ignored. 012 * 013 * @see <a href='../../../../../s/manual.xht#Poll-Response-reconstruct' 014 * >../../s/manual.xht#Poll-Response-reconstruct</a> 015 */ 016public final class CR_Reconstruct extends CommandResponder.Base 017{ 018 019 /** Constructs a CR_Reconstruct. 020 */ 021 public CR_Reconstruct( VoterService voterService ) 022 { 023 super( voterService, "a.count.CR_Reconstruct." ); 024 } 025 026 027 // - C o m m a n d - R e s p o n d e r ------------------------------------------------ 028 029 030 /** Returns true. 031 */ 032 public @Override boolean acceptsAnonymousIssue() { return true; } 033 034 035 036 public @Override Exception respond( final String[] argv, 037 final CommandResponder.Session session ) 038 { 039 final ReplyBuilder replyB = session.replyBuilder(); 040 final Map<String,Option> optionMap = compileBaseOptions( session ); 041 { 042 final int aFirstNonOption = parse( argv, optionMap, session ); // rearranges argv 043 if( aFirstNonOption == -1 ) return null; // parse error, message already appended 044 045 if( optionMap.get("a.voter.CommandResponder.option.help").hasOccured() ) 046 { 047 help( session ); 048 return null; 049 } 050 } 051 052 final StringWriter logStringWriter = new StringWriter(); 053 final PrintWriter logWriter = new PrintWriter( logStringWriter ); 054 try 055 { 056 voterService.vsRun().scopePoll().constructCachedPoll( 057 voterService.name(), logWriter ); 058 } 059 catch( IOException x ) { return x; } 060 catch( javax.script.ScriptException x ) { return x; } 061 catch( java.sql.SQLException x ) { return x; } 062 063 logWriter.close(); 064 replyB.append( logStringWriter.toString() ); 065 return null; 066 } 067 068 069 070}