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