1. /*
  2. * @(#)OldJIDLObjectKeyTemplate.java 1.13 03/12/19
  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.ior;
  8. import org.omg.CORBA.OctetSeqHolder ;
  9. import org.omg.CORBA_2_3.portable.InputStream ;
  10. import org.omg.CORBA_2_3.portable.OutputStream ;
  11. import com.sun.corba.se.spi.ior.ObjectId ;
  12. import com.sun.corba.se.spi.ior.ObjectKeyFactory ;
  13. import com.sun.corba.se.spi.orb.ORB ;
  14. import com.sun.corba.se.spi.orb.ORBVersion ;
  15. import com.sun.corba.se.spi.orb.ORBVersionFactory ;
  16. import com.sun.corba.se.impl.ior.ObjectKeyFactoryImpl ;
  17. import com.sun.corba.se.impl.encoding.CDRInputStream ;
  18. /**
  19. * Handles object keys created by JDK ORBs from before JDK 1.4.0.
  20. */
  21. public final class OldJIDLObjectKeyTemplate extends OldObjectKeyTemplateBase
  22. {
  23. /**
  24. * JDK 1.3.1 FCS did not include a version byte at the end of
  25. * its object keys. JDK 1.3.1_01 included the byte with the
  26. * value 1. Anything below 1 is considered an invalid value.
  27. */
  28. public static final byte NULL_PATCH_VERSION = 0;
  29. byte patchVersion = OldJIDLObjectKeyTemplate.NULL_PATCH_VERSION;
  30. public OldJIDLObjectKeyTemplate( ORB orb, int magic, int scid,
  31. InputStream is, OctetSeqHolder osh )
  32. {
  33. this( orb, magic, scid, is );
  34. osh.value = readObjectKey( is ) ;
  35. /**
  36. * Beginning with JDK 1.3.1_01, a byte was placed at the end of
  37. * the object key with a value indicating the patch version.
  38. * JDK 1.3.1_01 had the value 1. If other patches are necessary
  39. * which involve ORB versioning changes, they should increment
  40. * the patch version.
  41. *
  42. * Note that if we see a value greater than 1 in this code, we
  43. * will treat it as if we're talking to the most recent ORB version.
  44. *
  45. * WARNING: This code is sensitive to changes in CDRInputStream
  46. * getPosition. It assumes that the CDRInputStream is an
  47. * encapsulation whose position can be compared to the object
  48. * key array length.
  49. */
  50. if (magic == ObjectKeyFactoryImpl.JAVAMAGIC_NEW &&
  51. osh.value.length > ((CDRInputStream)is).getPosition()) {
  52. patchVersion = is.read_octet();
  53. if (patchVersion == ObjectKeyFactoryImpl.JDK1_3_1_01_PATCH_LEVEL)
  54. setORBVersion(ORBVersionFactory.getJDK1_3_1_01());
  55. else if (patchVersion > ObjectKeyFactoryImpl.JDK1_3_1_01_PATCH_LEVEL)
  56. setORBVersion(ORBVersionFactory.getORBVersion());
  57. else
  58. throw wrapper.invalidJdk131PatchLevel( new Integer( patchVersion ) ) ;
  59. }
  60. }
  61. public OldJIDLObjectKeyTemplate( ORB orb, int magic, int scid, int serverid)
  62. {
  63. super( orb, magic, scid, serverid, JIDL_ORB_ID, JIDL_OAID ) ;
  64. }
  65. public OldJIDLObjectKeyTemplate(ORB orb, int magic, int scid, InputStream is)
  66. {
  67. this( orb, magic, scid, is.read_long() ) ;
  68. }
  69. protected void writeTemplate( OutputStream os )
  70. {
  71. os.write_long( getMagic() ) ;
  72. os.write_long( getSubcontractId() ) ;
  73. os.write_long( getServerId() ) ;
  74. }
  75. public void write(ObjectId objectId, OutputStream os)
  76. {
  77. super.write(objectId, os);
  78. if (patchVersion != OldJIDLObjectKeyTemplate.NULL_PATCH_VERSION)
  79. os.write_octet( patchVersion ) ;
  80. }
  81. }