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 UnsafeQualifiedByteFieldAccessorImpl extends
031: UnsafeQualifiedFieldAccessorImpl {
032: UnsafeQualifiedByteFieldAccessorImpl(Field field, boolean isReadOnly) {
033: super (field, isReadOnly);
034: }
035:
036: public Object get(Object obj) throws IllegalArgumentException {
037: return new Byte(getByte(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: ensureObj(obj);
047: return unsafe.getByteVolatile(obj, fieldOffset);
048: }
049:
050: public char getChar(Object obj) throws IllegalArgumentException {
051: throw newGetCharIllegalArgumentException();
052: }
053:
054: public short getShort(Object obj) throws IllegalArgumentException {
055: return getByte(obj);
056: }
057:
058: public int getInt(Object obj) throws IllegalArgumentException {
059: return getByte(obj);
060: }
061:
062: public long getLong(Object obj) throws IllegalArgumentException {
063: return getByte(obj);
064: }
065:
066: public float getFloat(Object obj) throws IllegalArgumentException {
067: return getByte(obj);
068: }
069:
070: public double getDouble(Object obj) throws IllegalArgumentException {
071: return getByte(obj);
072: }
073:
074: public void set(Object obj, Object value)
075: throws IllegalArgumentException, IllegalAccessException {
076: ensureObj(obj);
077: if (isReadOnly) {
078: throwFinalFieldIllegalAccessException(value);
079: }
080: if (value == null) {
081: throwSetIllegalArgumentException(value);
082: }
083: if (value instanceof Byte) {
084: unsafe.putByteVolatile(obj, fieldOffset, ((Byte) value)
085: .byteValue());
086: return;
087: }
088: throwSetIllegalArgumentException(value);
089: }
090:
091: public void setBoolean(Object obj, boolean z)
092: throws IllegalArgumentException, IllegalAccessException {
093: throwSetIllegalArgumentException(z);
094: }
095:
096: public void setByte(Object obj, byte b)
097: throws IllegalArgumentException, IllegalAccessException {
098: ensureObj(obj);
099: if (isReadOnly) {
100: throwFinalFieldIllegalAccessException(b);
101: }
102: unsafe.putByteVolatile(obj, fieldOffset, b);
103: }
104:
105: public void setChar(Object obj, char c)
106: throws IllegalArgumentException, IllegalAccessException {
107: throwSetIllegalArgumentException(c);
108: }
109:
110: public void setShort(Object obj, short s)
111: throws IllegalArgumentException, IllegalAccessException {
112: throwSetIllegalArgumentException(s);
113: }
114:
115: public void setInt(Object obj, int i)
116: throws IllegalArgumentException, IllegalAccessException {
117: throwSetIllegalArgumentException(i);
118: }
119:
120: public void setLong(Object obj, long l)
121: throws IllegalArgumentException, IllegalAccessException {
122: throwSetIllegalArgumentException(l);
123: }
124:
125: public void setFloat(Object obj, float f)
126: throws IllegalArgumentException, IllegalAccessException {
127: throwSetIllegalArgumentException(f);
128: }
129:
130: public void setDouble(Object obj, double d)
131: throws IllegalArgumentException, IllegalAccessException {
132: throwSetIllegalArgumentException(d);
133: }
134: }
|