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, eCopyOfUuidSyntaxCheckerither 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.shared.ldap.model.schema.syntaxCheckers; 021 022import org.apache.directory.shared.ldap.model.constants.SchemaConstants; 023import org.apache.directory.shared.ldap.model.csn.Csn; 024import org.apache.directory.shared.ldap.model.csn.InvalidCSNException; 025import org.apache.directory.shared.ldap.model.schema.SyntaxChecker; 026import org.slf4j.Logger; 027import org.slf4j.LoggerFactory; 028 029 030/** 031 * An CSN syntax checker. 032 * 033 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 034 */ 035@SuppressWarnings("serial") 036public class CsnSyntaxChecker extends SyntaxChecker 037{ 038 /** A logger for this class */ 039 private static final Logger LOG = LoggerFactory.getLogger( CsnSyntaxChecker.class ); 040 041 /** 042 * Creates a new instance of CsnSyntaxChecker. 043 */ 044 public CsnSyntaxChecker() 045 { 046 super( SchemaConstants.CSN_SYNTAX ); 047 } 048 049 050 /** 051 * {@inheritDoc} 052 */ 053 public boolean isValidSyntax( Object value ) 054 { 055 if ( value == null ) 056 { 057 LOG.debug( "Syntax invalid for 'null'" ); 058 return false; 059 } 060 061 if ( ! ( value instanceof String ) ) 062 { 063 LOG.debug( "Syntax invalid for '{}'", value ); 064 return false; 065 } 066 067 String csnStr = (String)value; 068 069 // It must be a valid CSN : try to create a new one. 070 try 071 { 072 boolean result = Csn.isValid( csnStr ); 073 074 if ( result ) 075 { 076 LOG.debug( "Syntax valid for '{}'", value ); 077 } 078 else 079 { 080 LOG.debug( "Syntax invalid for '{}'", value ); 081 } 082 083 return result; 084 } 085 catch ( InvalidCSNException icsne ) 086 { 087 LOG.debug( "Syntax invalid for '{}'", value ); 088 return false; 089 } 090 } 091}