1 /*
2 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
1751 spClass = 0;
1752
1753 if (callbacks != null)
1754 callbacks.setSize(0); // discard any pending callbacks
1755 }
1756
1757 /**
1758 * Factored out of inputClassFields This reads a primitive value and sets it
1759 * in the field of o described by the ObjectStreamField field.
1760 *
1761 * Note that reflection cannot be used here, because reflection cannot be used
1762 * to set final fields.
1763 */
1764 private void inputPrimitiveField(Object o, Class cl, ObjectStreamField field)
1765 throws InvalidClassException, IOException {
1766
1767 try {
1768 switch (field.getTypeCode()) {
1769 case 'B':
1770 byte byteValue = orbStream.read_octet();
1771 bridge.putByte( o, field.getFieldID(), byteValue ) ;
1772 //reflective code: field.getField().setByte( o, byteValue ) ;
1773 break;
1774 case 'Z':
1775 boolean booleanValue = orbStream.read_boolean();
1776 bridge.putBoolean( o, field.getFieldID(), booleanValue ) ;
1777 //reflective code: field.getField().setBoolean( o, booleanValue ) ;
1778 break;
1779 case 'C':
1780 char charValue = orbStream.read_wchar();
1781 bridge.putChar( o, field.getFieldID(), charValue ) ;
1782 //reflective code: field.getField().setChar( o, charValue ) ;
1783 break;
1784 case 'S':
1785 short shortValue = orbStream.read_short();
1786 bridge.putShort( o, field.getFieldID(), shortValue ) ;
1787 //reflective code: field.getField().setShort( o, shortValue ) ;
1788 break;
1789 case 'I':
1790 int intValue = orbStream.read_long();
1791 bridge.putInt( o, field.getFieldID(), intValue ) ;
1792 //reflective code: field.getField().setInt( o, intValue ) ;
1793 break;
1794 case 'J':
1795 long longValue = orbStream.read_longlong();
1796 bridge.putLong( o, field.getFieldID(), longValue ) ;
1797 //reflective code: field.getField().setLong( o, longValue ) ;
1798 break;
1799 case 'F' :
1800 float floatValue = orbStream.read_float();
1801 bridge.putFloat( o, field.getFieldID(), floatValue ) ;
1802 //reflective code: field.getField().setFloat( o, floatValue ) ;
1803 break;
1804 case 'D' :
1805 double doubleValue = orbStream.read_double();
1806 bridge.putDouble( o, field.getFieldID(), doubleValue ) ;
1807 //reflective code: field.getField().setDouble( o, doubleValue ) ;
1808 break;
1809 default:
1810 // XXX I18N, logging needed.
1811 throw new InvalidClassException(cl.getName());
1812 }
1813 } catch (IllegalArgumentException e) {
1814 /* This case should never happen. If the field types
1815 are not the same, InvalidClassException is raised when
1816 matching the local class to the serialized ObjectStreamClass. */
1817 ClassCastException cce = new ClassCastException("Assigning instance of class " +
1818 field.getType().getName() +
1819 " to field " +
1820 currentClassDesc.getName() + '#' +
1821 field.getField().getName());
1822 cce.initCause( e ) ;
1823 throw cce ;
1824 }
1825 }
1826
1827 private Object inputObjectField(org.omg.CORBA.ValueMember field,
2200 * Read the fields of the specified class from the input stream and set
2201 * the values of the fields in the specified object. If the specified
2202 * object is null, just consume the fields without setting any values. If
2203 * any ObjectStreamField does not have a reflected Field, don't try to set
2204 * that field in the object.
2205 *
2206 * REVISIT -- This code doesn't do what the comment says to when
2207 * getField() is null!
2208 */
2209 private void inputClassFields(Object o, Class cl,
2210 ObjectStreamField[] fields,
2211 com.sun.org.omg.SendingContext.CodeBase sender)
2212 throws InvalidClassException, StreamCorruptedException,
2213 ClassNotFoundException, IOException
2214 {
2215
2216 int primFields = fields.length - currentClassDesc.objFields;
2217
2218 if (o != null) {
2219 for (int i = 0; i < primFields; ++i) {
2220 if (fields[i].getField() == null)
2221 continue;
2222
2223 inputPrimitiveField(o, cl, fields[i]);
2224 }
2225 }
2226
2227 /* Read and set object fields from the input stream. */
2228 if (currentClassDesc.objFields > 0) {
2229 for (int i = primFields; i < fields.length; i++) {
2230 Object objectValue = null;
2231
2232 try {
2233 objectValue = inputObjectField(fields[i]);
2234 } catch(IndirectionException cdrie) {
2235 // The CDR stream had never seen the given offset before,
2236 // so check the recursion manager (it will throw an
2237 // IOException if it doesn't have a reference, either).
2238 objectValue = activeRecursionMgr.getObject(cdrie.offset);
2239 }
2240
2241 if ((o == null) || (fields[i].getField() == null)) {
2242 continue;
|
1 /*
2 * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
1751 spClass = 0;
1752
1753 if (callbacks != null)
1754 callbacks.setSize(0); // discard any pending callbacks
1755 }
1756
1757 /**
1758 * Factored out of inputClassFields This reads a primitive value and sets it
1759 * in the field of o described by the ObjectStreamField field.
1760 *
1761 * Note that reflection cannot be used here, because reflection cannot be used
1762 * to set final fields.
1763 */
1764 private void inputPrimitiveField(Object o, Class cl, ObjectStreamField field)
1765 throws InvalidClassException, IOException {
1766
1767 try {
1768 switch (field.getTypeCode()) {
1769 case 'B':
1770 byte byteValue = orbStream.read_octet();
1771 if (field.getField() != null) {
1772 bridge.putByte( o, field.getFieldID(), byteValue ) ;
1773 //reflective code: field.getField().setByte( o, byteValue ) ;
1774 }
1775 break;
1776 case 'Z':
1777 boolean booleanValue = orbStream.read_boolean();
1778 if (field.getField() != null) {
1779 bridge.putBoolean( o, field.getFieldID(), booleanValue ) ;
1780 //reflective code: field.getField().setBoolean( o, booleanValue ) ;
1781 }
1782 break;
1783 case 'C':
1784 char charValue = orbStream.read_wchar();
1785 if (field.getField() != null) {
1786 bridge.putChar( o, field.getFieldID(), charValue ) ;
1787 //reflective code: field.getField().setChar( o, charValue ) ;
1788 }
1789 break;
1790 case 'S':
1791 short shortValue = orbStream.read_short();
1792 if (field.getField() != null) {
1793 bridge.putShort( o, field.getFieldID(), shortValue ) ;
1794 //reflective code: field.getField().setShort( o, shortValue ) ;
1795 }
1796 break;
1797 case 'I':
1798 int intValue = orbStream.read_long();
1799 if (field.getField() != null) {
1800 bridge.putInt( o, field.getFieldID(), intValue ) ;
1801 //reflective code: field.getField().setInt( o, intValue ) ;
1802 }
1803 break;
1804 case 'J':
1805 long longValue = orbStream.read_longlong();
1806 if (field.getField() != null) {
1807 bridge.putLong( o, field.getFieldID(), longValue ) ;
1808 //reflective code: field.getField().setLong( o, longValue ) ;
1809 }
1810 break;
1811 case 'F' :
1812 float floatValue = orbStream.read_float();
1813 if (field.getField() != null) {
1814 bridge.putFloat( o, field.getFieldID(), floatValue ) ;
1815 //reflective code: field.getField().setFloat( o, floatValue ) ;
1816 }
1817 break;
1818 case 'D' :
1819 double doubleValue = orbStream.read_double();
1820 if (field.getField() != null) {
1821 bridge.putDouble( o, field.getFieldID(), doubleValue ) ;
1822 //reflective code: field.getField().setDouble( o, doubleValue ) ;
1823 }
1824 break;
1825 default:
1826 // XXX I18N, logging needed.
1827 throw new InvalidClassException(cl.getName());
1828 }
1829 } catch (IllegalArgumentException e) {
1830 /* This case should never happen. If the field types
1831 are not the same, InvalidClassException is raised when
1832 matching the local class to the serialized ObjectStreamClass. */
1833 ClassCastException cce = new ClassCastException("Assigning instance of class " +
1834 field.getType().getName() +
1835 " to field " +
1836 currentClassDesc.getName() + '#' +
1837 field.getField().getName());
1838 cce.initCause( e ) ;
1839 throw cce ;
1840 }
1841 }
1842
1843 private Object inputObjectField(org.omg.CORBA.ValueMember field,
2216 * Read the fields of the specified class from the input stream and set
2217 * the values of the fields in the specified object. If the specified
2218 * object is null, just consume the fields without setting any values. If
2219 * any ObjectStreamField does not have a reflected Field, don't try to set
2220 * that field in the object.
2221 *
2222 * REVISIT -- This code doesn't do what the comment says to when
2223 * getField() is null!
2224 */
2225 private void inputClassFields(Object o, Class cl,
2226 ObjectStreamField[] fields,
2227 com.sun.org.omg.SendingContext.CodeBase sender)
2228 throws InvalidClassException, StreamCorruptedException,
2229 ClassNotFoundException, IOException
2230 {
2231
2232 int primFields = fields.length - currentClassDesc.objFields;
2233
2234 if (o != null) {
2235 for (int i = 0; i < primFields; ++i) {
2236 inputPrimitiveField(o, cl, fields[i]);
2237 }
2238 }
2239
2240 /* Read and set object fields from the input stream. */
2241 if (currentClassDesc.objFields > 0) {
2242 for (int i = primFields; i < fields.length; i++) {
2243 Object objectValue = null;
2244
2245 try {
2246 objectValue = inputObjectField(fields[i]);
2247 } catch(IndirectionException cdrie) {
2248 // The CDR stream had never seen the given offset before,
2249 // so check the recursion manager (it will throw an
2250 // IOException if it doesn't have a reference, either).
2251 objectValue = activeRecursionMgr.getObject(cdrie.offset);
2252 }
2253
2254 if ((o == null) || (fields[i].getField() == null)) {
2255 continue;
|