Source Code Cross Referenced for VisualDebuggerModel.java in  » Scripting » Pnuts » pnuts » tools » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Scripting » Pnuts » pnuts.tools 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#)VisualDebuggerModel.java 1.3 05/03/18
003:         * 
004:         * Copyright (c) 1997-2005 Sun Microsystems, Inc. All Rights Reserved.
005:         * 
006:         * See the file "LICENSE.txt" for information on usage and redistribution of
007:         * this file, and for a DISCLAIMER OF ALL WARRANTIES.
008:         */
009:        package pnuts.tools;
010:
011:        import java.io.PrintWriter;
012:        import java.util.Enumeration;
013:        import java.util.Hashtable;
014:        import java.util.Vector;
015:        import pnuts.lang.Context;
016:        import pnuts.lang.Pnuts;
017:        import pnuts.lang.PnutsException;
018:        import pnuts.lang.Runtime;
019:        import pnuts.lang.SimpleNode;
020:        import pnuts.lang.PnutsParserTreeConstants;
021:
022:        public class VisualDebuggerModel extends Runtime implements  Debugger {
023:            DebugContext dc;
024:            boolean quit;
025:            private Object currentSource;
026:            private int currentLine;
027:            private int n_nexts;
028:            private int n_steps;
029:            private int command;
030:            private Hashtable files; // source -> lines (break points)
031:            private boolean initialized = false;
032:            private int initialEvalDepth;
033:            private int initialCallDepth;
034:            private int e_depth;
035:            private int c_depth;
036:            private PrintWriter errorStream;
037:            private Object traceTag;
038:            private Context parent;
039:            private VisualDebuggerView view;
040:
041:            static final int OPEN = 1;
042:            static final int STEP = 2;
043:            static final int STEP_UP = 3;
044:            static final int NEXT = 4;
045:            static final int CONT = 5;
046:            static final int CLOSE = 6;
047:            static final int CLEAR_BP = 7;
048:            static final int INSPECT = 8;
049:
050:            public VisualDebuggerModel() {
051:                this .files = new Hashtable();
052:            }
053:
054:            void setView(VisualDebuggerView view) {
055:                this .view = view;
056:            }
057:
058:            void init(DebugContext dc) {
059:                quit = false;
060:                this .dc = dc;
061:                dc.setDebugger(this );
062:                initialEvalDepth = Pnuts.evalDepth(dc);
063:                e_depth = 0;
064:                c_depth = 0;
065:                n_steps = 1;
066:                n_nexts = 1;
067:            }
068:
069:            public synchronized void do_step(int n) {
070:                command = STEP;
071:                n_steps = n;
072:                notifyAll();
073:            }
074:
075:            public synchronized void do_stepup() {
076:                command = STEP_UP;
077:                c_depth = dc.getCallDepth();
078:                e_depth = dc.getEvalDepth();
079:                notifyAll();
080:            }
081:
082:            public synchronized void do_next(int n) {
083:                command = NEXT;
084:                n_nexts = n;
085:                notifyAll();
086:            }
087:
088:            public synchronized void do_cont() {
089:                command = CONT;
090:                n_steps = 0;
091:                n_nexts = 0;
092:                notifyAll();
093:            }
094:
095:            public synchronized void do_close() {
096:                command = CONT;
097:                quit = true;
098:                notifyAll();
099:            }
100:
101:            public Object getCurrentSource() {
102:                return currentSource;
103:            }
104:
105:            public void setBreakPoint(Object source, int lineno) {
106:                if (source == null) {
107:                    return;
108:                }
109:                Vector lines = (Vector) files.get(source);
110:                if (lines == null) {
111:                    lines = new Vector();
112:                    files.put(source, lines);
113:                }
114:                Integer i = new Integer(lineno + 1);
115:                if (!lines.contains(i)) {
116:                    lines.addElement(i);
117:                }
118:            }
119:
120:            public void removeBreakPoint(Object source, int lineno) {
121:                if (source == null) {
122:                    return;
123:                }
124:                Vector lines = (Vector) files.get(source);
125:                if (lines == null) {
126:                    return;
127:                }
128:                lines.removeElement(new Integer(lineno + 1));
129:            }
130:
131:            public Vector getBreakPoints(Object source) {
132:                if (source == null) {
133:                    return null;
134:                }
135:                return (Vector) files.get(source);
136:            }
137:
138:            public void clearBreakPoints() {
139:                files.clear();
140:            }
141:
142:            public void signal(CommandEvent event) {
143:                this .dc = (DebugContext) event.getSource();
144:
145:                int eventType = event.getType();
146:
147:                if (eventType == CommandEvent.EXITED) {
148:                    if (dc.getEvalDepth() <= initialEvalDepth
149:                            && dc.getCallDepth() <= initialCallDepth) {
150:                        if (!quit) {
151:                            showScript(dc.getScriptSource(), -1, null, dc);
152:                        }
153:                        initialized = false;
154:
155:                    }
156:                    return;
157:                }
158:
159:                if (eventType == CommandEvent.LINE_UPDATED) {
160:
161:                    SimpleNode node = (SimpleNode) event.getArg();
162:                    int beginLine = dc.getBeginLine();
163:                    int endLine = dc.getEndLine();
164:                    Object source = dc.getScriptSource();
165:
166:                    if (!initialized) {
167:                        init(dc);
168:                        initialized = true;
169:                        c_depth = dc.getCallDepth();
170:                        e_depth = dc.getEvalDepth();
171:                        initialCallDepth = dc.getCallDepth();
172:
173:                        showScript(source, beginLine, node, dc);
174:                        waitForCommands();
175:                        currentLine = beginLine;
176:                        return;
177:                    }
178:
179:                    if (hasToStop(source, node, beginLine, endLine)) {
180:                        c_depth = dc.getCallDepth();
181:                        e_depth = dc.getEvalDepth();
182:                        showScript(source, beginLine, node, dc);
183:                        waitForCommands();
184:                        currentLine = beginLine;
185:                    }
186:                } else if (eventType == CommandEvent.EXCEPTION) {
187:                    Throwable t = (Throwable) event.getArg();
188:                    if (t instanceof  PnutsException) {
189:                        PnutsException pe = (PnutsException) t;
190:                        Object source = pe.getScriptSource();
191:                        int beginLine = pe.getLine();
192:                        showScript(source, beginLine, null, dc);
193:                    }
194:                    initialized = false;
195:                }
196:            }
197:
198:            boolean checkBreakPoint(Vector lines, SimpleNode node, int begin,
199:                    int end) {
200:                if (node != null
201:                        && node.id == PnutsParserTreeConstants.JJTBLOCK) {
202:                    return false;
203:                }
204:                for (Enumeration e = lines.elements(); e.hasMoreElements();) {
205:                    int bp = ((Integer) e.nextElement()).intValue();
206:                    if (bp >= begin && bp <= end) {
207:                        return true;
208:                    }
209:                }
210:                return false;
211:            }
212:
213:            boolean hasToStop(Object source, SimpleNode node, int beginLine,
214:                    int endLine) {
215:                if (source instanceof  Runtime) {
216:                    return false;
217:                }
218:                if (source == null && node != null && command != CONT) {
219:                    return true;
220:                }
221:                if (command == OPEN) {
222:                    currentLine = beginLine;
223:                    command = 0;
224:                    return true;
225:                } else if (command == STEP) {
226:                    if (--n_steps < 1) {
227:                        return true;
228:                    }
229:                } else if (command == NEXT) {
230:                    int d1 = dc.getEvalDepth();
231:                    int d2 = dc.getCallDepth();
232:                    if (e_depth >= d1
233:                            && c_depth >= d2
234:                            && (currentSource != source || currentLine != beginLine)) {
235:                        if (--n_nexts < 1) {
236:                            return true;
237:                        }
238:                    }
239:                } else if (command == STEP_UP) {
240:                    int d1 = dc.getEvalDepth();
241:                    int d2 = dc.getCallDepth();
242:                    if (e_depth > d1 || e_depth >= d1 && c_depth > d2) {
243:                        return true;
244:                    }
245:                }
246:
247:                Vector lines = getBreakPoints(source);
248:
249:                if (lines != null
250:                        && checkBreakPoint(lines, node, beginLine, endLine)) {
251:                    currentLine = beginLine;
252:                    return true;
253:                }
254:
255:                return false;
256:            }
257:
258:            synchronized void waitForCommands() {
259:                command = 0;
260:                try {
261:                    while (command == 0) {
262:                        wait();
263:                    }
264:                } catch (InterruptedException e) {
265:                }
266:                if (quit) {
267:                    escape(null);
268:                }
269:            }
270:
271:            protected void showScript(Object source, int line, SimpleNode node,
272:                    Context context) {
273:                if (!quit && view != null) {
274:                    view.update(source, line, node, context);
275:                }
276:                currentSource = source;
277:            }
278:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.