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   *    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.syntaxCheckers;
21  
22  
23  import org.apache.directory.api.ldap.model.constants.SchemaConstants;
24  import org.apache.directory.api.ldap.model.schema.SyntaxChecker;
25  import org.apache.directory.api.util.Strings;
26  import org.slf4j.Logger;
27  import org.slf4j.LoggerFactory;
28  
29  
30  /**
31   * A SyntaxChecker which verifies that a value is a valid DerefAlias. We
32   * have four possible values :
33   * <ul>
34   * <li>NEVER</li>
35   * <li>SEARCHING</li>
36   * <li>FINDING</li>
37   * <li>ALWAYS</li>
38   * </ul>
39   * The value is case insensitive
40   *
41   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
42   */
43  @SuppressWarnings("serial")
44  public class DerefAliasSyntaxChecker extends SyntaxChecker
45  {
46      /** A logger for this class */
47      private static final Logger LOG = LoggerFactory.getLogger( DerefAliasSyntaxChecker.class );
48  
49  
50      /**
51       * Creates a new instance of DerefAliasSyntaxChecker.
52       */
53      public DerefAliasSyntaxChecker()
54      {
55          super( SchemaConstants.DEREF_ALIAS_SYNTAX );
56      }
57  
58  
59      /**
60       * {@inheritDoc}
61       */
62      public boolean isValidSyntax( Object value )
63      {
64          String strValue = null;
65  
66          if ( value == null )
67          {
68              LOG.debug( "Syntax invalid for 'null'" );
69              return false;
70          }
71  
72          if ( value instanceof String )
73          {
74              strValue = ( String ) value;
75          }
76          else if ( value instanceof byte[] )
77          {
78              strValue = Strings.utf8ToString( ( byte[] ) value );
79          }
80          else
81          {
82              strValue = value.toString();
83          }
84  
85          strValue = Strings.trim( Strings.toLowerCase( strValue ) );
86  
87          return ( "never".equals( strValue ) ||
88              "finding".equals( strValue ) ||
89              "searching".equals( strValue ) || "always".equals( strValue ) );
90      }
91  }