AttributeFormatting
Class DateAttributeHandler

java.lang.Object
  extended by com.wrq.vhi.script.api.AttributeEventHandler
      extended by AttributeFormatting.DateAttributeHandler
All Implemented Interfaces:
com.wrq.vhi.script.api.EventHandler

public class DateAttributeHandler
extends com.wrq.vhi.script.api.AttributeEventHandler

This example illustrates how to use an event handler to read and reformat an attribute before it is sent to the client application. This is done by:

  1. Using the defaultReadAttribute method provided by the event object to read the attribute as it is displayed by the host application, and
  2. Sending the attribute value to a method in a DateFormatter instance to reformat the date into the desired form.

The source code for the DateFormatter class is stored in the shared examples directory. The Jar file containing the class is copied into this example's lib directory by the ant build file.

What's different about this example is that the date formatter instance is created as a static variable within this class. When this class is loaded, the formatter static variable is created. The initialization parameters for the formatter tell it the host date syntax, and the era within which two-digit years are assumed to fall.

If you wanted to handle other two-digit dates with different separator characters, or within a different era, you would define a different attribute (or field) handler which would create a different DateFormatter instance initialized to handle that other kind of date.

When you look at the source code for the DateFormatter class, notice that the instance variables are all defined as final. This means that the only data changed by that class's methods are either parameters or local to each method; the methods are thread-safe.


Field Summary
static java.lang.String description
           
private static DateFormatter formatter
          This instance of DateFormatter is used to reformat dates in this application.
 
Fields inherited from interface com.wrq.vhi.script.api.EventHandler
DEFAULT_TIMEOUT
 
Constructor Summary
DateAttributeHandler()
           
 
Method Summary
 java.lang.String readAttribute(com.wrq.vhi.script.api.ReadAttributeEvent event)
          Called by the Host Integrator server to read the attribute.
 
Methods inherited from class com.wrq.vhi.script.api.AttributeEventHandler
writeAttribute
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

description

public static final java.lang.String description
See Also:
Constant Field Values

formatter

private static final DateFormatter formatter
This instance of DateFormatter is used to reformat dates in this application.

The first two-digit year is assumed to be 1970. Dates from "70" to "99" are assumed to be 1970-1999; dates from "00" to "69" are assumed to be 2000 to 2069.

The month, day, and year displayed by the host application are separated by "-" characters.

Constructor Detail

DateAttributeHandler

public DateAttributeHandler()
Method Detail

readAttribute

public java.lang.String readAttribute(com.wrq.vhi.script.api.ReadAttributeEvent event)
                               throws com.wrq.apptrieve.agent.ApptrieveException
Called by the Host Integrator server to read the attribute.

This attribute converts a single month, day, year string into a standard output form, and also converts 2- to 4-digit years.

Overrides:
readAttribute in class com.wrq.vhi.script.api.AttributeEventHandler
Parameters:
event - the event instance
Returns:
the attribute value
Throws:
com.wrq.apptrieve.agent.ApptrieveException