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 ; 8 import javax.servlet.http.HttpServletResponse ; 9 import java.io.Writer ; 10 import java.util.ArrayList ; 11 import java.util.Iterator ; 12 import java.util.List ; 13 import java.util.Map ; 14 15 20 public class Debug extends UIBean { 21 public static final String TEMPLATE = "debug"; 22 23 public Debug(OgnlValueStack stack, HttpServletRequest request, HttpServletResponse response) { 24 super(stack, request, response); 25 } 26 27 protected String getDefaultTemplate() { 28 return TEMPLATE; 29 } 30 31 public void start(Writer writer) { 32 super.start(writer); 33 34 OgnlValueStack stack = getStack(); 35 Iterator iter = stack.getRoot().iterator(); 36 List stackValues = new ArrayList (stack.getRoot().size()); 37 while (iter.hasNext()) { 38 Object o = iter.next(); 39 Map values; 40 try { 41 values = OgnlUtil.getBeanMap(o); 42 } catch (Exception e) { 43 throw new RuntimeException ("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 { 52 private Object key; 53 private Object value; 54 55 DebugMapEntry(Object key, Object value) { 56 this.key = key; 57 this.value = value; 58 } 59 60 public Object getKey() { 61 return key; 62 } 63 64 public Object getValue() { 65 return value; 66 } 67 68 public Object setValue(Object newVal) { 69 Object oldVal = value; 70 value = newVal; 71 return oldVal; 72 } 73 } 74 75 } 76 | Popular Tags |