KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > wcf > format > FormatHandler


1 /*
2  * ====================================================================
3  * This software is subject to the terms of the Common Public License
4  * Agreement, available at the following URL:
5  * http://www.opensource.org/licenses/cpl.html .
6  * Copyright (C) 2003-2004 TONBELLER AG.
7  * All Rights Reserved.
8  * You must accept the terms of that agreement to use this software.
9  * ====================================================================
10  *
11  *
12  */

13 package com.tonbeller.wcf.format;
14
15 import java.util.List JavaDoc;
16 import java.util.Locale JavaDoc;
17
18
19 /**
20  * defines a parser/printer for user input/display
21  */

22 public interface FormatHandler {
23   /**
24    * sets the Locale that this handler should use
25    */

26   public void setLocale(Locale JavaDoc locale);
27
28   /**
29    * returns the name of the FormatHandler. Example "string" or "date".
30    */

31   public String JavaDoc getName();
32
33   /**
34    * format an object
35    * @param o the object to format
36    * @param pattern the format string to use. If null or empty string,
37    * the configured pattern for the locale will be used.
38    */

39   public String JavaDoc format(Object JavaDoc o, String JavaDoc pattern);
40
41   /**
42    * parse a String and create an object
43    * @param s the string, eg user input
44    * @param pattern the format string to use. If null or empty string,
45    * the configured pattern for the locale will be used.
46    */

47   public Object JavaDoc parse(String JavaDoc s, String JavaDoc pattern) throws FormatException;
48   
49   /**
50    * returns true if this handler can handle the given object
51    */

52   boolean canHandle(Object JavaDoc value);
53   
54   /**
55    * returns a native array of the data type. E.g., the int handler will return
56    * an int[] array.
57    * @param list contains wrapper objects (e.g. Integer)
58    */

59   Object JavaDoc toNativeArray(List JavaDoc list);
60
61   /**
62    * returns an array of wrapper objects. E.g., the int handler will return
63    * an Integer[] array containing Integer instances.
64    * @param value either a scalar wrapper object (e.g. Integer) or an array of native types (e.g. int[])
65    * @return an array of wrapper types, e.g. Integer[].
66    * If <code>value</code> is a scalar, the returned array
67    * contains <code>value</code> as its only element.
68    */

69   Object JavaDoc[] toObjectArray(Object JavaDoc value);
70   
71 }
Popular Tags