< prev index next >

src/java.sql.rowset/share/classes/javax/sql/rowset/serial/SerialJavaObject.java

Print this page

  1 /*
  2  * Copyright (c) 2003, 2019, 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

217             return sjo;
218         } catch (CloneNotSupportedException ex) {
219             // this shouldn't happen, since we are Cloneable
220             throw new InternalError();
221         }
222     }
223 
224     /**
225      * Registers the given warning.
226      */
227     private void setWarning(RowSetWarning e) {
228         if (chain == null) {
229             chain = new Vector<>();
230         }
231         chain.add(e);
232     }
233 
234     /**
235      * readObject is called to restore the state of the {@code SerialJavaObject}
236      * from a stream.





237      */
238     private void readObject(ObjectInputStream s)
239             throws IOException, ClassNotFoundException {
240 
241         ObjectInputStream.GetField fields1 = s.readFields();
242         @SuppressWarnings("unchecked")
243         Vector<RowSetWarning> tmp = (Vector<RowSetWarning>)fields1.get("chain", null);
244         if (tmp != null)
245             chain = new Vector<>(tmp);
246 
247         obj = fields1.get("obj", null);
248         if (obj != null) {
249             fields = obj.getClass().getFields();
250             if(hasStaticFields(fields))
251                 throw new IOException("Located static fields in " +
252                 "object instance. Cannot serialize");
253         } else {
254             throw new IOException("Object cannot be null!");
255         }
256 
257     }
258 
259     /**
260      * writeObject is called to save the state of the {@code SerialJavaObject}
261      * to a stream.


262      */
263     private void writeObject(ObjectOutputStream s)
264             throws IOException {
265         ObjectOutputStream.PutField fields = s.putFields();
266         fields.put("obj", obj);
267         fields.put("chain", chain);
268         s.writeFields();
269     }
270 
271     /*
272      * Check to see if there are any Static Fields in this object
273      */
274     private static boolean hasStaticFields(Field[] fields) {
275         for (Field field : fields) {
276             if ( field.getModifiers() == Modifier.STATIC) {
277                 return true;
278             }
279         }
280         return false;
281     }

  1 /*
  2  * Copyright (c) 2003, 2020, 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

217             return sjo;
218         } catch (CloneNotSupportedException ex) {
219             // this shouldn't happen, since we are Cloneable
220             throw new InternalError();
221         }
222     }
223 
224     /**
225      * Registers the given warning.
226      */
227     private void setWarning(RowSetWarning e) {
228         if (chain == null) {
229             chain = new Vector<>();
230         }
231         chain.add(e);
232     }
233 
234     /**
235      * readObject is called to restore the state of the {@code SerialJavaObject}
236      * from a stream.
237      * @param s the {@code ObjectInputStream} to read from.
238      *
239      * @throws  ClassNotFoundException if the class of a serialized object
240      *          could not be found.
241      * @throws  IOException if an I/O error occurs.
242      */
243     private void readObject(ObjectInputStream s)
244             throws IOException, ClassNotFoundException {
245 
246         ObjectInputStream.GetField fields1 = s.readFields();
247         @SuppressWarnings("unchecked")
248         Vector<RowSetWarning> tmp = (Vector<RowSetWarning>)fields1.get("chain", null);
249         if (tmp != null)
250             chain = new Vector<>(tmp);
251 
252         obj = fields1.get("obj", null);
253         if (obj != null) {
254             fields = obj.getClass().getFields();
255             if(hasStaticFields(fields))
256                 throw new IOException("Located static fields in " +
257                 "object instance. Cannot serialize");
258         } else {
259             throw new IOException("Object cannot be null!");
260         }
261 
262     }
263 
264     /**
265      * writeObject is called to save the state of the {@code SerialJavaObject}
266      * to a stream.
267      * @param s the {@code ObjectOutputStream} to write to.
268      + @throws  IOException if I/O errors occur.
269      */
270     private void writeObject(ObjectOutputStream s)
271             throws IOException {
272         ObjectOutputStream.PutField fields = s.putFields();
273         fields.put("obj", obj);
274         fields.put("chain", chain);
275         s.writeFields();
276     }
277 
278     /*
279      * Check to see if there are any Static Fields in this object
280      */
281     private static boolean hasStaticFields(Field[] fields) {
282         for (Field field : fields) {
283             if ( field.getModifiers() == Modifier.STATIC) {
284                 return true;
285             }
286         }
287         return false;
288     }
< prev index next >