KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > spi > servicecontext > ServiceContextRegistry


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
8 package com.sun.corba.se.spi.servicecontext;
9
10 import org.omg.CORBA.BAD_PARAM JavaDoc;
11 import java.util.Vector JavaDoc ;
12 import java.util.Enumeration JavaDoc ;
13 import com.sun.corba.se.spi.servicecontext.ServiceContext ;
14 import com.sun.corba.se.spi.servicecontext.ServiceContextData ;
15 import com.sun.corba.se.spi.orb.ORB ;
16 import com.sun.corba.se.impl.orbutil.ORBUtility ;
17
18 public class ServiceContextRegistry {
19     private ORB orb ;
20     private Vector JavaDoc scCollection ;
21
22     private void dprint( String JavaDoc msg )
23     {
24     ORBUtility.dprint( this, msg ) ;
25     }
26
27     public ServiceContextRegistry( ORB orb )
28     {
29     scCollection = new Vector JavaDoc() ;
30     this.orb = orb ;
31     }
32
33     /** Register the ServiceContext class so that it will be recognized
34      * by the read method.
35      * Class cls must have the following properties:
36      * <ul>
37      * <li>It must derive from com.sun.corba.se.spi.servicecontext.ServiceContext.</li>
38      * <li>It must have a public static final int SERVICE_CONTEXT_ID
39      * member.</li>
40      * <li>It must implement a constructor that takes a
41      * org.omg.CORBA_2_3.portable.InputStream argument.</li>
42      * </ul>
43      */

44     public void register( Class JavaDoc cls )
45     {
46     if (ORB.ORBInitDebug)
47         dprint( "Registering service context class " + cls ) ;
48     
49     ServiceContextData scd = new ServiceContextData( cls ) ;
50
51     if (findServiceContextData(scd.getId()) == null)
52         scCollection.addElement( scd ) ;
53     else
54         throw new BAD_PARAM JavaDoc( "Tried to register duplicate service context" ) ;
55     }
56
57     public ServiceContextData findServiceContextData( int scId )
58     {
59     if (ORB.ORBInitDebug)
60         dprint( "Searching registry for service context id " + scId ) ;
61     
62     Enumeration JavaDoc enumeration = scCollection.elements() ;
63     while (enumeration.hasMoreElements()) {
64         ServiceContextData scd =
65         (ServiceContextData)(enumeration.nextElement()) ;
66         if (scd.getId() == scId) {
67         if (ORB.ORBInitDebug)
68             dprint( "Service context data found: " + scd ) ;
69
70         return scd ;
71         }
72     }
73
74     if (ORB.ORBInitDebug)
75         dprint( "Service context data not found" ) ;
76
77     return null ;
78     }
79 }
80
Popular Tags