1 17 package org.apache.ldap.server.schema.bootstrap; 18 19 20 import org.apache.ldap.common.schema.MatchingRule; 21 import org.apache.ldap.server.schema.MatchingRuleRegistry; 22 import org.apache.ldap.server.schema.MatchingRuleRegistryMonitor; 23 import org.apache.ldap.server.schema.MatchingRuleRegistryMonitorAdapter; 24 import org.apache.ldap.server.schema.OidRegistry; 25 26 import javax.naming.NamingException ; 27 import java.util.HashMap ; 28 import java.util.Iterator ; 29 import java.util.Map ; 30 31 32 38 public class BootstrapMatchingRuleRegistry implements MatchingRuleRegistry 39 { 40 41 private final Map byOid; 42 43 private final Map oidToSchema; 44 45 private final OidRegistry oidRegistry; 46 47 private MatchingRuleRegistryMonitor monitor = null; 48 49 50 54 55 60 public BootstrapMatchingRuleRegistry( OidRegistry oidRegistry ) 61 { 62 this.oidToSchema = new HashMap (); 63 this.oidRegistry = oidRegistry; 64 this.byOid = new HashMap (); 65 this.monitor = new MatchingRuleRegistryMonitorAdapter(); 66 } 67 68 69 73 74 77 public MatchingRule lookup( String id ) throws NamingException 78 { 79 id = oidRegistry.getOid( id ); 80 81 if ( byOid.containsKey( id ) ) 82 { 83 MatchingRule MatchingRule = ( MatchingRule ) byOid.get( id ); 84 monitor.lookedUp( MatchingRule ); 85 return MatchingRule; 86 } 87 88 NamingException fault = new NamingException ( "Unknown MatchingRule OID " + id ); 89 monitor.lookupFailed( id, fault ); 90 throw fault; 91 } 92 93 94 97 public void register( String schema, MatchingRule matchingRule ) throws NamingException 98 { 99 if ( byOid.containsKey( matchingRule.getOid() ) ) 100 { 101 NamingException e = new NamingException ( "matchingRule w/ OID " + 102 matchingRule.getOid() + " has already been registered!" ); 103 monitor.registerFailed( matchingRule, e ); 104 throw e; 105 } 106 107 oidToSchema.put( matchingRule.getOid(), schema ); 108 109 String [] names = matchingRule.getNames(); 110 for ( int ii = 0; ii < names.length; ii++ ) 111 { 112 oidRegistry.register( names[ii], matchingRule.getOid() ); 113 } 114 115 byOid.put( matchingRule.getOid(), matchingRule ); 116 monitor.registered( matchingRule ); 117 } 118 119 120 123 public boolean hasMatchingRule( String id ) 124 { 125 if ( oidRegistry.hasOid( id ) ) 126 { 127 try 128 { 129 return byOid.containsKey( oidRegistry.getOid( id ) ); 130 } 131 catch ( NamingException e ) 132 { 133 return false; 134 } 135 } 136 137 return false; 138 } 139 140 141 public String getSchemaName( String id ) throws NamingException 142 { 143 id = oidRegistry.getOid( id ); 144 if ( oidToSchema.containsKey( id ) ) 145 { 146 return ( String ) oidToSchema.get( id ); 147 } 148 149 throw new NamingException ( "OID " + id + " not found in oid to " + 150 "schema name map!" ); 151 } 152 153 154 158 159 164 MatchingRuleRegistryMonitor getMonitor() 165 { 166 return monitor; 167 } 168 169 170 175 void setMonitor( MatchingRuleRegistryMonitor monitor ) 176 { 177 this.monitor = monitor; 178 } 179 180 181 public Iterator list() 182 { 183 return byOid.values().iterator(); 184 } 185 } 186 | Popular Tags |