View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    https://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.api.ldap.model.schema;
21  
22  
23  import org.apache.directory.api.ldap.model.exception.LdapException;
24  
25  
26  /**
27   * Converts attribute values to a canonical form.
28   * 
29   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
30   */
31  public abstract class Normalizer extends LoadableSchemaObject
32  {
33      /** The mandatory serialVersionUID */
34      public static final long serialVersionUID = 1L;
35  
36  
37      /**
38       * The Normalizer base constructor. We use it's MR OID to
39       * initialize the SchemaObject instance
40       * 
41       * @param oid The associated OID. It's the element's MR OID
42       */
43      protected Normalizer( String oid )
44      {
45          super( SchemaObjectType.NORMALIZER, oid );
46      }
47  
48  
49      /**
50       * Use this default constructor when the Normalizer must be instantiated
51       * before setting the OID.
52       */
53      protected Normalizer()
54      {
55          super( SchemaObjectType.NORMALIZER );
56      }
57  
58  
59      /**
60       * Gets the normalized value of AssertionValues.
61       * 
62       * @param value the value to normalize. It must *not* be null !
63       * @return the normalized form for a value
64       * @throws LdapException if an error results during normalization
65       */
66      public abstract String normalize( String value ) throws LdapException;
67  
68  
69      /**
70       * Gets the normalized value of a substring assertion.
71       * 
72       * @param value the substring value to normalize. It must *not* be null !
73       * @param assertionType The type of assertion
74       * @return the normalized form for a value
75       * @throws LdapException if an error results during normalization
76       */
77      public abstract String normalize( String value, PrepareString.AssertionType assertionType ) throws LdapException;
78  
79  
80      /**
81       * Store the SchemaManager in this instance. It may be necessary for some
82       * normalizer which needs to have access to the oidNormalizer Map.
83       *
84       * @param schemaManager the schemaManager to store
85       */
86      public void setSchemaManager( SchemaManager schemaManager )
87      {
88          // Do nothing (general case).
89      }
90  
91  
92      /**
93       * {@inheritDoc}
94       */
95      @Override
96      public boolean equals( Object o )
97      {
98          if ( !super.equals( o ) )
99          {
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 }