1 17 package org.apache.ldap.server.schema.bootstrap; 18 19 20 import org.apache.ldap.common.schema.DITContentRule; 21 import org.apache.ldap.server.schema.DITContentRuleRegistry; 22 import org.apache.ldap.server.schema.DITContentRuleRegistryMonitor; 23 import org.apache.ldap.server.schema.DITContentRuleRegistryMonitorAdapter; 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 BootstrapDitContentRuleRegistry implements DITContentRuleRegistry 39 { 40 41 private final Map byOid; 42 43 private final Map oidToSchema; 44 45 private final OidRegistry oidRegistry; 46 47 private DITContentRuleRegistryMonitor monitor; 48 49 50 54 55 58 public BootstrapDitContentRuleRegistry( OidRegistry oidRegistry ) 59 { 60 this.byOid = new HashMap (); 61 this.oidToSchema = new HashMap (); 62 this.oidRegistry = oidRegistry; 63 this.monitor = new DITContentRuleRegistryMonitorAdapter(); 64 } 65 66 67 72 public void setMonitor( DITContentRuleRegistryMonitor monitor ) 73 { 74 this.monitor = monitor; 75 } 76 77 78 82 83 public void register( String schema, DITContentRule dITContentRule ) throws NamingException 84 { 85 if ( byOid.containsKey( dITContentRule.getOid() ) ) 86 { 87 NamingException e = new NamingException ( "dITContentRule w/ OID " + 88 dITContentRule.getOid() + " has already been registered!" ); 89 monitor.registerFailed( dITContentRule, e ); 90 throw e; 91 } 92 93 oidRegistry.register( dITContentRule.getName(), dITContentRule.getOid() ) ; 94 byOid.put( dITContentRule.getOid(), dITContentRule ); 95 oidToSchema.put( dITContentRule.getOid(), schema ); 96 monitor.registered( dITContentRule ); 97 } 98 99 100 public DITContentRule lookup( String id ) throws NamingException 101 { 102 id = oidRegistry.getOid( id ); 103 104 if ( ! byOid.containsKey( id ) ) 105 { 106 NamingException e = new NamingException ( "dITContentRule w/ OID " 107 + id + " not registered!" ); 108 monitor.lookupFailed( id, e ); 109 throw e; 110 } 111 112 DITContentRule dITContentRule = ( DITContentRule ) byOid.get( id ); 113 monitor.lookedUp( dITContentRule ); 114 return dITContentRule; 115 } 116 117 118 public boolean hasDITContentRule( String id ) 119 { 120 if ( oidRegistry.hasOid( id ) ) 121 { 122 try 123 { 124 return byOid.containsKey( oidRegistry.getOid( id ) ); 125 } 126 catch ( NamingException e ) 127 { 128 return false; 129 } 130 } 131 132 return false; 133 } 134 135 136 public String getSchemaName( String id ) throws NamingException 137 { 138 id = oidRegistry.getOid( id ); 139 if ( oidToSchema.containsKey( id ) ) 140 { 141 return ( String ) oidToSchema.get( id ); 142 } 143 144 throw new NamingException ( "OID " + id + " not found in oid to " + 145 "schema name map!" ); 146 } 147 148 149 public Iterator list() 150 { 151 return byOid.values().iterator(); 152 } 153 } 154 | Popular Tags |