com.isti.quakewatch.message
Class QWRecord

java.lang.Object
  extended by com.isti.quakewatch.message.QWRecord
Direct Known Subclasses:
QWMagnitudeRecord, QWMsgRecord, QWStatusMsgRecord

public abstract class QWRecord
extends java.lang.Object

Class QWRecord provides methods for extracting XML attribute values.


Field Summary
protected  org.jdom.Element currentElement
          Handle to current message 'Element' object being processed.
 
Constructor Summary
QWRecord(org.jdom.Element elementObj)
          Creates a record object and sets the current element to be used.
QWRecord(java.lang.String dataStr, Archivable.Marker mkrObj)
          Creates a record object from the archived-string data for an XML record.
 
Method Summary
 boolean equals(java.lang.Object obj)
          Indicates whether some other object is "equal to" this one.
protected  double getAttribDouble(java.lang.String nameStr)
          Returns the floating-point value of an attribute in the current element.
protected  int getAttribInteger(java.lang.String nameStr)
          Returns the integer value of an attribute in the current element.
protected  long getAttribLong(java.lang.String nameStr)
          Returns the long integer value of an attribute in the current element.
protected  java.lang.String getAttribStr(java.lang.String nameStr)
          Returns the value of an attribute in the current element.
protected  java.util.Date getAttribTime(java.lang.String nameStr)
          Returns the date/time value of an attribute in the current element.
 java.lang.Double getChildElementDouble(java.lang.String elemNameStr, java.lang.String childNameStr)
          Returns the double value of a sub-child element under a child element in the current element.
 java.lang.Double getChildElementDouble(java.lang.String elemNameStr, java.lang.String childNameStr, java.lang.String nsPrefixStr)
          Returns the double value of a sub-child element under a child element in the current element.
 java.lang.Integer getChildElementInteger(java.lang.String elemNameStr, java.lang.String childNameStr)
          Returns the integer value of a sub-child element under a child element in the current element.
 java.lang.Integer getChildElementInteger(java.lang.String elemNameStr, java.lang.String childNameStr, java.lang.String nsPrefixStr)
          Returns the integer value of a sub-child element under a child element in the current element.
 java.lang.String getChildElementStr(java.lang.String elemNameStr, java.lang.String childNameStr)
          Returns the value of a sub-child element under a child element in the current element.
 java.lang.String getChildElementStr(java.lang.String elemNameStr, java.lang.String childNameStr, java.lang.String nsPrefixStr)
          Returns the value of a sub-child element under a child element in the current element.
 org.jdom.Element getCurrentElement()
          Returns the current XML element for this record.
protected  boolean getDefAttribBoolean(java.lang.String nameStr, boolean defaultValueFlag)
          Returns the boolean value of an optional attribute in the current element, or a default value if the attribute is not found.
protected  boolean getDefElementBoolean(java.lang.String nameStr, boolean defaultValueFlag)
          Returns the boolean value of an optional element in the current element, or a default value if the element is not found.
protected  double getElementDouble(java.lang.String nameStr)
          Returns the floating-point value of a child-element of the current element.
protected  int getElementInteger(java.lang.String nameStr)
          Returns the integer value of a child-element of the current element.
protected  long getElementLong(java.lang.String nameStr)
          Returns the long integer value of a child-element of the current element.
protected  java.lang.String getElementStr(java.lang.String nameStr)
          Returns the value of a child element in the current element.
protected  java.util.Date getElementTime(java.lang.String nameStr)
          Returns the date/time value of a child-element of the current element.
protected  double getElementValueDouble(java.lang.String nameStr)
          Returns the floating-point value of the child element 'value' in a child-element of the current element.
protected  java.lang.String getElementValueStr(java.lang.String nameStr)
          Returns the text of the child element 'value' in a child element in the current element.
protected  java.util.Date getElementValueTime(java.lang.String nameStr)
          Returns the date/time value of the child element 'value' in a child-element of the current element.
protected  java.lang.String getNonNullOptAttribStr(java.lang.String nameStr)
          Returns the value of an attribute in the current element.
protected  java.lang.String getNonNullOptElementStr(java.lang.String nameStr)
          Returns the value of a child element in the current element.
protected  java.lang.Boolean getOptAttribBoolean(java.lang.String nameStr)
          Returns the boolean value of an optional attribute in the current element, or null if the attribute is not found.
protected  java.lang.Double getOptAttribDouble(java.lang.String nameStr)
          Returns the floating-point value of an optional attribute in the current element.
protected  java.lang.Integer getOptAttribInteger(java.lang.String nameStr)
          Returns the integer value of an optional attribute in the current element.
protected  java.lang.String getOptAttribStr(java.lang.String nameStr)
          Returns the value of an attribute in the current element.
protected  java.util.Date getOptAttribTime(java.lang.String nameStr)
          Returns the date/time value of an optional attribute in the current element.
protected  java.lang.Boolean getOptElementBoolean(java.lang.String nameStr)
          Returns the boolean value of an optional element in the current element, or null if the element is not found.
protected  java.lang.Double getOptElementDouble(java.lang.String nameStr)
          Returns the floating-point value of an optional child-element of the current element.
protected  java.lang.Integer getOptElementInteger(java.lang.String nameStr)
          Returns the integer value of an optional child-element of the current element.
protected  java.lang.String getOptElementStr(java.lang.String nameStr)
          Returns the value of a child element in the current element.
protected  java.util.Date getOptElementTime(java.lang.String nameStr)
          Returns the date/time value of an optional child-element of the current element.
protected  java.lang.Double getOptElementValueDouble(java.lang.String nameStr)
          Returns the floating-point value of the child element 'value' in an optional child-element of the current element.
protected  java.lang.Double getOptTextDouble()
          Returns the floating-point value of the text for the current element.
protected  java.lang.Boolean parseDataBoolean(java.lang.String nameStr, java.lang.String str)
          Parses a boolean string.
protected  java.lang.Double parseDataDouble(java.lang.String nameStr, java.lang.String str)
          Parses a floating-point numeric string.
protected  java.lang.Integer parseDataInteger(java.lang.String nameStr, java.lang.String str)
          Parses an integer numeric string.
protected  java.lang.Long parseDataLong(java.lang.String nameStr, java.lang.String str)
          Parses a long integer numeric string.
protected  java.util.Date parseDataTime(java.lang.String nameStr, java.lang.String str)
          Parses a date/time specification string.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

currentElement

protected org.jdom.Element currentElement
Handle to current message 'Element' object being processed.

Constructor Detail

QWRecord

public QWRecord(org.jdom.Element elementObj)
         throws QWRecordException
Creates a record object and sets the current element to be used.

Parameters:
elementObj - the XML element object to be used.
Throws:
QWRecordException - if the given object is null.

QWRecord

public QWRecord(java.lang.String dataStr,
                Archivable.Marker mkrObj)
         throws QWRecordException
Creates a record object from the archived-string data for an XML record.

Parameters:
dataStr - the archived-string data to use.
mkrObj - Archivable.Marker parameter to indicate that this constructor is used to dearchive a record.
Throws:
QWRecordException - if an error occurs while creating the data record.
Method Detail

equals

public boolean equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this one.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the reference object with which to compare.
Returns:
true if this object is the same as the obj argument; false otherwise.

getCurrentElement

public org.jdom.Element getCurrentElement()
Returns the current XML element for this record.

Returns:
The current 'Element' object for this record.

getAttribStr

protected java.lang.String getAttribStr(java.lang.String nameStr)
                                 throws QWRecordException
Returns the value of an attribute in the current element.

Parameters:
nameStr - the name of the attribute.
Returns:
The value string.
Throws:
QWRecordException - if the named attribute was not found.

getAttribDouble

protected double getAttribDouble(java.lang.String nameStr)
                          throws QWRecordException
Returns the floating-point value of an attribute in the current element.

Parameters:
nameStr - the name of the attribute.
Returns:
The numeric value from the attribute.
Throws:
QWRecordException - if the named attribute was not found or if its value could not be converted.

getAttribInteger

protected int getAttribInteger(java.lang.String nameStr)
                        throws QWRecordException
Returns the integer value of an attribute in the current element.

Parameters:
nameStr - the name of the attribute.
Returns:
The numeric value from the attribute.
Throws:
QWRecordException - if the named attribute was not found or if its value could not be converted.

getAttribLong

protected long getAttribLong(java.lang.String nameStr)
                      throws QWRecordException
Returns the long integer value of an attribute in the current element.

Parameters:
nameStr - the name of the attribute.
Returns:
The numeric value from the attribute.
Throws:
QWRecordException - if the named attribute was not found or if its value could not be converted.

getAttribTime

protected java.util.Date getAttribTime(java.lang.String nameStr)
                                throws QWRecordException
Returns the date/time value of an attribute in the current element.

Parameters:
nameStr - the name of the attribute.
Returns:
A new 'Date' object holding the date/time value.
Throws:
QWRecordException - if the named attribute was not found or if its value could not be converted.

getOptAttribStr

protected java.lang.String getOptAttribStr(java.lang.String nameStr)
Returns the value of an attribute in the current element.

Parameters:
nameStr - the name of the attribute.
Returns:
The value string, or null if the named attribute was not found.

getNonNullOptAttribStr

protected java.lang.String getNonNullOptAttribStr(java.lang.String nameStr)
Returns the value of an attribute in the current element.

Parameters:
nameStr - the name of the attribute.
Returns:
The value string, or an empty string if the named attribute was not found.

getOptAttribDouble

protected java.lang.Double getOptAttribDouble(java.lang.String nameStr)
                                       throws QWRecordException
Returns the floating-point value of an optional attribute in the current element.

Parameters:
nameStr - the name of the attribute.
Returns:
A new Double object holding the value, or null if the attribute was not found.
Throws:
QWRecordException - if the attribute was found but its value could not be converted.

getOptAttribInteger

protected java.lang.Integer getOptAttribInteger(java.lang.String nameStr)
                                         throws QWRecordException
Returns the integer value of an optional attribute in the current element.

Parameters:
nameStr - the name of the attribute.
Returns:
A new Integer object holding the value, or null if the attribute was not found.
Throws:
QWRecordException - if the attribute was found but its value could not be converted.

getDefAttribBoolean

protected boolean getDefAttribBoolean(java.lang.String nameStr,
                                      boolean defaultValueFlag)
                               throws QWRecordException
Returns the boolean value of an optional attribute in the current element, or a default value if the attribute is not found.

Parameters:
nameStr - the name of the attribute.
defaultValueFlag - the default value to be returned if the given attribute is not found.
Returns:
the boolean value.
Throws:
QWRecordException - if the attribute was found but its value could not be converted.

getOptAttribBoolean

protected java.lang.Boolean getOptAttribBoolean(java.lang.String nameStr)
                                         throws QWRecordException
Returns the boolean value of an optional attribute in the current element, or null if the attribute is not found.

Parameters:
nameStr - the name of the attribute.
Returns:
A new Boolean object holding the value, or null if the attribute was not found.
Throws:
QWRecordException - if the attribute was found but its value could not be converted.

getOptAttribTime

protected java.util.Date getOptAttribTime(java.lang.String nameStr)
                                   throws QWRecordException
Returns the date/time value of an optional attribute in the current element.

Parameters:
nameStr - the name of the attribute.
Returns:
A new Date object holding the date/time value, or null if the attribute was not found.
Throws:
QWRecordException - if the attribute was found but its value could not be converted.

parseDataDouble

protected java.lang.Double parseDataDouble(java.lang.String nameStr,
                                           java.lang.String str)
                                    throws QWRecordException
Parses a floating-point numeric string.

Parameters:
nameStr - the name of the item in use (for error message generation).
str - the floating-point numeric string to parse (or null for none).
Returns:
A new Double object holding the value, or null if the 'str' parameter is null.
Throws:
QWRecordException - if the string could not be converted.

parseDataInteger

protected java.lang.Integer parseDataInteger(java.lang.String nameStr,
                                             java.lang.String str)
                                      throws QWRecordException
Parses an integer numeric string.

Parameters:
nameStr - the name of the item in use (for error message generation).
str - the floating-point numeric string to parse (or null for none).
Returns:
A new Integer object holding the value, or null if the 'str' parameter is null.
Throws:
QWRecordException - if the string could not be converted.

parseDataLong

protected java.lang.Long parseDataLong(java.lang.String nameStr,
                                       java.lang.String str)
                                throws QWRecordException
Parses a long integer numeric string.

Parameters:
nameStr - the name of the item in use (for error message generation).
str - the floating-point numeric string to parse (or null for none).
Returns:
A new Long object holding the value, or null if the 'str' parameter is null.
Throws:
QWRecordException - if the string could not be converted.

parseDataTime

protected java.util.Date parseDataTime(java.lang.String nameStr,
                                       java.lang.String str)
                                throws QWRecordException
Parses a date/time specification string.

Parameters:
nameStr - the name of the item in use (for error message generation).
str - the date/time string to parse (or null for none).
Returns:
A new Date object holding the date/time, or null if the 'str' parameter is null.
Throws:
QWRecordException - if the string could not be converted.

parseDataBoolean

protected java.lang.Boolean parseDataBoolean(java.lang.String nameStr,
                                             java.lang.String str)
                                      throws QWRecordException
Parses a boolean string.

Parameters:
nameStr - the name of the item in use (for error message generation).
str - the boolean string to parse (or null for none).
Returns:
A new Boolean object holding the value, or null if the 'str' parameter is null.
Throws:
QWRecordException - if the string could not be converted.

getOptTextDouble

protected final java.lang.Double getOptTextDouble()
                                           throws QWRecordException
Returns the floating-point value of the text for the current element.

Returns:
A new Double object holding the value, or null if the element text is empty.
Throws:
QWRecordException - if the string could not be converted.

getElementStr

protected java.lang.String getElementStr(java.lang.String nameStr)
                                  throws QWRecordException
Returns the value of a child element in the current element.

Parameters:
nameStr - the name of the child element.
Returns:
The value string.
Throws:
QWRecordException - if the child element was not found.

getElementDouble

protected double getElementDouble(java.lang.String nameStr)
                           throws QWRecordException
Returns the floating-point value of a child-element of the current element.

Parameters:
nameStr - the name of the element.
Returns:
The numeric value from the element.
Throws:
QWRecordException - if the named element was not found or if its value could not be converted.

getElementInteger

protected int getElementInteger(java.lang.String nameStr)
                         throws QWRecordException
Returns the integer value of a child-element of the current element.

Parameters:
nameStr - the name of the element.
Returns:
The numeric value from the element.
Throws:
QWRecordException - if the named element was not found or if its value could not be converted.

getElementLong

protected long getElementLong(java.lang.String nameStr)
                       throws QWRecordException
Returns the long integer value of a child-element of the current element.

Parameters:
nameStr - the name of the element.
Returns:
The numeric value from the element.
Throws:
QWRecordException - if the named element was not found or if its value could not be converted.

getElementTime

protected java.util.Date getElementTime(java.lang.String nameStr)
                                 throws QWRecordException
Returns the date/time value of a child-element of the current element.

Parameters:
nameStr - the name of the element.
Returns:
A new 'Date' object holding the date/time value.
Throws:
QWRecordException - if the named element was not found or if its value could not be converted.

getOptElementStr

protected java.lang.String getOptElementStr(java.lang.String nameStr)
Returns the value of a child element in the current element.

Parameters:
nameStr - the name of the child element.
Returns:
The value string, or null if the named child element was not found.

getNonNullOptElementStr

protected java.lang.String getNonNullOptElementStr(java.lang.String nameStr)
Returns the value of a child element in the current element.

Parameters:
nameStr - the name of the child element.
Returns:
The value string, or an empty string if the named child element was not found.

getOptElementDouble

protected java.lang.Double getOptElementDouble(java.lang.String nameStr)
                                        throws QWRecordException
Returns the floating-point value of an optional child-element of the current element.

Parameters:
nameStr - the name of the element.
Returns:
A new Double object holding the value, or null if the element was not found.
Throws:
QWRecordException - if the element was found but its value could not be converted.

getOptElementInteger

protected java.lang.Integer getOptElementInteger(java.lang.String nameStr)
                                          throws QWRecordException
Returns the integer value of an optional child-element of the current element.

Parameters:
nameStr - the name of the element.
Returns:
A new Integer object holding the value, or null if the element was not found.
Throws:
QWRecordException - if the element was found but its value could not be converted.

getOptElementTime

protected java.util.Date getOptElementTime(java.lang.String nameStr)
                                    throws QWRecordException
Returns the date/time value of an optional child-element of the current element.

Parameters:
nameStr - the name of the element.
Returns:
A new Date object holding the date/time value, or null if the element was not found.
Throws:
QWRecordException - if the element was found but its value could not be converted.

getDefElementBoolean

protected boolean getDefElementBoolean(java.lang.String nameStr,
                                       boolean defaultValueFlag)
                                throws QWRecordException
Returns the boolean value of an optional element in the current element, or a default value if the element is not found.

Parameters:
nameStr - the name of the element.
defaultValueFlag - the default value to be returned if the given element is not found.
Returns:
the boolean value.
Throws:
QWRecordException - if the element was found but its value could not be converted.

getOptElementBoolean

protected java.lang.Boolean getOptElementBoolean(java.lang.String nameStr)
                                          throws QWRecordException
Returns the boolean value of an optional element in the current element, or null if the element is not found.

Parameters:
nameStr - the name of the element.
Returns:
A new Boolean object holding the value, or null if the element was not found.
Throws:
QWRecordException - if the element was found but its value could not be converted.

getElementValueStr

protected java.lang.String getElementValueStr(java.lang.String nameStr)
                                       throws QWRecordException
Returns the text of the child element 'value' in a child element in the current element.

Parameters:
nameStr - the name of the child element.
Returns:
The value string.
Throws:
QWRecordException - if the child element or 'value' element was not found.

getElementValueDouble

protected double getElementValueDouble(java.lang.String nameStr)
                                throws QWRecordException
Returns the floating-point value of the child element 'value' in a child-element of the current element.

Parameters:
nameStr - the name of the element.
Returns:
The numeric value from the element.
Throws:
QWRecordException - if the named element or 'value' element was not found or if its value could not be converted.

getElementValueTime

protected java.util.Date getElementValueTime(java.lang.String nameStr)
                                      throws QWRecordException
Returns the date/time value of the child element 'value' in a child-element of the current element.

Parameters:
nameStr - the name of the element.
Returns:
A new 'Date' object holding the date/time value.
Throws:
QWRecordException - if the named element or 'value' element was not found or if its value could not be converted.

getOptElementValueDouble

protected java.lang.Double getOptElementValueDouble(java.lang.String nameStr)
                                             throws QWRecordException
Returns the floating-point value of the child element 'value' in an optional child-element of the current element.

Parameters:
nameStr - the name of the element.
Returns:
A new Double object holding the value, or null if the element was not found.
Throws:
QWRecordException - if the element was found but its value could not be converted.

getChildElementStr

public java.lang.String getChildElementStr(java.lang.String elemNameStr,
                                           java.lang.String childNameStr,
                                           java.lang.String nsPrefixStr)
Returns the value of a sub-child element under a child element in the current element.

Parameters:
elemNameStr - name of child element.
childNameStr - name of sub-child element.
nsPrefixStr - namespace-prefix string for sub-child element, or null to use same namespace as parent.
Returns:
The value string, or null if the named child elements were not found.

getChildElementStr

public java.lang.String getChildElementStr(java.lang.String elemNameStr,
                                           java.lang.String childNameStr)
Returns the value of a sub-child element under a child element in the current element.

Parameters:
elemNameStr - name of child element.
childNameStr - name of sub-child element.
Returns:
The value string, or null if the named child elements were not found.

getChildElementInteger

public java.lang.Integer getChildElementInteger(java.lang.String elemNameStr,
                                                java.lang.String childNameStr,
                                                java.lang.String nsPrefixStr)
                                         throws QWRecordException
Returns the integer value of a sub-child element under a child element in the current element.

Parameters:
elemNameStr - name of child element.
childNameStr - name of sub-child element.
nsPrefixStr - namespace-prefix string for sub-child element, or null to use same namespace as parent.
Returns:
The value string, or null if the named child elements were not found.
Throws:
QWRecordException - if the element was found but its value could not be converted.

getChildElementInteger

public java.lang.Integer getChildElementInteger(java.lang.String elemNameStr,
                                                java.lang.String childNameStr)
                                         throws QWRecordException
Returns the integer value of a sub-child element under a child element in the current element.

Parameters:
elemNameStr - name of child element.
childNameStr - name of sub-child element.
Returns:
The value string, or null if the named child elements were not found.
Throws:
QWRecordException - if the element was found but its value could not be converted.

getChildElementDouble

public java.lang.Double getChildElementDouble(java.lang.String elemNameStr,
                                              java.lang.String childNameStr,
                                              java.lang.String nsPrefixStr)
                                       throws QWRecordException
Returns the double value of a sub-child element under a child element in the current element.

Parameters:
elemNameStr - name of child element.
childNameStr - name of sub-child element.
nsPrefixStr - namespace-prefix string for sub-child element, or null to use same namespace as parent.
Returns:
The value string, or null if the named child elements were not found.
Throws:
QWRecordException - if the element was found but its value could not be converted.

getChildElementDouble

public java.lang.Double getChildElementDouble(java.lang.String elemNameStr,
                                              java.lang.String childNameStr)
                                       throws QWRecordException
Returns the double value of a sub-child element under a child element in the current element.

Parameters:
elemNameStr - name of child element.
childNameStr - name of sub-child element.
Returns:
The value string, or null if the named child elements were not found.
Throws:
QWRecordException - if the element was found but its value could not be converted.