1. package org.omg.DynamicAny;
  2. /**
  3. * org/omg/DynamicAny/DynAnyHelper.java .
  4. * Generated by the IDL-to-Java compiler (portable), version "3.2"
  5. * from ../../../../src/share/classes/org/omg/DynamicAny/DynamicAny.idl
  6. * Wednesday, September 15, 2004 10:28:49 AM GMT
  7. */
  8. /**
  9. * Any values can be dynamically interpreted (traversed) and constructed through DynAny objects.
  10. * A DynAny object is associated with a data value which corresponds to a copy of the value
  11. * inserted into an any.
  12. * <P>A DynAny object may be viewed as an ordered collection of component DynAnys.
  13. * For DynAnys representing a basic type, such as long, or a type without components,
  14. * such as an empty exception, the ordered collection of components is empty.
  15. * Each DynAny object maintains the notion of a current position into its collection
  16. * of component DynAnys. The current position is identified by an index value that runs
  17. * from 0 to n-1, where n is the number of components.
  18. * The special index value -1 indicates a current position that points nowhere.
  19. * For values that cannot have a current position (such as an empty exception),
  20. * the index value is fixed at -1.
  21. * If a DynAny is initialized with a value that has components, the index is initialized to 0.
  22. * After creation of an uninitialized DynAny (that is, a DynAny that has no value but a TypeCode
  23. * that permits components), the current position depends on the type of value represented by
  24. * the DynAny. (The current position is set to 0 or -1, depending on whether the new DynAny
  25. * gets default values for its components.)
  26. * <P>The iteration operations rewind, seek, and next can be used to change the current position
  27. * and the current_component operation returns the component at the current position.
  28. * The component_count operation returns the number of components of a DynAny.
  29. * Collectively, these operations enable iteration over the components of a DynAny, for example,
  30. * to (recursively) examine its contents.
  31. * <P>A constructed DynAny object is a DynAny object associated with a constructed type.
  32. * There is a different interface, inheriting from the DynAny interface, associated with
  33. * each kind of constructed type in IDL (fixed, enum, struct, sequence, union, array,
  34. * exception, and value type).
  35. * <P>A constructed DynAny object exports operations that enable the creation of new DynAny objects,
  36. * each of them associated with a component of the constructed data value.
  37. * As an example, a DynStruct is associated with a struct value. This means that the DynStruct
  38. * may be seen as owning an ordered collection of components, one for each structure member.
  39. * The DynStruct object exports operations that enable the creation of new DynAny objects,
  40. * each of them associated with a member of the struct.
  41. * <P>If a DynAny object has been obtained from another (constructed) DynAny object,
  42. * such as a DynAny representing a structure member that was created from a DynStruct,
  43. * the member DynAny is logically contained in the DynStruct.
  44. * Calling an insert or get operation leaves the current position unchanged.
  45. * Destroying a top-level DynAny object (one that was not obtained as a component of another DynAny)
  46. * also destroys any component DynAny objects obtained from it.
  47. * Destroying a non-top level DynAny object does nothing.
  48. * Invoking operations on a destroyed top-level DynAny or any of its descendants raises OBJECT_NOT_EXIST.
  49. * If the programmer wants to destroy a DynAny object but still wants to manipulate some component
  50. * of the data value associated with it, then he or she should first create a DynAny for the component
  51. * and, after that, make a copy of the created DynAny object.
  52. * <P>The behavior of DynAny objects has been defined in order to enable efficient implementations
  53. * in terms of allocated memory space and speed of access. DynAny objects are intended to be used
  54. * for traversing values extracted from anys or constructing values of anys at runtime.
  55. * Their use for other purposes is not recommended.
  56. * <P>Insert and get operations are necessary to handle basic DynAny objects
  57. * but are also helpful to handle constructed DynAny objects.
  58. * Inserting a basic data type value into a constructed DynAny object
  59. * implies initializing the current component of the constructed data value
  60. * associated with the DynAny object. For example, invoking insert_boolean on a
  61. * DynStruct implies inserting a boolean data value at the current position
  62. * of the associated struct data value.
  63. * A type is consistent for inserting or extracting a value if its TypeCode is equivalent to
  64. * the TypeCode contained in the DynAny or, if the DynAny has components, is equivalent to the TypeCode
  65. * of the DynAny at the current position.
  66. * <P>DynAny and DynAnyFactory objects are intended to be local to the process in which they are
  67. * created and used. This means that references to DynAny and DynAnyFactory objects cannot be exported
  68. * to other processes, or externalized with ORB.object_to_string().
  69. * If any attempt is made to do so, the offending operation will raise a MARSHAL system exception.
  70. * Since their interfaces are specified in IDL, DynAny objects export operations defined in the standard
  71. * org.omg.CORBA.Object interface. However, any attempt to invoke operations exported through the Object
  72. * interface may raise the standard NO_IMPLEMENT exception.
  73. * An attempt to use a DynAny object with the DII may raise the NO_IMPLEMENT exception.
  74. */
  75. abstract public class DynAnyHelper
  76. {
  77. private static String _id = "IDL:omg.org/DynamicAny/DynAny:1.0";
  78. public static void insert (org.omg.CORBA.Any a, org.omg.DynamicAny.DynAny that)
  79. {
  80. org.omg.CORBA.portable.OutputStream out = a.create_output_stream ();
  81. a.type (type ());
  82. write (out, that);
  83. a.read_value (out.create_input_stream (), type ());
  84. }
  85. public static org.omg.DynamicAny.DynAny extract (org.omg.CORBA.Any a)
  86. {
  87. return read (a.create_input_stream ());
  88. }
  89. private static org.omg.CORBA.TypeCode __typeCode = null;
  90. synchronized public static org.omg.CORBA.TypeCode type ()
  91. {
  92. if (__typeCode == null)
  93. {
  94. __typeCode = org.omg.CORBA.ORB.init ().create_interface_tc (org.omg.DynamicAny.DynAnyHelper.id (), "DynAny");
  95. }
  96. return __typeCode;
  97. }
  98. public static String id ()
  99. {
  100. return _id;
  101. }
  102. public static org.omg.DynamicAny.DynAny read (org.omg.CORBA.portable.InputStream istream)
  103. {
  104. throw new org.omg.CORBA.MARSHAL ();
  105. }
  106. public static void write (org.omg.CORBA.portable.OutputStream ostream, org.omg.DynamicAny.DynAny value)
  107. {
  108. throw new org.omg.CORBA.MARSHAL ();
  109. }
  110. public static org.omg.DynamicAny.DynAny narrow (org.omg.CORBA.Object obj)
  111. {
  112. if (obj == null)
  113. return null;
  114. else if (obj instanceof org.omg.DynamicAny.DynAny)
  115. return (org.omg.DynamicAny.DynAny)obj;
  116. else if (!obj._is_a (id ()))
  117. throw new org.omg.CORBA.BAD_PARAM ();
  118. else
  119. {
  120. org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate ();
  121. org.omg.DynamicAny._DynAnyStub stub = new org.omg.DynamicAny._DynAnyStub ();
  122. stub._set_delegate(delegate);
  123. return stub;
  124. }
  125. }
  126. public static org.omg.DynamicAny.DynAny unchecked_narrow (org.omg.CORBA.Object obj)
  127. {
  128. if (obj == null)
  129. return null;
  130. else if (obj instanceof org.omg.DynamicAny.DynAny)
  131. return (org.omg.DynamicAny.DynAny)obj;
  132. else
  133. {
  134. org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate ();
  135. org.omg.DynamicAny._DynAnyStub stub = new org.omg.DynamicAny._DynAnyStub ();
  136. stub._set_delegate(delegate);
  137. return stub;
  138. }
  139. }
  140. }