001package votorola.a; // Copyright 2008-2009, 2012, 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 javax.xml.stream.*;
006import votorola.g.io.*;
007import votorola.g.lang.*;
008import votorola.g.sql.*;
009import votorola.g.util.*;
010
011
012/** The input store of a voter service.  The input store contains service input, such as
013  * voter registrations, votes and administrative configuration.  It includes both file
014  * data and relational data.
015  */
016public interface InputStore
017{
018
019
020   // - I n p u t - S t o r e ------------------------------------------------------------
021
022
023    /** The relational store of voter input for this service.  It is a table named
024      * "in_<em>something</em>", located in the vote-server's voter-input database.
025      *
026      *     @see VoteServer.Run#database()
027      */
028    public VoterInputTable<? extends VoterService> voterInputTable();
029
030
031
032   // ====================================================================================
033
034
035    /** Input store utilities.
036      */
037    public static @ThreadSafe final class U
038    {
039
040        private U() {}
041
042
043        /** All mirror source directories, each directory (S) located at
044          * <code>~/votorola/in/vomir/S</code>.
045          */
046        public static Iterable<File> mirrorSourceDirectories( final VoteServer voteServer )
047        {
048            return new Iterable<File>()
049            {
050                public Iterator<File> iterator()
051                {
052                    return new IteratorA<File>()
053                    {
054                        private int d;
055
056                        private final File[] directoryArray = FileX.listFilesNoNull(
057                          new File( voteServer.inDirectory(), "vomir" ), FileFilterX.DIR );
058
059                        public boolean hasNext() { return d < directoryArray.length; }
060
061                        public File next()
062                        {
063                            if( d >= directoryArray.length ) throw new NoSuchElementException();
064
065                            return directoryArray[d++];
066                        }
067                    };
068                }
069            };
070        }
071
072
073        /** Constructs a stream reader configured to read the input files for
074          * vote-mirroring and such.
075          */
076        public static XMLStreamReader newXMLStreamReader( final Reader reader )
077          throws XMLStreamException
078        {
079            return XMLColumnAppender.newStreamReader( reader );
080        }
081
082
083        /** Constructs a stream reader configured to read the input files for
084          * vote-mirroring and such.
085          */
086        public static XMLStreamReader newXMLStreamReader( final String systemId,
087          final Reader reader ) throws XMLStreamException
088        {
089            return XMLColumnAppender.newStreamReader( systemId, reader );
090        }
091
092
093    }
094
095
096}