1 17 package org.apache.ldap.server.schema.bootstrap; 18 19 20 import org.apache.ldap.server.schema.ComparatorRegistry; 21 import org.apache.ldap.server.schema.ComparatorRegistryMonitor; 22 import org.apache.ldap.server.schema.ComparatorRegistryMonitorAdapter; 23 import org.apache.ldap.server.schema.SerializableComparator; 24 25 import javax.naming.NamingException ; 26 import java.util.Comparator ; 27 import java.util.HashMap ; 28 import java.util.Map ; 29 30 31 37 public class BootstrapComparatorRegistry implements ComparatorRegistry 38 { 39 40 private final Map comparators; 41 42 private final Map oidToSchema; 43 44 private ComparatorRegistryMonitor monitor; 45 46 47 51 52 56 public BootstrapComparatorRegistry() 57 { 58 this.oidToSchema = new HashMap (); 59 this.comparators = new HashMap (); 60 this.monitor = new ComparatorRegistryMonitorAdapter(); 61 62 SerializableComparator.setRegistry( this ); 63 } 64 65 66 71 public void setMonitor( ComparatorRegistryMonitor monitor ) 72 { 73 this.monitor = monitor; 74 } 75 76 77 81 82 public void register( String schema, String oid, Comparator comparator ) throws NamingException 83 { 84 if ( comparators.containsKey( oid ) ) 85 { 86 NamingException e = new NamingException ( "Comparator with OID " 87 + oid + " already registered!" ); 88 monitor.registerFailed( oid, comparator, e ); 89 throw e; 90 } 91 92 oidToSchema.put( oid, schema ); 93 comparators.put( oid, comparator ); 94 monitor.registered( oid, comparator ); 95 } 96 97 98 public Comparator lookup( String oid ) throws NamingException 99 { 100 if ( comparators.containsKey( oid ) ) 101 { 102 Comparator c = ( Comparator ) comparators.get( oid ); 103 monitor.lookedUp( oid, c ); 104 return c; 105 } 106 107 108 NamingException e = new NamingException ( "Comparator not found for OID: " + oid ); 109 monitor.lookupFailed( oid, e ); 110 throw e; 111 } 112 113 114 public boolean hasComparator( String oid ) 115 { 116 return comparators.containsKey( oid ); 117 } 118 119 120 public String getSchemaName( String oid ) throws NamingException 121 { 122 if ( ! Character.isDigit( oid.charAt( 0 ) ) ) 123 { 124 throw new NamingException ( "OID " + oid + " is not a numeric OID" ); 125 } 126 127 if ( oidToSchema.containsKey( oid ) ) 128 { 129 return ( String ) oidToSchema.get( oid ); 130 } 131 132 throw new NamingException ( "OID " + oid + " not found in oid to " + 133 "schema name map!" ); 134 } 135 } 136 | Popular Tags |