KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > util > WebWorkTypeConverter


1 package com.opensymphony.webwork.util;
2
3 import ognl.DefaultTypeConverter;
4
5 import java.util.Map JavaDoc;
6
7 /**
8  * Base class for type converters used in WebWork. This class provides two abstract
9  * methods that are used to convert both to and from strings -- the critical
10  * functionality that is core to WebWork's type coversion system.
11  * <p/>
12  * Type converts do not have to use this class. It is merely a helper
13  * base class.
14  */

15 public abstract class WebWorkTypeConverter extends DefaultTypeConverter {
16     public Object JavaDoc convertValue(Map JavaDoc context, Object JavaDoc o, Class JavaDoc toClass) {
17         if (toClass.equals(String JavaDoc.class)) {
18             return convertToString(context, o);
19         } else if (o instanceof String JavaDoc[]) {
20             return convertFromString(context, (String JavaDoc[]) o, toClass);
21         } else if (o instanceof String JavaDoc) {
22             return convertFromString(context, new String JavaDoc[]{(String JavaDoc) o}, toClass);
23         } else {
24             return super.convertValue(context, o, toClass);
25         }
26     }
27
28     /**
29      * Converts one or more String values to the specified class.
30      *
31      * @param context the action context
32      * @param values the String values to be converted, such as those submitted from an HTML form
33      * @param toClass the class to convert to
34      * @return the converted object
35      */

36     public abstract Object JavaDoc convertFromString(Map JavaDoc context, String JavaDoc[] values, Class JavaDoc toClass);
37
38     /**
39      * Converts the specified object to a String.
40      *
41      * @param context the action context
42      * @param o the object to be converted
43      * @return the converted String
44      */

45     public abstract String JavaDoc convertToString(Map JavaDoc context, Object JavaDoc o);
46 }
47
Popular Tags