1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * https://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 *
19 */
20 package org.apache.directory.api.ldap.model.schema.normalizers;
21
22
23 import org.apache.directory.api.ldap.model.constants.SchemaConstants;
24 import org.apache.directory.api.ldap.model.exception.LdapException;
25 import org.apache.directory.api.ldap.model.name.Dn;
26 import org.apache.directory.api.ldap.model.schema.Normalizer;
27 import org.apache.directory.api.ldap.model.schema.PrepareString;
28 import org.apache.directory.api.ldap.model.schema.SchemaManager;
29
30
31 /**
32 * Normalizer a Dn
33 *
34 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
35 */
36 @SuppressWarnings("serial")
37 public class DnNormalizer extends Normalizer
38 {
39 /** A reference to the schema manager used to normalize the Dn */
40 private transient SchemaManager schemaManager;
41
42
43 /**
44 * Empty constructor
45 */
46 public DnNormalizer()
47 {
48 super( SchemaConstants.DISTINGUISHED_NAME_MATCH_MR_OID );
49 }
50
51
52 /**
53 * {@inheritDoc}
54 */
55 @Override
56 public String normalize( String value ) throws LdapException
57 {
58 Dn dn = new Dn( schemaManager, value );
59
60 return dn.getNormName();
61 }
62
63
64 /**
65 * {@inheritDoc}
66 */
67 @Override
68 public String normalize( String value, PrepareString.AssertionType assertionType ) throws LdapException
69 {
70 Dn dn = new Dn( schemaManager, value );
71
72 return dn.getNormName();
73 }
74
75
76 /**
77 * Normalize a Dn
78 * @param value The Dn to normalize
79 * @return A normalized Dn
80 * @throws LdapException If the DN is invalid
81 */
82 public String normalize( Dn value ) throws LdapException
83 {
84 Dn dn = value;
85
86 if ( !value.isSchemaAware() )
87 {
88 dn = new Dn( schemaManager, value );
89 }
90
91 return dn.getNormName();
92 }
93
94
95 /**
96 * {@inheritDoc}
97 */
98 @Override
99 public void setSchemaManager( SchemaManager schemaManager )
100 {
101 this.schemaManager = schemaManager;
102 }
103 }