1. /*
  2. * @(#)ServiceContextRegistry.java 1.17 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.servicecontext;
  8. import org.omg.CORBA.BAD_PARAM;
  9. import java.util.Vector ;
  10. import java.util.Enumeration ;
  11. import com.sun.corba.se.spi.servicecontext.ServiceContext ;
  12. import com.sun.corba.se.spi.servicecontext.ServiceContextData ;
  13. import com.sun.corba.se.spi.orb.ORB ;
  14. import com.sun.corba.se.impl.orbutil.ORBUtility ;
  15. public class ServiceContextRegistry {
  16. private ORB orb ;
  17. private Vector scCollection ;
  18. private void dprint( String msg )
  19. {
  20. ORBUtility.dprint( this, msg ) ;
  21. }
  22. public ServiceContextRegistry( ORB orb )
  23. {
  24. scCollection = new Vector() ;
  25. this.orb = orb ;
  26. }
  27. /** Register the ServiceContext class so that it will be recognized
  28. * by the read method.
  29. * Class cls must have the following properties:
  30. * <ul>
  31. * <li>It must derive from com.sun.corba.se.spi.servicecontext.ServiceContext.</li>
  32. * <li>It must have a public static final int SERVICE_CONTEXT_ID
  33. * member.</li>
  34. * <li>It must implement a constructor that takes a
  35. * org.omg.CORBA_2_3.portable.InputStream argument.</li>
  36. * </ul>
  37. */
  38. public void register( Class cls )
  39. {
  40. if (ORB.ORBInitDebug)
  41. dprint( "Registering service context class " + cls ) ;
  42. ServiceContextData scd = new ServiceContextData( cls ) ;
  43. if (findServiceContextData(scd.getId()) == null)
  44. scCollection.addElement( scd ) ;
  45. else
  46. throw new BAD_PARAM( "Tried to register duplicate service context" ) ;
  47. }
  48. public ServiceContextData findServiceContextData( int scId )
  49. {
  50. if (ORB.ORBInitDebug)
  51. dprint( "Searching registry for service context id " + scId ) ;
  52. Enumeration enumeration = scCollection.elements() ;
  53. while (enumeration.hasMoreElements()) {
  54. ServiceContextData scd =
  55. (ServiceContextData)(enumeration.nextElement()) ;
  56. if (scd.getId() == scId) {
  57. if (ORB.ORBInitDebug)
  58. dprint( "Service context data found: " + scd ) ;
  59. return scd ;
  60. }
  61. }
  62. if (ORB.ORBInitDebug)
  63. dprint( "Service context data not found" ) ;
  64. return null ;
  65. }
  66. }