001: /*
002: * Copyright 2001-2005 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.reflect;
027:
028: import java.lang.reflect.Field;
029:
030: class UnsafeStaticFloatFieldAccessorImpl extends
031: UnsafeStaticFieldAccessorImpl {
032: UnsafeStaticFloatFieldAccessorImpl(Field field) {
033: super (field);
034: }
035:
036: public Object get(Object obj) throws IllegalArgumentException {
037: return new Float(getFloat(obj));
038: }
039:
040: public boolean getBoolean(Object obj)
041: throws IllegalArgumentException {
042: throw newGetBooleanIllegalArgumentException();
043: }
044:
045: public byte getByte(Object obj) throws IllegalArgumentException {
046: throw newGetByteIllegalArgumentException();
047: }
048:
049: public char getChar(Object obj) throws IllegalArgumentException {
050: throw newGetCharIllegalArgumentException();
051: }
052:
053: public short getShort(Object obj) throws IllegalArgumentException {
054: throw newGetShortIllegalArgumentException();
055: }
056:
057: public int getInt(Object obj) throws IllegalArgumentException {
058: throw newGetIntIllegalArgumentException();
059: }
060:
061: public long getLong(Object obj) throws IllegalArgumentException {
062: throw newGetLongIllegalArgumentException();
063: }
064:
065: public float getFloat(Object obj) throws IllegalArgumentException {
066: return unsafe.getFloat(base, fieldOffset);
067: }
068:
069: public double getDouble(Object obj) throws IllegalArgumentException {
070: return getFloat(obj);
071: }
072:
073: public void set(Object obj, Object value)
074: throws IllegalArgumentException, IllegalAccessException {
075: if (isFinal) {
076: throwFinalFieldIllegalAccessException(value);
077: }
078: if (value == null) {
079: throwSetIllegalArgumentException(value);
080: }
081: if (value instanceof Byte) {
082: unsafe.putFloat(base, fieldOffset, ((Byte) value)
083: .byteValue());
084: return;
085: }
086: if (value instanceof Short) {
087: unsafe.putFloat(base, fieldOffset, ((Short) value)
088: .shortValue());
089: return;
090: }
091: if (value instanceof Character) {
092: unsafe.putFloat(base, fieldOffset, ((Character) value)
093: .charValue());
094: return;
095: }
096: if (value instanceof Integer) {
097: unsafe.putFloat(base, fieldOffset, ((Integer) value)
098: .intValue());
099: return;
100: }
101: if (value instanceof Long) {
102: unsafe.putFloat(base, fieldOffset, ((Long) value)
103: .longValue());
104: return;
105: }
106: if (value instanceof Float) {
107: unsafe.putFloat(base, fieldOffset, ((Float) value)
108: .floatValue());
109: return;
110: }
111: throwSetIllegalArgumentException(value);
112: }
113:
114: public void setBoolean(Object obj, boolean z)
115: throws IllegalArgumentException, IllegalAccessException {
116: throwSetIllegalArgumentException(z);
117: }
118:
119: public void setByte(Object obj, byte b)
120: throws IllegalArgumentException, IllegalAccessException {
121: setFloat(obj, b);
122: }
123:
124: public void setChar(Object obj, char c)
125: throws IllegalArgumentException, IllegalAccessException {
126: setFloat(obj, c);
127: }
128:
129: public void setShort(Object obj, short s)
130: throws IllegalArgumentException, IllegalAccessException {
131: setFloat(obj, s);
132: }
133:
134: public void setInt(Object obj, int i)
135: throws IllegalArgumentException, IllegalAccessException {
136: setFloat(obj, i);
137: }
138:
139: public void setLong(Object obj, long l)
140: throws IllegalArgumentException, IllegalAccessException {
141: setFloat(obj, l);
142: }
143:
144: public void setFloat(Object obj, float f)
145: throws IllegalArgumentException, IllegalAccessException {
146: if (isFinal) {
147: throwFinalFieldIllegalAccessException(f);
148: }
149: unsafe.putFloat(base, fieldOffset, f);
150: }
151:
152: public void setDouble(Object obj, double d)
153: throws IllegalArgumentException, IllegalAccessException {
154: throwSetIllegalArgumentException(d);
155: }
156: }
|