1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.ldap.server.schema.bootstrap;
18
19
20 import java.util.HashMap;
21
22 import javax.naming.NamingException;
23
24 import org.apache.ldap.server.jndi.ServerDirStateFactory;
25 import org.apache.ldap.server.schema.StateFactoryRegistry;
26
27
28 /***
29 * A bootstrap service implementation for a state factory registry.
30 *
31 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
32 * @version $Rev: 264732 $
33 */
34 public class BootstrapStateFactoryRegistry implements StateFactoryRegistry
35 {
36 /*** Used to lookup a state factory by class */
37 private final HashMap byClass = new HashMap();
38
39
40 public ServerDirStateFactory getStateFactories( Object obj ) throws NamingException
41 {
42 Class c = obj.getClass();
43
44
45
46 if ( byClass.containsKey( c ) )
47 {
48 return ( ServerDirStateFactory ) byClass.get( c );
49 }
50
51 while ( ( c = c.getSuperclass() ) != null )
52 {
53 if ( byClass.containsKey( c ) )
54 {
55 return ( ServerDirStateFactory ) byClass.get( c );
56 }
57 }
58
59
60
61 Class[] interfaces = c.getInterfaces();
62
63 for ( int ii = 0; ii < interfaces.length; ii++ )
64 {
65 if ( byClass.containsKey( interfaces[ii] ) )
66 {
67 return ( ServerDirStateFactory ) byClass.get( interfaces[ii] );
68 }
69 }
70
71 return null;
72 }
73
74
75 public void register( ServerDirStateFactory factory )
76 {
77 byClass.put( factory.getAssociatedClass(), factory );
78 }
79 }