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        protected SCBuilder( String oid )
053        {
054            this.oid = oid;
055        }
056        
057        
058        /**
059         * Set the SyntaxChecker's OID
060         * 
061         * @param oid The OID
062         * @return The Builder's Instance
063         */
064        public SCBuilder<SC> setOid( String oid )
065        {
066            this.oid = oid;
067            
068            return this;
069        }
070        
071        public abstract SC build();
072    }
073
074
075    /**
076     * The SyntaxChecker base constructor
077     * @param oid The associated OID
078     */
079    protected SyntaxChecker( String oid )
080    {
081        super( SchemaObjectType.SYNTAX_CHECKER, oid );
082    }
083
084
085    /**
086     * The SyntaxChecker default constructor where the oid is set after 
087     * instantiation.
088     */
089    protected SyntaxChecker()
090    {
091        super( SchemaObjectType.SYNTAX_CHECKER );
092    }
093
094
095    /**
096     * Determines if the attribute's value conforms to the attribute syntax.
097     * 
098     * @param value the value of some attribute with the syntax
099     * @return true if the value is in the valid syntax, false otherwise
100     */
101    public boolean isValidSyntax( Object value )
102    {
103        if ( LOG.isDebugEnabled() )
104        {
105            LOG.debug( I18n.msg( I18n.MSG_04489_SYNTAX_VALID, value ) );
106        }
107        
108        return true;
109    }
110
111
112    /**
113     * Store the SchemaManager in this instance. It may be necessary for some
114     * syntaxChecker which needs to have access to the oidNormalizer Map.
115     *
116     * @param schemaManager the schemaManager to store
117     */
118    public void setSchemaManager( SchemaManager schemaManager )
119    {
120        // Do nothing (general case).
121    }
122
123
124    /**
125     * {@inheritDoc}
126     */
127    @Override
128    public boolean equals( Object o )
129    {
130        if ( !super.equals( o ) )
131        {
132            return false;
133        }
134
135        return o instanceof SyntaxChecker;
136    }
137
138
139    /**
140     * {@inheritDoc}
141     */
142    @Override
143    public String toString()
144    {
145        return objectType + " " + DescriptionUtils.getDescription( this );
146    }
147}