1. /*
  2. * @(#)IORFactories.java 1.15 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.spi.ior ;
  8. import java.io.Serializable ;
  9. import org.omg.CORBA_2_3.portable.InputStream ;
  10. import org.omg.CORBA.BAD_PARAM ;
  11. import org.omg.CORBA.portable.ValueFactory ;
  12. import org.omg.PortableInterceptor.ObjectReferenceTemplate ;
  13. import org.omg.PortableInterceptor.ObjectReferenceFactory ;
  14. import com.sun.corba.se.impl.ior.ObjectIdImpl ;
  15. import com.sun.corba.se.impl.ior.ObjectKeyImpl ;
  16. import com.sun.corba.se.impl.ior.IORImpl ;
  17. import com.sun.corba.se.impl.ior.IORTemplateImpl ;
  18. import com.sun.corba.se.impl.ior.IORTemplateListImpl ;
  19. import com.sun.corba.se.impl.ior.ObjectReferenceProducerBase ;
  20. import com.sun.corba.se.impl.ior.ObjectReferenceFactoryImpl ;
  21. import com.sun.corba.se.impl.ior.ObjectReferenceTemplateImpl ;
  22. import com.sun.corba.se.impl.ior.ObjectKeyFactoryImpl ;
  23. import com.sun.corba.se.impl.orbutil.ORBUtility ;
  24. import com.sun.corba.se.spi.orb.ORB ;
  25. /** This class provides a number of factory methods for creating
  26. * various IOR SPI classes which are not subclassed for specific protocols.
  27. * The following types must be created using this class:
  28. * <ul>
  29. * <li>ObjectId</li>
  30. * <li>ObjectKey</li>
  31. * <li>IOR</li>
  32. * <li>IORTemplate</li>
  33. * </ul>
  34. */
  35. public class IORFactories {
  36. private IORFactories() {}
  37. /** Create an ObjectId for the given byte sequence.
  38. */
  39. public static ObjectId makeObjectId( byte[] id )
  40. {
  41. return new ObjectIdImpl( id ) ;
  42. }
  43. /** Create an ObjectKey for the given ObjectKeyTemplate and
  44. * ObjectId.
  45. */
  46. public static ObjectKey makeObjectKey( ObjectKeyTemplate oktemp, ObjectId oid )
  47. {
  48. return new ObjectKeyImpl( oktemp, oid ) ;
  49. }
  50. /** Create an empty IOR for the given orb and typeid. The result is mutable.
  51. */
  52. public static IOR makeIOR( ORB orb, String typeid )
  53. {
  54. return new IORImpl( orb, typeid ) ;
  55. }
  56. /** Create an empty IOR for the given orb with a null typeid. The result is mutable.
  57. */
  58. public static IOR makeIOR( ORB orb )
  59. {
  60. return new IORImpl( orb ) ;
  61. }
  62. /** Read an IOR from an InputStream. ObjectKeys are not shared.
  63. */
  64. public static IOR makeIOR( InputStream is )
  65. {
  66. return new IORImpl( is ) ;
  67. }
  68. /** Create an IORTemplate with the given ObjectKeyTemplate. The result
  69. * is mutable.
  70. */
  71. public static IORTemplate makeIORTemplate( ObjectKeyTemplate oktemp )
  72. {
  73. return new IORTemplateImpl( oktemp ) ;
  74. }
  75. /** Read an IORTemplate from an InputStream.
  76. */
  77. public static IORTemplate makeIORTemplate( InputStream is )
  78. {
  79. return new IORTemplateImpl( is ) ;
  80. }
  81. public static IORTemplateList makeIORTemplateList()
  82. {
  83. return new IORTemplateListImpl() ;
  84. }
  85. public static IORTemplateList makeIORTemplateList( InputStream is )
  86. {
  87. return new IORTemplateListImpl( is ) ;
  88. }
  89. public static IORFactory getIORFactory( ObjectReferenceTemplate ort )
  90. {
  91. if (ort instanceof ObjectReferenceTemplateImpl) {
  92. ObjectReferenceTemplateImpl orti =
  93. (ObjectReferenceTemplateImpl)ort ;
  94. return orti.getIORFactory() ;
  95. }
  96. throw new BAD_PARAM() ;
  97. }
  98. public static IORTemplateList getIORTemplateList( ObjectReferenceFactory orf )
  99. {
  100. if (orf instanceof ObjectReferenceProducerBase) {
  101. ObjectReferenceProducerBase base =
  102. (ObjectReferenceProducerBase)orf ;
  103. return base.getIORTemplateList() ;
  104. }
  105. throw new BAD_PARAM() ;
  106. }
  107. public static ObjectReferenceTemplate makeObjectReferenceTemplate( ORB orb,
  108. IORTemplate iortemp )
  109. {
  110. return new ObjectReferenceTemplateImpl( orb, iortemp ) ;
  111. }
  112. public static ObjectReferenceFactory makeObjectReferenceFactory( ORB orb,
  113. IORTemplateList iortemps )
  114. {
  115. return new ObjectReferenceFactoryImpl( orb, iortemps ) ;
  116. }
  117. public static ObjectKeyFactory makeObjectKeyFactory( ORB orb )
  118. {
  119. return new ObjectKeyFactoryImpl( orb ) ;
  120. }
  121. public static IOR getIOR( org.omg.CORBA.Object obj )
  122. {
  123. return ORBUtility.getIOR( obj ) ;
  124. }
  125. public static org.omg.CORBA.Object makeObjectReference( IOR ior )
  126. {
  127. return ORBUtility.makeObjectReference( ior ) ;
  128. }
  129. /** This method must be called in order to register the value
  130. * factories for the ObjectReferenceTemplate and ObjectReferenceFactory
  131. * value types.
  132. */
  133. public static void registerValueFactories( ORB orb )
  134. {
  135. // Create and register the factory for the Object Reference Template
  136. // implementation.
  137. ValueFactory vf = new ValueFactory() {
  138. public Serializable read_value( InputStream is )
  139. {
  140. return new ObjectReferenceTemplateImpl( is ) ;
  141. }
  142. } ;
  143. orb.register_value_factory( ObjectReferenceTemplateImpl.repositoryId, vf ) ;
  144. // Create and register the factory for the Object Reference Factory
  145. // implementation.
  146. vf = new ValueFactory() {
  147. public Serializable read_value( InputStream is )
  148. {
  149. return new ObjectReferenceFactoryImpl( is ) ;
  150. }
  151. } ;
  152. orb.register_value_factory( ObjectReferenceFactoryImpl.repositoryId, vf ) ;
  153. }
  154. }