1 17 package org.apache.ldap.server.schema.bootstrap; 18 19 20 import org.apache.ldap.common.schema.Syntax; 21 import org.apache.ldap.server.schema.OidRegistry; 22 import org.apache.ldap.server.schema.SyntaxRegistry; 23 import org.apache.ldap.server.schema.SyntaxRegistryMonitor; 24 import org.apache.ldap.server.schema.SyntaxRegistryMonitorAdapter; 25 26 import javax.naming.NamingException ; 27 import java.util.HashMap ; 28 import java.util.Iterator ; 29 import java.util.Map ; 30 31 32 39 public class BootstrapSyntaxRegistry implements SyntaxRegistry 40 { 41 42 private final Map byOid; 43 44 private final Map oidToSchema; 45 46 private final OidRegistry oidRegistry; 47 48 private SyntaxRegistryMonitor monitor = null; 49 50 51 55 56 59 public BootstrapSyntaxRegistry( OidRegistry registry ) 60 { 61 this.oidRegistry = registry; 62 this.byOid = new HashMap (); 63 this.oidToSchema = new HashMap (); 64 this.monitor = new SyntaxRegistryMonitorAdapter(); 65 } 66 67 68 72 73 76 public Syntax lookup( String id ) throws NamingException 77 { 78 id = oidRegistry.getOid( id ); 79 80 if ( byOid.containsKey( id ) ) 81 { 82 Syntax syntax = ( Syntax ) byOid.get( id ); 83 monitor.lookedUp( syntax ); 84 return syntax; 85 } 86 87 NamingException fault = new NamingException ( "Unknown syntax OID " + id ); 88 monitor.lookupFailed( id, fault ); 89 throw fault; 90 } 91 92 93 96 public void register( String schema, Syntax syntax ) throws NamingException 97 { 98 if ( byOid.containsKey( syntax.getOid() ) ) 99 { 100 NamingException e = new NamingException ( "syntax w/ OID " + 101 syntax.getOid() + " has already been registered!" ); 102 monitor.registerFailed( syntax, e ); 103 throw e; 104 } 105 106 oidRegistry.register( syntax.getName(), syntax.getOid() ); 107 byOid.put( syntax.getOid(), syntax ); 108 oidToSchema.put( syntax.getOid(), schema ); 109 monitor.registered( syntax ); 110 } 111 112 113 116 public boolean hasSyntax( String id ) 117 { 118 if ( oidRegistry.hasOid( id ) ) 119 { 120 try 121 { 122 return byOid.containsKey( oidRegistry.getOid( id ) ); 123 } 124 catch ( NamingException e ) 125 { 126 return false; 127 } 128 } 129 130 return false; 131 } 132 133 134 public String getSchemaName( String id ) throws NamingException 135 { 136 id = oidRegistry.getOid( id ); 137 if ( oidToSchema.containsKey( id ) ) 138 { 139 return ( String ) oidToSchema.get( id ); 140 } 141 142 throw new NamingException ( "OID " + id + " not found in oid to " + 143 "schema name map!" ); 144 } 145 146 147 151 152 157 SyntaxRegistryMonitor getMonitor() 158 { 159 return monitor; 160 } 161 162 163 168 void setMonitor( SyntaxRegistryMonitor monitor ) 169 { 170 this.monitor = monitor; 171 } 172 173 174 public Iterator list() 175 { 176 return byOid.values().iterator(); 177 } 178 } 179 | Popular Tags |