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 021 package org.apache.directory.shared.ldap.name; 022 023 024 import org.apache.directory.shared.i18n.I18n; 025 import org.apache.directory.shared.ldap.entry.BinaryValue; 026 import org.apache.directory.shared.ldap.exception.LdapException; 027 import org.apache.directory.shared.ldap.exception.LdapInvalidDnException; 028 import org.apache.directory.shared.ldap.schema.Normalizer; 029 030 031 /** 032 * A simple NameComponentNormalizer which uses the same Normalizer to always 033 * normalize the value the same way regardless of the attribute the value is 034 * for. 035 * 036 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 037 * @version $Rev: 928296 $ 038 */ 039 public class SimpleNameComponentNormalizer implements NameComponentNormalizer 040 { 041 /** the normalizer used to normalize the value every time */ 042 private final Normalizer normalizer; 043 044 045 /** 046 * Creates a new SimpleNameComponentNormalizer with the normalizer it uses 047 * ever time irrespective of the attribute name or oid. 048 * 049 * @param normalizer 050 * the Normalizer to use for all normalization requests 051 */ 052 public SimpleNameComponentNormalizer( Normalizer normalizer ) 053 { 054 this.normalizer = normalizer; 055 } 056 057 058 public Object normalizeByName( String name, String val ) throws LdapException 059 { 060 return normalizer.normalize( val ); 061 } 062 063 064 public Object normalizeByName( String name, byte[] val ) throws LdapException 065 { 066 return normalizer.normalize( new BinaryValue( val ) ); 067 } 068 069 070 public Object normalizeByOid( String oid, String val ) throws LdapException 071 { 072 return normalizer.normalize( val ); 073 } 074 075 076 public Object normalizeByOid( String oid, byte[] val ) throws LdapException 077 { 078 return normalizer.normalize( new BinaryValue( val ) ); 079 } 080 081 082 public boolean isDefined( String oid ) 083 { 084 return true; 085 } 086 087 088 public String normalizeName( String attributeName ) throws LdapInvalidDnException 089 { 090 throw new UnsupportedOperationException( I18n.err( I18n.ERR_04216 ) ); 091 } 092 }