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