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.exception.LdapException;
24 import org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException;
25 import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
26
27
28 /**
29 * Used to validate values of a particular syntax. This interface does not
30 * correlate to any LDAP or X.500 construct. It has been created as a means to
31 * enforce a syntax within the Eve server.
32 *
33 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
34 */
35 public abstract class SyntaxChecker extends LoadableSchemaObject
36 {
37 /** The mandatory serialVersionUID */
38 public static final long serialVersionUID = 1L;
39
40
41 /**
42 * The SyntaxChecker base constructor
43 * @param oid The associated OID
44 */
45 protected SyntaxChecker( String oid )
46 {
47 super( SchemaObjectType.SYNTAX_CHECKER, oid );
48 }
49
50
51 /**
52 * The SyntaxChecker default constructor where the oid is set after
53 * instantiation.
54 */
55 protected SyntaxChecker()
56 {
57 super( SchemaObjectType.SYNTAX_CHECKER );
58 }
59
60
61 /**
62 * Determines if the attribute's value conforms to the attribute syntax.
63 *
64 * @param value the value of some attribute with the syntax
65 * @return true if the value is in the valid syntax, false otherwise
66 */
67 public abstract boolean isValidSyntax( Object value );
68
69
70 /**
71 * Asserts whether or not the attribute's value conforms to the attribute
72 * syntax.
73 *
74 * @param value the value of some attribute with the syntax
75 * @throws LdapException if the value does not conform to the attribute syntax.
76 */
77 public void assertSyntax( Object value ) throws LdapException
78 {
79 if ( !isValidSyntax( value ) )
80 {
81 throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
82 }
83 }
84
85
86 /**
87 * Store the SchemaManager in this instance. It may be necessary for some
88 * syntaxChecker which needs to have access to the oidNormalizer Map.
89 *
90 * @param schemaManager the schemaManager to store
91 */
92 public void setSchemaManager( SchemaManager schemaManager )
93 {
94 // Do nothing (general case).
95 }
96
97
98 /**
99 * {@inheritDoc}
100 */
101 @Override
102 public boolean equals( Object o )
103 {
104 if ( !super.equals( o ) )
105 {
106 return false;
107 }
108
109 return o instanceof SyntaxChecker;
110 }
111
112
113 /**
114 * {@inheritDoc}
115 */
116 @Override
117 public String toString()
118 {
119 return objectType + " " + DescriptionUtils.getDescription( this );
120 }
121 }