Source Code Cross Referenced for Extension.java in  » Scripting » jacl » tcl » lang » 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 » jacl » tcl.lang 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Extension.java --
003:         *
004:         * Copyright (c) 1997 Cornell University.
005:         * Copyright (c) 1997 Sun Microsystems, Inc.
006:         *
007:         * See the file "license.terms" for information on usage and
008:         * redistribution of this file, and for a DISCLAIMER OF ALL
009:         * WARRANTIES.
010:         * 
011:         * RCS: @(#) $Id: Extension.java,v 1.5 2006/04/13 07:36:50 mdejong Exp $
012:         *
013:         */
014:
015:        package tcl.lang;
016:
017:        /**
018:         * Base class for all Tcl Extensions. A Tcl Extension defines a set of
019:         * commands that can be loaded into an Interp as a single unit.
020:         *
021:         * When a Tcl Extension is loaded into an Interp, either statically
022:         * (using the "new" operator inside Java code) or dynamically (using
023:         * the java::load command in Tcl scripts), it usually creates a set of
024:         * commands inside the interpreter. Occasionally, loading an Extension
025:         * may lead to additional side effects. For example, a communications
026:         * Extension may open network connections when it's loaded. Please
027:         * refer to the documentation of the specific Extension for details.
028:         */
029:
030:        abstract public class Extension {
031:
032:            /**
033:             * Default constructor. Does nothing. The purpose of this
034:             * constructor is to make sure instances of this Extension can be
035:             * loaded dynamically using the "java::load" command, which calls
036:             * Class.newInstance().
037:             */
038:
039:            public Extension() {
040:            }
041:
042:            /**
043:             * Initialize the Extension to run in a normal (unsafe)
044:             * interpreter. This usually means creating all the commands
045:             * provided by this class. A particular implementation can arrange
046:             * the commands to be loaded on-demand using the loadOnDemand()
047:             * function.
048:             *
049:             * @param interp current interpreter.
050:             */
051:
052:            abstract public void init(Interp interp) throws TclException;
053:
054:            /**
055:             * Initialize the Extension to run in a safe interpreter.  This
056:             * method should be written carefully, so that it initializes the
057:             * safe interpreter only with partial functionality provided by
058:             * the Extension that is safe for use by untrusted code.
059:             *
060:             * The default implementation always throws a TclException, so that
061:             * a subclass of Extension cannot be loaded into a safe interpreter
062:             * unless it has overridden the safeInit() method.
063:             *
064:             * @param safeInterp the safe interpreter in which the Extension should
065:             *     be initialized.
066:             */
067:
068:            public void safeInit(Interp safeInterp) throws TclException {
069:                throw new TclException(safeInterp, "Extension \""
070:                        + getClass().toString()
071:                        + "\" cannot be loaded into a safe interpreter");
072:            }
073:
074:            /**
075:             * Create a stub command which autoloads the real command the first time
076:             * the stub command is invoked. Register the stub command in the	
077:             * interpreter.
078:             *
079:             * @param interp current interp.
080:             * @param cmdName name of the command, e.g., "after".
081:             * @param clsName name of the Java class that implements this command,
082:             *     e.g. "tcl.lang.AfterCmd"
083:             */
084:
085:            public static final void loadOnDemand(Interp interp,
086:                    String cmdName, String clsName) {
087:                interp.createCommand(cmdName, new AutoloadStub(clsName));
088:            }
089:        }
090:
091:        /**
092:         * The purpose of AutoloadStub is to load-on-demand the classes that
093:         * implement Tcl commands. This reduces Jacl start up time and, when
094:         * running Jacl off a web page, reduces download time significantly.
095:         */
096:
097:        class AutoloadStub implements  Command {
098:            String className;
099:
100:            /**
101:             * Create a stub command which autoloads the real command the first time
102:             * the stub command is invoked.
103:             *
104:             * @param clsName name of the Java class that implements this command,
105:             *     e.g. "tcl.lang.AfterCmd"
106:             */
107:            AutoloadStub(String clsName) {
108:                className = clsName;
109:            }
110:
111:            /**
112:             * Load the class that implements the given command and execute it.
113:             *
114:             * @param interp the current interpreter.
115:             * @param argv command arguments.
116:             * @exception TclException if error happens inside the real command proc.
117:             */
118:            public void cmdProc(Interp interp, TclObject[] objv)
119:                    throws TclException {
120:                Command cmd = load(interp, objv[0].toString());
121:                cmd.cmdProc(interp, objv);
122:            }
123:
124:            /**
125:             * Load the class that implements the given command, create
126:             * the command in the interpreter, and return. This helper
127:             * method is provided so to handle the case where a command
128:             * wants to create a stub command without executing it.
129:             * The qname argument should be the fully qualified name
130:             * of the command.
131:             */
132:
133:            Command load(Interp interp, String qname) throws TclException {
134:                Class cmdClass = null;
135:                Command cmd;
136:
137:                try {
138:                    TclClassLoader classLoader = (TclClassLoader) interp
139:                            .getClassLoader();
140:                    cmdClass = classLoader.loadClass(className);
141:                } catch (ClassNotFoundException e) {
142:                    throw new TclException(interp,
143:                            "ClassNotFoundException for class \"" + className
144:                                    + "\"");
145:                } catch (PackageNameException e) {
146:                    throw new TclException(interp,
147:                            "PackageNameException for class \"" + className
148:                                    + "\"");
149:                }
150:
151:                try {
152:                    cmd = (Command) cmdClass.newInstance();
153:                } catch (IllegalAccessException e1) {
154:                    throw new TclException(interp,
155:                            "IllegalAccessException for class \""
156:                                    + cmdClass.getName() + "\"");
157:                } catch (InstantiationException e2) {
158:                    throw new TclException(interp,
159:                            "InstantiationException for class \""
160:                                    + cmdClass.getName() + "\"");
161:                } catch (ClassCastException e3) {
162:                    throw new TclException(interp,
163:                            "ClassCastException for class \""
164:                                    + cmdClass.getName() + "\"");
165:                }
166:                interp.createCommand(qname, cmd);
167:                return cmd;
168:            }
169:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.