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