com.alien.enterpriseRFID.tags
Class TagUtil

java.lang.Object
  extended bycom.alien.enterpriseRFID.tags.TagUtil

public class TagUtil
extends java.lang.Object

TagUtils provides utility methods for parsing XML- and text-based taglists from the reader into Tags and arrays of Tags.

Version:
1.8 Mar 2013 The ${Dir} token can now be "0", as well as "+" or "-". Also backslash-escaped the "+", in case the regexp got confused., 1.7 Nov 2012 Started keeping this changelog.
Author:
David Krull

Constructor Summary
TagUtil()
          Constructor is not required, since all fields and methods are declared static.
 
Method Summary
static Tag decodeCustomTag(java.lang.String tagLine)
           
static Tag[] decodeCustomTagList(java.lang.String tagLines)
           
static Tag[] decodeCustomTagList(java.lang.String tagLines, java.lang.String customFormatString)
          Decodes a custom-formatted tag list message from a reader into an array of Tags.
static Tag decodeTag(java.lang.String tagLine)
          Decode a single text-based line of tag list data into a single Tag item.
static Tag[] decodeTagList(java.lang.String tagLines)
          Decodes a text-based tag list message from a reader into an array of Tags.
static Tag decodeXMLTag(java.lang.String xmlData)
          Decode an individual tag's information from an XML-based tag message.
static Tag[] decodeXMLTagList(java.lang.String xmlData)
          Decodes an XML-based tag list message from a reader into an array of Tags.
static java.lang.String getCustomFormatString()
           
static java.util.Date parseDate(java.lang.String dateString)
          Converts a date string from a reader into a Date object.
static java.util.Date parseDateAndTime(java.lang.String dateString)
          Converts a date+time string from a reader into a Date object.
static java.util.Date parseTime(java.lang.String timeString)
          Converts a time string from a reader into a Date object.
static void setCustomFormatString(java.lang.String customFormatString)
           
static java.lang.String taglistAsString(Tag[] taglist)
          Returns a string representation of an entire taglist, Tag[].
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TagUtil

public TagUtil()
Constructor is not required, since all fields and methods are declared static. For instance, to use the decodeXMLTagList() method, simply call TagUtil.decodeXMLTagList().

Method Detail

setCustomFormatString

public static void setCustomFormatString(java.lang.String customFormatString)

getCustomFormatString

public static java.lang.String getCustomFormatString()

decodeXMLTagList

public static Tag[] decodeXMLTagList(java.lang.String xmlData)
Decodes an XML-based tag list message from a reader into an array of Tags. The xmlData that is passed in should be of the form:
   <Alien-RFID-Tag-List>
     <Alien-RFID-Tag>
       <TagID>0203 0405 0607 0809</TagID>
       <DiscoveryTime>2003/12/09 16:16:16</DiscoveryTime>
       <LastSeenTime>2003/12/09 16:16:57</LastSeenTime>
       <Antenna>0</Antenna>
       <ReadCount>48</ReadCount>
       <Protocol>1</Protocol> (optional)
     </Alien-RFID-Tag>
     <Alien-RFID-Tag>
       <TagID>8000 8004 0000 003B</TagID>
       <DiscoveryTime>2003/12/09 16:16:16</DiscoveryTime>
       <LastSeenTime>2003/12/09 16:16:58</LastSeenTime>
       <Antenna>0</Antenna>
       <ReadCount>222</ReadCount>
       <Protocol>1</Protocol> (optional)
     </Alien-RFID-Tag>
   </Alien-RFID-Tag-List>
 

Parameters:
xmlData - the XML string to be parsed and decoded
Returns:
an array of Tag objects, or null if there are no tags in the list

decodeXMLTag

public static Tag decodeXMLTag(java.lang.String xmlData)
Decode an individual tag's information from an XML-based tag message. The tag information should be of the form:
    <Alien-RFID-Tag>
      <TagID>0203 0405 0607 0809</TagID>
      <DiscoveryTime>2003/12/09 16:16:16</DiscoveryTime>
      <LastSeenTime>2003/12/09 16:16:57</LastSeenTime>
      <Antenna>0</Antenna>
      <ReadCount>48</ReadCount>
      <Protocol>1</Protocol> (optional)
    </Alien-RFID-Tag>
 

Parameters:
xmlData - the XML string containing the Tag information to be parsed
Returns:
a single Tag object, or null if the tag could not be decoded

decodeTagList

public static Tag[] decodeTagList(java.lang.String tagLines)
Decodes a text-based tag list message from a reader into an array of Tags. The string data that is passed in should be of the form:
Tag:4000 0000 0000 0200, Disc:1985/06/17 06:19:35, Last:1985/06/17 06:19:30, Count:77, Ant:1, Proto:1
Tag:4000 0000 0000 0201, Disc:1985/06/17 06:19:34, Last:1985/06/17 06:19:30, Count:76, Ant:1, Proto:1

Parameters:
tagLines - the multi-line String containing text-based taglist data
Returns:
an array of Tag objects, or null if there is no valid tag data in the list

decodeTag

public static Tag decodeTag(java.lang.String tagLine)
Decode a single text-based line of tag list data into a single Tag item. The string data that is passed in should be of the form:
Tag:4000 0000 0000 0200, Disc:1985/06/17 06:19:35, Last:1985/06/17 06:19:30, Count:77, Ant:1, Proto:1

The only mandatory field is the TagID - other fields are optional.

Parameters:
tagLine - the line of text-based tag data to be parsed
Returns:
a Tag object or null if there is no valid tag data

decodeCustomTagList

public static Tag[] decodeCustomTagList(java.lang.String tagLines,
                                        java.lang.String customFormatString)
Decodes a custom-formatted tag list message from a reader into an array of Tags. The string data that is passed in should be of the form specified by customFormatString.

This method uses the supplied customFormatString as a template for parsing the tagLines.

Parameters:
tagLines - the multi-line String containing custom-formatted taglist data
Returns:
an array of Tag objects, or null if there is no valid tag data in the list

decodeCustomTagList

public static Tag[] decodeCustomTagList(java.lang.String tagLines)

decodeCustomTag

public static Tag decodeCustomTag(java.lang.String tagLine)

parseDateAndTime

public static java.util.Date parseDateAndTime(java.lang.String dateString)
Converts a date+time string from a reader into a Date object. It is assumed that the date+time string will strictly adhere to the format, yyyy/MM/dd HH:mm:ss or yyyy/MM/dd HH:mm:ss.SSS

Parameters:
dateString - the date+time string to be parsed
Returns:
the Date object, or null if parse error

parseDate

public static java.util.Date parseDate(java.lang.String dateString)
Converts a date string from a reader into a Date object. It is assumed that the date string will strictly adhere to the format, yyyy/MM/dd. The resulting date object will have a clock time of 00:00:00.

Parameters:
dateString - the date string to be parsed
Returns:
the Date object, or null if parse error

parseTime

public static java.util.Date parseTime(java.lang.String timeString)
Converts a time string from a reader into a Date object. It is assumed that the time string will strictly adhere to the format, HH:mm:ss or HH:mm:ss.SSS. The resulting date object will have a calendar date of 1/1/1970.

Parameters:
timeString - the time string to be parsed
Returns:
the Date object, or null if parse error

taglistAsString

public static java.lang.String taglistAsString(Tag[] taglist)
Returns a string representation of an entire taglist, Tag[].

Parameters:
taglist - the array of Tags to dump
Returns:
a string with one tag per line