1 17 package org.apache.ldap.server.schema.bootstrap; 18 19 20 import org.apache.ldap.server.jndi.ServerDirObjectFactory; 21 import org.apache.ldap.server.schema.ObjectFactoryRegistry; 22 import org.apache.ldap.server.schema.OidRegistry; 23 24 import javax.naming.NamingException ; 25 import javax.naming.directory.Attribute ; 26 import javax.naming.ldap.LdapContext ; 27 import java.util.HashMap ; 28 29 30 36 public class BootstrapObjectFactoryRegistry implements ObjectFactoryRegistry 37 { 38 39 private final HashMap byOid = new HashMap (); 40 41 42 private final OidRegistry oidRegistry; 43 44 45 49 50 55 public BootstrapObjectFactoryRegistry( OidRegistry oidRegistry ) 56 { 57 this.oidRegistry = oidRegistry; 58 } 59 60 61 public ServerDirObjectFactory getObjectFactories( LdapContext ctx ) throws NamingException 62 { 63 Attribute objectClass = ctx.getAttributes( "" ).get( "objectClass" ); 64 65 if ( objectClass == null ) 66 { 67 return null; 68 } 69 70 if ( ctx.getEnvironment().containsKey( "factory.hint" ) ) 71 { 72 String oid = ( String ) ctx.getEnvironment().get( "factory.hint" ); 73 74 String noid = oidRegistry.getOid( oid ); 75 76 if ( byOid.containsKey( noid ) ) 77 { 78 return ( ServerDirObjectFactory ) byOid.get( noid ); 79 } 80 } 81 82 84 for ( int ii = 0; ii < objectClass.size(); ii++ ) 85 { 86 String noid = oidRegistry.getOid( ( String ) objectClass.get( ii ) ); 87 if ( byOid.containsKey( noid ) ) 88 { 89 return ( ServerDirObjectFactory ) byOid.get( noid ); 90 } 91 } 92 93 return null; 94 } 95 96 97 public void register( ServerDirObjectFactory factory ) throws NamingException 98 { 99 byOid.put( oidRegistry.getOid( factory.getObjectClassId() ), factory ); 100 } 101 } 102 | Popular Tags |