KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ldap > server > schema > ConcreteNameComponentNormalizer


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;
18
19
20 import org.apache.ldap.common.name.NameComponentNormalizer;
21 import org.apache.ldap.common.schema.AttributeType;
22 import org.apache.ldap.common.schema.Normalizer;
23
24 import javax.naming.NamingException JavaDoc;
25
26
27 /**
28  * A DN Name component Normalizer which uses the bootstrap registries to find
29  * the appropriate normalizer for the attribute of the name component with which
30  * to normalize the name component value.
31  *
32  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
33  * @version $Rev: 169198 $
34  */

35 public class ConcreteNameComponentNormalizer implements NameComponentNormalizer
36 {
37     /** the at registry used to dynamically resolve Normalizers */
38     private final AttributeTypeRegistry registry;
39
40
41     /**
42      * Creates a DN Name component Normalizer which uses the bootstrap
43      * registries to find the appropriate normalizer for the attribute of the
44      * name component with which to normalize the name component value.
45      *
46      * @param registry the at registry used to dynamically resolve Normalizers
47      */

48     public ConcreteNameComponentNormalizer( AttributeTypeRegistry registry )
49     {
50         this.registry = registry;
51     }
52
53
54     /**
55      * @see NameComponentNormalizer#normalizeByName(String, String)
56      */

57     public String JavaDoc normalizeByName( String JavaDoc name, String JavaDoc value ) throws NamingException JavaDoc
58     {
59         return lookup( name ).normalize( value ).toString();
60     }
61
62
63     /**
64      * @see NameComponentNormalizer#normalizeByOid(String, String)
65      */

66     public String JavaDoc normalizeByOid( String JavaDoc oid, String JavaDoc value ) throws NamingException JavaDoc
67     {
68         return lookup( oid ).normalize( value ).toString();
69     }
70
71
72     /**
73      * Looks up the Normalizer to use for a name component using the attributeId
74      * for the name component. First the attribute is resolved, then its
75      * equality matching rule is looked up. The normalizer of that matching
76      * rule is returned.
77      *
78      * @param id the name or oid of the attribute in the name component to
79      * normalize the value of
80      * @return the Normalizer to use for normalizing the value of the attribute
81      * @throws NamingException if there are failures resolving the Normalizer
82      */

83     private Normalizer lookup( String JavaDoc id ) throws NamingException JavaDoc
84     {
85         AttributeType type = registry.lookup( id );
86         return type.getEquality().getNormalizer();
87     }
88 }
89
Popular Tags