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