KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > debug > watchesfiltering > JspElWatch


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.web.debug.watchesfiltering;
21
22 import org.netbeans.api.debugger.Watch;
23 import org.netbeans.api.debugger.jpda.InvalidExpressionException;
24 import org.netbeans.api.debugger.jpda.Variable;
25 import org.netbeans.api.debugger.jpda.JPDADebugger;
26 import org.openide.util.WeakListeners;
27
28 import java.beans.PropertyChangeListener JavaDoc;
29 import java.beans.PropertyChangeEvent JavaDoc;
30
31 /**
32  * Represents a JSP EL watch.
33  *
34  * @author Maros Sandor
35  */

36 public class JspElWatch implements PropertyChangeListener JavaDoc {
37
38     private final Watch watch;
39     
40     private boolean evaluated = false;
41     private JPDADebugger debugger;
42     private Variable variable;
43     private Exception JavaDoc exception;
44
45     public JspElWatch(Watch w, JPDADebugger debugger) {
46         watch = w;
47         this.debugger = debugger;
48         w.addPropertyChangeListener((PropertyChangeListener JavaDoc) WeakListeners.create(PropertyChangeListener JavaDoc.class, this, w));
49     }
50
51     public String JavaDoc getExpression () {
52         return watch.getExpression();
53     }
54
55     public String JavaDoc getType() {
56         if (!evaluated) {
57             evaluate();
58         }
59         return variable == null ? "" : variable.getType();
60     }
61
62     public String JavaDoc getValue() {
63         if (!evaluated) {
64             evaluate();
65         }
66         return variable == null ? "" : variable.getValue();
67     }
68
69     public String JavaDoc getExceptionDescription() {
70         if (!evaluated) {
71             evaluate();
72         }
73         return exception == null ? null : exception.getMessage();
74     }
75
76     public String JavaDoc getToStringValue() throws InvalidExpressionException {
77         return getValue().toString();
78     }
79
80     public Watch getWatch() {
81         return watch;
82     }
83     
84     private synchronized void evaluate() {
85         String JavaDoc text = watch.getExpression ();
86         text = org.openide.util.Utilities.replaceString(text, "\"", "\\\"");
87         text = "pageContext.getExpressionEvaluator().evaluate(\"" + text +
88                             "\", java.lang.String.class, (javax.servlet.jsp.PageContext)pageContext, null)";
89         try {
90             variable = debugger.evaluate(text);
91             exception = null;
92         } catch (Exception JavaDoc e) {
93             exception = e;
94         } finally {
95             evaluated = true;
96         }
97     }
98
99     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
100         setUnevaluated();
101     }
102     
103     public void setUnevaluated() {
104         evaluated = false;
105     }
106 }
107
Popular Tags