org.hackystat.sensor.xmldata.option
Class OptionUtil

java.lang.Object
  extended by org.hackystat.sensor.xmldata.option.OptionUtil

public class OptionUtil
extends java.lang.Object

The option utility class that contains methods used by multiple options.

Author:
aito

Method Summary
static org.hackystat.sensorshell.Shell createShell(org.hackystat.sensorshell.SensorShellProperties properties, XmlDataController controller)
          Creates a Shell instance based on the information found in the specified controller.
static javax.xml.bind.Unmarshaller createUnmarshaller(java.lang.Class<?> contextClass, java.lang.String schemaFileName)
          The helper method that returns an unmarshaller that is created using the specified JAXB context class and schema file.
static void fireSendMessage(XmlDataController controller, org.hackystat.sensorshell.Shell shell, int entriesAdded)
          The helper method that fires a message to the specified controller based on the connectivity of the sensorshell to a Hackystat server.
static javax.xml.datatype.XMLGregorianCalendar getCurrentTimestamp(boolean isUnique, org.hackystat.utilities.tstamp.TstampSet tstampSet)
          Returns the current timestamp based on the specified parameters.
static java.lang.String getMapVerboseString(java.util.Map<java.lang.String,java.lang.String> keyValMap)
          Returns the string containing the information stored in the key-value mapping of sensor data.
static long getTimestampInMillis(java.lang.String timestamp)
          Returns the long value of the specified timestamp string representation.
static javax.xml.datatype.XMLGregorianCalendar massageTimestamp(java.lang.Boolean isUnique, org.hackystat.utilities.tstamp.TstampSet tstampSet, long timestamp)
          "Massages" the specified timestamp by using the specified parameters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getMapVerboseString

public static java.lang.String getMapVerboseString(java.util.Map<java.lang.String,java.lang.String> keyValMap)
Returns the string containing the information stored in the key-value mapping of sensor data. This string is helpful when running this option in verbose mode.

Parameters:
keyValMap - the map used to generate the returned string.
Returns:
the informative string.

getTimestampInMillis

public static long getTimestampInMillis(java.lang.String timestamp)
                                 throws java.lang.Exception
Returns the long value of the specified timestamp string representation. This method expects the timestamp string to be a long or in the SimpleDateFormat: MM/dd/yyyy-hh:mm:ss. If the timestamp does not fit either specification, a runtime exception is thrown.

Parameters:
timestamp - the specified string representation of a timestamp.
Returns:
the long value of the specified string timestamp.
Throws:
java.lang.Exception - thrown if the specified timestamp string is not in a valid SimpleDateFormat.

getCurrentTimestamp

public static javax.xml.datatype.XMLGregorianCalendar getCurrentTimestamp(boolean isUnique,
                                                                          org.hackystat.utilities.tstamp.TstampSet tstampSet)
Returns the current timestamp based on the specified parameters.

Parameters:
isUnique - if this is true, a unique timestamp, based on the specified tstampSet, is returned.
tstampSet - the set of timestamps that is managed to ensure that a unique timestamp is generated.
Returns:
the XmlGregorianCalendar instance representing the current timestamp.

massageTimestamp

public static javax.xml.datatype.XMLGregorianCalendar massageTimestamp(java.lang.Boolean isUnique,
                                                                       org.hackystat.utilities.tstamp.TstampSet tstampSet,
                                                                       long timestamp)
"Massages" the specified timestamp by using the specified parameters.

Parameters:
isUnique - if this is true, the specified timestamp is changed to be unique based on the specified tstampSet.
tstampSet - the set of timestamps that is managed to ensure that a unique timestamp is generated.
timestamp - the timestamp to massage.
Returns:
the XmlGregorianCalendar instance representing the current timestamp.

createUnmarshaller

public static javax.xml.bind.Unmarshaller createUnmarshaller(java.lang.Class<?> contextClass,
                                                             java.lang.String schemaFileName)
                                                      throws javax.xml.bind.JAXBException,
                                                             org.xml.sax.SAXException,
                                                             java.net.MalformedURLException
The helper method that returns an unmarshaller that is created using the specified JAXB context class and schema file. The schema file name is the name of a file that is relative to the '[top-level dir]/xml/schema/' directory.

Parameters:
contextClass - the specified context class used to build the unmarshaller.
schemaFileName - the schema file that adds schema validation to the unmarshaller.
Returns:
the unmarshaller instance.
Throws:
javax.xml.bind.JAXBException - thrown if there is a problem creating the unmarshaller with the specified context class.
org.xml.sax.SAXException - thrown if there is a problem adding schema validation with the specified schema file.
java.net.MalformedURLException - thrown if there is a problem finding the xsd schema directory.

fireSendMessage

public static void fireSendMessage(XmlDataController controller,
                                   org.hackystat.sensorshell.Shell shell,
                                   int entriesAdded)
The helper method that fires a message to the specified controller based on the connectivity of the sensorshell to a Hackystat server. If the server exists, a normal message is sent. If the server does not exist, a message informing the user of offline storage is sent. This method should be used by all options that send data.

Parameters:
controller - the controller that the message is fired to.
shell - the shell used to test the connectivity of the Hackystat server.
entriesAdded - the number of entries added to the specified shell.

createShell

public static org.hackystat.sensorshell.Shell createShell(org.hackystat.sensorshell.SensorShellProperties properties,
                                                          XmlDataController controller)
                                                   throws java.lang.Exception
Creates a Shell instance based on the information found in the specified controller.

Parameters:
properties - the properties used to create the shell instance.
controller - the controller that contains the information used to determine which shell to use.
Returns:
the Shell instance.
Throws:
java.lang.Exception - thrown if there is a problem instantiating a MultiSensorShell instance.