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