1. /*
  2. * @(#)TypeCode.java 1.51 03/01/23
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package org.omg.CORBA;
  8. import org.omg.CORBA.TypeCodePackage.*;
  9. import org.omg.CORBA.portable.IDLEntity;
  10. /**
  11. * A container for information about a specific CORBA data
  12. * type.
  13. *<P>
  14. * <code>TypeCode</code> objects are used:
  15. * <UL>
  16. * <LI>in the Dynamic Invocation Interface -- to indicate the types
  17. * of the actual arguments or the type of the return value. <BR>
  18. * <code>NamedValue</code> objects are used to represent arguments and
  19. * return values. One of their components is an <code>Any</code>
  20. * object, which in turn has as one of its components a
  21. * <code>TypeCode</code> object.
  22. * <LI>by an Interface Repository to represent the type specifications
  23. * that are part of many OMG IDL declarations
  24. * </UL>
  25. * <P>
  26. * The representation of a <code>TypeCode</code> object is opaque,
  27. * but abstractly, a <code>TypeCode</code> object consists of:
  28. * <UL>
  29. * <LI>a <code>kind</code> field, which is set to an instance
  30. * of the class <code>TCKind</code>
  31. * <LI>zero or more additional fields appropriate
  32. * for the particular kind. For example, the
  33. * <code>TypeCode</code> object
  34. * describing the OMG IDL type <code>1ong</code> has kind
  35. * <code>TCKind.tk_long</code> and no additional fields.
  36. * The <code>TypeCode</code> describing OMG IDL type
  37. * <code>sequence<boolean, 10></code> has a <code>kind</code> field
  38. * with the value
  39. * <code>TCKind.tk_sequence</code> and also fields with the values
  40. * <code>boolean</code> and <code>10</code> for the
  41. * type of sequence elements and the length of the sequence. <p>
  42. * </UL>
  43. *
  44. * <code>TypeCode</code> objects can be obtained in various ways:
  45. * <OL>
  46. * <LI>from a call to the method <code>Any.insert_X</code>, where X is
  47. * a basic IDL type. This method creates a <code>TypeCode</code> object
  48. * for type X and assigns it to the <code>Any</code> object's
  49. * <code>type</code> field.
  50. * <LI>from invocations of methods in the ORB class
  51. * <P>For example, the following creates a <code>TypeCode</code>
  52. * object for a <code>string</code> with a maximum of 30 characters:
  53. * <PRE>
  54. * org.omg.CORBA.TypeCode tcString = orb.create_string_tc(30);
  55. * </PRE>
  56. * <P> The following creates a <code>TypeCode</code>
  57. * object for an <code>array</code> of five <code>string</code>s:
  58. * <PRE>
  59. * org.omg.CORBA.TypeCode tcArray = orb.create_array_tc(
  60. * 5, TCKind.tk_string);
  61. * </PRE>
  62. * <P> The following creates a <code>TypeCode</code>
  63. * object for an interface named "Account":
  64. * <PRE>
  65. * org.omg.CORBA.TypeCode tcInterface = orb.create_interface_tc(
  66. * "thisId", "Account");
  67. * </PRE>
  68. * <LI>as the return value from the <code>_type</code> method
  69. * in <code>Holder</code> classes for user-defined
  70. * IDL types. These <code>Holder</code> classes are generated
  71. * by the <code>idltojava</code> compiler.
  72. * <LI>from a CORBA Interface Repository
  73. * </OL>
  74. * <P>
  75. * Most of the methods in the class <code>TypeCode</code>
  76. * are accessors, and the information contained in a <code>TypeCode</code>
  77. * object is specific to a particular type. Therefore, methods
  78. * must be invoked
  79. * only on the kind of type codes to which they apply. If an
  80. * accessor method
  81. * tries to access information from an inappropriate kind of
  82. * type code, it will throw
  83. * the exception <code>TypeCodePackage.BadKind</code>. For example,
  84. * if the method <code>discriminator_type</code> is called on anything
  85. * other than a <code>union</code>, it will throw <code>BadKind</code>
  86. * because only <code>union</code>s have a discriminator.
  87. * The following list shows which methods apply to which kinds of
  88. * type codes:
  89. * <P>
  90. * These methods may be invoked on all <code>TypeCode</code> kinds:
  91. * <UL>
  92. * <LI><code>equal</code>
  93. * <LI><code>kind</code>
  94. * </UL>
  95. * <P>
  96. * These methods may be invoked on <code>objref</code>, <code>struct</code>,
  97. * <code>union</code>, <code>enum</code>,
  98. * <code>alias</code>, <code>exception</code>, <code>value</code>,
  99. * <code>value_box</code>, <code>native</code>,
  100. * and <code>abstract_interface</code>:
  101. * <UL>
  102. * <LI><code>id</code>
  103. * <LI><code>name</code>
  104. * </UL>
  105. * <P>
  106. * These methods may be invoked on <code>struct</code>,
  107. * <code>union</code>, <code>enum</code>,
  108. * and <code>exception</code>:
  109. * <UL>
  110. * <LI><code>member_count</code>
  111. * <LI><code>member_name</code>
  112. * </UL>
  113. * <P>
  114. * These methods may be invoked on <code>struct</code>,
  115. * <code>union</code>, and <code>exception</code>:
  116. * <UL>
  117. * <LI><code>member_type(int index)</code>
  118. * </UL>
  119. * <P>
  120. * These methods may be invoked on <code>union</code>:
  121. * <UL>
  122. * <LI><code>member_label</code>
  123. * <LI><code>discriminator_type</code>
  124. * <LI><code>default_index</code>
  125. * </UL>
  126. * <P>
  127. * These methods may be invoked on <code>string</code>,
  128. * <code>sequence</code>, and <code>array</code>:
  129. * <UL>
  130. * <LI><code>length</code>
  131. * </UL>
  132. * <P>
  133. * These methods may be invoked on <code>alias</code>,
  134. * <code>sequence</code>, <code>array</code>, and <code>value_box</code>:
  135. * <UL>
  136. * <LI><code>content_type</code>
  137. * </UL>
  138. * <P>
  139. * Unlike other CORBA pseudo-objects, <code>TypeCode</code>
  140. * objects can be passed as general IDL parameters. <p>
  141. * The methods <code>parameter</code> and <code>param_count</code>,
  142. * which are deprecated, are not mapped. <p>
  143. *
  144. * Java IDL extends the CORBA specification to allow all operations permitted
  145. * on a <code>struct</code> <code>TypeCode</code> to be permitted
  146. * on an <code>exception</code> <code>TypeCode</code> as well. <p>
  147. *
  148. * @version 1.25 09/09/97
  149. */
  150. public abstract class TypeCode implements IDLEntity {
  151. /**
  152. * Compares this <code>TypeCode</code> object with the given one,
  153. * testing for equality. <code>TypeCode</code> objects are equal if
  154. * they are interchangeable and give identical results when
  155. * <code>TypeCode</code> operations are applied to them.
  156. *
  157. * @param tc the <code>TypeCode</code> object to compare against
  158. * @return <code>true</code> if the type codes are equal;
  159. * <code>false</code> otherwise
  160. */
  161. public abstract boolean equal(TypeCode tc);
  162. /**
  163. * Tests to see if the given <code>TypeCode</code> object is
  164. * equivalent to this <code>TypeCode</code> object.
  165. * <P>
  166. *
  167. *
  168. * @param tc the typecode to compare with this typecode
  169. *
  170. * @return <code>true</code> if the given typecode is equivalent to
  171. * this typecode; <code>false</code> otherwise
  172. *
  173. */
  174. public abstract boolean equivalent(TypeCode tc);
  175. /**
  176. * Strips out all optional name and member name fields,
  177. * but leaves all alias typecodes intact.
  178. * @return a <code>TypeCode</code> object with optional name and
  179. * member name fields stripped out, except for alias typecodes,
  180. * which are left intact
  181. * @see <a href="package-summary.html#unimpl"><code>CORBA</code> package
  182. * comments for unimplemented features</a>
  183. */
  184. public abstract TypeCode get_compact_typecode();
  185. /**
  186. * Retrieves the kind of this <code>TypeCode</code> object.
  187. * The kind of a type code determines which <code>TypeCode</code>
  188. * methods may legally be invoked on it.
  189. * <P>
  190. * The method <code>kind</code> may be invoked on any
  191. * <code>TypeCode</code> object.
  192. *
  193. * @return the <code>TCKind</code> instance indicating the
  194. * value of the <code>kind</code> field of this
  195. * <code>TypeCode</code> object
  196. */
  197. public abstract TCKind kind();
  198. /**
  199. * Retrieves the RepositoryId globally identifying the type
  200. * of this <code>TypeCode</code> object.
  201. * <P>
  202. * The method <code>id</code> can be invoked on object reference,
  203. * structure, union, enumeration, alias, exception, valuetype,
  204. * boxed valuetype, native, and abstract interface type codes.
  205. * Object reference, exception, valuetype, boxed valuetype,
  206. * native, and abstract interface <code>TypeCode</code> objects
  207. * always have a RepositoryId.
  208. * Structure, union, enumeration, and alias <code>TypeCode</code> objects
  209. * obtained from the Interface Repository or the method
  210. * <code>ORB.create_operation_list</code>
  211. * also always have a RepositoryId. If there is no RepositoryId, the
  212. * method can return an empty string.
  213. *
  214. * @return the RepositoryId for this <code>TypeCode</code> object
  215. * or an empty string if there is no RepositoryID
  216. * @throws org.omg.CORBA.TypeCodePackage.BadKind if the method
  217. * is invoked on an inappropriate kind of<code>TypeCode</code>
  218. * object
  219. */
  220. public abstract String id() throws BadKind;
  221. /**
  222. * Retrieves the simple name identifying this <code>TypeCode</code>
  223. * object within its
  224. * enclosing scope. Since names are local to a Repository, the
  225. * name returned from a <code>TypeCode</code> object
  226. * may not match the name of the
  227. * type in any particular Repository, and may even be an empty
  228. * string.
  229. * <P>
  230. * The method <code>name</code> can be invoked on object reference,
  231. * structure, union, enumeration, alias, exception, valuetype,
  232. * boxed valuetype, native, and abstract interface
  233. * <code>TypeCode</code> objects.
  234. *
  235. * @return the name identifying this <code>TypeCode</code> object
  236. * or an empty string
  237. * @throws org.omg.CORBA.TypeCodePackage.BadKind if the method
  238. * is invoked on an inappropriate kind of<code>TypeCode</code>
  239. * object
  240. */
  241. public abstract String name() throws BadKind;
  242. /**
  243. * Retrieves the number of members in the type described by
  244. * this <code>TypeCode</code> object.
  245. * <P>
  246. * The method <code>member_count</code> can be invoked on
  247. * structure, union, and enumeration <code>TypeCode</code> objects.
  248. * Java IDL extends the CORBA specification to allow this method to
  249. * operate on exceptions as well.
  250. *
  251. * @return the number of members constituting the type described
  252. * by this <code>TypeCode</code> object
  253. *
  254. * @throws org.omg.CORBA.TypeCodePackage.BadKind if the method
  255. * is invoked on an inappropriate kind of <code>TypeCode</code>
  256. * object
  257. */
  258. public abstract int member_count() throws BadKind;
  259. /**
  260. * Retrieves the simple name of the member identified by
  261. * the given index. Since names are local to a
  262. * Repository, the name returned from a <code>TypeCode</code> object
  263. * may not match the name of the member in any particular
  264. * Repository, and may even be an empty string.
  265. * <P>
  266. * The method <code>member_name</code> can be invoked on structure, union,
  267. * and enumeration <code>TypeCode</code> objects.
  268. * Java IDL extends the CORBA specification to allow this method to
  269. * operate on exceptions as well.
  270. *
  271. * @param index index of the member for which a name is being reqested
  272. * @return simple name of the member identified by the
  273. * index or an empty string
  274. * @throws org.omg.CORBA.TypeCodePackage.Bounds if the index is equal
  275. * to or greater than
  276. * the number of members constituting the type
  277. * @throws org.omg.CORBA.TypeCodePackage.BadKind if the method
  278. * is invoked on an inappropriate kind of <code>TypeCode</code>
  279. * object
  280. */
  281. public abstract String member_name(int index)
  282. throws BadKind, org.omg.CORBA.TypeCodePackage.Bounds;
  283. /**
  284. * Retrieves the <code>TypeCode</code> object describing the type
  285. * of the member identified by the given index.
  286. * <P>
  287. * The method <code>member_type</code> can be invoked on structure
  288. * and union <code>TypeCode</code> objects.
  289. * Java IDL extends the CORBA specification to allow this method to
  290. * operate on exceptions as well.
  291. *
  292. * @param index index of the member for which type information
  293. * is begin requested
  294. * @return the <code>TypeCode</code> object describing the
  295. * member at the given index
  296. * @throws org.omg.CORBA.TypeCodePackage.Bounds if the index is
  297. * equal to or greater than
  298. * the number of members constituting the type
  299. * @throws org.omg.CORBA.TypeCodePackage.BadKind if the method
  300. * is invoked on an inappropriate kind of <code>TypeCode</code>
  301. * object
  302. */
  303. public abstract TypeCode member_type(int index)
  304. throws BadKind, org.omg.CORBA.TypeCodePackage.Bounds;
  305. /**
  306. * Retrieves the label of the union member
  307. * identified by the given index. For the default member,
  308. * the label is the zero octet.
  309. *<P>
  310. * The method <code>member_label</code> can only be invoked on union
  311. * <code>TypeCode</code> objects.
  312. *
  313. * @param index index of the union member for which the
  314. * label is being requested
  315. * @return an <code>Any</code> object describing the label of
  316. * the requested union member or the zero octet for
  317. * the default member
  318. * @throws org.omg.CORBA.TypeCodePackage.Bounds if the index is
  319. * equal to or greater than
  320. * the number of members constituting the union
  321. * @throws org.omg.CORBA.TypeCodePackage.BadKind if the method
  322. * is invoked on a non-union <code>TypeCode</code>
  323. * object
  324. */
  325. public abstract Any member_label(int index)
  326. throws BadKind, org.omg.CORBA.TypeCodePackage.Bounds;
  327. /**
  328. * Returns a <code>TypeCode</code> object describing
  329. * all non-default member labels.
  330. * The method <code>discriminator_type</code> can be invoked only
  331. * on union <code>TypeCode</code> objects.
  332. *
  333. * @return the <code>TypeCode</code> object describing
  334. * the non-default member labels
  335. * @throws org.omg.CORBA.TypeCodePackage.BadKind if the method
  336. * is invoked on a non-union <code>TypeCode</code>
  337. * object
  338. */
  339. public abstract TypeCode discriminator_type()
  340. throws BadKind;
  341. /**
  342. * Returns the index of the
  343. * default member, or -1 if there is no default member.
  344. * <P>
  345. * The method <code>default_index</code> can be invoked only on union
  346. * <code>TypeCode</code> objects.
  347. *
  348. * @return the index of the default member, or -1 if
  349. * there is no default member
  350. * @throws org.omg.CORBA.TypeCodePackage.BadKind if the method
  351. * is invoked on a non-union <code>TypeCode</code>
  352. * object
  353. */
  354. public abstract int default_index() throws BadKind;
  355. /**
  356. * Returns the number of elements in the type described by
  357. * this <code>TypeCode</code> object.
  358. * For strings and sequences, it returns the
  359. * bound, with zero indicating an unbounded string or sequence.
  360. * For arrays, it returns the number of elements in the array.
  361. * <P>
  362. * The method <code>length</code> can be invoked on string, sequence, and
  363. * array <code>TypeCode</code> objects.
  364. *
  365. * @return the bound for strings and sequences, or the
  366. * number of elements for arrays
  367. * @throws org.omg.CORBA.TypeCodePackage.BadKind if the method
  368. * is invoked on an inappropriate kind of <code>TypeCode</code>
  369. * object
  370. */
  371. public abstract int length() throws BadKind;
  372. /**
  373. * Returns the <code>TypeCode</code> object representing the
  374. * IDL type for the members of the object described by this
  375. * <code>TypeCode</code> object.
  376. * For sequences and arrays, it returns the
  377. * element type. For aliases, it returns the original type. Note
  378. * that multidimensional arrays are represented by nesting
  379. * <code>TypeCode</code> objects, one per dimension.
  380. * For boxed valuetypes, it returns the boxed type.
  381. *<P>
  382. * The method <code>content_type</code> can be invoked on sequence, array,
  383. * alias, and boxed valuetype <code>TypeCode</code> objects.
  384. *
  385. * @return a <code>TypeCode</code> object representing
  386. * the element type for sequences and arrays, the
  387. * original type for aliases, or the
  388. * boxed type for boxed valuetypes.
  389. * @throws org.omg.CORBA.TypeCodePackage.BadKind if the method
  390. * is invoked on an inappropriate kind of <code>TypeCode</code>
  391. * object
  392. */
  393. public abstract TypeCode content_type() throws BadKind;
  394. /**
  395. * Returns the number of digits in the fixed type described by this
  396. * <code>TypeCode</code> object. For example, the typecode for
  397. * the number 3000.275d could be <code>fixed<7,3></code>, where
  398. * 7 is the precision and 3 is the scale.
  399. *
  400. * @return the total number of digits
  401. * @throws org.omg.CORBA.TypeCodePackage.BadKind if this method
  402. * is invoked on an inappropriate kind of <code>TypeCode</code>
  403. * object
  404. *
  405. */
  406. public abstract short fixed_digits() throws BadKind ;
  407. /**
  408. * Returns the scale of the fixed type described by this
  409. * <code>TypeCode</code> object. A positive number indicates the
  410. * number of digits to the right of the decimal point.
  411. * For example, the number 3000d could have the
  412. * typecode <code>fixed<4,0></code>, where the first number is
  413. * the precision and the second number is the scale.
  414. * A negative number is also possible and adds zeroes to the
  415. * left of the decimal point. In this case, <code>fixed<1,-3></code>,
  416. * could be the typecode for the number 3000d.
  417. *
  418. * @return the scale of the fixed type that this
  419. * <code>TypeCode</code> object describes
  420. * @throws org.omg.CORBA.TypeCodePackage.BadKind if this method
  421. * is invoked on an inappropriate kind of <code>TypeCode</code>
  422. * object
  423. */
  424. public abstract short fixed_scale() throws BadKind ;
  425. /**
  426. * Returns the constant that indicates the visibility of the member
  427. * at the given index.
  428. *
  429. * This operation can only be invoked on non-boxed value
  430. * <code>TypeCode</code> objects.
  431. *
  432. * @param index an <code>int</code> indicating the index into the
  433. * value
  434. * @return either <code>PRIVATE_MEMBER.value</code> or
  435. * <code>PUBLIC_MEMBER.value</code>
  436. * @throws org.omg.CORBA.TypeCodePackage.BadKind if this method
  437. * is invoked on a non-value type <code>TypeCode</code>
  438. * object
  439. * @throws org.omg.CORBA.TypeCodePackage.Bounds
  440. * if the given index is out of bounds
  441. * @see <a href="package-summary.html#unimpl"><code>CORBA</code> package
  442. * comments for unimplemented features</a>
  443. */
  444. abstract public short member_visibility(int index)
  445. throws BadKind, org.omg.CORBA.TypeCodePackage.Bounds ;
  446. /**
  447. * Returns a constant indicating the modifier of the value type
  448. * that this <code>TypeCode</code> object describes. The constant
  449. * returned must be one of the following: <code>VM_NONE.value</code>,
  450. * <code>VM_ABSTRACT.value</code>, <code>VM_CUSTOM.value</code>,
  451. * or <code>VM_TRUNCATABLE.value</code>,
  452. *
  453. * @return a constant describing the value type
  454. * that this <code>TypeCode</code> object describes
  455. * @throws org.omg.CORBA.TypeCodePackage.BadKind
  456. * if this method
  457. * is invoked on a non-value type <code>TypeCode</code>
  458. * object
  459. * @see <a href="package-summary.html#unimpl"><code>CORBA</code> package
  460. * comments for unimplemented features</a>
  461. */
  462. abstract public short type_modifier() throws BadKind ;
  463. /**
  464. * Returns the <code>TypeCode</code> object that describes the concrete base type
  465. * of the value type that this <code>TypeCode</code> object describes.
  466. * Returns null if it doesn't have a concrete base type.
  467. *
  468. * @return the <code>TypeCode</code> object that describes the
  469. * concrete base type of the value type
  470. * that this <code>TypeCode</code> object describes
  471. * @throws org.omg.CORBA.TypeCodePackage.BadKind if this method
  472. * is invoked on a non-boxed value type <code>TypeCode</code> object
  473. * @see <a href="package-summary.html#unimpl"><code>CORBA</code> package
  474. * comments for unimplemented features</a>
  475. */
  476. abstract public TypeCode concrete_base_type() throws BadKind ;
  477. }