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 *    https://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
021package org.apache.directory.api.ldap.model.schema.normalizers;
022
023
024import org.apache.directory.api.ldap.model.exception.LdapException;
025import org.apache.directory.api.ldap.model.schema.AttributeType;
026
027
028/**
029 * Normalizers of ldap name component attributes and their values.
030 * 
031 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
032 */
033public interface NameComponentNormalizer
034{
035    /**
036     * Checks to see if an attribute name/oid is defined.
037     * 
038     * @param id
039     *            the name/oid of the attribute to see if it is defined
040     * @return true if it is, false otherwise
041     */
042    boolean isDefined( String id );
043
044
045    /**
046     * Normalizes the attribute name/alias to use the OID for it instead.
047     * 
048     * @param attributeName the name or OID of the attributeType
049     * @return the OID of the attributeType if it is recognized
050     * @throws LdapException if the attributeName is not recognized as a valid alias
051     */
052    String normalizeName( String attributeName ) throws LdapException;
053
054
055    /**
056     * Normalizes an attribute's value given the name of the attribute - short
057     * names like 'cn' as well as 'commonName' should work here.
058     * 
059     * @param attributeName
060     *            the name of the attribute
061     * @param value
062     *            the value of the attribute to normalize
063     * @return the normalized value
064     * @throws LdapException
065     *             if there is a recognition problem or a syntax issue
066     */
067    Object normalizeByName( String attributeName, String value ) throws LdapException;
068
069
070    /**
071     * Normalizes an attribute's value given the name of the attribute - short
072     * names like 'cn' as well as 'commonName' should work here.
073     * 
074     * @param attributeType the attributeType
075     * @param value the value of the attribute to normalize
076     * @return the normalized value
077     * @throws LdapException if there is a recognition problem or a syntax issue
078     */
079    Object normalizeByName( AttributeType attributeType, String value ) throws LdapException;
080
081
082    /**
083     * Normalizes an attribute's value given the name of the attribute - short
084     * names like 'cn' as well as 'commonName' should work here.
085     * 
086     * @param attributeName
087     *            the name of the attribute
088     * @param value
089     *            the value of the attribute to normalize
090     * @return the normalized value
091     * @throws LdapException
092     *             if there is a recognition problem or a syntax issue
093     */
094    Object normalizeByName( String attributeName, byte[] value ) throws LdapException;
095
096
097    /**
098     * Normalizes an attribute's value given the OID of the attribute.
099     * 
100     * @param attributeOid
101     *            the OID of the attribute
102     * @param value
103     *            the value of the attribute to normalize
104     * @return the normalized value
105     * @throws LdapException
106     *             if there is a recognition problem or a syntax issue
107     */
108    Object normalizeByOid( String attributeOid, String value ) throws LdapException;
109
110
111    /**
112     * Normalizes an attribute's value given the OID of the attribute.
113     * 
114     * @param attributeOid
115     *            the OID of the attribute
116     * @param value
117     *            the value of the attribute to normalize
118     * @return the normalized value
119     * @throws LdapException
120     *             if there is a recognition problem or a syntax issue
121     */
122    Object normalizeByOid( String attributeOid, byte[] value ) throws LdapException;
123}