01: /*
02: * @(#)debug.java 1.2 04/12/06
03: *
04: * Copyright (c) 1997-2004 Sun Microsystems, Inc. All Rights Reserved.
05: *
06: * See the file "LICENSE.txt" for information on usage and redistribution
07: * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
08: */
09: package org.pnuts.servlet;
10:
11: import pnuts.servlet.*;
12: import pnuts.lang.Pnuts;
13: import pnuts.lang.Context;
14: import pnuts.lang.Executable;
15: import pnuts.lang.PnutsFunction;
16: import pnuts.lang.PnutsException;
17: import pnuts.tools.VisualDebugger;
18: import java.io.FileNotFoundException;
19:
20: /*
21: * debug(script)
22: */
23: public class debug extends PnutsFunction {
24:
25: public debug() {
26: super ("debug");
27: }
28:
29: public boolean defined(int nargs) {
30: return nargs == 1;
31: }
32:
33: protected Object exec(Object[] args, Context context) {
34: int nargs = args.length;
35: String script;
36: if (nargs == 1) {
37: Context c = new VisualDebugger().createContext(context);
38: c.set(PnutsServlet.SERVLET_COMPILER, null);
39: Object arg0 = args[0];
40: if (arg0 instanceof String) {
41: try {
42: return Pnuts.load((String) arg0, c);
43: } catch (FileNotFoundException e) {
44: throw new PnutsException(e, context);
45: }
46: } else if (arg0 instanceof Executable) {
47: return ((Executable) arg0).run(c);
48: } else {
49: throw new IllegalArgumentException(String.valueOf(arg0));
50: }
51: } else {
52: undefined(args, context);
53: return null;
54: }
55: }
56:
57: public String toString() {
58: return "function debug((String|Executable) script)";
59: }
60: }
|