KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JSX > NoSuchFieldHandler


1     //Extend this class to write your own handler.
2
//Note: the "fieldName" may be class-qualified (eg: ClassName.FieldName)
3
//and you will need to check for this explicitly.
4

5 package JSX;
6
7 public class NoSuchFieldHandler {
8     public NoSuchFieldHandler() {} //default constructor has package visibility
9
//field name mapper:
10
public String JavaDoc noSuchField(Class JavaDoc clazz, String JavaDoc fieldName)
11             throws NoSuchFieldException JavaDoc {
12         //Better to use a Hash instead, if need more, and for generality; but the
13
//best and simplest way to do few is:
14
//if (clazz==aaaaa.class) {
15
// if (fieldName.equals("xxxx1") {
16
// return "yyyy1";
17
// if (fieldName.equals("xxxx2") {
18
// return "yyyy2";
19
// }
20
//} else if (clazz==bbbb.class) {
21
// if (fieldName.equals("xxxx1") {
22
// return "yyyy1";
23
//}
24
throw new NoSuchFieldException JavaDoc("Couldn't find a mapping for field '"+fieldName+"', for class '"+clazz.getName()+"'");
25     }
26 /*
27     public void noSuchField(Class clazz, String fieldName, Object o) {
28         //handle it entirely in code here.
29     }
30 */

31 }
32
Free Books   Free Magazines  
Popular Tags