1. /*
  2. * @(#)DynValueBoxImpl.java 1.6 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.corba.se.internal.DynamicAny;
  8. import org.omg.CORBA.ORB;
  9. import org.omg.CORBA.TypeCode;
  10. import org.omg.CORBA.TCKind;
  11. import org.omg.CORBA.Any;
  12. import org.omg.CORBA.NO_IMPLEMENT;
  13. import org.omg.CORBA.OBJECT_NOT_EXIST;
  14. import org.omg.CORBA.TypeCodePackage.BadKind;
  15. import org.omg.CORBA.TypeCodePackage.Bounds;
  16. import org.omg.DynamicAny.*;
  17. import org.omg.DynamicAny.DynAnyPackage.TypeMismatch;
  18. import org.omg.DynamicAny.DynAnyPackage.InvalidValue;
  19. import org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode;
  20. public class DynValueBoxImpl extends DynValueCommonImpl implements DynValueBox
  21. {
  22. //
  23. // Constructors
  24. //
  25. private DynValueBoxImpl() {
  26. this(null, (Any)null, false);
  27. }
  28. protected DynValueBoxImpl(ORB orb, Any any, boolean copyValue) {
  29. super(orb, any, copyValue);
  30. }
  31. protected DynValueBoxImpl(ORB orb, TypeCode typeCode) {
  32. super(orb, typeCode);
  33. }
  34. //
  35. // DynValueBox methods
  36. //
  37. public Any get_boxed_value()
  38. throws org.omg.DynamicAny.DynAnyPackage.InvalidValue
  39. {
  40. if (isNull) {
  41. throw new InvalidValue();
  42. }
  43. checkInitAny();
  44. return any;
  45. }
  46. public void set_boxed_value(org.omg.CORBA.Any boxed)
  47. throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch
  48. {
  49. if ( ! isNull && ! boxed.type().equal(this.type())) {
  50. throw new TypeMismatch();
  51. }
  52. clearData();
  53. any = boxed;
  54. representations = REPRESENTATION_ANY;
  55. index = 0;
  56. isNull = false;
  57. }
  58. public DynAny get_boxed_value_as_dyn_any()
  59. throws org.omg.DynamicAny.DynAnyPackage.InvalidValue
  60. {
  61. if (isNull) {
  62. throw new InvalidValue();
  63. }
  64. checkInitComponents();
  65. return components[0];
  66. }
  67. public void set_boxed_value_as_dyn_any(DynAny boxed)
  68. throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch
  69. {
  70. if ( ! isNull && ! boxed.type().equal(this.type())) {
  71. throw new TypeMismatch();
  72. }
  73. clearData();
  74. components = new DynAny[] {boxed};
  75. representations = REPRESENTATION_COMPONENTS;
  76. index = 0;
  77. isNull = false;
  78. }
  79. protected boolean initializeComponentsFromAny() {
  80. try {
  81. components = new DynAny[] {DynAnyUtil.createMostDerivedDynAny(any, orb, false)};
  82. } catch (InconsistentTypeCode ictc) {
  83. return false; // impossible
  84. }
  85. return true;
  86. }
  87. protected boolean initializeComponentsFromTypeCode() {
  88. try {
  89. any = DynAnyUtil.createDefaultAnyOfType(any.type(), orb);
  90. components = new DynAny[] {DynAnyUtil.createMostDerivedDynAny(any, orb, false)};
  91. } catch (InconsistentTypeCode ictc) {
  92. return false; // impossible
  93. }
  94. return true;
  95. }
  96. protected boolean initializeAnyFromComponents() {
  97. any = getAny(components[0]);
  98. return true;
  99. }
  100. }