Source Code Cross Referenced for JaclEngine.java in  » Scripting » bsf-2.4.0 » org » apache » bsf » engines » jacl » 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.engines.jacl 
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.engines.jacl;
018:
019:        import java.util.Vector;
020:
021:        import org.apache.bsf.BSFDeclaredBean;
022:        import org.apache.bsf.BSFException;
023:        import org.apache.bsf.BSFManager;
024:        import org.apache.bsf.util.BSFEngineImpl;
025:
026:        import tcl.lang.Interp;
027:        import tcl.lang.ReflectObject;
028:        import tcl.lang.TclDouble;
029:        import tcl.lang.TclException;
030:        import tcl.lang.TclInteger;
031:        import tcl.lang.TclObject;
032:        import tcl.lang.TclString;
033:
034:        /**
035:         * This is the interface to Scriptics's Jacl (Tcl) from the
036:         * Bean Scripting Framework.
037:         * <p>
038:         *
039:         * @author   Sanjiva Weerawarana
040:         */
041:
042:        public class JaclEngine extends BSFEngineImpl {
043:            /* the Jacl interpretor object */
044:            private Interp interp;
045:
046:            /**
047:             * 
048:             * @param method The name of the method to call.
049:             * @param args an array of arguments to be
050:             * passed to the extension, which may be either
051:             * Vectors of Nodes, or Strings.
052:             */
053:            public Object call(Object obj, String method, Object[] args)
054:                    throws BSFException {
055:                StringBuffer tclScript = new StringBuffer(method);
056:                if (args != null) {
057:                    for (int i = 0; i < args.length; i++) {
058:                        tclScript.append(" ");
059:                        tclScript.append(args[i].toString());
060:                    }
061:                }
062:                return eval("<function call>", 0, 0, tclScript.toString());
063:            }
064:
065:            /**
066:             * Declare a bean
067:             */
068:            public void declareBean(BSFDeclaredBean bean) throws BSFException {
069:                String expr = "set " + bean.name + " [bsf lookupBean \""
070:                        + bean.name + "\"]";
071:                eval("<declare bean>", 0, 0, expr);
072:            }
073:
074:            /**
075:             * This is used by an application to evaluate a string containing
076:             * some expression.
077:             */
078:            public Object eval(String source, int lineNo, int columnNo,
079:                    Object oscript) throws BSFException {
080:                String script = oscript.toString();
081:                try {
082:                    interp.eval(script);
083:                    TclObject result = interp.getResult();
084:                    Object internalRep = result.getInternalRep();
085:
086:                    // if the object has a corresponding Java type, unwrap it
087:                    if (internalRep instanceof  ReflectObject)
088:                        return ReflectObject.get(interp, result);
089:                    if (internalRep instanceof  TclString)
090:                        return result.toString();
091:                    if (internalRep instanceof  TclDouble)
092:                        return new Double(TclDouble.get(interp, result));
093:                    if (internalRep instanceof  TclInteger)
094:                        return new Integer(TclInteger.get(interp, result));
095:
096:                    return result;
097:                } catch (TclException e) {
098:                    throw new BSFException(BSFException.REASON_EXECUTION_ERROR,
099:                            "error while eval'ing Jacl expression: "
100:                                    + interp.getResult(), e);
101:                }
102:            }
103:
104:            /**
105:             * Initialize the engine.
106:             */
107:            public void initialize(BSFManager mgr, String lang,
108:                    Vector declaredBeans) throws BSFException {
109:                super .initialize(mgr, lang, declaredBeans);
110:
111:                // create interpreter
112:                interp = new Interp();
113:
114:                // register the extension that user's can use to get at objects
115:                // registered by the app
116:                interp.createCommand("bsf", new BSFCommand(mgr, this ));
117:
118:                // Make java functions be available to Jacl
119:                try {
120:                    interp.eval("jaclloadjava");
121:                } catch (TclException e) {
122:                    throw new BSFException(BSFException.REASON_OTHER_ERROR,
123:                            "error while loading java package: "
124:                                    + interp.getResult(), e);
125:                }
126:
127:                int size = declaredBeans.size();
128:                for (int i = 0; i < size; i++) {
129:                    declareBean((BSFDeclaredBean) declaredBeans.elementAt(i));
130:                }
131:            }
132:
133:            /**
134:             * Undeclare a previously declared bean.
135:             */
136:            public void undeclareBean(BSFDeclaredBean bean) throws BSFException {
137:                eval("<undeclare bean>", 0, 0, "set " + bean.name + " \"\"");
138:            }
139:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.