author | lancea |
Thu, 17 Oct 2013 15:14:58 -0400 | |
changeset 20880 | 1b610151b316 |
parent 18564 | f9db68ff2cbb |
child 24197 | a5c2cff81e25 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
18211 | 2 |
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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 |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package javax.sql.rowset.serial; |
|
27 |
||
28 |
import java.io.*; |
|
29 |
import java.lang.reflect.*; |
|
14409
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
30 |
import java.util.Arrays; |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
31 |
import java.util.Vector; |
2 | 32 |
import javax.sql.rowset.RowSetWarning; |
18235
5cef881c0a28
8012692: SerialJavaObject.java should be CallerSensitive aware
chegar
parents:
18211
diff
changeset
|
33 |
import sun.reflect.CallerSensitive; |
18211 | 34 |
import sun.reflect.Reflection; |
18235
5cef881c0a28
8012692: SerialJavaObject.java should be CallerSensitive aware
chegar
parents:
18211
diff
changeset
|
35 |
import sun.reflect.misc.ReflectUtil; |
2 | 36 |
|
37 |
/** |
|
38 |
* A serializable mapping in the Java programming language of an SQL |
|
39 |
* <code>JAVA_OBJECT</code> value. Assuming the Java object |
|
40 |
* implements the <code>Serializable</code> interface, this class simply wraps the |
|
41 |
* serialization process. |
|
42 |
* <P> |
|
43 |
* If however, the serialization is not possible because |
|
44 |
* the Java object is not immediately serializable, this class will |
|
45 |
* attempt to serialize all non-static members to permit the object |
|
46 |
* state to be serialized. |
|
47 |
* Static or transient fields cannot be serialized; an attempt to serialize |
|
48 |
* them will result in a <code>SerialException</code> object being thrown. |
|
49 |
* |
|
18564 | 50 |
* <h3> Thread safety </h3> |
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
51 |
* |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
52 |
* A SerialJavaObject is not safe for use by multiple concurrent threads. If a |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
53 |
* SerialJavaObject is to be used by more than one thread then access to the |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
54 |
* SerialJavaObject should be controlled by appropriate synchronization. |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
55 |
* |
2 | 56 |
* @author Jonathan Bruce |
57 |
*/ |
|
58 |
public class SerialJavaObject implements Serializable, Cloneable { |
|
59 |
||
60 |
/** |
|
61 |
* Placeholder for object to be serialized. |
|
62 |
*/ |
|
14409
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
63 |
private Object obj; |
2 | 64 |
|
65 |
||
66 |
/** |
|
67 |
* Placeholder for all fields in the <code>JavaObject</code> being serialized. |
|
68 |
*/ |
|
69 |
private transient Field[] fields; |
|
70 |
||
71 |
/** |
|
72 |
* Constructor for <code>SerialJavaObject</code> helper class. |
|
73 |
* <p> |
|
74 |
* |
|
75 |
* @param obj the Java <code>Object</code> to be serialized |
|
7972 | 76 |
* @throws SerialException if the object is found not to be serializable |
2 | 77 |
*/ |
78 |
public SerialJavaObject(Object obj) throws SerialException { |
|
79 |
||
80 |
// if any static fields are found, an exception |
|
81 |
// should be thrown |
|
82 |
||
83 |
||
84 |
// get Class. Object instance should always be available |
|
7972 | 85 |
Class<?> c = obj.getClass(); |
2 | 86 |
|
87 |
// determine if object implements Serializable i/f |
|
7972 | 88 |
if (!(obj instanceof java.io.Serializable)) { |
89 |
setWarning(new RowSetWarning("Warning, the object passed to the constructor does not implement Serializable")); |
|
2 | 90 |
} |
91 |
||
92 |
// can only determine public fields (obviously). If |
|
93 |
// any of these are static, this should invalidate |
|
94 |
// the action of attempting to persist these fields |
|
95 |
// in a serialized form |
|
96 |
fields = c.getFields(); |
|
97 |
||
14409
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
98 |
if (hasStaticFields(fields)) { |
2 | 99 |
throw new SerialException("Located static fields in " + |
100 |
"object instance. Cannot serialize"); |
|
101 |
} |
|
102 |
||
103 |
this.obj = obj; |
|
104 |
} |
|
105 |
||
106 |
/** |
|
107 |
* Returns an <code>Object</code> that is a copy of this <code>SerialJavaObject</code> |
|
108 |
* object. |
|
109 |
* |
|
110 |
* @return a copy of this <code>SerialJavaObject</code> object as an |
|
111 |
* <code>Object</code> in the Java programming language |
|
112 |
* @throws SerialException if the instance is corrupt |
|
113 |
*/ |
|
114 |
public Object getObject() throws SerialException { |
|
115 |
return this.obj; |
|
116 |
} |
|
117 |
||
118 |
/** |
|
119 |
* Returns an array of <code>Field</code> objects that contains each |
|
120 |
* field of the object that this helper class is serializing. |
|
121 |
* |
|
122 |
* @return an array of <code>Field</code> objects |
|
123 |
* @throws SerialException if an error is encountered accessing |
|
124 |
* the serialized object |
|
18211 | 125 |
* @throws SecurityException If a security manager, <i>s</i>, is present |
126 |
* and the caller's class loader is not the same as or an |
|
127 |
* ancestor of the class loader for the class of the |
|
128 |
* {@linkplain #getObject object} being serialized |
|
129 |
* and invocation of {@link SecurityManager#checkPackageAccess |
|
130 |
* s.checkPackageAccess()} denies access to the package |
|
131 |
* of that class. |
|
132 |
* @see Class#getFields |
|
2 | 133 |
*/ |
18235
5cef881c0a28
8012692: SerialJavaObject.java should be CallerSensitive aware
chegar
parents:
18211
diff
changeset
|
134 |
@CallerSensitive |
2 | 135 |
public Field[] getFields() throws SerialException { |
136 |
if (fields != null) { |
|
7972 | 137 |
Class<?> c = this.obj.getClass(); |
18235
5cef881c0a28
8012692: SerialJavaObject.java should be CallerSensitive aware
chegar
parents:
18211
diff
changeset
|
138 |
SecurityManager sm = System.getSecurityManager(); |
5cef881c0a28
8012692: SerialJavaObject.java should be CallerSensitive aware
chegar
parents:
18211
diff
changeset
|
139 |
if (sm != null) { |
5cef881c0a28
8012692: SerialJavaObject.java should be CallerSensitive aware
chegar
parents:
18211
diff
changeset
|
140 |
/* |
5cef881c0a28
8012692: SerialJavaObject.java should be CallerSensitive aware
chegar
parents:
18211
diff
changeset
|
141 |
* Check if the caller is allowed to access the specified class's package. |
5cef881c0a28
8012692: SerialJavaObject.java should be CallerSensitive aware
chegar
parents:
18211
diff
changeset
|
142 |
* If access is denied, throw a SecurityException. |
5cef881c0a28
8012692: SerialJavaObject.java should be CallerSensitive aware
chegar
parents:
18211
diff
changeset
|
143 |
*/ |
5cef881c0a28
8012692: SerialJavaObject.java should be CallerSensitive aware
chegar
parents:
18211
diff
changeset
|
144 |
Class<?> caller = sun.reflect.Reflection.getCallerClass(); |
5cef881c0a28
8012692: SerialJavaObject.java should be CallerSensitive aware
chegar
parents:
18211
diff
changeset
|
145 |
if (ReflectUtil.needsPackageAccessCheck(caller.getClassLoader(), |
5cef881c0a28
8012692: SerialJavaObject.java should be CallerSensitive aware
chegar
parents:
18211
diff
changeset
|
146 |
c.getClassLoader())) { |
5cef881c0a28
8012692: SerialJavaObject.java should be CallerSensitive aware
chegar
parents:
18211
diff
changeset
|
147 |
ReflectUtil.checkPackageAccess(c); |
5cef881c0a28
8012692: SerialJavaObject.java should be CallerSensitive aware
chegar
parents:
18211
diff
changeset
|
148 |
} |
5cef881c0a28
8012692: SerialJavaObject.java should be CallerSensitive aware
chegar
parents:
18211
diff
changeset
|
149 |
} |
7972 | 150 |
return c.getFields(); |
2 | 151 |
} else { |
152 |
throw new SerialException("SerialJavaObject does not contain" + |
|
153 |
" a serialized object instance"); |
|
154 |
} |
|
155 |
} |
|
156 |
||
157 |
/** |
|
14409
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
158 |
* The identifier that assists in the serialization of this |
2 | 159 |
* <code>SerialJavaObject</code> object. |
160 |
*/ |
|
161 |
static final long serialVersionUID = -1465795139032831023L; |
|
162 |
||
163 |
/** |
|
164 |
* A container for the warnings issued on this <code>SerialJavaObject</code> |
|
165 |
* object. When there are multiple warnings, each warning is chained to the |
|
166 |
* previous warning. |
|
167 |
*/ |
|
14409
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
168 |
Vector<RowSetWarning> chain; |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
169 |
|
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
170 |
/** |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
171 |
* Compares this SerialJavaObject to the specified object. |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
172 |
* The result is {@code true} if and only if the argument |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
173 |
* is not {@code null} and is a {@code SerialJavaObject} |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
174 |
* object that is identical to this object |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
175 |
* |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
176 |
* @param o The object to compare this {@code SerialJavaObject} against |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
177 |
* |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
178 |
* @return {@code true} if the given object represents a {@code SerialJavaObject} |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
179 |
* equivalent to this SerialJavaObject, {@code false} otherwise |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
180 |
* |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
181 |
*/ |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
182 |
public boolean equals(Object o) { |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
183 |
if (this == o) { |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
184 |
return true; |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
185 |
} |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
186 |
if (o instanceof SerialJavaObject) { |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
187 |
SerialJavaObject sjo = (SerialJavaObject) o; |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
188 |
return obj.equals(sjo.obj); |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
189 |
} |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
190 |
return false; |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
191 |
} |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
192 |
|
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
193 |
/** |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
194 |
* Returns a hash code for this SerialJavaObject. The hash code for a |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
195 |
* {@code SerialJavaObject} object is taken as the hash code of |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
196 |
* the {@code Object} it stores |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
197 |
* |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
198 |
* @return a hash code value for this object. |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
199 |
*/ |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
200 |
public int hashCode() { |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
201 |
return 31 + obj.hashCode(); |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
202 |
} |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
203 |
|
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
204 |
/** |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
205 |
* Returns a clone of this {@code SerialJavaObject}. |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
206 |
* |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
207 |
* @return a clone of this SerialJavaObject |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
208 |
*/ |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
209 |
|
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
210 |
public Object clone() { |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
211 |
try { |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
212 |
SerialJavaObject sjo = (SerialJavaObject) super.clone(); |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
213 |
sjo.fields = Arrays.copyOf(fields, fields.length); |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
214 |
if (chain != null) |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
215 |
sjo.chain = new Vector<>(chain); |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
216 |
return sjo; |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
217 |
} catch (CloneNotSupportedException ex) { |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
218 |
// this shouldn't happen, since we are Cloneable |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
219 |
throw new InternalError(); |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
220 |
} |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
221 |
} |
2 | 222 |
|
223 |
/** |
|
224 |
* Registers the given warning. |
|
225 |
*/ |
|
226 |
private void setWarning(RowSetWarning e) { |
|
227 |
if (chain == null) { |
|
14409
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
228 |
chain = new Vector<>(); |
2 | 229 |
} |
230 |
chain.add(e); |
|
231 |
} |
|
14409
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
232 |
|
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
233 |
/** |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
234 |
* readObject is called to restore the state of the {@code SerialJavaObject} |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
235 |
* from a stream. |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
236 |
*/ |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
237 |
private void readObject(ObjectInputStream s) |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
238 |
throws IOException, ClassNotFoundException { |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
239 |
|
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
240 |
ObjectInputStream.GetField fields1 = s.readFields(); |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
241 |
@SuppressWarnings("unchecked") |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
242 |
Vector<RowSetWarning> tmp = (Vector<RowSetWarning>)fields1.get("chain", null); |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
243 |
if (tmp != null) |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
244 |
chain = new Vector<>(tmp); |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
245 |
|
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
246 |
obj = fields1.get("obj", null); |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
247 |
if (obj != null) { |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
248 |
fields = obj.getClass().getFields(); |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
249 |
if(hasStaticFields(fields)) |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
250 |
throw new IOException("Located static fields in " + |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
251 |
"object instance. Cannot serialize"); |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
252 |
} else { |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
253 |
throw new IOException("Object cannot be null!"); |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
254 |
} |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
255 |
|
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
256 |
} |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
257 |
|
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
258 |
/** |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
259 |
* writeObject is called to save the state of the {@code SerialJavaObject} |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
260 |
* to a stream. |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
261 |
*/ |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
262 |
private void writeObject(ObjectOutputStream s) |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
263 |
throws IOException { |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
264 |
ObjectOutputStream.PutField fields = s.putFields(); |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
265 |
fields.put("obj", obj); |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
266 |
fields.put("chain", chain); |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
267 |
s.writeFields(); |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
268 |
} |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
269 |
|
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
270 |
/* |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
271 |
* Check to see if there are any Static Fields in this object |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
272 |
*/ |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
273 |
private static boolean hasStaticFields(Field[] fields) { |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
274 |
for (Field field : fields) { |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
275 |
if ( field.getModifiers() == Modifier.STATIC) { |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
276 |
return true; |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
277 |
} |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
278 |
} |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
279 |
return false; |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
11129
diff
changeset
|
280 |
} |
2 | 281 |
} |