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; 021 022import org.apache.directory.api.i18n.I18n; 023import org.slf4j.Logger; 024import org.slf4j.LoggerFactory; 025 026/** 027 * Used to validate values of a particular syntax. This interface does not 028 * correlate to any LDAP or X.500 construct. It has been created as a means to 029 * enforce a syntax within the Eve server. 030 * 031 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 032 */ 033public abstract class SyntaxChecker extends LoadableSchemaObject 034{ 035 /** The mandatory serialVersionUID */ 036 public static final long serialVersionUID = 1L; 037 038 /** A logger for this class */ 039 protected static final Logger LOG = LoggerFactory.getLogger( SyntaxChecker.class ); 040 041 /** 042 * A static Builder for this class 043 */ 044 public abstract static class SCBuilder<SC> 045 { 046 /** The SyntaxChecker OID */ 047 protected String oid; 048 049 /** 050 * The Builder constructor 051 * 052 * @param oid The SyntaxChecker OID 053 */ 054 protected SCBuilder( String oid ) 055 { 056 this.oid = oid; 057 } 058 059 060 /** 061 * Set the SyntaxChecker's OID 062 * 063 * @param oid The OID 064 * @return The Builder's Instance 065 */ 066 public SCBuilder<SC> setOid( String oid ) 067 { 068 this.oid = oid; 069 070 return this; 071 } 072 073 public abstract SC build(); 074 } 075 076 /** 077 * The SyntaxChecker base constructor 078 * 079 * @param oid The associated OID 080 */ 081 protected SyntaxChecker( String oid ) 082 { 083 super( SchemaObjectType.SYNTAX_CHECKER, oid ); 084 } 085 086 087 /** 088 * The SyntaxChecker default constructor where the oid is set after 089 * instantiation. 090 */ 091 protected SyntaxChecker() 092 { 093 super( SchemaObjectType.SYNTAX_CHECKER ); 094 } 095 096 097 /** 098 * Determines if the attribute's value conforms to the attribute syntax. 099 * 100 * @param value the value of some attribute with the syntax 101 * @return true if the value is in the valid syntax, false otherwise 102 */ 103 public boolean isValidSyntax( Object value ) 104 { 105 if ( LOG.isDebugEnabled() ) 106 { 107 LOG.debug( I18n.msg( I18n.MSG_13701_SYNTAX_VALID, value ) ); 108 } 109 110 return true; 111 } 112 113 114 /** 115 * Store the SchemaManager in this instance. It may be necessary for some 116 * syntaxChecker which needs to have access to the oidNormalizer Map. 117 * 118 * @param schemaManager the schemaManager to store 119 */ 120 public void setSchemaManager( SchemaManager schemaManager ) 121 { 122 // Do nothing (general case). 123 } 124 125 126 /** 127 * {@inheritDoc} 128 */ 129 @Override 130 public boolean equals( Object o ) 131 { 132 if ( !super.equals( o ) ) 133 { 134 return false; 135 } 136 137 return o instanceof SyntaxChecker; 138 } 139 140 141 /** 142 * {@inheritDoc} 143 */ 144 @Override 145 public String toString() 146 { 147 return objectType + " " + DescriptionUtils.getDescription( this ); 148 } 149}