1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.ldap.server.schema;
18
19
20 import javax.naming.NamingException;
21
22 import org.apache.ldap.common.name.NameComponentNormalizer;
23 import org.apache.ldap.common.schema.AttributeType;
24 import org.apache.ldap.common.schema.Normalizer;
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: 264732 $
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 normalizeByName( String name, String value ) throws NamingException
58 {
59 return lookup( name ).normalize( value ).toString();
60 }
61
62
63 /***
64 * @see NameComponentNormalizer#normalizeByOid(String, String)
65 */
66 public String normalizeByOid( String oid, String value ) throws NamingException
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 id ) throws NamingException
84 {
85 AttributeType type = registry.lookup( id );
86 return type.getEquality().getNormalizer();
87 }
88 }