001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 *
019 */
020 package org.apache.directory.shared.ldap.schema.normalizers;
021
022
023 import javax.naming.NamingException;
024
025 import org.apache.directory.shared.ldap.constants.SchemaConstants;
026 import org.apache.directory.shared.ldap.entry.Value;
027 import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
028 import org.apache.directory.shared.ldap.name.DN;
029 import org.apache.directory.shared.ldap.schema.Normalizer;
030 import org.apache.directory.shared.ldap.schema.SchemaManager;
031
032
033 /**
034 * Normalizer a DN
035 *
036 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
037 * @version $Rev$
038 */
039 public class DnNormalizer extends Normalizer
040 {
041 // The serial UID
042 private static final long serialVersionUID = 1L;
043
044 /** A reference to the schema manager used to normalize the DN */
045 private SchemaManager schemaManager;
046
047 /**
048 * Empty constructor
049 */
050 public DnNormalizer()
051 {
052 super( SchemaConstants.DISTINGUISHED_NAME_MATCH_MR_OID );
053 }
054
055
056 /**
057 * {@inheritDoc}
058 */
059 public Value<?> normalize( Value<?> value ) throws NamingException
060 {
061 DN dn = null;
062
063 String dnStr = value.getString();
064
065 dn = new DN( dnStr );
066
067 dn.normalize( schemaManager.getNormalizerMapping() );
068 return new ClientStringValue( dn.getNormName() );
069 }
070
071
072 /**
073 * {@inheritDoc}
074 */
075 public String normalize( String value ) throws NamingException
076 {
077 DN dn = null;
078
079 dn = new DN( value );
080
081 dn.normalize( schemaManager.getNormalizerMapping() );
082 return dn.getNormName();
083 }
084
085
086 /**
087 * Normalize a DN
088 * @param value The DN to normalize
089 * @return A normalized DN
090 * @throws NamingException
091 */
092 public String normalize( DN value ) throws NamingException
093 {
094 DN dn = null;
095
096 dn = new DN( value );
097
098 dn.normalize( schemaManager.getNormalizerMapping() );
099 return dn.getNormName();
100 }
101
102
103 /**
104 * {@inheritDoc}
105 */
106 public void setSchemaManager( SchemaManager schemaManager )
107 {
108 this.schemaManager = schemaManager;
109 }
110 }