1 17 package org.apache.ldap.server.schema.bootstrap; 18 19 20 import org.apache.ldap.common.schema.SyntaxChecker; 21 import org.apache.ldap.server.schema.SyntaxCheckerRegistry; 22 import org.apache.ldap.server.schema.SyntaxCheckerRegistryMonitor; 23 import org.apache.ldap.server.schema.SyntaxCheckerRegistryMonitorAdapter; 24 25 import javax.naming.NamingException ; 26 import java.util.HashMap ; 27 import java.util.Map ; 28 29 30 36 public class BootstrapSyntaxCheckerRegistry implements SyntaxCheckerRegistry 37 { 38 39 private final Map byOid; 40 41 private final Map oidToSchema; 42 43 private SyntaxCheckerRegistryMonitor monitor; 44 45 46 50 51 54 public BootstrapSyntaxCheckerRegistry() 55 { 56 this.byOid = new HashMap (); 57 this.oidToSchema = new HashMap (); 58 this.monitor = new SyntaxCheckerRegistryMonitorAdapter(); 59 } 60 61 62 67 public void setMonitor( SyntaxCheckerRegistryMonitor monitor ) 68 { 69 this.monitor = monitor; 70 } 71 72 73 77 78 public void register( String schema, String oid, SyntaxChecker syntaxChecker ) 79 throws NamingException 80 { 81 if ( byOid.containsKey( oid ) ) 82 { 83 NamingException e = new NamingException ( "SyntaxChecker with OID " + 84 oid + " already registered!" ); 85 monitor.registerFailed( oid, syntaxChecker,e ); 86 throw e; 87 } 88 89 byOid.put( oid, syntaxChecker ); 90 oidToSchema.put( oid, schema ); 91 monitor.registered( oid, syntaxChecker ); 92 } 93 94 95 public SyntaxChecker lookup( String oid ) throws NamingException 96 { 97 if ( ! byOid.containsKey( oid ) ) 98 { 99 NamingException e = new NamingException ( "SyntaxChecker for OID " 100 + oid + " not found!" ); 101 monitor.lookupFailed( oid, e ); 102 throw e; 103 } 104 105 SyntaxChecker syntaxChecker = ( SyntaxChecker ) byOid.get( oid ); 106 monitor.lookedUp( oid, syntaxChecker ); 107 return null; 108 } 109 110 111 public boolean hasSyntaxChecker( String oid ) 112 { 113 return byOid.containsKey( oid ); 114 } 115 116 117 public String getSchemaName( String oid ) throws NamingException 118 { 119 if ( Character.isDigit( oid.charAt( 0 ) ) ) 120 { 121 throw new NamingException ( "Looks like the arg is not a numeric OID" ); 122 } 123 124 if ( oidToSchema.containsKey( oid ) ) 125 { 126 return ( String ) oidToSchema.get( oid ); 127 } 128 129 throw new NamingException ( "OID " + oid + " not found in oid to " + 130 "schema name map!" ); 131 } 132 } 133 | Popular Tags |