LegacyHookGetFields.java revision 608:7e06bf1dcb09
1/*
2 * Copyright (c) 2001, 2002, 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
23 * questions.
24 */
25
26/*
27 */
28package com.sun.corba.se.impl.orbutil;
29
30import java.io.*;
31import java.util.Hashtable;
32
33class LegacyHookGetFields extends ObjectInputStream.GetField {
34    private Hashtable fields = null;
35
36    LegacyHookGetFields(Hashtable fields){
37        this.fields = fields;
38    }
39
40    /**
41     * Get the ObjectStreamClass that describes the fields in the stream.
42     */
43    public java.io.ObjectStreamClass getObjectStreamClass() {
44        return null;
45    }
46
47    /**
48     * Return true if the named field is defaulted and has no value
49     * in this stream.
50     */
51    public boolean defaulted(String name)
52        throws IOException, IllegalArgumentException  {
53        return (!fields.containsKey(name));
54    }
55
56    /**
57     * Get the value of the named boolean field from the persistent field.
58     */
59    public boolean get(String name, boolean defvalue)
60        throws IOException, IllegalArgumentException {
61        if (defaulted(name))
62            return defvalue;
63        else return ((Boolean)fields.get(name)).booleanValue();
64    }
65
66    /**
67     * Get the value of the named char field from the persistent fields.
68     */
69    public char get(String name, char defvalue)
70        throws IOException, IllegalArgumentException {
71        if (defaulted(name))
72            return defvalue;
73        else return ((Character)fields.get(name)).charValue();
74
75    }
76
77    /**
78     * Get the value of the named byte field from the persistent fields.
79     */
80    public byte get(String name, byte defvalue)
81        throws IOException, IllegalArgumentException {
82        if (defaulted(name))
83            return defvalue;
84        else return ((Byte)fields.get(name)).byteValue();
85
86    }
87
88    /**
89     * Get the value of the named short field from the persistent fields.
90     */
91    public short get(String name, short defvalue)
92        throws IOException, IllegalArgumentException {
93        if (defaulted(name))
94            return defvalue;
95        else return ((Short)fields.get(name)).shortValue();
96
97    }
98
99    /**
100     * Get the value of the named int field from the persistent fields.
101     */
102    public int get(String name, int defvalue)
103        throws IOException, IllegalArgumentException {
104        if (defaulted(name))
105            return defvalue;
106        else return ((Integer)fields.get(name)).intValue();
107
108    }
109
110    /**
111     * Get the value of the named long field from the persistent fields.
112     */
113    public long get(String name, long defvalue)
114        throws IOException, IllegalArgumentException {
115        if (defaulted(name))
116            return defvalue;
117        else return ((Long)fields.get(name)).longValue();
118
119    }
120
121    /**
122     * Get the value of the named float field from the persistent fields.
123     */
124    public float get(String name, float defvalue)
125        throws IOException, IllegalArgumentException {
126        if (defaulted(name))
127            return defvalue;
128        else return ((Float)fields.get(name)).floatValue();
129
130    }
131
132    /**
133     * Get the value of the named double field from the persistent field.
134     */
135    public double get(String name, double defvalue)
136        throws IOException, IllegalArgumentException  {
137        if (defaulted(name))
138            return defvalue;
139        else return ((Double)fields.get(name)).doubleValue();
140
141    }
142
143    /**
144     * Get the value of the named Object field from the persistent field.
145     */
146    public Object get(String name, Object defvalue)
147        throws IOException, IllegalArgumentException {
148        if (defaulted(name))
149            return defvalue;
150        else return fields.get(name);
151
152    }
153
154    public String toString(){
155        return fields.toString();
156    }
157}
158