1. /*
  2. * @(#)IDLType.java 1.6 04/06/21
  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.presentation.rmi ;
  8. /**
  9. * Holds information about the OMG IDL mapping of a Java type.
  10. */
  11. public class IDLType {
  12. private Class cl_;
  13. // terminology for OMG IDL type package name
  14. private String[] modules_;
  15. // name of element within module
  16. private String memberName_;
  17. public IDLType(Class cl, String[] modules, String memberName) {
  18. cl_ = cl;
  19. modules_ = modules;
  20. memberName_ = memberName;
  21. }
  22. public IDLType(Class cl, String memberName) {
  23. this( cl, new String[0], memberName ) ;
  24. }
  25. public Class getJavaClass() {
  26. return cl_;
  27. }
  28. public String[] getModules()
  29. {
  30. return modules_ ;
  31. }
  32. public String makeConcatenatedName( char separator, boolean fixIDLKeywords ) {
  33. StringBuffer sbuff = new StringBuffer() ;
  34. for (int ctr=0; ctr<modules_.length; ctr++) {
  35. String mod = modules_[ctr] ;
  36. if (ctr>0)
  37. sbuff.append( separator ) ;
  38. if (fixIDLKeywords && IDLNameTranslatorImpl.isIDLKeyword(mod))
  39. mod = IDLNameTranslatorImpl.mangleIDLKeywordClash( mod ) ;
  40. sbuff.append( mod ) ;
  41. }
  42. return sbuff.toString() ;
  43. }
  44. public String getModuleName() {
  45. // Note that this should probably be makeConcatenatedName( '/', true )
  46. // for spec compliance,
  47. // but rmic does it this way, so we'll leave this.
  48. // The effect is that an overloaded method like
  49. // void foo( bar.typedef.Baz )
  50. // will get an IDL name of foo__bar_typedef_Baz instead of
  51. // foo__bar__typedef_Baz (note the extra _ before typedef).
  52. return makeConcatenatedName( '_', false ) ;
  53. }
  54. public String getExceptionName() {
  55. // Here we will check for IDL keyword collisions (see bug 5010332).
  56. // This means that the repository ID for
  57. // foo.exception.SomeException is
  58. // "IDL:foo/_exception/SomeEx:1.0" (note the underscore in front
  59. // of the exception module name).
  60. String modName = makeConcatenatedName( '/', true ) ;
  61. String suffix = "Exception" ;
  62. String excName = memberName_ ;
  63. if (excName.endsWith( suffix )) {
  64. int last = excName.length() - suffix.length() ;
  65. excName = excName.substring( 0, last ) ;
  66. }
  67. // See bug 4989312: we must always add the Ex.
  68. excName += "Ex" ;
  69. if (modName.length() == 0)
  70. return "IDL:" + excName + ":1.0" ;
  71. else
  72. return "IDL:" + modName + '/' + excName + ":1.0" ;
  73. }
  74. public String getMemberName() {
  75. return memberName_;
  76. }
  77. /**
  78. * True if this type doesn't have a containing module. This
  79. * would be true of a java type defined in the default package
  80. * or a primitive.
  81. */
  82. public boolean hasModule() {
  83. return (modules_.length > 0) ;
  84. }
  85. }