1. /*
  2. * @(#)ORBVersionFactory.java 1.13 04/03/01
  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.spi.orb ;
  8. import com.sun.corba.se.spi.orb.ORBVersion ;
  9. import com.sun.corba.se.impl.orb.ORBVersionImpl ;
  10. import org.omg.CORBA.portable.InputStream ;
  11. import org.omg.CORBA.INTERNAL ;
  12. public class ORBVersionFactory {
  13. private ORBVersionFactory() {} ;
  14. public static ORBVersion getFOREIGN()
  15. {
  16. return ORBVersionImpl.FOREIGN ;
  17. }
  18. public static ORBVersion getOLD()
  19. {
  20. return ORBVersionImpl.OLD ;
  21. }
  22. public static ORBVersion getNEW()
  23. {
  24. return ORBVersionImpl.NEW ;
  25. }
  26. public static ORBVersion getJDK1_3_1_01()
  27. {
  28. return ORBVersionImpl.JDK1_3_1_01 ;
  29. }
  30. public static ORBVersion getNEWER()
  31. {
  32. return ORBVersionImpl.NEWER ;
  33. }
  34. public static ORBVersion getPEORB()
  35. {
  36. return ORBVersionImpl.PEORB ;
  37. }
  38. /** Return the current version of this ORB
  39. */
  40. public static ORBVersion getORBVersion()
  41. {
  42. return ORBVersionImpl.PEORB ;
  43. }
  44. public static ORBVersion create( InputStream is )
  45. {
  46. byte value = is.read_octet() ;
  47. return byteToVersion( value ) ;
  48. }
  49. private static ORBVersion byteToVersion( byte value )
  50. {
  51. /* Throwing an exception here would cause this version to be
  52. * incompatible with future versions of the ORB, to the point
  53. * that this version could
  54. * not even unmarshal objrefs from a newer version that uses
  55. * extended versioning. Therefore, we will simply treat all
  56. * unknown versions as the latest version.
  57. if (value < 0)
  58. throw new INTERNAL() ;
  59. */
  60. /**
  61. * Update: If we treat all unknown versions as the latest version
  62. * then when we send an IOR with a PEORB version to an ORB that
  63. * doesn't know the PEORB version it will treat it as whatever
  64. * its idea of the latest version is. Then, if that IOR is
  65. * sent back to the server and compared with the original
  66. * the equality check will fail because the versions will be
  67. * different.
  68. *
  69. * Instead, just capture the version bytes.
  70. */
  71. switch (value) {
  72. case ORBVersion.FOREIGN : return ORBVersionImpl.FOREIGN ;
  73. case ORBVersion.OLD : return ORBVersionImpl.OLD ;
  74. case ORBVersion.NEW : return ORBVersionImpl.NEW ;
  75. case ORBVersion.JDK1_3_1_01: return ORBVersionImpl.JDK1_3_1_01 ;
  76. case ORBVersion.NEWER : return ORBVersionImpl.NEWER ;
  77. case ORBVersion.PEORB : return ORBVersionImpl.PEORB ;
  78. default : return new ORBVersionImpl(value);
  79. }
  80. }
  81. }