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