001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 *
019 */
020 package org.apache.directory.shared.ldap.schema.syntaxCheckers;
021
022
023 import org.apache.directory.shared.ldap.constants.SchemaConstants;
024 import org.apache.directory.shared.ldap.schema.SyntaxChecker;
025 import org.apache.directory.shared.ldap.util.StringTools;
026 import org.slf4j.Logger;
027 import org.slf4j.LoggerFactory;
028
029
030 /**
031 * A syntax checker which checks to see if an objectClass' type is either:
032 * AUXILIARY, STRUCTURAL, or ABSTRACT. The case is NOT ignored.
033 *
034 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
035 * @version $Rev$
036 */
037 public class ObjectClassTypeSyntaxChecker extends SyntaxChecker
038 {
039 /** A logger for this class */
040 private static final Logger LOG = LoggerFactory.getLogger( ObjectClassTypeSyntaxChecker.class );
041
042 /** The serialVersionUID */
043 private static final long serialVersionUID = 1L;
044
045 /**
046 * Creates a new instance of ObjectClassTypeSyntaxChecker.
047 */
048 public ObjectClassTypeSyntaxChecker()
049 {
050 super( SchemaConstants.OBJECT_CLASS_TYPE_SYNTAX );
051 }
052
053
054 /**
055 * {@inheritDoc}
056 */
057 public boolean isValidSyntax( Object value )
058 {
059 String strValue = null;
060
061 if ( value == null )
062 {
063 LOG.debug( "Syntax invalid for '{}'", value );
064 return false;
065 }
066
067 if ( value instanceof String )
068 {
069 strValue = ( String ) value;
070 }
071 else if ( value instanceof byte[] )
072 {
073 strValue = StringTools.utf8ToString( ( byte[] ) value );
074 }
075 else
076 {
077 strValue = value.toString();
078 }
079
080 if ( strValue.length() < 8 || strValue.length() > 10 )
081 {
082 LOG.debug( "Syntax invalid for '{}'", value );
083 return false;
084 }
085
086 char ch = strValue.charAt( 0 );
087
088 switch( ch )
089 {
090 case( 'A' ):
091 if ( "AUXILIARY".equals( strValue ) || "ABSTRACT".equals( strValue ) )
092 {
093 LOG.debug( "Syntax valid for '{}'", value );
094 return true;
095 }
096
097 LOG.debug( "Syntax invalid for '{}'", value );
098 return false;
099
100 case( 'S' ):
101 boolean result = "STRUCTURAL".equals( strValue );
102
103 if ( result )
104 {
105 LOG.debug( "Syntax valid for '{}'", value );
106 }
107 else
108 {
109 LOG.debug( "Syntax invalid for '{}'", value );
110 }
111
112 return result;
113
114 default:
115 LOG.debug( "Syntax invalid for '{}'", value );
116 return false;
117 }
118 }
119 }