001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.cldchi.test;
028:
029: import com.sun.cldc.isolate.Isolate;
030:
031: public class Reflect {
032:
033: private Object obj;
034:
035: private Reflect() {
036: obj = new Object();
037: }
038:
039: public static Reflect get(Isolate iso, String className,
040: String fieldName) {
041: Reflect r = new Reflect();
042: r.obj = getStaticField(iso.id(), className, fieldName);
043: return r;
044: }
045:
046: public Reflect getField(String fieldName) {
047: Reflect r = new Reflect();
048: r.obj = getInstanceField(this .obj, fieldName);
049: return r;
050: }
051:
052: /* Accessors for static fields */
053: public static int getStaticIntValue(Isolate iso, String className,
054: String fieldName) {
055: return getStaticIntField(iso.id(), className, fieldName);
056: }
057:
058: public static boolean getStaticBooleanValue(Isolate iso,
059: String className, String fieldName) {
060: return getStaticBooleanField(iso.id(), className, fieldName);
061: }
062:
063: public static String getStaticStringValue(Isolate iso,
064: String className, String fieldName) {
065: return (String) (getStaticField(iso.id(), className, fieldName));
066: }
067:
068: /* Accessors for instance fields */
069: public int getIntValue(String fieldName) {
070: return getIntField(this .obj, fieldName);
071: }
072:
073: public boolean getBooleanValue(String fieldName) {
074: return getBooleanField(this .obj, fieldName);
075: }
076:
077: public String getStringValue(String fieldName) {
078: return (String) getInstanceField(this .obj, fieldName);
079: }
080:
081: public Object getObjectValue() {
082: return this .obj;
083: }
084:
085: /* Native methods */
086: private static native Object getStaticField(int taskId,
087: String className, String fieldName);
088:
089: private static native int getStaticIntField(int taskId,
090: String className, String fieldName);
091:
092: private static native boolean getStaticBooleanField(int taskId,
093: String className, String fieldName);
094:
095: private native Object getInstanceField(Object obj, String fieldName);
096:
097: private native int getIntField(Object obj, String fieldName);
098:
099: private native boolean getBooleanField(Object obj, String fieldName);
100: }
|