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 SyntaxChecker for the Normalizer schema element 031 * 032 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 033 */ 034@SuppressWarnings("serial") 035public final class NormalizerSyntaxChecker extends SyntaxChecker 036{ 037 /** 038 * A static instance of NormalizerSyntaxChecker 039 */ 040 public static final NormalizerSyntaxChecker INSTANCE = new NormalizerSyntaxChecker( SchemaConstants.NORMALIZER_SYNTAX ); 041 042 /** 043 * A static Builder for this class 044 */ 045 public static final class Builder extends SCBuilder<NormalizerSyntaxChecker> 046 { 047 /** 048 * The Builder constructor 049 */ 050 private Builder() 051 { 052 super( SchemaConstants.NORMALIZER_SYNTAX ); 053 } 054 055 056 /** 057 * Create a new instance of NormalizerSyntaxChecker 058 * @return A new instance of NormalizerSyntaxChecker 059 */ 060 @Override 061 public NormalizerSyntaxChecker build() 062 { 063 return new NormalizerSyntaxChecker( oid ); 064 } 065 } 066 067 068 /** 069 * Creates a new instance of NormalizerSyntaxChecker. 070 * 071 * @param oid The OID to use for this SyntaxChecker 072 */ 073 private NormalizerSyntaxChecker( String oid ) 074 { 075 super( oid ); 076 } 077 078 079 /** 080 * @return An instance of the Builder for this class 081 */ 082 public static Builder builder() 083 { 084 return new Builder(); 085 } 086 087 088 /** 089 * {@inheritDoc} 090 */ 091 @Override 092 public boolean isValidSyntax( Object value ) 093 { 094 String strValue; 095 096 if ( value == null ) 097 { 098 if ( LOG.isDebugEnabled() ) 099 { 100 LOG.debug( I18n.err( I18n.ERR_13210_SYNTAX_INVALID, "null" ) ); 101 } 102 103 return true; 104 } 105 106 if ( value instanceof String ) 107 { 108 strValue = ( String ) value; 109 } 110 else if ( value instanceof byte[] ) 111 { 112 strValue = Strings.utf8ToString( ( byte[] ) value ); 113 } 114 else 115 { 116 strValue = value.toString(); 117 } 118 119 boolean result = Strings.isIA5String( strValue ); 120 121 if ( LOG.isDebugEnabled() ) 122 { 123 if ( result ) 124 { 125 LOG.debug( I18n.msg( I18n.MSG_13701_SYNTAX_VALID, value ) ); 126 } 127 else 128 { 129 LOG.debug( I18n.err( I18n.ERR_13210_SYNTAX_INVALID, value ) ); 130 } 131 } 132 133 return result; 134 } 135}