01: /*
02: * PublicMemberAccessor
03: *
04: * Copyright (c) 1997-2007 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.lang;
10:
11: import pnuts.ext.ConfigurationAdapter;
12: import java.security.*;
13: import java.lang.reflect.*;
14:
15: /**
16: * This is a configuration for public field access.
17: */
18: public class PublicMemberAccessor extends ConfigurationAdapter {
19:
20: /**
21: * Constructor
22: */
23: public PublicMemberAccessor() {
24: }
25:
26: public PublicMemberAccessor(Configuration base) {
27: super (base);
28: }
29:
30: public Object getField(Context context, Object target, String name) {
31: return context.runtime._getField(context, target.getClass(),
32: name, target);
33: }
34:
35: public void putField(Context context, Object target, String name,
36: Object value) {
37: context.runtime._putField(context, target.getClass(), name,
38: target, value);
39: }
40:
41: public Object getStaticField(Context context, Class cls, String name) {
42: return context.runtime._getField(context, cls, name, null);
43: }
44:
45: public void putStaticField(Context context, Class cls, String name,
46: Object value) {
47: context.runtime._putField(context, cls, name, null, value);
48: }
49:
50: public Method[] getMethods(final Class cls) {
51: return (Method[]) AccessController
52: .doPrivileged(new PrivilegedAction() {
53: public Object run() {
54: return cls.getMethods();
55: }
56: });
57: }
58:
59: public Constructor[] getConstructors(final Class cls) {
60: return (Constructor[]) AccessController
61: .doPrivileged(new PrivilegedAction() {
62: public Object run() {
63: return cls.getConstructors();
64: }
65: });
66: }
67:
68: }
|