1 17 package org.apache.ldap.server.schema.bootstrap; 18 19 20 import org.apache.ldap.common.schema.Normalizer; 21 import org.apache.ldap.server.schema.NormalizerRegistry; 22 import org.apache.ldap.server.schema.NormalizerRegistryMonitor; 23 import org.apache.ldap.server.schema.NormalizerRegistryMonitorAdapter; 24 25 import javax.naming.NamingException ; 26 import java.util.HashMap ; 27 import java.util.Map ; 28 29 30 36 public class BootstrapNormalizerRegistry implements NormalizerRegistry 37 { 38 39 private final Map byOid; 40 41 private final Map oidToSchema; 42 43 private NormalizerRegistryMonitor monitor; 44 45 46 50 51 54 public BootstrapNormalizerRegistry() 55 { 56 this.byOid = new HashMap (); 57 this.oidToSchema = new HashMap (); 58 this.monitor = new NormalizerRegistryMonitorAdapter(); 59 } 60 61 62 67 public void setMonitor( NormalizerRegistryMonitor monitor ) 68 { 69 this.monitor = monitor; 70 } 71 72 73 77 78 public void register( String schema, String oid, Normalizer normalizer ) 79 throws NamingException 80 { 81 if ( byOid.containsKey( oid ) ) 82 { 83 NamingException e = new NamingException ( "Normalizer already " + 84 "registered for OID " + oid ); 85 monitor.registerFailed( oid, normalizer, e ); 86 throw e; 87 } 88 89 oidToSchema.put( oid, schema ); 90 byOid.put( oid, normalizer ); 91 monitor.registered( oid, normalizer ); 92 } 93 94 95 public Normalizer lookup( String oid ) throws NamingException 96 { 97 if ( ! byOid.containsKey( oid ) ) 98 { 99 NamingException e = new NamingException ( "Normalizer for OID " 100 + oid + " does not exist!" ); 101 monitor.lookupFailed( oid, e ); 102 throw e; 103 } 104 105 Normalizer normalizer = ( Normalizer ) byOid.get( oid ); 106 monitor.lookedUp( oid, normalizer ); 107 return normalizer; 108 } 109 110 111 public boolean hasNormalizer( String oid ) 112 { 113 return byOid.containsKey( oid ); 114 } 115 116 117 public String getSchemaName( String oid ) throws NamingException 118 { 119 if ( Character.isDigit( oid.charAt( 0 ) ) ) 120 { 121 throw new NamingException ( "Looks like the arg is not a numeric OID" ); 122 } 123 124 if ( oidToSchema.containsKey( oid ) ) 125 { 126 return ( String ) oidToSchema.get( oid ); 127 } 128 129 throw new NamingException ( "OID " + oid + " not found in oid to " + 130 "schema name map!" ); 131 } 132 } 133 | Popular Tags |