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 */ 020package org.apache.directory.api.ldap.model.schema.syntaxCheckers; 021 022 023import org.apache.directory.api.ldap.model.constants.SchemaConstants; 024import org.apache.directory.api.ldap.model.schema.SyntaxChecker; 025import org.apache.directory.api.util.Strings; 026import org.slf4j.Logger; 027import 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 */ 036@SuppressWarnings("serial") 037public class ObjectClassTypeSyntaxChecker extends SyntaxChecker 038{ 039 /** A logger for this class */ 040 private static final Logger LOG = LoggerFactory.getLogger( ObjectClassTypeSyntaxChecker.class ); 041 042 043 /** 044 * Creates a new instance of ObjectClassTypeSyntaxChecker. 045 */ 046 public ObjectClassTypeSyntaxChecker() 047 { 048 super( SchemaConstants.OBJECT_CLASS_TYPE_SYNTAX ); 049 } 050 051 052 /** 053 * {@inheritDoc} 054 */ 055 public boolean isValidSyntax( Object value ) 056 { 057 String strValue = null; 058 059 if ( value == null ) 060 { 061 LOG.debug( "Syntax invalid for 'null'" ); 062 return false; 063 } 064 065 if ( value instanceof String ) 066 { 067 strValue = ( String ) value; 068 } 069 else if ( value instanceof byte[] ) 070 { 071 strValue = Strings.utf8ToString( ( byte[] ) value ); 072 } 073 else 074 { 075 strValue = value.toString(); 076 } 077 078 if ( strValue.length() < 8 || strValue.length() > 10 ) 079 { 080 LOG.debug( "Syntax invalid for '{}'", value ); 081 return false; 082 } 083 084 char ch = strValue.charAt( 0 ); 085 086 switch ( ch ) 087 { 088 case ( 'A' ): 089 if ( "AUXILIARY".equals( strValue ) || "ABSTRACT".equals( strValue ) ) 090 { 091 LOG.debug( "Syntax valid for '{}'", value ); 092 return true; 093 } 094 095 LOG.debug( "Syntax invalid for '{}'", value ); 096 return false; 097 098 case ( 'S' ): 099 boolean result = "STRUCTURAL".equals( strValue ); 100 101 if ( result ) 102 { 103 LOG.debug( "Syntax valid for '{}'", value ); 104 } 105 else 106 { 107 LOG.debug( "Syntax invalid for '{}'", value ); 108 } 109 110 return result; 111 112 default: 113 LOG.debug( "Syntax invalid for '{}'", value ); 114 return false; 115 } 116 } 117}