Source Code Cross Referenced for JavaCmd.java in  » Scripting » hecl » org » hecl » java » 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 » hecl » org.hecl.java 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright 2007 David N. Welton - DedaSys LLC - http://www.dedasys.com
002:
003:           Licensed under the Apache License, Version 2.0 (the "License");
004:           you may not use this file except in compliance with the License.
005:           You may obtain a copy of the License at
006:
007:           http://www.apache.org/licenses/LICENSE-2.0
008:
009:           Unless required by applicable law or agreed to in writing, software
010:           distributed under the License is distributed on an "AS IS" BASIS,
011:           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012:           See the License for the specific language governing permissions and
013:           limitations under the License.
014:         */
015:
016:        package org.hecl.java;
017:
018:        import java.lang.reflect.InvocationTargetException;
019:
020:        import java.util.Enumeration;
021:        import java.util.Vector;
022:
023:        import org.hecl.ClassCommand;
024:        import org.hecl.ClassCommandInfo;
025:        import org.hecl.HeclException;
026:        import org.hecl.Interp;
027:        import org.hecl.IntThing;
028:        import org.hecl.ListThing;
029:        import org.hecl.ObjectThing;
030:        import org.hecl.Properties;
031:        import org.hecl.StringThing;
032:        import org.hecl.Thing;
033:        import java.util.Map;
034:
035:        /**
036:         * The <code>JavaCmd</code> class is utilized to implement Hecl
037:         * commands that can interact with Java classes.  The real work is
038:         * done in the Reflector class, which maps between Hecl and Java
039:         * types.
040:         *
041:         * @author <a href="mailto:davidw@dedasys.com">David N. Welton</a>
042:         * @version 1.0
043:         */
044:        public class JavaCmd implements  ClassCommand, org.hecl.Command {
045:            private static Vector commands = null;
046:
047:            private String cmdname = null;
048:            private Class this class = null;
049:            private Reflector classreflector = null;
050:
051:            public JavaCmd(String clsname, String cmd) throws HeclException {
052:
053:                classreflector = new Reflector(clsname);
054:                try {
055:                    this class = Class.forName(clsname);
056:                } catch (Exception e) {
057:                    //Hecl.logStacktrace(e);
058:                    throw new HeclException("Error trying to create " + clsname
059:                            + " : " + e.toString());
060:                }
061:            }
062:
063:            public Thing cmdCode(Interp interp, Thing[] argv)
064:                    throws HeclException {
065:                try {
066:                    String argv1 = argv[1].toString();
067:
068:                    /* These are for all the attributes like -text -height, etc... */
069:                    if (argv1.equals("-new")) {
070:                        MethodProps mp = new MethodProps();
071:                        mp.setProps(argv, 1);
072:
073:                        Thing[] targs;
074:                        Thing cargs = mp.getProp("-new");
075:
076:                        /* Instantiate a new one.  */
077:                        String thingclass = cargs.getVal().thingclass();
078:                        /* Be careful not to turn it into a list over and over again. */
079:                        if (thingclass.equals("list")
080:                                || thingclass.equals("string")) {
081:                            targs = ListThing.getArray(cargs);
082:                        } else {
083:                            targs = new Thing[] { cargs };
084:                        }
085:                        mp.delProp("-new");
086:
087:                        /* Create a new instance. */
088:                        Thing newthing = classreflector.instantiate(targs);
089:                        mp.evalProps(interp, ObjectThing.get(newthing),
090:                                classreflector);
091:                        return newthing;
092:                    } else if (argv1.equals("-field")) {
093:                        /* Access a field. */
094:                        return classreflector.getConstField(argv[2].toString());
095:                    } else if (argv1.equals("-methods")) {
096:                        return classreflector.methods();
097:                    } else {
098:                        /* Try calling a static method. */
099:                        return classreflector.evaluate(null, argv1, argv);
100:                    }
101:                    /* 	} catch (InvocationTargetException te) {
102:                     throw new HeclException("Constructor error: " + te.getTargetException().toString());  */
103:                } catch (Exception e) {
104:                    //	    Hecl.logStacktrace(e);
105:                    e.printStackTrace();
106:                    throw new HeclException(argv[0].toString() + " "
107:                            + argv[1].toString() + " error " + e.toString());
108:                }
109:            }
110:
111:            public Thing method(Interp interp, ClassCommandInfo context,
112:                    Thing[] argv) throws HeclException {
113:                if (argv.length > 1) {
114:                    Object target = ObjectThing.get(argv[0]);
115:                    String subcmd = argv[1].toString().toLowerCase();
116:                    if (subcmd.equals("-field")) {
117:                        /* Look for the field.  */
118:                        return classreflector.getField(target, argv[2]
119:                                .toString());
120:                    } else {
121:                        /* Invoke the method.  */
122:                        return classreflector.evaluate(target, subcmd, argv);
123:                    }
124:                }
125:                throw HeclException.createWrongNumArgsException(argv, 2,
126:                        "Object method [arg...]");
127:            }
128:
129:            public Class getCmdClass() {
130:                return this class;
131:            }
132:
133:            public String getCmdName() {
134:                return cmdname;
135:            }
136:
137:            public static void load(Interp ip, String cname, String cmd)
138:                    throws HeclException {
139:
140:                if (commands == null) {
141:                    commands = new Vector();
142:                }
143:                JavaCmd newjavacmd = new JavaCmd(cname, cmd);
144:                ip.addCommand(cmd, newjavacmd);
145:                ip.addClassCmd(newjavacmd.getCmdClass(), newjavacmd);
146:                commands.add(newjavacmd);
147:            }
148:
149:            public static void unload(Interp ip) {
150:                Enumeration e = commands.elements();
151:                while (e.hasMoreElements()) {
152:                    JavaCmd c = (JavaCmd) e.nextElement();
153:                    ip.removeCommand(c.getCmdName());
154:                    ip.removeClassCmd(c.getCmdClass());
155:                }
156:            }
157:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.