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 * https://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.i18n.I18n; 024import org.apache.directory.api.ldap.model.constants.SchemaConstants; 025import org.apache.directory.api.ldap.model.schema.SyntaxChecker; 026import org.apache.directory.api.util.Strings; 027 028 029/** 030 * A syntax checker which checks to see if an objectClass' type is either: 031 * <em>AUXILIARY</em>, <em>STRUCTURAL</em>, or <em>ABSTRACT</em>. The case is NOT ignored. 032 * 033 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 034 */ 035@SuppressWarnings("serial") 036public final class ObjectClassTypeSyntaxChecker extends SyntaxChecker 037{ 038 /** 039 * A static instance of ObjectClassTypeSyntaxChecker 040 */ 041 public static final ObjectClassTypeSyntaxChecker INSTANCE = 042 new ObjectClassTypeSyntaxChecker( SchemaConstants.OBJECT_CLASS_TYPE_SYNTAX ); 043 044 /** 045 * A static Builder for this class 046 */ 047 public static final class Builder extends SCBuilder<ObjectClassTypeSyntaxChecker> 048 { 049 /** 050 * The Builder constructor 051 */ 052 private Builder() 053 { 054 super( SchemaConstants.OBJECT_CLASS_TYPE_SYNTAX ); 055 } 056 057 058 /** 059 * Create a new instance of ObjectClassTypeSyntaxChecker 060 * @return A new instance of ObjectClassTypeSyntaxChecker 061 */ 062 @Override 063 public ObjectClassTypeSyntaxChecker build() 064 { 065 return new ObjectClassTypeSyntaxChecker( oid ); 066 } 067 } 068 069 070 /** 071 * Creates a new instance of ObjectClassTypeSyntaxChecker. 072 * 073 * @param oid The OID to use for this SyntaxChecker 074 */ 075 private ObjectClassTypeSyntaxChecker( String oid ) 076 { 077 super( oid ); 078 } 079 080 081 /** 082 * @return An instance of the Builder for this class 083 */ 084 public static Builder builder() 085 { 086 return new Builder(); 087 } 088 089 090 /** 091 * {@inheritDoc} 092 */ 093 @Override 094 public boolean isValidSyntax( Object value ) 095 { 096 String strValue; 097 098 if ( value == null ) 099 { 100 if ( LOG.isDebugEnabled() ) 101 { 102 LOG.debug( I18n.err( I18n.ERR_13210_SYNTAX_INVALID, "null" ) ); 103 } 104 105 return false; 106 } 107 108 if ( value instanceof String ) 109 { 110 strValue = ( String ) value; 111 } 112 else if ( value instanceof byte[] ) 113 { 114 strValue = Strings.utf8ToString( ( byte[] ) value ); 115 } 116 else 117 { 118 strValue = value.toString(); 119 } 120 121 if ( strValue.length() < 8 || strValue.length() > 10 ) 122 { 123 if ( LOG.isDebugEnabled() ) 124 { 125 LOG.debug( I18n.err( I18n.ERR_13210_SYNTAX_INVALID, value ) ); 126 } 127 128 return false; 129 } 130 131 switch ( strValue ) 132 { 133 case "AUXILIARY" : 134 case "ABSTRACT" : 135 case "STRUCTURAL" : 136 if ( LOG.isDebugEnabled() ) 137 { 138 LOG.debug( I18n.msg( I18n.MSG_13701_SYNTAX_VALID, value ) ); 139 } 140 141 return true; 142 143 default : 144 if ( LOG.isDebugEnabled() ) 145 { 146 LOG.debug( I18n.err( I18n.ERR_13210_SYNTAX_INVALID, value ) ); 147 } 148 149 return false; 150 } 151 } 152}