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 import org.apache.directory.api.i18n.I18n;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 /**
27 * Used to validate values of a particular syntax. This interface does not
28 * correlate to any LDAP or X.500 construct. It has been created as a means to
29 * enforce a syntax within the Eve server.
30 *
31 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
32 */
33 public abstract class SyntaxChecker extends LoadableSchemaObject
34 {
35 /** The mandatory serialVersionUID */
36 public static final long serialVersionUID = 1L;
37
38 /** A logger for this class */
39 protected static final Logger LOG = LoggerFactory.getLogger( SyntaxChecker.class );
40
41 /**
42 * A static Builder for this class
43 */
44 public abstract static class SCBuilder<SC>
45 {
46 /** The SyntaxChecker OID */
47 protected String oid;
48
49 /**
50 * The Builder constructor
51 */
52 protected SCBuilder( String oid )
53 {
54 this.oid = oid;
55 }
56
57
58 /**
59 * Set the SyntaxChecker's OID
60 *
61 * @param oid The OID
62 * @return The Builder's Instance
63 */
64 public SCBuilder<SC> setOid( String oid )
65 {
66 this.oid = oid;
67
68 return this;
69 }
70
71 public abstract SC build();
72 }
73
74
75 /**
76 * The SyntaxChecker base constructor
77 * @param oid The associated OID
78 */
79 protected SyntaxChecker( String oid )
80 {
81 super( SchemaObjectType.SYNTAX_CHECKER, oid );
82 }
83
84
85 /**
86 * The SyntaxChecker default constructor where the oid is set after
87 * instantiation.
88 */
89 protected SyntaxChecker()
90 {
91 super( SchemaObjectType.SYNTAX_CHECKER );
92 }
93
94
95 /**
96 * Determines if the attribute's value conforms to the attribute syntax.
97 *
98 * @param value the value of some attribute with the syntax
99 * @return true if the value is in the valid syntax, false otherwise
100 */
101 public boolean isValidSyntax( Object value )
102 {
103 if ( LOG.isDebugEnabled() )
104 {
105 LOG.debug( I18n.msg( I18n.MSG_04489_SYNTAX_VALID, value ) );
106 }
107
108 return true;
109 }
110
111
112 /**
113 * Store the SchemaManager in this instance. It may be necessary for some
114 * syntaxChecker which needs to have access to the oidNormalizer Map.
115 *
116 * @param schemaManager the schemaManager to store
117 */
118 public void setSchemaManager( SchemaManager schemaManager )
119 {
120 // Do nothing (general case).
121 }
122
123
124 /**
125 * {@inheritDoc}
126 */
127 @Override
128 public boolean equals( Object o )
129 {
130 if ( !super.equals( o ) )
131 {
132 return false;
133 }
134
135 return o instanceof SyntaxChecker;
136 }
137
138
139 /**
140 * {@inheritDoc}
141 */
142 @Override
143 public String toString()
144 {
145 return objectType + " " + DescriptionUtils.getDescription( this );
146 }
147 }