01: /*
02: * @(#)ImplementationAdapter.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 pnuts.ext;
10:
11: import java.io.FileNotFoundException;
12: import java.net.URL;
13:
14: import pnuts.lang.Context;
15: import pnuts.lang.Implementation;
16: import pnuts.lang.PnutsImpl;
17: import pnuts.lang.SimpleNode;
18:
19: /**
20: * This class is used to customize an existing Implementation.
21: */
22: public class ImplementationAdapter extends PnutsImpl {
23:
24: private Implementation impl;
25:
26: public ImplementationAdapter(Implementation impl) {
27: this .impl = impl;
28: }
29:
30: /**
31: * Returns the base Implementation which was passed to the constructor
32: *
33: * @return the base Implementation object.
34: */
35: public Implementation getBaseImpl() {
36: return impl;
37: }
38:
39: /**
40: * Evaluate an expreesion
41: *
42: * @param str
43: * the expression to be evaluated
44: * @param context
45: * the context in which the expression is evaluated
46: * @return the result of the evaluation
47: */
48: public Object eval(String str, Context context) {
49: return impl.eval(str, context);
50: }
51:
52: /**
53: * Load a script file from local file system
54: *
55: * @param filename
56: * the file name of the script
57: * @param context
58: * the context in which the expression is evaluated
59: * @return the result of the evaluation
60: */
61: public Object loadFile(String filename, Context context)
62: throws FileNotFoundException {
63: return impl.loadFile(filename, context);
64: }
65:
66: /**
67: * Load a script file using classloader
68: *
69: * @param file
70: * the name of the script
71: * @param context
72: * the context in which the script is executed
73: * @return the result of the evaluation
74: */
75: public Object load(String file, Context context)
76: throws FileNotFoundException {
77: return impl.load(file, context);
78: }
79:
80: /**
81: * Load a script file from a URL
82: *
83: * @param scriptURL
84: * the URL of the script
85: * @param context
86: * the context in which the script is executed
87: * @return the result of the evaluation
88: */
89: public Object load(URL scriptURL, Context context) {
90: return impl.load(scriptURL, context);
91: }
92:
93: public Object accept(SimpleNode node, Context context) {
94: return impl.accept(node, context);
95: }
96: }
|