1. /*
  2. * @(#)IIOPFactories.java 1.11 04/06/21
  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.iiop ;
  8. import org.omg.CORBA_2_3.portable.InputStream ;
  9. import com.sun.corba.se.spi.ior.Identifiable ;
  10. import com.sun.corba.se.spi.ior.IdentifiableFactory ;
  11. import com.sun.corba.se.spi.ior.EncapsulationFactoryBase ;
  12. import com.sun.corba.se.spi.ior.ObjectId ;
  13. import com.sun.corba.se.spi.ior.ObjectKeyTemplate ;
  14. import com.sun.corba.se.spi.ior.iiop.IIOPAddress ;
  15. import com.sun.corba.se.spi.ior.iiop.IIOPProfileTemplate ;
  16. import com.sun.corba.se.spi.ior.iiop.GIOPVersion ;
  17. import com.sun.corba.se.spi.orb.ORB ;
  18. import com.sun.corba.se.impl.encoding.MarshalInputStream ;
  19. import com.sun.corba.se.impl.ior.iiop.IIOPAddressImpl ;
  20. import com.sun.corba.se.impl.ior.iiop.CodeSetsComponentImpl ;
  21. import com.sun.corba.se.impl.ior.iiop.AlternateIIOPAddressComponentImpl ;
  22. import com.sun.corba.se.impl.ior.iiop.JavaCodebaseComponentImpl ;
  23. import com.sun.corba.se.impl.ior.iiop.MaxStreamFormatVersionComponentImpl ;
  24. import com.sun.corba.se.impl.ior.iiop.JavaSerializationComponent;
  25. import com.sun.corba.se.impl.ior.iiop.ORBTypeComponentImpl ;
  26. import com.sun.corba.se.impl.ior.iiop.IIOPProfileImpl ;
  27. import com.sun.corba.se.impl.ior.iiop.IIOPProfileTemplateImpl ;
  28. import com.sun.corba.se.impl.ior.iiop.RequestPartitioningComponentImpl ;
  29. import com.sun.corba.se.impl.orbutil.ORBConstants;
  30. import com.sun.corba.se.impl.orbutil.ORBConstants;
  31. import org.omg.IOP.TAG_ALTERNATE_IIOP_ADDRESS ;
  32. import org.omg.IOP.TAG_CODE_SETS ;
  33. import org.omg.IOP.TAG_JAVA_CODEBASE ;
  34. import org.omg.IOP.TAG_RMI_CUSTOM_MAX_STREAM_FORMAT ;
  35. import org.omg.IOP.TAG_ORB_TYPE ;
  36. import org.omg.IOP.TAG_INTERNET_IOP ;
  37. /** This class provides all of the factories for the IIOP profiles and
  38. * components. This includes direct construction of profiles and templates,
  39. * as well as constructing factories that can be registered with an
  40. * IdentifiableFactoryFinder.
  41. */
  42. public abstract class IIOPFactories {
  43. private IIOPFactories() {}
  44. public static IdentifiableFactory makeRequestPartitioningComponentFactory()
  45. {
  46. return new EncapsulationFactoryBase(ORBConstants.TAG_REQUEST_PARTITIONING_ID) {
  47. public Identifiable readContents(InputStream in)
  48. {
  49. int threadPoolToUse = in.read_ulong();
  50. Identifiable comp =
  51. new RequestPartitioningComponentImpl(threadPoolToUse);
  52. return comp;
  53. }
  54. };
  55. }
  56. public static RequestPartitioningComponent makeRequestPartitioningComponent(
  57. int threadPoolToUse)
  58. {
  59. return new RequestPartitioningComponentImpl(threadPoolToUse);
  60. }
  61. public static IdentifiableFactory makeAlternateIIOPAddressComponentFactory()
  62. {
  63. return new EncapsulationFactoryBase(TAG_ALTERNATE_IIOP_ADDRESS.value) {
  64. public Identifiable readContents( InputStream in )
  65. {
  66. IIOPAddress addr = new IIOPAddressImpl( in ) ;
  67. Identifiable comp =
  68. new AlternateIIOPAddressComponentImpl( addr ) ;
  69. return comp ;
  70. }
  71. } ;
  72. }
  73. public static AlternateIIOPAddressComponent makeAlternateIIOPAddressComponent(
  74. IIOPAddress addr )
  75. {
  76. return new AlternateIIOPAddressComponentImpl( addr ) ;
  77. }
  78. public static IdentifiableFactory makeCodeSetsComponentFactory()
  79. {
  80. return new EncapsulationFactoryBase(TAG_CODE_SETS.value) {
  81. public Identifiable readContents( InputStream in )
  82. {
  83. return new CodeSetsComponentImpl( in ) ;
  84. }
  85. } ;
  86. }
  87. public static CodeSetsComponent makeCodeSetsComponent( ORB orb )
  88. {
  89. return new CodeSetsComponentImpl( orb ) ;
  90. }
  91. public static IdentifiableFactory makeJavaCodebaseComponentFactory()
  92. {
  93. return new EncapsulationFactoryBase(TAG_JAVA_CODEBASE.value) {
  94. public Identifiable readContents( InputStream in )
  95. {
  96. String url = in.read_string() ;
  97. Identifiable comp = new JavaCodebaseComponentImpl( url ) ;
  98. return comp ;
  99. }
  100. } ;
  101. }
  102. public static JavaCodebaseComponent makeJavaCodebaseComponent(
  103. String codebase )
  104. {
  105. return new JavaCodebaseComponentImpl( codebase ) ;
  106. }
  107. public static IdentifiableFactory makeORBTypeComponentFactory()
  108. {
  109. return new EncapsulationFactoryBase(TAG_ORB_TYPE.value) {
  110. public Identifiable readContents( InputStream in )
  111. {
  112. int type = in.read_ulong() ;
  113. Identifiable comp = new ORBTypeComponentImpl( type ) ;
  114. return comp ;
  115. }
  116. } ;
  117. }
  118. public static ORBTypeComponent makeORBTypeComponent( int type )
  119. {
  120. return new ORBTypeComponentImpl( type ) ;
  121. }
  122. public static IdentifiableFactory makeMaxStreamFormatVersionComponentFactory()
  123. {
  124. return new EncapsulationFactoryBase(TAG_RMI_CUSTOM_MAX_STREAM_FORMAT.value) {
  125. public Identifiable readContents(InputStream in)
  126. {
  127. byte version = in.read_octet() ;
  128. Identifiable comp = new MaxStreamFormatVersionComponentImpl(version);
  129. return comp ;
  130. }
  131. };
  132. }
  133. public static MaxStreamFormatVersionComponent makeMaxStreamFormatVersionComponent()
  134. {
  135. return new MaxStreamFormatVersionComponentImpl() ;
  136. }
  137. public static IdentifiableFactory makeJavaSerializationComponentFactory() {
  138. return new EncapsulationFactoryBase(
  139. ORBConstants.TAG_JAVA_SERIALIZATION_ID) {
  140. public Identifiable readContents(InputStream in) {
  141. byte version = in.read_octet();
  142. Identifiable cmp = new JavaSerializationComponent(version);
  143. return cmp;
  144. }
  145. };
  146. }
  147. public static JavaSerializationComponent makeJavaSerializationComponent() {
  148. return JavaSerializationComponent.singleton();
  149. }
  150. public static IdentifiableFactory makeIIOPProfileFactory()
  151. {
  152. return new EncapsulationFactoryBase(TAG_INTERNET_IOP.value) {
  153. public Identifiable readContents( InputStream in )
  154. {
  155. Identifiable result = new IIOPProfileImpl( in ) ;
  156. return result ;
  157. }
  158. } ;
  159. }
  160. public static IIOPProfile makeIIOPProfile( ORB orb, ObjectKeyTemplate oktemp,
  161. ObjectId oid, IIOPProfileTemplate ptemp )
  162. {
  163. return new IIOPProfileImpl( orb, oktemp, oid, ptemp ) ;
  164. }
  165. public static IIOPProfile makeIIOPProfile( ORB orb,
  166. org.omg.IOP.TaggedProfile profile )
  167. {
  168. return new IIOPProfileImpl( orb, profile ) ;
  169. }
  170. public static IdentifiableFactory makeIIOPProfileTemplateFactory()
  171. {
  172. return new EncapsulationFactoryBase(TAG_INTERNET_IOP.value) {
  173. public Identifiable readContents( InputStream in )
  174. {
  175. Identifiable result = new IIOPProfileTemplateImpl( in ) ;
  176. return result ;
  177. }
  178. } ;
  179. }
  180. public static IIOPProfileTemplate makeIIOPProfileTemplate( ORB orb,
  181. GIOPVersion version, IIOPAddress primary )
  182. {
  183. return new IIOPProfileTemplateImpl( orb, version, primary ) ;
  184. }
  185. public static IIOPAddress makeIIOPAddress( ORB orb, String host, int port )
  186. {
  187. return new IIOPAddressImpl( orb, host, port ) ;
  188. }
  189. public static IIOPAddress makeIIOPAddress( InputStream is )
  190. {
  191. return new IIOPAddressImpl( is ) ;
  192. }
  193. }