KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > views > jsp > ui > Debug


1 package com.opensymphony.webwork.views.jsp.ui;
2
3 import com.opensymphony.webwork.components.UIBean;
4 import com.opensymphony.xwork.util.OgnlUtil;
5 import com.opensymphony.xwork.util.OgnlValueStack;
6
7 import javax.servlet.http.HttpServletRequest JavaDoc;
8 import javax.servlet.http.HttpServletResponse JavaDoc;
9 import java.io.Writer JavaDoc;
10 import java.util.ArrayList JavaDoc;
11 import java.util.Iterator JavaDoc;
12 import java.util.List JavaDoc;
13 import java.util.Map JavaDoc;
14
15 /**
16  * User: plightbo
17  * Date: Jul 30, 2005
18  * Time: 5:35:42 PM
19  */

20 public class Debug extends UIBean {
21     public static final String JavaDoc TEMPLATE = "debug";
22
23     public Debug(OgnlValueStack stack, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
24         super(stack, request, response);
25     }
26
27     protected String JavaDoc getDefaultTemplate() {
28         return TEMPLATE;
29     }
30
31     public void start(Writer JavaDoc writer) {
32         super.start(writer);
33
34         OgnlValueStack stack = getStack();
35         Iterator JavaDoc iter = stack.getRoot().iterator();
36         List JavaDoc stackValues = new ArrayList JavaDoc(stack.getRoot().size());
37         while (iter.hasNext()) {
38             Object JavaDoc o = iter.next();
39             Map JavaDoc values;
40             try {
41                 values = OgnlUtil.getBeanMap(o);
42             } catch (Exception JavaDoc e) {
43                 throw new RuntimeException JavaDoc("Caught an exception while getting the property values of " + o, e);
44             }
45             stackValues.add(new DebugMapEntry(o.getClass().getName(), values));
46         }
47
48         addParameter("stackValues", stackValues);
49     }
50
51     private class DebugMapEntry implements Map.Entry JavaDoc {
52         private Object JavaDoc key;
53         private Object JavaDoc value;
54
55         DebugMapEntry(Object JavaDoc key, Object JavaDoc value) {
56             this.key = key;
57             this.value = value;
58         }
59
60         public Object JavaDoc getKey() {
61             return key;
62         }
63
64         public Object JavaDoc getValue() {
65             return value;
66         }
67
68         public Object JavaDoc setValue(Object JavaDoc newVal) {
69             Object JavaDoc oldVal = value;
70             value = newVal;
71             return oldVal;
72         }
73     }
74
75 }
76
Popular Tags