01: /*
02: * @(#)setProperty.java 1.2 04/12/06
03: *
04: * Copyright (c) 2001-2003 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.util;
10:
11: import pnuts.lang.PnutsFunction;
12: import pnuts.lang.Context;
13:
14: /*
15: * function setProperty(propertyName, value)
16: */
17: public class setProperty extends PnutsFunction {
18: public setProperty() {
19: super ("setProperty");
20: }
21:
22: public boolean defined(int nargs) {
23: return nargs == 2;
24: }
25:
26: protected Object exec(Object[] args, Context context) {
27: if (args.length != 2) {
28: undefined(args, context);
29: return null;
30: }
31: Properties prop = System.getProperties();
32: String key = (String) args[0];
33: Object old = prop.get(key);
34: prop.put(key, (String) args[1]);
35: return old;
36: }
37: }
|