1 17 package org.apache.ldap.server.schema.bootstrap; 18 19 20 import org.apache.ldap.common.schema.MatchingRuleUse; 21 import org.apache.ldap.server.schema.MatchingRuleUseRegistry; 22 import org.apache.ldap.server.schema.MatchingRuleUseRegistryMonitor; 23 import org.apache.ldap.server.schema.MatchingRuleUseRegistryMonitorAdapter; 24 25 import javax.naming.NamingException ; 26 import java.util.HashMap ; 27 import java.util.Iterator ; 28 import java.util.Map ; 29 30 31 37 public class BootstrapMatchingRuleUseRegistry implements MatchingRuleUseRegistry 38 { 39 40 private final Map byName; 41 42 private final Map nameToSchema; 43 44 private MatchingRuleUseRegistryMonitor monitor; 45 46 47 51 52 55 public BootstrapMatchingRuleUseRegistry() 56 { 57 this.byName = new HashMap (); 58 this.nameToSchema = new HashMap (); 59 this.monitor = new MatchingRuleUseRegistryMonitorAdapter(); 60 } 61 62 63 68 public void setMonitor( MatchingRuleUseRegistryMonitor monitor ) 69 { 70 this.monitor = monitor; 71 } 72 73 74 78 79 public void register( String schema, MatchingRuleUse matchingRuleUse ) 80 throws NamingException 81 { 82 if ( byName.containsKey( matchingRuleUse.getName() ) ) 83 { 84 NamingException e = new NamingException ( "matchingRuleUse w/ name " 85 + matchingRuleUse.getName() + " has already been registered!" ); 86 monitor.registerFailed( matchingRuleUse, e ); 87 throw e; 88 } 89 90 nameToSchema.put( matchingRuleUse.getName(), schema ); 91 byName.put( matchingRuleUse.getName(), matchingRuleUse ); 92 monitor.registered( matchingRuleUse ); 93 } 94 95 96 public MatchingRuleUse lookup( String name ) throws NamingException 97 { 98 if ( ! byName.containsKey( name ) ) 99 { 100 NamingException e = new NamingException ( "matchingRuleUse w/ name " 101 + name + " not registered!" ); 102 monitor.lookupFailed( name, e ); 103 throw e; 104 } 105 106 MatchingRuleUse matchingRuleUse = ( MatchingRuleUse ) byName.get( name ); 107 monitor.lookedUp( matchingRuleUse ); 108 return matchingRuleUse; 109 } 110 111 112 public boolean hasMatchingRuleUse( String name ) 113 { 114 return byName.containsKey( name ); 115 } 116 117 118 public String getSchemaName( String id ) throws NamingException 119 { 120 if ( nameToSchema.containsKey( id ) ) 121 { 122 return ( String ) nameToSchema.get( id ); 123 } 124 125 throw new NamingException ( "Name " + id + " not found in name to " + 126 "schema name map!" ); 127 } 128 129 130 public Iterator list() 131 { 132 return byName.values().iterator(); 133 } 134 } 135 | Popular Tags |