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  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           * @param oid The SyntaxChecker OID
53           */
54          protected SCBuilder( String oid )
55          {
56              this.oid = oid;
57          }
58          
59          
60          /**
61           * Set the SyntaxChecker's OID
62           * 
63           * @param oid The OID
64           * @return The Builder's Instance
65           */
66          public SCBuilder<SC> setOid( String oid )
67          {
68              this.oid = oid;
69              
70              return this;
71          }
72          
73          public abstract SC build();
74      }
75  
76      /**
77       * The SyntaxChecker base constructor
78       * 
79       * @param oid The associated OID
80       */
81      protected SyntaxChecker( String oid )
82      {
83          super( SchemaObjectType.SYNTAX_CHECKER, oid );
84      }
85  
86  
87      /**
88       * The SyntaxChecker default constructor where the oid is set after 
89       * instantiation.
90       */
91      protected SyntaxChecker()
92      {
93          super( SchemaObjectType.SYNTAX_CHECKER );
94      }
95  
96  
97      /**
98       * Determines if the attribute's value conforms to the attribute syntax.
99       * 
100      * @param value the value of some attribute with the syntax
101      * @return true if the value is in the valid syntax, false otherwise
102      */
103     public boolean isValidSyntax( Object value )
104     {
105         if ( LOG.isDebugEnabled() )
106         {
107             LOG.debug( I18n.msg( I18n.MSG_13701_SYNTAX_VALID, value ) );
108         }
109         
110         return true;
111     }
112 
113 
114     /**
115      * Store the SchemaManager in this instance. It may be necessary for some
116      * syntaxChecker which needs to have access to the oidNormalizer Map.
117      *
118      * @param schemaManager the schemaManager to store
119      */
120     public void setSchemaManager( SchemaManager schemaManager )
121     {
122         // Do nothing (general case).
123     }
124 
125 
126     /**
127      * {@inheritDoc}
128      */
129     @Override
130     public boolean equals( Object o )
131     {
132         if ( !super.equals( o ) )
133         {
134             return false;
135         }
136 
137         return o instanceof SyntaxChecker;
138     }
139 
140 
141     /**
142      * {@inheritDoc}
143      */
144     @Override
145     public String toString()
146     {
147         return objectType + " " + DescriptionUtils.getDescription( this );
148     }
149 }