KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ldap > server > schema > bootstrap > BootstrapNormalizerRegistry


1 /*
2  * Copyright 2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17 package org.apache.ldap.server.schema.bootstrap;
18
19
20 import org.apache.ldap.common.schema.Normalizer;
21 import org.apache.ldap.server.schema.NormalizerRegistry;
22 import org.apache.ldap.server.schema.NormalizerRegistryMonitor;
23 import org.apache.ldap.server.schema.NormalizerRegistryMonitorAdapter;
24
25 import javax.naming.NamingException JavaDoc;
26 import java.util.HashMap JavaDoc;
27 import java.util.Map JavaDoc;
28
29
30 /**
31  * The POJO implementation for the NormalizerRegistry service.
32  *
33  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
34  * @version $Rev: 169198 $
35  */

36 public class BootstrapNormalizerRegistry implements NormalizerRegistry
37 {
38     /** a map of Normalizers looked up by OID */
39     private final Map JavaDoc byOid;
40     /** maps an OID to a schema name*/
41     private final Map JavaDoc oidToSchema;
42     /** the monitor used to deliver callback notification events */
43     private NormalizerRegistryMonitor monitor;
44
45
46     // ------------------------------------------------------------------------
47
// C O N S T R U C T O R S
48
// ------------------------------------------------------------------------
49

50
51     /**
52      * Creates a default normalizer registry.
53      */

54     public BootstrapNormalizerRegistry()
55     {
56         this.byOid = new HashMap JavaDoc();
57         this.oidToSchema = new HashMap JavaDoc();
58         this.monitor = new NormalizerRegistryMonitorAdapter();
59     }
60
61
62     /**
63      * Sets the monitor used to deliver notification events to via callbacks.
64      *
65      * @param monitor the monitor to recieve callback events
66      */

67     public void setMonitor( NormalizerRegistryMonitor monitor )
68     {
69         this.monitor = monitor;
70     }
71
72
73     // ------------------------------------------------------------------------
74
// Service Methods
75
// ------------------------------------------------------------------------
76

77
78     public void register( String JavaDoc schema, String JavaDoc oid, Normalizer normalizer )
79         throws NamingException JavaDoc
80     {
81         if ( byOid.containsKey( oid ) )
82         {
83             NamingException JavaDoc e = new NamingException JavaDoc( "Normalizer already " +
84                 "registered for OID " + oid );
85             monitor.registerFailed( oid, normalizer, e );
86             throw e;
87         }
88
89         oidToSchema.put( oid, schema );
90         byOid.put( oid, normalizer );
91         monitor.registered( oid, normalizer );
92     }
93
94
95     public Normalizer lookup( String JavaDoc oid ) throws NamingException JavaDoc
96     {
97         if ( ! byOid.containsKey( oid ) )
98         {
99             NamingException JavaDoc e = new NamingException JavaDoc( "Normalizer for OID "
100                 + oid + " does not exist!" );
101             monitor.lookupFailed( oid, e );
102             throw e;
103         }
104
105         Normalizer normalizer = ( Normalizer ) byOid.get( oid );
106         monitor.lookedUp( oid, normalizer );
107         return normalizer;
108     }
109
110
111     public boolean hasNormalizer( String JavaDoc oid )
112     {
113         return byOid.containsKey( oid );
114     }
115
116
117     public String JavaDoc getSchemaName( String JavaDoc oid ) throws NamingException JavaDoc
118     {
119         if ( Character.isDigit( oid.charAt( 0 ) ) )
120         {
121             throw new NamingException JavaDoc( "Looks like the arg is not a numeric OID" );
122         }
123
124         if ( oidToSchema.containsKey( oid ) )
125         {
126             return ( String JavaDoc ) oidToSchema.get( oid );
127         }
128
129         throw new NamingException JavaDoc( "OID " + oid + " not found in oid to " +
130             "schema name map!" );
131     }
132 }
133
Popular Tags