1. /*
  2. * @(#)DynValueCommonImpl.java 1.8 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.corba.se.impl.dynamicany;
  8. import org.omg.CORBA.TypeCode;
  9. import org.omg.CORBA.TCKind;
  10. import org.omg.CORBA.Any;
  11. import org.omg.CORBA.TypeCodePackage.BadKind;
  12. import org.omg.CORBA.TypeCodePackage.Bounds;
  13. import org.omg.DynamicAny.*;
  14. import org.omg.DynamicAny.DynAnyPackage.TypeMismatch;
  15. import org.omg.DynamicAny.DynAnyPackage.InvalidValue;
  16. import org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode;
  17. import com.sun.corba.se.spi.orb.ORB ;
  18. import com.sun.corba.se.spi.logging.CORBALogDomains ;
  19. import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
  20. abstract class DynValueCommonImpl extends DynAnyComplexImpl implements DynValueCommon
  21. {
  22. //
  23. // Constructors
  24. //
  25. protected boolean isNull;
  26. private DynValueCommonImpl() {
  27. this(null, (Any)null, false);
  28. isNull = true;
  29. }
  30. protected DynValueCommonImpl(ORB orb, Any any, boolean copyValue) {
  31. super(orb, any, copyValue);
  32. isNull = checkInitComponents();
  33. }
  34. protected DynValueCommonImpl(ORB orb, TypeCode typeCode) {
  35. super(orb, typeCode);
  36. isNull = true;
  37. }
  38. //
  39. // DynValueCommon methods
  40. //
  41. // Returns TRUE if this object represents a null valuetype
  42. public boolean is_null() {
  43. return isNull;
  44. }
  45. // Changes the representation to a null valuetype.
  46. public void set_to_null() {
  47. isNull = true;
  48. clearData();
  49. }
  50. // If this object represents a null valuetype then this operation
  51. // replaces it with a newly constructed value with its components
  52. // initialized to default values as in DynAnyFactory::create_dyn_any_from_type_code.
  53. // If this object represents a non-null valuetype, then this operation has no effect.
  54. public void set_to_value() {
  55. if (isNull) {
  56. isNull = false;
  57. // the rest is done lazily
  58. }
  59. // else: there is nothing to do
  60. }
  61. //
  62. // Methods differing from DynStruct
  63. //
  64. // Required to raise InvalidValue if this is a null value type.
  65. public org.omg.DynamicAny.NameValuePair[] get_members ()
  66. throws org.omg.DynamicAny.DynAnyPackage.InvalidValue
  67. {
  68. if (status == STATUS_DESTROYED) {
  69. throw wrapper.dynAnyDestroyed() ;
  70. }
  71. if (isNull) {
  72. throw new InvalidValue();
  73. }
  74. checkInitComponents();
  75. return nameValuePairs;
  76. }
  77. // Required to raise InvalidValue if this is a null value type.
  78. public org.omg.DynamicAny.NameDynAnyPair[] get_members_as_dyn_any ()
  79. throws org.omg.DynamicAny.DynAnyPackage.InvalidValue
  80. {
  81. if (status == STATUS_DESTROYED) {
  82. throw wrapper.dynAnyDestroyed() ;
  83. }
  84. if (isNull) {
  85. throw new InvalidValue();
  86. }
  87. checkInitComponents();
  88. return nameDynAnyPairs;
  89. }
  90. //
  91. // Overridden methods
  92. //
  93. // Overridden to change to non-null status.
  94. public void set_members (org.omg.DynamicAny.NameValuePair[] value)
  95. throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch,
  96. org.omg.DynamicAny.DynAnyPackage.InvalidValue
  97. {
  98. super.set_members(value);
  99. // If we didn't get an exception then this must be a valid non-null value
  100. isNull = false;
  101. }
  102. // Overridden to change to non-null status.
  103. public void set_members_as_dyn_any (org.omg.DynamicAny.NameDynAnyPair[] value)
  104. throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch,
  105. org.omg.DynamicAny.DynAnyPackage.InvalidValue
  106. {
  107. super.set_members_as_dyn_any(value);
  108. // If we didn't get an exception then this must be a valid non-null value
  109. isNull = false;
  110. }
  111. }