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