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 */ 020package org.apache.directory.api.ldap.model.schema.normalizers; 021 022 023import org.apache.directory.api.ldap.model.constants.SchemaConstants; 024import org.apache.directory.api.ldap.model.entry.StringValue; 025import org.apache.directory.api.ldap.model.entry.Value; 026import org.apache.directory.api.ldap.model.exception.LdapException; 027import org.apache.directory.api.ldap.model.name.Dn; 028import org.apache.directory.api.ldap.model.schema.Normalizer; 029import org.apache.directory.api.ldap.model.schema.SchemaManager; 030 031 032/** 033 * Normalizer a Dn 034 * 035 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 036 */ 037@SuppressWarnings("serial") 038public class DnNormalizer extends Normalizer 039{ 040 /** A reference to the schema manager used to normalize the Dn */ 041 private SchemaManager schemaManager; 042 043 044 /** 045 * Empty constructor 046 */ 047 public DnNormalizer() 048 { 049 super( SchemaConstants.DISTINGUISHED_NAME_MATCH_MR_OID ); 050 } 051 052 053 /** 054 * {@inheritDoc} 055 */ 056 public Value<?> normalize( Value<?> value ) throws LdapException 057 { 058 Dn dn = null; 059 060 String dnStr = value.getString(); 061 062 dn = new Dn( schemaManager, dnStr ); 063 064 return new StringValue( dn.getNormName() ); 065 } 066 067 068 /** 069 * {@inheritDoc} 070 */ 071 public String normalize( String value ) throws LdapException 072 { 073 Dn dn = null; 074 075 dn = new Dn( schemaManager, value ); 076 077 return dn.getNormName(); 078 } 079 080 081 /** 082 * Normalize a Dn 083 * @param value The Dn to normalize 084 * @return A normalized Dn 085 * @throws LdapException 086 */ 087 public String normalize( Dn value ) throws LdapException 088 { 089 Dn dn = null; 090 091 dn = value.apply( schemaManager ); 092 093 return dn.getNormName(); 094 } 095 096 097 /** 098 * {@inheritDoc} 099 */ 100 public void setSchemaManager( SchemaManager schemaManager ) 101 { 102 this.schemaManager = schemaManager; 103 } 104}