fc.util
Class ThreadLocalDateFormat

java.lang.Object
  extended by fc.util.ThreadLocalDateFormat

public final class ThreadLocalDateFormat
extends Object

Useful to store thread-local date format instances. This class is intended for servlets/molly pages. Instead of static get/set methods, this class must be instantiated and the instance methods used to get/set the calendar object. This allows multiple instances of this class in the webapp, with each instance being able to get/set a seperate calendar. [If the methods in this class were static, then only 1 calendar could be get/set per thread].

Each thread must remember to individually create a seperate calendar instance and store it via the set method. The usage idiom is:


//WebApp has a map of ThreadLocalDateFormat's and also a instance variable
//with a default ThreadLocalDateFormat
ThreadLocalDateFormat mydf = WebApp.getThreadLocalDateFormat("foo");

if (mydf.isNull())  {
        mydf.set(DateFormat.getInstance());
        }

DateFormat df = mydf.get();

Note, the lines in red are always needed every time this class is used.


Constructor Summary
ThreadLocalDateFormat()
           
 
Method Summary
 DateFormat get()
           
 boolean isNull()
           
static void main(String[] args)
           
 void set(DateFormat df)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThreadLocalDateFormat

public ThreadLocalDateFormat()
Method Detail

get

public DateFormat get()

set

public void set(DateFormat df)

isNull

public boolean isNull()

main

public static void main(String[] args)
                 throws Exception
Throws:
Exception