1
2
3
4
5
6
7
8
9
10 package nl.tudelft.simulation.event.ref;
11
12 import java.io.IOException;
13 import java.io.ObjectOutputStream;
14
15 /***
16 * A WeakReference. The weakreference extends the
17 * <code>java.lang.ref.WeakReference</code> and besides implementing the
18 * Reference interface no changes are defined.
19 * <p>
20 * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
21 * University of Technology </a>, the Netherlands. <br>
22 * See for project information <a
23 * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
24 * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
25 * License (GPL) </a>, no warranty <br>
26 *
27 * @author <a href="http://www.simulation.tudelft.nl/people/jacobs.html">Peter
28 * Jacobs </a>
29 * @version 1.2 2004-03-18
30 * @since 1.2
31 */
32 public class WeakReference implements Reference
33 {
34 /*** the reference */
35 private java.lang.ref.WeakReference reference = null;
36
37 /***
38 * Creates a new weak reference that refers to the given object. The new
39 * reference is not registered with any queue.
40 *
41 * @param referent object the new weak reference will refer to
42 */
43 public WeakReference(final Object referent)
44 {
45 this.reference = new java.lang.ref.WeakReference(referent);
46 }
47
48 /***
49 * @see nl.tudelft.simulation.event.ref.Reference#get()
50 */
51 public Object get()
52 {
53 return this.reference.get();
54 }
55
56 /***
57 * writes a serializable method to stream
58 *
59 * @param out the outputstream
60 * @throws IOException on IOException
61 */
62 private void writeObject(final ObjectOutputStream out) throws IOException
63 {
64 out.writeObject(this.reference.get());
65 }
66
67 /***
68 * reads a serializable method from stream
69 *
70 * @param in the inputstream
71 * @throws IOException on IOException
72 */
73 private void readObject(final java.io.ObjectInputStream in)
74 throws IOException
75 {
76 try
77 {
78 this.reference = new java.lang.ref.WeakReference(in.readObject());
79 } catch (Exception exception)
80 {
81 throw new IOException(exception.getMessage());
82 }
83 }
84 }