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 */ 020package org.apache.directory.api.ldap.model.schema; 021 022 023import org.apache.directory.api.ldap.model.exception.LdapException; 024 025 026/** 027 * Converts attribute values to a canonical form. 028 * 029 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 030 */ 031public abstract class Normalizer extends LoadableSchemaObject 032{ 033 /** The mandatory serialVersionUID */ 034 public static final long serialVersionUID = 1L; 035 036 037 /** 038 * The Normalizer base constructor. We use it's MR OID to 039 * initialize the SchemaObject instance 040 * 041 * @param oid The associated OID. It's the element's MR OID 042 */ 043 protected Normalizer( String oid ) 044 { 045 super( SchemaObjectType.NORMALIZER, oid ); 046 } 047 048 049 /** 050 * Use this default constructor when the Normalizer must be instantiated 051 * before setting the OID. 052 */ 053 protected Normalizer() 054 { 055 super( SchemaObjectType.NORMALIZER ); 056 } 057 058 059 /** 060 * Gets the normalized value of AssertionValues. 061 * 062 * @param value the value to normalize. It must *not* be null ! 063 * @return the normalized form for a value 064 * @throws LdapException if an error results during normalization 065 */ 066 public abstract String normalize( String value ) throws LdapException; 067 068 069 /** 070 * Gets the normalized value of a substring assertion. 071 * 072 * @param value the substring value to normalize. It must *not* be null ! 073 * @param assertionType The type of assertion 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, PrepareString.AssertionType assertionType ) 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}