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 UnsafeQualifiedStaticDoubleFieldAccessorImpl extends
031: UnsafeQualifiedStaticFieldAccessorImpl {
032: UnsafeQualifiedStaticDoubleFieldAccessorImpl(Field field,
033: boolean isReadOnly) {
034: super (field, isReadOnly);
035: }
036:
037: public Object get(Object obj) throws IllegalArgumentException {
038: return new Double(getDouble(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: throw newGetIntIllegalArgumentException();
060: }
061:
062: public long getLong(Object obj) throws IllegalArgumentException {
063: throw newGetLongIllegalArgumentException();
064: }
065:
066: public float getFloat(Object obj) throws IllegalArgumentException {
067: throw newGetFloatIllegalArgumentException();
068: }
069:
070: public double getDouble(Object obj) throws IllegalArgumentException {
071: return unsafe.getDoubleVolatile(base, fieldOffset);
072: }
073:
074: public void set(Object obj, Object value)
075: throws IllegalArgumentException, IllegalAccessException {
076: if (isReadOnly) {
077: throwFinalFieldIllegalAccessException(value);
078: }
079: if (value == null) {
080: throwSetIllegalArgumentException(value);
081: }
082: if (value instanceof Byte) {
083: unsafe.putDoubleVolatile(base, fieldOffset, ((Byte) value)
084: .byteValue());
085: return;
086: }
087: if (value instanceof Short) {
088: unsafe.putDoubleVolatile(base, fieldOffset, ((Short) value)
089: .shortValue());
090: return;
091: }
092: if (value instanceof Character) {
093: unsafe.putDoubleVolatile(base, fieldOffset,
094: ((Character) value).charValue());
095: return;
096: }
097: if (value instanceof Integer) {
098: unsafe.putDoubleVolatile(base, fieldOffset,
099: ((Integer) value).intValue());
100: return;
101: }
102: if (value instanceof Long) {
103: unsafe.putDoubleVolatile(base, fieldOffset, ((Long) value)
104: .longValue());
105: return;
106: }
107: if (value instanceof Float) {
108: unsafe.putDoubleVolatile(base, fieldOffset, ((Float) value)
109: .floatValue());
110: return;
111: }
112: if (value instanceof Double) {
113: unsafe.putDoubleVolatile(base, fieldOffset,
114: ((Double) value).doubleValue());
115: return;
116: }
117: throwSetIllegalArgumentException(value);
118: }
119:
120: public void setBoolean(Object obj, boolean z)
121: throws IllegalArgumentException, IllegalAccessException {
122: throwSetIllegalArgumentException(z);
123: }
124:
125: public void setByte(Object obj, byte b)
126: throws IllegalArgumentException, IllegalAccessException {
127: setDouble(obj, b);
128: }
129:
130: public void setChar(Object obj, char c)
131: throws IllegalArgumentException, IllegalAccessException {
132: setDouble(obj, c);
133: }
134:
135: public void setShort(Object obj, short s)
136: throws IllegalArgumentException, IllegalAccessException {
137: setDouble(obj, s);
138: }
139:
140: public void setInt(Object obj, int i)
141: throws IllegalArgumentException, IllegalAccessException {
142: setDouble(obj, i);
143: }
144:
145: public void setLong(Object obj, long l)
146: throws IllegalArgumentException, IllegalAccessException {
147: setDouble(obj, l);
148: }
149:
150: public void setFloat(Object obj, float f)
151: throws IllegalArgumentException, IllegalAccessException {
152: setDouble(obj, f);
153: }
154:
155: public void setDouble(Object obj, double d)
156: throws IllegalArgumentException, IllegalAccessException {
157: if (isReadOnly) {
158: throwFinalFieldIllegalAccessException(d);
159: }
160: unsafe.putDoubleVolatile(base, fieldOffset, d);
161: }
162: }
|