1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package net.sourceforge.servletspy.handler.std;
23
24 import java.math.BigDecimal;
25 import java.math.BigInteger;
26 import java.util.Calendar;
27 import java.util.Currency;
28 import java.util.Date;
29 import java.util.Locale;
30 import java.util.TimeZone;
31
32 import net.sourceforge.servletspy.IContext;
33 import net.sourceforge.servletspy.IContextHandler;
34 import net.sourceforge.servletspy.config.Param;
35
36 /***
37 * @author arno schumacher
38 */
39 public final class PrimitivesHandler implements IContextHandler {
40
41 /*** The <i>primitive</i> objects. */
42 private static final Class[] PRIMITIVES = new Class[] {String.class,
43 Locale.class, Number.class, BigDecimal.class, BigInteger.class,
44 Boolean.class, Character.class, Class.class, Date.class,
45 Currency.class, Calendar.class, TimeZone.class};
46
47
48
49
50 public void init(final Param[] params) {
51 }
52
53
54
55
56 public void destroy() {
57 }
58
59
60
61
62 public void handle(final IContext context) throws Exception {
63 final Class subjectClass = context.getSubject().getClass();
64 if (subjectClass.isPrimitive()) {
65 context.setValue(String.valueOf(context.getSubject()));
66 return;
67 }
68 for (int i = 0; i < PRIMITIVES.length; i++) {
69 if (PRIMITIVES[i].isAssignableFrom(subjectClass)) {
70 context.setValue(String.valueOf(context.getSubject()));
71 return;
72 }
73 }
74 context.proceed();
75 }
76 }