KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > orbutil > LegacyHookGetFields


1 /*
2  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
3  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
4  */

5
6 /*
7  * @(#)LegacyHookGetFields.java 1.5 03/12/19
8  */

9 package com.sun.corba.se.impl.orbutil;
10
11 import java.io.*;
12 import java.util.Hashtable JavaDoc;
13
14 class LegacyHookGetFields extends ObjectInputStream.GetField {
15     private Hashtable JavaDoc fields = null;
16
17     LegacyHookGetFields(Hashtable JavaDoc fields){
18         this.fields = fields;
19     }
20
21     /**
22      * Get the ObjectStreamClass that describes the fields in the stream.
23      */

24     public java.io.ObjectStreamClass JavaDoc getObjectStreamClass() {
25         return null;
26     }
27         
28     /**
29      * Return true if the named field is defaulted and has no value
30      * in this stream.
31      */

32     public boolean defaulted(String JavaDoc name)
33         throws IOException, IllegalArgumentException JavaDoc {
34         return (!fields.containsKey(name));
35     }
36         
37     /**
38      * Get the value of the named boolean field from the persistent field.
39      */

40     public boolean get(String JavaDoc name, boolean defvalue)
41         throws IOException, IllegalArgumentException JavaDoc {
42         if (defaulted(name))
43             return defvalue;
44         else return ((Boolean JavaDoc)fields.get(name)).booleanValue();
45     }
46         
47     /**
48      * Get the value of the named char field from the persistent fields.
49      */

50     public char get(String JavaDoc name, char defvalue)
51         throws IOException, IllegalArgumentException JavaDoc {
52         if (defaulted(name))
53             return defvalue;
54         else return ((Character JavaDoc)fields.get(name)).charValue();
55
56     }
57         
58     /**
59      * Get the value of the named byte field from the persistent fields.
60      */

61     public byte get(String JavaDoc name, byte defvalue)
62         throws IOException, IllegalArgumentException JavaDoc {
63         if (defaulted(name))
64             return defvalue;
65         else return ((Byte JavaDoc)fields.get(name)).byteValue();
66
67     }
68         
69     /**
70      * Get the value of the named short field from the persistent fields.
71      */

72     public short get(String JavaDoc name, short defvalue)
73         throws IOException, IllegalArgumentException JavaDoc {
74         if (defaulted(name))
75             return defvalue;
76         else return ((Short JavaDoc)fields.get(name)).shortValue();
77
78     }
79         
80     /**
81      * Get the value of the named int field from the persistent fields.
82      */

83     public int get(String JavaDoc name, int defvalue)
84         throws IOException, IllegalArgumentException JavaDoc {
85         if (defaulted(name))
86             return defvalue;
87         else return ((Integer JavaDoc)fields.get(name)).intValue();
88
89     }
90         
91     /**
92      * Get the value of the named long field from the persistent fields.
93      */

94     public long get(String JavaDoc name, long defvalue)
95         throws IOException, IllegalArgumentException JavaDoc {
96         if (defaulted(name))
97             return defvalue;
98         else return ((Long JavaDoc)fields.get(name)).longValue();
99
100     }
101         
102     /**
103      * Get the value of the named float field from the persistent fields.
104      */

105     public float get(String JavaDoc name, float defvalue)
106         throws IOException, IllegalArgumentException JavaDoc {
107         if (defaulted(name))
108             return defvalue;
109         else return ((Float JavaDoc)fields.get(name)).floatValue();
110
111     }
112         
113     /**
114      * Get the value of the named double field from the persistent field.
115      */

116     public double get(String JavaDoc name, double defvalue)
117         throws IOException, IllegalArgumentException JavaDoc {
118         if (defaulted(name))
119             return defvalue;
120         else return ((Double JavaDoc)fields.get(name)).doubleValue();
121
122     }
123         
124     /**
125      * Get the value of the named Object field from the persistent field.
126      */

127     public Object JavaDoc get(String JavaDoc name, Object JavaDoc defvalue)
128         throws IOException, IllegalArgumentException JavaDoc {
129         if (defaulted(name))
130             return defvalue;
131         else return fields.get(name);
132
133     }
134         
135     public String JavaDoc toString(){
136         return fields.toString();
137     }
138 }
139
Popular Tags