01: /*
02: * @(#)nodeEdit.java 1.2 04/12/06
03: *
04: * Copyright (c) 2003,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.xml;
10:
11: import pnuts.lang.*;
12: import pnuts.xml.NodeEditingConfiguration;
13:
14: /*
15: * function nodeEdit({boolean})
16: */
17: public class nodeEdit extends PnutsFunction {
18:
19: public nodeEdit() {
20: super ("nodeEdit");
21: }
22:
23: public boolean defined(int nargs) {
24: return (nargs == 0 || nargs == 1);
25: }
26:
27: protected Object exec(Object[] args, Context context) {
28: int nargs = args.length;
29: Configuration current = context.getConfiguration();
30: if (nargs == 0) {
31: return (current instanceof NodeEditingConfiguration) ? Boolean.TRUE
32: : Boolean.FALSE;
33: } else if (nargs == 1) {
34: boolean enabled = ((Boolean) args[0]).booleanValue();
35: if (enabled) {
36: if (!(current instanceof NodeEditingConfiguration)) {
37: context
38: .setConfiguration(new NodeEditingConfiguration(
39: current));
40: }
41: } else {
42: if (current instanceof NodeEditingConfiguration) {
43: context
44: .setConfiguration(((NodeEditingConfiguration) current)
45: .getParent());
46: }
47: }
48: return null;
49: } else {
50: undefined(args, context);
51: return null;
52: }
53: }
54:
55: public String toString() {
56: return "function nodeEdit( { boolean } )";
57: }
58: }
|