1. /*
  2. * @(#)ObjectKeyFactory.java 1.20 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. // @(#)ObjectKeyFactory.java 1.15 00/10/26
  8. package com.sun.corba.se.internal.ior;
  9. import org.omg.CORBA.ORB ;
  10. import org.omg.CORBA.OctetSeqHolder ;
  11. import com.sun.corba.se.internal.orbutil.ORBConstants ;
  12. import com.sun.corba.se.internal.ior.ObjectKeyTemplate ;
  13. import com.sun.corba.se.internal.ior.JIDLObjectKeyTemplate ;
  14. import com.sun.corba.se.internal.ior.POAObjectKeyTemplate ;
  15. import com.sun.corba.se.internal.ior.WireObjectKeyTemplate ;
  16. import com.sun.corba.se.internal.corba.EncapsInputStream ;
  17. /**
  18. * @author
  19. */
  20. public class ObjectKeyFactory
  21. {
  22. private ObjectKeyFactory()
  23. {
  24. }
  25. private static ObjectKeyFactory factory = null ;
  26. // initialize-on-demand holder
  27. private static class ObjectKeyFactoryHolder {
  28. static ObjectKeyFactory value =
  29. new ObjectKeyFactory() ;
  30. }
  31. static public ObjectKeyFactory get()
  32. {
  33. return ObjectKeyFactoryHolder.value ;
  34. }
  35. private static final int CDR_LONG_SIZE = 4 ;
  36. /**
  37. * @param byte[]
  38. * @return ObjectKey
  39. * @exception
  40. * @author
  41. * @roseuid 391604E40147
  42. */
  43. public ObjectKey create(ORB orb, byte[] key)
  44. {
  45. OctetSeqHolder osh = new OctetSeqHolder() ;
  46. // WARNING: If we move away from using an encapsulation, we must
  47. // update OldJIDLObjectKeyTemplate since it assumes it can
  48. // compare stream position and key length.
  49. EncapsInputStream is = new EncapsInputStream( orb, key, key.length ) ;
  50. ObjectKeyTemplate template = null ;
  51. // If key is too small to contain a MAGIC long, fall through
  52. // to the WireObjectKeyTemplate case
  53. if (key.length >= CDR_LONG_SIZE) {
  54. is.mark(0) ;
  55. int magic = is.read_long() ;
  56. // If key is too small to contain a MAGIC long followed by an SCID long,
  57. // fall through to the WireObjectKeyTemplate case.
  58. if ((key.length >= 2*CDR_LONG_SIZE) && (magic >= ObjectKeyTemplate.MAGIC_BASE)
  59. && (magic <= ObjectKeyTemplate.MAX_MAGIC)) {
  60. int scid = is.read_long() ;
  61. if ((scid >= ORBConstants.FIRST_POA_SCID) &&
  62. (scid <= ORBConstants.MAX_POA_SCID)) {
  63. if (magic >= ObjectKeyTemplate.JAVAMAGIC_NEWER)
  64. template = new POAObjectKeyTemplate( magic, scid, is, osh ) ;
  65. else
  66. template = new OldPOAObjectKeyTemplate( magic, scid, is, osh ) ;
  67. } else if ((scid >= 0) && (scid < ORBConstants.FIRST_POA_SCID)) {
  68. if (magic >= ObjectKeyTemplate.JAVAMAGIC_NEWER)
  69. template = new JIDLObjectKeyTemplate( magic, scid, is, osh ) ;
  70. else
  71. template = new OldJIDLObjectKeyTemplate( key, magic, scid, is, osh );
  72. }
  73. }
  74. // If we did not successfully construct a template here, reset the
  75. // stream so that WireObjectKeyTemplate can correctly construct the
  76. // object key.
  77. if (template == null)
  78. is.reset() ;
  79. }
  80. if (template == null)
  81. template = new WireObjectKeyTemplate( is, osh ) ;
  82. // byte[] id = template.getId( is ) ;
  83. ObjectId oid = new ObjectId( osh.value ) ;
  84. return new ObjectKey( template, oid ) ;
  85. }
  86. }