View Javadoc

1   
2   /*
3    * Copyright (C) 2005 by Arno Schumacher
4    *
5    * This file is part of net.sourceforge.servletspy
6    *
7    * net.sourceforge.servletspy is free software; you can redistribute
8    * it and/or modify it under the terms of the GNU General Public 
9    * License as published by the Free Software Foundation; either 
10   * version 2, or (at your option) any later version.
11   *
12   * net.sourceforge.servletspy is distributed in the hope that it will
13   * be useful, but WITHOUT ANY WARRANTY; without even the implied 
14   * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
15   * See the GNU General Public License for more details.
16   *
17   * You should have received a copy of the GNU General Public License
18   * along with this program; if not, write to the Free Software
19   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA 
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      /* (non-Javadoc)
48       * @see net.sourceforge.servletspy.ILifecycle#init(net.sourceforge.servletspy.config.Param[])
49       */
50      public void init(final Param[] params) {
51      }
52  
53      /* (non-Javadoc)
54       * @see net.sourceforge.servletspy.ILifecycle#destroy()
55       */
56      public void destroy() {
57      }
58  
59      /* (non-Javadoc)
60       * @see net.sourceforge.servletspy.IContextHandler#handle(net.sourceforge.servletspy.IContext)
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  }