1. /*
  2. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  3. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  4. */
  5. /*
  6. * @(#)LegacyHookGetFields.java 1.5 03/12/19
  7. */
  8. package com.sun.corba.se.impl.orbutil;
  9. import java.io.*;
  10. import java.util.Hashtable;
  11. class LegacyHookGetFields extends ObjectInputStream.GetField {
  12. private Hashtable fields = null;
  13. LegacyHookGetFields(Hashtable fields){
  14. this.fields = fields;
  15. }
  16. /**
  17. * Get the ObjectStreamClass that describes the fields in the stream.
  18. */
  19. public java.io.ObjectStreamClass getObjectStreamClass() {
  20. return null;
  21. }
  22. /**
  23. * Return true if the named field is defaulted and has no value
  24. * in this stream.
  25. */
  26. public boolean defaulted(String name)
  27. throws IOException, IllegalArgumentException {
  28. return (!fields.containsKey(name));
  29. }
  30. /**
  31. * Get the value of the named boolean field from the persistent field.
  32. */
  33. public boolean get(String name, boolean defvalue)
  34. throws IOException, IllegalArgumentException {
  35. if (defaulted(name))
  36. return defvalue;
  37. else return ((Boolean)fields.get(name)).booleanValue();
  38. }
  39. /**
  40. * Get the value of the named char field from the persistent fields.
  41. */
  42. public char get(String name, char defvalue)
  43. throws IOException, IllegalArgumentException {
  44. if (defaulted(name))
  45. return defvalue;
  46. else return ((Character)fields.get(name)).charValue();
  47. }
  48. /**
  49. * Get the value of the named byte field from the persistent fields.
  50. */
  51. public byte get(String name, byte defvalue)
  52. throws IOException, IllegalArgumentException {
  53. if (defaulted(name))
  54. return defvalue;
  55. else return ((Byte)fields.get(name)).byteValue();
  56. }
  57. /**
  58. * Get the value of the named short field from the persistent fields.
  59. */
  60. public short get(String name, short defvalue)
  61. throws IOException, IllegalArgumentException {
  62. if (defaulted(name))
  63. return defvalue;
  64. else return ((Short)fields.get(name)).shortValue();
  65. }
  66. /**
  67. * Get the value of the named int field from the persistent fields.
  68. */
  69. public int get(String name, int defvalue)
  70. throws IOException, IllegalArgumentException {
  71. if (defaulted(name))
  72. return defvalue;
  73. else return ((Integer)fields.get(name)).intValue();
  74. }
  75. /**
  76. * Get the value of the named long field from the persistent fields.
  77. */
  78. public long get(String name, long defvalue)
  79. throws IOException, IllegalArgumentException {
  80. if (defaulted(name))
  81. return defvalue;
  82. else return ((Long)fields.get(name)).longValue();
  83. }
  84. /**
  85. * Get the value of the named float field from the persistent fields.
  86. */
  87. public float get(String name, float defvalue)
  88. throws IOException, IllegalArgumentException {
  89. if (defaulted(name))
  90. return defvalue;
  91. else return ((Float)fields.get(name)).floatValue();
  92. }
  93. /**
  94. * Get the value of the named double field from the persistent field.
  95. */
  96. public double get(String name, double defvalue)
  97. throws IOException, IllegalArgumentException {
  98. if (defaulted(name))
  99. return defvalue;
  100. else return ((Double)fields.get(name)).doubleValue();
  101. }
  102. /**
  103. * Get the value of the named Object field from the persistent field.
  104. */
  105. public Object get(String name, Object defvalue)
  106. throws IOException, IllegalArgumentException {
  107. if (defaulted(name))
  108. return defvalue;
  109. else return fields.get(name);
  110. }
  111. public String toString(){
  112. return fields.toString();
  113. }
  114. }