jdk/src/share/classes/javax/sql/rowset/serial/SerialRef.java
author lancea
Thu, 27 Jun 2013 15:07:56 -0400
changeset 18564 f9db68ff2cbb
parent 18149 5997c9aedb0e
child 24968 3308660aa3f2
permissions -rw-r--r--
8017471: Fix JDBC -Xdoclint public errors Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
18564
f9db68ff2cbb 8017471: Fix JDBC -Xdoclint public errors
lancea
parents: 18149
diff changeset
     2
 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.sql.rowset.serial;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.sql.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * A serialized mapping of a <code>Ref</code> object, which is the mapping in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * Java programming language of an SQL <code>REF</code> value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * The <code>SerialRef</code> class provides a constructor  for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * creating a <code>SerialRef</code> instance from a <code>Ref</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * object and provides methods for getting and setting the <code>Ref</code> object.
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14409
diff changeset
    39
 *
18564
f9db68ff2cbb 8017471: Fix JDBC -Xdoclint public errors
lancea
parents: 18149
diff changeset
    40
 * <h3> Thread safety </h3>
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14409
diff changeset
    41
 *
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14409
diff changeset
    42
 * A SerialRef 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
    43
 * SerialRef is to be used by more than one thread then access to the SerialRef
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14409
diff changeset
    44
 * should be controlled by appropriate synchronization.
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14409
diff changeset
    45
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
public class SerialRef implements Ref, Serializable, Cloneable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * String containing the base type name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private String baseTypeName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * This will store the type <code>Ref</code> as an <code>Object</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private Object object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * Private copy of the Ref reference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private Ref reference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * Constructs a <code>SerialRef</code> object from the given <code>Ref</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * @param ref a Ref object; cannot be <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * @throws SQLException if a database access occurs; if <code>ref</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     *     is <code>null</code>; or if the <code>Ref</code> object returns a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     *     <code>null</code> value base type name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * @throws SerialException if an error occurs serializing the <code>Ref</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     *     object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public SerialRef(Ref ref) throws SerialException, SQLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        if (ref == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            throw new SQLException("Cannot instantiate a SerialRef object " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                "with a null Ref object");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        reference = ref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        object = ref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        if (ref.getBaseTypeName() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            throw new SQLException("Cannot instantiate a SerialRef object " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                "that returns a null base type name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        } else {
6692
aef4e294026f 6988993: Address Findbugs warnings for the use of String Constructor
lancea
parents: 5506
diff changeset
    87
            baseTypeName = ref.getBaseTypeName();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * Returns a string describing the base type name of the <code>Ref</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @return a string of the base type name of the Ref
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @throws SerialException in no Ref object has been set
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    public String getBaseTypeName() throws SerialException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        return baseTypeName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * Returns an <code>Object</code> representing the SQL structured type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * to which this <code>SerialRef</code> object refers.  The attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * of the structured type are mapped according to the given type map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @param map a <code>java.util.Map</code> object containing zero or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *        more entries, with each entry consisting of 1) a <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *        giving the fully qualified name of a UDT and 2) the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *        <code>Class</code> object for the <code>SQLData</code> implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *        that defines how the UDT is to be mapped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @return an object instance resolved from the Ref reference and mapped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *        according to the supplied type map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @throws SerialException if an error is encountered in the reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     *        resolution
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public Object getObject(java.util.Map<String,Class<?>> map)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        throws SerialException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    {
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 6697
diff changeset
   119
        map = new Hashtable<String, Class<?>>(map);
6697
39929804f9d4 6989139: Address JDBC Findbugs where Number type Constructor are used
lancea
parents: 6692
diff changeset
   120
        if (object != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            return map.get(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            throw new SerialException("The object is not set");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * Returns an <code>Object</code> representing the SQL structured type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * to which this <code>SerialRef</code> object refers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @return an object instance resolved from the Ref reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @throws SerialException if an error is encountered in the reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *         resolution
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public Object getObject() throws SerialException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        if (reference != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                return reference.getObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            } catch (SQLException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                throw new SerialException("SQLException: " + e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        if (object != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            return object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        throw new SerialException("The object is not set");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * Sets the SQL structured type that this <code>SerialRef</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * references to the given <code>Object</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @param obj an <code>Object</code> representing the SQL structured type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *        to be referenced
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @throws SerialException if an error is encountered generating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * the structured type referenced by this <code>SerialRef</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    public void setObject(Object obj) throws SerialException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            reference.setObject(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        } catch (SQLException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            throw new SerialException("SQLException: " + e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        object = obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    /**
14409
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   173
     * Compares this SerialRef to the specified object.  The result is {@code
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   174
     * true} if and only if the argument is not {@code null} and is a {@code
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   175
     * SerialRef} object that represents the same object as this
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   176
     * object.
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   177
     *
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   178
     * @param  obj The object to compare this {@code SerialRef} against
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   179
     *
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   180
     * @return  {@code true} if the given object represents a {@code SerialRef}
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   181
     *          equivalent to this SerialRef, {@code false} otherwise
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   182
     *
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   183
     */
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   184
    public boolean equals(Object obj) {
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   185
        if (this == obj) {
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   186
            return true;
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   187
        }
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   188
        if(obj instanceof SerialRef) {
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   189
            SerialRef ref = (SerialRef)obj;
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   190
            return baseTypeName.equals(ref.baseTypeName) &&
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   191
                    object.equals(ref.object);
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   192
        }
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   193
        return false;
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   194
    }
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   195
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   196
    /**
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   197
     * Returns a hash code for this {@code SerialRef}.
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   198
     * @return  a hash code value for this object.
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   199
     */
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   200
    public int hashCode() {
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   201
        return (31 + object.hashCode()) * 31 + baseTypeName.hashCode();
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   202
    }
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   203
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   204
    /**
18149
5997c9aedb0e 8016101: Fix typo in SerialRef and missing @param in SerialStruct
lancea
parents: 14781
diff changeset
   205
     * Returns a clone of this {@code SerialRef}.
14409
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   206
     * The underlying {@code Ref} object will be set to null.
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   207
     *
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   208
     * @return  a clone of this SerialRef
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   209
     */
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   210
    public Object clone() {
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   211
        try {
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   212
            SerialRef ref = (SerialRef) super.clone();
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   213
            ref.reference = null;
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   214
            return ref;
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   215
        } catch (CloneNotSupportedException ex) {
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   216
            // this shouldn't happen, since we are Cloneable
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   217
            throw new InternalError();
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   218
        }
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   219
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   220
    }
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   221
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   222
    /**
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   223
     * readObject is called to restore the state of the SerialRef from
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   224
     * a stream.
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   225
     */
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   226
    private void readObject(ObjectInputStream s)
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   227
            throws IOException, ClassNotFoundException {
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   228
        ObjectInputStream.GetField fields = s.readFields();
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   229
        object = fields.get("object", null);
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   230
        baseTypeName = (String) fields.get("baseTypeName", null);
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   231
        reference = (Ref) fields.get("reference", null);
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   232
    }
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   233
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   234
    /**
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   235
     * writeObject is called to save the state of the SerialRef
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   236
     * to a stream.
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   237
     */
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   238
    private void writeObject(ObjectOutputStream s)
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   239
            throws IOException, ClassNotFoundException {
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   240
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   241
        ObjectOutputStream.PutField fields = s.putFields();
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   242
        fields.put("baseTypeName", baseTypeName);
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   243
        fields.put("object", object);
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   244
        // Note: this check to see if it is an instance of Serializable
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   245
        // is for backwards compatibiity
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   246
        fields.put("reference", reference instanceof Serializable ? reference : null);
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   247
        s.writeFields();
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   248
    }
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   249
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   250
    /**
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 14342
diff changeset
   251
     * The identifier that assists in the serialization of this <code>SerialRef</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    static final long serialVersionUID = -4727123500609662274L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
}