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;
021
022
023 import org.apache.directory.shared.ldap.entry.Value;
024 import org.apache.directory.shared.ldap.exception.LdapException;
025
026
027 /**
028 * Converts attribute values to a canonical form.
029 *
030 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
031 * @version $Rev: 929091 $
032 */
033 public abstract class Normalizer extends LoadableSchemaObject
034 {
035 /** The serialversionUID */
036 private static final long serialVersionUID = 1L;
037
038
039 /**
040 * The Normalizer base constructor. We use it's MR OID to
041 * initialize the SchemaObject instance
042 *
043 * @param oid The associated OID. It's the element's MR OID
044 */
045 protected Normalizer( String oid )
046 {
047 super( SchemaObjectType.NORMALIZER, oid );
048 }
049
050
051 /**
052 * Use this default constructor when the Normalizer must be instantiated
053 * before setting the OID.
054 */
055 protected Normalizer()
056 {
057 super( SchemaObjectType.NORMALIZER );
058 }
059
060
061 /**
062 * Gets the normalized value.
063 *
064 * @param value the value to normalize. It must *not* be null !
065 * @return the normalized form for a value
066 * @throws LdapException if an error results during normalization
067 */
068 public abstract Value<?> normalize( Value<?> value ) throws LdapException;
069
070
071 /**
072 * Gets the normalized value.
073 *
074 * @param value the value to normalize. It must *not* be null !
075 * @return the normalized form for a value
076 * @throws LdapException if an error results during normalization
077 */
078 public abstract String normalize( String value ) throws LdapException;
079
080
081 /**
082 * Store the SchemaManager in this instance. It may be necessary for some
083 * normalizer which needs to have access to the oidNormalizer Map.
084 *
085 * @param schemaManager the schemaManager to store
086 */
087 public void setSchemaManager( SchemaManager schemaManager )
088 {
089 // Do nothing (general case).
090 }
091
092
093 /**
094 * @see Object#equals()
095 */
096 public boolean equals( Object o )
097 {
098 if ( !super.equals( o ) )
099 {
100 return false;
101 }
102
103 return o instanceof Normalizer;
104 }
105
106
107 /**
108 * @see Object#toString()
109 */
110 public String toString()
111 {
112 return objectType + " " + DescriptionUtils.getDescription( this );
113 }
114 }