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     */
020    package org.apache.directory.shared.ldap.schema;
021    
022    
023    import org.apache.directory.shared.ldap.exception.LdapException;
024    
025    import org.apache.directory.shared.ldap.exception.LdapInvalidAttributeValueException;
026    import org.apache.directory.shared.ldap.message.ResultCodeEnum;
027    
028    
029    /**
030     * Used to validate values of a particular syntax. This interface does not
031     * correlate to any LDAP or X.500 construct. It has been created as a means to
032     * enforce a syntax within the Eve server.
033     * 
034     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
035     * @version $Rev: 923524 $, $Date: 2010-03-16 01:31:36 +0100 (Tue, 16 Mar 2010) $
036     */
037    public abstract class SyntaxChecker extends LoadableSchemaObject
038    {
039        /** The serialversionUID */
040        private static final long serialVersionUID = 1L;
041    
042        /**
043         * The SyntaxChecker base constructor
044         * @param oid The associated OID
045         */
046        protected SyntaxChecker( String oid )
047        {
048            super( SchemaObjectType.SYNTAX_CHECKER, oid );
049        }
050    
051    
052        /**
053         * The SyntaxChecker default constructor where the oid is set after 
054         * instantiation.
055         */
056        protected SyntaxChecker()
057        {
058            super( SchemaObjectType.SYNTAX_CHECKER );
059        }
060    
061    
062        /**
063         * Determines if the attribute's value conforms to the attribute syntax.
064         * 
065         * @param value the value of some attribute with the syntax
066         * @return true if the value is in the valid syntax, false otherwise
067         */
068        public abstract boolean isValidSyntax( Object value );
069    
070    
071        /**
072         * Asserts whether or not the attribute's value conforms to the attribute
073         * syntax.
074         * 
075         * @param value the value of some attribute with the syntax
076         * @throws LdapException if the value does not conform to the attribute syntax.
077         */
078        public void assertSyntax( Object value ) throws LdapException
079        {
080            if ( !isValidSyntax( value ) )
081            {
082                throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
083            }
084        }
085    
086    
087        /**
088         * @see Object#equals()
089         */
090        public boolean equals( Object o )
091        {
092            if ( !super.equals( o ) )
093            {
094                return false;
095            }
096    
097            return o instanceof SyntaxChecker;
098        }
099    
100        
101        /**
102         * @see Object#toString()
103         */
104        public String toString()
105        {
106            return objectType + " " + DescriptionUtils.getDescription( this );
107        }
108    }