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