1. /*
  2. * @(#)TypeCode.java 1.51 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 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. * Not implemented; see package comments.
  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. * @see <a href="package-summary.html#unimpl"><code>CORBA</code> package
  173. * comments for unimplemented features</a>
  174. */
  175. public abstract boolean equivalent(TypeCode tc);
  176. /**
  177. * Strips out all optional name and member name fields,
  178. * but leaves all alias typecodes intact.
  179. * @return a <code>TypeCode</code> object with optional name and
  180. * member name fields stripped out, except for alias typecodes,
  181. * which are left intact
  182. * @see <a href="package-summary.html#unimpl"><code>CORBA</code> package
  183. * comments for unimplemented features</a>
  184. */
  185. public abstract TypeCode get_compact_typecode();
  186. /**
  187. * Retrieves the kind of this <code>TypeCode</code> object.
  188. * The kind of a type code determines which <code>TypeCode</code>
  189. * methods may legally be invoked on it.
  190. * <P>
  191. * The method <code>kind</code> may be invoked on any
  192. * <code>TypeCode</code> object.
  193. *
  194. * @return the <code>TCKind</code> instance indicating the
  195. * value of the <code>kind</code> field of this
  196. * <code>TypeCode</code> object
  197. */
  198. public abstract TCKind kind();
  199. /**
  200. * Retrieves the RepositoryId globally identifying the type
  201. * of this <code>TypeCode</code> object.
  202. * <P>
  203. * The method <code>id</code> can be invoked on object reference,
  204. * structure, union, enumeration, alias, exception, valuetype,
  205. * boxed valuetype, native, and abstract interface type codes.
  206. * Object reference, exception, valuetype, boxed valuetype,
  207. * native, and abstract interface <code>TypeCode</code> objects
  208. * always have a RepositoryId.
  209. * Structure, union, enumeration, and alias <code>TypeCode</code> objects
  210. * obtained from the Interface Repository or the method
  211. * <code>ORB.create_operation_list</code>
  212. * also always have a RepositoryId. If there is no RepositoryId, the
  213. * method can return an empty string.
  214. *
  215. * @return the RepositoryId for this <code>TypeCode</code> object
  216. * or an empty string if there is no RepositoryID
  217. * @throws org.omg.CORBA.TypeCodePackage.BadKind if the method
  218. * is invoked on an inappropriate kind of<code>TypeCode</code>
  219. * object
  220. */
  221. public abstract String id() throws BadKind;
  222. /**
  223. * Retrieves the simple name identifying this <code>TypeCode</code>
  224. * object within its
  225. * enclosing scope. Since names are local to a Repository, the
  226. * name returned from a <code>TypeCode</code> object
  227. * may not match the name of the
  228. * type in any particular Repository, and may even be an empty
  229. * string.
  230. * <P>
  231. * The method <code>name</code> can be invoked on object reference,
  232. * structure, union, enumeration, alias, exception, valuetype,
  233. * boxed valuetype, native, and abstract interface
  234. * <code>TypeCode</code> objects.
  235. *
  236. * @return the name identifying this <code>TypeCode</code> object
  237. * or an empty string
  238. * @throws org.omg.CORBA.TypeCodePackage.BadKind if the method
  239. * is invoked on an inappropriate kind of<code>TypeCode</code>
  240. * object
  241. */
  242. public abstract String name() throws BadKind;
  243. /**
  244. * Retrieves the number of members in the type described by
  245. * this <code>TypeCode</code> object.
  246. * <P>
  247. * The method <code>member_count</code> can be invoked on
  248. * structure, union, and enumeration <code>TypeCode</code> objects.
  249. * Java IDL extends the CORBA specification to allow this method to
  250. * operate on exceptions as well.
  251. *
  252. * @return the number of members constituting the type described
  253. * by this <code>TypeCode</code> object
  254. *
  255. * @throws org.omg.CORBA.TypeCodePackage.BadKind if the method
  256. * is invoked on an inappropriate kind of <code>TypeCode</code>
  257. * object
  258. */
  259. public abstract int member_count() throws BadKind;
  260. /**
  261. * Retrieves the simple name of the member identified by
  262. * the given index. Since names are local to a
  263. * Repository, the name returned from a <code>TypeCode</code> object
  264. * may not match the name of the member in any particular
  265. * Repository, and may even be an empty string.
  266. * <P>
  267. * The method <code>member_name</code> can be invoked on structure, union,
  268. * and enumeration <code>TypeCode</code> objects.
  269. * Java IDL extends the CORBA specification to allow this method to
  270. * operate on exceptions as well.
  271. *
  272. * @param index index of the member for which a name is being reqested
  273. * @return simple name of the member identified by the
  274. * index or an empty string
  275. * @throws org.omg.CORBA.TypeCodePackage.Bounds if the index is equal
  276. * to or greater than
  277. * the number of members constituting the type
  278. * @throws org.omg.CORBA.TypeCodePackage.BadKind if the method
  279. * is invoked on an inappropriate kind of <code>TypeCode</code>
  280. * object
  281. */
  282. public abstract String member_name(int index)
  283. throws BadKind, org.omg.CORBA.TypeCodePackage.Bounds;
  284. /**
  285. * Retrieves the <code>TypeCode</code> object describing the type
  286. * of the member identified by the given index.
  287. * <P>
  288. * The method <code>member_type</code> can be invoked on structure
  289. * and union <code>TypeCode</code> objects.
  290. * Java IDL extends the CORBA specification to allow this method to
  291. * operate on exceptions as well.
  292. *
  293. * @param index index of the member for which type information
  294. * is begin requested
  295. * @return the <code>TypeCode</code> object describing the
  296. * member at the given index
  297. * @throws org.omg.CORBA.TypeCodePackage.Bounds if the index is
  298. * equal to or greater than
  299. * the number of members constituting the type
  300. * @throws org.omg.CORBA.TypeCodePackage.BadKind if the method
  301. * is invoked on an inappropriate kind of <code>TypeCode</code>
  302. * object
  303. */
  304. public abstract TypeCode member_type(int index)
  305. throws BadKind, org.omg.CORBA.TypeCodePackage.Bounds;
  306. /**
  307. * Retrieves the label of the union member
  308. * identified by the given index. For the default member,
  309. * the label is the zero octet.
  310. *<P>
  311. * The method <code>member_label</code> can only be invoked on union
  312. * <code>TypeCode</code> objects.
  313. *
  314. * @param index index of the union member for which the
  315. * label is being requested
  316. * @return an <code>Any</code> object describing the label of
  317. * the requested union member or the zero octet for
  318. * the default member
  319. * @throws org.omg.CORBA.TypeCodePackage.Bounds if the index is
  320. * equal to or greater than
  321. * the number of members constituting the union
  322. * @throws org.omg.CORBA.TypeCodePackage.BadKind if the method
  323. * is invoked on a non-union <code>TypeCode</code>
  324. * object
  325. */
  326. public abstract Any member_label(int index)
  327. throws BadKind, org.omg.CORBA.TypeCodePackage.Bounds;
  328. /**
  329. * Returns a <code>TypeCode</code> object describing
  330. * all non-default member labels.
  331. * The method <code>discriminator_type</code> can be invoked only
  332. * on union <code>TypeCode</code> objects.
  333. *
  334. * @return the <code>TypeCode</code> object describing
  335. * the non-default member labels
  336. * @throws org.omg.CORBA.TypeCodePackage.BadKind if the method
  337. * is invoked on a non-union <code>TypeCode</code>
  338. * object
  339. */
  340. public abstract TypeCode discriminator_type()
  341. throws BadKind;
  342. /**
  343. * Returns the index of the
  344. * default member, or -1 if there is no default member.
  345. * <P>
  346. * The method <code>default_index</code> can be invoked only on union
  347. * <code>TypeCode</code> objects.
  348. *
  349. * @return the index of the default member, or -1 if
  350. * there is no default member
  351. * @throws org.omg.CORBA.TypeCodePackage.BadKind if the method
  352. * is invoked on a non-union <code>TypeCode</code>
  353. * object
  354. */
  355. public abstract int default_index() throws BadKind;
  356. /**
  357. * Returns the number of elements in the type described by
  358. * this <code>TypeCode</code> object.
  359. * For strings and sequences, it returns the
  360. * bound, with zero indicating an unbounded string or sequence.
  361. * For arrays, it returns the number of elements in the array.
  362. * <P>
  363. * The method <code>length</code> can be invoked on string, sequence, and
  364. * array <code>TypeCode</code> objects.
  365. *
  366. * @return the bound for strings and sequences, or the
  367. * number of elements for arrays
  368. * @throws org.omg.CORBA.TypeCodePackage.BadKind if the method
  369. * is invoked on an inappropriate kind of <code>TypeCode</code>
  370. * object
  371. */
  372. public abstract int length() throws BadKind;
  373. /**
  374. * Returns the <code>TypeCode</code> object representing the
  375. * IDL type for the members of the object described by this
  376. * <code>TypeCode</code> object.
  377. * For sequences and arrays, it returns the
  378. * element type. For aliases, it returns the original type. Note
  379. * that multidimensional arrays are represented by nesting
  380. * <code>TypeCode</code> objects, one per dimension.
  381. * For boxed valuetypes, it returns the boxed type.
  382. *<P>
  383. * The method <code>content_type</code> can be invoked on sequence, array,
  384. * alias, and boxed valuetype <code>TypeCode</code> objects.
  385. *
  386. * @return a <code>TypeCode</code> object representing
  387. * the element type for sequences and arrays, the
  388. * original type for aliases, or the
  389. * boxed type for boxed valuetypes.
  390. * @throws org.omg.CORBA.TypeCodePackage.BadKind if the method
  391. * is invoked on an inappropriate kind of <code>TypeCode</code>
  392. * object
  393. */
  394. public abstract TypeCode content_type() throws BadKind;
  395. /**
  396. * Returns the number of digits in the fixed type described by this
  397. * <code>TypeCode</code> object. For example, the typecode for
  398. * the number 3000.275d could be <code>fixed<7,3></code>, where
  399. * 7 is the precision and 3 is the scale.
  400. *
  401. * @return the total number of digits
  402. * @throws org.omg.CORBA.TypeCodePackage.BadKind if this method
  403. * is invoked on an inappropriate kind of <code>TypeCode</code>
  404. * object
  405. *
  406. */
  407. public abstract short fixed_digits() throws BadKind ;
  408. /**
  409. * Returns the scale of the fixed type described by this
  410. * <code>TypeCode</code> object. A positive number indicates the
  411. * number of digits to the right of the decimal point.
  412. * For example, the number 3000d could have the
  413. * typecode <code>fixed<4,0></code>, where the first number is
  414. * the precision and the second number is the scale.
  415. * A negative number is also possible and adds zeroes to the
  416. * left of the decimal point. In this case, <code>fixed<1,-3></code>,
  417. * could be the typecode for the number 3000d.
  418. *
  419. * @return the scale of the fixed type that this
  420. * <code>TypeCode</code> object describes
  421. * @throws org.omg.CORBA.TypeCodePackage.BadKind if this method
  422. * is invoked on an inappropriate kind of <code>TypeCode</code>
  423. * object
  424. */
  425. public abstract short fixed_scale() throws BadKind ;
  426. /**
  427. * Returns the constant that indicates the visibility of the member
  428. * at the given index.
  429. *
  430. * This operation can only be invoked on non-boxed value
  431. * <code>TypeCode</code> objects.
  432. *
  433. * @param index an <code>int</code> indicating the index into the
  434. * value
  435. * @return either <code>PRIVATE_MEMBER.value</code> or
  436. * <code>PUBLIC_MEMBER.value</code>
  437. * @throws org.omg.CORBA.TypeCodePackage.BadKind if this method
  438. * is invoked on a non-value type <code>TypeCode</code>
  439. * object
  440. * @throws org.omg.CORBA.TypeCodePackage.Bounds
  441. * if the given index is out of bounds
  442. * @see <a href="package-summary.html#unimpl"><code>CORBA</code> package
  443. * comments for unimplemented features</a>
  444. */
  445. abstract public short member_visibility(int index)
  446. throws BadKind, org.omg.CORBA.TypeCodePackage.Bounds ;
  447. /**
  448. * Returns a constant indicating the modifier of the value type
  449. * that this <code>TypeCode</code> object describes. The constant
  450. * returned must be one of the following: <code>VM_NONE.value</code>,
  451. * <code>VM_ABSTRACT.value</code>, <code>VM_CUSTOM.value</code>,
  452. * or <code>VM_TRUNCATABLE.value</code>,
  453. *
  454. * @return a constant describing the value type
  455. * that this <code>TypeCode</code> object describes
  456. * @throws org.omg.CORBA.TypeCodePackage.BadKind
  457. * if this method
  458. * is invoked on a non-value type <code>TypeCode</code>
  459. * object
  460. * @see <a href="package-summary.html#unimpl"><code>CORBA</code> package
  461. * comments for unimplemented features</a>
  462. */
  463. abstract public short type_modifier() throws BadKind ;
  464. /**
  465. * Returns the <code>TypeCode</code> object that describes the concrete base type
  466. * of the value type that this <code>TypeCode</code> object describes.
  467. * Returns null if it doesn't have a concrete base type.
  468. *
  469. * @return the <code>TypeCode</code> object that describes the
  470. * concrete base type of the value type
  471. * that this <code>TypeCode</code> object describes
  472. * @throws org.omg.CORBA.TypeCodePackage.BadKind if this method
  473. * is invoked on a non-boxed value type <code>TypeCode</code> object
  474. * @see <a href="package-summary.html#unimpl"><code>CORBA</code> package
  475. * comments for unimplemented features</a>
  476. */
  477. abstract public TypeCode concrete_base_type() throws BadKind ;
  478. }