01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package javax.sql.rowset.serial;
19:
20: import java.io.Serializable;
21: import java.sql.Ref;
22: import java.sql.SQLException;
23: import java.util.Map;
24:
25: import org.apache.harmony.sql.internal.nls.Messages;
26:
27: public class SerialRef implements Ref, Serializable, Cloneable {
28: private static final long serialVersionUID = -4727123500609662274L;
29:
30: /**
31: * required by serialized form
32: */
33: private String baseTypeName;
34:
35: /**
36: * store <code> reference </code> as an object, required by serialized form.
37: */
38: private Object object;
39:
40: /**
41: * required by serialized form
42: */
43: private Ref reference;
44:
45: public SerialRef(Ref ref) throws SerialException, SQLException {
46: if (ref == null) {
47: throw new SQLException(Messages.getString("sql.9")); //$NON-NLS-1$
48: }
49: reference = ref;
50: object = ref;
51: baseTypeName = ref.getBaseTypeName();
52: if (baseTypeName == null) {
53: throw new SQLException(Messages.getString("sql.10"));//$NON-NLS-1$
54: }
55: }
56:
57: public String getBaseTypeName() throws SerialException {
58: return baseTypeName;
59: }
60:
61: public Object getObject() throws SerialException {
62: try {
63: return reference.getObject();
64: } catch (SQLException e) {
65: throw new SerialException(Messages.getString(
66: "sql.11", e.getMessage())); //$NON-NLS-1$
67: }
68: }
69:
70: public Object getObject(Map<String, Class<?>> map)
71: throws SerialException {
72: return map.get(object);
73: }
74:
75: public void setObject(Object value) throws SerialException {
76: try {
77: reference.setObject(value);
78: object = value;
79: } catch (SQLException e) {
80: throw new SerialException(Messages.getString(
81: "sql.11", e.getMessage())); //$NON-NLS-1$
82: }
83: }
84:
85: }
|