Source Code Cross Referenced for SimpleInteractionsModel.java in  » IDE » DrJava » edu » rice » cs » drjava » model » repl » 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 » IDE » DrJava » edu.rice.cs.drjava.model.repl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*BEGIN_COPYRIGHT_BLOCK
002:         *
003:         * Copyright (c) 2001-2007, JavaPLT group at Rice University (javaplt@rice.edu)
004:         * All rights reserved.
005:         * 
006:         * Redistribution and use in source and binary forms, with or without
007:         * modification, are permitted provided that the following conditions are met:
008:         *    * Redistributions of source code must retain the above copyright
009:         *      notice, this list of conditions and the following disclaimer.
010:         *    * Redistributions in binary form must reproduce the above copyright
011:         *      notice, this list of conditions and the following disclaimer in the
012:         *      documentation and/or other materials provided with the distribution.
013:         *    * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
014:         *      names of its contributors may be used to endorse or promote products
015:         *      derived from this software without specific prior written permission.
016:         * 
017:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
018:         * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
019:         * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
020:         * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
021:         * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
022:         * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
023:         * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
024:         * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
025:         * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
026:         * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
027:         * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028:         *
029:         * This software is Open Source Initiative approved Open Source Software.
030:         * Open Source Initative Approved is a trademark of the Open Source Initiative.
031:         * 
032:         * This file is part of DrJava.  Download the current version of this project
033:         * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
034:         * 
035:         * END_COPYRIGHT_BLOCK*/
036:
037:        package edu.rice.cs.drjava.model.repl;
038:
039:        import java.io.File;
040:
041:        import edu.rice.cs.drjava.model.repl.newjvm.InterpreterJVM;
042:        import edu.rice.cs.drjava.model.repl.newjvm.ClassPathManager;
043:
044:        import edu.rice.cs.util.StringOps;
045:        import edu.rice.cs.util.swing.Utilities;
046:
047:        import edu.rice.cs.util.text.ConsoleDocument;
048:
049:        /** A simple implementation of InteractionsModel, which uses a DynamicJavaAdapter directly (in the same JVM) to 
050:         *  interpret code.  It can be used in a standalone interface, such as edu.rice.cs.drjava.ui.SimpleInteractionsWindow.
051:         *  @version $Id: SimpleInteractionsModel.java 4255 2007-08-28 19:17:37Z mgricken $
052:         */
053:        public class SimpleInteractionsModel extends InteractionsModel {
054:
055:            /** Milliseconds to wait after each println */
056:            protected static final int WRITE_DELAY = 5;
057:
058:            /** An interpreter to evaluate interactions. */
059:            protected JavaInterpreter _interpreter;
060:
061:            /** Creates a new InteractionsModel using a InteractionsDJDocument. */
062:            public SimpleInteractionsModel() {
063:                this (new InteractionsDJDocument());
064:            }
065:
066:            /** Creates a new InteractionsModel with the given document adapter.
067:             *  @param document Toolkit-independent document adapter
068:             */
069:            public SimpleInteractionsModel(InteractionsDJDocument document) {
070:                super (document, new File(System.getProperty("user.dir")), 1000,
071:                        WRITE_DELAY);
072:                _interpreter = new DynamicJavaAdapter(new ClassPathManager());
073:
074:                _interpreter.defineVariable("INTERPRETER", _interpreter);
075:            }
076:
077:            /**
078:             * Interprets the given command.
079:             * @param toEval command to be evaluated
080:             */
081:            protected void _interpret(String toEval) {
082:                try {
083:                    Object result = _interpreter.interpret(toEval);
084:                    if (result != Interpreter.NO_RESULT) {
085:                        append(
086:                                String.valueOf(result) + "\n" /* formerly StringOps.EOL*/,
087:                                InteractionsDocument.OBJECT_RETURN_STYLE);
088:                    }
089:                } catch (ExceptionReturnedException e) {
090:                    Throwable t = e.getContainedException();
091:                    // getStackTrace should be a utility method somewhere...
092:                    _document.appendExceptionResult(t.getClass().getName(), t
093:                            .getMessage(), InterpreterJVM.getStackTrace(t),
094:                            InteractionsDocument.DEFAULT_STYLE);
095:                } finally {
096:                    _interactionIsOver();
097:                }
098:            }
099:
100:            /**
101:             * Gets the string representation of the value of a variable in the current interpreter.
102:             * @param var the name of the variable
103:             */
104:            public String getVariableToString(String var) {
105:                Object value = _interpreter.getVariable(var);
106:                return value.toString();
107:            }
108:
109:            /**
110:             * Gets the class name of a variable in the current interpreter.
111:             * @param var the name of the variable
112:             */
113:            public String getVariableClassName(String var) {
114:                Class c = _interpreter.getVariableClass(var);
115:                return c.getName();
116:            }
117:
118:            /** Adds the given path to the interpreter's classpath.
119:             *  @param path Path to add
120:             */
121:            public void addProjectClassPath(File path) {
122:                _interpreter.addProjectClassPath(path);
123:            }
124:
125:            /** Adds the given path to the interpreter's classpath.
126:             *  @param path Path to add
127:             */
128:            public void addBuildDirectoryClassPath(File path) {
129:                _interpreter.addBuildDirectoryClassPath(path);
130:            }
131:
132:            /** Adds the given path to the interpreter's classpath.
133:             *  @param path Path to add
134:             */
135:            public void addProjectFilesClassPath(File path) {
136:                _interpreter.addProjectFilesClassPath(path);
137:            }
138:
139:            /** Adds the given path to the interpreter's classpath.
140:             *  @param path Path to add
141:             */
142:            public void addExternalFilesClassPath(File path) {
143:                _interpreter.addExternalFilesClassPath(path);
144:            }
145:
146:            /** Adds the given path to the interpreter's classpath.
147:             *  @param path Path to add
148:             */
149:            public void addExtraClassPath(File path) {
150:                _interpreter.addExtraClassPath(path);
151:            }
152:
153:            /** Defines a variable in the interpreter to the given value. */
154:            public void defineVariable(String name, Object value) {
155:                _interpreter.defineVariable(name, value);
156:            }
157:
158:            /** Defines a final variable in the interpreter to the given value. */
159:            public void defineConstant(String name, Object value) {
160:                _interpreter.defineConstant(name, value);
161:            }
162:
163:            /** Sets whether protected and private variables and methods can be accessed from within the interpreter. */
164:            public void setInterpreterPrivateAccessible(boolean accessible) {
165:                _interpreter.setPrivateAccessible(accessible);
166:            }
167:
168:            /** Any extra action to perform (beyond notifying listeners) when the interpreter fails to reset.
169:             *  @param t The Throwable thrown by System.exit
170:             */
171:            protected void _interpreterResetFailed(Throwable t) {
172:                _document.insertBeforeLastPrompt("Reset Failed!" + _newLine,
173:                        InteractionsDocument.ERROR_STYLE);
174:            }
175:
176:            /** Resets the Java interpreter. */
177:            protected void _resetInterpreter(File wd) {
178:                interpreterResetting();
179:                _interpreter = new DynamicJavaAdapter(new ClassPathManager());
180:                interpreterReady(wd);
181:            }
182:
183:            /** Notifies listeners that an interaction has started. */
184:            protected void _notifyInteractionStarted() {
185:                Utilities.invokeLater(new Runnable() {
186:                    public void run() {
187:                        _notifier.interactionStarted();
188:                    }
189:                });
190:            }
191:
192:            /** Notifies listeners that an interaction has ended. */
193:            protected void _notifyInteractionEnded() {
194:                Utilities.invokeLater(new Runnable() {
195:                    public void run() {
196:                        _notifier.interactionEnded();
197:                    }
198:                });
199:            }
200:
201:            /** Notifies listeners that an interaction contained a syntax error. */
202:            protected void _notifySyntaxErrorOccurred(final int offset,
203:                    final int length) {
204:                Utilities.invokeLater(new Runnable() {
205:                    public void run() {
206:                        _notifier.interactionErrorOccurred(offset, length);
207:                    }
208:                });
209:            }
210:
211:            /** Notifies listeners that the interpreter is resetting. */
212:            protected void _notifyInterpreterResetting() { /* do nothing */
213:            }
214:
215:            /** Notifies listeners that the interpreter is ready.  */
216:            public void _notifyInterpreterReady(File wd) {
217:                //  Ok, we don't need to do anything special
218:            }
219:
220:            /** Notifies listeners that the interpreter has exited unexpectedly.
221:             *  @param status Status code of the dead process
222:             */
223:            protected void _notifyInterpreterExited(final int status) {
224:                // Won't happen in a single JVM
225:            }
226:
227:            /** Notifies listeners that the interpreter reset failed. */
228:            protected void _notifyInterpreterResetFailed(Throwable t) {
229:                // Won't happen in a single JVM
230:            }
231:
232:            /** Notifies listeners that the interperaction was incomplete. */
233:            protected void _notifyInteractionIncomplete() {
234:                // Oh well.  Nothing to do.
235:            }
236:
237:            /** Notifies listeners that the slave JVM has been used. */
238:            protected void _notifySlaveJVMUsed() { /* do nothing; no slave JVM */
239:            }
240:
241:            /** Returns null because console tab document is not supported in this model */
242:            public ConsoleDocument getConsoleDocument() {
243:                return null;
244:            }
245:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.