package votorola.a.register; // Copyright 2008, 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 votorola.a.register.trust.*;
import votorola.g.lang.*;
/** A compiled list of voters from an electoral register.
*/
public @ThreadSafe final class VoterList implements Serializable
{
// Cf. a/election/Count
private static final long serialVersionUID = 6L; // Depends on the structure of the relational tables, as well as the structure of this class.
/** Constructs a VoterList.
*
* @param readyDirectory per {@linkplain #readyDirectory() readyDirectory}()
*/
VoterList( Register register, ReadyDirectory readyDirectory )
{
this.readyDirectory = readyDirectory;
summaryDescription = register.listSummaryDescription();
}
/** @see #writeObjectToMountedListFile()
*/
public static VoterList readObjectFromMountedListFile( ReadyDirectory readyDirectory )
throws IOException
{
final ObjectInputStream in = new ObjectInputStream
( new BufferedInputStream( new FileInputStream( readyDirectory.mountedFile() )));
final VoterList list;
try
{
list = (VoterList)in.readObject();
}
catch( ClassNotFoundException x ) { throw new RuntimeException( x ); }
finally{ in.close(); }
list.readyDirectory = readyDirectory;
return list;
}
/** @see #readObjectFromMountedListFile(ReadyDirectory)
*/
void writeObjectToMountedListFile() throws IOException
{
ObjectOutputStream out = new ObjectOutputStream( new BufferedOutputStream(
new FileOutputStream( readyDirectory.mountedFile() )));
try
{
out.writeObject( VoterList.this );
}
finally{ out.close(); }
}
/** @see #listNodeTable()
* @see #neighbourhoodTable()
* @see #trustEdgeTable()
*/
@ThreadRestricted("constructor") void init( ListNodeC.Table listNodeTable,
Neighbourhood.Table neighbourhoodTable, TrustEdge.Table trustEdgeTable )
{
this.listNodeTable = listNodeTable;
this.neighbourhoodTable = neighbourhoodTable;
this.trustEdgeTable = trustEdgeTable;
}
// ------------------------------------------------------------------------------------
/** The relational store of voters that (in part) backs this list.
* It is a schema.table named
* "{@linkplain Register#name() register-name}.date-list_node-date",
* stored in the list database.
*
* @return reference to relational store; or null, if the list
* was not initialized with a reference
*
* @see Register#listDatabase()
* @see #init(ListNodeC.Table,Neighbourhood.Table,TrustEdge.Table)
*/
public ListNodeC.Table listNodeTable() { return listNodeTable; }
private transient ListNodeC.Table listNodeTable; // final after init
/** The relational store of neighbourhoods that (in part) backs this list.
* It is a schema.table named
* "{@linkplain Register#name() register-name}.date-neighbourhood-date",
* stored in the list database.
*
* @return reference to relational store; or null, if the list
* was not initialized with a reference
*
* @see Register#listDatabase()
* @see #init(ListNodeC.Table,Neighbourhood.Table,TrustEdge.Table)
*/
public Neighbourhood.Table neighbourhoodTable() { return neighbourhoodTable; }
private transient Neighbourhood.Table neighbourhoodTable; // final after init
/** The file part of the backing for this list.
*/
public ReadyDirectory readyDirectory() { return readyDirectory; }
private transient ReadyDirectory readyDirectory; // final after init
/** A brief description of this list, in sentence form. It is intended for display,
* for example, as an introductory paragraph. It ordinarilly specifies the bar
* criteria for the list - minimum trust level, residency, and so forth.
*
* @see Register.ConfigurationContext#setListSummaryDescription(String)
*/
public String summaryDescription() { return summaryDescription; }
private final String summaryDescription;
/** The relational store of trust edges that (in part) backs this list.
* It is a schema.table named
* "{@linkplain Register#name() register-name}.date-trust_edge-date",
* stored in the list database.
*
* @return reference to relational store; or null, if the list
* was not initialized with a reference
*
* @see Register#listDatabase()
* @see #init(ListNodeC.Table,Neighbourhood.Table,TrustEdge.Table)
*/
public TrustEdge.Table trustEdgeTable() { return trustEdgeTable; }
private transient TrustEdge.Table trustEdgeTable; // final after init
}