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 * http://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.entry.Value;
24 import org.apache.directory.api.ldap.model.exception.LdapException;
25
26
27 /**
28 * Converts attribute values to a canonical form.
29 *
30 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
31 */
32 public abstract class Normalizer extends LoadableSchemaObject
33 {
34 /** The mandatory serialVersionUID */
35 public static final long serialVersionUID = 1L;
36
37
38 /**
39 * The Normalizer base constructor. We use it's MR OID to
40 * initialize the SchemaObject instance
41 *
42 * @param oid The associated OID. It's the element's MR OID
43 */
44 protected Normalizer( String oid )
45 {
46 super( SchemaObjectType.NORMALIZER, oid );
47 }
48
49
50 /**
51 * Use this default constructor when the Normalizer must be instantiated
52 * before setting the OID.
53 */
54 protected Normalizer()
55 {
56 super( SchemaObjectType.NORMALIZER );
57 }
58
59
60 /**
61 * Gets the normalized value.
62 *
63 * @param value the value to normalize. It must *not* be null !
64 * @return the normalized form for a value
65 * @throws LdapException if an error results during normalization
66 */
67 public abstract Value<?> normalize( Value<?> value ) throws LdapException;
68
69
70 /**
71 * Gets the normalized value.
72 *
73 * @param value the value to normalize. It must *not* be null !
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 ) 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 }