Source Code Cross Referenced for BSFEngineImpl.java in  » Scripting » bsf-2.4.0 » org » apache » bsf » util » 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 » bsf 2.4.0 » org.apache.bsf.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2004,2004 The Apache Software Foundation.
003:         * 
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         * 
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.apache.bsf.util;
018:
019:        import java.beans.PropertyChangeEvent;
020:        import java.util.Vector;
021:
022:        import org.apache.bsf.BSFDeclaredBean;
023:        import org.apache.bsf.BSFEngine;
024:        import org.apache.bsf.BSFException;
025:        import org.apache.bsf.BSFManager;
026:
027:        /**
028:         * This is a base implementation of the BSFEngine interface which
029:         * engine implementations may choose to extend to get the basic 
030:         * methods of the interface implemented. 
031:         * <p>
032:         *
033:         * @author   Sanjiva Weerawarana
034:         * @author   Olivier Gruber (added original debugging support)
035:         */
036:
037:        public abstract class BSFEngineImpl implements  BSFEngine {
038:
039:            protected BSFManager mgr; // my manager
040:            protected String lang; // my language string
041:            protected Vector declaredBeans; // BSFDeclaredBeans
042:            protected String classPath;
043:            protected String tempDir;
044:            protected ClassLoader classLoader;
045:
046:            /**
047:             * Default impl of apply - calls eval ignoring parameters and returns
048:             * the result.
049:             */
050:            public Object apply(String source, int lineNo, int columnNo,
051:                    Object funcBody, Vector paramNames, Vector arguments)
052:                    throws BSFException {
053:                return eval(source, lineNo, columnNo, funcBody);
054:            }
055:
056:            /**
057:             * Default impl of compileApply - calls compileExpr ignoring parameters.
058:             */
059:            public void compileApply(String source, int lineNo, int columnNo,
060:                    Object funcBody, Vector paramNames, Vector arguments,
061:                    CodeBuffer cb) throws BSFException {
062:                compileExpr(source, lineNo, columnNo, funcBody, cb);
063:            }
064:
065:            /**
066:             * Default impl of compileExpr - generates code that'll create a new
067:             * manager, evaluate the expression, and return the value.
068:             */
069:            public void compileExpr(String source, int lineNo, int columnNo,
070:                    Object expr, CodeBuffer cb) throws BSFException {
071:                ObjInfo bsfInfo = cb.getSymbol("bsf");
072:
073:                if (bsfInfo == null) {
074:                    bsfInfo = new ObjInfo(BSFManager.class, "bsf");
075:                    cb.addFieldDeclaration("org.apache.bsf.BSFManager bsf = "
076:                            + "new org.apache.bsf.BSFManager();");
077:                    cb.putSymbol("bsf", bsfInfo);
078:                }
079:
080:                String evalString = bsfInfo.objName + ".eval(\"" + lang
081:                        + "\", ";
082:                evalString += "request.getRequestURI(), " + lineNo + ", "
083:                        + columnNo;
084:                evalString += "," + StringUtils.lineSeparator;
085:                evalString += StringUtils.getSafeString(expr.toString()) + ")";
086:
087:                ObjInfo oldRet = cb.getFinalServiceMethodStatement();
088:
089:                if (oldRet != null && oldRet.isExecutable()) {
090:                    cb.addServiceMethodStatement(oldRet.objName + ";");
091:                }
092:
093:                cb.setFinalServiceMethodStatement(new ObjInfo(Object.class,
094:                        evalString));
095:
096:                cb.addServiceMethodException("org.apache.bsf.BSFException");
097:            }
098:
099:            /**
100:             * Default impl of compileScript - generates code that'll create a new
101:             * manager, and execute the script.
102:             */
103:            public void compileScript(String source, int lineNo, int columnNo,
104:                    Object script, CodeBuffer cb) throws BSFException {
105:                ObjInfo bsfInfo = cb.getSymbol("bsf");
106:
107:                if (bsfInfo == null) {
108:                    bsfInfo = new ObjInfo(BSFManager.class, "bsf");
109:                    cb.addFieldDeclaration("org.apache.bsf.BSFManager bsf = "
110:                            + "new org.apache.bsf.BSFManager();");
111:                    cb.putSymbol("bsf", bsfInfo);
112:                }
113:
114:                String execString = bsfInfo.objName + ".exec(\"" + lang
115:                        + "\", ";
116:                execString += "request.getRequestURI(), " + lineNo + ", "
117:                        + columnNo;
118:                execString += "," + StringUtils.lineSeparator;
119:                execString += StringUtils.getSafeString(script.toString())
120:                        + ")";
121:
122:                ObjInfo oldRet = cb.getFinalServiceMethodStatement();
123:
124:                if (oldRet != null && oldRet.isExecutable()) {
125:                    cb.addServiceMethodStatement(oldRet.objName + ";");
126:                }
127:
128:                cb.setFinalServiceMethodStatement(new ObjInfo(void.class,
129:                        execString));
130:
131:                cb.addServiceMethodException("org.apache.bsf.BSFException");
132:            }
133:
134:            public void declareBean(BSFDeclaredBean bean) throws BSFException {
135:                throw new BSFException(BSFException.REASON_UNSUPPORTED_FEATURE,
136:                        "language " + lang
137:                                + " does not support declareBean(...).");
138:            }
139:
140:            /**
141:             * Default impl of execute - calls eval and ignores the result.
142:             */
143:            public void exec(String source, int lineNo, int columnNo,
144:                    Object script) throws BSFException {
145:                eval(source, lineNo, columnNo, script);
146:            }
147:
148:            /**
149:             * Default impl of interactive execution - calls eval and ignores the result.
150:             */
151:            public void iexec(String source, int lineNo, int columnNo,
152:                    Object script) throws BSFException {
153:                eval(source, lineNo, columnNo, script);
154:            }
155:
156:            /**
157:             * initialize the engine; called right after construction by 
158:             * the manager. Declared beans are simply kept in a vector and
159:             * that's it. Subclasses must do whatever they want with it.
160:             */
161:            public void initialize(BSFManager mgr, String lang,
162:                    Vector declaredBeans) throws BSFException {
163:
164:                this .mgr = mgr;
165:                this .lang = lang;
166:                this .declaredBeans = declaredBeans;
167:
168:                // initialize my properties from those of the manager. It'll send
169:                // propagate change events to me
170:                this .classPath = mgr.getClassPath();
171:                this .tempDir = mgr.getTempDir();
172:                this .classLoader = mgr.getClassLoader();
173:            }
174:
175:            /**
176:             * Receive property change events from the manager and update my fields
177:             * as needed.
178:             *
179:             * @param e PropertyChange event with the change data
180:             */
181:            public void propertyChange(PropertyChangeEvent e) {
182:                String name = e.getPropertyName();
183:                Object value = e.getNewValue();
184:
185:                if (name.equals("classPath")) {
186:                    classPath = (String) value;
187:                } else if (name.equals("tempDir")) {
188:                    tempDir = (String) value;
189:                } else if (name.equals("classLoader")) {
190:                    classLoader = (ClassLoader) value;
191:                }
192:            }
193:
194:            public void terminate() {
195:                mgr = null;
196:                declaredBeans = null;
197:                classLoader = null;
198:            }
199:
200:            public void undeclareBean(BSFDeclaredBean bean) throws BSFException {
201:                throw new BSFException(BSFException.REASON_UNSUPPORTED_FEATURE,
202:                        "language " + lang
203:                                + " does not support undeclareBean(...).");
204:            }
205:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.