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 UnsafeQualifiedLongFieldAccessorImpl extends
031: UnsafeQualifiedFieldAccessorImpl {
032: UnsafeQualifiedLongFieldAccessorImpl(Field field, boolean isReadOnly) {
033: super (field, isReadOnly);
034: }
035:
036: public Object get(Object obj) throws IllegalArgumentException {
037: return new Long(getLong(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: ensureObj(obj);
063: return unsafe.getLongVolatile(obj, fieldOffset);
064: }
065:
066: public float getFloat(Object obj) throws IllegalArgumentException {
067: return getLong(obj);
068: }
069:
070: public double getDouble(Object obj) throws IllegalArgumentException {
071: return getLong(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.putLongVolatile(obj, fieldOffset, ((Byte) value)
085: .byteValue());
086: return;
087: }
088: if (value instanceof Short) {
089: unsafe.putLongVolatile(obj, fieldOffset, ((Short) value)
090: .shortValue());
091: return;
092: }
093: if (value instanceof Character) {
094: unsafe.putLongVolatile(obj, fieldOffset,
095: ((Character) value).charValue());
096: return;
097: }
098: if (value instanceof Integer) {
099: unsafe.putLongVolatile(obj, fieldOffset, ((Integer) value)
100: .intValue());
101: return;
102: }
103: if (value instanceof Long) {
104: unsafe.putLongVolatile(obj, fieldOffset, ((Long) value)
105: .longValue());
106: return;
107: }
108: throwSetIllegalArgumentException(value);
109: }
110:
111: public void setBoolean(Object obj, boolean z)
112: throws IllegalArgumentException, IllegalAccessException {
113: throwSetIllegalArgumentException(z);
114: }
115:
116: public void setByte(Object obj, byte b)
117: throws IllegalArgumentException, IllegalAccessException {
118: setLong(obj, b);
119: }
120:
121: public void setChar(Object obj, char c)
122: throws IllegalArgumentException, IllegalAccessException {
123: setLong(obj, c);
124: }
125:
126: public void setShort(Object obj, short s)
127: throws IllegalArgumentException, IllegalAccessException {
128: setLong(obj, s);
129: }
130:
131: public void setInt(Object obj, int i)
132: throws IllegalArgumentException, IllegalAccessException {
133: setLong(obj, i);
134: }
135:
136: public void setLong(Object obj, long l)
137: throws IllegalArgumentException, IllegalAccessException {
138: ensureObj(obj);
139: if (isReadOnly) {
140: throwFinalFieldIllegalAccessException(l);
141: }
142: unsafe.putLongVolatile(obj, fieldOffset, l);
143: }
144:
145: public void setFloat(Object obj, float f)
146: throws IllegalArgumentException, IllegalAccessException {
147: throwSetIllegalArgumentException(f);
148: }
149:
150: public void setDouble(Object obj, double d)
151: throws IllegalArgumentException, IllegalAccessException {
152: throwSetIllegalArgumentException(d);
153: }
154: }
|