1. /*
  2. * @(#)TaggedComponentFactoryFinder.java 1.15 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. //Source file: J:/ws/serveractivation/src/share/classes/com.sun.corba.se.internal.ior/TaggedComponentFactoryFinder.java
  8. package com.sun.corba.se.internal.ior;
  9. import java.util.HashMap;
  10. import com.sun.corba.se.internal.ior.IdEncapsulationFactory ;
  11. import com.sun.corba.se.internal.ior.IdEncapsulation ;
  12. import com.sun.corba.se.internal.ior.GenericTaggedComponent ;
  13. import com.sun.corba.se.internal.corba.EncapsOutputStream ;
  14. import org.omg.CORBA_2_3.portable.InputStream ;
  15. import org.omg.CORBA.ORB ;
  16. /**
  17. * @author
  18. */
  19. public class TaggedComponentFactoryFinder implements
  20. IdEncapsulationFactoryFinder
  21. {
  22. private HashMap map;
  23. // initialize-on-demand holder
  24. private static class TaggedComponentFactoryFinderHolder {
  25. static TaggedComponentFactoryFinder value =
  26. new TaggedComponentFactoryFinder() ;
  27. }
  28. public static TaggedComponentFactoryFinder getFinder()
  29. {
  30. return TaggedComponentFactoryFinderHolder.value ;
  31. }
  32. /**
  33. * @return
  34. * @exception
  35. * @author
  36. * @roseuid 391098510095
  37. */
  38. private TaggedComponentFactoryFinder()
  39. {
  40. map = new HashMap() ;
  41. }
  42. /**
  43. * @param arg0
  44. * @param arg1
  45. * @return IdEncapsulation
  46. * @exception
  47. * @author
  48. * @roseuid 3910985100A9
  49. */
  50. public IdEncapsulation create(int id, InputStream is)
  51. {
  52. IdEncapsulationFactory factory = getFactory( id ) ;
  53. if (factory != null)
  54. return factory.create( id, is ) ;
  55. else
  56. return new GenericTaggedComponent( id, is ) ;
  57. }
  58. public TaggedComponent create( ORB orb,
  59. org.omg.IOP.TaggedComponent comp )
  60. {
  61. EncapsOutputStream os = new EncapsOutputStream( orb ) ;
  62. org.omg.IOP.TaggedComponentHelper.write( os, comp ) ;
  63. InputStream is = (InputStream)(os.create_input_stream() ) ;
  64. // Skip the component ID: we just wrote it out above
  65. is.read_ulong() ;
  66. return (TaggedComponent)create( comp.tag, is ) ;
  67. }
  68. /**
  69. * @param arg0
  70. * @return IdEncapsulationFactory
  71. * @exception
  72. * @author
  73. * @roseuid 3910985100BD
  74. */
  75. private IdEncapsulationFactory getFactory(int id)
  76. {
  77. Integer ident = new Integer( id ) ;
  78. IdEncapsulationFactory factory = (IdEncapsulationFactory)(map.get(
  79. ident ) ) ;
  80. return factory ;
  81. }
  82. /**
  83. * @param arg0
  84. * @param arg1
  85. * @return void
  86. * @exception
  87. * @author
  88. * @roseuid 3910985100BF
  89. */
  90. public void registerFactory(int id,
  91. IdEncapsulationFactory factory)
  92. {
  93. Integer ident = new Integer( id ) ;
  94. map.put( ident, factory ) ;
  95. }
  96. }