KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > ior > IdentifiableFactoryFinderBase


1 /*
2  * @(#)IdentifiableFactoryFinderBase.java 1.4 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
8 package com.sun.corba.se.impl.ior ;
9
10 import org.omg.CORBA_2_3.portable.InputStream JavaDoc ;
11
12 import java.util.Map JavaDoc ;
13 import java.util.HashMap JavaDoc ;
14
15 import com.sun.corba.se.spi.orb.ORB ;
16
17 import com.sun.corba.se.spi.ior.Identifiable ;
18 import com.sun.corba.se.spi.ior.IdentifiableFactory ;
19 import com.sun.corba.se.spi.ior.IdentifiableFactoryFinder ;
20
21 import com.sun.corba.se.spi.logging.CORBALogDomains ;
22
23 import com.sun.corba.se.impl.logging.IORSystemException ;
24
25 public abstract class IdentifiableFactoryFinderBase implements
26     IdentifiableFactoryFinder
27 {
28     private ORB orb ;
29     private Map JavaDoc map ;
30     protected IORSystemException wrapper ;
31
32     protected IdentifiableFactoryFinderBase( ORB orb )
33     {
34     map = new HashMap JavaDoc() ;
35     this.orb = orb ;
36     wrapper = IORSystemException.get( orb,
37         CORBALogDomains.OA_IOR ) ;
38     }
39
40     protected IdentifiableFactory getFactory(int id)
41     {
42     Integer JavaDoc ident = new Integer JavaDoc( id ) ;
43     IdentifiableFactory factory = (IdentifiableFactory)(map.get(
44         ident ) ) ;
45     return factory ;
46     }
47
48     public abstract Identifiable handleMissingFactory( int id, InputStream JavaDoc is ) ;
49     
50     public Identifiable create(int id, InputStream JavaDoc is)
51     {
52     IdentifiableFactory factory = getFactory( id ) ;
53
54     if (factory != null)
55         return factory.create( is ) ;
56     else
57         return handleMissingFactory( id, is ) ;
58     }
59     
60     public void registerFactory(IdentifiableFactory factory)
61     {
62     Integer JavaDoc ident = new Integer JavaDoc( factory.getId() ) ;
63     map.put( ident, factory ) ;
64     }
65 }
66
Popular Tags