Source Code Cross Referenced for JXInterpreter.java in  » Swing-Library » OpenJX » org » openjx » core » 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 » Swing Library » OpenJX » org.openjx.core 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) 2007 Jared Alexander Spigner
003:         *
004:         * This library is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU Lesser General Public
006:         * License as published by the Free Software Foundation; either
007:         * version 2.1 of the License, or any later version.
008:         *
009:         * This library is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012:         * Lesser General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU Lesser General Public
015:         * License along with this library; if not, write to the Free Software
016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
017:         *
018:         * jspigner@openjx.org
019:         *
020:         * JXInterpreter.java
021:         *
022:         * Created on June 9, 2007, 11:19 PM
023:         *
024:         */
025:
026:        package org.openjx.core;
027:
028:        import java.lang.reflect.Constructor;
029:        import java.lang.reflect.Field;
030:        import java.lang.reflect.Method;
031:
032:        import javax.script.ScriptEngine;
033:        import javax.script.ScriptEngineManager;
034:
035:        import javax.swing.JOptionPane;
036:
037:        import org.openjx.conf.JXGLOBAL;
038:        import org.openjx.display.JXMessageBox;
039:
040:        /**
041:         * This class interprets the object stack into Java and executes it.
042:         *
043:         * @author Jared Spigner
044:         */
045:        public class JXInterpreter {
046:
047:            /** This is a reference to the Virtual Machine. */
048:            private VirtualMachine virtualMachine;
049:
050:            /** This is a reference to the ScriptEngine. */
051:            private ScriptEngine scriptEngine;
052:
053:            /** This is a reference to the ScriptEngineManager. */
054:            private ScriptEngineManager scriptEngineManager;
055:
056:            /** 
057:             * This the constructor for the JXInterpreter class.  It creates a new 
058:             * instance of JXInterpreter.
059:             *
060:             * @param vm is a reference to the virtual machine.
061:             */
062:            public JXInterpreter(VirtualMachine vm) {
063:                this .virtualMachine = vm;
064:            }
065:
066:            /**
067:             * This method executes a specific script.
068:             *
069:             * @param script is the script we want to execute.
070:             *
071:             * @return true on success, else false on failure.
072:             */
073:            public boolean executeScript(String script) {
074:                try {
075:                    if (script != null && !script.equals(""))
076:                        this .scriptEngine.eval(script);
077:                } catch (Exception e) {
078:                    new JXMessageBox(JOptionPane.ERROR_MESSAGE,
079:                            "Interpreter Error", e.getMessage(),
080:                            this .virtualMachine.getViewer());
081:                    return false;
082:                }
083:
084:                return true;
085:            }
086:
087:            /**
088:             * This method interprets individual elements of the stack.
089:             *
090:             * @param jxObject is the object we want to interpret.
091:             *
092:             * @return true on success, else false on failure.
093:             */
094:            public boolean interpretJXObject(JXObject jxObject) {
095:                if (JXGLOBAL.DEBUG_INTERPRET)
096:                    System.out.println("INTERPRET JXOBJECT: "
097:                            + jxObject.getName());
098:
099:                try {
100:                    Class c = null;
101:
102:                    try {
103:                        c = Class.forName("org.openjx.jx." + jxObject.getTAG()
104:                                + "CTL");
105:                    } catch (ClassNotFoundException e) {
106:                        try {
107:                            c = Class.forName(jxObject.getTAG() + "CTL");
108:                        } catch (ClassNotFoundException e2) {
109:                            new JXMessageBox(JOptionPane.ERROR_MESSAGE,
110:                                    "JXObject Interpretation Error",
111:                                    "Can not find class " + e.getMessage()
112:                                            + " or class " + e2.getMessage(),
113:                                    this .virtualMachine.getViewer());
114:                            return false;
115:                        }
116:                    }
117:
118:                    Class parameters[] = { VirtualMachine.class };
119:                    Constructor cr = c.getConstructor(parameters);
120:                    Object obj = cr.newInstance(this .virtualMachine);
121:
122:                    c = obj.getClass();
123:                    Class p[] = { JXObject.class };
124:                    Method method = c.getMethod("Interpret", p);
125:                    Object arguments[] = { jxObject };
126:                    return (Boolean) method.invoke(obj, arguments);
127:                } catch (Exception e) {
128:                    new JXMessageBox(JOptionPane.ERROR_MESSAGE,
129:                            "Interpreter Error", "Error interpreting class "
130:                                    + jxObject.getTAG() + "CTL, "
131:                                    + e.getMessage(), this .virtualMachine
132:                                    .getViewer());
133:                    return false;
134:                }
135:            }
136:
137:            /**
138:             * This method interprets the jxscript by walking the stack.
139:             * 
140:             * @param jxObject is the object we want to start interpretation with.
141:             *
142:             * @return true on success, else false on failure.
143:             */
144:            public boolean interpretScript(JXObject jxObject) {
145:                for (int i = 0; i < jxObject.getLength(); i++) {
146:                    JXObject tmpObject = jxObject.stack.elementAt(i);
147:
148:                    this .interpretScript(tmpObject);
149:                    this .interpretJXObject(tmpObject);
150:                }
151:
152:                return true;
153:            }
154:
155:            /**
156:             * This method interprets the jxscript by walking the stack.
157:             *
158:             * @param jxObject is the top level JXObject.
159:             *
160:             * @return true on success, else false on failure.
161:             */
162:            public boolean oldinterpretScript(JXObject jxObject) {
163:                for (int i = 0; i < jxObject.getLength(); i++) {
164:                    JXObject tmpObject = jxObject.stack.elementAt(i);
165:
166:                    this .interpretScript(tmpObject);
167:                    this .interpretJXObject(tmpObject);
168:                }
169:
170:                this .interpretJXObject(this .virtualMachine.stackObject);
171:
172:                return this .interpretScript(this .virtualMachine.stackObject);
173:
174:            }
175:
176:            /**
177:             * This method sets the script engine and script engine manager.  It also
178:             * makes the virtual machine available to the scripting language.
179:             *
180:             * @param se is the script engine we want to set.
181:             * @param sem is the script engine manager we want to set.
182:             */
183:            public void setScriptEngine(ScriptEngine se, ScriptEngineManager sem) {
184:
185:                this .scriptEngine = se;
186:                this .scriptEngineManager = sem;
187:
188:                this .scriptEngine.put("VM", this.virtualMachine);
189:            }
190:
191:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.