Votorola

votorola.a
Class VoterInputTable<S extends VoterService>

java.lang.Object
  extended by VoterInputTable<S>
Direct Known Subclasses:
InputTable

@ThreadSafe
public abstract class VoterInputTable<S extends VoterService>
extends Object

The input table of a voter service, storing its voter input in a relational form. Multiple services may share a single physical table. The columnar structure is fixed by the use of a single 'xml' column, as required by the synchronization interface.

See Also:
../s/manual.xht#Synchronization-Interface

Nested Class Summary
static class VoterInputTable.BadInputException
          Thrown when voter input is unacceptable for storage.
 
Field Summary
protected  Database database
           
static int MAX_INPUT_LENGTH
          Maximum length of a single input string, in characters.
protected  String statementKeyBase
           
protected  String tableName
           
protected  S voterService
           
 
Constructor Summary
protected VoterInputTable(S _voterService, String _tableName)
          Partially constructs a VoterInputTable.
 
Method Summary
static void appendAttribute(String nameA, String value, StringBuilder xmlB)
          Serializes the string value of an attribute and appends it to a string builder, destined for writing to the 'xml' column.
static String booleanToString(boolean b)
          Returns a non-empty string if b is true; null otherwise.
static String checkedDelimiterless(String dataString)
          Throws a runtime exception if the specified data string contains a serialization delimiter character (tab or newline), making it invalid for storage in a voter input table.
static boolean containsDelimiter(String dataString)
          Returns true if the specified data string contains a serialization delimiter character (tab or newline), making it invalid for storage in a voter input table.
 Database database()
          The database in which this table is stored.
protected  boolean exists()
          Returns true if this table exists; false otherwise.
 String get(String voterEmail)
          Retrieves a voter's data from the 'xml' column.
 void init()
          Finishes constructing a VoterInputTable, physical creating it if it does not already exist.
static String lengthConstrained(String inputString)
          Throws a BadInputException if the input string is longer than MAX_INPUT_LENGTH; otherwise returns the same input string.
static String longToString(long n)
          Returns null if n is 0L, otherwise the standard string representation of n.
 VotorolaRuntimeException newUnparseableInputException(String voterEmail, String xml, XMLStreamException nestedException)
          Constructs an exception that complains about "unparseable data from input table...".
static XMLStreamReader newXMLStreamReader(Reader reader)
          Constructs a new stream reader that is configured to read the data of the 'xml' column.
static XMLStreamReader newXMLStreamReader(String systemId, Reader reader)
          Constructs a new stream reader that is configured to read the data of the 'xml' column.
 void put(String voterEmail, String xml, Pollserver.UserSession userSession)
          Stores a voter's data to the 'xml' column.
 void put(String voterEmail, String xml, Pollserver.UserSession userSession, boolean toBypassSecurityFailsafe)
          Stores a voter's data to the 'xml' column.
 void remove(String voterEmail)
          Removes a voter's data from the table, if any is stored there.
static boolean stringToBoolean(String s)
          Returns true if s is non-null and non-empty; false otherwise.
static long stringToLong(String s)
          Returns 0L if s is null or empty, otherwise the parsed value of s.
 String tableName()
          The name of this table (relation).
static void testAccessAllowed(String voterEmail, Pollserver.UserSession userSession)
          Throws a VotorolaSecurityException if voterEmail is unequal to userSession.userEmail().
 S voterService()
          Returns the service whose voter input this table stores.
static XMLInputFactory xmlInputFactory()
          An XML input factory that is configured to read the data of the 'xml' column.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

database

protected final Database database

MAX_INPUT_LENGTH

public static final int MAX_INPUT_LENGTH
Maximum length of a single input string, in characters. This limit is imposed in order to guard against big-string attacks - if those are really a concern.

See Also:
Constant Field Values

tableName

protected final String tableName

voterService

protected final S extends VoterService voterService

statementKeyBase

protected final String statementKeyBase
Constructor Detail

VoterInputTable

protected VoterInputTable(S _voterService,
                          String _tableName)
Partially constructs a VoterInputTable.

See Also:
tableName(), voterService(), init()
Method Detail

init

public void init()
          throws SQLException
Finishes constructing a VoterInputTable, physical creating it if it does not already exist.

Throws:
SQLException

appendAttribute

public static void appendAttribute(String nameA,
                                   String value,
                                   StringBuilder xmlB)
                            throws VoterInputTable.BadInputException
Serializes the string value of an attribute and appends it to a string builder, destined for writing to the 'xml' column. If the value is null, does nothing; otherwise, appends a serial form consisting of a space delimiter, followed by an attribute declaration.

Parameters:
nameA - attribute's archival name, a valid XML name
value - whose toString() is escaped where necessary with XML character entities, and used as the attribute value; or null to append nothing
Throws:
VoterInputTable.BadInputException - if the attribute value is longer than the allowed limit

booleanToString

public static String booleanToString(boolean b)
Returns a non-empty string if b is true; null otherwise.

See Also:
stringToBoolean(String)

stringToBoolean

public static boolean stringToBoolean(String s)
Returns true if s is non-null and non-empty; false otherwise.

See Also:
booleanToString(boolean)

checkedDelimiterless

public static String checkedDelimiterless(String dataString)
Throws a runtime exception if the specified data string contains a serialization delimiter character (tab or newline), making it invalid for storage in a voter input table.

Returns:
the same dataString
See Also:
containsDelimiter(String)

containsDelimiter

public static boolean containsDelimiter(String dataString)
Returns true if the specified data string contains a serialization delimiter character (tab or newline), making it invalid for storage in a voter input table.

It's only the register that still has this constraint, polls now serialize in proper XML format and can handle any characters.

See Also:
checkedDelimiterless(String)

database

@Warning(value="thread restricted object")
public final Database database()
The database in which this table is stored.

See Also:
Pollserver.Run.voterInputDatabase()

get

public String get(String voterEmail)
           throws SQLException
Retrieves a voter's data from the 'xml' column.

Returns:
data, or null if the table has no such voter
Throws:
SQLException

lengthConstrained

public static String lengthConstrained(String inputString)
                                throws VoterInputTable.BadInputException
Throws a BadInputException if the input string is longer than MAX_INPUT_LENGTH; otherwise returns the same input string.

Throws:
VoterInputTable.BadInputException

longToString

public static String longToString(long n)
Returns null if n is 0L, otherwise the standard string representation of n.

See Also:
stringToLong(String)

stringToLong

public static long stringToLong(String s)
Returns 0L if s is null or empty, otherwise the parsed value of s.

See Also:
longToString(long)

newXMLStreamReader

public static XMLStreamReader newXMLStreamReader(Reader reader)
                                          throws XMLStreamException
Constructs a new stream reader that is configured to read the data of the 'xml' column.

Throws:
XMLStreamException

newXMLStreamReader

public static XMLStreamReader newXMLStreamReader(String systemId,
                                                 Reader reader)
                                          throws XMLStreamException
Constructs a new stream reader that is configured to read the data of the 'xml' column.

Throws:
XMLStreamException

newUnparseableInputException

public final VotorolaRuntimeException newUnparseableInputException(String voterEmail,
                                                                   String xml,
                                                                   XMLStreamException nestedException)
Constructs an exception that complains about "unparseable data from input table...".


put

public final void put(String voterEmail,
                      String xml,
                      Pollserver.UserSession userSession)
               throws VoterInputTable.BadInputException,
                      SQLException
Stores a voter's data to the 'xml' column.

Parameters:
xml - data to store
Throws:
VotorolaSecurityException - if voterEmail is unequal to userSession.userEmail() (failsafe bug trap)
VoterInputTable.BadInputException
SQLException

put

public void put(String voterEmail,
                String xml,
                Pollserver.UserSession userSession,
                boolean toBypassSecurityFailsafe)
         throws VoterInputTable.BadInputException,
                SQLException
Stores a voter's data to the 'xml' column.

Parameters:
xml - data to store
Throws:
VotorolaSecurityException - if toBypassSecurityFailsafe is false, and voterEmail is unequal to userSession.userEmail() (failsafe bug trap)
VoterInputTable.BadInputException
SQLException

remove

public void remove(String voterEmail)
            throws SQLException
Removes a voter's data from the table, if any is stored there.

Throws:
SQLException

tableName

public final String tableName()
The name of this table (relation). It typically corresponds to a type of voter service, such as 'poll' or 'register'.


testAccessAllowed

public static void testAccessAllowed(String voterEmail,
                                     Pollserver.UserSession userSession)
                              throws VotorolaSecurityException
Throws a VotorolaSecurityException if voterEmail is unequal to userSession.userEmail().

Throws:
VotorolaSecurityException

voterService

public S voterService()
Returns the service whose voter input this table stores.


xmlInputFactory

@Warning(value="thread restricted object, holds VoterInputTable.class")
public static XMLInputFactory xmlInputFactory()
An XML input factory that is configured to read the data of the 'xml' column.


exists

protected boolean exists()
                  throws SQLException
Returns true if this table exists; false otherwise.

Throws:
SQLException

Votorola