01: /*
02: * Copyright (c) 2005 Advanced Micro Devices, Inc.
03: *
04: * See the file "license.amd" for information on usage and
05: * redistribution of this file, and for a DISCLAIMER OF ALL
06: * WARRANTIES.
07: *
08: * RCS: @(#) $Id: TJCCommandCmd.java,v 1.5 2006/06/04 20:35:21 mdejong Exp $
09: *
10: */
11:
12: package tcl.lang;
13:
14: public class TJCCommandCmd implements Command {
15:
16: // Implementation of TJC::command used to create
17: // compiled command instances at runtime.
18:
19: public void cmdProc(Interp interp, TclObject[] objv)
20: throws TclException {
21: if (objv.length != 3) {
22: throw new TclNumArgsException(interp, 1, objv,
23: "cmdname classname");
24: }
25: String cmdname = objv[1].toString();
26: String classname = objv[2].toString();
27:
28: // Create instance of named command
29: Class c = JavaInvoke.getClassByName(interp, classname);
30:
31: Object o = null;
32: try {
33: o = c.newInstance();
34: } catch (InstantiationException ie) {
35: throw new TclException(interp, "instance of class "
36: + classname + " could not be created");
37: } catch (IllegalAccessException iae) {
38: throw new TclException(interp, "instance of class "
39: + classname + " could not be created");
40: }
41: if (!(o instanceof TJC.CompiledCommand)) {
42: throw new TclException(interp, "class " + classname
43: + " must extend TJC.CompiledCommand");
44: }
45: TJC.CompiledCommand cmd = (TJC.CompiledCommand) o;
46: TJC.createCommand(interp, cmdname, cmd);
47: interp.resetResult();
48: return;
49: }
50: }
|