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