1. /*
  2. * @(#)CodecFactoryImpl.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.impl.interceptors;
  8. import org.omg.IOP.Codec;
  9. import org.omg.IOP.CodecFactory;
  10. import org.omg.IOP.CodecFactoryPackage.UnknownEncoding;
  11. import org.omg.IOP.Encoding;
  12. import org.omg.IOP.ENCODING_CDR_ENCAPS;
  13. import com.sun.corba.se.spi.logging.CORBALogDomains;
  14. import com.sun.corba.se.impl.logging.ORBUtilSystemException;
  15. import org.omg.CORBA.ORB;
  16. import org.omg.CORBA.LocalObject;
  17. /**
  18. * CodecFactoryImpl is the implementation of the Codec Factory, as described
  19. * in orbos/99-12-02.
  20. */
  21. public final class CodecFactoryImpl
  22. extends org.omg.CORBA.LocalObject
  23. implements CodecFactory
  24. {
  25. // The ORB that created this Codec Factory
  26. private ORB orb;
  27. private ORBUtilSystemException wrapper ;
  28. // The maximum minor version of GIOP supported by this codec factory.
  29. // Currently, this is 1.2.
  30. private static final int MAX_MINOR_VERSION_SUPPORTED = 2;
  31. // The pre-created minor versions of Codec version 1.0, 1.1, ...,
  32. // 1.(MAX_MINOR_VERSION_SUPPORTED)
  33. private Codec codecs[] = new Codec[MAX_MINOR_VERSION_SUPPORTED + 1];
  34. /**
  35. * Creates a new CodecFactory implementation. Stores the ORB that
  36. * created this factory, for later use by the Codec.
  37. */
  38. public CodecFactoryImpl( ORB orb ) {
  39. this.orb = orb;
  40. wrapper = ORBUtilSystemException.get(
  41. (com.sun.corba.se.spi.orb.ORB)orb,
  42. CORBALogDomains.RPC_PROTOCOL ) ;
  43. // Precreate a codec for version 1.0 through
  44. // 1.(MAX_MINOR_VERSION_SUPPORTED). This can be
  45. // done since Codecs are immutable in their current implementation.
  46. // This is an optimization that eliminates the overhead of creating
  47. // a new Codec each time create_codec is called.
  48. for( int minor = 0; minor <= MAX_MINOR_VERSION_SUPPORTED; minor++ ) {
  49. codecs[minor] = new CDREncapsCodec( orb, 1, minor );
  50. }
  51. }
  52. /**
  53. * Creates a codec of the given encoding. The only format recognized
  54. * by this factory is ENCODING_CDR_ENCAPS, versions 1.0 through
  55. * 1.(MAX_MINOR_VERSION_SUPPORTED).
  56. *
  57. * @exception UnknownEncoding Thrown if this factory cannot create a
  58. * Codec of the given encoding.
  59. */
  60. public Codec create_codec ( Encoding enc )
  61. throws UnknownEncoding
  62. {
  63. if( enc == null ) nullParam();
  64. Codec result = null;
  65. // This is the only format we can currently create codecs for:
  66. if( (enc.format == ENCODING_CDR_ENCAPS.value) &&
  67. (enc.major_version == 1) )
  68. {
  69. if( (enc.minor_version >= 0) &&
  70. (enc.minor_version <= MAX_MINOR_VERSION_SUPPORTED) )
  71. {
  72. result = codecs[enc.minor_version];
  73. }
  74. }
  75. if( result == null ) {
  76. throw new UnknownEncoding();
  77. }
  78. return result;
  79. }
  80. /**
  81. * Called when an invalid null parameter was passed. Throws a
  82. * BAD_PARAM with a minor code of 1
  83. */
  84. private void nullParam()
  85. {
  86. throw wrapper.nullParam() ;
  87. }
  88. }