001: /*
002: * Copyright 2004-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 UnsafeQualifiedIntegerFieldAccessorImpl extends
031: UnsafeQualifiedFieldAccessorImpl {
032: UnsafeQualifiedIntegerFieldAccessorImpl(Field field,
033: boolean isReadOnly) {
034: super (field, isReadOnly);
035: }
036:
037: public Object get(Object obj) throws IllegalArgumentException {
038: return new Integer(getInt(obj));
039: }
040:
041: public boolean getBoolean(Object obj)
042: throws IllegalArgumentException {
043: throw newGetBooleanIllegalArgumentException();
044: }
045:
046: public byte getByte(Object obj) throws IllegalArgumentException {
047: throw newGetByteIllegalArgumentException();
048: }
049:
050: public char getChar(Object obj) throws IllegalArgumentException {
051: throw newGetCharIllegalArgumentException();
052: }
053:
054: public short getShort(Object obj) throws IllegalArgumentException {
055: throw newGetShortIllegalArgumentException();
056: }
057:
058: public int getInt(Object obj) throws IllegalArgumentException {
059: ensureObj(obj);
060: return unsafe.getIntVolatile(obj, fieldOffset);
061: }
062:
063: public long getLong(Object obj) throws IllegalArgumentException {
064: return getInt(obj);
065: }
066:
067: public float getFloat(Object obj) throws IllegalArgumentException {
068: return getInt(obj);
069: }
070:
071: public double getDouble(Object obj) throws IllegalArgumentException {
072: return getInt(obj);
073: }
074:
075: public void set(Object obj, Object value)
076: throws IllegalArgumentException, IllegalAccessException {
077: ensureObj(obj);
078: if (isReadOnly) {
079: throwFinalFieldIllegalAccessException(value);
080: }
081: if (value == null) {
082: throwSetIllegalArgumentException(value);
083: }
084: if (value instanceof Byte) {
085: unsafe.putIntVolatile(obj, fieldOffset, ((Byte) value)
086: .byteValue());
087: return;
088: }
089: if (value instanceof Short) {
090: unsafe.putIntVolatile(obj, fieldOffset, ((Short) value)
091: .shortValue());
092: return;
093: }
094: if (value instanceof Character) {
095: unsafe.putIntVolatile(obj, fieldOffset, ((Character) value)
096: .charValue());
097: return;
098: }
099: if (value instanceof Integer) {
100: unsafe.putIntVolatile(obj, fieldOffset, ((Integer) value)
101: .intValue());
102: return;
103: }
104: throwSetIllegalArgumentException(value);
105: }
106:
107: public void setBoolean(Object obj, boolean z)
108: throws IllegalArgumentException, IllegalAccessException {
109: throwSetIllegalArgumentException(z);
110: }
111:
112: public void setByte(Object obj, byte b)
113: throws IllegalArgumentException, IllegalAccessException {
114: setInt(obj, b);
115: }
116:
117: public void setChar(Object obj, char c)
118: throws IllegalArgumentException, IllegalAccessException {
119: setInt(obj, c);
120: }
121:
122: public void setShort(Object obj, short s)
123: throws IllegalArgumentException, IllegalAccessException {
124: setInt(obj, s);
125: }
126:
127: public void setInt(Object obj, int i)
128: throws IllegalArgumentException, IllegalAccessException {
129: ensureObj(obj);
130: if (isReadOnly) {
131: throwFinalFieldIllegalAccessException(i);
132: }
133: unsafe.putIntVolatile(obj, fieldOffset, i);
134: }
135:
136: public void setLong(Object obj, long l)
137: throws IllegalArgumentException, IllegalAccessException {
138: throwSetIllegalArgumentException(l);
139: }
140:
141: public void setFloat(Object obj, float f)
142: throws IllegalArgumentException, IllegalAccessException {
143: throwSetIllegalArgumentException(f);
144: }
145:
146: public void setDouble(Object obj, double d)
147: throws IllegalArgumentException, IllegalAccessException {
148: throwSetIllegalArgumentException(d);
149: }
150: }
|