1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.ldap.server.schema.bootstrap;
18
19
20 import java.util.HashMap;
21 import java.util.Map;
22
23 import javax.naming.NamingException;
24
25 import org.apache.ldap.common.schema.SyntaxChecker;
26 import org.apache.ldap.server.schema.SyntaxCheckerRegistry;
27 import org.apache.ldap.server.schema.SyntaxCheckerRegistryMonitor;
28 import org.apache.ldap.server.schema.SyntaxCheckerRegistryMonitorAdapter;
29
30
31 /***
32 * The POJO implementation for the SyntaxCheckerRegistry service.
33 *
34 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
35 * @version $Rev: 264732 $
36 */
37 public class BootstrapSyntaxCheckerRegistry implements SyntaxCheckerRegistry
38 {
39 /*** a map by OID of SyntaxCheckers */
40 private final Map byOid;
41 /*** maps an OID to a schema name*/
42 private final Map oidToSchema;
43 /*** the monitor to use for callback event notifications */
44 private SyntaxCheckerRegistryMonitor monitor;
45
46
47
48
49
50
51
52 /***
53 * Creates an instance of a BootstrapSyntaxRegistry.
54 */
55 public BootstrapSyntaxCheckerRegistry()
56 {
57 this.byOid = new HashMap();
58 this.oidToSchema = new HashMap();
59 this.monitor = new SyntaxCheckerRegistryMonitorAdapter();
60 }
61
62
63 /***
64 * Sets the monitor used to deliver notification events to via callbacks.
65 *
66 * @param monitor the monitor to recieve callback events
67 */
68 public void setMonitor( SyntaxCheckerRegistryMonitor monitor )
69 {
70 this.monitor = monitor;
71 }
72
73
74
75
76
77
78
79 public void register( String schema, String oid, SyntaxChecker syntaxChecker )
80 throws NamingException
81 {
82 if ( byOid.containsKey( oid ) )
83 {
84 NamingException e = new NamingException( "SyntaxChecker with OID " +
85 oid + " already registered!" );
86 monitor.registerFailed( oid, syntaxChecker,e );
87 throw e;
88 }
89
90 byOid.put( oid, syntaxChecker );
91 oidToSchema.put( oid, schema );
92 monitor.registered( oid, syntaxChecker );
93 }
94
95
96 public SyntaxChecker lookup( String oid ) throws NamingException
97 {
98 if ( ! byOid.containsKey( oid ) )
99 {
100 NamingException e = new NamingException( "SyntaxChecker for OID "
101 + oid + " not found!" );
102 monitor.lookupFailed( oid, e );
103 throw e;
104 }
105
106 SyntaxChecker syntaxChecker = ( SyntaxChecker ) byOid.get( oid );
107 monitor.lookedUp( oid, syntaxChecker );
108 return null;
109 }
110
111
112 public boolean hasSyntaxChecker( String oid )
113 {
114 return byOid.containsKey( oid );
115 }
116
117
118 public String getSchemaName( String oid ) throws NamingException
119 {
120 if ( Character.isDigit( oid.charAt( 0 ) ) )
121 {
122 throw new NamingException( "Looks like the arg is not a numeric OID" );
123 }
124
125 if ( oidToSchema.containsKey( oid ) )
126 {
127 return ( String ) oidToSchema.get( oid );
128 }
129
130 throw new NamingException( "OID " + oid + " not found in oid to " +
131 "schema name map!" );
132 }
133 }